@flatten-js/core
Advanced tools
Comparing version 1.2.4 to 1.2.5
// Just hit "node index.js" in the terminal while you are in the directory of this project | ||
let Flatten = require('@flatten-js/core'); | ||
let {point, segment, circle} = Flatten; | ||
let {point, segment, circle} = require('@flatten-js/core'); | ||
@@ -5,0 +4,0 @@ // make some construction |
{ | ||
"name": "@flatten-js/core", | ||
"version": "1.2.4", | ||
"version": "1.2.5", | ||
"description": "Javascript library for 2d geometry", | ||
@@ -5,0 +5,0 @@ "main": "dist/main.cjs.js", |
@@ -645,4 +645,4 @@ /** | ||
// If union - add face from wrk_polygon that is not intersected with res_polygon | ||
if ( (op === BOOLEAN_UNION || op == BOOLEAN_SUBTRACT) && | ||
int_points && int_points.find((ip) => (ip.face === face)) === undefined) { | ||
if ( /*(op === BOOLEAN_UNION || op == BOOLEAN_SUBTRACT) &&*/ | ||
int_points.find((ip) => (ip.face === face)) === undefined) { | ||
res_polygon.addFace(face.first, face.last); | ||
@@ -649,0 +649,0 @@ } |
@@ -21,3 +21,4 @@ /* | ||
intersectPolygon2Polygon, | ||
intersectShape2Polygon | ||
intersectShape2Polygon, | ||
intersectCircle2Circle | ||
} from "./intersection"; | ||
@@ -138,5 +139,19 @@ import {Multiline} from "../classes/multiline"; | ||
} | ||
else if ( (shape1 instanceof Flatten.Segment || shape1 instanceof Flatten.Arc) && | ||
(shape2 instanceof Flatten.Circle || shape2 instanceof Flatten.Box) ) { | ||
return relateShape2Polygon(shape1, new Flatten.Polygon(shape2)); | ||
} | ||
else if (shape1 instanceof Flatten.Polygon && shape2 instanceof Flatten.Polygon) { | ||
return relatePolygon2Polygon(shape1, shape2); | ||
} | ||
else if ((shape1 instanceof Flatten.Circle || shape1 instanceof Flatten.Box) && | ||
(shape2 instanceof Flatten.Circle || shape2 instanceof Flatten.Box)) { | ||
return relatePolygon2Polygon(new Flatten.Polygon(shape1), new Flatten.Polygon(shape2)); | ||
} | ||
else if ((shape1 instanceof Flatten.Circle || shape1 instanceof Flatten.Box) && shape2 instanceof Flatten.Polygon) { | ||
return relatePolygon2Polygon(new Flatten.Polygon(shape1), shape2); | ||
} | ||
else if (shape1 instanceof Flatten.Polygon && (shape2 instanceof Flatten.Circle || shape2 instanceof Flatten.Box)) { | ||
return relatePolygon2Polygon(shape1, new Flatten.Polygon(shape2)); | ||
} | ||
} | ||
@@ -143,0 +158,0 @@ |
@@ -105,3 +105,3 @@ /** | ||
} | ||
/* Instantiate face from circle circle in CCW orientation */ | ||
/* Instantiate face from a circle in CCW orientation */ | ||
else if (args[0] instanceof Flatten.Circle) { | ||
@@ -108,0 +108,0 @@ this.shapes2face(polygon.edges, [args[0].toArc(Flatten.CCW)]); |
@@ -42,8 +42,9 @@ /** | ||
/* It may be array of something that represent one loop (face) or | ||
/* It may be array of something that may represent one loop (face) or | ||
array of arrays that represent multiple loops | ||
*/ | ||
if (args.length === 1 && args[0] instanceof Array) { | ||
if (args.length === 1 && | ||
(args[0] instanceof Array || args[0] instanceof Flatten.Circle || args[0] instanceof Flatten.Box)){ | ||
let argsArray = args[0]; | ||
if (argsArray.every((loop) => {return loop instanceof Array})) { | ||
if (args[0] instanceof Array && argsArray.every((loop) => {return loop instanceof Array})) { | ||
if (argsArray.every( el => {return el instanceof Array && el.length === 2 && typeof(el[0]) === "number" && typeof(el[1]) === "number"} )) { | ||
@@ -50,0 +51,0 @@ this.faces.add(new Flatten.Face(this, argsArray)); // one-loop polygon as array of pairs of numbers |
@@ -441,2 +441,10 @@ /** | ||
}); | ||
it("issue #42 Intersect does not seem to work when a second is inside first", function() { | ||
const item1 = new Polygon([[0, 30], [30, 30], [30, 0], [0, 0]]); | ||
const item2 = new Polygon([[10, 20], [20, 20], [20, 10], [10, 10]]); | ||
const intersection = intersect(item1, item2); | ||
expect(intersection.faces.size).to.equal(1); | ||
expect(intersection.edges.size).to.equal(4); | ||
}) | ||
it("Issue #2 with intersection of circle and box", function() { | ||
@@ -443,0 +451,0 @@ "use strict" |
@@ -133,2 +133,36 @@ 'use strict'; | ||
}); | ||
describe('#Algorithms.Relation.Circle2Circle', function() { | ||
it ('Intersection case', () => { | ||
const c1 = circle(point(250, 150), 100); | ||
const c2 = circle(point(350, 150), 50); | ||
expect(intersect(c1, c2)).to.be.true; | ||
}); | ||
it ('Disjoint case', () => { | ||
const c1 = circle(point(250, 150), 100); | ||
const c2 = circle(point(450, 150), 50); | ||
expect(disjoint(c1, c2)).to.be.true; | ||
expect(intersect(c1, c2)).to.be.false; | ||
}); | ||
it ('Touching case', () => { | ||
const c1 = circle(point(250, 150), 100); | ||
const c2 = circle(point(400, 150), 50); | ||
expect(disjoint(c1, c2)).to.be.false; | ||
expect(intersect(c1, c2)).to.be.true; | ||
expect(touch(c1, c2)).to.be.true; | ||
}); | ||
it ('Contain case', () => { | ||
const c1 = circle(point(250, 150), 100); | ||
const c2 = circle(point(275, 150), 50); | ||
expect(disjoint(c1, c2)).to.be.false; | ||
expect(intersect(c1, c2)).to.be.true; | ||
expect(contain(c1, c2)).to.be.true; | ||
}); | ||
it ('Inside case', () => { | ||
const c1 = circle(point(250, 150), 100); | ||
const c2 = circle(point(275, 150), 50); | ||
expect(disjoint(c1, c2)).to.be.false; | ||
expect(intersect(c1, c2)).to.be.true; | ||
expect(inside(c2, c1)).to.be.true; | ||
}); | ||
}); | ||
describe('#Algorithms.Relation.Polygoon2Polygon', function() { | ||
@@ -135,0 +169,0 @@ it('May calculate relations. Disjoint case', () => { |
@@ -73,4 +73,4 @@ /** | ||
it('Can construct polygon from Circle in CCW orientation', function() { | ||
let polygon = new Polygon(); | ||
polygon.addFace(circle(point(3,3),50)); | ||
let polygon = new Polygon(circle(point(3,3),50)); | ||
// polygon.addFace(circle(point(3,3),50)); | ||
expect(polygon.faces.size).to.equal(1); | ||
@@ -81,4 +81,4 @@ expect(polygon.edges.size).to.equal(1); | ||
it('Can construct polygon from a box in CCW orientation', function() { | ||
let polygon = new Polygon(); | ||
polygon.addFace(box(30,40,100,200)); | ||
let polygon = new Polygon(box(30,40,100,200)); | ||
// polygon.addFace(box(30,40,100,200)); | ||
expect(polygon.faces.size).to.equal(1); | ||
@@ -85,0 +85,0 @@ expect(polygon.edges.size).to.equal(4); |
Sorry, the diff of this file is too big to display
Sorry, the diff of this file is too big to display
Sorry, the diff of this file is too big to display
Sorry, the diff of this file is not supported yet
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
Native code
Supply chain riskContains native code (e.g., compiled binaries or shared libraries). Including native code can obscure malicious behavior.
Found 1 instance in 1 package
5168188
32523
14
1