@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.
Files changed (139) hide show
  1. package/LICENSE +376 -0
  2. package/README.md +49 -0
  3. package/dist/geometry.js +6486 -0
  4. package/dist/geometry.min.js +8 -0
  5. package/dist/joint.d.ts +5536 -0
  6. package/dist/joint.js +39629 -0
  7. package/dist/joint.min.js +8 -0
  8. package/dist/joint.nowrap.js +39626 -0
  9. package/dist/joint.nowrap.min.js +8 -0
  10. package/dist/vectorizer.js +9135 -0
  11. package/dist/vectorizer.min.js +8 -0
  12. package/dist/version.mjs +3 -0
  13. package/index.js +3 -0
  14. package/joint.mjs +27 -0
  15. package/package.json +192 -0
  16. package/src/V/annotation.mjs +0 -0
  17. package/src/V/index.mjs +2642 -0
  18. package/src/anchors/index.mjs +123 -0
  19. package/src/config/index.mjs +12 -0
  20. package/src/connectionPoints/index.mjs +202 -0
  21. package/src/connectionStrategies/index.mjs +73 -0
  22. package/src/connectors/curve.mjs +553 -0
  23. package/src/connectors/index.mjs +6 -0
  24. package/src/connectors/jumpover.mjs +452 -0
  25. package/src/connectors/normal.mjs +12 -0
  26. package/src/connectors/rounded.mjs +17 -0
  27. package/src/connectors/smooth.mjs +44 -0
  28. package/src/connectors/straight.mjs +110 -0
  29. package/src/dia/Cell.mjs +945 -0
  30. package/src/dia/CellView.mjs +1316 -0
  31. package/src/dia/Element.mjs +519 -0
  32. package/src/dia/ElementView.mjs +859 -0
  33. package/src/dia/Graph.mjs +1112 -0
  34. package/src/dia/HighlighterView.mjs +319 -0
  35. package/src/dia/Link.mjs +565 -0
  36. package/src/dia/LinkView.mjs +2207 -0
  37. package/src/dia/Paper.mjs +3171 -0
  38. package/src/dia/PaperLayer.mjs +75 -0
  39. package/src/dia/ToolView.mjs +69 -0
  40. package/src/dia/ToolsView.mjs +128 -0
  41. package/src/dia/attributes/calc.mjs +128 -0
  42. package/src/dia/attributes/connection.mjs +75 -0
  43. package/src/dia/attributes/defs.mjs +76 -0
  44. package/src/dia/attributes/eval.mjs +64 -0
  45. package/src/dia/attributes/index.mjs +69 -0
  46. package/src/dia/attributes/legacy.mjs +148 -0
  47. package/src/dia/attributes/offset.mjs +53 -0
  48. package/src/dia/attributes/props.mjs +30 -0
  49. package/src/dia/attributes/shape.mjs +92 -0
  50. package/src/dia/attributes/text.mjs +180 -0
  51. package/src/dia/index.mjs +13 -0
  52. package/src/dia/layers/GridLayer.mjs +176 -0
  53. package/src/dia/ports.mjs +874 -0
  54. package/src/elementTools/Control.mjs +153 -0
  55. package/src/elementTools/HoverConnect.mjs +37 -0
  56. package/src/elementTools/index.mjs +5 -0
  57. package/src/env/index.mjs +43 -0
  58. package/src/g/bezier.mjs +175 -0
  59. package/src/g/curve.mjs +956 -0
  60. package/src/g/ellipse.mjs +245 -0
  61. package/src/g/extend.mjs +64 -0
  62. package/src/g/geometry.helpers.mjs +58 -0
  63. package/src/g/index.mjs +17 -0
  64. package/src/g/intersection.mjs +511 -0
  65. package/src/g/line.bearing.mjs +30 -0
  66. package/src/g/line.length.mjs +5 -0
  67. package/src/g/line.mjs +356 -0
  68. package/src/g/line.squaredLength.mjs +10 -0
  69. package/src/g/path.mjs +2260 -0
  70. package/src/g/point.mjs +375 -0
  71. package/src/g/points.mjs +247 -0
  72. package/src/g/polygon.mjs +51 -0
  73. package/src/g/polyline.mjs +523 -0
  74. package/src/g/rect.mjs +556 -0
  75. package/src/g/types.mjs +10 -0
  76. package/src/highlighters/addClass.mjs +27 -0
  77. package/src/highlighters/index.mjs +5 -0
  78. package/src/highlighters/list.mjs +111 -0
  79. package/src/highlighters/mask.mjs +220 -0
  80. package/src/highlighters/opacity.mjs +17 -0
  81. package/src/highlighters/stroke.mjs +100 -0
  82. package/src/layout/index.mjs +4 -0
  83. package/src/layout/ports/port.mjs +188 -0
  84. package/src/layout/ports/portLabel.mjs +224 -0
  85. package/src/linkAnchors/index.mjs +76 -0
  86. package/src/linkTools/Anchor.mjs +235 -0
  87. package/src/linkTools/Arrowhead.mjs +103 -0
  88. package/src/linkTools/Boundary.mjs +48 -0
  89. package/src/linkTools/Button.mjs +121 -0
  90. package/src/linkTools/Connect.mjs +85 -0
  91. package/src/linkTools/HoverConnect.mjs +161 -0
  92. package/src/linkTools/Segments.mjs +393 -0
  93. package/src/linkTools/Vertices.mjs +253 -0
  94. package/src/linkTools/helpers.mjs +33 -0
  95. package/src/linkTools/index.mjs +8 -0
  96. package/src/mvc/Collection.mjs +560 -0
  97. package/src/mvc/Data.mjs +46 -0
  98. package/src/mvc/Dom/Dom.mjs +587 -0
  99. package/src/mvc/Dom/Event.mjs +130 -0
  100. package/src/mvc/Dom/animations.mjs +122 -0
  101. package/src/mvc/Dom/events.mjs +69 -0
  102. package/src/mvc/Dom/index.mjs +13 -0
  103. package/src/mvc/Dom/methods.mjs +392 -0
  104. package/src/mvc/Dom/props.mjs +77 -0
  105. package/src/mvc/Dom/vars.mjs +5 -0
  106. package/src/mvc/Events.mjs +337 -0
  107. package/src/mvc/Listener.mjs +33 -0
  108. package/src/mvc/Model.mjs +239 -0
  109. package/src/mvc/View.mjs +323 -0
  110. package/src/mvc/ViewBase.mjs +182 -0
  111. package/src/mvc/index.mjs +9 -0
  112. package/src/mvc/mvcUtils.mjs +90 -0
  113. package/src/polyfills/array.js +4 -0
  114. package/src/polyfills/base64.js +68 -0
  115. package/src/polyfills/index.mjs +5 -0
  116. package/src/polyfills/number.js +3 -0
  117. package/src/polyfills/string.js +3 -0
  118. package/src/polyfills/typedArray.js +47 -0
  119. package/src/routers/index.mjs +6 -0
  120. package/src/routers/manhattan.mjs +856 -0
  121. package/src/routers/metro.mjs +91 -0
  122. package/src/routers/normal.mjs +6 -0
  123. package/src/routers/oneSide.mjs +60 -0
  124. package/src/routers/orthogonal.mjs +323 -0
  125. package/src/routers/rightAngle.mjs +1056 -0
  126. package/src/shapes/index.mjs +3 -0
  127. package/src/shapes/standard.mjs +755 -0
  128. package/src/util/cloneCells.mjs +67 -0
  129. package/src/util/getRectPoint.mjs +65 -0
  130. package/src/util/index.mjs +5 -0
  131. package/src/util/svgTagTemplate.mjs +110 -0
  132. package/src/util/util.mjs +1754 -0
  133. package/src/util/utilHelpers.mjs +2402 -0
  134. package/src/util/wrappers.mjs +56 -0
  135. package/types/geometry.d.ts +815 -0
  136. package/types/index.d.ts +53 -0
  137. package/types/joint.d.ts +4391 -0
  138. package/types/joint.head.d.ts +12 -0
  139. package/types/vectorizer.d.ts +327 -0
@@ -0,0 +1,511 @@
1
+ import { Line } from './line.mjs';
2
+ import { Polygon } from './polygon.mjs';
3
+ import { Rect } from './rect.mjs';
4
+ import { types } from './types.mjs';
5
+
6
+ export function exists(shape1, shape2, shape1opt, shape2opt) {
7
+ switch (shape1.type) {
8
+ case types.Line: {
9
+ switch (shape2.type) {
10
+ case types.Line: {
11
+ return lineWithLine(shape1, shape2);
12
+ }
13
+ }
14
+ break;
15
+ }
16
+ case types.Ellipse: {
17
+ switch (shape2.type) {
18
+ case types.Line: {
19
+ return ellipseWithLine(shape1, shape2);
20
+ }
21
+ case types.Ellipse: {
22
+ return ellipseWithEllipse(shape1, shape2);
23
+ }
24
+ }
25
+ break;
26
+ }
27
+ case types.Rect: {
28
+ switch (shape2.type) {
29
+ case types.Line: {
30
+ return rectWithLine(shape1, shape2);
31
+ }
32
+ case types.Ellipse: {
33
+ return rectWithEllipse(shape1, shape2);
34
+ }
35
+ case types.Rect: {
36
+ return rectWithRect(shape1, shape2);
37
+ }
38
+ }
39
+ break;
40
+ }
41
+ case types.Polyline: {
42
+ switch (shape2.type) {
43
+ case types.Line: {
44
+ return polylineWithLine(shape1, shape2);
45
+ }
46
+ case types.Ellipse: {
47
+ return polylineWithEllipse(shape1, shape2);
48
+ }
49
+ case types.Rect: {
50
+ return polylineWithRect(shape1, shape2);
51
+ }
52
+ case types.Polyline: {
53
+ return polylineWithPolyline(shape1, shape2);
54
+ }
55
+ }
56
+ break;
57
+ }
58
+ case types.Polygon: {
59
+ switch (shape2.type) {
60
+ case types.Line: {
61
+ return polygonWithLine(shape1, shape2);
62
+ }
63
+ case types.Ellipse: {
64
+ return polygonWithEllipse(shape1, shape2);
65
+ }
66
+ case types.Rect: {
67
+ return polygonWithRect(shape1, shape2);
68
+ }
69
+ case types.Polyline: {
70
+ return polygonWithPolyline(shape1, shape2);
71
+ }
72
+ case types.Polygon: {
73
+ return polygonWithPolygon(shape1, shape2);
74
+ }
75
+ }
76
+ break;
77
+ }
78
+ case types.Path: {
79
+ switch (shape2.type) {
80
+ case types.Line: {
81
+ return pathWithLine(shape1, shape2, shape1opt);
82
+ }
83
+ case types.Ellipse: {
84
+ return pathWithEllipse(shape1, shape2, shape1opt);
85
+ }
86
+ case types.Rect: {
87
+ return pathWithRect(shape1, shape2, shape1opt);
88
+ }
89
+ case types.Polyline: {
90
+ return pathWithPolyline(shape1, shape2, shape1opt);
91
+ }
92
+ case types.Polygon: {
93
+ return pathWithPolygon(shape1, shape2, shape1opt);
94
+ }
95
+ case types.Path: {
96
+ return pathWithPath(shape1, shape2, shape1opt, shape2opt);
97
+ }
98
+ }
99
+ break;
100
+ }
101
+ }
102
+ // None of the cases above
103
+ switch (shape2.type) {
104
+ case types.Ellipse:
105
+ case types.Rect:
106
+ case types.Polyline:
107
+ case types.Polygon:
108
+ case types.Path: {
109
+ return exists(shape2, shape1, shape2opt, shape1opt);
110
+ }
111
+ default: {
112
+ throw Error(`The intersection for ${shape1} and ${shape2} could not be found.`);
113
+ }
114
+ }
115
+ }
116
+
117
+ /* Line */
118
+
119
+ export function lineWithLine(line1, line2) {
120
+ const x1 = line1.start.x;
121
+ const y1 = line1.start.y;
122
+ const x2 = line1.end.x;
123
+ const y2 = line1.end.y;
124
+ const x3 = line2.start.x;
125
+ const y3 = line2.start.y;
126
+ const x4 = line2.end.x;
127
+ const y4 = line2.end.y;
128
+ const s1x = x2 - x1;
129
+ const s1y = y2 - y1;
130
+ const s2x = x4 - x3;
131
+ const s2y = y4 - y3;
132
+ const s3x = x1 - x3;
133
+ const s3y = y1 - y3;
134
+ const p = s1x * s2y - s2x * s1y;
135
+ const s = (s1x * s3y - s1y * s3x) / p;
136
+ const t = (s2x * s3y - s2y * s3x) / p;
137
+ return s >= 0 && s <= 1 && t >= 0 && t <= 1;
138
+ }
139
+
140
+ /* Ellipse */
141
+
142
+ export function ellipseWithLine(ellipse, line) {
143
+ const rex = ellipse.a;
144
+ const rey = ellipse.b;
145
+ const xe = ellipse.x;
146
+ const ye = ellipse.y;
147
+ const x1 = line.start.x - xe;
148
+ const x2 = line.end.x - xe;
149
+ const y1 = line.start.y - ye;
150
+ const y2 = line.end.y - ye;
151
+ const rex_2 = rex * rex;
152
+ const rey_2 = rey * rey;
153
+ const dx = x2 - x1;
154
+ const dy = y2 - y1;
155
+ const A = dx * dx / rex_2 + dy * dy / rey_2;
156
+ const B = 2 * x1 * dx / rex_2 + 2 * y1 * dy / rey_2;
157
+ const C = x1 * x1 / rex_2 + y1 * y1 / rey_2 - 1;
158
+ const D = B * B - 4 * A * C;
159
+ if (D === 0) {
160
+ const t = -B / 2 / A;
161
+ return t >= 0 && t <= 1;
162
+ } else if (D > 0) {
163
+ const sqrt = Math.sqrt(D);
164
+ const t1 = (-B + sqrt) / 2 / A;
165
+ const t2 = (-B - sqrt) / 2 / A;
166
+ return (t1 >= 0 && t1 <= 1) || (t2 >= 0 && t2 <= 1);
167
+ }
168
+ return false;
169
+ }
170
+
171
+ export function ellipseWithEllipse(ellipse1, ellipse2) {
172
+ return _ellipsesIntersection(ellipse1, 0, ellipse2, 0);
173
+ }
174
+
175
+ /* Rect */
176
+
177
+ export function rectWithLine(rect, line) {
178
+ const { start, end } = line;
179
+ const { x, y, width, height } = rect;
180
+ if (
181
+ (start.x > x + width && end.x > x + width)
182
+ || (start.x < x && end.x < x)
183
+ || (start.y > y + height && end.y > y + height)
184
+ || (start.y < y && end.y < y)
185
+ ) {
186
+ return false;
187
+ }
188
+ if (rect.containsPoint(line.start) || rect.containsPoint(line.end)) {
189
+ return true;
190
+ }
191
+ return lineWithLine(rect.topLine(), line)
192
+ || lineWithLine(rect.rightLine(), line)
193
+ || lineWithLine(rect.bottomLine(), line)
194
+ || lineWithLine(rect.leftLine(), line);
195
+ }
196
+
197
+ export function rectWithEllipse(rect, ellipse) {
198
+ if (!rectWithRect(rect, Rect.fromEllipse(ellipse))) return false;
199
+ return polygonWithEllipse(Polygon.fromRect(rect), ellipse);
200
+ }
201
+
202
+ export function rectWithRect(rect1, rect2) {
203
+ return rect1.x < rect2.x + rect2.width
204
+ && rect1.x + rect1.width > rect2.x
205
+ && rect1.y < rect2.y + rect2.height
206
+ && rect1.y + rect1.height > rect2.y;
207
+ }
208
+
209
+ /* Polyline */
210
+
211
+ export function polylineWithLine(polyline, line) {
212
+ return _polylineWithLine(polyline, line, { interior: false });
213
+ }
214
+
215
+ export function polylineWithEllipse(polyline, ellipse) {
216
+ return _polylineWithEllipse(polyline, ellipse, { interior: false });
217
+ }
218
+
219
+ export function polylineWithRect(polyline, rect) {
220
+ return _polylineWithRect(polyline, rect, { interior: false });
221
+ }
222
+
223
+ export function polylineWithPolyline(polyline1, polyline2) {
224
+ return _polylineWithPolyline(polyline1, polyline2, { interior: false });
225
+ }
226
+
227
+ /* Polygon */
228
+
229
+ export function polygonWithLine(polygon, line) {
230
+ return _polylineWithLine(polygon, line, { interior: true });
231
+ }
232
+
233
+ export function polygonWithEllipse(polygon, ellipse) {
234
+ return _polylineWithEllipse(polygon, ellipse, { interior: true });
235
+ }
236
+
237
+ export function polygonWithRect(polygon, rect) {
238
+ return _polylineWithRect(polygon, rect, { interior: true });
239
+ }
240
+
241
+ export function polygonWithPolyline(polygon, polyline) {
242
+ return _polylineWithPolyline(polygon, polyline, { interior: true });
243
+ }
244
+
245
+ export function polygonWithPolygon(polygon1, polygon2) {
246
+ return _polylineWithPolygon(polygon1, polygon2, { interior: true });
247
+ }
248
+
249
+ /* Path */
250
+
251
+ export function pathWithLine(path, line, pathOpt) {
252
+ return path.getSubpaths().some(subpath => {
253
+ const [polyline] = subpath.toPolylines(pathOpt);
254
+ const { type } = subpath.getSegment(-1);
255
+ if (type === 'Z') {
256
+ return polygonWithLine(polyline, line);
257
+ } else {
258
+ return polylineWithLine(polyline, line);
259
+ }
260
+ });
261
+ }
262
+
263
+ export function pathWithEllipse(path, ellipse, pathOpt) {
264
+ return path.getSubpaths().some(subpath => {
265
+ const [polyline] = subpath.toPolylines(pathOpt);
266
+ const { type } = subpath.getSegment(-1);
267
+ if (type === 'Z') {
268
+ return polygonWithEllipse(polyline, ellipse);
269
+ } else {
270
+ return polylineWithEllipse(polyline, ellipse);
271
+ }
272
+ });
273
+ }
274
+
275
+ export function pathWithRect(path, rect, pathOpt) {
276
+ return pathWithPolygon(path, Polygon.fromRect(rect), pathOpt);
277
+ }
278
+
279
+ export function pathWithPolyline(path, polyline, pathOpt) {
280
+ return _pathWithPolyline(path, polyline, pathOpt, { interior: false });
281
+ }
282
+
283
+ export function pathWithPolygon(path, polygon, pathOpt) {
284
+ return _pathWithPolyline(path, polygon, pathOpt, { interior: true });
285
+ }
286
+
287
+ export function pathWithPath(path1, path2, pathOpt1, pathOpt2) {
288
+ return path1.getSubpaths().some(subpath => {
289
+ const [polyline1] = subpath.toPolylines(pathOpt1);
290
+ const { type } = subpath.getSegment(-1);
291
+ if (type === 'Z') {
292
+ return pathWithPolygon(path2, polyline1, pathOpt2);
293
+ } else {
294
+ return pathWithPolyline(path2, polyline1, pathOpt2);
295
+ }
296
+ });
297
+ }
298
+
299
+ function _polylineWithLine(polyline, line, opt = {}) {
300
+ const { interior = false } = opt;
301
+ let thisPoints;
302
+ if (interior) {
303
+ if (polyline.containsPoint(line.start)) {
304
+ // If any point of the polyline lies inside this polygon (interior = true)
305
+ // there is an intersection (we've chosen the start point)
306
+ return true;
307
+ }
308
+ const { start, end, points } = polyline;
309
+ thisPoints = end.equals(start) ? points : [...points, start];
310
+ } else {
311
+ thisPoints = polyline.points;
312
+ }
313
+ const { length } = thisPoints;
314
+ const segment = new Line();
315
+ for (let i = 0; i < length - 1; i++) {
316
+ segment.start = thisPoints[i];
317
+ segment.end = thisPoints[i + 1];
318
+ if (lineWithLine(line, segment)) {
319
+ return true;
320
+ }
321
+ }
322
+ return false;
323
+ }
324
+
325
+ function _polylineWithEllipse(polyline, ellipse, opt = {}) {
326
+ const { start, end, points } = polyline;
327
+ if (ellipse.containsPoint(start)) {
328
+ return true;
329
+ }
330
+ let thisPoints;
331
+ const { interior = false } = opt;
332
+ if (interior) {
333
+ if (polyline.containsPoint(ellipse.center())) {
334
+ // If any point of the ellipse lies inside this polygon (interior = true)
335
+ // there is an intersection (we've chosen the center point)
336
+ return true;
337
+ }
338
+ thisPoints = end.equals(start) ? points : [...points, start];
339
+ } else {
340
+ thisPoints = points;
341
+ }
342
+
343
+ const { length } = thisPoints;
344
+ const segment = new Line();
345
+ for (let i = 0; i < length - 1; i++) {
346
+ segment.start = thisPoints[i];
347
+ segment.end = thisPoints[i + 1];
348
+ if (ellipseWithLine(ellipse, segment)) {
349
+ return true;
350
+ }
351
+ }
352
+ return false;
353
+ }
354
+
355
+ function _polylineWithRect(polyline, rect, opt) {
356
+ const polygon = Polygon.fromRect(rect);
357
+ return _polylineWithPolygon(polyline, polygon, opt);
358
+ }
359
+
360
+ function _pathWithPolyline(path, polyline1, pathOpt, opt) {
361
+ return path.getSubpaths().some(subpath => {
362
+ const [polyline2] = subpath.toPolylines(pathOpt);
363
+ const { type } = subpath.getSegment(-1);
364
+ if (type === 'Z') {
365
+ return _polylineWithPolygon(polyline1, polyline2, opt);
366
+ } else {
367
+ return _polylineWithPolyline(polyline1, polyline2, opt);
368
+ }
369
+ });
370
+ }
371
+
372
+ function _polylineWithPolyline(polyline1, polyline2, opt = {}) {
373
+ const { interior = false } = opt;
374
+ let thisPolyline;
375
+ if (interior) {
376
+ const { start } = polyline2;
377
+ if (polyline1.containsPoint(start)) {
378
+ // If any point of the polyline lies inside this polygon (interior = true)
379
+ // there is an intersection (we've chosen the start point)
380
+ return true;
381
+ }
382
+ thisPolyline = polyline1.clone().close();
383
+ } else {
384
+ thisPolyline = polyline1;
385
+ }
386
+ const otherPoints = polyline2.points;
387
+ const { length } = otherPoints;
388
+ const segment = new Line();
389
+ for (let i = 0; i < length - 1; i++) {
390
+ segment.start = otherPoints[i];
391
+ segment.end = otherPoints[i + 1];
392
+ if (polylineWithLine(thisPolyline, segment)) {
393
+ return true;
394
+ }
395
+ }
396
+ return false;
397
+ }
398
+
399
+ function _polylineWithPolygon(polyline, polygon, opt) {
400
+ return polygon.containsPoint(polyline.start) || _polylineWithPolyline(polyline, polygon.clone().close(), opt);
401
+ }
402
+
403
+ function _ellipsesIntersection(e1, w1, e2, w2) {
404
+ const { cos, sin } = Math;
405
+ const sinW1 = sin(w1);
406
+ const cosW1 = cos(w1);
407
+ const sinW2 = sin(w2);
408
+ const cosW2 = cos(w2);
409
+ const sinW1s = sinW1 * sinW1;
410
+ const cosW1s = cosW1 * cosW1;
411
+ const sinCos1 = sinW1 * cosW1;
412
+ const sinW2s = sinW2 * sinW2;
413
+ const cosW2s = cosW2 * cosW2;
414
+ const sinCos2 = sinW2 * cosW2;
415
+ const a1s = e1.a * e1.a;
416
+ const b1s = e1.b * e1.b;
417
+ const a2s = e2.a * e2.a;
418
+ const b2s = e2.b * e2.b;
419
+ const A1 = a1s * sinW1s + b1s * cosW1s;
420
+ const A2 = a2s * sinW2s + b2s * cosW2s;
421
+ const B1 = a1s * cosW1s + b1s * sinW1s;
422
+ const B2 = a2s * cosW2s + b2s * sinW2s;
423
+ let C1 = 2 * (b1s - a1s) * sinCos1;
424
+ let C2 = 2 * (b2s - a2s) * sinCos2;
425
+ let D1 = (-2 * A1 * e1.x - C1 * e1.y);
426
+ let D2 = (-2 * A2 * e2.x - C2 * e2.y);
427
+ let E1 = (-C1 * e1.x - 2 * B1 * e1.y);
428
+ let E2 = (-C2 * e2.x - 2 * B2 * e2.y);
429
+ const F1 = A1 * e1.x * e1.x + B1 * e1.y * e1.y + C1 * e1.x * e1.y - a1s * b1s;
430
+ const F2 = A2 * e2.x * e2.x + B2 * e2.y * e2.y + C2 * e2.x * e2.y - a2s * b2s;
431
+
432
+ C1 = C1 / 2;
433
+ C2 = C2 / 2;
434
+ D1 = D1 / 2;
435
+ D2 = D2 / 2;
436
+ E1 = E1 / 2;
437
+ E2 = E2 / 2;
438
+
439
+ const l3 = det3([
440
+ [A1, C1, D1],
441
+ [C1, B1, E1],
442
+ [D1, E1, F1]
443
+ ]);
444
+ const l0 = det3([
445
+ [A2, C2, D2],
446
+ [C2, B2, E2],
447
+ [D2, E2, F2]
448
+ ]);
449
+ const l2 = 0.33333333 * (det3([
450
+ [A2, C1, D1],
451
+ [C2, B1, E1],
452
+ [D2, E1, F1]
453
+ ]) + det3([
454
+ [A1, C2, D1],
455
+ [C1, B2, E1],
456
+ [D1, E2, F1]
457
+ ]) + det3([
458
+ [A1, C1, D2],
459
+ [C1, B1, E2],
460
+ [D1, E1, F2]
461
+ ]));
462
+ const l1 = 0.33333333 * (det3([
463
+ [A1, C2, D2],
464
+ [C1, B2, E2],
465
+ [D1, E2, F2]
466
+ ]) + det3([
467
+ [A2, C1, D2],
468
+ [C2, B1, E2],
469
+ [D2, E1, F2]
470
+ ]) + det3([
471
+ [A2, C2, D1],
472
+ [C2, B2, E1],
473
+ [D2, E2, F1]
474
+ ]));
475
+
476
+ const delta1 = det2([
477
+ [l3, l2],
478
+ [l2, l1]
479
+ ]);
480
+ const delta2 = det2([
481
+ [l3, l1],
482
+ [l2, l0]
483
+ ]);
484
+ const delta3 = det2([
485
+ [l2, l1],
486
+ [l1, l0]
487
+ ]);
488
+
489
+ const dP = det2([
490
+ [2 * delta1, delta2],
491
+ [delta2, 2 * delta3]
492
+ ]);
493
+
494
+ if (dP > 0 && (l1 > 0 || l2 > 0)) {
495
+ return false;
496
+ }
497
+ return true;
498
+ }
499
+
500
+ function det2(m) {
501
+ return m[0][0] * m[1][1] - m[0][1] * m[1][0];
502
+ }
503
+
504
+ function det3(m) {
505
+ return m[0][0] * m[1][1] * m[2][2] -
506
+ m[0][0] * m[1][2] * m[2][1] -
507
+ m[0][1] * m[1][0] * m[2][2] +
508
+ m[0][1] * m[1][2] * m[2][0] +
509
+ m[0][2] * m[1][0] * m[2][1] -
510
+ m[0][2] * m[1][1] * m[2][0];
511
+ }
@@ -0,0 +1,30 @@
1
+ // @return the bearing (cardinal direction) of the line. For example N, W, or SE.
2
+ // @returns {String} One of the following bearings : NE, E, SE, S, SW, W, NW, N.
3
+ import { toDeg, toRad } from './geometry.helpers.mjs';
4
+
5
+ const {
6
+ cos,
7
+ sin,
8
+ atan2
9
+ } = Math;
10
+
11
+ export const bearing = function(p, q) {
12
+
13
+ var lat1 = toRad(p.y);
14
+ var lat2 = toRad(q.y);
15
+ var lon1 = p.x;
16
+ var lon2 = q.x;
17
+ var dLon = toRad(lon2 - lon1);
18
+ var y = sin(dLon) * cos(lat2);
19
+ var x = cos(lat1) * sin(lat2) - sin(lat1) * cos(lat2) * cos(dLon);
20
+ var brng = toDeg(atan2(y, x));
21
+
22
+ var bearings = ['NE', 'E', 'SE', 'S', 'SW', 'W', 'NW', 'N'];
23
+
24
+ var index = brng - 22.5;
25
+ if (index < 0)
26
+ index += 360;
27
+ index = parseInt(index / 45);
28
+
29
+ return bearings[index];
30
+ };
@@ -0,0 +1,5 @@
1
+ import { squaredLength } from './line.squaredLength.mjs';
2
+
3
+ export const length = function(start, end) {
4
+ return Math.sqrt(squaredLength(start, end));
5
+ };