diff --git a/dist/main.cjs b/dist/main.cjs index 871afe1e..85dce761 100644 --- a/dist/main.cjs +++ b/dist/main.cjs @@ -3983,28 +3983,35 @@ class PlanarSet extends Set { * This happens with no error, it is possible to use size property to check if * a shape was actually added.
* Method returns planar set object updated and may be chained - * @param {Shape} shape - shape to be added, should have valid box property + * @param {AnyShape | {Box, AnyShape}} entry - shape to be added, should have valid box property + * Another option to transfer as an object {key: Box, value: AnyShape} * @returns {PlanarSet} */ - add(shape) { + add(entry) { let size = this.size; + const {key, value} = entry; + const box = key || entry.box; + const shape = value || entry; super.add(shape); // size not changed - item not added, probably trying to add same item twice if (this.size > size) { - this.index.insert(shape.box, shape); + this.index.insert(box, shape); } return this; // in accordance to Set.add interface } /** * Delete shape from planar set. Returns true if shape was actually deleted, false otherwise - * @param {Shape} shape - shape to be deleted + * @param {AnyShape | {Box, AnyShape}} entry - shape to be deleted * @returns {boolean} */ - delete(shape) { + delete(entry) { + const {key, value} = entry; + const box = key || entry.box; + const shape = value || entry; let deleted = super.delete(shape); if (deleted) { - this.index.remove(shape.box, shape); + this.index.remove(box, shape); } return deleted; } @@ -4021,7 +4028,7 @@ class PlanarSet extends Set { * 2d range search in planar set.
* Returns array of all shapes in planar set which bounding box is intersected with query box * @param {Box} box - query box - * @returns {Shapes[]} + * @returns {AnyShape[]} */ search(box) { let resp = this.index.search(box); @@ -4031,7 +4038,7 @@ class PlanarSet extends Set { /** * Point location test. Returns array of shapes which contains given point * @param {Point} point - query point - * @returns {Array} + * @returns {AnyShape[]} */ hit(point) { let box = new Flatten.Box(point.x - 1, point.y - 1, point.x + 1, point.y + 1); @@ -4302,7 +4309,7 @@ let Point$1 = class Point extends Shape { /** * Returns true if point is on a shape, false otherwise - * @param {Shape} shape Shape of the one of supported types Point, Line, Circle, Segment, Arc, Polygon + * @param {Shape} shape * @returns {boolean} */ on(shape) { @@ -4310,6 +4317,10 @@ let Point$1 = class Point extends Shape { return this.equalTo(shape); } + if (shape instanceof Flatten.Box) { + return shape.contains(this); + } + if (shape instanceof Flatten.Line) { return shape.contains(this); } @@ -6330,6 +6341,46 @@ class Box extends Shape { (new_box, pt) => new_box.merge(pt.box), new Box()) } + /** + * Return true if box contains shape: no point of shape lies outside the box + * @param {AnyShape} shape - test shape + * @returns {boolean} + */ + contains(shape) { + if (shape instanceof Flatten.Point) { + return (shape.x >= this.xmin) && (shape.x <= this.xmax) && (shape.y >= this.ymin) && (shape.y <= this.ymax); + } + + if (shape instanceof Flatten.Segment) { + return shape.vertices.every(vertex => this.contains(vertex)) + } + + if (shape instanceof Flatten.Box) { + return shape.toSegments().every(segment => this.contains(segment)) + } + + if (shape instanceof Flatten.Circle) { + return this.contains(shape.box) + } + + if (shape instanceof Flatten.Arc) { + return shape.vertices.every(vertex => this.contains(vertex)) && + shape.toSegments().every(segment => intersectSegment2Arc(segment, shape).length === 0) + } + + if (shape instanceof Flatten.Line || shape instanceof Flatten.Ray) { + return false + } + + if (shape instanceof Flatten.Multiline) { + return shape.toShapes().every(shape => this.contains(shape)) + } + + if (shape instanceof Flatten.Polygon) { + return this.contains(shape.box) + } + } + get name() { return "box" } diff --git a/dist/main.mjs b/dist/main.mjs index ea2f5ecf..445c38cf 100644 --- a/dist/main.mjs +++ b/dist/main.mjs @@ -3979,28 +3979,35 @@ class PlanarSet extends Set { * This happens with no error, it is possible to use size property to check if * a shape was actually added.
* Method returns planar set object updated and may be chained - * @param {Shape} shape - shape to be added, should have valid box property + * @param {AnyShape | {Box, AnyShape}} entry - shape to be added, should have valid box property + * Another option to transfer as an object {key: Box, value: AnyShape} * @returns {PlanarSet} */ - add(shape) { + add(entry) { let size = this.size; + const {key, value} = entry; + const box = key || entry.box; + const shape = value || entry; super.add(shape); // size not changed - item not added, probably trying to add same item twice if (this.size > size) { - this.index.insert(shape.box, shape); + this.index.insert(box, shape); } return this; // in accordance to Set.add interface } /** * Delete shape from planar set. Returns true if shape was actually deleted, false otherwise - * @param {Shape} shape - shape to be deleted + * @param {AnyShape | {Box, AnyShape}} entry - shape to be deleted * @returns {boolean} */ - delete(shape) { + delete(entry) { + const {key, value} = entry; + const box = key || entry.box; + const shape = value || entry; let deleted = super.delete(shape); if (deleted) { - this.index.remove(shape.box, shape); + this.index.remove(box, shape); } return deleted; } @@ -4017,7 +4024,7 @@ class PlanarSet extends Set { * 2d range search in planar set.
* Returns array of all shapes in planar set which bounding box is intersected with query box * @param {Box} box - query box - * @returns {Shapes[]} + * @returns {AnyShape[]} */ search(box) { let resp = this.index.search(box); @@ -4027,7 +4034,7 @@ class PlanarSet extends Set { /** * Point location test. Returns array of shapes which contains given point * @param {Point} point - query point - * @returns {Array} + * @returns {AnyShape[]} */ hit(point) { let box = new Flatten.Box(point.x - 1, point.y - 1, point.x + 1, point.y + 1); @@ -4298,7 +4305,7 @@ let Point$1 = class Point extends Shape { /** * Returns true if point is on a shape, false otherwise - * @param {Shape} shape Shape of the one of supported types Point, Line, Circle, Segment, Arc, Polygon + * @param {Shape} shape * @returns {boolean} */ on(shape) { @@ -4306,6 +4313,10 @@ let Point$1 = class Point extends Shape { return this.equalTo(shape); } + if (shape instanceof Flatten.Box) { + return shape.contains(this); + } + if (shape instanceof Flatten.Line) { return shape.contains(this); } @@ -6326,6 +6337,46 @@ class Box extends Shape { (new_box, pt) => new_box.merge(pt.box), new Box()) } + /** + * Return true if box contains shape: no point of shape lies outside the box + * @param {AnyShape} shape - test shape + * @returns {boolean} + */ + contains(shape) { + if (shape instanceof Flatten.Point) { + return (shape.x >= this.xmin) && (shape.x <= this.xmax) && (shape.y >= this.ymin) && (shape.y <= this.ymax); + } + + if (shape instanceof Flatten.Segment) { + return shape.vertices.every(vertex => this.contains(vertex)) + } + + if (shape instanceof Flatten.Box) { + return shape.toSegments().every(segment => this.contains(segment)) + } + + if (shape instanceof Flatten.Circle) { + return this.contains(shape.box) + } + + if (shape instanceof Flatten.Arc) { + return shape.vertices.every(vertex => this.contains(vertex)) && + shape.toSegments().every(segment => intersectSegment2Arc(segment, shape).length === 0) + } + + if (shape instanceof Flatten.Line || shape instanceof Flatten.Ray) { + return false + } + + if (shape instanceof Flatten.Multiline) { + return shape.toShapes().every(shape => this.contains(shape)) + } + + if (shape instanceof Flatten.Polygon) { + return this.contains(shape.box) + } + } + get name() { return "box" } diff --git a/dist/main.umd.js b/dist/main.umd.js index 60aec7cf..412b61dd 100644 --- a/dist/main.umd.js +++ b/dist/main.umd.js @@ -3985,28 +3985,35 @@ * This happens with no error, it is possible to use size property to check if * a shape was actually added.
* Method returns planar set object updated and may be chained - * @param {Shape} shape - shape to be added, should have valid box property + * @param {AnyShape | {Box, AnyShape}} entry - shape to be added, should have valid box property + * Another option to transfer as an object {key: Box, value: AnyShape} * @returns {PlanarSet} */ - add(shape) { + add(entry) { let size = this.size; + const {key, value} = entry; + const box = key || entry.box; + const shape = value || entry; super.add(shape); // size not changed - item not added, probably trying to add same item twice if (this.size > size) { - this.index.insert(shape.box, shape); + this.index.insert(box, shape); } return this; // in accordance to Set.add interface } /** * Delete shape from planar set. Returns true if shape was actually deleted, false otherwise - * @param {Shape} shape - shape to be deleted + * @param {AnyShape | {Box, AnyShape}} entry - shape to be deleted * @returns {boolean} */ - delete(shape) { + delete(entry) { + const {key, value} = entry; + const box = key || entry.box; + const shape = value || entry; let deleted = super.delete(shape); if (deleted) { - this.index.remove(shape.box, shape); + this.index.remove(box, shape); } return deleted; } @@ -4023,7 +4030,7 @@ * 2d range search in planar set.
* Returns array of all shapes in planar set which bounding box is intersected with query box * @param {Box} box - query box - * @returns {Shapes[]} + * @returns {AnyShape[]} */ search(box) { let resp = this.index.search(box); @@ -4033,7 +4040,7 @@ /** * Point location test. Returns array of shapes which contains given point * @param {Point} point - query point - * @returns {Array} + * @returns {AnyShape[]} */ hit(point) { let box = new Flatten.Box(point.x - 1, point.y - 1, point.x + 1, point.y + 1); @@ -4304,7 +4311,7 @@ /** * Returns true if point is on a shape, false otherwise - * @param {Shape} shape Shape of the one of supported types Point, Line, Circle, Segment, Arc, Polygon + * @param {Shape} shape * @returns {boolean} */ on(shape) { @@ -4312,6 +4319,10 @@ return this.equalTo(shape); } + if (shape instanceof Flatten.Box) { + return shape.contains(this); + } + if (shape instanceof Flatten.Line) { return shape.contains(this); } @@ -6332,6 +6343,46 @@ (new_box, pt) => new_box.merge(pt.box), new Box()) } + /** + * Return true if box contains shape: no point of shape lies outside the box + * @param {AnyShape} shape - test shape + * @returns {boolean} + */ + contains(shape) { + if (shape instanceof Flatten.Point) { + return (shape.x >= this.xmin) && (shape.x <= this.xmax) && (shape.y >= this.ymin) && (shape.y <= this.ymax); + } + + if (shape instanceof Flatten.Segment) { + return shape.vertices.every(vertex => this.contains(vertex)) + } + + if (shape instanceof Flatten.Box) { + return shape.toSegments().every(segment => this.contains(segment)) + } + + if (shape instanceof Flatten.Circle) { + return this.contains(shape.box) + } + + if (shape instanceof Flatten.Arc) { + return shape.vertices.every(vertex => this.contains(vertex)) && + shape.toSegments().every(segment => intersectSegment2Arc(segment, shape).length === 0) + } + + if (shape instanceof Flatten.Line || shape instanceof Flatten.Ray) { + return false + } + + if (shape instanceof Flatten.Multiline) { + return shape.toShapes().every(shape => this.contains(shape)) + } + + if (shape instanceof Flatten.Polygon) { + return this.contains(shape.box) + } + } + get name() { return "box" } diff --git a/docs/Arc.html b/docs/Arc.html index 919cb82b..7b6c3514 100644 --- a/docs/Arc.html +++ b/docs/Arc.html @@ -24,7 +24,7 @@
@@ -3096,7 +3096,7 @@
Returns:

diff --git a/docs/Box.html b/docs/Box.html index 7ac75e2d..c9427128 100644 --- a/docs/Box.html +++ b/docs/Box.html @@ -24,7 +24,7 @@
@@ -100,7 +100,7 @@

new BoxSource:
@@ -332,7 +332,7 @@

boxSource:
@@ -396,7 +396,7 @@

centerSource:
@@ -460,7 +460,7 @@

heightSource:
@@ -524,7 +524,7 @@

highSource:
@@ -588,7 +588,7 @@

lowSource:
@@ -652,7 +652,7 @@

maxSource:
@@ -716,7 +716,7 @@

widthSource:
@@ -780,7 +780,7 @@

xmaxSource:
@@ -854,7 +854,7 @@

xminSource:
@@ -928,7 +928,7 @@

ymaxSource:
@@ -1002,7 +1002,7 @@

yminSource:
@@ -1086,7 +1086,7 @@

cloneSource:
@@ -1140,6 +1140,162 @@
Returns:
+

+ + +
+ + + +

contains(shape) → {boolean}

+ + + + + +
+ Return true if box contains shape: no point of shape lies outside the box +
+ + + + + +
+ + + + + + + + + + + + + + + + + + + + + + + + + + +
Source:
+
+ + + + + + + +
+ + + + + + + + + +
Parameters:
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
NameTypeDescription
shape + + +AnyShape + + + + + test shape + +
+ + + + + + + + + + + + + + +
+
Returns:
+ + + +
+
+ Type: +
+
+ +boolean + + +
+
+ + + +
+ + +
@@ -1190,7 +1346,7 @@

equal_toSource:
@@ -1346,7 +1502,7 @@

intersectSource:
@@ -1502,7 +1658,7 @@

less_thanSource:
@@ -1662,7 +1818,7 @@

mergeSource:
@@ -1818,7 +1974,7 @@

not_inte
Source:
@@ -1975,7 +2131,7 @@

rotateSource:
@@ -2168,7 +2324,7 @@

setSource:
@@ -2381,7 +2537,7 @@

svgSource:
@@ -2537,7 +2693,7 @@

toPointsSource:
@@ -2641,7 +2797,7 @@

toSegments<
Source:
@@ -2746,7 +2902,7 @@

transformSource:
@@ -2871,7 +3027,7 @@
Returns:

- Generated by JSDoc 3.6.11 on Fri Dec 08 2023 17:16:27 GMT+0200 (Israel Standard Time) using the Minami theme. + Generated by JSDoc 3.6.11 on Sat Dec 23 2023 10:36:58 GMT+0200 (Israel Standard Time) using the Minami theme.
diff --git a/docs/Circle.html b/docs/Circle.html index 64ef53ed..6a43af9c 100644 --- a/docs/Circle.html +++ b/docs/Circle.html @@ -24,7 +24,7 @@
@@ -1788,7 +1788,7 @@
Returns:

- Generated by JSDoc 3.6.11 on Fri Dec 08 2023 17:16:27 GMT+0200 (Israel Standard Time) using the Minami theme. + Generated by JSDoc 3.6.11 on Sat Dec 23 2023 10:36:58 GMT+0200 (Israel Standard Time) using the Minami theme.
diff --git a/docs/CircularLinkedList.html b/docs/CircularLinkedList.html index 4e6d02cb..d3ffeaa9 100644 --- a/docs/CircularLinkedList.html +++ b/docs/CircularLinkedList.html @@ -24,7 +24,7 @@
@@ -664,7 +664,7 @@
Returns:

- Generated by JSDoc 3.6.11 on Fri Dec 08 2023 17:16:27 GMT+0200 (Israel Standard Time) using the Minami theme. + Generated by JSDoc 3.6.11 on Sat Dec 23 2023 10:36:58 GMT+0200 (Israel Standard Time) using the Minami theme.
diff --git a/docs/DE9IM.html b/docs/DE9IM.html index 529aa9f5..dc20a311 100644 --- a/docs/DE9IM.html +++ b/docs/DE9IM.html @@ -24,7 +24,7 @@
@@ -1507,7 +1507,7 @@
Returns:

- Generated by JSDoc 3.6.11 on Fri Dec 08 2023 17:16:27 GMT+0200 (Israel Standard Time) using the Minami theme. + Generated by JSDoc 3.6.11 on Sat Dec 23 2023 10:36:58 GMT+0200 (Israel Standard Time) using the Minami theme.
diff --git a/docs/Edge.html b/docs/Edge.html index ec2a6815..7918238a 100644 --- a/docs/Edge.html +++ b/docs/Edge.html @@ -24,7 +24,7 @@
@@ -1819,7 +1819,7 @@
Parameters:

- Generated by JSDoc 3.6.11 on Fri Dec 08 2023 17:16:27 GMT+0200 (Israel Standard Time) using the Minami theme. + Generated by JSDoc 3.6.11 on Sat Dec 23 2023 10:36:58 GMT+0200 (Israel Standard Time) using the Minami theme.
diff --git a/docs/Errors.html b/docs/Errors.html index 90108bd5..c6bde709 100644 --- a/docs/Errors.html +++ b/docs/Errors.html @@ -24,7 +24,7 @@
@@ -426,7 +426,7 @@

(static)
- Generated by JSDoc 3.6.11 on Fri Dec 08 2023 17:16:27 GMT+0200 (Israel Standard Time) using the Minami theme. + Generated by JSDoc 3.6.11 on Sat Dec 23 2023 10:36:58 GMT+0200 (Israel Standard Time) using the Minami theme.
diff --git a/docs/Face.html b/docs/Face.html index 3aafa87b..bb2a1342 100644 --- a/docs/Face.html +++ b/docs/Face.html @@ -24,7 +24,7 @@
@@ -2343,7 +2343,7 @@
Returns:

- Generated by JSDoc 3.6.11 on Fri Dec 08 2023 17:16:27 GMT+0200 (Israel Standard Time) using the Minami theme. + Generated by JSDoc 3.6.11 on Sat Dec 23 2023 10:36:58 GMT+0200 (Israel Standard Time) using the Minami theme.
diff --git a/docs/Inversion.html b/docs/Inversion.html index 5236a32c..216d2b83 100644 --- a/docs/Inversion.html +++ b/docs/Inversion.html @@ -24,7 +24,7 @@
@@ -232,7 +232,7 @@

Classes


- Generated by JSDoc 3.6.11 on Fri Dec 08 2023 17:16:27 GMT+0200 (Israel Standard Time) using the Minami theme. + Generated by JSDoc 3.6.11 on Sat Dec 23 2023 10:36:58 GMT+0200 (Israel Standard Time) using the Minami theme.
diff --git a/docs/Line.html b/docs/Line.html index bc683c5b..24726c29 100644 --- a/docs/Line.html +++ b/docs/Line.html @@ -24,7 +24,7 @@
@@ -2629,7 +2629,7 @@
Returns:

- Generated by JSDoc 3.6.11 on Fri Dec 08 2023 17:16:27 GMT+0200 (Israel Standard Time) using the Minami theme. + Generated by JSDoc 3.6.11 on Sat Dec 23 2023 10:36:58 GMT+0200 (Israel Standard Time) using the Minami theme.
diff --git a/docs/LinkedList.html b/docs/LinkedList.html index 1b3935d8..3d7e479f 100644 --- a/docs/LinkedList.html +++ b/docs/LinkedList.html @@ -24,7 +24,7 @@
@@ -1094,7 +1094,7 @@
Returns:

- Generated by JSDoc 3.6.11 on Fri Dec 08 2023 17:16:27 GMT+0200 (Israel Standard Time) using the Minami theme. + Generated by JSDoc 3.6.11 on Sat Dec 23 2023 10:36:58 GMT+0200 (Israel Standard Time) using the Minami theme.
diff --git a/docs/Matrix.html b/docs/Matrix.html index de61c7d6..7ee25849 100644 --- a/docs/Matrix.html +++ b/docs/Matrix.html @@ -24,7 +24,7 @@
@@ -1613,7 +1613,7 @@
Returns:

- Generated by JSDoc 3.6.11 on Fri Dec 08 2023 17:16:27 GMT+0200 (Israel Standard Time) using the Minami theme. + Generated by JSDoc 3.6.11 on Sat Dec 23 2023 10:36:58 GMT+0200 (Israel Standard Time) using the Minami theme.
diff --git a/docs/Multiline.html b/docs/Multiline.html index 98308f18..aec92f0f 100644 --- a/docs/Multiline.html +++ b/docs/Multiline.html @@ -24,7 +24,7 @@
@@ -1849,7 +1849,7 @@
Returns:

- Generated by JSDoc 3.6.11 on Fri Dec 08 2023 17:16:27 GMT+0200 (Israel Standard Time) using the Minami theme. + Generated by JSDoc 3.6.11 on Sat Dec 23 2023 10:36:58 GMT+0200 (Israel Standard Time) using the Minami theme.
diff --git a/docs/PlanarSet.html b/docs/PlanarSet.html index d57361fa..50db8074 100644 --- a/docs/PlanarSet.html +++ b/docs/PlanarSet.html @@ -24,7 +24,7 @@
@@ -218,7 +218,7 @@

Methods

-

add(shape) → {PlanarSet}

+

add(entry) → {PlanarSet}

@@ -265,7 +265,7 @@

addSource:
@@ -309,13 +309,16 @@
Parameters:
- shape + entry -Shape +AnyShape +| + +Object @@ -327,6 +330,7 @@
Parameters:
shape to be added, should have valid box property +Another option to transfer as an object {key: Box, value: AnyShape} @@ -421,7 +425,7 @@

clearSource:
@@ -461,7 +465,7 @@

cleardelete(shape) → {boolean}

+

delete(entry) → {boolean}

@@ -504,7 +508,7 @@

deleteSource:
@@ -548,13 +552,16 @@
Parameters:
- shape + entry -Shape +AnyShape +| + +Object @@ -617,7 +624,7 @@
Returns:
-

hit(point) → {Array}

+

hit(point) → {Array.<AnyShape>}

@@ -660,7 +667,7 @@

hitSource:
@@ -754,7 +761,7 @@
Returns:
-Array +Array.<AnyShape>
@@ -773,7 +780,7 @@
Returns:
- + @@ -817,7 +824,7 @@