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 @@
Flatten.Errors.INFINITE_LOOP
+Errors.INFINITE_LOOP
@@ -1094,7 +1094,7 @@ vector
args
Vector
-
-
-
tx
number
-
-
-
- ty
number
-
-
-
-