Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

@mathigon/euclid

Package Overview
Dependencies
Maintainers
0
Versions
50
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@mathigon/euclid - npm Package Compare versions

Comparing version 1.1.23 to 1.2.0

1

dist/index.d.ts

@@ -14,3 +14,2 @@ export * from './angle';

export * from './types';
export * from './boolean';
export { GeoElement, GeoShape, rad, SimplePoint, TransformMatrix, TWO_PI } from './utilities';

@@ -23,9 +23,4 @@ import { Circle } from './circle';

get oriented(): this;
/** Cut this polygon along a line, and return multiple parts. */
cut(line: Line, precision?: number): Polygon[];
/** Checks if two polygons p1 and p2 collide. */
static collision(p1: Polygon, p2: Polygon): boolean;
static union(polygons: Polygon[], precision?: number): Polygon[];
static intersection(polygons: Polygon[], precision?: number): Polygon[];
static difference(p1: Polygon, p2: Polygon, precision?: number): Polygon[];
/** Creates a regular polygon. */

@@ -32,0 +27,0 @@ static regular(n: number, radius?: number): Polygon;

@@ -34,3 +34,2 @@ import { Bounds } from './bounds';

offset(p: Point): number;
cut(line: Line): Polygon[];
get oriented(): Polygon;

@@ -37,0 +36,0 @@ transform(m: TransformMatrix): Polygon;

14

package.json
{
"name": "@mathigon/euclid",
"version": "1.1.23",
"version": "1.2.0",
"license": "MIT",

@@ -35,10 +35,10 @@ "homepage": "https://mathigon.io/euclid",

"dependencies": {
"@mathigon/core": "1.1.18",
"@mathigon/fermat": "1.1.18"
"@mathigon/core": "1.1.19",
"@mathigon/fermat": "1.1.20"
},
"devDependencies": {
"@types/tape": "5.6.4",
"@typescript-eslint/eslint-plugin": "7.13.1",
"@typescript-eslint/parser": "7.13.1",
"esbuild": "0.21.5",
"@typescript-eslint/eslint-plugin": "8.0.0",
"@typescript-eslint/parser": "8.0.0",
"esbuild": "0.23.0",
"eslint": "8.57.0",

@@ -49,4 +49,4 @@ "eslint-plugin-import": "2.29.1",

"tslib": "2.6.3",
"typescript": "5.5.2"
"typescript": "5.5.4"
}
}

@@ -20,3 +20,2 @@ // =============================================================================

export * from './types';
export * from './boolean';
export {GeoElement, GeoShape, rad, SimplePoint, TransformMatrix, TWO_PI} from './utilities';

@@ -9,3 +9,2 @@ // =============================================================================

import {nearlyEquals} from '@mathigon/fermat';
import {difference, intersect, union} from './boolean';
import {Circle} from './circle';

@@ -92,16 +91,2 @@ import {intersections} from './intersection';

/** Cut this polygon along a line, and return multiple parts. */
cut(line: Line, precision?: number) {
// This feels a bit hacky... can we find the bounding box of the Polygon?
const t = this.radius / line.length * 10;
const a = line.at(-t);
const b = line.at(t);
const d = line.perpendicularVector.scale(line.length * t);
const mask = [a, b, b.add(d), a.add(d)];
const side1 = intersect([this.points], [mask], precision);
const side2 = difference([this.points], [mask], precision);
return [...side1, ...side2].map(p => new Polygon(...p));
}
/** Checks if two polygons p1 and p2 collide. */

@@ -123,33 +108,2 @@ static collision(p1: Polygon, p2: Polygon) {

static union(polygons: Polygon[], precision?: number): Polygon[] {
const [first, ...other] = polygons;
if (!other.length) return [first];
const p1 = [first.points];
const p2 = other.length > 1 ? Polygon.union(other, precision).map(p => p.points) : [polygons[1].points];
return union(p1, p2, precision).map(p => new Polygon(...p));
}
static intersection(polygons: Polygon[], precision?: number): Polygon[] {
const [first, ...other] = polygons;
if (!other.length) return [first];
let intersection = [first.points];
for (const poly of other) {
const p1 = intersection;
const p2 = [poly.points];
intersection = intersect(p1, p2, precision);
if (!intersection.length) return [];
}
return intersection.map(p => new Polygon(...p));
}
static difference(p1: Polygon, p2: Polygon, precision?: number): Polygon[] {
const poly12 = difference([p1.points], [p2.points], precision);
const poly21 = difference([p2.points], [p1.points], precision);
return poly12.concat(poly21).map(p => new Polygon(...p));
}
/** Creates a regular polygon. */

@@ -156,0 +110,0 @@ static regular(n: number, radius = 1) {

@@ -121,6 +121,2 @@ // =============================================================================

cut(line: Line) {
return this.polygon.cut(line);
}
get oriented() {

@@ -127,0 +123,0 @@ return this.polygon.oriented;

@@ -12,4 +12,2 @@ // =============================================================================

const poly = (...p: number[][]) => new Polygon(...p.map(q => new Point(q[0], q[1])));
const line = (...p: number[][]) => new Line(new Point(p[0][0], p[0][1]), new Point(p[1][0], p[1][1]));
const points = (p: Polygon) => p.points.map(q => q.array);

@@ -38,19 +36,1 @@

});
tape('Cutting', (test) => {
const shape = poly([0, 0], [2, 0], [2, 1], [1, 1], [1, 2], [0, 2]);
const c1 = shape.cut(line([1, 0], [1, 1])).map(p => points(p));
test.deepEquals(c1, [[[2, 1], [2, 0], [1, 0], [1, 1]], [[1, 2], [1, 0], [0, 0], [0, 2]]]);
const c2 = shape.cut(line([-1, 1], [0, 1])).map(p => points(p));
test.deepEquals(c2, [[[2, 1], [2, 0], [0, 0], [0, 1]], [[1, 2], [1, 1], [0, 1], [0, 2]]]);
const c3 = shape.cut(line([0, 0], [1, 1])).map(p => points(p));
test.deepEquals(c3, [[[2, 1], [2, 0], [0, 0], [1, 1]], [[1, 2], [1, 1], [0, 0], [0, 2]]]);
const c4 = shape.cut(line([0, 2], [2, 0])).map(p => points(p));
test.deepEquals(c4, [[[2, 0], [0, 0], [0, 2]], [[0, 2], [1, 1], [1, 2]], [[1, 1], [2, 0], [2, 1]]]);
test.end();
});

Sorry, the diff of this file is too big to display

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is too big to display

Sorry, the diff of this file is not supported yet

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc