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

@flatten-js/core

Package Overview
Dependencies
Maintainers
1
Versions
82
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@flatten-js/core - npm Package Compare versions

Comparing version 1.2.0 to 1.2.1

docs/algorithms_ray_shooting.js.html

7

.jsdoc.json

@@ -11,3 +11,8 @@ {

"template": "./node_modules/minami"
},
"templates": {
"cleverLinks": false,
"monospaceLinks": true,
"sort": false
}
}
}

152

index.d.ts

@@ -64,3 +64,3 @@ // Type definitions for flatten-js library

type DE9IM_element = Array<Shape> | undefined;
/* Isn't possible to set length for tuple ? Really ? */
/* Impossible to set length for tuple ? Really ? */
type DE9IM_matrix = [

@@ -141,20 +141,20 @@ DE9IM_element,DE9IM_element,DE9IM_element,

// public methods
breakToFunctional(): Array<Arc>;
chordHeight(): number;
clone(): Arc;
contains(pt: Point): boolean;
split(pt: Point): [Arc | undefined, Arc | undefined];
middle(): Point;
chordHeight(): number;
intersect(shape: Shape): Array<Point>;
distanceTo(geom: Shape | PlanarSet): [number, Segment];
intersect(shape: Shape): Array<Point>;
middle(): Point;
reverse(): Arc;
rotate(angle: number, center: Point): Arc;
split(pt: Point): [Arc | undefined, Arc | undefined];
svg(attrs?: SVGAttributes): string;
breakToFunctional(): Array<Arc>;
tangentInEnd(): Vector;
tangentInStart(): Vector;
transform(matrix?: Matrix): Arc;
reverse(): Arc;
translate(vec: Vector): Arc;
translate(x:number, y:number): Arc;
rotate(angle: number, center: Point): Arc;
transform(matrix?: Matrix): Arc;
sortPoints(pts: Array<Point>): Array<Point>;
toJSON() : Object;
svg(attrs?: SVGAttributes): string;
}

@@ -178,10 +178,10 @@

// public methods
clone(): Interval;
equal_to(box: Interval): boolean;
intersect(box: Interval): boolean;
less_than(box: Interval): boolean;
clone(): Box;
not_intersect(box: Box): boolean;
intersect(box: Box): boolean;
merge(box: Box): Box;
not_intersect(box: Interval): boolean;
output() : void;
less_than(box: Box): boolean;
equal_to(box: Box): boolean;
set(xmin: number, ymin: number, xmax: number, ymax: number): void;
output() : Box;
svg(attrs?: SVGAttributes): string;

@@ -207,7 +207,7 @@

contains(shape: Shape): boolean;
toArc(counterclockwise?: boolean): Arc;
intersect(shape: Shape): Array<Point>;
distanceTo(geom: Shape | PlanarSet): [number, Segment];
intersect(shape: Shape): Array<Point>;
toJSON() : Object;
svg(attrs?: SVGAttributes): string;
toArc(counterclockwise?: boolean): Arc;
toJSON() : Object;
}

@@ -234,12 +234,12 @@

clone(): Line;
parallelTo(line: Line): boolean;
incidentTo(line: Line): boolean;
contains(pt: Point): boolean;
coord(pt: Point): number;
intersect(shape: Shape): Point[];
distanceTo(shape: Shape): [number, Segment];
incidentTo(line: Line): boolean;
intersect(shape: Shape): Point[];
parallelTo(line: Line): boolean;
coord(pt: Point): number;
split(pt: Point | Point[]): Edge[];
split(pt: Point | Point[]): Shape[];
sortPoints(points: Point[]): Point[];
toJSON() : Object;
svg(box: Box, attrs?: SVGAttributes): string;
toJSON() : Object;
}

@@ -261,22 +261,20 @@

clone(): Point;
distanceTo(geom: Shape | PlanarSet): [number, Segment];
equalTo(pt: Point): boolean;
leftTo(line: Line): boolean;
lessThan(pt: Point): boolean;
on(shape: Point | Shape): boolean;
projectionOn(line: Line): Point;
rotate(angle: number, center?: Point): Point;
svg(attrs?: SVGAttributes): string;
transform(matrix: Matrix): Point;
translate(vec: Vector): Point;
translate(x: number, y: number): Point;
projectionOn(line: Line): Point;
distanceTo(geom: Shape | PlanarSet): [number, Segment];
leftTo(line: Line): boolean;
on(shape: Point | Shape): boolean;
toJSON() : Object;
svg(attrs?: SVGAttributes): string;
}
class Ray {
norm: Vector;
// members
pt: Point;
readonly slope: number;
norm: Vector;

@@ -286,2 +284,3 @@ // getters

readonly box: Box;
readonly slope: number;

@@ -292,5 +291,6 @@ constructor(pt?: Point, norm?: Vector);

clone(): Ray;
contains(pt: Point): boolean;
split(pt: Point[]): Shape[];
intersect(shape: Segment | Arc): Point[];
svg(box: Box, attrs?: SVGAttributes): string;
}

@@ -315,18 +315,18 @@

clone(): Segment;
equalTo(seg: Segment): boolean;
contains(pt: Point): boolean;
intersect(shape: Shape): Point[];
distanceTo(shape: Shape): [number, Segment];
equalTo(seg: Segment): boolean;
intersect(shape: Shape): Point[];
isZeroLength(): boolean;
tangentInStart(): Vector;
tangentInEnd(): Vector;
reverse(): Segment;
split(pt: Point): [Segment|null,Segment|null];
middle(): Point;
reverse(): Segment;
rotate(angle: number, center?: Point): Segment;
split(pt: Point): [Segment|undefined,Segment|undefined];
tangentInStart(): Vector;
tangentInEnd(): Vector;
transform(matrix: Matrix): Segment;
translate(vec: Vector): Segment;
translate(x: number, y: number): Segment;
isZeroLength(): boolean;
toJSON() : Object;
svg(attrs?: SVGAttributes): string;
toJSON() : Object;
}

@@ -347,16 +347,16 @@

// public methods
add(v: Vector): Vector;
angleTo(v: Vector): number;
clone(): Vector;
cross(v: Vector): number;
dot(v: Vector): number;
equalTo(v: Vector): boolean;
invert(): Vector;
multiply(scalar: number): Vector;
dot(v: Vector): number;
cross(v: Vector): number;
normalize(): Vector;
projectionOn(v: Vector): Vector;
rotate(angle: number): Vector;
rotate90CCW(): Vector;
rotate90CW(): Vector;
invert(): Vector;
add(v: Vector): Vector;
subtract(v: Vector): Vector;
angleTo(v: Vector): number;
projectionOn(v: Vector): Vector;
toJSON() : Object;

@@ -416,3 +416,2 @@ }

enum EdgeRelationType {INSIDE, OUTSIDE, BOUNDARY}
enum RelationType {INSIDE, OUTSIDE, BOUNDARY, CONTAINS, INTERLACE}
const OVERLAP_SAME = 1;

@@ -467,9 +466,8 @@ const OVERLAP_OPPOSITE = 2;

remove(element: Edge): Face;
area(): number;
getRelation(polygon: Polygon): RelationType;
isSimple(edges: Edge[]): boolean;
orientation(): Flatten.ORIENTATION.PolygonOrientationType;
reverse(): void;
setArcLength(): void;
area(): number;
signedArea(): number;
orientation(): Flatten.ORIENTATION.PolygonOrientationType;
isSimple(edges: Edge[]): boolean;
findEdgeByPoint(pt: Point): Edge | undefined;

@@ -499,19 +497,21 @@ toPolygon(): Polygon;

// public methods
clone(): Polygon;
isEmpty(): boolean;
isValid(): boolean;
area(): number;
addFace(args: Array<Point> | Array<Segment | Arc> | Circle | Box): Face;
deleteFace(face: Face): boolean;
removeChain(face: Face, edgeFrom: Edge, edgeTo: Edge): void;
addVertex(edge: Edge, pt: Point): Edge;
area(): number;
clone(): Polygon;
cut(multiline: Multiline): Polygon[];
cutFace(pt1: Point, pt2: Point): [Polygon, Polygon];
findEdgeByPoint(pt: Point): Edge;
splitToIslands() : Polygon[];
reverse(): Polygon;
contains(shape: Shape): boolean;
deleteFace(face: Face): boolean;
distanceTo(shape: Shape): [number, Segment];
intersect(shape: Shape): Point[];
isValid(): boolean;
removeChain(face: Face, edgeFrom: Edge, edgeTo: Edge): void;
rotate(angle?: number, center?: Point): Polygon;
transform(matrix?: Matrix): Polygon;
translate(vec: Vector): Polygon;
splitToIslands() : Polygon[];
findEdgeByPoint(pt: Point): Edge;
cutFace(pt1: Point, pt2: Point): [Polygon, Polygon];
cut(multiline: Multiline): Polygon[];
toJSON() : Object;

@@ -530,13 +530,15 @@ toArray() : Polygon[];

clone(): Multiline;
addVertex(pt: Point, edge: Edge): Edge;
split(ip: Point[]) : Multiline;
findEdgeByPoint(pt: Point): Edge | undefined;
toShapes(): MultilineShapes;
rotate(angle?: number, center?: Point): Multiline;
transform(matrix?: Matrix): Multiline;
translate(vec: Vector): Multiline;
svg(attrs?: SVGAttributes, pathDefined? : boolean): string;
toShapes(): MultilineShapes;
toJSON() : Object;
svg(attrs?: SVGAttributes): string;
}
type Shape = Point | Line | Circle | Box | Segment | Arc | Polygon;
type Shape = Point | Line | Ray | Circle | Box | Segment | Arc | Polygon;

@@ -577,2 +579,22 @@ function point(x?: number, y?: number): Point;

declare namespace Flatten.BooleanOperations {
function unify(polygon1: Polygon, polygon2: Polygon): Polygon;
function subtract(polygon1: Polygon, polygon2: Polygon): Polygon;
function intersect(polygon1: Polygon, polygon2: Polygon): Polygon;
function innerClip(polygon1: Polygon, polygon2: Polygon): [Shape[], Shape[]];
function outerClip(polygon1: Polygon, polygon2: Polygon): Shape[];
function calculateIntersections(polygon1: Polygon, polygon2: Polygon): [Point[],Point[]];
}
declare namespace Flatten.Relations {
function relate(shape1: Shape, shape2: Shape): DE9IM_matrix;
function equal(shape1: Shape, shape2: Shape): boolean;
function intersect(shape1: Shape, shape2: Shape): boolean;
function touch(shape1: Shape, shape2: Shape): boolean;
function disjoint(shape1: Shape, shape2: Shape): boolean;
function inside(shape1: Shape, shape2: Shape): boolean;
function covered(shape1: Shape, shape2: Shape): boolean;
function cover(shape1: Shape, shape2: Shape): boolean;
}
export default Flatten;

@@ -8,2 +8,4 @@ /**

import * as Errors from "./src/utils/errors";
import * as BooleanOperations from './src/algorithms/boolean_op';
import * as Relations from './src/algorithms/relation';

@@ -25,9 +27,10 @@ export {Utils, Errors};

export {Multiline, multiline} from './src/classes/multiline';
export {Polygon} from './src/classes/polygon';
export {Polygon, polygon} from './src/classes/polygon';
export {Distance} from './src/algorithms/distance';
export {inverse} from './src/algorithms/inversion';
export {relate, disjoint, equal, touch, intersect} from './src/algorithms/relation';
export {BooleanOperations};
export {Relations};
export {CCW, CW, ORIENTATION, INSIDE, OUTSIDE, BOUNDARY, CONTAINS, INTERLACE, OVERLAP_SAME, OVERLAP_OPPOSITE} from './src/utils/constants';
export {CCW, CW, ORIENTATION, INSIDE, OUTSIDE, BOUNDARY} from './src/utils/constants';
export default Flatten;
{
"name": "@flatten-js/core",
"version": "1.2.0",
"version": "1.2.1",
"description": "Javascript library for 2d geometry",

@@ -5,0 +5,0 @@ "main": "dist/main.cjs.js",

@@ -7,3 +7,3 @@ [![npm version](https://badge.fury.io/js/%40flatten-js%2Fcore.svg)](https://badge.fury.io/js/%40flatten-js%2Fcore)

**flatten-js** is a javascript library for manipulating abstract geometrical shapes like point, vector, line, segment,
**flatten-js** is a javascript library for manipulating abstract geometrical shapes like point, vector, line, ray, segment,
circle, arc and polygon. Shapes may be organized into Planar Set - searchable container which support spatial queries.

@@ -51,3 +51,3 @@

```javascript
import {Point, Vector, Circle, Line, Segment, Arc, Box, Polygon, Matrix, PlanarSet} from '@flatten-js/core';
import {Point, Vector, Circle, Line, Ray, Segment, Arc, Box, Polygon, Matrix, PlanarSet} from '@flatten-js/core';
```

@@ -58,3 +58,3 @@

import Flatten from '@flatten-js/core'
const {Point, Vector, Circle, Line, Segment, Arc, Box, Polygon, Matrix, PlanarSet} = Flatten;
const {Point, Vector, Circle, Line, Ray, Segment, Arc, Box, Polygon, Matrix, PlanarSet} = Flatten;
```

@@ -64,3 +64,3 @@

```javascript
import {point, vector, circle, line, segment, arc, ray, matrix} from '@flatten-js/core';
import {point, vector, circle, line, ray, segment, arc, polygon, matrix} from '@flatten-js/core';
```

@@ -67,0 +67,0 @@

/**
* Created by Alex Bol on 12/02/2018.
*/
/**
* @module BooleanOp
*/
"use strict";

@@ -22,5 +25,5 @@ import Flatten from '../flatten';

* Point belongs to the resulted polygon if it belongs to the first OR to the second polygon
* @param {Flatten.Polygon} polygon1 - first operand
* @param {Flatten.Polygon} polygon2 - second operand
* @returns {Flatten.Polygon}
* @param {Polygon} polygon1 - first operand
* @param {Polygon} polygon2 - second operand
* @returns {Polygon}
*/

@@ -35,5 +38,5 @@ export function unify(polygon1, polygon2) {

* Point belongs to the resulted polygon if it belongs to the first polygon AND NOT to the second polygon
* @param {Flatten.Polygon} polygon1 - first operand
* @param {Flatten.Polygon} polygon2 - second operand
* @returns {Flatten.Polygon}
* @param {Polygon} polygon1 - first operand
* @param {Polygon} polygon2 - second operand
* @returns {Polygon}
*/

@@ -50,5 +53,5 @@ export function subtract(polygon1, polygon2) {

* Point belongs to the resultes polygon is it belongs to the first AND to the second polygon
* @param {Flatten.Polygon} polygon1 - first operand
* @param {Flatten.Polygon} polygon2 - second operand
* @returns {Flatten.Polygon}
* @param {Polygon} polygon1 - first operand
* @param {Polygon} polygon2 - second operand
* @returns {Polygon}
*/

@@ -60,3 +63,10 @@ export function intersect(polygon1, polygon2) {

export function inner_clip(polygon1, polygon2) {
/**
* Returns boundary of intersection between two polygons as two arrays of shapes (Segments/Arcs) <br/>
* The first array are shapes from the first polygon, the second array are shapes from the second
* @param {Polygon} polygon1 - first operand
* @param {Polygon} polygon2 - second operand
* @returns {Shape[][]}
*/
export function innerClip(polygon1, polygon2) {
let [res_poly, wrk_poly] = booleanOpBinary(polygon1, polygon2, BOOLEAN_INTERSECT, false);

@@ -79,3 +89,9 @@

export function outer_clip(polygon1, polygon2) {
/**
* Returns boundary of subtraction of the second polygon from first polygon as array of shapes
* @param {Polygon} polygon1 - first operand
* @param {Polygon} polygon2 - second operand
* @returns {Shape[]}
*/
export function outerClip(polygon1, polygon2) {
let [res_poly, wrk_poly] = booleanOpBinary(polygon1, polygon2, BOOLEAN_SUBTRACT, false);

@@ -93,3 +109,11 @@

export function calculateIntersections(polygon1, polygon2, op, restore) {
/**
* Returns intersection points between boundaries of two polygons as two array of points <br/>
* Points in the first array belong to first polygon, points from the second - to the second.
* Points in each array are ordered according to the direction of the correspondent polygon
* @param {Polygon} polygon1 - first operand
* @param {Polygon} polygon2 - second operand
* @returns {Point[][]}
*/
export function calculateIntersections(polygon1, polygon2) {
let res_poly = polygon1.clone();

@@ -96,0 +120,0 @@ let wrk_poly = polygon2.clone();

@@ -1,2 +0,4 @@

/**
* @module RayShoot
*/
"use strict";

@@ -6,3 +8,9 @@ import Flatten from '../flatten';

export const ray_shoot = function(polygon, point) {
/**
* Implements ray shooting algorithm. Returns relation between point and polygon: inside, outside or boundary
* @param {Polgon} polygon - polygon to test
* @param {Point} point - point to test
* @returns {Flatten.Inside|Flatten.OUTSIDE|Flatten.Boundary}
*/
export function ray_shoot(polygon, point) {
let contains = undefined;

@@ -9,0 +17,0 @@

@@ -5,2 +5,6 @@ /*

*/
/**
* @module Relation
*/
"use strict";

@@ -34,3 +38,3 @@

/**
* Returns true is shapes topologically equal: their interiors intersect and
* Returns true if shapes are topologically equal: their interiors intersect and
* no part of the interior or boundary of one geometry intersects the exterior of the other

@@ -42,8 +46,7 @@ * @param shape1

export function equal(shape1, shape2) {
let denim = relate(shape1, shape2);
return EQUAL.test(denim.toString());
return relate(shape1, shape2).equal();
}
/**
* Returns true is shapes have at least one point in common, same as "not disjoint"
* Returns true if shapes have at least one point in common, same as "not disjoint"
* @param shape1

@@ -54,4 +57,3 @@ * @param shape2

export function intersect(shape1, shape2) {
let denim = relate(shape1, shape2);
return INTERSECT.test(denim.toString());
return relate(shape1, shape2).intersect();
}

@@ -66,4 +68,3 @@

export function touch(shape1, shape2) {
let denim = relate(shape1, shape2);
return TOUCH.test(denim.toString());
return relate(shape1, shape2).touch();
}

@@ -88,4 +89,3 @@

export function inside(shape1, shape2) {
let denim = relate(shape1, shape2);
return INSIDE.test(denim.toString());
return relate(shape1, shape2).inside();
}

@@ -100,4 +100,3 @@

export function covered(shape1, shape2) {
let denim = relate(shape1, shape2);
return COVERED.test(denim.toString());
return relate(shape1, shape2).covered();
}

@@ -157,10 +156,3 @@

/**
* Return intersection between 2 lines as intersection matrix <br/>
* Note, the lines has no boundary so intersection between boundaries is irrelevant <br/>
* @param {Line} line1
* @param {Line} line2
* @returns {DE9IM}
*/
export function relateLine2Line(line1, line2) {
function relateLine2Line(line1, line2) {
let denim = new DE9IM();

@@ -187,14 +179,3 @@ let ip = intersectLine2Line(line1, line2);

/**
* Return intersection between lines and circle as intersection matrix <br/>
* Intersection between line interior abd circle boundary are one or two intersection points
* Intersection between line interior and circle interior is a line segment inside circle
* Intersection between line interior and circle exterior are two rays outside circle
* Intersection between line exterior and circle interior are two circle segments cut by lines
* Other relations are irrelevant
* @param {Line} line
* @param {Circle} circle
* @returns {DE9IM}
*/
export function relateLine2Circle(line,circle) {
function relateLine2Circle(line,circle) {
let denim = new DE9IM();

@@ -224,3 +205,3 @@ let ip = intersectLine2Circle(line, circle);

denim.E2I = polygon([circle.toArc()]).cut(multiline);
denim.E2I = new Flatten.Polygon([circle.toArc()]).cut(multiline);
}

@@ -231,14 +212,3 @@

/**
* Return intersection between lines and box as intersection matrix <br/>
* Intersection between line interior and box interior is a segment
* Intersection between line interior and box boundary may be one point, two points or segment
* Intersection between line interior and box exterior are two rays
* Intersection between line exterior and box interior are two polygons
* Other relations are irrelevant
* @param {Line} line
* @param {Box} box
* @returns {DE9IM}
*/
export function relateLine2Box(line, box) {
function relateLine2Box(line, box) {
let denim = new DE9IM();

@@ -277,3 +247,3 @@ let ip = intersectLine2Box(line, box);

denim.E2I = polygon(box.toSegments()).cut(multiline);
denim.E2I = new Flatten.Polygon(box.toSegments()).cut(multiline);
}

@@ -284,9 +254,3 @@ }

/**
* Relate line to polygon
* @param line
* @param polygon
* @returns {DE9IM}
*/
export function relateLine2Polygon(line, polygon) {
function relateLine2Polygon(line, polygon) {
let denim = new DE9IM();

@@ -310,8 +274,2 @@ let ip = intersectLine2Polygon(line, polygon);

/**
* Relate Segment or Arc to polygon
* @param {Shape} shape
* @param {Polygon} polygon
* @returns {DE9IM}
*/
function relateShape2Polygon(shape, polygon) {

@@ -354,8 +312,2 @@ let denim = new DE9IM();

/**
* Relate polygon to polygon
* @param polygon1
* @param polygon2
* @returns {DE9IM}
*/
function relatePolygon2Polygon(polygon1, polygon2) {

@@ -368,5 +320,5 @@ let denim = new DE9IM();

let boolean_difference2 = BooleanOp.subtract(polygon1, polygon2);
let [inner_clip_shapes1, inner_clip_shapes2] = BooleanOp.inner_clip(polygon1, polygon2);
let outer_clip_shapes1 = BooleanOp.outer_clip(polygon1, polygon2);
let outer_clip_shapes2 = BooleanOp.outer_clip(polygon2, polygon1);
let [inner_clip_shapes1, inner_clip_shapes2] = BooleanOp.innerClip(polygon1, polygon2);
let outer_clip_shapes1 = BooleanOp.outerClip(polygon1, polygon2);
let outer_clip_shapes2 = BooleanOp.outerClip(polygon2, polygon1);

@@ -373,0 +325,0 @@ denim.I2I = boolean_intersection.isEmpty() ? [] : [boolean_intersection];

@@ -74,3 +74,3 @@ /**

/**
* Return new instance of arc
* Return new cloned instance of arc
* @returns {Arc}

@@ -476,2 +476,11 @@ */

/**
* This method returns an object that defines how data will be
* serialized when called JSON.stringify() method
* @returns {Object}
*/
toJSON() {
return Object.assign({}, this, {name: "arc"});
}
/**
* Return string to draw arc in svg

@@ -501,10 +510,2 @@ * @param {Object} attrs - an object with attributes of svg path element,

/**
* This method returns an object that defines how data will be
* serialized when called JSON.stringify() method
* @returns {Object}
*/
toJSON() {
return Object.assign({}, this, {name: "arc"});
}
};

@@ -511,0 +512,0 @@

@@ -44,3 +44,3 @@ /**

/**
* Clones and returns new instance of box
* Return new cloned instance of box
* @returns {Box}

@@ -47,0 +47,0 @@ */

@@ -48,3 +48,3 @@ /**

/**
* Method clone returns new instance of a Circle
* Return new cloned instance of circle
* @returns {Circle}

@@ -197,2 +197,11 @@ */

/**
* This method returns an object that defines how data will be
* serialized when called JSON.stringify() method
* @returns {Object}
*/
toJSON() {
return Object.assign({}, this, {name: "circle"});
}
/**
* Return string to draw circle in svg

@@ -213,10 +222,2 @@ * @param {Object} attrs - an object with attributes of svg circle element,

/**
* This method returns an object that defines how data will be
* serialized when called JSON.stringify() method
* @returns {Object}
*/
toJSON() {
return Object.assign({}, this, {name: "circle"});
}
};

@@ -223,0 +224,0 @@

@@ -22,2 +22,3 @@ /**

* Shape of the edge: Segment or Arc
* @type {Segment|Arc}
*/

@@ -27,2 +28,3 @@ this.shape = shape;

* Pointer to the next edge in the face
* @type {Edge}
*/

@@ -32,2 +34,3 @@ this.next = undefined;

* Pointer to the previous edge in the face
* @type {Edge}
*/

@@ -47,3 +50,3 @@ this.prev = undefined;

* Start inclusion flag (inside/outside/boundary)
* @type {Boolean}
* @type {*}
*/

@@ -53,3 +56,3 @@ this.bvStart = undefined;

* End inclusion flag (inside/outside/boundary)
* @type {Boolean}
* @type {*}
*/

@@ -56,0 +59,0 @@ this.bvEnd = undefined;

@@ -187,3 +187,3 @@ /**

/**
* Append given edge after the last edge (and before the first edge). <br/>
* Append edge after the last edge of the face (and before the first edge). <br/>
* @param {Edge} edge - Edge to be appended to the linked list

@@ -217,3 +217,2 @@ * @returns {Face}

* Remove the given edge from the linked list of the face <br/>
* @param {PlanarSet} edges - Container of edges
* @param {Edge} edge - Edge to be removed

@@ -231,3 +230,4 @@ * @returns {Face}

* Reverse orientation of the face: first edge become last and vice a verse,
* all edges starts and ends swapped, direction of arcs inverted.
* all edges starts and ends swapped, direction of arcs inverted. If face was oriented
* clockwise, it becomes counter clockwise and vice versa
*/

@@ -348,5 +348,4 @@ reverse() {

* Returns true if face of the polygon is simple (no self-intersection points found)
* NOTE: this method is incomplete because it does not exclude touching points
* Real self intersection inverts orientation of the polygon.
* But this is also good enough for the demonstration of the idea
* NOTE: this method is incomplete because it does not exclude touching points.
* Self intersection test should check if polygon change orientation in the test point.
* @param {Edges} edges - reference to polygon.edges to provide search index

@@ -416,3 +415,3 @@ * @returns {boolean}

* Returns edge which contains given point
* @param {Point} pt
* @param {Point} pt - test point
* @returns {Edge}

@@ -432,23 +431,4 @@ */

/**
* Return chain edges between edgeFrom and edgeTo
* @param {Edge} edgeFrom
* @param {Edge} edgeTo
* @returns {Edge[]}
*/
getChainEdges(edgeFrom, edgeTo) {
let edges = [];
if (edgeTo.next === edgeFrom) { // Special case: return all face edges
edges = this.edges;
}
else {
for (let edge = edgeFrom; edge !== edgeTo.next; edge = edge.next) {
edges.push(edge);
}
}
return edges;
}
/**
* Returns new polygon created from one face
* @returns {Flatten.Polygon}
* @returns {Polygon}
*/

@@ -455,0 +435,0 @@ toPolygon() {

@@ -90,3 +90,3 @@ /**

/**
* Returns cloned new instance of a line
* Return new cloned instance of line
* @returns {Line}

@@ -133,3 +133,2 @@ */

*/
get middle() {return undefined}

@@ -196,3 +195,3 @@

* This method assumes that point lays on the line and does not check it
* @param pt
* @param {Point} pt - point on line
* @returns {number}

@@ -296,3 +295,3 @@ */

* The method assumes that points lay on the line and does not check this
* @param {Point[]} array of points
* @param {Point[]} pts - array of points
* @returns {Point[]} new array sorted

@@ -313,2 +312,11 @@ */

/**
* This method returns an object that defines how data will be
* serialized when called JSON.stringify() method
* @returns {Object}
*/
toJSON() {
return Object.assign({}, this, {name: "line"});
}
/**
* Return string to draw svg segment representing line inside given box

@@ -329,11 +337,2 @@ * @param {Box} box Box representing drawing area

/**
* This method returns an object that defines how data will be
* serialized when called JSON.stringify() method
* @returns {Object}
*/
toJSON() {
return Object.assign({}, this, {name: "line"});
}
static points2norm(pt1, pt2) {

@@ -340,0 +339,0 @@ if (pt1.equalTo(pt2)) {

@@ -35,3 +35,3 @@ "use strict";

/**
* Returns a clone of the Matrix instance.
* Return new cloned instance of matrix
* @return {Matrix}

@@ -103,3 +103,3 @@ **/

* point (0,0) in counter clockwise direction
* @param angle
* @param {number} angle - angle in radians
* @returns {Matrix}

@@ -116,4 +116,4 @@ */

* by the matrix (sx,0,0,sy,0,0) that defines scaling
* @param sx
* @param sy
* @param {number} sx
* @param {number} sy
* @returns {Matrix}

@@ -120,0 +120,0 @@ */

@@ -69,5 +69,13 @@ "use strict";

/**
* Return new cloned instance of Multiline
* @returns {Multiline}
*/
clone() {
return new Multiline(this.toShapes());
}
/**
* Split edge and add new vertex, return new edge inserted
* @param pt
* @param edge
* @param {Point} pt - point on edge that will be added as new vertex
* @param {Edge} edge - edge to split
* @returns {Edge}

@@ -99,3 +107,3 @@ */

* Split edges of multiline with intersection points and return mutated multiline
* @param ip
* @param {Point[]} ip - array of points to be added as new vertices
* @returns {Multiline}

@@ -102,0 +110,0 @@ */

@@ -71,3 +71,3 @@ /**

/**
* Method clone returns new copied instance of point
* Return new cloned instance of point
* @returns {Point}

@@ -256,2 +256,11 @@ */

/**
* This method returns an object that defines how data will be
* serialized when called JSON.stringify() method
* @returns {Object}
*/
toJSON() {
return Object.assign({}, this, {name: "point"});
}
/**
* Return string to draw point in svg as circle with radius "r" <br/>

@@ -277,10 +286,2 @@ * Accept any valid attributes of svg elements as svg object

/**
* This method returns an object that defines how data will be
* serialized when called JSON.stringify() method
* @returns {Object}
*/
toJSON() {
return Object.assign({}, this, {name: "point"});
}
};

@@ -287,0 +288,0 @@

@@ -80,2 +80,14 @@ /**

/**
* Create new cloned instance of the polygon
* @returns {Polygon}
*/
clone() {
let polygon = new Polygon();
for (let face of this.faces) {
polygon.addFace(face.shapes);
}
return polygon;
}
/**
* Return true is polygon has no edges

@@ -89,2 +101,33 @@ * @returns {boolean}

/**
* Return true if polygon is valid for boolean operations
* Polygon is valid if <br/>
* 1. All faces are simple polygons (there are no self-intersected polygons) <br/>
* 2. All faces are orientable and there is no island inside island or hole inside hole - TODO <br/>
* 3. There is no intersections between faces (excluding touching) - TODO <br/>
* @returns {boolean}
*/
isValid() {
let valid = true;
// 1. Polygon is invalid if at least one face is not simple
for (let face of this.faces) {
if (!face.isSimple(this.edges)) {
valid = false;
break;
}
}
// 2. TODO: check if no island inside island and no hole inside hole
// 3. TODO: check the there is no intersection between faces
return valid;
}
/**
* Returns area of the polygon. Area of an island will be added, area of a hole will be subtracted
* @returns {number}
*/
area() {
let signedArea = [...this.faces].reduce((acc, face) => acc + face.signedArea(), 0);
return Math.abs(signedArea);
}
/**
* Add new face to polygon. Returns added face

@@ -277,31 +320,43 @@ * @param {Points[]|Segments[]|Arcs[]|Circle|Box} args - new face may be create with one of the following ways: <br/>

reverse() {
for (let face of this.faces) {
face.reverse();
/**
* Split polygon into array of polygons, where each polygon is an island with all
* hole that it contains
* @returns {Flatten.Polygon[]}
*/
splitToIslands() {
let polygons = this.toArray(); // split into array of one-loop polygons
/* Sort polygons by area in descending order */
polygons.sort( (polygon1, polygon2) => polygon2.area() - polygon1.area() );
/* define orientation of the island by orientation of the first polygon in array */
let orientation = [...polygons[0].faces][0].orientation();
/* Create output array from polygons with same orientation as a first polygon (array of islands) */
let newPolygons = polygons.filter( polygon => [...polygon.faces][0].orientation() === orientation);
for (let polygon of polygons) {
let face = [...polygon.faces][0];
if (face.orientation() === orientation) continue; // skip same orientation
/* Proceed with opposite orientation */
/* Look if any of island polygons contains tested polygon as a hole */
for (let islandPolygon of newPolygons) {
if (face.shapes.every(shape => islandPolygon.contains(shape))) {
islandPolygon.addFace(face.shapes); // add polygon as a hole in islandPolygon
break;
}
}
}
return this;
// TODO: assert if not all polygons added into output
return newPolygons;
}
/**
* Create new copied instance of the polygon
* Reverse orientation of all faces to opposite
* @returns {Polygon}
*/
clone() {
let polygon = new Polygon();
reverse() {
for (let face of this.faces) {
polygon.addFace(face.shapes);
face.reverse();
}
return polygon;
return this;
}
/**
* Returns area of the polygon. Area of an island will be added, area of a hole will be subtracted
* @returns {number}
*/
area() {
let signedArea = [...this.faces].reduce((acc, face) => acc + face.signedArea(), 0);
return Math.abs(signedArea);
}
/**
* Returns true if polygon contains shape: no point of shape lies outside of the polygon,

@@ -399,24 +454,2 @@ * false otherwise

/**
* Return true if polygon is valid for boolean operations
* Polygon is valid if <br/>
* 1. All faces are simple polygons (there are no self-intersected polygons) <br/>
* 2. All faces are orientable and there is no island inside island or hole inside hole - TODO <br/>
* 3. There is no intersections between faces (excluding touching) - TODO <br/>
* @returns {boolean}
*/
isValid() {
let valid = true;
// 1. Polygon is invalid if at least one face is not simple
for (let face of this.faces) {
if (!face.isSimple(this.edges)) {
valid = false;
break;
}
}
// 2. TODO: check if no island inside island and no hole inside hole
// 3. TODO: check the there is no intersection between faces
return valid;
}
/**
* Returns new polygon translated by vector vec

@@ -464,2 +497,19 @@ * @param {Vector} vec

/**
* This method returns an object that defines how data will be
* serialized when called JSON.stringify() method
* @returns {Object}
*/
toJSON() {
return [...this.faces].map(face => face.toJSON());
}
/**
* Transform all faces into array of polygons
* @returns {Flatten.Polygon[]}
*/
toArray() {
return [...this.faces].map(face => face.toPolygon());
}
/**
* Return string to draw polygon in svg

@@ -484,49 +534,2 @@ * @param attrs - an object with attributes for svg path element,

}
/**
* This method returns an object that defines how data will be
* serialized when called JSON.stringify() method
* @returns {Object}
*/
toJSON() {
return [...this.faces].map(face => face.toJSON());
}
/**
* Return array of
* @returns {Flatten.Polygon[]}
*/
toArray() {
return [...this.faces].map(face => face.toPolygon());
}
/**
* Split polygon into array of polygons, where each polygon is an island with all
* hole that it contains
* @returns {Flatten.Polygon[]}
*/
splitToIslands() {
let polygons = this.toArray(); // split into array of one-loop polygons
/* Sort polygons by area in descending order */
polygons.sort( (polygon1, polygon2) => polygon2.area() - polygon1.area() );
/* define orientation of the island by orientation of the first polygon in array */
let orientation = [...polygons[0].faces][0].orientation();
/* Create output array from polygons with same orientation as a first polygon (array of islands) */
let newPolygons = polygons.filter( polygon => [...polygon.faces][0].orientation() === orientation);
for (let polygon of polygons) {
let face = [...polygon.faces][0];
if (face.orientation() === orientation) continue; // skip same orientation
/* Proceed with opposite orientation */
/* Look if any of island polygons contains tested polygon as a hole */
for (let islandPolygon of newPolygons) {
if (face.shapes.every(shape => islandPolygon.contains(shape))) {
islandPolygon.addFace(face.shapes); // add polygon as a hole in islandPolygon
break;
}
}
}
// TODO: assert if not all polygons added into output
return newPolygons;
}
}

@@ -533,0 +536,0 @@

@@ -49,3 +49,3 @@ "use strict";

/**
* Returns copied instance of the ray object
* Return new cloned instance of ray
* @returns {Ray}

@@ -117,3 +117,3 @@ */

* Split ray with point and return array of segment and new ray
* @param pt
* @param {Point} pt
* @returns [Segment,Ray]

@@ -120,0 +120,0 @@ */

@@ -66,3 +66,3 @@ /**

/**
* Method clone copies segment and returns a new instance
* Return new cloned instance of segment
* @returns {Segment}

@@ -343,2 +343,11 @@ */

/**
* This method returns an object that defines how data will be
* serialized when called JSON.stringify() method
* @returns {Object}
*/
toJSON() {
return Object.assign({}, this, {name: "segment"});
}
/**
* Return string to draw segment in svg

@@ -360,10 +369,2 @@ * @param {Object} attrs - an object with attributes for svg path element,

/**
* This method returns an object that defines how data will be
* serialized when called JSON.stringify() method
* @returns {Object}
*/
toJSON() {
return Object.assign({}, this, {name: "segment"});
}
};

@@ -370,0 +371,0 @@

import LinkedList from './linked_list';
/**
* Class implements circular bidirectional linked list
* Class implements circular bidirectional linked list <br/>
* LinkedListElement - object of any type that has properties next and prev.
*/

@@ -32,3 +33,3 @@ class CircularLinkedList extends LinkedList {

* Append new element to the end of the list
* @param element
* @param {LinkedListElement} element - new element to be appended
* @returns {CircularLinkedList}

@@ -44,4 +45,4 @@ */

* Insert new element to the list after elementBefore
* @param newElement
* @param elementBefore
* @param {LinkedListElement} newElement - new element to be inserted
* @param {LinkedListElement} elementBefore - element in the list to insert after it
* @returns {CircularLinkedList}

@@ -57,3 +58,3 @@ */

* Remove element from the list
* @param element
* @param {LinkedListElement} element - element to be removed from the list
* @returns {CircularLinkedList}

@@ -60,0 +61,0 @@ */

@@ -5,2 +5,9 @@ /*

*/
// const DISJOINT = RegExp('FF.FF....');
const EQUAL = RegExp('T.F..FFF.|T.F...F..');
const INTERSECT = RegExp('T........|.T.......|...T.....|....T....');
const TOUCH = RegExp('FT.......|F..T.....|F...T....');
const INSIDE = RegExp('T.F..F...');
const COVERED = RegExp('T.F..F...|.TF..F...|..FT.F...|..F.TF...');
class DE9IM {

@@ -183,4 +190,24 @@ /**

}
equal() {
return EQUAL.test(this.toString());
}
intersect() {
return INTERSECT.test(this.toString());
}
touch() {
return TOUCH.test(this.toString());
}
inside() {
return INSIDE.test(this.toString());
}
covered() {
return COVERED.test(this.toString());
}
}
export default DE9IM;
/**
* Class implements bidirectional non-circular linked list
* Class implements bidirectional non-circular linked list. <br/>
* LinkedListElement - object of any type that has properties next and prev.
*/

@@ -52,3 +53,3 @@ class LinkedList {

* Append new element to the end of the list
* @param element
* @param {LinkedListElement} element
* @returns {LinkedList}

@@ -75,4 +76,4 @@ */

* Insert new element to the list after elementBefore
* @param newElement
* @param elementBefore
* @param {LinkedListElement} newElement
* @param {LinkedListElement} elementBefore
* @returns {LinkedList}

@@ -112,3 +113,3 @@ */

* Remove element from the list
* @param element
* @param {LinkedListElement} element
* @returns {LinkedList}

@@ -115,0 +116,0 @@ */

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

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

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