mathigon / euclid.js Goto Github PK
View Code? Open in Web Editor NEW2D Euclidean geometry classes, utilities, and drawing tools
Home Page: https://mathigon.io/euclid
License: MIT License
2D Euclidean geometry classes, utilities, and drawing tools
Home Page: https://mathigon.io/euclid
License: MIT License
This issue lists Renovate updates and detected dependencies. Read the Dependency Dashboard docs to learn more.
These updates are awaiting their schedule. Click on a checkbox to get an update now.
esbuild
, eslint
, eslint-plugin-import
).github/workflows/codeql.yml
actions/checkout v3
github/codeql-action v2
github/codeql-action v2
.github/workflows/test.yml
actions/checkout v3
actions/setup-node v3
bahmutov/npm-install v1
package.json
@mathigon/core 1.1.10
@mathigon/fermat 1.1.9
@types/tape 5.6.0
@typescript-eslint/eslint-plugin 6.4.0
@typescript-eslint/parser 6.4.0
esbuild 0.18.17
eslint 8.46.0
eslint-plugin-import 2.28.0
tape 5.6.6
ts-node 10.9.1
tslib 2.6.1
typescript 5.1.6
node >=14
Currently, if I have a circle, there is no way to change the origin of the point to a given point.
There is translate(Point)
and shift(x,y)
, but translate just invokes shift
, and it moves the point, not sets it at the new point.
The current solution is to use the verbose constructor and go myCircle = new Circle(new Point(x,y),myCircle.radius)
.
Either offer a new interface method like Circle.setOrigin(Point)
or Circle.setOrigin(x,y)
or offer a Point.set(x,y)
which will mutate the x and y variables in place.
This way APIs could accept an interface of { points: Point[] }
and be made to work with both Polygon
-type shapes and Line
-type shapes easily.
This would also allow for destructuring line.points
to quickly renaming variables, for example:
// could be...
let [a, b] = line.points
// instead of...
let a = line.p1
let b = line.p2
(I'm just opening issues as I use the library and run into problems or inconveniences, but let me know if you'd prefer I not open these kind of ideas issues.)
(new Polygon([
new Point(0,0),
new Point(100,0),
new Point(100,100),
new Point(0,100),
])).contains(new Point(50,50));
Throws "Uncaught TypeError: e.p1.equals is not a function" in Polygon.contains
When finding intersections of a ray and a polygon, the result may contain point that does not lie on the ray. Try the following code:
const polygon = new Polygon(new Point(0, 0), new Point(100, 0), new Point(100, 100), new Point(0, 100), new Point(0, 50));
const ray = new Ray(new Point(50, 50), new Point(100, 50));
console.log(intersections(ray, polygon));
The result of the intersections
function contains Point(0, 50)
which does not lie on the ray.
I think this happens when there is a polygon vertex that lies on a line coincident with the ray. If Point(0, 50)
is removed from the polygon, the result is valid.
The following produces no intersections but seems like it should:
intersections(
new Circle( new Point(2, 3), 1),
new Polygon( new Point(2, 3), new Point(3, 3), new Point(3, 4), new Point(2, 4)
);
Intersections should be reported at 3, 3
and 2, 4
. It seems that when the intersections occur at the polygon's vertices, they are not reported. Is this a bug or have I misunderstood how to use intersections
? Thanks!
Hello, and thanks for this great library!
I wanted to use this library to calculate the intersection between a line segment and a rectangle but was unable to figure out how to do that. The intersections
method looked promising, but it does not accept LineSegment
or Rectangle
as arguments.
In my particular case, it would always just be one intersection because I want to draw a line from the center of one rectangle to the center of another non-overlapping rectangle, but in general, I guess such a function should return a list of potentially more than one intersection.
Hi,
I was getting perplexing results using Line and reading the source I realized that the intercept method has a wrong sign.
A possible test case fragment is the following:
const testline = new Line(
new Point(1, 1),
new Point(2, 2)
);
console.log('DUA LIPA IS ' + ( testline.intercept === 0 ? 'GORGEOUS' : 'UGLY'));
(of course the intercept should be 0 and Dua is gorgeous)
Trying to locate the error, in file line.ts at line 45 I read
return this.p1.y + this.slope * this.p1.x;
it should be:
return this.p1.y - this.slope * this.p1.x;
Thanks in advance for fixing...
The src/boolean.ts
module is the only one which is not exported in src/index.ts
. Is there any specific reason for that? Or is it just an accidental omission? I would love to use the module :)
Right now you can do:
segment.contract(0.25)
But it would be nice to be able to specify the contraction ratio for both the start and end points differently:
segment.contract(0.1, 0.4)
With the default being the same for both.
I tried following snippet:
const ellipse = new Ellipse(new Point(100, 100), 5, 3, 0);
const pt = new Point(100,100);
console.log("RESULT", intersections(pt, ellipse).length)
Ithe point is inside the ellipse, but the elngth of the intersections() is 0. how to use this correctly?
First off, this set of libraries is absolutely brilliant, thank you!
I'm playing around with it for some generative art, and wondering if there is a way to convert shapes like circles, ellipses, etc. into polygons. So that I can do things like distort the points, chop them up, smoothing, etc., etc.
It would be great if there was a ellipse.polygon(60)
for example which "rasterized" it into a 60-sided polygon.
For example, Point.translate(Point)
should just accept Point.translate({x:100,y:100})
, which is less verbose than Point.translate(new Point(100,100))
Hello, some functionality can be added to the Rectangle class:
/**
Restricts the rectangle within another larger rectangle.
{x: -50, y: -50, w: 100, y: 100} restrictWithin {x: 0: y: 0, w: 500, h: 500} -> {x: 0, y: 0, w: 100, y: 100}
*/
restrictWithin(rect: Rectangle): Rectangle;
This also can be added to Circle and Ellipse classes. The method can be overloaded:
restrictWithin(rect: Rectangle): Rectangle;
restrictWithin(rect: Circle): Rectangle;
restrictWithin(rect: Ellipse): Rectangle;
Calling drawCanvas with a line doesn't work.
drawCanvas(this.context2d, new Line(new Point(100, 100), new Point(200, 100)), {
stroke: 'orange',
strokeWidth: 3,
});
Hallo,
May I know is there a method that can check a polygon is completely inside another?
Thanks in advance.
Best regards,
In my case I'm trying to quickly interpolate between two line segments. Ideally it would be as easy as Segment.interpolate(a, b, 0.25)
.
I thought I might be able to use Polygon.interpolate
instead, but the TypeScript types complain about that. And using Point.interpolate
for the individual points gets tedious. Maybe I'm doing something wrong or missing an easier approach though!
Some references for how this can be accomplished in general:
This issue lists Renovate updates and detected dependencies. Read the Dependency Dashboard docs to learn more.
These updates are awaiting their schedule. Click on a checkbox to get an update now.
@typescript-eslint/eslint-plugin
, @typescript-eslint/parser
)These updates have all been created already. Click a checkbox below to force a retry/rebase of any.
esbuild
, eslint
, tape
).github/workflows/codeql.yml
actions/checkout v4
github/codeql-action v2
github/codeql-action v2
.github/workflows/test.yml
actions/checkout v4
actions/setup-node v3
bahmutov/npm-install v1
package.json
@mathigon/core 1.1.16
@mathigon/fermat 1.1.15
@types/tape 5.6.4
@typescript-eslint/eslint-plugin 6.21.0
@typescript-eslint/parser 6.21.0
esbuild 0.20.0
eslint 8.56.0
eslint-plugin-import 2.29.1
tape 5.7.4
ts-node 10.9.2
tslib 2.6.2
typescript 5.3.3
node >=16
There is an error with this repository's Renovate configuration that needs to be fixed. As a precaution, Renovate will stop PRs until it is resolved.
Error type: Cannot find preset's package (github>whitesource/merge-confidence:beta)
I noticed that in the test files this pattern is already used, with inline poly
and line
helpers defined. It would be really nice to be able to use this out of the box, because defining polygons or lines gets tedious having to do new Point(...), new Point(...), new Point(...)
manually.
Some actual code of mine:
let poly = new Polygon(
new Point(rx, rh),
new Point(lx, lh),
new Point(lx, ly),
new Point(rx, ry)
)
Would be nicely simplified to:
let poly = new Polygon(
[rx, rh],
[lx, lh],
[lx, ly],
[rx, ry]
)
It seems like this would be a variant of SimplePoint
, as a tuple instead of an object?
Hello, the method scale on the ellipse does not scale the center point but only the axes. It would be nice if the behavior was the same as in the circle. Many thanks in advance!
scale(sx: number, sy = sx) {
return new Ellipse(this.c.scale(sx, sy), this.a * sx, this.b * sy, this.angle);
}
A declarative, efficient, and flexible JavaScript library for building user interfaces.
๐ Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. ๐๐๐
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google โค๏ธ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.