diff --git a/dist/main.cjs b/dist/main.cjs index c0b1a5db..871afe1e 100644 --- a/dist/main.cjs +++ b/dist/main.cjs @@ -152,10 +152,40 @@ var Utils$1 = /*#__PURE__*/Object.freeze({ setTolerance: setTolerance }); +let Flatten = { + Utils: Utils$1, + Errors: undefined, + Matrix: undefined, + Planar_set: undefined, + Point: undefined, + Vector: undefined, + Line: undefined, + Circle: undefined, + Segment: undefined, + Arc: undefined, + Box: undefined, + Edge: undefined, + Face: undefined, + Ray: undefined, + Ray_shooting: undefined, + Multiline: undefined, + Polygon: undefined, + Distance: undefined, + Inversion: undefined +}; + +for (let c in Constants) {Flatten[c] = Constants[c];} + +Object.defineProperty(Flatten, 'DP_TOL', { + get:function(){return getTolerance()}, + set:function(value){setTolerance(value);} +}); + /** * Created by Alex Bol on 2/19/2017. */ + /** * Class of system errors */ @@ -193,6 +223,10 @@ class Errors { return new Error('Infinite loop'); } + static get CANNOT_COMPLETE_BOOLEAN_OPERATION() { + return new Error('Cannot complete boolean operation') + } + static get CANNOT_INVOKE_ABSTRACT_METHOD() { return new Error('Abstract method cannot be invoked'); } @@ -202,39 +236,7 @@ class Errors { } } -var errors = /*#__PURE__*/Object.freeze({ - __proto__: null, - default: Errors -}); - -let Flatten = { - Utils: Utils$1, - Errors: Errors, - Matrix: undefined, - Planar_set: undefined, - Point: undefined, - Vector: undefined, - Line: undefined, - Circle: undefined, - Segment: undefined, - Arc: undefined, - Box: undefined, - Edge: undefined, - Face: undefined, - Ray: undefined, - Ray_shooting: undefined, - Multiline: undefined, - Polygon: undefined, - Distance: undefined, - Inversion: undefined -}; - -for (let c in Constants) {Flatten[c] = Constants[c];} - -Object.defineProperty(Flatten, 'DP_TOL', { - get:function(){return getTolerance()}, - set:function(value){setTolerance(value);} -}); +Flatten.Errors = Errors; /** * Class implements bidirectional non-circular linked list.
@@ -382,14 +384,14 @@ class LinkedList { /** * Throw an error if circular loop detected in the linked list * @param {LinkedListElement} first element to start iteration - * @throws {Flatten.Errors.INFINITE_LOOP} + * @throws {Errors.INFINITE_LOOP} */ static testInfiniteLoop(first) { let edge = first; let controlEdge = first; do { if (edge != first && edge === controlEdge) { - throw Flatten.Errors.INFINITE_LOOP; // new Error("Infinite loop") + throw Errors.INFINITE_LOOP; // new Error("Infinite loop") } edge = edge.next; controlEdge = controlEdge.next.next; @@ -1407,12 +1409,17 @@ function restoreFaces(polygon, int_points, other_int_points) let first = int_point.edge_after; // face start let last = int_point.edge_before; // face end; - LinkedList.testInfiniteLoop(first); // check and throw error if infinite loop found + try { + LinkedList.testInfiniteLoop(first); // check and throw error if infinite loop found + } + catch (error) { + throw Errors.CANNOT_COMPLETE_BOOLEAN_OPERATION + } let face = polygon.addFace(first, last); // Mark intersection points from the newly create face - // to avoid multiple creation of the same face + // to avoid multiple creation of the same face. // Face was assigned to each edge of new face in addFace function for (let int_point_tmp of int_points) { if (int_point_tmp.edge_before && int_point_tmp.edge_after && @@ -3060,7 +3067,7 @@ class Matrix { tx = args[0]; ty = args[1]; } else { - throw Flatten.Errors.ILLEGAL_PARAMETERS; + throw Errors.ILLEGAL_PARAMETERS; } return this.multiply(new Matrix(1, 0, 0, 1, tx, ty)) }; @@ -4050,23 +4057,22 @@ Flatten.PlanarSet = PlanarSet; */ class Shape { get name() { - throw(Flatten.Errors.CANNOT_INVOKE_ABSTRACT_METHOD); + throw(Errors.CANNOT_INVOKE_ABSTRACT_METHOD); } get box() { - throw(Flatten.Errors.CANNOT_INVOKE_ABSTRACT_METHOD); + throw(Errors.CANNOT_INVOKE_ABSTRACT_METHOD); } clone() { - throw(Flatten.Errors.CANNOT_INVOKE_ABSTRACT_METHOD); + throw(Errors.CANNOT_INVOKE_ABSTRACT_METHOD); } /** * Returns new shape translated by given vector. * Translation vector may be also defined by a pair of numbers. - * @param {Vector} vector - Translation vector or - * @param {number} tx - Translation by x-axis - * @param {number} ty - Translation by y-axis + * @param {Vector | (number, number) } args - Translation vector + * or tuple of numbers * @returns {Shape} */ translate(...args) { @@ -4097,7 +4103,7 @@ class Shape { } transform(...args) { - throw(Flatten.Errors.CANNOT_INVOKE_ABSTRACT_METHOD); + throw(Errors.CANNOT_INVOKE_ABSTRACT_METHOD); } /** @@ -4110,7 +4116,7 @@ class Shape { } svg(attrs = {}) { - throw(Flatten.Errors.CANNOT_INVOKE_ABSTRACT_METHOD); + throw(Errors.CANNOT_INVOKE_ABSTRACT_METHOD); } } @@ -4170,7 +4176,7 @@ let Point$1 = class Point extends Shape { return; } } - throw Flatten.Errors.ILLEGAL_PARAMETERS; + throw Errors.ILLEGAL_PARAMETERS; } /** @@ -4431,7 +4437,7 @@ let Vector$1 = class Vector extends Shape { } - throw Flatten.Errors.ILLEGAL_PARAMETERS; + throw Errors.ILLEGAL_PARAMETERS; } /** @@ -4508,7 +4514,7 @@ let Vector$1 = class Vector extends Shape { if (!Flatten.Utils.EQ_0(this.length)) { return (new Flatten.Vector(this.x / this.length, this.y / this.length)); } - throw Flatten.Errors.ZERO_DIVISION; + throw Errors.ZERO_DIVISION; } /** @@ -4523,7 +4529,7 @@ let Vector$1 = class Vector extends Shape { if (center.x === 0 && center.y === 0) { return this.transform(new Matrix().rotate(angle)); } - throw(Flatten.Errors.OPERATION_IS_NOT_SUPPORTED); + throw(Errors.OPERATION_IS_NOT_SUPPORTED); } /** @@ -4681,7 +4687,7 @@ class Segment extends Shape { return; } - throw Flatten.Errors.ILLEGAL_PARAMETERS; + throw Errors.ILLEGAL_PARAMETERS; } /** @@ -5037,7 +5043,7 @@ let Line$1 = class Line extends Shape { if (a1 instanceof Flatten.Point && a2 instanceof Flatten.Vector) { if (Flatten.Utils.EQ_0(a2.x) && Flatten.Utils.EQ_0(a2.y)) { - throw Flatten.Errors.ILLEGAL_PARAMETERS; + throw Errors.ILLEGAL_PARAMETERS; } this.pt = a1.clone(); this.norm = a2.clone(); @@ -5050,7 +5056,7 @@ let Line$1 = class Line extends Shape { if (a1 instanceof Flatten.Vector && a2 instanceof Flatten.Point) { if (Flatten.Utils.EQ_0(a1.x) && Flatten.Utils.EQ_0(a1.y)) { - throw Flatten.Errors.ILLEGAL_PARAMETERS; + throw Errors.ILLEGAL_PARAMETERS; } this.pt = a2.clone(); this.norm = a1.clone(); @@ -5062,7 +5068,7 @@ let Line$1 = class Line extends Shape { } } - throw Flatten.Errors.ILLEGAL_PARAMETERS; + throw Errors.ILLEGAL_PARAMETERS; } /** @@ -5332,7 +5338,7 @@ let Line$1 = class Line extends Shape { static points2norm(pt1, pt2) { if (pt1.equalTo(pt2)) { - throw Flatten.Errors.ILLEGAL_PARAMETERS; + throw Errors.ILLEGAL_PARAMETERS; } let vec = new Flatten.Vector(pt1, pt2); let unit = vec.normalize(); @@ -5390,7 +5396,7 @@ let Circle$1 = class Circle extends Shape { if (pc && pc instanceof Flatten.Point) this.pc = pc.clone(); if (r !== undefined) this.r = r; } - // throw Flatten.Errors.ILLEGAL_PARAMETERS; unreachable code + // throw Errors.ILLEGAL_PARAMETERS; unreachable code } /** @@ -5469,9 +5475,9 @@ let Circle$1 = class Circle extends Shape { */ scale(sx, sy) { if (sx !== sy) - throw Flatten.Errors.OPERATION_IS_NOT_SUPPORTED + throw Errors.OPERATION_IS_NOT_SUPPORTED if (!(this.pc.x === 0.0 && this.pc.y === 0.0)) - throw Flatten.Errors.OPERATION_IS_NOT_SUPPORTED + throw Errors.OPERATION_IS_NOT_SUPPORTED return new Flatten.Circle(this.pc, this.r*sx) } @@ -6309,7 +6315,7 @@ class Box extends Shape { * @param {Point} [center=(0,0)] center */ rotate(angle, center = new Flatten.Point()) { - throw Flatten.Errors.OPERATION_IS_NOT_SUPPORTED + throw Errors.OPERATION_IS_NOT_SUPPORTED } /** @@ -7176,7 +7182,7 @@ class Ray extends Shape { return; } - throw Flatten.Errors.ILLEGAL_PARAMETERS; + throw Errors.ILLEGAL_PARAMETERS; } /** @@ -8745,7 +8751,7 @@ exports.CW = CW; exports.Circle = Circle$1; exports.Distance = Distance; exports.Edge = Edge; -exports.Errors = errors; +exports.Errors = Errors; exports.Face = Face; exports.INSIDE = INSIDE$2; exports.Inversion = Inversion; diff --git a/dist/main.mjs b/dist/main.mjs index c7ed24cc..ea2f5ecf 100644 --- a/dist/main.mjs +++ b/dist/main.mjs @@ -148,10 +148,40 @@ var Utils$1 = /*#__PURE__*/Object.freeze({ setTolerance: setTolerance }); +let Flatten = { + Utils: Utils$1, + Errors: undefined, + Matrix: undefined, + Planar_set: undefined, + Point: undefined, + Vector: undefined, + Line: undefined, + Circle: undefined, + Segment: undefined, + Arc: undefined, + Box: undefined, + Edge: undefined, + Face: undefined, + Ray: undefined, + Ray_shooting: undefined, + Multiline: undefined, + Polygon: undefined, + Distance: undefined, + Inversion: undefined +}; + +for (let c in Constants) {Flatten[c] = Constants[c];} + +Object.defineProperty(Flatten, 'DP_TOL', { + get:function(){return getTolerance()}, + set:function(value){setTolerance(value);} +}); + /** * Created by Alex Bol on 2/19/2017. */ + /** * Class of system errors */ @@ -189,6 +219,10 @@ class Errors { return new Error('Infinite loop'); } + static get CANNOT_COMPLETE_BOOLEAN_OPERATION() { + return new Error('Cannot complete boolean operation') + } + static get CANNOT_INVOKE_ABSTRACT_METHOD() { return new Error('Abstract method cannot be invoked'); } @@ -198,39 +232,7 @@ class Errors { } } -var errors = /*#__PURE__*/Object.freeze({ - __proto__: null, - default: Errors -}); - -let Flatten = { - Utils: Utils$1, - Errors: Errors, - Matrix: undefined, - Planar_set: undefined, - Point: undefined, - Vector: undefined, - Line: undefined, - Circle: undefined, - Segment: undefined, - Arc: undefined, - Box: undefined, - Edge: undefined, - Face: undefined, - Ray: undefined, - Ray_shooting: undefined, - Multiline: undefined, - Polygon: undefined, - Distance: undefined, - Inversion: undefined -}; - -for (let c in Constants) {Flatten[c] = Constants[c];} - -Object.defineProperty(Flatten, 'DP_TOL', { - get:function(){return getTolerance()}, - set:function(value){setTolerance(value);} -}); +Flatten.Errors = Errors; /** * Class implements bidirectional non-circular linked list.
@@ -378,14 +380,14 @@ class LinkedList { /** * Throw an error if circular loop detected in the linked list * @param {LinkedListElement} first element to start iteration - * @throws {Flatten.Errors.INFINITE_LOOP} + * @throws {Errors.INFINITE_LOOP} */ static testInfiniteLoop(first) { let edge = first; let controlEdge = first; do { if (edge != first && edge === controlEdge) { - throw Flatten.Errors.INFINITE_LOOP; // new Error("Infinite loop") + throw Errors.INFINITE_LOOP; // new Error("Infinite loop") } edge = edge.next; controlEdge = controlEdge.next.next; @@ -1403,12 +1405,17 @@ function restoreFaces(polygon, int_points, other_int_points) let first = int_point.edge_after; // face start let last = int_point.edge_before; // face end; - LinkedList.testInfiniteLoop(first); // check and throw error if infinite loop found + try { + LinkedList.testInfiniteLoop(first); // check and throw error if infinite loop found + } + catch (error) { + throw Errors.CANNOT_COMPLETE_BOOLEAN_OPERATION + } let face = polygon.addFace(first, last); // Mark intersection points from the newly create face - // to avoid multiple creation of the same face + // to avoid multiple creation of the same face. // Face was assigned to each edge of new face in addFace function for (let int_point_tmp of int_points) { if (int_point_tmp.edge_before && int_point_tmp.edge_after && @@ -3056,7 +3063,7 @@ class Matrix { tx = args[0]; ty = args[1]; } else { - throw Flatten.Errors.ILLEGAL_PARAMETERS; + throw Errors.ILLEGAL_PARAMETERS; } return this.multiply(new Matrix(1, 0, 0, 1, tx, ty)) }; @@ -4046,23 +4053,22 @@ Flatten.PlanarSet = PlanarSet; */ class Shape { get name() { - throw(Flatten.Errors.CANNOT_INVOKE_ABSTRACT_METHOD); + throw(Errors.CANNOT_INVOKE_ABSTRACT_METHOD); } get box() { - throw(Flatten.Errors.CANNOT_INVOKE_ABSTRACT_METHOD); + throw(Errors.CANNOT_INVOKE_ABSTRACT_METHOD); } clone() { - throw(Flatten.Errors.CANNOT_INVOKE_ABSTRACT_METHOD); + throw(Errors.CANNOT_INVOKE_ABSTRACT_METHOD); } /** * Returns new shape translated by given vector. * Translation vector may be also defined by a pair of numbers. - * @param {Vector} vector - Translation vector or - * @param {number} tx - Translation by x-axis - * @param {number} ty - Translation by y-axis + * @param {Vector | (number, number) } args - Translation vector + * or tuple of numbers * @returns {Shape} */ translate(...args) { @@ -4093,7 +4099,7 @@ class Shape { } transform(...args) { - throw(Flatten.Errors.CANNOT_INVOKE_ABSTRACT_METHOD); + throw(Errors.CANNOT_INVOKE_ABSTRACT_METHOD); } /** @@ -4106,7 +4112,7 @@ class Shape { } svg(attrs = {}) { - throw(Flatten.Errors.CANNOT_INVOKE_ABSTRACT_METHOD); + throw(Errors.CANNOT_INVOKE_ABSTRACT_METHOD); } } @@ -4166,7 +4172,7 @@ let Point$1 = class Point extends Shape { return; } } - throw Flatten.Errors.ILLEGAL_PARAMETERS; + throw Errors.ILLEGAL_PARAMETERS; } /** @@ -4427,7 +4433,7 @@ let Vector$1 = class Vector extends Shape { } - throw Flatten.Errors.ILLEGAL_PARAMETERS; + throw Errors.ILLEGAL_PARAMETERS; } /** @@ -4504,7 +4510,7 @@ let Vector$1 = class Vector extends Shape { if (!Flatten.Utils.EQ_0(this.length)) { return (new Flatten.Vector(this.x / this.length, this.y / this.length)); } - throw Flatten.Errors.ZERO_DIVISION; + throw Errors.ZERO_DIVISION; } /** @@ -4519,7 +4525,7 @@ let Vector$1 = class Vector extends Shape { if (center.x === 0 && center.y === 0) { return this.transform(new Matrix().rotate(angle)); } - throw(Flatten.Errors.OPERATION_IS_NOT_SUPPORTED); + throw(Errors.OPERATION_IS_NOT_SUPPORTED); } /** @@ -4677,7 +4683,7 @@ class Segment extends Shape { return; } - throw Flatten.Errors.ILLEGAL_PARAMETERS; + throw Errors.ILLEGAL_PARAMETERS; } /** @@ -5033,7 +5039,7 @@ let Line$1 = class Line extends Shape { if (a1 instanceof Flatten.Point && a2 instanceof Flatten.Vector) { if (Flatten.Utils.EQ_0(a2.x) && Flatten.Utils.EQ_0(a2.y)) { - throw Flatten.Errors.ILLEGAL_PARAMETERS; + throw Errors.ILLEGAL_PARAMETERS; } this.pt = a1.clone(); this.norm = a2.clone(); @@ -5046,7 +5052,7 @@ let Line$1 = class Line extends Shape { if (a1 instanceof Flatten.Vector && a2 instanceof Flatten.Point) { if (Flatten.Utils.EQ_0(a1.x) && Flatten.Utils.EQ_0(a1.y)) { - throw Flatten.Errors.ILLEGAL_PARAMETERS; + throw Errors.ILLEGAL_PARAMETERS; } this.pt = a2.clone(); this.norm = a1.clone(); @@ -5058,7 +5064,7 @@ let Line$1 = class Line extends Shape { } } - throw Flatten.Errors.ILLEGAL_PARAMETERS; + throw Errors.ILLEGAL_PARAMETERS; } /** @@ -5328,7 +5334,7 @@ let Line$1 = class Line extends Shape { static points2norm(pt1, pt2) { if (pt1.equalTo(pt2)) { - throw Flatten.Errors.ILLEGAL_PARAMETERS; + throw Errors.ILLEGAL_PARAMETERS; } let vec = new Flatten.Vector(pt1, pt2); let unit = vec.normalize(); @@ -5386,7 +5392,7 @@ let Circle$1 = class Circle extends Shape { if (pc && pc instanceof Flatten.Point) this.pc = pc.clone(); if (r !== undefined) this.r = r; } - // throw Flatten.Errors.ILLEGAL_PARAMETERS; unreachable code + // throw Errors.ILLEGAL_PARAMETERS; unreachable code } /** @@ -5465,9 +5471,9 @@ let Circle$1 = class Circle extends Shape { */ scale(sx, sy) { if (sx !== sy) - throw Flatten.Errors.OPERATION_IS_NOT_SUPPORTED + throw Errors.OPERATION_IS_NOT_SUPPORTED if (!(this.pc.x === 0.0 && this.pc.y === 0.0)) - throw Flatten.Errors.OPERATION_IS_NOT_SUPPORTED + throw Errors.OPERATION_IS_NOT_SUPPORTED return new Flatten.Circle(this.pc, this.r*sx) } @@ -6305,7 +6311,7 @@ class Box extends Shape { * @param {Point} [center=(0,0)] center */ rotate(angle, center = new Flatten.Point()) { - throw Flatten.Errors.OPERATION_IS_NOT_SUPPORTED + throw Errors.OPERATION_IS_NOT_SUPPORTED } /** @@ -7172,7 +7178,7 @@ class Ray extends Shape { return; } - throw Flatten.Errors.ILLEGAL_PARAMETERS; + throw Errors.ILLEGAL_PARAMETERS; } /** @@ -8732,4 +8738,4 @@ Flatten.Distance = Distance; Flatten.BooleanOperations = BooleanOperations; Flatten.Relations = Relations; -export { Arc, BOUNDARY$1 as BOUNDARY, BooleanOperations, Box, CCW, CW, Circle$1 as Circle, Distance, Edge, errors as Errors, Face, INSIDE$2 as INSIDE, Inversion, Line$1 as Line, Matrix, Multiline, ORIENTATION, OUTSIDE$1 as OUTSIDE, PlanarSet, Point$1 as Point, Polygon, Ray, Relations, Segment, smart_intersections as SmartIntersections, Utils$1 as Utils, Vector$1 as Vector, arc, box, circle, Flatten as default, inversion, line, matrix, multiline, point, polygon, ray, ray_shoot, segment, vector$1 as vector }; +export { Arc, BOUNDARY$1 as BOUNDARY, BooleanOperations, Box, CCW, CW, Circle$1 as Circle, Distance, Edge, Errors, Face, INSIDE$2 as INSIDE, Inversion, Line$1 as Line, Matrix, Multiline, ORIENTATION, OUTSIDE$1 as OUTSIDE, PlanarSet, Point$1 as Point, Polygon, Ray, Relations, Segment, smart_intersections as SmartIntersections, Utils$1 as Utils, Vector$1 as Vector, arc, box, circle, Flatten as default, inversion, line, matrix, multiline, point, polygon, ray, ray_shoot, segment, vector$1 as vector }; diff --git a/dist/main.umd.js b/dist/main.umd.js index b90fd647..60aec7cf 100644 --- a/dist/main.umd.js +++ b/dist/main.umd.js @@ -154,10 +154,40 @@ setTolerance: setTolerance }); + let Flatten = { + Utils: Utils$1, + Errors: undefined, + Matrix: undefined, + Planar_set: undefined, + Point: undefined, + Vector: undefined, + Line: undefined, + Circle: undefined, + Segment: undefined, + Arc: undefined, + Box: undefined, + Edge: undefined, + Face: undefined, + Ray: undefined, + Ray_shooting: undefined, + Multiline: undefined, + Polygon: undefined, + Distance: undefined, + Inversion: undefined + }; + + for (let c in Constants) {Flatten[c] = Constants[c];} + + Object.defineProperty(Flatten, 'DP_TOL', { + get:function(){return getTolerance()}, + set:function(value){setTolerance(value);} + }); + /** * Created by Alex Bol on 2/19/2017. */ + /** * Class of system errors */ @@ -195,6 +225,10 @@ return new Error('Infinite loop'); } + static get CANNOT_COMPLETE_BOOLEAN_OPERATION() { + return new Error('Cannot complete boolean operation') + } + static get CANNOT_INVOKE_ABSTRACT_METHOD() { return new Error('Abstract method cannot be invoked'); } @@ -204,39 +238,7 @@ } } - var errors = /*#__PURE__*/Object.freeze({ - __proto__: null, - default: Errors - }); - - let Flatten = { - Utils: Utils$1, - Errors: Errors, - Matrix: undefined, - Planar_set: undefined, - Point: undefined, - Vector: undefined, - Line: undefined, - Circle: undefined, - Segment: undefined, - Arc: undefined, - Box: undefined, - Edge: undefined, - Face: undefined, - Ray: undefined, - Ray_shooting: undefined, - Multiline: undefined, - Polygon: undefined, - Distance: undefined, - Inversion: undefined - }; - - for (let c in Constants) {Flatten[c] = Constants[c];} - - Object.defineProperty(Flatten, 'DP_TOL', { - get:function(){return getTolerance()}, - set:function(value){setTolerance(value);} - }); + Flatten.Errors = Errors; /** * Class implements bidirectional non-circular linked list.
@@ -384,14 +386,14 @@ /** * Throw an error if circular loop detected in the linked list * @param {LinkedListElement} first element to start iteration - * @throws {Flatten.Errors.INFINITE_LOOP} + * @throws {Errors.INFINITE_LOOP} */ static testInfiniteLoop(first) { let edge = first; let controlEdge = first; do { if (edge != first && edge === controlEdge) { - throw Flatten.Errors.INFINITE_LOOP; // new Error("Infinite loop") + throw Errors.INFINITE_LOOP; // new Error("Infinite loop") } edge = edge.next; controlEdge = controlEdge.next.next; @@ -1409,12 +1411,17 @@ let first = int_point.edge_after; // face start let last = int_point.edge_before; // face end; - LinkedList.testInfiniteLoop(first); // check and throw error if infinite loop found + try { + LinkedList.testInfiniteLoop(first); // check and throw error if infinite loop found + } + catch (error) { + throw Errors.CANNOT_COMPLETE_BOOLEAN_OPERATION + } let face = polygon.addFace(first, last); // Mark intersection points from the newly create face - // to avoid multiple creation of the same face + // to avoid multiple creation of the same face. // Face was assigned to each edge of new face in addFace function for (let int_point_tmp of int_points) { if (int_point_tmp.edge_before && int_point_tmp.edge_after && @@ -3062,7 +3069,7 @@ tx = args[0]; ty = args[1]; } else { - throw Flatten.Errors.ILLEGAL_PARAMETERS; + throw Errors.ILLEGAL_PARAMETERS; } return this.multiply(new Matrix(1, 0, 0, 1, tx, ty)) }; @@ -4052,23 +4059,22 @@ */ class Shape { get name() { - throw(Flatten.Errors.CANNOT_INVOKE_ABSTRACT_METHOD); + throw(Errors.CANNOT_INVOKE_ABSTRACT_METHOD); } get box() { - throw(Flatten.Errors.CANNOT_INVOKE_ABSTRACT_METHOD); + throw(Errors.CANNOT_INVOKE_ABSTRACT_METHOD); } clone() { - throw(Flatten.Errors.CANNOT_INVOKE_ABSTRACT_METHOD); + throw(Errors.CANNOT_INVOKE_ABSTRACT_METHOD); } /** * Returns new shape translated by given vector. * Translation vector may be also defined by a pair of numbers. - * @param {Vector} vector - Translation vector or - * @param {number} tx - Translation by x-axis - * @param {number} ty - Translation by y-axis + * @param {Vector | (number, number) } args - Translation vector + * or tuple of numbers * @returns {Shape} */ translate(...args) { @@ -4099,7 +4105,7 @@ } transform(...args) { - throw(Flatten.Errors.CANNOT_INVOKE_ABSTRACT_METHOD); + throw(Errors.CANNOT_INVOKE_ABSTRACT_METHOD); } /** @@ -4112,7 +4118,7 @@ } svg(attrs = {}) { - throw(Flatten.Errors.CANNOT_INVOKE_ABSTRACT_METHOD); + throw(Errors.CANNOT_INVOKE_ABSTRACT_METHOD); } } @@ -4172,7 +4178,7 @@ return; } } - throw Flatten.Errors.ILLEGAL_PARAMETERS; + throw Errors.ILLEGAL_PARAMETERS; } /** @@ -4433,7 +4439,7 @@ } - throw Flatten.Errors.ILLEGAL_PARAMETERS; + throw Errors.ILLEGAL_PARAMETERS; } /** @@ -4510,7 +4516,7 @@ if (!Flatten.Utils.EQ_0(this.length)) { return (new Flatten.Vector(this.x / this.length, this.y / this.length)); } - throw Flatten.Errors.ZERO_DIVISION; + throw Errors.ZERO_DIVISION; } /** @@ -4525,7 +4531,7 @@ if (center.x === 0 && center.y === 0) { return this.transform(new Matrix().rotate(angle)); } - throw(Flatten.Errors.OPERATION_IS_NOT_SUPPORTED); + throw(Errors.OPERATION_IS_NOT_SUPPORTED); } /** @@ -4683,7 +4689,7 @@ return; } - throw Flatten.Errors.ILLEGAL_PARAMETERS; + throw Errors.ILLEGAL_PARAMETERS; } /** @@ -5039,7 +5045,7 @@ if (a1 instanceof Flatten.Point && a2 instanceof Flatten.Vector) { if (Flatten.Utils.EQ_0(a2.x) && Flatten.Utils.EQ_0(a2.y)) { - throw Flatten.Errors.ILLEGAL_PARAMETERS; + throw Errors.ILLEGAL_PARAMETERS; } this.pt = a1.clone(); this.norm = a2.clone(); @@ -5052,7 +5058,7 @@ if (a1 instanceof Flatten.Vector && a2 instanceof Flatten.Point) { if (Flatten.Utils.EQ_0(a1.x) && Flatten.Utils.EQ_0(a1.y)) { - throw Flatten.Errors.ILLEGAL_PARAMETERS; + throw Errors.ILLEGAL_PARAMETERS; } this.pt = a2.clone(); this.norm = a1.clone(); @@ -5064,7 +5070,7 @@ } } - throw Flatten.Errors.ILLEGAL_PARAMETERS; + throw Errors.ILLEGAL_PARAMETERS; } /** @@ -5334,7 +5340,7 @@ static points2norm(pt1, pt2) { if (pt1.equalTo(pt2)) { - throw Flatten.Errors.ILLEGAL_PARAMETERS; + throw Errors.ILLEGAL_PARAMETERS; } let vec = new Flatten.Vector(pt1, pt2); let unit = vec.normalize(); @@ -5392,7 +5398,7 @@ if (pc && pc instanceof Flatten.Point) this.pc = pc.clone(); if (r !== undefined) this.r = r; } - // throw Flatten.Errors.ILLEGAL_PARAMETERS; unreachable code + // throw Errors.ILLEGAL_PARAMETERS; unreachable code } /** @@ -5471,9 +5477,9 @@ */ scale(sx, sy) { if (sx !== sy) - throw Flatten.Errors.OPERATION_IS_NOT_SUPPORTED + throw Errors.OPERATION_IS_NOT_SUPPORTED if (!(this.pc.x === 0.0 && this.pc.y === 0.0)) - throw Flatten.Errors.OPERATION_IS_NOT_SUPPORTED + throw Errors.OPERATION_IS_NOT_SUPPORTED return new Flatten.Circle(this.pc, this.r*sx) } @@ -6311,7 +6317,7 @@ * @param {Point} [center=(0,0)] center */ rotate(angle, center = new Flatten.Point()) { - throw Flatten.Errors.OPERATION_IS_NOT_SUPPORTED + throw Errors.OPERATION_IS_NOT_SUPPORTED } /** @@ -7178,7 +7184,7 @@ return; } - throw Flatten.Errors.ILLEGAL_PARAMETERS; + throw Errors.ILLEGAL_PARAMETERS; } /** @@ -8747,7 +8753,7 @@ exports.Circle = Circle$1; exports.Distance = Distance; exports.Edge = Edge; - exports.Errors = errors; + exports.Errors = Errors; exports.Face = Face; exports.INSIDE = INSIDE$2; exports.Inversion = Inversion; diff --git a/docs/Arc.html b/docs/Arc.html index fcfa81f6..d38cf0b9 100644 --- a/docs/Arc.html +++ b/docs/Arc.html @@ -3096,7 +3096,7 @@
Returns:

diff --git a/docs/Box.html b/docs/Box.html index d09f06e8..666606af 100644 --- a/docs/Box.html +++ b/docs/Box.html @@ -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:
@@ -1190,7 +1190,7 @@

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

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

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

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

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

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

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

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

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

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

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

- Generated by JSDoc 3.6.11 on Sun Sep 03 2023 14:17:22 GMT+0300 (Israel Daylight Time) using the Minami theme. + Generated by JSDoc 3.6.11 on Sat Dec 02 2023 22:25:22 GMT+0200 (Israel Standard Time) using the Minami theme.
diff --git a/docs/Circle.html b/docs/Circle.html index d406f1ad..6a4e5275 100644 --- a/docs/Circle.html +++ b/docs/Circle.html @@ -99,7 +99,7 @@

new CircleSource:
@@ -279,7 +279,7 @@

boxSource:
@@ -343,7 +343,7 @@

centerSource:
@@ -407,7 +407,7 @@

pcSource:
@@ -481,7 +481,7 @@

rSource:
@@ -565,7 +565,7 @@

cloneSource:
@@ -669,7 +669,7 @@

containsSource:
@@ -825,7 +825,7 @@

distanceTo<
Source:
@@ -1005,7 +1005,7 @@

intersectSource:
@@ -1161,7 +1161,7 @@

scaleSource:
@@ -1343,7 +1343,7 @@

svgSource:
@@ -1499,7 +1499,7 @@

toArcSource:
@@ -1663,7 +1663,7 @@

transformSource:
@@ -1788,7 +1788,7 @@
Returns:

- Generated by JSDoc 3.6.11 on Sun Sep 03 2023 14:17:22 GMT+0300 (Israel Daylight Time) using the Minami theme. + Generated by JSDoc 3.6.11 on Sat Dec 02 2023 22:25:22 GMT+0200 (Israel Standard Time) using the Minami theme.
diff --git a/docs/CircularLinkedList.html b/docs/CircularLinkedList.html index a6fc31dd..5bbaec98 100644 --- a/docs/CircularLinkedList.html +++ b/docs/CircularLinkedList.html @@ -664,7 +664,7 @@
Returns:

- Generated by JSDoc 3.6.11 on Sun Sep 03 2023 14:17:22 GMT+0300 (Israel Daylight Time) using the Minami theme. + Generated by JSDoc 3.6.11 on Sat Dec 02 2023 22:25:22 GMT+0200 (Israel Standard Time) using the Minami theme.
diff --git a/docs/DE9IM.html b/docs/DE9IM.html index 837123e3..82d756ce 100644 --- a/docs/DE9IM.html +++ b/docs/DE9IM.html @@ -1507,7 +1507,7 @@
Returns:

- Generated by JSDoc 3.6.11 on Sun Sep 03 2023 14:17:22 GMT+0300 (Israel Daylight Time) using the Minami theme. + Generated by JSDoc 3.6.11 on Sat Dec 02 2023 22:25:22 GMT+0200 (Israel Standard Time) using the Minami theme.
diff --git a/docs/Edge.html b/docs/Edge.html index 8732cbe8..7dcf178c 100644 --- a/docs/Edge.html +++ b/docs/Edge.html @@ -1819,7 +1819,7 @@
Parameters:

- Generated by JSDoc 3.6.11 on Sun Sep 03 2023 14:17:22 GMT+0300 (Israel Daylight Time) using the Minami theme. + Generated by JSDoc 3.6.11 on Sat Dec 02 2023 22:25:22 GMT+0200 (Israel Standard Time) using the Minami theme.
diff --git a/docs/Errors.html b/docs/Errors.html index eb07b237..89cecfe6 100644 --- a/docs/Errors.html +++ b/docs/Errors.html @@ -426,7 +426,7 @@

(static)
- Generated by JSDoc 3.6.11 on Sun Sep 03 2023 14:17:22 GMT+0300 (Israel Daylight Time) using the Minami theme. + Generated by JSDoc 3.6.11 on Sat Dec 02 2023 22:25:22 GMT+0200 (Israel Standard Time) using the Minami theme.
diff --git a/docs/Face.html b/docs/Face.html index 4985b15b..31a804cd 100644 --- a/docs/Face.html +++ b/docs/Face.html @@ -2343,7 +2343,7 @@
Returns:

- Generated by JSDoc 3.6.11 on Sun Sep 03 2023 14:17:22 GMT+0300 (Israel Daylight Time) using the Minami theme. + Generated by JSDoc 3.6.11 on Sat Dec 02 2023 22:25:22 GMT+0200 (Israel Standard Time) using the Minami theme.
diff --git a/docs/Inversion.html b/docs/Inversion.html index 9f44c292..89f39193 100644 --- a/docs/Inversion.html +++ b/docs/Inversion.html @@ -232,7 +232,7 @@

Classes


- Generated by JSDoc 3.6.11 on Sun Sep 03 2023 14:17:22 GMT+0300 (Israel Daylight Time) using the Minami theme. + Generated by JSDoc 3.6.11 on Sat Dec 02 2023 22:25:22 GMT+0200 (Israel Standard Time) using the Minami theme.
diff --git a/docs/Line.html b/docs/Line.html index edf1ffa7..0bfc55e7 100644 --- a/docs/Line.html +++ b/docs/Line.html @@ -103,7 +103,7 @@

new LineSource:
@@ -286,7 +286,7 @@

boxSource:
@@ -350,7 +350,7 @@

endSource:
@@ -414,7 +414,7 @@

lengthSource:
@@ -478,7 +478,7 @@

middleSource:
@@ -544,7 +544,7 @@

normSource:
@@ -618,7 +618,7 @@

ptSource:
@@ -692,7 +692,7 @@

slopeSource:
@@ -756,7 +756,7 @@

standardSource:
@@ -830,7 +830,7 @@

cloneSource:
@@ -934,7 +934,7 @@

containsSource:
@@ -1093,7 +1093,7 @@

coordSource:
@@ -1249,7 +1249,7 @@

distanceTo<
Source:
@@ -1393,7 +1393,7 @@

incidentTo<
Source:
@@ -1549,7 +1549,7 @@

intersectSource:
@@ -1705,7 +1705,7 @@

parallelTo<
Source:
@@ -1861,7 +1861,7 @@

rotateSource:
@@ -2023,7 +2023,7 @@

sortPoints<
Source:
@@ -2184,7 +2184,7 @@

splitSource:
@@ -2343,7 +2343,7 @@

svgSource:
@@ -2504,7 +2504,7 @@

transformSource:
@@ -2629,7 +2629,7 @@
Returns:

- Generated by JSDoc 3.6.11 on Sun Sep 03 2023 14:17:22 GMT+0300 (Israel Daylight Time) using the Minami theme. + Generated by JSDoc 3.6.11 on Sat Dec 02 2023 22:25:22 GMT+0200 (Israel Standard Time) using the Minami theme.
diff --git a/docs/LinkedList.html b/docs/LinkedList.html index 95422758..b9b38c55 100644 --- a/docs/LinkedList.html +++ b/docs/LinkedList.html @@ -358,7 +358,7 @@
Throws:
-Flatten.Errors.INFINITE_LOOP +Errors.INFINITE_LOOP @@ -1094,7 +1094,7 @@
Returns:

- Generated by JSDoc 3.6.11 on Sun Sep 03 2023 14:17:22 GMT+0300 (Israel Daylight Time) using the Minami theme. + Generated by JSDoc 3.6.11 on Sat Dec 02 2023 22:25:22 GMT+0200 (Israel Standard Time) using the Minami theme.
diff --git a/docs/Matrix.html b/docs/Matrix.html index 1614b600..064f4bbe 100644 --- a/docs/Matrix.html +++ b/docs/Matrix.html @@ -109,7 +109,7 @@

new MatrixSource:
@@ -437,7 +437,7 @@

cloneSource:
@@ -541,7 +541,7 @@

equalToSource:
@@ -701,7 +701,7 @@

multiplySource:
@@ -859,7 +859,7 @@

rotateSource:
@@ -1086,7 +1086,7 @@

scaleSource:
@@ -1275,7 +1275,7 @@

transformSource:
@@ -1436,7 +1436,7 @@

translateSource:
@@ -1613,7 +1613,7 @@
Returns:

- Generated by JSDoc 3.6.11 on Sun Sep 03 2023 14:17:22 GMT+0300 (Israel Daylight Time) using the Minami theme. + Generated by JSDoc 3.6.11 on Sat Dec 02 2023 22:25:22 GMT+0200 (Israel Standard Time) using the Minami theme.
diff --git a/docs/Multiline.html b/docs/Multiline.html index 2b28eb7b..cb3f8484 100644 --- a/docs/Multiline.html +++ b/docs/Multiline.html @@ -1849,7 +1849,7 @@
Returns:

- Generated by JSDoc 3.6.11 on Sun Sep 03 2023 14:17:22 GMT+0300 (Israel Daylight Time) using the Minami theme. + Generated by JSDoc 3.6.11 on Sat Dec 02 2023 22:25:22 GMT+0200 (Israel Standard Time) using the Minami theme.
diff --git a/docs/PlanarSet.html b/docs/PlanarSet.html index c77cfb5f..f9420df9 100644 --- a/docs/PlanarSet.html +++ b/docs/PlanarSet.html @@ -1046,7 +1046,7 @@
Returns:

- Generated by JSDoc 3.6.11 on Sun Sep 03 2023 14:17:22 GMT+0300 (Israel Daylight Time) using the Minami theme. + Generated by JSDoc 3.6.11 on Sat Dec 02 2023 22:25:22 GMT+0200 (Israel Standard Time) using the Minami theme.
diff --git a/docs/Point.html b/docs/Point.html index 3284c48c..ce9f310e 100644 --- a/docs/Point.html +++ b/docs/Point.html @@ -103,7 +103,7 @@

new PointSource:
@@ -283,7 +283,7 @@

boxSource:
@@ -347,7 +347,7 @@

xSource:
@@ -421,7 +421,7 @@

ySource:
@@ -505,7 +505,7 @@

cloneSource:
@@ -609,7 +609,7 @@

distanceTo<
Source:
@@ -789,7 +789,7 @@

equalToSource:
@@ -946,7 +946,7 @@

leftToSource:
@@ -1104,7 +1104,7 @@

lessThanSource:
@@ -1260,7 +1260,7 @@

onSource:
@@ -1416,7 +1416,7 @@

projectio
Source:
@@ -1580,7 +1580,7 @@

svgSource:
@@ -1736,7 +1736,7 @@

transformSource:
@@ -1861,7 +1861,7 @@
Returns:

- Generated by JSDoc 3.6.11 on Sun Sep 03 2023 14:17:22 GMT+0300 (Israel Daylight Time) using the Minami theme. + Generated by JSDoc 3.6.11 on Sat Dec 02 2023 22:25:22 GMT+0200 (Israel Standard Time) using the Minami theme.
diff --git a/docs/Polygon.html b/docs/Polygon.html index 54212522..c229984f 100644 --- a/docs/Polygon.html +++ b/docs/Polygon.html @@ -4262,7 +4262,7 @@
Returns:

- Generated by JSDoc 3.6.11 on Sun Sep 03 2023 14:17:22 GMT+0300 (Israel Daylight Time) using the Minami theme. + Generated by JSDoc 3.6.11 on Sat Dec 02 2023 22:25:22 GMT+0200 (Israel Standard Time) using the Minami theme.
diff --git a/docs/Ray.html b/docs/Ray.html index 0015979c..f91f3eef 100644 --- a/docs/Ray.html +++ b/docs/Ray.html @@ -108,7 +108,7 @@

new RaySource:
@@ -288,7 +288,7 @@

boxSource:
@@ -352,7 +352,7 @@

endSource:
@@ -416,7 +416,7 @@

lengthSource:
@@ -480,7 +480,7 @@

slopeSource:
@@ -544,7 +544,7 @@

startSource:
@@ -618,7 +618,7 @@

cloneSource:
@@ -722,7 +722,7 @@

containsSource:
@@ -878,7 +878,7 @@

intersectSource:
@@ -1038,7 +1038,7 @@

rotateSource:
@@ -1199,7 +1199,7 @@

splitSource:
@@ -1347,7 +1347,7 @@

svgSource:
@@ -1508,7 +1508,7 @@

transformSource:
@@ -1633,7 +1633,7 @@
Returns:

- Generated by JSDoc 3.6.11 on Sun Sep 03 2023 14:17:22 GMT+0300 (Israel Daylight Time) using the Minami theme. + Generated by JSDoc 3.6.11 on Sat Dec 02 2023 22:25:22 GMT+0200 (Israel Standard Time) using the Minami theme.
diff --git a/docs/Segment.html b/docs/Segment.html index 6c0d7a6b..d15d2479 100644 --- a/docs/Segment.html +++ b/docs/Segment.html @@ -99,7 +99,7 @@

new SegmentSource:
@@ -279,7 +279,7 @@

boxSource:
@@ -343,7 +343,7 @@

endSource:
@@ -407,7 +407,7 @@

lengthSource:
@@ -471,7 +471,7 @@

peSource:
@@ -545,7 +545,7 @@

psSource:
@@ -619,7 +619,7 @@

slopeSource:
@@ -683,7 +683,7 @@

startSource:
@@ -747,7 +747,7 @@

verticesSource:
@@ -821,7 +821,7 @@

cloneSource:
@@ -925,7 +925,7 @@

containsSource:
@@ -1081,7 +1081,7 @@

distanceTo<
Source:
@@ -1261,7 +1261,7 @@

equalToSource:
@@ -1417,7 +1417,7 @@

intersectSource:
@@ -1573,7 +1573,7 @@

isZeroLen
Source:
@@ -1677,7 +1677,7 @@

middleSource:
@@ -1781,7 +1781,7 @@

pointAtL
Source:
@@ -1937,7 +1937,7 @@

reverseSource:
@@ -2041,7 +2041,7 @@

sortPoints<
Source:
@@ -2203,7 +2203,7 @@

splitSource:
@@ -2359,7 +2359,7 @@

svgSource:
@@ -2517,7 +2517,7 @@

tangentIn
Source:
@@ -2621,7 +2621,7 @@

tangent
Source:
@@ -2725,7 +2725,7 @@

transformSource:
@@ -2854,7 +2854,7 @@
Returns:

- Generated by JSDoc 3.6.11 on Sun Sep 03 2023 14:17:22 GMT+0300 (Israel Daylight Time) using the Minami theme. + Generated by JSDoc 3.6.11 on Sat Dec 02 2023 22:25:22 GMT+0200 (Israel Standard Time) using the Minami theme.
diff --git a/docs/Shape.html b/docs/Shape.html index 6e35ce9d..c2a5df92 100644 --- a/docs/Shape.html +++ b/docs/Shape.html @@ -100,7 +100,7 @@

new ShapeSource:
@@ -662,7 +662,7 @@
Returns:
-

translate(vector, tx, ty) → {Shape}

+

translate(…args) → {Shape}

@@ -738,6 +738,8 @@
Parameters:
Type + Attributes + @@ -750,76 +752,29 @@
Parameters:
- vector + args - -Vector - - - - - - - - Translation vector or + - - - - - - - tx - - - - -number - - - - - - - - - - Translation by x-axis - - - - - - - - ty - - - - + <repeatable>
-number - - - - - + - Translation by y-axis + @@ -883,7 +838,7 @@
Returns:

- Generated by JSDoc 3.6.11 on Sun Sep 03 2023 14:17:22 GMT+0300 (Israel Daylight Time) using the Minami theme. + Generated by JSDoc 3.6.11 on Sat Dec 02 2023 22:25:22 GMT+0200 (Israel Standard Time) using the Minami theme.
diff --git a/docs/Vector.html b/docs/Vector.html index 10140051..3da311d1 100644 --- a/docs/Vector.html +++ b/docs/Vector.html @@ -104,7 +104,7 @@

new VectorSource:
@@ -284,7 +284,7 @@

lengthSource:
@@ -348,7 +348,7 @@

slopeSource:
@@ -412,7 +412,7 @@

xSource:
@@ -486,7 +486,7 @@

ySource:
@@ -570,7 +570,7 @@

addSource:
@@ -728,7 +728,7 @@

angleToSource:
@@ -884,7 +884,7 @@

cloneSource:
@@ -989,7 +989,7 @@

crossSource:
@@ -1146,7 +1146,7 @@

dotSource:
@@ -1303,7 +1303,7 @@

equalToSource:
@@ -1459,7 +1459,7 @@

invertSource:
@@ -1563,7 +1563,7 @@

multiplySource:
@@ -1720,7 +1720,7 @@

normalizeSource:
@@ -1824,7 +1824,7 @@

projectio
Source:
@@ -1983,7 +1983,7 @@

rotateSource:
@@ -2139,7 +2139,7 @@

rotate90CC
Source:
@@ -2243,7 +2243,7 @@

rotate90CW<
Source:
@@ -2347,7 +2347,7 @@

subtractSource:
@@ -2503,7 +2503,7 @@

transformSource:
@@ -2628,7 +2628,7 @@
Returns:

- Generated by JSDoc 3.6.11 on Sun Sep 03 2023 14:17:22 GMT+0300 (Israel Daylight Time) using the Minami theme. + Generated by JSDoc 3.6.11 on Sat Dec 02 2023 22:25:22 GMT+0200 (Israel Standard Time) using the Minami theme.
diff --git a/docs/algorithms_boolean_op.js.html b/docs/algorithms_boolean_op.js.html index a8836685..756772c9 100644 --- a/docs/algorithms_boolean_op.js.html +++ b/docs/algorithms_boolean_op.js.html @@ -47,7 +47,7 @@

algorithms/boolean_op.js

*/ "use strict"; import Flatten from '../flatten'; -import Errors from "../utils/errors"; +import {Errors} from "../utils/errors"; import * as Constants from '../utils/constants'; import LinkedList from "../data_structures/linked_list"; import {addToIntPoints, sortIntersections, @@ -680,12 +680,17 @@

algorithms/boolean_op.js

let first = int_point.edge_after; // face start let last = int_point.edge_before; // face end; - LinkedList.testInfiniteLoop(first); // check and throw error if infinite loop found + try { + LinkedList.testInfiniteLoop(first); // check and throw error if infinite loop found + } + catch (error) { + throw Errors.CANNOT_COMPLETE_BOOLEAN_OPERATION + } let face = polygon.addFace(first, last); // Mark intersection points from the newly create face - // to avoid multiple creation of the same face + // to avoid multiple creation of the same face. // Face was assigned to each edge of new face in addFace function for (let int_point_tmp of int_points) { if (int_point_tmp.edge_before && int_point_tmp.edge_after && @@ -736,7 +741,7 @@

algorithms/boolean_op.js


- Generated by JSDoc 3.6.11 on Sun Sep 03 2023 14:17:22 GMT+0300 (Israel Daylight Time) using the Minami theme. + Generated by JSDoc 3.6.11 on Sat Dec 02 2023 22:25:22 GMT+0200 (Israel Standard Time) using the Minami theme.
diff --git a/docs/algorithms_distance.js.html b/docs/algorithms_distance.js.html index 7477f76c..5890c783 100644 --- a/docs/algorithms_distance.js.html +++ b/docs/algorithms_distance.js.html @@ -651,7 +651,7 @@

algorithms/distance.js


- Generated by JSDoc 3.6.11 on Sun Sep 03 2023 14:17:22 GMT+0300 (Israel Daylight Time) using the Minami theme. + Generated by JSDoc 3.6.11 on Sat Dec 02 2023 22:25:22 GMT+0200 (Israel Standard Time) using the Minami theme.
diff --git a/docs/algorithms_ray_shooting.js.html b/docs/algorithms_ray_shooting.js.html index 1cec5da5..3d27ed83 100644 --- a/docs/algorithms_ray_shooting.js.html +++ b/docs/algorithms_ray_shooting.js.html @@ -194,7 +194,7 @@

algorithms/ray_shooting.js


- Generated by JSDoc 3.6.11 on Sun Sep 03 2023 14:17:22 GMT+0300 (Israel Daylight Time) using the Minami theme. + Generated by JSDoc 3.6.11 on Sat Dec 02 2023 22:25:22 GMT+0200 (Israel Standard Time) using the Minami theme.
diff --git a/docs/algorithms_relation.js.html b/docs/algorithms_relation.js.html index 9ea9cda6..6dad2e07 100644 --- a/docs/algorithms_relation.js.html +++ b/docs/algorithms_relation.js.html @@ -387,7 +387,7 @@

algorithms/relation.js


- Generated by JSDoc 3.6.11 on Sun Sep 03 2023 14:17:22 GMT+0300 (Israel Daylight Time) using the Minami theme. + Generated by JSDoc 3.6.11 on Sat Dec 02 2023 22:25:22 GMT+0200 (Israel Standard Time) using the Minami theme.
diff --git a/docs/classes_arc.js.html b/docs/classes_arc.js.html index 259a82b9..1dbfbbc1 100644 --- a/docs/classes_arc.js.html +++ b/docs/classes_arc.js.html @@ -549,7 +549,7 @@

classes/arc.js


- Generated by JSDoc 3.6.11 on Sun Sep 03 2023 14:17:22 GMT+0300 (Israel Daylight Time) using the Minami theme. + Generated by JSDoc 3.6.11 on Sat Dec 02 2023 22:25:22 GMT+0200 (Israel Standard Time) using the Minami theme.
diff --git a/docs/classes_box.js.html b/docs/classes_box.js.html index c983aa42..b0bbaf21 100644 --- a/docs/classes_box.js.html +++ b/docs/classes_box.js.html @@ -47,6 +47,7 @@

classes/box.js

import Flatten from '../flatten'; import {convertToString} from "../utils/attributes"; import {Shape} from "./shape"; +import {Errors} from "../utils/errors"; /** * Class Box represents bounding box of the shape. @@ -269,7 +270,7 @@

classes/box.js

* @param {Point} [center=(0,0)] center */ rotate(angle, center = new Flatten.Point()) { - throw Flatten.Errors.OPERATION_IS_NOT_SUPPORTED + throw Errors.OPERATION_IS_NOT_SUPPORTED } /** @@ -321,7 +322,7 @@

classes/box.js


- Generated by JSDoc 3.6.11 on Sun Sep 03 2023 14:17:22 GMT+0300 (Israel Daylight Time) using the Minami theme. + Generated by JSDoc 3.6.11 on Sat Dec 02 2023 22:25:22 GMT+0200 (Israel Standard Time) using the Minami theme.
diff --git a/docs/classes_circle.js.html b/docs/classes_circle.js.html index 49bc9e82..4193ade8 100644 --- a/docs/classes_circle.js.html +++ b/docs/classes_circle.js.html @@ -50,6 +50,7 @@

classes/circle.js

import {convertToString} from "../utils/attributes"; import {Shape} from "./shape"; import {Matrix} from "./matrix"; +import {Errors} from "../utils/errors"; /** * Class representing a circle @@ -88,7 +89,7 @@

classes/circle.js

if (pc && pc instanceof Flatten.Point) this.pc = pc.clone(); if (r !== undefined) this.r = r; } - // throw Flatten.Errors.ILLEGAL_PARAMETERS; unreachable code + // throw Errors.ILLEGAL_PARAMETERS; unreachable code } /** @@ -167,9 +168,9 @@

classes/circle.js

*/ scale(sx, sy) { if (sx !== sy) - throw Flatten.Errors.OPERATION_IS_NOT_SUPPORTED + throw Errors.OPERATION_IS_NOT_SUPPORTED if (!(this.pc.x === 0.0 && this.pc.y === 0.0)) - throw Flatten.Errors.OPERATION_IS_NOT_SUPPORTED + throw Errors.OPERATION_IS_NOT_SUPPORTED return new Flatten.Circle(this.pc, this.r*sx) } @@ -300,7 +301,7 @@

classes/circle.js


- Generated by JSDoc 3.6.11 on Sun Sep 03 2023 14:17:22 GMT+0300 (Israel Daylight Time) using the Minami theme. + Generated by JSDoc 3.6.11 on Sat Dec 02 2023 22:25:22 GMT+0200 (Israel Standard Time) using the Minami theme.
diff --git a/docs/classes_edge.js.html b/docs/classes_edge.js.html index b702d644..aeb4a183 100644 --- a/docs/classes_edge.js.html +++ b/docs/classes_edge.js.html @@ -286,7 +286,7 @@

classes/edge.js


- Generated by JSDoc 3.6.11 on Sun Sep 03 2023 14:17:22 GMT+0300 (Israel Daylight Time) using the Minami theme. + Generated by JSDoc 3.6.11 on Sat Dec 02 2023 22:25:22 GMT+0200 (Israel Standard Time) using the Minami theme.
diff --git a/docs/classes_face.js.html b/docs/classes_face.js.html index a9735362..1d7a0229 100644 --- a/docs/classes_face.js.html +++ b/docs/classes_face.js.html @@ -548,7 +548,7 @@

classes/face.js


- Generated by JSDoc 3.6.11 on Sun Sep 03 2023 14:17:22 GMT+0300 (Israel Daylight Time) using the Minami theme. + Generated by JSDoc 3.6.11 on Sat Dec 02 2023 22:25:22 GMT+0200 (Israel Standard Time) using the Minami theme.
diff --git a/docs/classes_inversion.js.html b/docs/classes_inversion.js.html index 4039d86a..dff246c2 100644 --- a/docs/classes_inversion.js.html +++ b/docs/classes_inversion.js.html @@ -141,7 +141,7 @@

classes/inversion.js


- Generated by JSDoc 3.6.11 on Sun Sep 03 2023 14:17:22 GMT+0300 (Israel Daylight Time) using the Minami theme. + Generated by JSDoc 3.6.11 on Sat Dec 02 2023 22:25:22 GMT+0200 (Israel Standard Time) using the Minami theme.
diff --git a/docs/classes_line.js.html b/docs/classes_line.js.html index b504ce57..f69a96de 100644 --- a/docs/classes_line.js.html +++ b/docs/classes_line.js.html @@ -48,6 +48,7 @@

classes/line.js

import * as Intersection from '../algorithms/intersection'; import {Shape} from "./shape"; import {Matrix} from "./matrix"; +import {Errors} from "../utils/errors"; let {vector} = Flatten; @@ -102,7 +103,7 @@

classes/line.js

if (a1 instanceof Flatten.Point && a2 instanceof Flatten.Vector) { if (Flatten.Utils.EQ_0(a2.x) && Flatten.Utils.EQ_0(a2.y)) { - throw Flatten.Errors.ILLEGAL_PARAMETERS; + throw Errors.ILLEGAL_PARAMETERS; } this.pt = a1.clone(); this.norm = a2.clone(); @@ -115,7 +116,7 @@

classes/line.js

if (a1 instanceof Flatten.Vector && a2 instanceof Flatten.Point) { if (Flatten.Utils.EQ_0(a1.x) && Flatten.Utils.EQ_0(a1.y)) { - throw Flatten.Errors.ILLEGAL_PARAMETERS; + throw Errors.ILLEGAL_PARAMETERS; } this.pt = a2.clone(); this.norm = a1.clone(); @@ -127,7 +128,7 @@

classes/line.js

} } - throw Flatten.Errors.ILLEGAL_PARAMETERS; + throw Errors.ILLEGAL_PARAMETERS; } /** @@ -397,7 +398,7 @@

classes/line.js

static points2norm(pt1, pt2) { if (pt1.equalTo(pt2)) { - throw Flatten.Errors.ILLEGAL_PARAMETERS; + throw Errors.ILLEGAL_PARAMETERS; } let vec = new Flatten.Vector(pt1, pt2); let unit = vec.normalize(); @@ -424,7 +425,7 @@

classes/line.js


- Generated by JSDoc 3.6.11 on Sun Sep 03 2023 14:17:22 GMT+0300 (Israel Daylight Time) using the Minami theme. + Generated by JSDoc 3.6.11 on Sat Dec 02 2023 22:25:22 GMT+0200 (Israel Standard Time) using the Minami theme.
diff --git a/docs/classes_matrix.js.html b/docs/classes_matrix.js.html index 99c81cb1..ccfc90d4 100644 --- a/docs/classes_matrix.js.html +++ b/docs/classes_matrix.js.html @@ -42,6 +42,7 @@

classes/matrix.js

"use strict";
 
 import Flatten from '../flatten';
+import {Errors} from "../utils/errors";
 
 /**
  * Class representing an affine transformation 3x3 matrix:
@@ -132,7 +133,7 @@ 

classes/matrix.js

tx = args[0]; ty = args[1]; } else { - throw Flatten.Errors.ILLEGAL_PARAMETERS; + throw Errors.ILLEGAL_PARAMETERS; } return this.multiply(new Matrix(1, 0, 0, 1, tx, ty)) }; @@ -201,7 +202,7 @@

classes/matrix.js


- Generated by JSDoc 3.6.11 on Sun Sep 03 2023 14:17:22 GMT+0300 (Israel Daylight Time) using the Minami theme. + Generated by JSDoc 3.6.11 on Sat Dec 02 2023 22:25:22 GMT+0200 (Israel Standard Time) using the Minami theme.
diff --git a/docs/classes_multiline.js.html b/docs/classes_multiline.js.html index 283a00c4..45aa83a3 100644 --- a/docs/classes_multiline.js.html +++ b/docs/classes_multiline.js.html @@ -258,7 +258,7 @@

classes/multiline.js


- Generated by JSDoc 3.6.11 on Sun Sep 03 2023 14:17:22 GMT+0300 (Israel Daylight Time) using the Minami theme. + Generated by JSDoc 3.6.11 on Sat Dec 02 2023 22:25:22 GMT+0200 (Israel Standard Time) using the Minami theme.
diff --git a/docs/classes_point.js.html b/docs/classes_point.js.html index ffe5ab4a..022ee8ab 100644 --- a/docs/classes_point.js.html +++ b/docs/classes_point.js.html @@ -47,6 +47,7 @@

classes/point.js

import {convertToString} from "../utils/attributes"; import {Matrix} from "./matrix"; import {Shape} from "./shape"; +import {Errors} from "../utils/errors"; /** * @@ -99,7 +100,7 @@

classes/point.js

return; } } - throw Flatten.Errors.ILLEGAL_PARAMETERS; + throw Errors.ILLEGAL_PARAMETERS; } /** @@ -303,7 +304,7 @@

classes/point.js


- Generated by JSDoc 3.6.11 on Sun Sep 03 2023 14:17:22 GMT+0300 (Israel Daylight Time) using the Minami theme. + Generated by JSDoc 3.6.11 on Sat Dec 02 2023 22:25:22 GMT+0200 (Israel Standard Time) using the Minami theme.
diff --git a/docs/classes_polygon.js.html b/docs/classes_polygon.js.html index efa43825..0ec043a7 100644 --- a/docs/classes_polygon.js.html +++ b/docs/classes_polygon.js.html @@ -762,7 +762,7 @@

classes/polygon.js


- Generated by JSDoc 3.6.11 on Sun Sep 03 2023 14:17:22 GMT+0300 (Israel Daylight Time) using the Minami theme. + Generated by JSDoc 3.6.11 on Sat Dec 02 2023 22:25:22 GMT+0200 (Israel Standard Time) using the Minami theme.
diff --git a/docs/classes_ray.js.html b/docs/classes_ray.js.html index 04b6d5e1..f742a26e 100644 --- a/docs/classes_ray.js.html +++ b/docs/classes_ray.js.html @@ -44,6 +44,7 @@

classes/ray.js

import Flatten from '../flatten'; import * as Intersection from "../algorithms/intersection"; import {Shape} from "./shape"; +import {Errors} from "../utils/errors"; /** * Class representing a ray (a half-infinite line). @@ -82,7 +83,7 @@

classes/ray.js

return; } - throw Flatten.Errors.ILLEGAL_PARAMETERS; + throw Errors.ILLEGAL_PARAMETERS; } /** @@ -270,7 +271,7 @@

classes/ray.js


- Generated by JSDoc 3.6.11 on Sun Sep 03 2023 14:17:22 GMT+0300 (Israel Daylight Time) using the Minami theme. + Generated by JSDoc 3.6.11 on Sat Dec 02 2023 22:25:22 GMT+0200 (Israel Standard Time) using the Minami theme.
diff --git a/docs/classes_segment.js.html b/docs/classes_segment.js.html index 0178cec2..bf01217e 100644 --- a/docs/classes_segment.js.html +++ b/docs/classes_segment.js.html @@ -49,6 +49,7 @@

classes/segment.js

import * as Intersection from '../algorithms/intersection'; import {convertToString} from "../utils/attributes"; import {Shape} from "./shape"; +import {Errors} from "../utils/errors"; /** * Class representing a segment @@ -109,7 +110,7 @@

classes/segment.js

return; } - throw Flatten.Errors.ILLEGAL_PARAMETERS; + throw Errors.ILLEGAL_PARAMETERS; } /** @@ -419,7 +420,7 @@

classes/segment.js


- Generated by JSDoc 3.6.11 on Sun Sep 03 2023 14:17:22 GMT+0300 (Israel Daylight Time) using the Minami theme. + Generated by JSDoc 3.6.11 on Sat Dec 02 2023 22:25:22 GMT+0200 (Israel Standard Time) using the Minami theme.
diff --git a/docs/classes_shape.js.html b/docs/classes_shape.js.html index f8c1abc0..888a15e7 100644 --- a/docs/classes_shape.js.html +++ b/docs/classes_shape.js.html @@ -41,6 +41,7 @@

classes/shape.js

import Flatten from '../flatten';
 import {Matrix} from "./matrix";
+import {Errors} from "../utils/errors";
 
 /**
  * Base class representing shape
@@ -48,23 +49,22 @@ 

classes/shape.js

*/ export class Shape { get name() { - throw(Flatten.Errors.CANNOT_INVOKE_ABSTRACT_METHOD); + throw(Errors.CANNOT_INVOKE_ABSTRACT_METHOD); } get box() { - throw(Flatten.Errors.CANNOT_INVOKE_ABSTRACT_METHOD); + throw(Errors.CANNOT_INVOKE_ABSTRACT_METHOD); } clone() { - throw(Flatten.Errors.CANNOT_INVOKE_ABSTRACT_METHOD); + throw(Errors.CANNOT_INVOKE_ABSTRACT_METHOD); } /** * Returns new shape translated by given vector. * Translation vector may be also defined by a pair of numbers. - * @param {Vector} vector - Translation vector or - * @param {number} tx - Translation by x-axis - * @param {number} ty - Translation by y-axis + * @param {Vector | (number, number) } args - Translation vector + * or tuple of numbers * @returns {Shape} */ translate(...args) { @@ -95,7 +95,7 @@

classes/shape.js

} transform(...args) { - throw(Flatten.Errors.CANNOT_INVOKE_ABSTRACT_METHOD); + throw(Errors.CANNOT_INVOKE_ABSTRACT_METHOD); } /** @@ -108,7 +108,7 @@

classes/shape.js

} svg(attrs = {}) { - throw(Flatten.Errors.CANNOT_INVOKE_ABSTRACT_METHOD); + throw(Errors.CANNOT_INVOKE_ABSTRACT_METHOD); } }
@@ -122,7 +122,7 @@

classes/shape.js


- Generated by JSDoc 3.6.11 on Sun Sep 03 2023 14:17:22 GMT+0300 (Israel Daylight Time) using the Minami theme. + Generated by JSDoc 3.6.11 on Sat Dec 02 2023 22:25:22 GMT+0200 (Israel Standard Time) using the Minami theme.
diff --git a/docs/classes_vector.js.html b/docs/classes_vector.js.html index 8d3b2aa8..4b6b095c 100644 --- a/docs/classes_vector.js.html +++ b/docs/classes_vector.js.html @@ -48,6 +48,7 @@

classes/vector.js

import Flatten from '../flatten'; import {Shape} from "./shape"; import {Matrix} from "./matrix"; +import {Errors} from "../utils/errors"; /** * Class representing a vector @@ -112,7 +113,7 @@

classes/vector.js

} - throw Flatten.Errors.ILLEGAL_PARAMETERS; + throw Errors.ILLEGAL_PARAMETERS; } /** @@ -189,7 +190,7 @@

classes/vector.js

if (!Flatten.Utils.EQ_0(this.length)) { return (new Flatten.Vector(this.x / this.length, this.y / this.length)); } - throw Flatten.Errors.ZERO_DIVISION; + throw Errors.ZERO_DIVISION; } /** @@ -204,7 +205,7 @@

classes/vector.js

if (center.x === 0 && center.y === 0) { return this.transform(new Matrix().rotate(angle)); } - throw(Flatten.Errors.OPERATION_IS_NOT_SUPPORTED); + throw(Errors.OPERATION_IS_NOT_SUPPORTED); } /** @@ -310,7 +311,7 @@

classes/vector.js


- Generated by JSDoc 3.6.11 on Sun Sep 03 2023 14:17:22 GMT+0300 (Israel Daylight Time) using the Minami theme. + Generated by JSDoc 3.6.11 on Sat Dec 02 2023 22:25:22 GMT+0200 (Israel Standard Time) using the Minami theme.
diff --git a/docs/data_structures_circular_linked_list.js.html b/docs/data_structures_circular_linked_list.js.html index 35283901..d042c424 100644 --- a/docs/data_structures_circular_linked_list.js.html +++ b/docs/data_structures_circular_linked_list.js.html @@ -117,7 +117,7 @@

data_structures/circular_linked_list.js


- Generated by JSDoc 3.6.11 on Sun Sep 03 2023 14:17:22 GMT+0300 (Israel Daylight Time) using the Minami theme. + Generated by JSDoc 3.6.11 on Sat Dec 02 2023 22:25:22 GMT+0200 (Israel Standard Time) using the Minami theme.
diff --git a/docs/data_structures_de9im.js.html b/docs/data_structures_de9im.js.html index 6469fd35..2f6dc554 100644 --- a/docs/data_structures_de9im.js.html +++ b/docs/data_structures_de9im.js.html @@ -262,7 +262,7 @@

data_structures/de9im.js


- Generated by JSDoc 3.6.11 on Sun Sep 03 2023 14:17:22 GMT+0300 (Israel Daylight Time) using the Minami theme. + Generated by JSDoc 3.6.11 on Sat Dec 02 2023 22:25:22 GMT+0200 (Israel Standard Time) using the Minami theme.
diff --git a/docs/data_structures_linked_list.js.html b/docs/data_structures_linked_list.js.html index d591577e..c53c1a82 100644 --- a/docs/data_structures_linked_list.js.html +++ b/docs/data_structures_linked_list.js.html @@ -39,7 +39,7 @@

data_structures/linked_list.js

-
import Flatten from "../flatten";
+            
import {Errors} from "../utils/errors";
 
 /**
  * Class implements bidirectional non-circular linked list. <br/>
@@ -187,14 +187,14 @@ 

data_structures/linked_list.js

/** * Throw an error if circular loop detected in the linked list * @param {LinkedListElement} first element to start iteration - * @throws {Flatten.Errors.INFINITE_LOOP} + * @throws {Errors.INFINITE_LOOP} */ static testInfiniteLoop(first) { let edge = first; let controlEdge = first; do { if (edge != first && edge === controlEdge) { - throw Flatten.Errors.INFINITE_LOOP; // new Error("Infinite loop") + throw Errors.INFINITE_LOOP; // new Error("Infinite loop") } edge = edge.next; controlEdge = controlEdge.next.next; @@ -215,7 +215,7 @@

data_structures/linked_list.js


- Generated by JSDoc 3.6.11 on Sun Sep 03 2023 14:17:22 GMT+0300 (Israel Daylight Time) using the Minami theme. + Generated by JSDoc 3.6.11 on Sat Dec 02 2023 22:25:22 GMT+0200 (Israel Standard Time) using the Minami theme.
diff --git a/docs/data_structures_planar_set.js.html b/docs/data_structures_planar_set.js.html index 5f5b7e99..5b306c8c 100644 --- a/docs/data_structures_planar_set.js.html +++ b/docs/data_structures_planar_set.js.html @@ -149,7 +149,7 @@

data_structures/planar_set.js


- Generated by JSDoc 3.6.11 on Sun Sep 03 2023 14:17:22 GMT+0300 (Israel Daylight Time) using the Minami theme. + Generated by JSDoc 3.6.11 on Sat Dec 02 2023 22:25:22 GMT+0200 (Israel Standard Time) using the Minami theme.
diff --git a/docs/global.html b/docs/global.html index 2adc42d1..f60afe3b 100644 --- a/docs/global.html +++ b/docs/global.html @@ -218,7 +218,7 @@

(constant) boxSource:
@@ -356,7 +356,7 @@

(constant) circ
Source:
@@ -633,7 +633,7 @@

(constant) lineSource:
@@ -697,7 +697,7 @@

(constant) matr
Source:
@@ -900,7 +900,7 @@

(constant) point
Source:
@@ -1028,7 +1028,7 @@

(constant) seg
Source:
@@ -1092,7 +1092,7 @@

(constant) vect
Source:
@@ -2466,7 +2466,7 @@

Parameters:

- Generated by JSDoc 3.6.11 on Sun Sep 03 2023 14:17:22 GMT+0300 (Israel Daylight Time) using the Minami theme. + Generated by JSDoc 3.6.11 on Sat Dec 02 2023 22:25:22 GMT+0200 (Israel Standard Time) using the Minami theme.
diff --git a/docs/index.html b/docs/index.html index 1295a393..02461a1c 100644 --- a/docs/index.html +++ b/docs/index.html @@ -341,7 +341,7 @@

Support


- Generated by JSDoc 3.6.11 on Sun Sep 03 2023 14:17:22 GMT+0300 (Israel Daylight Time) using the Minami theme. + Generated by JSDoc 3.6.11 on Sat Dec 02 2023 22:25:22 GMT+0200 (Israel Standard Time) using the Minami theme.
diff --git a/docs/module-BooleanOperations.html b/docs/module-BooleanOperations.html index 9a8a8bdf..9b481a0b 100644 --- a/docs/module-BooleanOperations.html +++ b/docs/module-BooleanOperations.html @@ -1185,7 +1185,7 @@
Returns:

- Generated by JSDoc 3.6.11 on Sun Sep 03 2023 14:17:22 GMT+0300 (Israel Daylight Time) using the Minami theme. + Generated by JSDoc 3.6.11 on Sat Dec 02 2023 22:25:22 GMT+0200 (Israel Standard Time) using the Minami theme.
diff --git a/docs/module-RayShoot.html b/docs/module-RayShoot.html index 63f22f3c..0a952595 100644 --- a/docs/module-RayShoot.html +++ b/docs/module-RayShoot.html @@ -275,7 +275,7 @@
Returns:

- Generated by JSDoc 3.6.11 on Sun Sep 03 2023 14:17:22 GMT+0300 (Israel Daylight Time) using the Minami theme. + Generated by JSDoc 3.6.11 on Sat Dec 02 2023 22:25:22 GMT+0200 (Israel Standard Time) using the Minami theme.
diff --git a/docs/module-Relation.html b/docs/module-Relation.html index b25526c1..ec831838 100644 --- a/docs/module-Relation.html +++ b/docs/module-Relation.html @@ -1641,7 +1641,7 @@
Returns:

- Generated by JSDoc 3.6.11 on Sun Sep 03 2023 14:17:22 GMT+0300 (Israel Daylight Time) using the Minami theme. + Generated by JSDoc 3.6.11 on Sat Dec 02 2023 22:25:22 GMT+0200 (Israel Standard Time) using the Minami theme.
diff --git a/docs/utils_constants.js.html b/docs/utils_constants.js.html index 55e4361a..c7d24721 100644 --- a/docs/utils_constants.js.html +++ b/docs/utils_constants.js.html @@ -85,7 +85,7 @@

utils/constants.js


- Generated by JSDoc 3.6.11 on Sun Sep 03 2023 14:17:22 GMT+0300 (Israel Daylight Time) using the Minami theme. + Generated by JSDoc 3.6.11 on Sat Dec 02 2023 22:25:22 GMT+0200 (Israel Standard Time) using the Minami theme.
diff --git a/docs/utils_errors.js.html b/docs/utils_errors.js.html index a4a6c495..426af76c 100644 --- a/docs/utils_errors.js.html +++ b/docs/utils_errors.js.html @@ -46,7 +46,7 @@

utils/errors.js

/** * Class of system errors */ -class Errors { +export class Errors { /** * Throw error ILLEGAL_PARAMETERS when cannot instantiate from given parameter * @returns {ReferenceError} @@ -80,6 +80,10 @@

utils/errors.js

return new Error('Infinite loop'); } + static get CANNOT_COMPLETE_BOOLEAN_OPERATION() { + return new Error('Cannot complete boolean operation') + } + static get CANNOT_INVOKE_ABSTRACT_METHOD() { return new Error('Abstract method cannot be invoked'); } @@ -89,7 +93,6 @@

utils/errors.js

} } -export default Errors;

@@ -102,7 +105,7 @@

utils/errors.js


- Generated by JSDoc 3.6.11 on Sun Sep 03 2023 14:17:22 GMT+0300 (Israel Daylight Time) using the Minami theme. + Generated by JSDoc 3.6.11 on Sat Dec 02 2023 22:25:22 GMT+0200 (Israel Standard Time) using the Minami theme.
diff --git a/docs/utils_utils.js.html b/docs/utils_utils.js.html index c69df241..fd88da30 100644 --- a/docs/utils_utils.js.html +++ b/docs/utils_utils.js.html @@ -135,7 +135,7 @@

utils/utils.js


- Generated by JSDoc 3.6.11 on Sun Sep 03 2023 14:17:22 GMT+0300 (Israel Daylight Time) using the Minami theme. + Generated by JSDoc 3.6.11 on Sat Dec 02 2023 22:25:22 GMT+0200 (Israel Standard Time) using the Minami theme.
diff --git a/index.d.ts b/index.d.ts index 2a97a4e7..897f2034 100644 --- a/index.d.ts +++ b/index.d.ts @@ -593,6 +593,16 @@ declare namespace Flatten { inverse(Circle: Circle) : Line | Circle; } + class Errors { + readonly ILLEGAL_PARAMETERS: ReferenceError; + readonly ZERO_DIVISION: Error; + readonly UNRESOLVED_BOUNDARY_CONFLICT: Error; + readonly INFINITE_LOOP: Error; + readonly CANNOT_COMPLETE_BOOLEAN_OPERATION: Error; + readonly CANNOT_INVOKE_ABSTRACT_METHOD: Error; + readonly OPERATION_IS_NOT_SUPPORTED: Error; + } + type AnyShape = Point | Vector | Line | Ray | Circle | Box | Segment | Arc | Polygon; function point(x?: number, y?: number): Point; diff --git a/index.js b/index.js index 1f22824b..4d7082cf 100644 --- a/index.js +++ b/index.js @@ -4,12 +4,12 @@ import Flatten from './src/flatten'; import * as Utils from "./src/utils/utils"; -import * as Errors from "./src/utils/errors"; import * as BooleanOperations from './src/algorithms/boolean_op'; import * as Relations from './src/algorithms/relation'; import * as SmartIntersections from './src/data_structures/smart_intersections'; -export {Utils, Errors}; +export {Utils} +export {Errors} from './src/utils/errors'; export {Matrix, matrix} from './src/classes/matrix'; export {PlanarSet} from './src/data_structures/planar_set'; export {Point, point} from './src/classes/point'; diff --git a/package.json b/package.json index 1a847bd8..fd8101af 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "@flatten-js/core", - "version": "1.4.5", + "version": "1.4.6", "description": "Javascript library for 2d geometry", "main": "dist/main.cjs", "umd:main": "dist/main.umd.js", diff --git a/src/algorithms/boolean_op.js b/src/algorithms/boolean_op.js index 54c17124..4b1aed11 100644 --- a/src/algorithms/boolean_op.js +++ b/src/algorithms/boolean_op.js @@ -6,7 +6,7 @@ */ "use strict"; import Flatten from '../flatten'; -import Errors from "../utils/errors"; +import {Errors} from "../utils/errors"; import * as Constants from '../utils/constants'; import LinkedList from "../data_structures/linked_list"; import {addToIntPoints, sortIntersections, @@ -639,12 +639,17 @@ export function restoreFaces(polygon, int_points, other_int_points) let first = int_point.edge_after; // face start let last = int_point.edge_before; // face end; - LinkedList.testInfiniteLoop(first); // check and throw error if infinite loop found + try { + LinkedList.testInfiniteLoop(first); // check and throw error if infinite loop found + } + catch (error) { + throw Errors.CANNOT_COMPLETE_BOOLEAN_OPERATION + } let face = polygon.addFace(first, last); // Mark intersection points from the newly create face - // to avoid multiple creation of the same face + // to avoid multiple creation of the same face. // Face was assigned to each edge of new face in addFace function for (let int_point_tmp of int_points) { if (int_point_tmp.edge_before && int_point_tmp.edge_after && diff --git a/src/classes/box.js b/src/classes/box.js index f1f75353..4bade3ee 100644 --- a/src/classes/box.js +++ b/src/classes/box.js @@ -6,6 +6,7 @@ import Flatten from '../flatten'; import {convertToString} from "../utils/attributes"; import {Shape} from "./shape"; +import {Errors} from "../utils/errors"; /** * Class Box represents bounding box of the shape. @@ -228,7 +229,7 @@ export class Box extends Shape { * @param {Point} [center=(0,0)] center */ rotate(angle, center = new Flatten.Point()) { - throw Flatten.Errors.OPERATION_IS_NOT_SUPPORTED + throw Errors.OPERATION_IS_NOT_SUPPORTED } /** diff --git a/src/classes/circle.js b/src/classes/circle.js index 2ff5856b..c4b4c744 100644 --- a/src/classes/circle.js +++ b/src/classes/circle.js @@ -9,6 +9,7 @@ import * as Intersection from '../algorithms/intersection'; import {convertToString} from "../utils/attributes"; import {Shape} from "./shape"; import {Matrix} from "./matrix"; +import {Errors} from "../utils/errors"; /** * Class representing a circle @@ -47,7 +48,7 @@ export class Circle extends Shape { if (pc && pc instanceof Flatten.Point) this.pc = pc.clone(); if (r !== undefined) this.r = r; } - // throw Flatten.Errors.ILLEGAL_PARAMETERS; unreachable code + // throw Errors.ILLEGAL_PARAMETERS; unreachable code } /** @@ -126,9 +127,9 @@ export class Circle extends Shape { */ scale(sx, sy) { if (sx !== sy) - throw Flatten.Errors.OPERATION_IS_NOT_SUPPORTED + throw Errors.OPERATION_IS_NOT_SUPPORTED if (!(this.pc.x === 0.0 && this.pc.y === 0.0)) - throw Flatten.Errors.OPERATION_IS_NOT_SUPPORTED + throw Errors.OPERATION_IS_NOT_SUPPORTED return new Flatten.Circle(this.pc, this.r*sx) } diff --git a/src/classes/line.js b/src/classes/line.js index 43641271..17a1d067 100644 --- a/src/classes/line.js +++ b/src/classes/line.js @@ -7,6 +7,7 @@ import Flatten from '../flatten'; import * as Intersection from '../algorithms/intersection'; import {Shape} from "./shape"; import {Matrix} from "./matrix"; +import {Errors} from "../utils/errors"; let {vector} = Flatten; @@ -61,7 +62,7 @@ export class Line extends Shape { if (a1 instanceof Flatten.Point && a2 instanceof Flatten.Vector) { if (Flatten.Utils.EQ_0(a2.x) && Flatten.Utils.EQ_0(a2.y)) { - throw Flatten.Errors.ILLEGAL_PARAMETERS; + throw Errors.ILLEGAL_PARAMETERS; } this.pt = a1.clone(); this.norm = a2.clone(); @@ -74,7 +75,7 @@ export class Line extends Shape { if (a1 instanceof Flatten.Vector && a2 instanceof Flatten.Point) { if (Flatten.Utils.EQ_0(a1.x) && Flatten.Utils.EQ_0(a1.y)) { - throw Flatten.Errors.ILLEGAL_PARAMETERS; + throw Errors.ILLEGAL_PARAMETERS; } this.pt = a2.clone(); this.norm = a1.clone(); @@ -86,7 +87,7 @@ export class Line extends Shape { } } - throw Flatten.Errors.ILLEGAL_PARAMETERS; + throw Errors.ILLEGAL_PARAMETERS; } /** @@ -356,7 +357,7 @@ export class Line extends Shape { static points2norm(pt1, pt2) { if (pt1.equalTo(pt2)) { - throw Flatten.Errors.ILLEGAL_PARAMETERS; + throw Errors.ILLEGAL_PARAMETERS; } let vec = new Flatten.Vector(pt1, pt2); let unit = vec.normalize(); diff --git a/src/classes/matrix.js b/src/classes/matrix.js index 74e66946..9ae3ac72 100644 --- a/src/classes/matrix.js +++ b/src/classes/matrix.js @@ -1,6 +1,7 @@ "use strict"; import Flatten from '../flatten'; +import {Errors} from "../utils/errors"; /** * Class representing an affine transformation 3x3 matrix: @@ -91,7 +92,7 @@ export class Matrix { tx = args[0]; ty = args[1]; } else { - throw Flatten.Errors.ILLEGAL_PARAMETERS; + throw Errors.ILLEGAL_PARAMETERS; } return this.multiply(new Matrix(1, 0, 0, 1, tx, ty)) }; diff --git a/src/classes/point.js b/src/classes/point.js index 87fc39f2..3522ca13 100644 --- a/src/classes/point.js +++ b/src/classes/point.js @@ -6,6 +6,7 @@ import Flatten from '../flatten'; import {convertToString} from "../utils/attributes"; import {Matrix} from "./matrix"; import {Shape} from "./shape"; +import {Errors} from "../utils/errors"; /** * @@ -58,7 +59,7 @@ export class Point extends Shape { return; } } - throw Flatten.Errors.ILLEGAL_PARAMETERS; + throw Errors.ILLEGAL_PARAMETERS; } /** diff --git a/src/classes/ray.js b/src/classes/ray.js index 95ce1de4..302c2f28 100644 --- a/src/classes/ray.js +++ b/src/classes/ray.js @@ -3,6 +3,7 @@ import Flatten from '../flatten'; import * as Intersection from "../algorithms/intersection"; import {Shape} from "./shape"; +import {Errors} from "../utils/errors"; /** * Class representing a ray (a half-infinite line). @@ -41,7 +42,7 @@ export class Ray extends Shape { return; } - throw Flatten.Errors.ILLEGAL_PARAMETERS; + throw Errors.ILLEGAL_PARAMETERS; } /** diff --git a/src/classes/segment.js b/src/classes/segment.js index 599e82cf..bbaed884 100644 --- a/src/classes/segment.js +++ b/src/classes/segment.js @@ -8,6 +8,7 @@ import Flatten from '../flatten'; import * as Intersection from '../algorithms/intersection'; import {convertToString} from "../utils/attributes"; import {Shape} from "./shape"; +import {Errors} from "../utils/errors"; /** * Class representing a segment @@ -68,7 +69,7 @@ export class Segment extends Shape { return; } - throw Flatten.Errors.ILLEGAL_PARAMETERS; + throw Errors.ILLEGAL_PARAMETERS; } /** diff --git a/src/classes/shape.js b/src/classes/shape.js index b060f4c0..01cd5448 100644 --- a/src/classes/shape.js +++ b/src/classes/shape.js @@ -1,5 +1,6 @@ import Flatten from '../flatten'; import {Matrix} from "./matrix"; +import {Errors} from "../utils/errors"; /** * Base class representing shape @@ -7,23 +8,22 @@ import {Matrix} from "./matrix"; */ export class Shape { get name() { - throw(Flatten.Errors.CANNOT_INVOKE_ABSTRACT_METHOD); + throw(Errors.CANNOT_INVOKE_ABSTRACT_METHOD); } get box() { - throw(Flatten.Errors.CANNOT_INVOKE_ABSTRACT_METHOD); + throw(Errors.CANNOT_INVOKE_ABSTRACT_METHOD); } clone() { - throw(Flatten.Errors.CANNOT_INVOKE_ABSTRACT_METHOD); + throw(Errors.CANNOT_INVOKE_ABSTRACT_METHOD); } /** * Returns new shape translated by given vector. * Translation vector may be also defined by a pair of numbers. - * @param {Vector} vector - Translation vector or - * @param {number} tx - Translation by x-axis - * @param {number} ty - Translation by y-axis + * @param {Vector | (number, number) } args - Translation vector + * or tuple of numbers * @returns {Shape} */ translate(...args) { @@ -54,7 +54,7 @@ export class Shape { } transform(...args) { - throw(Flatten.Errors.CANNOT_INVOKE_ABSTRACT_METHOD); + throw(Errors.CANNOT_INVOKE_ABSTRACT_METHOD); } /** @@ -67,6 +67,6 @@ export class Shape { } svg(attrs = {}) { - throw(Flatten.Errors.CANNOT_INVOKE_ABSTRACT_METHOD); + throw(Errors.CANNOT_INVOKE_ABSTRACT_METHOD); } } \ No newline at end of file diff --git a/src/classes/vector.js b/src/classes/vector.js index 30b959c5..fa8708fd 100644 --- a/src/classes/vector.js +++ b/src/classes/vector.js @@ -7,6 +7,7 @@ import Flatten from '../flatten'; import {Shape} from "./shape"; import {Matrix} from "./matrix"; +import {Errors} from "../utils/errors"; /** * Class representing a vector @@ -71,7 +72,7 @@ export class Vector extends Shape { } - throw Flatten.Errors.ILLEGAL_PARAMETERS; + throw Errors.ILLEGAL_PARAMETERS; } /** @@ -148,7 +149,7 @@ export class Vector extends Shape { if (!Flatten.Utils.EQ_0(this.length)) { return (new Flatten.Vector(this.x / this.length, this.y / this.length)); } - throw Flatten.Errors.ZERO_DIVISION; + throw Errors.ZERO_DIVISION; } /** @@ -163,7 +164,7 @@ export class Vector extends Shape { if (center.x === 0 && center.y === 0) { return this.transform(new Matrix().rotate(angle)); } - throw(Flatten.Errors.OPERATION_IS_NOT_SUPPORTED); + throw(Errors.OPERATION_IS_NOT_SUPPORTED); } /** diff --git a/src/data_structures/linked_list.js b/src/data_structures/linked_list.js index 7490ebf6..00c05b0d 100644 --- a/src/data_structures/linked_list.js +++ b/src/data_structures/linked_list.js @@ -1,4 +1,4 @@ -import Flatten from "../flatten"; +import {Errors} from "../utils/errors"; /** * Class implements bidirectional non-circular linked list.
@@ -146,14 +146,14 @@ class LinkedList { /** * Throw an error if circular loop detected in the linked list * @param {LinkedListElement} first element to start iteration - * @throws {Flatten.Errors.INFINITE_LOOP} + * @throws {Errors.INFINITE_LOOP} */ static testInfiniteLoop(first) { let edge = first; let controlEdge = first; do { if (edge != first && edge === controlEdge) { - throw Flatten.Errors.INFINITE_LOOP; // new Error("Infinite loop") + throw Errors.INFINITE_LOOP; // new Error("Infinite loop") } edge = edge.next; controlEdge = controlEdge.next.next; diff --git a/src/flatten.js b/src/flatten.js index 9b06ab6b..c1344f17 100644 --- a/src/flatten.js +++ b/src/flatten.js @@ -1,10 +1,9 @@ import * as Constants from './utils/constants'; import * as Utils from './utils/utils'; -import Errors from './utils/errors'; let Flatten = { Utils: Utils, - Errors: Errors, + Errors: undefined, Matrix: undefined, Planar_set: undefined, Point: undefined, diff --git a/src/utils/errors.js b/src/utils/errors.js index 990b9e54..e77ca068 100644 --- a/src/utils/errors.js +++ b/src/utils/errors.js @@ -2,10 +2,12 @@ * Created by Alex Bol on 2/19/2017. */ +import Flatten from "../flatten"; + /** * Class of system errors */ -class Errors { +export class Errors { /** * Throw error ILLEGAL_PARAMETERS when cannot instantiate from given parameter * @returns {ReferenceError} @@ -39,6 +41,10 @@ class Errors { return new Error('Infinite loop'); } + static get CANNOT_COMPLETE_BOOLEAN_OPERATION() { + return new Error('Cannot complete boolean operation') + } + static get CANNOT_INVOKE_ABSTRACT_METHOD() { return new Error('Abstract method cannot be invoked'); } @@ -48,4 +54,4 @@ class Errors { } } -export default Errors; +Flatten.Errors = Errors; diff --git a/test/algorithms/boolean_op.js b/test/algorithms/boolean_op.js index 520929f1..3e9c87ea 100644 --- a/test/algorithms/boolean_op.js +++ b/test/algorithms/boolean_op.js @@ -5,15 +5,10 @@ 'use strict'; import {expect} from 'chai'; -//import Flatten from 'https://unpkg.com/@flatten-js/core'; -//import {Polygon} from 'https://unpkg.com/@flatten-js/core'; -//import {point, segment, arc, circle} from 'https://unpkg.com/@flatten-js/core'; - import Flatten from '../../index'; - import {Polygon} from '../../index'; import {point, circle, segment, arc} from '../../index'; - +import {Errors} from "../../src/utils/errors"; import * as BooleanOperations from "../../src/algorithms/boolean_op"; let {unify, subtract, intersect} = BooleanOperations; @@ -296,7 +291,7 @@ describe('#Algorithms.Boolean Operations', function () { expect(poly1.faces.size).to.equal(1); expect(poly2.faces.size).to.equal(1); - expect( () => unify(poly1, poly2)).to.throw("Infinite loop") + expect( () => unify(poly1, poly2)).to.throw(Errors.CANNOT_COMPLETE_BOOLEAN_OPERATION.message) // let res = unify(poly1, poly2); // expect(res.faces.size).to.equal(1); // expect(res.edges.size).to.equal(44); @@ -313,7 +308,6 @@ describe('#Algorithms.Boolean Operations', function () { expect(poly1.faces.size).to.equal(1); expect(poly2.faces.size).to.equal(1); - // expect( () => unify(poly1, poly2)).to.throw("Unresolved boundary conflict in boolean operation") let res = unify(poly1, poly2); expect(res.faces.size).to.equal(1); expect(res.edges.size).to.equal(30); @@ -463,22 +457,22 @@ describe('#Algorithms.Boolean Operations', function () { expect(poly.faces.size).to.equal(2); expect(poly.edges.size).to.equal(9); }); - // it('Can perform (boolean) subtraction. First polygon inside the second', function () { - // "use strict"; - // - // let {Polygon, point} = Flatten; - // - // let polygon1 = new Polygon(); - // polygon1.addFace([point(100, 10), point(100, 300), point(400, 150), point(250, 10)]); - // - // let polygon2 = new Polygon(); - // polygon2.addFace([point(50, 0), point(50, 400), point(500, 400), point(500, 0)]); - // - // let poly = subtract(polygon2, polygon1); - // expect(poly.faces.size).to.equal(2); - // expect(poly.edges.size).to.equal(8); - // - // }); + it('Can perform (boolean) subtraction. First polygon inside the second', function () { + "use strict"; + + let {Polygon, point} = Flatten; + + let polygon1 = new Polygon(); + polygon1.addFace([point(100, 10), point(100, 300), point(400, 150), point(250, 10)]); + + let polygon2 = new Polygon(); + polygon2.addFace([point(50, 0), point(50, 400), point(500, 400), point(500, 0)]); + + let poly = subtract(polygon2, polygon1); + expect(poly.faces.size).to.equal(2); + expect(poly.edges.size).to.equal(8); + + }); it('Can perform subtract big polygon from smaller polygon and get empty result (Issue #4)', function() { let polygon1 = new Polygon(); @@ -551,10 +545,9 @@ describe('#Algorithms.Boolean Operations', function () { expect(poly1.faces.size).to.equal(1); expect(poly2.faces.size).to.equal(1); - // expect( () => subtract(poly1, poly2)).to.throw(Flatten.Errors.INFINITE_LOOP.message) let res = subtract(poly1, poly2); - // expect(res.faces.size).to.equal(1); - // expect(res.edges.size).to.equal(42); + expect(res.faces.size).to.equal(6); + expect(res.edges.size).to.equal(30); }); it('Can perform subtract. Fixed: Infinite loop for boolean union over (valid) polygons. Issue #55 case 2', function () { "use strict"; @@ -568,10 +561,9 @@ describe('#Algorithms.Boolean Operations', function () { expect(poly1.faces.size).to.equal(1); expect(poly2.faces.size).to.equal(1); - // expect( () => subtract(poly1, poly2)).to.throw(Flatten.Errors.INFINITE_LOOP.message) let res = subtract(poly1, poly2); - // expect(res.faces.size).to.equal(1); - // expect(res.edges.size).to.equal(11); + expect(res.faces.size).to.equal(3); + expect(res.edges.size).to.equal(11); }); it('Can perform subtract. Fixed: Infinite loop for boolean union over (valid) polygons. Issue #55 case 3', function () { "use strict"; @@ -755,49 +747,36 @@ describe('#Algorithms.Boolean Operations', function () { let myPoly = new Polygon(); myPoly.addFace([point(6, 6), point(6,114), point(114, 114), point(114, 6)]); - // state.layers[state.layers.length] = Layers.newLayer(stage, layers).add(myPoly); // 0 let myCircle = new Polygon(); myCircle.addFace([arc(point(0,0),84.5779281026111, 0, 2*Math.PI, Flatten.CW)]); - // state.layers[state.layers.length] = Layers.newLayer(stage, layers).add(myCircle); // 1 myPoly = intersect(myPoly,myCircle); - // state.layers[state.layers.length] = Layers.newLayer(stage, layers).add(myPoly); // 2 myCircle = new Polygon(); myCircle.addFace([arc(point(0,0),84.49938828627135, 0, 2*Math.PI, Flatten.CW)]); - // state.layers[state.layers.length] = Layers.newLayer(stage, layers).add(myCircle); // 3 myPoly = subtract(myPoly,myCircle); - // state.layers[state.layers.length] = Layers.newLayer(stage, layers).add(myPoly); // 4 myCircle = new Polygon(); myCircle.addFace([arc(point(0,120),84.8710637077582, 0, 2*Math.PI, Flatten.CW)]); - // state.layers[state.layers.length] = Layers.newLayer(stage, layers).add(myCircle); // 5 myPoly = intersect(myPoly,myCircle); - // state.layers[state.layers.length] = Layers.newLayer(stage, layers).add(myPoly); // 6 myCircle = new Polygon(); myCircle.addFace([arc(point(0,120),84.79252389141845, 0, 2*Math.PI, Flatten.CW)]); - // state.layers[state.layers.length] = Layers.newLayer(stage, layers).add(myCircle); // 7 myPoly = subtract(myPoly,myCircle); - // state.layers[state.layers.length] = Layers.newLayer(stage, layers).add(myPoly); // 8 myCircle = new Polygon(); myCircle.addFace([arc(point(120,120),85.20624291591454, 0, 2*Math.PI, Flatten.CW)]); - // state.layers[state.layers.length] = Layers.newLayer(stage, layers).add(myCircle); // 9 myPoly = intersect(myPoly,myCircle); - // state.layers[state.layers.length] = Layers.newLayer(stage, layers).add(myPoly); // 10 myCircle = new Polygon(); myCircle.addFace([arc(point(120,120), 85.1277030995748, 0, 2*Math.PI, Flatten.CW)]); - // state.layers[state.layers.length] = Layers.newLayer(stage, layers).add(myCircle); // 11 myPoly = subtract(myPoly,myCircle); - // state.layers[state.layers.length] = Layers.newLayer(stage, layers).add(myPoly); // 12 expect(myPoly.faces.size).to.equal(1); expect(myPoly.edges.size).to.equal(7); @@ -882,8 +861,6 @@ describe('#Algorithms.Boolean Operations', function () { expect(poly1.faces.size).to.equal(1); expect(poly2.faces.size).to.equal(1); - // expect( () => intersect(poly1, poly2)).to.throw(Flatten.Errors.INFINITE_LOOP.message) - // expect( () => intersect(poly1, poly2)).to.throw("Infinite loop") let res = intersect(poly1, poly2); expect(res.faces.size).to.equal(1); expect(res.edges.size).to.equal(26); diff --git a/test/classes/line.js b/test/classes/line.js index 7afda976..97a8866b 100644 --- a/test/classes/line.js +++ b/test/classes/line.js @@ -5,6 +5,7 @@ import { expect } from 'chai'; import Flatten from '../../index'; +import {Errors} from "../../src/utils/errors"; let {Point, Vector, Circle, Line, Segment, Arc, Box, Polygon, Edge, Face, Ray} = Flatten; @@ -38,23 +39,23 @@ describe('#Flatten.Line', function() { it('Constructor with illegal parameters throws error. Case 1', function () { let pt = new Flatten.Point(1, 1); let fn1 = function() { new Flatten.Line(pt) }; - expect(fn1).to.throw(ReferenceError); + expect(fn1).to.throw(Errors.ILLEGAL_PARAMETERS.message); }); it('Constructor with illegal parameters throws error. Case 2', function () { let pt = new Flatten.Point(1, 1); let fn2 = function() { new Flatten.Line(pt, '123') }; - expect(fn2).to.throw(ReferenceError); + expect(fn2).to.throw(Errors.ILLEGAL_PARAMETERS.message); }); it('Constructor with illegal parameters throws error. Case 3', function () { let pt = new Flatten.Point(1, 1); let fn3 = function() { new Flatten.Line(pt, pt) }; - expect(fn3).to.throw(ReferenceError); + expect(fn3).to.throw(Errors.ILLEGAL_PARAMETERS.message); }); it('Constructor with zero vector throws error', function () { let fn1 = function() { new Flatten.Line(point(1, 1), vector(0,0)) }; let fn2 = function() { new Flatten.Line(vector(0,0), point(1, 1) ) }; - expect(fn1).to.throw(ReferenceError); - expect(fn2).to.throw(ReferenceError); + expect(fn1).to.throw(Errors.ILLEGAL_PARAMETERS.message); + expect(fn2).to.throw(Errors.ILLEGAL_PARAMETERS.message); }); it('New line may be constructed by function call', function() { let l = line(point(1,3), point(3,3)); diff --git a/test/classes/point.js b/test/classes/point.js index 1f81aa9f..cc321159 100644 --- a/test/classes/point.js +++ b/test/classes/point.js @@ -3,111 +3,113 @@ */ 'use strict'; -import { expect } from 'chai'; -import Flatten from '../../index'; +import {expect} from 'chai'; import {Point, Vector, Circle, Line, Segment, Arc, Box, Polygon, Edge, Face, Ray} from '../../index'; import {point, vector, circle, line, segment, arc, ray, matrix} from '../../index'; +import {Errors} from "../../src/utils/errors"; -describe('#Flatten.Point', function() { - it('May create new Point', function() { +describe('#Flatten.Point', function () { + it('May create new Point', function () { let point = new Point(); expect(point).to.be.an.instanceof(Point); }); - it('Default constructor creates new (0,0) point', function() { + it('Default constructor creates new (0,0) point', function () { let point = new Point(); - expect(point).to.deep.equal({x:0, y:0}); + expect(point).to.deep.equal({x: 0, y: 0}); }); - it('New point may be constructed by function call', function() { - expect(point(1,3)).to.deep.equal({x:1, y:3}); + it('New point may be constructed by function call', function () { + expect(point(1, 3)).to.deep.equal({x: 1, y: 3}); }); - it('New point may be constructed with array of two numbers', function() { - expect(point([1,3])).to.deep.equal({x:1, y:3}); + it('New point may be constructed with array of two numbers', function () { + expect(point([1, 3])).to.deep.equal({x: 1, y: 3}); }); - it('Constructor with illegal parameters throw error', function() { + it('Constructor with illegal parameters throw error', function () { let fn = function () { return new Point(1, "1"); }; - expect(fn).to.throw(ReferenceError); + expect(fn).to.throw(Errors.ILLEGAL_PARAMETERS.message); }); - it('Method clone creates new instance of Point', function() { - let point1 = new Point(2,1); + it('Method clone creates new instance of Point', function () { + let point1 = new Point(2, 1); let point2 = point1.clone(); expect(point2).to.be.an.instanceof(Point); expect(point2).to.not.equal(point1); expect(point2).to.deep.equal(point1); }); - it('Method equalTo return true if points are equal', function() { + it('Method equalTo return true if points are equal', function () { let point = new Point(); - let zero = new Point(0,0); + let zero = new Point(0, 0); let equals = point.equalTo(zero); expect(equals).to.equal(true); }); - it('Method equalTo return true if points are equal up to DP_TOL tolerance', function() { - let point1 = new Point(1,1); - let point2 = new Point(1,1.000000999); + it('Method equalTo return true if points are equal up to DP_TOL tolerance', function () { + let point1 = new Point(1, 1); + let point2 = new Point(1, 1.000000999); let equals = point1.equalTo(point2); expect(equals).to.equal(true); }); - it ('Method translate returns new point translated by (dx, dy)', function() { - let point = new Point(1,1); - let tpoint = point.translate(2,0); - expect(tpoint).to.deep.equal({x:3,y:1}); + it('Method translate returns new point translated by (dx, dy)', function () { + let point = new Point(1, 1); + let tpoint = point.translate(2, 0); + expect(tpoint).to.deep.equal({x: 3, y: 1}); }); - it ('Method rotates returns new point rotated by default around (0.0), counterclockwise', function() { - let point = new Point(1,1); - let rotated_point = point.rotate(Math.PI/2); + it('Method rotates returns new point rotated by default around (0.0), counterclockwise', function () { + let point = new Point(1, 1); + let rotated_point = point.rotate(Math.PI / 2); let expected_point = new Point(-1, 1); let equals = rotated_point.equalTo(expected_point); expect(equals).to.equal(true); }); - it ('Method rotate returns new point rotated around center, counterclockwise', function() { - let point = new Point(2,1); - let center = new Point(1,1); - let rotated_point = point.rotate(Math.PI/2, center); + it('Method rotate returns new point rotated around center, counterclockwise', function () { + let point = new Point(2, 1); + let center = new Point(1, 1); + let rotated_point = point.rotate(Math.PI / 2, center); let expected_point = new Point(1, 2); let equals = rotated_point.equalTo(expected_point); expect(equals).to.equal(true); }); - it ('Method translate returns new point translated by vector', function() { - let point = new Point(1,1); - let v = new Vector(2,0); + it('Method translate returns new point translated by vector', function () { + let point = new Point(1, 1); + let v = new Vector(2, 0); let tpoint = point.translate(v); - expect(tpoint).to.deep.equal({x:3,y:1}); + expect(tpoint).to.deep.equal({x: 3, y: 1}); }); - it('Can scale point with scale factor', function() { - const point = new Point(2,3); - const scaled_point = point.scale(2,2); - expect(scaled_point).to.deep.equal({x:4, y:6}) + it('Can scale point with scale factor', function () { + const point = new Point(2, 3); + const scaled_point = point.scale(2, 2); + expect(scaled_point).to.deep.equal({x: 4, y: 6}) }); it('Method translate with illegal parameters throws error', function () { - let point = new Point(1,1); - let v = new Vector(2,0); - let fn = function() { return point.translate(v,1) }; - expect(fn).to.throw(ReferenceError); - }); - it ('Method returns projection point on given line', function() { - let anchor = new Point(1,1); - let norm = new Vector(0,1); + let point = new Point(1, 1); + let v = new Vector(2, 0); + let fn = function () { + return point.translate(v, 1) + }; + expect(fn).to.throw(Errors.ILLEGAL_PARAMETERS.message); + }); + it('Method returns projection point on given line', function () { + let anchor = new Point(1, 1); + let norm = new Vector(0, 1); let line = new Line(anchor, norm); - let pt = new Point(2,2); + let pt = new Point(2, 2); let proj_pt = pt.projectionOn(line); - expect(proj_pt).to.deep.equal({x:2,y:1}); + expect(proj_pt).to.deep.equal({x: 2, y: 1}); }); - it('Method transform returns new point transformed by affine transformation matrix',function() { - let pt = point(4,1); - let pc = point(1,1); + it('Method transform returns new point transformed by affine transformation matrix', function () { + let pt = point(4, 1); + let pc = point(1, 1); // Transform coordinate origin into point x,y, then rotate, then transform origin back - let m = matrix().translate(pc.x,pc.y).rotate(3*Math.PI/2).translate(-pc.x,-pc.y); + let m = matrix().translate(pc.x, pc.y).rotate(3 * Math.PI / 2).translate(-pc.x, -pc.y); let transformed_pt = pt.transform(m); - let expected_pt = point(1,-2); + let expected_pt = point(1, -2); expect(transformed_pt.equalTo(expected_pt)).to.be.true; }); - describe('#Flatten.Point.Distance methods', function() { - it('Method distanceTo return distance to other point ', function() { - let point1 = new Point(1,1); - let point2 = new Point(2,2); + describe('#Flatten.Point.Distance methods', function () { + it('Method distanceTo return distance to other point ', function () { + let point1 = new Point(1, 1); + let point2 = new Point(2, 2); let [dist, shortest_segment] = point1.distanceTo(point2); expect(dist).to.equal(Math.sqrt(2)); }); @@ -119,12 +121,12 @@ describe('#Flatten.Point', function() { expect(pt.distanceTo(line)[0]).to.equal(1); }); it('Method distanceTo returns distance to segment', function () { - let ps = new Point(-2,2); - let pe = new Point(2,2); + let ps = new Point(-2, 2); + let pe = new Point(2, 2); let segment = new Segment(ps, pe); - let pt1 = new Point(2,4); /* point in segment scope */ - let pt2 = new Point(-5,2); /* point is out of segment scope */ - let pt3 = new Point(6,2); /* point is out of segment scope */ + let pt1 = new Point(2, 4); /* point in segment scope */ + let pt2 = new Point(-5, 2); /* point is out of segment scope */ + let pt3 = new Point(6, 2); /* point is out of segment scope */ expect(pt1.distanceTo(segment)[0]).to.equal(2); expect(pt2.distanceTo(segment)[0]).to.equal(3); @@ -132,20 +134,20 @@ describe('#Flatten.Point', function() { }); it('Method distanceTo returns distance to circle', function () { let circle = new Circle(new Point(), 3); - let pt1 = new Point(5,0); - let pt2 = new Point(0,2); + let pt1 = new Point(5, 0); + let pt2 = new Point(0, 2); expect(pt1.distanceTo(circle)[0]).to.equal(2); expect(pt2.distanceTo(circle)[0]).to.equal(1); }); it('Method distanceTo returns distance to arc', function () { let circle = new Circle(new Point(), 3); let arc = circle.toArc(); - let pt1 = new Point(5,0); - let pt2 = new Point(0,2); + let pt1 = new Point(5, 0); + let pt2 = new Point(0, 2); expect(pt1.distanceTo(arc)[0]).to.equal(2); expect(pt2.distanceTo(arc)[0]).to.equal(1); }); - it('Method distanceTo returns distance to polygon', function() { + it('Method distanceTo returns distance to polygon', function () { let points = [ point(100, 20), point(250, 75), @@ -163,7 +165,7 @@ describe('#Flatten.Point', function() { expect(pt.distanceTo(poly)[0]).to.equal(25); }) }); - describe('#Flatten.Point.On inclusion queries', function() { + describe('#Flatten.Point.On inclusion queries', function () { it('Method "on" returns true if point checked with same points', function () { let pt = new Point(0, 1); expect(pt.on(pt.clone())).to.equal(true); @@ -188,11 +190,11 @@ describe('#Flatten.Point', function() { expect(pt2.on(segment)).to.equal(true); }); it('Method "on" returns true if point belongs to arc', function () { - let arc = new Arc(new Point(), 1, -Math.PI/4, Math.PI/4, false); - let pt = new Point(-1,0); + let arc = new Arc(new Point(), 1, -Math.PI / 4, Math.PI / 4, false); + let pt = new Point(-1, 0); expect(pt.on(arc)).to.equal(true); }); - it('Method "on" returns true if point belong to polygon', function() { + it('Method "on" returns true if point belong to polygon', function () { let points = [ point(100, 20), point(250, 75), @@ -205,7 +207,7 @@ describe('#Flatten.Point', function() { let poly = new Polygon(); poly.addFace(points); - poly.addFace([circle(point(175,150), 30).toArc()]); + poly.addFace([circle(point(175, 150), 30).toArc()]); let pt1 = point(300, 50); let pt2 = point(50, 75); @@ -218,34 +220,34 @@ describe('#Flatten.Point', function() { expect(pt4.on(poly)).to.equal(true); }) }); - it('Method leftTo returns true if point is on the "left" semi plane, which is the side of the normal vector', function() { - let line = new Line(new Point(-1, -1), new Point(1,1)); - let pt1 = new Point(-2,2); - let pt2 = new Point(3,1); + it('Method leftTo returns true if point is on the "left" semi plane, which is the side of the normal vector', function () { + let line = new Line(new Point(-1, -1), new Point(1, 1)); + let pt1 = new Point(-2, 2); + let pt2 = new Point(3, 1); expect(pt1.leftTo(line)).to.equal(true); expect(pt2.leftTo(line)).to.equal(false); }); - it('Method svg() without parameters creates svg string with default attributes', function() { - let pt = new Point(-2,2); + it('Method svg() without parameters creates svg string with default attributes', function () { + let pt = new Point(-2, 2); let svg = pt.svg(); expect(svg.search("stroke")).to.not.equal(-1); }); - it('Method svg() with extra parameters may add additional attributes', function() { - let pt = new Point(-2,2); - let svg = pt.svg({id:"123",className:"name", r: 5, fill: "green"}); + it('Method svg() with extra parameters may add additional attributes', function () { + let pt = new Point(-2, 2); + let svg = pt.svg({id: "123", className: "name", r: 5, fill: "green"}); expect(svg.search("stroke")).to.not.equal(-1); expect(svg.search("id")).to.not.equal(-1); expect(svg.search("class")).to.not.equal(-1); }); - it('May stringify and parse point', function() { - let pt = new Point(-20,30); + it('May stringify and parse point', function () { + let pt = new Point(-20, 30); let str = JSON.stringify(pt); let pt_json = JSON.parse(str); let pt_new = new Point(pt_json); expect(pt_new).to.deep.equal(pt); }); - it('May stringify and parse array of points', function() { - let pts = [point(-20,30), point(-5,18), point(40,28)]; + it('May stringify and parse array of points', function () { + let pts = [point(-20, 30), point(-5, 18), point(40, 28)]; let str = JSON.stringify(pts); let pts_json = JSON.parse(str); let pts_new = pts_json.map(pt_json => point(pt_json)); diff --git a/test/classes/segment.js b/test/classes/segment.js index 35995bd2..1ba6821a 100644 --- a/test/classes/segment.js +++ b/test/classes/segment.js @@ -8,6 +8,7 @@ import Flatten from '../../index'; import {Point, Vector, Circle, Line, Segment, Arc, Box, Polygon, Edge, Face, Ray} from '../../index'; import {point, vector, circle, line, segment, arc, ray} from '../../index'; +import {Errors} from "../../src/utils/errors"; describe('#Flatten.Segment', function() { it('May create new instance of Segment', function () { @@ -39,7 +40,7 @@ describe('#Flatten.Segment', function() { }); it('Constructor with illegal parameters throw error', function() { let fn = function () {new Segment([1,2,3])}; - expect(fn).to.throw(ReferenceError); + expect(fn).to.throw(Errors.ILLEGAL_PARAMETERS.message); }); it('Method clone copy to a new instance of Segment', function () { let ps = new Point(1,1); diff --git a/test/classes/vector.js b/test/classes/vector.js index 364a553a..d6b2ab7c 100644 --- a/test/classes/vector.js +++ b/test/classes/vector.js @@ -6,6 +6,7 @@ import { expect } from 'chai'; import Flatten from '../../index'; +import {Errors} from "../../src/utils/errors"; import {Point, Vector, Circle, Line, Segment, Arc, Box, Polygon, Edge, Face, Ray} from '../../index'; import {point, vector, circle, line, segment, arc, ray} from '../../index'; @@ -36,7 +37,7 @@ describe('#Flatten.Vector', function() { it('Constructor Vector with illegal parameters throw error', function () { let ps = new Point(1,1); let fn = function() { new Vector(ps,2) }; - expect(fn).to.throw(ReferenceError); + expect(fn).to.throw(Errors.ILLEGAL_PARAMETERS.message); }); it('New vector may be constructed by function call', function() { expect(vector(point(1,1), point(3,3))).to.deep.equal({x:2, y:2}); @@ -85,7 +86,7 @@ describe('#Flatten.Vector', function() { it('Method normalize throw error on zero length vector', function () { let v = new Vector(0,0); let fn = function() { v.normalize() }; - expect(fn).to.throw(Error); + expect(fn).to.throw(Errors.ZERO_DIVISION.message); }); it ('Method rotate returns new vector rotated by given angle, positive angle defines rotation in counterclockwise direction', function() { let vector = new Vector(1,1);