@joint/core 4.0.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/LICENSE +376 -0
- package/README.md +49 -0
- package/dist/geometry.js +6486 -0
- package/dist/geometry.min.js +8 -0
- package/dist/joint.d.ts +5536 -0
- package/dist/joint.js +39629 -0
- package/dist/joint.min.js +8 -0
- package/dist/joint.nowrap.js +39626 -0
- package/dist/joint.nowrap.min.js +8 -0
- package/dist/vectorizer.js +9135 -0
- package/dist/vectorizer.min.js +8 -0
- package/dist/version.mjs +3 -0
- package/index.js +3 -0
- package/joint.mjs +27 -0
- package/package.json +192 -0
- package/src/V/annotation.mjs +0 -0
- package/src/V/index.mjs +2642 -0
- package/src/anchors/index.mjs +123 -0
- package/src/config/index.mjs +12 -0
- package/src/connectionPoints/index.mjs +202 -0
- package/src/connectionStrategies/index.mjs +73 -0
- package/src/connectors/curve.mjs +553 -0
- package/src/connectors/index.mjs +6 -0
- package/src/connectors/jumpover.mjs +452 -0
- package/src/connectors/normal.mjs +12 -0
- package/src/connectors/rounded.mjs +17 -0
- package/src/connectors/smooth.mjs +44 -0
- package/src/connectors/straight.mjs +110 -0
- package/src/dia/Cell.mjs +945 -0
- package/src/dia/CellView.mjs +1316 -0
- package/src/dia/Element.mjs +519 -0
- package/src/dia/ElementView.mjs +859 -0
- package/src/dia/Graph.mjs +1112 -0
- package/src/dia/HighlighterView.mjs +319 -0
- package/src/dia/Link.mjs +565 -0
- package/src/dia/LinkView.mjs +2207 -0
- package/src/dia/Paper.mjs +3171 -0
- package/src/dia/PaperLayer.mjs +75 -0
- package/src/dia/ToolView.mjs +69 -0
- package/src/dia/ToolsView.mjs +128 -0
- package/src/dia/attributes/calc.mjs +128 -0
- package/src/dia/attributes/connection.mjs +75 -0
- package/src/dia/attributes/defs.mjs +76 -0
- package/src/dia/attributes/eval.mjs +64 -0
- package/src/dia/attributes/index.mjs +69 -0
- package/src/dia/attributes/legacy.mjs +148 -0
- package/src/dia/attributes/offset.mjs +53 -0
- package/src/dia/attributes/props.mjs +30 -0
- package/src/dia/attributes/shape.mjs +92 -0
- package/src/dia/attributes/text.mjs +180 -0
- package/src/dia/index.mjs +13 -0
- package/src/dia/layers/GridLayer.mjs +176 -0
- package/src/dia/ports.mjs +874 -0
- package/src/elementTools/Control.mjs +153 -0
- package/src/elementTools/HoverConnect.mjs +37 -0
- package/src/elementTools/index.mjs +5 -0
- package/src/env/index.mjs +43 -0
- package/src/g/bezier.mjs +175 -0
- package/src/g/curve.mjs +956 -0
- package/src/g/ellipse.mjs +245 -0
- package/src/g/extend.mjs +64 -0
- package/src/g/geometry.helpers.mjs +58 -0
- package/src/g/index.mjs +17 -0
- package/src/g/intersection.mjs +511 -0
- package/src/g/line.bearing.mjs +30 -0
- package/src/g/line.length.mjs +5 -0
- package/src/g/line.mjs +356 -0
- package/src/g/line.squaredLength.mjs +10 -0
- package/src/g/path.mjs +2260 -0
- package/src/g/point.mjs +375 -0
- package/src/g/points.mjs +247 -0
- package/src/g/polygon.mjs +51 -0
- package/src/g/polyline.mjs +523 -0
- package/src/g/rect.mjs +556 -0
- package/src/g/types.mjs +10 -0
- package/src/highlighters/addClass.mjs +27 -0
- package/src/highlighters/index.mjs +5 -0
- package/src/highlighters/list.mjs +111 -0
- package/src/highlighters/mask.mjs +220 -0
- package/src/highlighters/opacity.mjs +17 -0
- package/src/highlighters/stroke.mjs +100 -0
- package/src/layout/index.mjs +4 -0
- package/src/layout/ports/port.mjs +188 -0
- package/src/layout/ports/portLabel.mjs +224 -0
- package/src/linkAnchors/index.mjs +76 -0
- package/src/linkTools/Anchor.mjs +235 -0
- package/src/linkTools/Arrowhead.mjs +103 -0
- package/src/linkTools/Boundary.mjs +48 -0
- package/src/linkTools/Button.mjs +121 -0
- package/src/linkTools/Connect.mjs +85 -0
- package/src/linkTools/HoverConnect.mjs +161 -0
- package/src/linkTools/Segments.mjs +393 -0
- package/src/linkTools/Vertices.mjs +253 -0
- package/src/linkTools/helpers.mjs +33 -0
- package/src/linkTools/index.mjs +8 -0
- package/src/mvc/Collection.mjs +560 -0
- package/src/mvc/Data.mjs +46 -0
- package/src/mvc/Dom/Dom.mjs +587 -0
- package/src/mvc/Dom/Event.mjs +130 -0
- package/src/mvc/Dom/animations.mjs +122 -0
- package/src/mvc/Dom/events.mjs +69 -0
- package/src/mvc/Dom/index.mjs +13 -0
- package/src/mvc/Dom/methods.mjs +392 -0
- package/src/mvc/Dom/props.mjs +77 -0
- package/src/mvc/Dom/vars.mjs +5 -0
- package/src/mvc/Events.mjs +337 -0
- package/src/mvc/Listener.mjs +33 -0
- package/src/mvc/Model.mjs +239 -0
- package/src/mvc/View.mjs +323 -0
- package/src/mvc/ViewBase.mjs +182 -0
- package/src/mvc/index.mjs +9 -0
- package/src/mvc/mvcUtils.mjs +90 -0
- package/src/polyfills/array.js +4 -0
- package/src/polyfills/base64.js +68 -0
- package/src/polyfills/index.mjs +5 -0
- package/src/polyfills/number.js +3 -0
- package/src/polyfills/string.js +3 -0
- package/src/polyfills/typedArray.js +47 -0
- package/src/routers/index.mjs +6 -0
- package/src/routers/manhattan.mjs +856 -0
- package/src/routers/metro.mjs +91 -0
- package/src/routers/normal.mjs +6 -0
- package/src/routers/oneSide.mjs +60 -0
- package/src/routers/orthogonal.mjs +323 -0
- package/src/routers/rightAngle.mjs +1056 -0
- package/src/shapes/index.mjs +3 -0
- package/src/shapes/standard.mjs +755 -0
- package/src/util/cloneCells.mjs +67 -0
- package/src/util/getRectPoint.mjs +65 -0
- package/src/util/index.mjs +5 -0
- package/src/util/svgTagTemplate.mjs +110 -0
- package/src/util/util.mjs +1754 -0
- package/src/util/utilHelpers.mjs +2402 -0
- package/src/util/wrappers.mjs +56 -0
- package/types/geometry.d.ts +815 -0
- package/types/index.d.ts +53 -0
- package/types/joint.d.ts +4391 -0
- package/types/joint.head.d.ts +12 -0
- package/types/vectorizer.d.ts +327 -0
|
@@ -0,0 +1,245 @@
|
|
|
1
|
+
import { Rect } from './rect.mjs';
|
|
2
|
+
import { Point } from './point.mjs';
|
|
3
|
+
import { types } from './types.mjs';
|
|
4
|
+
|
|
5
|
+
const {
|
|
6
|
+
sqrt,
|
|
7
|
+
round,
|
|
8
|
+
pow
|
|
9
|
+
} = Math;
|
|
10
|
+
|
|
11
|
+
export const Ellipse = function(c, a, b) {
|
|
12
|
+
|
|
13
|
+
if (!(this instanceof Ellipse)) {
|
|
14
|
+
return new Ellipse(c, a, b);
|
|
15
|
+
}
|
|
16
|
+
|
|
17
|
+
if (c instanceof Ellipse) {
|
|
18
|
+
return new Ellipse(new Point(c.x, c.y), c.a, c.b);
|
|
19
|
+
}
|
|
20
|
+
|
|
21
|
+
c = new Point(c);
|
|
22
|
+
this.x = c.x;
|
|
23
|
+
this.y = c.y;
|
|
24
|
+
this.a = a;
|
|
25
|
+
this.b = b;
|
|
26
|
+
};
|
|
27
|
+
|
|
28
|
+
Ellipse.fromRect = function(rect) {
|
|
29
|
+
|
|
30
|
+
rect = new Rect(rect);
|
|
31
|
+
return new Ellipse(rect.center(), rect.width / 2, rect.height / 2);
|
|
32
|
+
};
|
|
33
|
+
|
|
34
|
+
Ellipse.prototype = {
|
|
35
|
+
|
|
36
|
+
type: types.Ellipse,
|
|
37
|
+
|
|
38
|
+
bbox: function() {
|
|
39
|
+
|
|
40
|
+
return new Rect(this.x - this.a, this.y - this.b, 2 * this.a, 2 * this.b);
|
|
41
|
+
},
|
|
42
|
+
|
|
43
|
+
/**
|
|
44
|
+
* @returns {g.Point}
|
|
45
|
+
*/
|
|
46
|
+
center: function() {
|
|
47
|
+
|
|
48
|
+
return new Point(this.x, this.y);
|
|
49
|
+
},
|
|
50
|
+
|
|
51
|
+
clone: function() {
|
|
52
|
+
|
|
53
|
+
return new Ellipse(this);
|
|
54
|
+
},
|
|
55
|
+
|
|
56
|
+
/**
|
|
57
|
+
* @param {g.Point} p
|
|
58
|
+
* @returns {boolean}
|
|
59
|
+
*/
|
|
60
|
+
containsPoint: function(p) {
|
|
61
|
+
|
|
62
|
+
return this.normalizedDistance(p) <= 1;
|
|
63
|
+
},
|
|
64
|
+
|
|
65
|
+
equals: function(ellipse) {
|
|
66
|
+
|
|
67
|
+
return !!ellipse &&
|
|
68
|
+
ellipse.x === this.x &&
|
|
69
|
+
ellipse.y === this.y &&
|
|
70
|
+
ellipse.a === this.a &&
|
|
71
|
+
ellipse.b === this.b;
|
|
72
|
+
},
|
|
73
|
+
|
|
74
|
+
// inflate by dx and dy
|
|
75
|
+
// @param dx {delta_x} representing additional size to x
|
|
76
|
+
// @param dy {delta_y} representing additional size to y -
|
|
77
|
+
// dy param is not required -> in that case y is sized by dx
|
|
78
|
+
inflate: function(dx, dy) {
|
|
79
|
+
if (dx === undefined) {
|
|
80
|
+
dx = 0;
|
|
81
|
+
}
|
|
82
|
+
|
|
83
|
+
if (dy === undefined) {
|
|
84
|
+
dy = dx;
|
|
85
|
+
}
|
|
86
|
+
|
|
87
|
+
this.a += 2 * dx;
|
|
88
|
+
this.b += 2 * dy;
|
|
89
|
+
|
|
90
|
+
return this;
|
|
91
|
+
},
|
|
92
|
+
|
|
93
|
+
intersectionWithLine: function(line) {
|
|
94
|
+
|
|
95
|
+
var intersections = [];
|
|
96
|
+
var a1 = line.start;
|
|
97
|
+
var a2 = line.end;
|
|
98
|
+
var rx = this.a;
|
|
99
|
+
var ry = this.b;
|
|
100
|
+
var dir = line.vector();
|
|
101
|
+
var diff = a1.difference(new Point(this));
|
|
102
|
+
var mDir = new Point(dir.x / (rx * rx), dir.y / (ry * ry));
|
|
103
|
+
var mDiff = new Point(diff.x / (rx * rx), diff.y / (ry * ry));
|
|
104
|
+
|
|
105
|
+
var a = dir.dot(mDir);
|
|
106
|
+
var b = dir.dot(mDiff);
|
|
107
|
+
var c = diff.dot(mDiff) - 1.0;
|
|
108
|
+
var d = b * b - a * c;
|
|
109
|
+
|
|
110
|
+
if (d < 0) {
|
|
111
|
+
return null;
|
|
112
|
+
} else if (d > 0) {
|
|
113
|
+
var root = sqrt(d);
|
|
114
|
+
var ta = (-b - root) / a;
|
|
115
|
+
var tb = (-b + root) / a;
|
|
116
|
+
|
|
117
|
+
if ((ta < 0 || 1 < ta) && (tb < 0 || 1 < tb)) {
|
|
118
|
+
// if ((ta < 0 && tb < 0) || (ta > 1 && tb > 1)) outside else inside
|
|
119
|
+
return null;
|
|
120
|
+
} else {
|
|
121
|
+
if (0 <= ta && ta <= 1) intersections.push(a1.lerp(a2, ta));
|
|
122
|
+
if (0 <= tb && tb <= 1) intersections.push(a1.lerp(a2, tb));
|
|
123
|
+
}
|
|
124
|
+
} else {
|
|
125
|
+
var t = -b / a;
|
|
126
|
+
if (0 <= t && t <= 1) {
|
|
127
|
+
intersections.push(a1.lerp(a2, t));
|
|
128
|
+
} else {
|
|
129
|
+
// outside
|
|
130
|
+
return null;
|
|
131
|
+
}
|
|
132
|
+
}
|
|
133
|
+
|
|
134
|
+
return intersections;
|
|
135
|
+
},
|
|
136
|
+
|
|
137
|
+
// Find point on me where line from my center to
|
|
138
|
+
// point p intersects my boundary.
|
|
139
|
+
// @param {number} angle If angle is specified, intersection with rotated ellipse is computed.
|
|
140
|
+
intersectionWithLineFromCenterToPoint: function(p, angle) {
|
|
141
|
+
|
|
142
|
+
p = new Point(p);
|
|
143
|
+
|
|
144
|
+
if (angle) p.rotate(new Point(this.x, this.y), angle);
|
|
145
|
+
|
|
146
|
+
var dx = p.x - this.x;
|
|
147
|
+
var dy = p.y - this.y;
|
|
148
|
+
var result;
|
|
149
|
+
|
|
150
|
+
if (dx === 0) {
|
|
151
|
+
result = this.bbox().pointNearestToPoint(p);
|
|
152
|
+
if (angle) return result.rotate(new Point(this.x, this.y), -angle);
|
|
153
|
+
return result;
|
|
154
|
+
}
|
|
155
|
+
|
|
156
|
+
var m = dy / dx;
|
|
157
|
+
var mSquared = m * m;
|
|
158
|
+
var aSquared = this.a * this.a;
|
|
159
|
+
var bSquared = this.b * this.b;
|
|
160
|
+
|
|
161
|
+
var x = sqrt(1 / ((1 / aSquared) + (mSquared / bSquared)));
|
|
162
|
+
x = dx < 0 ? -x : x;
|
|
163
|
+
|
|
164
|
+
var y = m * x;
|
|
165
|
+
result = new Point(this.x + x, this.y + y);
|
|
166
|
+
|
|
167
|
+
if (angle) return result.rotate(new Point(this.x, this.y), -angle);
|
|
168
|
+
return result;
|
|
169
|
+
},
|
|
170
|
+
|
|
171
|
+
/**
|
|
172
|
+
* @param {g.Point} point
|
|
173
|
+
* @returns {number} result < 1 - inside ellipse, result == 1 - on ellipse boundary, result > 1 - outside
|
|
174
|
+
*/
|
|
175
|
+
normalizedDistance: function(point) {
|
|
176
|
+
|
|
177
|
+
var x0 = point.x;
|
|
178
|
+
var y0 = point.y;
|
|
179
|
+
var a = this.a;
|
|
180
|
+
var b = this.b;
|
|
181
|
+
var x = this.x;
|
|
182
|
+
var y = this.y;
|
|
183
|
+
|
|
184
|
+
return ((x0 - x) * (x0 - x)) / (a * a) + ((y0 - y) * (y0 - y)) / (b * b);
|
|
185
|
+
},
|
|
186
|
+
|
|
187
|
+
round: function(precision) {
|
|
188
|
+
|
|
189
|
+
let f = 1; // case 0
|
|
190
|
+
if (precision) {
|
|
191
|
+
switch (precision) {
|
|
192
|
+
case 1: f = 10; break;
|
|
193
|
+
case 2: f = 100; break;
|
|
194
|
+
case 3: f = 1000; break;
|
|
195
|
+
default: f = pow(10, precision); break;
|
|
196
|
+
}
|
|
197
|
+
}
|
|
198
|
+
|
|
199
|
+
this.x = round(this.x * f) / f;
|
|
200
|
+
this.y = round(this.y * f) / f;
|
|
201
|
+
this.a = round(this.a * f) / f;
|
|
202
|
+
this.b = round(this.b * f) / f;
|
|
203
|
+
return this;
|
|
204
|
+
},
|
|
205
|
+
|
|
206
|
+
/** Compute angle between tangent and x axis
|
|
207
|
+
* @param {g.Point} p Point of tangency, it has to be on ellipse boundaries.
|
|
208
|
+
* @returns {number} angle between tangent and x axis
|
|
209
|
+
*/
|
|
210
|
+
tangentTheta: function(p) {
|
|
211
|
+
|
|
212
|
+
var refPointDelta = 30;
|
|
213
|
+
var x0 = p.x;
|
|
214
|
+
var y0 = p.y;
|
|
215
|
+
var a = this.a;
|
|
216
|
+
var b = this.b;
|
|
217
|
+
var center = this.bbox().center();
|
|
218
|
+
var m = center.x;
|
|
219
|
+
var n = center.y;
|
|
220
|
+
|
|
221
|
+
var q1 = x0 > center.x + a / 2;
|
|
222
|
+
var q3 = x0 < center.x - a / 2;
|
|
223
|
+
|
|
224
|
+
var y, x;
|
|
225
|
+
if (q1 || q3) {
|
|
226
|
+
y = x0 > center.x ? y0 - refPointDelta : y0 + refPointDelta;
|
|
227
|
+
x = (a * a / (x0 - m)) - (a * a * (y0 - n) * (y - n)) / (b * b * (x0 - m)) + m;
|
|
228
|
+
|
|
229
|
+
} else {
|
|
230
|
+
x = y0 > center.y ? x0 + refPointDelta : x0 - refPointDelta;
|
|
231
|
+
y = (b * b / (y0 - n)) - (b * b * (x0 - m) * (x - m)) / (a * a * (y0 - n)) + n;
|
|
232
|
+
}
|
|
233
|
+
|
|
234
|
+
return (new Point(x, y)).theta(p);
|
|
235
|
+
|
|
236
|
+
},
|
|
237
|
+
|
|
238
|
+
toString: function() {
|
|
239
|
+
|
|
240
|
+
return (new Point(this.x, this.y)).toString() + ' ' + this.a + ' ' + this.b;
|
|
241
|
+
}
|
|
242
|
+
};
|
|
243
|
+
|
|
244
|
+
// For backwards compatibility:
|
|
245
|
+
export const ellipse = Ellipse;
|
package/src/g/extend.mjs
ADDED
|
@@ -0,0 +1,64 @@
|
|
|
1
|
+
// Local helper function.
|
|
2
|
+
// Add properties from arguments on top of properties from `obj`.
|
|
3
|
+
// This allows for rudimentary inheritance.
|
|
4
|
+
// - The `obj` argument acts as parent.
|
|
5
|
+
// - This function creates a new object that inherits all `obj` properties and adds/replaces those that are present in arguments.
|
|
6
|
+
// - A high-level example: calling `extend(Vehicle, Car)` would be akin to declaring `class Car extends Vehicle`.
|
|
7
|
+
export function extend(obj) {
|
|
8
|
+
// In JavaScript, the combination of a constructor function (e.g. `g.Line = function(...) {...}`) and prototype (e.g. `g.Line.prototype = {...}) is akin to a C++ class.
|
|
9
|
+
// - When inheritance is not necessary, we can leave it at that. (This would be akin to calling extend with only `obj`.)
|
|
10
|
+
// - But, what if we wanted the `g.Line` quasiclass to inherit from another quasiclass (let's call it `g.GeometryObject`) in JavaScript?
|
|
11
|
+
// - First, realize that both of those quasiclasses would still have their own separate constructor function.
|
|
12
|
+
// - So what we are actually saying is that we want the `g.Line` prototype to inherit from `g.GeometryObject` prototype.
|
|
13
|
+
// - This method provides a way to do exactly that.
|
|
14
|
+
// - It copies parent prototype's properties, then adds extra ones from child prototype/overrides parent prototype properties with child prototype properties.
|
|
15
|
+
// - Therefore, to continue with the example above:
|
|
16
|
+
// - `g.Line.prototype = extend(g.GeometryObject.prototype, linePrototype)`
|
|
17
|
+
// - Where `linePrototype` is a properties object that looks just like `g.Line.prototype` does right now.
|
|
18
|
+
// - Then, `g.Line` would allow the programmer to access to all methods currently in `g.Line.Prototype`, plus any non-overridden methods from `g.GeometryObject.prototype`.
|
|
19
|
+
// - In that aspect, `g.GeometryObject` would then act like the parent of `g.Line`.
|
|
20
|
+
// - Multiple inheritance is also possible, if multiple arguments are provided.
|
|
21
|
+
// - What if we wanted to add another level of abstraction between `g.GeometryObject` and `g.Line` (let's call it `g.LinearObject`)?
|
|
22
|
+
// - `g.Line.prototype = extend(g.GeometryObject.prototype, g.LinearObject.prototype, linePrototype)`
|
|
23
|
+
// - The ancestors are applied in order of appearance.
|
|
24
|
+
// - That means that `g.Line` would have inherited from `g.LinearObject` that would have inherited from `g.GeometryObject`.
|
|
25
|
+
// - Any number of ancestors may be provided.
|
|
26
|
+
// - Note that neither `obj` nor any of the arguments need to actually be prototypes of any JavaScript quasiclass, that was just a simplified explanation.
|
|
27
|
+
// - We can create a new object composed from the properties of any number of other objects (since they do not have a constructor, we can think of those as interfaces).
|
|
28
|
+
// - `extend({ a: 1, b: 2 }, { b: 10, c: 20 }, { c: 100, d: 200 })` gives `{ a: 1, b: 10, c: 100, d: 200 }`.
|
|
29
|
+
// - Basically, with this function, we can emulate the `extends` keyword as well as the `implements` keyword.
|
|
30
|
+
// - Therefore, both of the following are valid:
|
|
31
|
+
// - `Lineto.prototype = extend(Line.prototype, segmentPrototype, linetoPrototype)`
|
|
32
|
+
// - `Moveto.prototype = extend(segmentPrototype, movetoPrototype)`
|
|
33
|
+
|
|
34
|
+
var i;
|
|
35
|
+
var n;
|
|
36
|
+
|
|
37
|
+
var args = [];
|
|
38
|
+
n = arguments.length;
|
|
39
|
+
for (i = 1; i < n; i++) { // skip over obj
|
|
40
|
+
args.push(arguments[i]);
|
|
41
|
+
}
|
|
42
|
+
|
|
43
|
+
if (!obj) throw new Error('Missing a parent object.');
|
|
44
|
+
var child = Object.create(obj);
|
|
45
|
+
|
|
46
|
+
n = args.length;
|
|
47
|
+
for (i = 0; i < n; i++) {
|
|
48
|
+
|
|
49
|
+
var src = args[i];
|
|
50
|
+
|
|
51
|
+
var inheritedProperty;
|
|
52
|
+
var key;
|
|
53
|
+
for (key in src) {
|
|
54
|
+
|
|
55
|
+
if (src.hasOwnProperty(key)) {
|
|
56
|
+
delete child[key]; // delete property inherited from parent
|
|
57
|
+
inheritedProperty = Object.getOwnPropertyDescriptor(src, key); // get new definition of property from src
|
|
58
|
+
Object.defineProperty(child, key, inheritedProperty); // re-add property with new definition (includes getter/setter methods)
|
|
59
|
+
}
|
|
60
|
+
}
|
|
61
|
+
}
|
|
62
|
+
|
|
63
|
+
return child;
|
|
64
|
+
}
|
|
@@ -0,0 +1,58 @@
|
|
|
1
|
+
// Declare shorthands to the most used math functions.
|
|
2
|
+
const {
|
|
3
|
+
round,
|
|
4
|
+
floor,
|
|
5
|
+
PI
|
|
6
|
+
} = Math;
|
|
7
|
+
|
|
8
|
+
export const scale = {
|
|
9
|
+
|
|
10
|
+
// Return the `value` from the `domain` interval scaled to the `range` interval.
|
|
11
|
+
linear: function(domain, range, value) {
|
|
12
|
+
|
|
13
|
+
var domainSpan = domain[1] - domain[0];
|
|
14
|
+
var rangeSpan = range[1] - range[0];
|
|
15
|
+
return (((value - domain[0]) / domainSpan) * rangeSpan + range[0]) || 0;
|
|
16
|
+
}
|
|
17
|
+
};
|
|
18
|
+
|
|
19
|
+
export const normalizeAngle = function(angle) {
|
|
20
|
+
|
|
21
|
+
return (angle % 360) + (angle < 0 ? 360 : 0);
|
|
22
|
+
};
|
|
23
|
+
|
|
24
|
+
export const snapToGrid = function(value, gridSize) {
|
|
25
|
+
|
|
26
|
+
return gridSize * round(value / gridSize);
|
|
27
|
+
};
|
|
28
|
+
|
|
29
|
+
export const toDeg = function(rad) {
|
|
30
|
+
|
|
31
|
+
return (180 * rad / PI) % 360;
|
|
32
|
+
};
|
|
33
|
+
|
|
34
|
+
export const toRad = function(deg, over360) {
|
|
35
|
+
|
|
36
|
+
over360 = over360 || false;
|
|
37
|
+
deg = over360 ? deg : (deg % 360);
|
|
38
|
+
return deg * PI / 180;
|
|
39
|
+
};
|
|
40
|
+
|
|
41
|
+
// Return a random integer from the interval [min,max], inclusive.
|
|
42
|
+
export const random = function(min, max) {
|
|
43
|
+
|
|
44
|
+
if (max === undefined) {
|
|
45
|
+
// use first argument as max, min is 0
|
|
46
|
+
max = (min === undefined) ? 1 : min;
|
|
47
|
+
min = 0;
|
|
48
|
+
|
|
49
|
+
} else if (max < min) {
|
|
50
|
+
// switch max and min
|
|
51
|
+
const temp = min;
|
|
52
|
+
min = max;
|
|
53
|
+
max = temp;
|
|
54
|
+
}
|
|
55
|
+
|
|
56
|
+
return floor((Math.random() * (max - min + 1)) + min);
|
|
57
|
+
};
|
|
58
|
+
|
package/src/g/index.mjs
ADDED
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
// Geometry library.
|
|
2
|
+
// -----------------
|
|
3
|
+
|
|
4
|
+
export * from './geometry.helpers.mjs';
|
|
5
|
+
export * from './bezier.mjs';
|
|
6
|
+
export * from './curve.mjs';
|
|
7
|
+
export * from './ellipse.mjs';
|
|
8
|
+
export * from './line.mjs';
|
|
9
|
+
export * from './path.mjs';
|
|
10
|
+
export * from './point.mjs';
|
|
11
|
+
export * from './polyline.mjs';
|
|
12
|
+
export * from './polygon.mjs';
|
|
13
|
+
export * from './rect.mjs';
|
|
14
|
+
export * from './types.mjs';
|
|
15
|
+
|
|
16
|
+
import * as _intersection from './intersection.mjs';
|
|
17
|
+
export const intersection = _intersection;
|