1 |
|
2 |
|
3 |
|
4 | var earthRadius = 6371008.8;
|
5 |
|
6 |
|
7 |
|
8 |
|
9 | var factors = {
|
10 | meters: earthRadius,
|
11 | metres: earthRadius,
|
12 | millimeters: earthRadius * 1000,
|
13 | millimetres: earthRadius * 1000,
|
14 | centimeters: earthRadius * 100,
|
15 | centimetres: earthRadius * 100,
|
16 | kilometers: earthRadius / 1000,
|
17 | kilometres: earthRadius / 1000,
|
18 | miles: earthRadius / 1609.344,
|
19 | nauticalmiles: earthRadius / 1852,
|
20 | inches: earthRadius * 39.370,
|
21 | yards: earthRadius / 1.0936,
|
22 | feet: earthRadius * 3.28084,
|
23 | radians: 1,
|
24 | degrees: earthRadius / 111325,
|
25 | };
|
26 |
|
27 |
|
28 |
|
29 |
|
30 | var unitsFactors = {
|
31 | meters: 1,
|
32 | metres: 1,
|
33 | millimeters: 1000,
|
34 | millimetres: 1000,
|
35 | centimeters: 100,
|
36 | centimetres: 100,
|
37 | kilometers: 1 / 1000,
|
38 | kilometres: 1 / 1000,
|
39 | miles: 1 / 1609.344,
|
40 | nauticalmiles: 1 / 1852,
|
41 | inches: 39.370,
|
42 | yards: 1 / 1.0936,
|
43 | feet: 3.28084,
|
44 | radians: 1 / earthRadius,
|
45 | degrees: 1 / 111325,
|
46 | };
|
47 |
|
48 |
|
49 |
|
50 |
|
51 | var areaFactors = {
|
52 | meters: 1,
|
53 | metres: 1,
|
54 | millimeters: 1000000,
|
55 | millimetres: 1000000,
|
56 | centimeters: 10000,
|
57 | centimetres: 10000,
|
58 | kilometers: 0.000001,
|
59 | kilometres: 0.000001,
|
60 | acres: 0.000247105,
|
61 | miles: 3.86e-7,
|
62 | yards: 1.195990046,
|
63 | feet: 10.763910417,
|
64 | inches: 1550.003100006
|
65 | };
|
66 |
|
67 |
|
68 |
|
69 |
|
70 |
|
71 |
|
72 |
|
73 |
|
74 |
|
75 |
|
76 |
|
77 |
|
78 |
|
79 |
|
80 |
|
81 |
|
82 |
|
83 |
|
84 |
|
85 |
|
86 |
|
87 | function feature(geometry, properties, options) {
|
88 |
|
89 | options = options || {};
|
90 | if (!isObject(options)) throw new Error('options is invalid');
|
91 | var bbox = options.bbox;
|
92 | var id = options.id;
|
93 |
|
94 |
|
95 | if (geometry === undefined) throw new Error('geometry is required');
|
96 | if (properties && properties.constructor !== Object) throw new Error('properties must be an Object');
|
97 | if (bbox) validateBBox(bbox);
|
98 | if (id) validateId(id);
|
99 |
|
100 |
|
101 | var feat = {type: 'Feature'};
|
102 | if (id) feat.id = id;
|
103 | if (bbox) feat.bbox = bbox;
|
104 | feat.properties = properties || {};
|
105 | feat.geometry = geometry;
|
106 | return feat;
|
107 | }
|
108 |
|
109 |
|
110 |
|
111 |
|
112 |
|
113 |
|
114 |
|
115 |
|
116 |
|
117 |
|
118 |
|
119 |
|
120 |
|
121 |
|
122 |
|
123 |
|
124 |
|
125 |
|
126 |
|
127 | function geometry(type, coordinates, options) {
|
128 |
|
129 | options = options || {};
|
130 | if (!isObject(options)) throw new Error('options is invalid');
|
131 | var bbox = options.bbox;
|
132 |
|
133 |
|
134 | if (!type) throw new Error('type is required');
|
135 | if (!coordinates) throw new Error('coordinates is required');
|
136 | if (!Array.isArray(coordinates)) throw new Error('coordinates must be an Array');
|
137 | if (bbox) validateBBox(bbox);
|
138 |
|
139 |
|
140 | var geom;
|
141 | switch (type) {
|
142 | case 'Point': geom = point(coordinates).geometry; break;
|
143 | case 'LineString': geom = lineString(coordinates).geometry; break;
|
144 | case 'Polygon': geom = polygon(coordinates).geometry; break;
|
145 | case 'MultiPoint': geom = multiPoint(coordinates).geometry; break;
|
146 | case 'MultiLineString': geom = multiLineString(coordinates).geometry; break;
|
147 | case 'MultiPolygon': geom = multiPolygon(coordinates).geometry; break;
|
148 | default: throw new Error(type + ' is invalid');
|
149 | }
|
150 | if (bbox) geom.bbox = bbox;
|
151 | return geom;
|
152 | }
|
153 |
|
154 |
|
155 |
|
156 |
|
157 |
|
158 |
|
159 |
|
160 |
|
161 |
|
162 |
|
163 |
|
164 |
|
165 |
|
166 |
|
167 |
|
168 |
|
169 | function point(coordinates, properties, options) {
|
170 | if (!coordinates) throw new Error('coordinates is required');
|
171 | if (!Array.isArray(coordinates)) throw new Error('coordinates must be an Array');
|
172 | if (coordinates.length < 2) throw new Error('coordinates must be at least 2 numbers long');
|
173 | if (!isNumber(coordinates[0]) || !isNumber(coordinates[1])) throw new Error('coordinates must contain numbers');
|
174 |
|
175 | return feature({
|
176 | type: 'Point',
|
177 | coordinates: coordinates
|
178 | }, properties, options);
|
179 | }
|
180 |
|
181 |
|
182 |
|
183 |
|
184 |
|
185 |
|
186 |
|
187 |
|
188 |
|
189 |
|
190 |
|
191 |
|
192 |
|
193 |
|
194 |
|
195 |
|
196 |
|
197 |
|
198 |
|
199 |
|
200 | function points(coordinates, properties, options) {
|
201 | if (!coordinates) throw new Error('coordinates is required');
|
202 | if (!Array.isArray(coordinates)) throw new Error('coordinates must be an Array');
|
203 |
|
204 | return featureCollection(coordinates.map(function (coords) {
|
205 | return point(coords, properties);
|
206 | }), options);
|
207 | }
|
208 |
|
209 |
|
210 |
|
211 |
|
212 |
|
213 |
|
214 |
|
215 |
|
216 |
|
217 |
|
218 |
|
219 |
|
220 |
|
221 |
|
222 |
|
223 |
|
224 | function polygon(coordinates, properties, options) {
|
225 | if (!coordinates) throw new Error('coordinates is required');
|
226 |
|
227 | for (var i = 0; i < coordinates.length; i++) {
|
228 | var ring = coordinates[i];
|
229 | if (ring.length < 4) {
|
230 | throw new Error('Each LinearRing of a Polygon must have 4 or more Positions.');
|
231 | }
|
232 | for (var j = 0; j < ring[ring.length - 1].length; j++) {
|
233 |
|
234 | if (i === 0 && j === 0 && !isNumber(ring[0][0]) || !isNumber(ring[0][1])) throw new Error('coordinates must contain numbers');
|
235 | if (ring[ring.length - 1][j] !== ring[0][j]) {
|
236 | throw new Error('First and last Position are not equivalent.');
|
237 | }
|
238 | }
|
239 | }
|
240 |
|
241 | return feature({
|
242 | type: 'Polygon',
|
243 | coordinates: coordinates
|
244 | }, properties, options);
|
245 | }
|
246 |
|
247 |
|
248 |
|
249 |
|
250 |
|
251 |
|
252 |
|
253 |
|
254 |
|
255 |
|
256 |
|
257 |
|
258 |
|
259 |
|
260 |
|
261 |
|
262 |
|
263 |
|
264 |
|
265 | function polygons(coordinates, properties, options) {
|
266 | if (!coordinates) throw new Error('coordinates is required');
|
267 | if (!Array.isArray(coordinates)) throw new Error('coordinates must be an Array');
|
268 |
|
269 | return featureCollection(coordinates.map(function (coords) {
|
270 | return polygon(coords, properties);
|
271 | }), options);
|
272 | }
|
273 |
|
274 |
|
275 |
|
276 |
|
277 |
|
278 |
|
279 |
|
280 |
|
281 |
|
282 |
|
283 |
|
284 |
|
285 |
|
286 |
|
287 |
|
288 |
|
289 |
|
290 |
|
291 | function lineString(coordinates, properties, options) {
|
292 | if (!coordinates) throw new Error('coordinates is required');
|
293 | if (coordinates.length < 2) throw new Error('coordinates must be an array of two or more positions');
|
294 |
|
295 | if (!isNumber(coordinates[0][1]) || !isNumber(coordinates[0][1])) throw new Error('coordinates must contain numbers');
|
296 |
|
297 | return feature({
|
298 | type: 'LineString',
|
299 | coordinates: coordinates
|
300 | }, properties, options);
|
301 | }
|
302 |
|
303 |
|
304 |
|
305 |
|
306 |
|
307 |
|
308 |
|
309 |
|
310 |
|
311 |
|
312 |
|
313 |
|
314 |
|
315 |
|
316 |
|
317 |
|
318 |
|
319 |
|
320 |
|
321 | function lineStrings(coordinates, properties, options) {
|
322 | if (!coordinates) throw new Error('coordinates is required');
|
323 | if (!Array.isArray(coordinates)) throw new Error('coordinates must be an Array');
|
324 |
|
325 | return featureCollection(coordinates.map(function (coords) {
|
326 | return lineString(coords, properties);
|
327 | }), options);
|
328 | }
|
329 |
|
330 |
|
331 |
|
332 |
|
333 |
|
334 |
|
335 |
|
336 |
|
337 |
|
338 |
|
339 |
|
340 |
|
341 |
|
342 |
|
343 |
|
344 |
|
345 |
|
346 |
|
347 |
|
348 |
|
349 |
|
350 |
|
351 |
|
352 | function featureCollection(features, options) {
|
353 |
|
354 | options = options || {};
|
355 | if (!isObject(options)) throw new Error('options is invalid');
|
356 | var bbox = options.bbox;
|
357 | var id = options.id;
|
358 |
|
359 |
|
360 | if (!features) throw new Error('No features passed');
|
361 | if (!Array.isArray(features)) throw new Error('features must be an Array');
|
362 | if (bbox) validateBBox(bbox);
|
363 | if (id) validateId(id);
|
364 |
|
365 |
|
366 | var fc = {type: 'FeatureCollection'};
|
367 | if (id) fc.id = id;
|
368 | if (bbox) fc.bbox = bbox;
|
369 | fc.features = features;
|
370 | return fc;
|
371 | }
|
372 |
|
373 |
|
374 |
|
375 |
|
376 |
|
377 |
|
378 |
|
379 |
|
380 |
|
381 |
|
382 |
|
383 |
|
384 |
|
385 |
|
386 |
|
387 |
|
388 |
|
389 |
|
390 | function multiLineString(coordinates, properties, options) {
|
391 | if (!coordinates) throw new Error('coordinates is required');
|
392 |
|
393 | return feature({
|
394 | type: 'MultiLineString',
|
395 | coordinates: coordinates
|
396 | }, properties, options);
|
397 | }
|
398 |
|
399 |
|
400 |
|
401 |
|
402 |
|
403 |
|
404 |
|
405 |
|
406 |
|
407 |
|
408 |
|
409 |
|
410 |
|
411 |
|
412 |
|
413 |
|
414 |
|
415 |
|
416 | function multiPoint(coordinates, properties, options) {
|
417 | if (!coordinates) throw new Error('coordinates is required');
|
418 |
|
419 | return feature({
|
420 | type: 'MultiPoint',
|
421 | coordinates: coordinates
|
422 | }, properties, options);
|
423 | }
|
424 |
|
425 |
|
426 |
|
427 |
|
428 |
|
429 |
|
430 |
|
431 |
|
432 |
|
433 |
|
434 |
|
435 |
|
436 |
|
437 |
|
438 |
|
439 |
|
440 |
|
441 |
|
442 |
|
443 | function multiPolygon(coordinates, properties, options) {
|
444 | if (!coordinates) throw new Error('coordinates is required');
|
445 |
|
446 | return feature({
|
447 | type: 'MultiPolygon',
|
448 | coordinates: coordinates
|
449 | }, properties, options);
|
450 | }
|
451 |
|
452 |
|
453 |
|
454 |
|
455 |
|
456 |
|
457 |
|
458 |
|
459 |
|
460 |
|
461 |
|
462 |
|
463 |
|
464 |
|
465 |
|
466 |
|
467 |
|
468 |
|
469 |
|
470 |
|
471 |
|
472 |
|
473 |
|
474 |
|
475 |
|
476 | function geometryCollection(geometries, properties, options) {
|
477 | if (!geometries) throw new Error('geometries is required');
|
478 | if (!Array.isArray(geometries)) throw new Error('geometries must be an Array');
|
479 |
|
480 | return feature({
|
481 | type: 'GeometryCollection',
|
482 | geometries: geometries
|
483 | }, properties, options);
|
484 | }
|
485 |
|
486 |
|
487 |
|
488 |
|
489 |
|
490 |
|
491 |
|
492 |
|
493 |
|
494 |
|
495 |
|
496 |
|
497 |
|
498 |
|
499 | function round(num, precision) {
|
500 | if (num === undefined || num === null || isNaN(num)) throw new Error('num is required');
|
501 | if (precision && !(precision >= 0)) throw new Error('precision must be a positive number');
|
502 | var multiplier = Math.pow(10, precision || 0);
|
503 | return Math.round(num * multiplier) / multiplier;
|
504 | }
|
505 |
|
506 |
|
507 |
|
508 |
|
509 |
|
510 |
|
511 |
|
512 |
|
513 |
|
514 |
|
515 | function radiansToLength(radians, units) {
|
516 | if (radians === undefined || radians === null) throw new Error('radians is required');
|
517 |
|
518 | if (units && typeof units !== 'string') throw new Error('units must be a string');
|
519 | var factor = factors[units || 'kilometers'];
|
520 | if (!factor) throw new Error(units + ' units is invalid');
|
521 | return radians * factor;
|
522 | }
|
523 |
|
524 |
|
525 |
|
526 |
|
527 |
|
528 |
|
529 |
|
530 |
|
531 |
|
532 |
|
533 | function lengthToRadians(distance, units) {
|
534 | if (distance === undefined || distance === null) throw new Error('distance is required');
|
535 |
|
536 | if (units && typeof units !== 'string') throw new Error('units must be a string');
|
537 | var factor = factors[units || 'kilometers'];
|
538 | if (!factor) throw new Error(units + ' units is invalid');
|
539 | return distance / factor;
|
540 | }
|
541 |
|
542 |
|
543 |
|
544 |
|
545 |
|
546 |
|
547 |
|
548 |
|
549 |
|
550 |
|
551 | function lengthToDegrees(distance, units) {
|
552 | return radiansToDegrees(lengthToRadians(distance, units));
|
553 | }
|
554 |
|
555 |
|
556 |
|
557 |
|
558 |
|
559 |
|
560 |
|
561 |
|
562 |
|
563 | function bearingToAzimuth(bearing) {
|
564 | if (bearing === null || bearing === undefined) throw new Error('bearing is required');
|
565 |
|
566 | var angle = bearing % 360;
|
567 | if (angle < 0) angle += 360;
|
568 | return angle;
|
569 | }
|
570 |
|
571 |
|
572 |
|
573 |
|
574 |
|
575 |
|
576 |
|
577 |
|
578 | function radiansToDegrees(radians) {
|
579 | if (radians === null || radians === undefined) throw new Error('radians is required');
|
580 |
|
581 | var degrees = radians % (2 * Math.PI);
|
582 | return degrees * 180 / Math.PI;
|
583 | }
|
584 |
|
585 |
|
586 |
|
587 |
|
588 |
|
589 |
|
590 |
|
591 |
|
592 | function degreesToRadians(degrees) {
|
593 | if (degrees === null || degrees === undefined) throw new Error('degrees is required');
|
594 |
|
595 | var radians = degrees % 360;
|
596 | return radians * Math.PI / 180;
|
597 | }
|
598 |
|
599 |
|
600 |
|
601 |
|
602 |
|
603 |
|
604 |
|
605 |
|
606 |
|
607 |
|
608 | function convertLength(length, originalUnit, finalUnit) {
|
609 | if (length === null || length === undefined) throw new Error('length is required');
|
610 | if (!(length >= 0)) throw new Error('length must be a positive number');
|
611 |
|
612 | return radiansToLength(lengthToRadians(length, originalUnit), finalUnit || 'kilometers');
|
613 | }
|
614 |
|
615 |
|
616 |
|
617 |
|
618 |
|
619 |
|
620 |
|
621 |
|
622 |
|
623 | function convertArea(area, originalUnit, finalUnit) {
|
624 | if (area === null || area === undefined) throw new Error('area is required');
|
625 | if (!(area >= 0)) throw new Error('area must be a positive number');
|
626 |
|
627 | var startFactor = areaFactors[originalUnit || 'meters'];
|
628 | if (!startFactor) throw new Error('invalid original units');
|
629 |
|
630 | var finalFactor = areaFactors[finalUnit || 'kilometers'];
|
631 | if (!finalFactor) throw new Error('invalid final units');
|
632 |
|
633 | return (area / startFactor) * finalFactor;
|
634 | }
|
635 |
|
636 |
|
637 |
|
638 |
|
639 |
|
640 |
|
641 |
|
642 |
|
643 |
|
644 |
|
645 |
|
646 |
|
647 | function isNumber(num) {
|
648 | return !isNaN(num) && num !== null && !Array.isArray(num);
|
649 | }
|
650 |
|
651 |
|
652 |
|
653 |
|
654 |
|
655 |
|
656 |
|
657 |
|
658 |
|
659 |
|
660 |
|
661 |
|
662 | function isObject(input) {
|
663 | return (!!input) && (input.constructor === Object);
|
664 | }
|
665 |
|
666 |
|
667 |
|
668 |
|
669 |
|
670 |
|
671 |
|
672 |
|
673 |
|
674 |
|
675 |
|
676 |
|
677 |
|
678 |
|
679 |
|
680 |
|
681 |
|
682 |
|
683 |
|
684 |
|
685 |
|
686 |
|
687 | function validateBBox(bbox) {
|
688 | if (!bbox) throw new Error('bbox is required');
|
689 | if (!Array.isArray(bbox)) throw new Error('bbox must be an Array');
|
690 | if (bbox.length !== 4 && bbox.length !== 6) throw new Error('bbox must be an Array of 4 or 6 numbers');
|
691 | bbox.forEach(function (num) {
|
692 | if (!isNumber(num)) throw new Error('bbox must only contain numbers');
|
693 | });
|
694 | }
|
695 |
|
696 |
|
697 |
|
698 |
|
699 |
|
700 |
|
701 |
|
702 |
|
703 |
|
704 |
|
705 |
|
706 |
|
707 |
|
708 |
|
709 |
|
710 |
|
711 |
|
712 |
|
713 |
|
714 |
|
715 |
|
716 |
|
717 | function validateId(id) {
|
718 | if (!id) throw new Error('id is required');
|
719 | if (['string', 'number'].indexOf(typeof id) === -1) throw new Error('id must be a number or a string');
|
720 | }
|
721 |
|
722 |
|
723 | function radians2degrees() {
|
724 | throw new Error('method has been renamed to `radiansToDegrees`');
|
725 | }
|
726 |
|
727 | function degrees2radians() {
|
728 | throw new Error('method has been renamed to `degreesToRadians`');
|
729 | }
|
730 |
|
731 | function distanceToDegrees() {
|
732 | throw new Error('method has been renamed to `lengthToDegrees`');
|
733 | }
|
734 |
|
735 | function distanceToRadians() {
|
736 | throw new Error('method has been renamed to `lengthToRadians`');
|
737 | }
|
738 |
|
739 | function radiansToDistance() {
|
740 | throw new Error('method has been renamed to `radiansToLength`');
|
741 | }
|
742 |
|
743 | function bearingToAngle() {
|
744 | throw new Error('method has been renamed to `bearingToAzimuth`');
|
745 | }
|
746 |
|
747 | function convertDistance() {
|
748 | throw new Error('method has been renamed to `convertLength`');
|
749 | }
|
750 |
|
751 |
|
752 |
|
753 |
|
754 | var main_es$1 = Object.freeze({
|
755 | earthRadius: earthRadius,
|
756 | factors: factors,
|
757 | unitsFactors: unitsFactors,
|
758 | areaFactors: areaFactors,
|
759 | feature: feature,
|
760 | geometry: geometry,
|
761 | point: point,
|
762 | points: points,
|
763 | polygon: polygon,
|
764 | polygons: polygons,
|
765 | lineString: lineString,
|
766 | lineStrings: lineStrings,
|
767 | featureCollection: featureCollection,
|
768 | multiLineString: multiLineString,
|
769 | multiPoint: multiPoint,
|
770 | multiPolygon: multiPolygon,
|
771 | geometryCollection: geometryCollection,
|
772 | round: round,
|
773 | radiansToLength: radiansToLength,
|
774 | lengthToRadians: lengthToRadians,
|
775 | lengthToDegrees: lengthToDegrees,
|
776 | bearingToAzimuth: bearingToAzimuth,
|
777 | radiansToDegrees: radiansToDegrees,
|
778 | degreesToRadians: degreesToRadians,
|
779 | convertLength: convertLength,
|
780 | convertArea: convertArea,
|
781 | isNumber: isNumber,
|
782 | isObject: isObject,
|
783 | validateBBox: validateBBox,
|
784 | validateId: validateId,
|
785 | radians2degrees: radians2degrees,
|
786 | degrees2radians: degrees2radians,
|
787 | distanceToDegrees: distanceToDegrees,
|
788 | distanceToRadians: distanceToRadians,
|
789 | radiansToDistance: radiansToDistance,
|
790 | bearingToAngle: bearingToAngle,
|
791 | convertDistance: convertDistance
|
792 | });
|
793 |
|
794 |
|
795 |
|
796 |
|
797 |
|
798 |
|
799 |
|
800 |
|
801 |
|
802 |
|
803 |
|
804 |
|
805 |
|
806 |
|
807 |
|
808 |
|
809 |
|
810 |
|
811 |
|
812 |
|
813 |
|
814 |
|
815 |
|
816 |
|
817 |
|
818 |
|
819 |
|
820 |
|
821 |
|
822 |
|
823 |
|
824 |
|
825 |
|
826 | function coordEach(geojson, callback, excludeWrapCoord) {
|
827 |
|
828 | if (geojson === null) return;
|
829 | var j, k, l, geometry$$1, stopG, coords,
|
830 | geometryMaybeCollection,
|
831 | wrapShrink = 0,
|
832 | coordIndex = 0,
|
833 | isGeometryCollection,
|
834 | type = geojson.type,
|
835 | isFeatureCollection = type === 'FeatureCollection',
|
836 | isFeature = type === 'Feature',
|
837 | stop = isFeatureCollection ? geojson.features.length : 1;
|
838 |
|
839 |
|
840 |
|
841 |
|
842 |
|
843 |
|
844 |
|
845 |
|
846 |
|
847 |
|
848 |
|
849 |
|
850 |
|
851 | for (var featureIndex = 0; featureIndex < stop; featureIndex++) {
|
852 | geometryMaybeCollection = (isFeatureCollection ? geojson.features[featureIndex].geometry :
|
853 | (isFeature ? geojson.geometry : geojson));
|
854 | isGeometryCollection = (geometryMaybeCollection) ? geometryMaybeCollection.type === 'GeometryCollection' : false;
|
855 | stopG = isGeometryCollection ? geometryMaybeCollection.geometries.length : 1;
|
856 |
|
857 | for (var geomIndex = 0; geomIndex < stopG; geomIndex++) {
|
858 | var multiFeatureIndex = 0;
|
859 | var geometryIndex = 0;
|
860 | geometry$$1 = isGeometryCollection ?
|
861 | geometryMaybeCollection.geometries[geomIndex] : geometryMaybeCollection;
|
862 |
|
863 |
|
864 | if (geometry$$1 === null) continue;
|
865 | coords = geometry$$1.coordinates;
|
866 | var geomType = geometry$$1.type;
|
867 |
|
868 | wrapShrink = (excludeWrapCoord && (geomType === 'Polygon' || geomType === 'MultiPolygon')) ? 1 : 0;
|
869 |
|
870 | switch (geomType) {
|
871 | case null:
|
872 | break;
|
873 | case 'Point':
|
874 | callback(coords, coordIndex, featureIndex, multiFeatureIndex, geometryIndex);
|
875 | coordIndex++;
|
876 | multiFeatureIndex++;
|
877 | break;
|
878 | case 'LineString':
|
879 | case 'MultiPoint':
|
880 | for (j = 0; j < coords.length; j++) {
|
881 | callback(coords[j], coordIndex, featureIndex, multiFeatureIndex, geometryIndex);
|
882 | coordIndex++;
|
883 | if (geomType === 'MultiPoint') multiFeatureIndex++;
|
884 | }
|
885 | if (geomType === 'LineString') multiFeatureIndex++;
|
886 | break;
|
887 | case 'Polygon':
|
888 | case 'MultiLineString':
|
889 | for (j = 0; j < coords.length; j++) {
|
890 | for (k = 0; k < coords[j].length - wrapShrink; k++) {
|
891 | callback(coords[j][k], coordIndex, featureIndex, multiFeatureIndex, geometryIndex);
|
892 | coordIndex++;
|
893 | }
|
894 | if (geomType === 'MultiLineString') multiFeatureIndex++;
|
895 | if (geomType === 'Polygon') geometryIndex++;
|
896 | }
|
897 | if (geomType === 'Polygon') multiFeatureIndex++;
|
898 | break;
|
899 | case 'MultiPolygon':
|
900 | for (j = 0; j < coords.length; j++) {
|
901 | if (geomType === 'MultiPolygon') geometryIndex = 0;
|
902 | for (k = 0; k < coords[j].length; k++) {
|
903 | for (l = 0; l < coords[j][k].length - wrapShrink; l++) {
|
904 | callback(coords[j][k][l], coordIndex, featureIndex, multiFeatureIndex, geometryIndex);
|
905 | coordIndex++;
|
906 | }
|
907 | geometryIndex++;
|
908 | }
|
909 | multiFeatureIndex++;
|
910 | }
|
911 | break;
|
912 | case 'GeometryCollection':
|
913 | for (j = 0; j < geometry$$1.geometries.length; j++)
|
914 | coordEach(geometry$$1.geometries[j], callback, excludeWrapCoord);
|
915 | break;
|
916 | default:
|
917 | throw new Error('Unknown Geometry Type');
|
918 | }
|
919 | }
|
920 | }
|
921 | }
|
922 |
|
923 |
|
924 |
|
925 |
|
926 |
|
927 |
|
928 |
|
929 |
|
930 |
|
931 |
|
932 |
|
933 |
|
934 |
|
935 |
|
936 |
|
937 |
|
938 |
|
939 |
|
940 |
|
941 |
|
942 |
|
943 |
|
944 |
|
945 |
|
946 |
|
947 |
|
948 |
|
949 |
|
950 |
|
951 |
|
952 |
|
953 |
|
954 |
|
955 |
|
956 |
|
957 |
|
958 |
|
959 |
|
960 |
|
961 |
|
962 |
|
963 |
|
964 |
|
965 |
|
966 |
|
967 |
|
968 |
|
969 |
|
970 |
|
971 |
|
972 |
|
973 | function coordReduce(geojson, callback, initialValue, excludeWrapCoord) {
|
974 | var previousValue = initialValue;
|
975 | coordEach(geojson, function (currentCoord, coordIndex, featureIndex, multiFeatureIndex, geometryIndex) {
|
976 | if (coordIndex === 0 && initialValue === undefined) previousValue = currentCoord;
|
977 | else previousValue = callback(previousValue, currentCoord, coordIndex, featureIndex, multiFeatureIndex, geometryIndex);
|
978 | }, excludeWrapCoord);
|
979 | return previousValue;
|
980 | }
|
981 |
|
982 |
|
983 |
|
984 |
|
985 |
|
986 |
|
987 |
|
988 |
|
989 |
|
990 |
|
991 |
|
992 |
|
993 |
|
994 |
|
995 |
|
996 |
|
997 |
|
998 |
|
999 |
|
1000 |
|
1001 |
|
1002 |
|
1003 |
|
1004 |
|
1005 |
|
1006 |
|
1007 | function propEach(geojson, callback) {
|
1008 | var i;
|
1009 | switch (geojson.type) {
|
1010 | case 'FeatureCollection':
|
1011 | for (i = 0; i < geojson.features.length; i++) {
|
1012 | callback(geojson.features[i].properties, i);
|
1013 | }
|
1014 | break;
|
1015 | case 'Feature':
|
1016 | callback(geojson.properties, 0);
|
1017 | break;
|
1018 | }
|
1019 | }
|
1020 |
|
1021 |
|
1022 |
|
1023 |
|
1024 |
|
1025 |
|
1026 |
|
1027 |
|
1028 |
|
1029 |
|
1030 |
|
1031 |
|
1032 |
|
1033 |
|
1034 |
|
1035 |
|
1036 |
|
1037 |
|
1038 |
|
1039 |
|
1040 |
|
1041 |
|
1042 |
|
1043 |
|
1044 |
|
1045 |
|
1046 |
|
1047 |
|
1048 |
|
1049 |
|
1050 |
|
1051 |
|
1052 |
|
1053 |
|
1054 |
|
1055 |
|
1056 |
|
1057 |
|
1058 |
|
1059 |
|
1060 |
|
1061 |
|
1062 |
|
1063 |
|
1064 |
|
1065 |
|
1066 | function propReduce(geojson, callback, initialValue) {
|
1067 | var previousValue = initialValue;
|
1068 | propEach(geojson, function (currentProperties, featureIndex) {
|
1069 | if (featureIndex === 0 && initialValue === undefined) previousValue = currentProperties;
|
1070 | else previousValue = callback(previousValue, currentProperties, featureIndex);
|
1071 | });
|
1072 | return previousValue;
|
1073 | }
|
1074 |
|
1075 |
|
1076 |
|
1077 |
|
1078 |
|
1079 |
|
1080 |
|
1081 |
|
1082 |
|
1083 |
|
1084 |
|
1085 |
|
1086 |
|
1087 |
|
1088 |
|
1089 |
|
1090 |
|
1091 |
|
1092 |
|
1093 |
|
1094 |
|
1095 |
|
1096 |
|
1097 |
|
1098 |
|
1099 |
|
1100 |
|
1101 | function featureEach(geojson, callback) {
|
1102 | if (geojson.type === 'Feature') {
|
1103 | callback(geojson, 0);
|
1104 | } else if (geojson.type === 'FeatureCollection') {
|
1105 | for (var i = 0; i < geojson.features.length; i++) {
|
1106 | callback(geojson.features[i], i);
|
1107 | }
|
1108 | }
|
1109 | }
|
1110 |
|
1111 |
|
1112 |
|
1113 |
|
1114 |
|
1115 |
|
1116 |
|
1117 |
|
1118 |
|
1119 |
|
1120 |
|
1121 |
|
1122 |
|
1123 |
|
1124 |
|
1125 |
|
1126 |
|
1127 |
|
1128 |
|
1129 |
|
1130 |
|
1131 |
|
1132 |
|
1133 |
|
1134 |
|
1135 |
|
1136 |
|
1137 |
|
1138 |
|
1139 |
|
1140 |
|
1141 |
|
1142 |
|
1143 |
|
1144 |
|
1145 |
|
1146 |
|
1147 |
|
1148 |
|
1149 |
|
1150 |
|
1151 |
|
1152 |
|
1153 | function featureReduce(geojson, callback, initialValue) {
|
1154 | var previousValue = initialValue;
|
1155 | featureEach(geojson, function (currentFeature, featureIndex) {
|
1156 | if (featureIndex === 0 && initialValue === undefined) previousValue = currentFeature;
|
1157 | else previousValue = callback(previousValue, currentFeature, featureIndex);
|
1158 | });
|
1159 | return previousValue;
|
1160 | }
|
1161 |
|
1162 |
|
1163 |
|
1164 |
|
1165 |
|
1166 |
|
1167 |
|
1168 |
|
1169 |
|
1170 |
|
1171 |
|
1172 |
|
1173 |
|
1174 |
|
1175 |
|
1176 |
|
1177 | function coordAll(geojson) {
|
1178 | var coords = [];
|
1179 | coordEach(geojson, function (coord) {
|
1180 | coords.push(coord);
|
1181 | });
|
1182 | return coords;
|
1183 | }
|
1184 |
|
1185 |
|
1186 |
|
1187 |
|
1188 |
|
1189 |
|
1190 |
|
1191 |
|
1192 |
|
1193 |
|
1194 |
|
1195 |
|
1196 |
|
1197 |
|
1198 |
|
1199 |
|
1200 |
|
1201 |
|
1202 |
|
1203 |
|
1204 |
|
1205 |
|
1206 |
|
1207 |
|
1208 |
|
1209 |
|
1210 |
|
1211 |
|
1212 |
|
1213 |
|
1214 |
|
1215 |
|
1216 | function geomEach(geojson, callback) {
|
1217 | var i, j, g, geometry$$1, stopG,
|
1218 | geometryMaybeCollection,
|
1219 | isGeometryCollection,
|
1220 | featureProperties,
|
1221 | featureBBox,
|
1222 | featureId,
|
1223 | featureIndex = 0,
|
1224 | isFeatureCollection = geojson.type === 'FeatureCollection',
|
1225 | isFeature = geojson.type === 'Feature',
|
1226 | stop = isFeatureCollection ? geojson.features.length : 1;
|
1227 |
|
1228 |
|
1229 |
|
1230 |
|
1231 |
|
1232 |
|
1233 |
|
1234 |
|
1235 |
|
1236 |
|
1237 |
|
1238 |
|
1239 |
|
1240 | for (i = 0; i < stop; i++) {
|
1241 |
|
1242 | geometryMaybeCollection = (isFeatureCollection ? geojson.features[i].geometry :
|
1243 | (isFeature ? geojson.geometry : geojson));
|
1244 | featureProperties = (isFeatureCollection ? geojson.features[i].properties :
|
1245 | (isFeature ? geojson.properties : {}));
|
1246 | featureBBox = (isFeatureCollection ? geojson.features[i].bbox :
|
1247 | (isFeature ? geojson.bbox : undefined));
|
1248 | featureId = (isFeatureCollection ? geojson.features[i].id :
|
1249 | (isFeature ? geojson.id : undefined));
|
1250 | isGeometryCollection = (geometryMaybeCollection) ? geometryMaybeCollection.type === 'GeometryCollection' : false;
|
1251 | stopG = isGeometryCollection ? geometryMaybeCollection.geometries.length : 1;
|
1252 |
|
1253 | for (g = 0; g < stopG; g++) {
|
1254 | geometry$$1 = isGeometryCollection ?
|
1255 | geometryMaybeCollection.geometries[g] : geometryMaybeCollection;
|
1256 |
|
1257 |
|
1258 | if (geometry$$1 === null) {
|
1259 | callback(null, featureIndex, featureProperties, featureBBox, featureId);
|
1260 | continue;
|
1261 | }
|
1262 | switch (geometry$$1.type) {
|
1263 | case 'Point':
|
1264 | case 'LineString':
|
1265 | case 'MultiPoint':
|
1266 | case 'Polygon':
|
1267 | case 'MultiLineString':
|
1268 | case 'MultiPolygon': {
|
1269 | callback(geometry$$1, featureIndex, featureProperties, featureBBox, featureId);
|
1270 | break;
|
1271 | }
|
1272 | case 'GeometryCollection': {
|
1273 | for (j = 0; j < geometry$$1.geometries.length; j++) {
|
1274 | callback(geometry$$1.geometries[j], featureIndex, featureProperties, featureBBox, featureId);
|
1275 | }
|
1276 | break;
|
1277 | }
|
1278 | default:
|
1279 | throw new Error('Unknown Geometry Type');
|
1280 | }
|
1281 | }
|
1282 |
|
1283 | featureIndex++;
|
1284 | }
|
1285 | }
|
1286 |
|
1287 |
|
1288 |
|
1289 |
|
1290 |
|
1291 |
|
1292 |
|
1293 |
|
1294 |
|
1295 |
|
1296 |
|
1297 |
|
1298 |
|
1299 |
|
1300 |
|
1301 |
|
1302 |
|
1303 |
|
1304 |
|
1305 |
|
1306 |
|
1307 |
|
1308 |
|
1309 |
|
1310 |
|
1311 |
|
1312 |
|
1313 |
|
1314 |
|
1315 |
|
1316 |
|
1317 |
|
1318 |
|
1319 |
|
1320 |
|
1321 |
|
1322 |
|
1323 |
|
1324 |
|
1325 |
|
1326 |
|
1327 |
|
1328 |
|
1329 |
|
1330 |
|
1331 |
|
1332 |
|
1333 |
|
1334 |
|
1335 | function geomReduce(geojson, callback, initialValue) {
|
1336 | var previousValue = initialValue;
|
1337 | geomEach(geojson, function (currentGeometry, featureIndex, featureProperties, featureBBox, featureId) {
|
1338 | if (featureIndex === 0 && initialValue === undefined) previousValue = currentGeometry;
|
1339 | else previousValue = callback(previousValue, currentGeometry, featureIndex, featureProperties, featureBBox, featureId);
|
1340 | });
|
1341 | return previousValue;
|
1342 | }
|
1343 |
|
1344 |
|
1345 |
|
1346 |
|
1347 |
|
1348 |
|
1349 |
|
1350 |
|
1351 |
|
1352 |
|
1353 |
|
1354 |
|
1355 |
|
1356 |
|
1357 |
|
1358 |
|
1359 |
|
1360 |
|
1361 |
|
1362 |
|
1363 |
|
1364 |
|
1365 |
|
1366 |
|
1367 |
|
1368 |
|
1369 |
|
1370 |
|
1371 |
|
1372 | function flattenEach(geojson, callback) {
|
1373 | geomEach(geojson, function (geometry$$1, featureIndex, properties, bbox, id) {
|
1374 |
|
1375 | var type = (geometry$$1 === null) ? null : geometry$$1.type;
|
1376 | switch (type) {
|
1377 | case null:
|
1378 | case 'Point':
|
1379 | case 'LineString':
|
1380 | case 'Polygon':
|
1381 | callback(feature(geometry$$1, properties, {bbox: bbox, id: id}), featureIndex, 0);
|
1382 | return;
|
1383 | }
|
1384 |
|
1385 | var geomType;
|
1386 |
|
1387 |
|
1388 | switch (type) {
|
1389 | case 'MultiPoint':
|
1390 | geomType = 'Point';
|
1391 | break;
|
1392 | case 'MultiLineString':
|
1393 | geomType = 'LineString';
|
1394 | break;
|
1395 | case 'MultiPolygon':
|
1396 | geomType = 'Polygon';
|
1397 | break;
|
1398 | }
|
1399 |
|
1400 | geometry$$1.coordinates.forEach(function (coordinate, multiFeatureIndex) {
|
1401 | var geom = {
|
1402 | type: geomType,
|
1403 | coordinates: coordinate
|
1404 | };
|
1405 | callback(feature(geom, properties), featureIndex, multiFeatureIndex);
|
1406 | });
|
1407 |
|
1408 | });
|
1409 | }
|
1410 |
|
1411 |
|
1412 |
|
1413 |
|
1414 |
|
1415 |
|
1416 |
|
1417 |
|
1418 |
|
1419 |
|
1420 |
|
1421 |
|
1422 |
|
1423 |
|
1424 |
|
1425 |
|
1426 |
|
1427 |
|
1428 |
|
1429 |
|
1430 |
|
1431 |
|
1432 |
|
1433 |
|
1434 |
|
1435 |
|
1436 |
|
1437 |
|
1438 |
|
1439 |
|
1440 |
|
1441 |
|
1442 |
|
1443 |
|
1444 |
|
1445 |
|
1446 |
|
1447 |
|
1448 |
|
1449 |
|
1450 |
|
1451 |
|
1452 |
|
1453 |
|
1454 |
|
1455 | function flattenReduce(geojson, callback, initialValue) {
|
1456 | var previousValue = initialValue;
|
1457 | flattenEach(geojson, function (currentFeature, featureIndex, multiFeatureIndex) {
|
1458 | if (featureIndex === 0 && multiFeatureIndex === 0 && initialValue === undefined) previousValue = currentFeature;
|
1459 | else previousValue = callback(previousValue, currentFeature, featureIndex, multiFeatureIndex);
|
1460 | });
|
1461 | return previousValue;
|
1462 | }
|
1463 |
|
1464 |
|
1465 |
|
1466 |
|
1467 |
|
1468 |
|
1469 |
|
1470 |
|
1471 |
|
1472 |
|
1473 |
|
1474 |
|
1475 |
|
1476 |
|
1477 |
|
1478 |
|
1479 |
|
1480 |
|
1481 |
|
1482 |
|
1483 |
|
1484 |
|
1485 |
|
1486 |
|
1487 |
|
1488 |
|
1489 |
|
1490 |
|
1491 |
|
1492 |
|
1493 |
|
1494 |
|
1495 |
|
1496 |
|
1497 |
|
1498 |
|
1499 |
|
1500 |
|
1501 | function segmentEach(geojson, callback) {
|
1502 | flattenEach(geojson, function (feature$$1, featureIndex, multiFeatureIndex) {
|
1503 | var segmentIndex = 0;
|
1504 |
|
1505 |
|
1506 | if (!feature$$1.geometry) return;
|
1507 |
|
1508 | var type = feature$$1.geometry.type;
|
1509 | if (type === 'Point' || type === 'MultiPoint') return;
|
1510 |
|
1511 |
|
1512 | coordReduce(feature$$1, function (previousCoords, currentCoord, coordIndex, featureIndexCoord, mutliPartIndexCoord, geometryIndex) {
|
1513 | var currentSegment = lineString([previousCoords, currentCoord], feature$$1.properties);
|
1514 | callback(currentSegment, featureIndex, multiFeatureIndex, geometryIndex, segmentIndex);
|
1515 | segmentIndex++;
|
1516 | return currentCoord;
|
1517 | });
|
1518 | });
|
1519 | }
|
1520 |
|
1521 |
|
1522 |
|
1523 |
|
1524 |
|
1525 |
|
1526 |
|
1527 |
|
1528 |
|
1529 |
|
1530 |
|
1531 |
|
1532 |
|
1533 |
|
1534 |
|
1535 |
|
1536 |
|
1537 |
|
1538 |
|
1539 |
|
1540 |
|
1541 |
|
1542 |
|
1543 |
|
1544 |
|
1545 |
|
1546 |
|
1547 |
|
1548 |
|
1549 |
|
1550 |
|
1551 |
|
1552 |
|
1553 |
|
1554 |
|
1555 |
|
1556 |
|
1557 |
|
1558 |
|
1559 |
|
1560 |
|
1561 |
|
1562 |
|
1563 |
|
1564 |
|
1565 |
|
1566 |
|
1567 |
|
1568 |
|
1569 |
|
1570 |
|
1571 |
|
1572 |
|
1573 |
|
1574 | function segmentReduce(geojson, callback, initialValue) {
|
1575 | var previousValue = initialValue;
|
1576 | var started = false;
|
1577 | segmentEach(geojson, function (currentSegment, featureIndex, multiFeatureIndex, geometryIndex, segmentIndex) {
|
1578 | if (started === false && initialValue === undefined) previousValue = currentSegment;
|
1579 | else previousValue = callback(previousValue, currentSegment, featureIndex, multiFeatureIndex, geometryIndex, segmentIndex);
|
1580 | started = true;
|
1581 | });
|
1582 | return previousValue;
|
1583 | }
|
1584 |
|
1585 |
|
1586 |
|
1587 |
|
1588 |
|
1589 |
|
1590 |
|
1591 |
|
1592 |
|
1593 |
|
1594 |
|
1595 |
|
1596 |
|
1597 |
|
1598 |
|
1599 |
|
1600 |
|
1601 |
|
1602 |
|
1603 |
|
1604 |
|
1605 |
|
1606 |
|
1607 |
|
1608 |
|
1609 |
|
1610 |
|
1611 |
|
1612 |
|
1613 |
|
1614 |
|
1615 | function lineEach(geojson, callback) {
|
1616 |
|
1617 | if (!geojson) throw new Error('geojson is required');
|
1618 |
|
1619 | flattenEach(geojson, function (feature$$1, featureIndex, multiFeatureIndex) {
|
1620 | if (feature$$1.geometry === null) return;
|
1621 | var type = feature$$1.geometry.type;
|
1622 | var coords = feature$$1.geometry.coordinates;
|
1623 | switch (type) {
|
1624 | case 'LineString':
|
1625 | callback(feature$$1, featureIndex, multiFeatureIndex, 0, 0);
|
1626 | break;
|
1627 | case 'Polygon':
|
1628 | for (var geometryIndex = 0; geometryIndex < coords.length; geometryIndex++) {
|
1629 | callback(lineString(coords[geometryIndex], feature$$1.properties), featureIndex, multiFeatureIndex, geometryIndex);
|
1630 | }
|
1631 | break;
|
1632 | }
|
1633 | });
|
1634 | }
|
1635 |
|
1636 |
|
1637 |
|
1638 |
|
1639 |
|
1640 |
|
1641 |
|
1642 |
|
1643 |
|
1644 |
|
1645 |
|
1646 |
|
1647 |
|
1648 |
|
1649 |
|
1650 |
|
1651 |
|
1652 |
|
1653 |
|
1654 |
|
1655 |
|
1656 |
|
1657 |
|
1658 |
|
1659 |
|
1660 |
|
1661 |
|
1662 |
|
1663 |
|
1664 |
|
1665 |
|
1666 |
|
1667 |
|
1668 |
|
1669 |
|
1670 |
|
1671 |
|
1672 |
|
1673 |
|
1674 |
|
1675 |
|
1676 |
|
1677 |
|
1678 |
|
1679 |
|
1680 |
|
1681 |
|
1682 | function lineReduce(geojson, callback, initialValue) {
|
1683 | var previousValue = initialValue;
|
1684 | lineEach(geojson, function (currentLine, featureIndex, multiFeatureIndex, geometryIndex) {
|
1685 | if (featureIndex === 0 && initialValue === undefined) previousValue = currentLine;
|
1686 | else previousValue = callback(previousValue, currentLine, featureIndex, multiFeatureIndex, geometryIndex);
|
1687 | });
|
1688 | return previousValue;
|
1689 | }
|
1690 |
|
1691 |
|
1692 |
|
1693 |
|
1694 | var main_es = Object.freeze({
|
1695 | coordEach: coordEach,
|
1696 | coordReduce: coordReduce,
|
1697 | propEach: propEach,
|
1698 | propReduce: propReduce,
|
1699 | featureEach: featureEach,
|
1700 | featureReduce: featureReduce,
|
1701 | coordAll: coordAll,
|
1702 | geomEach: geomEach,
|
1703 | geomReduce: geomReduce,
|
1704 | flattenEach: flattenEach,
|
1705 | flattenReduce: flattenReduce,
|
1706 | segmentEach: segmentEach,
|
1707 | segmentReduce: segmentReduce,
|
1708 | lineEach: lineEach,
|
1709 | lineReduce: lineReduce
|
1710 | });
|
1711 |
|
1712 |
|
1713 |
|
1714 |
|
1715 |
|
1716 |
|
1717 |
|
1718 |
|
1719 |
|
1720 |
|
1721 |
|
1722 |
|
1723 |
|
1724 |
|
1725 |
|
1726 | function bbox(geojson) {
|
1727 | var BBox = [Infinity, Infinity, -Infinity, -Infinity];
|
1728 | coordEach(geojson, function (coord) {
|
1729 | if (BBox[0] > coord[0]) BBox[0] = coord[0];
|
1730 | if (BBox[1] > coord[1]) BBox[1] = coord[1];
|
1731 | if (BBox[2] < coord[0]) BBox[2] = coord[0];
|
1732 | if (BBox[3] < coord[1]) BBox[3] = coord[1];
|
1733 | });
|
1734 | return BBox;
|
1735 | }
|
1736 |
|
1737 |
|
1738 |
|
1739 |
|
1740 |
|
1741 |
|
1742 |
|
1743 |
|
1744 |
|
1745 |
|
1746 |
|
1747 |
|
1748 |
|
1749 | function getCoord(obj) {
|
1750 | if (!obj) throw new Error('obj is required');
|
1751 |
|
1752 | var coordinates = getCoords(obj);
|
1753 |
|
1754 |
|
1755 | if (coordinates.length > 1 && isNumber(coordinates[0]) && isNumber(coordinates[1])) {
|
1756 | return coordinates;
|
1757 | } else {
|
1758 | throw new Error('Coordinate is not a valid Point');
|
1759 | }
|
1760 | }
|
1761 |
|
1762 |
|
1763 |
|
1764 |
|
1765 |
|
1766 |
|
1767 |
|
1768 |
|
1769 |
|
1770 |
|
1771 |
|
1772 |
|
1773 |
|
1774 | function getCoords(obj) {
|
1775 | if (!obj) throw new Error('obj is required');
|
1776 | var coordinates;
|
1777 |
|
1778 |
|
1779 | if (obj.length) {
|
1780 | coordinates = obj;
|
1781 |
|
1782 |
|
1783 | } else if (obj.coordinates) {
|
1784 | coordinates = obj.coordinates;
|
1785 |
|
1786 |
|
1787 | } else if (obj.geometry && obj.geometry.coordinates) {
|
1788 | coordinates = obj.geometry.coordinates;
|
1789 | }
|
1790 |
|
1791 | if (coordinates) {
|
1792 | containsNumber(coordinates);
|
1793 | return coordinates;
|
1794 | }
|
1795 | throw new Error('No valid coordinates');
|
1796 | }
|
1797 |
|
1798 |
|
1799 |
|
1800 |
|
1801 |
|
1802 |
|
1803 |
|
1804 |
|
1805 | function containsNumber(coordinates) {
|
1806 | if (coordinates.length > 1 && isNumber(coordinates[0]) && isNumber(coordinates[1])) {
|
1807 | return true;
|
1808 | }
|
1809 |
|
1810 | if (Array.isArray(coordinates[0]) && coordinates[0].length) {
|
1811 | return containsNumber(coordinates[0]);
|
1812 | }
|
1813 | throw new Error('coordinates must only contain numbers');
|
1814 | }
|
1815 |
|
1816 |
|
1817 |
|
1818 |
|
1819 |
|
1820 |
|
1821 |
|
1822 |
|
1823 |
|
1824 |
|
1825 | function geojsonType(value, type, name) {
|
1826 | if (!type || !name) throw new Error('type and name required');
|
1827 |
|
1828 | if (!value || value.type !== type) {
|
1829 | throw new Error('Invalid input to ' + name + ': must be a ' + type + ', given ' + value.type);
|
1830 | }
|
1831 | }
|
1832 |
|
1833 |
|
1834 |
|
1835 |
|
1836 |
|
1837 |
|
1838 |
|
1839 |
|
1840 |
|
1841 |
|
1842 |
|
1843 | function featureOf(feature$$1, type, name) {
|
1844 | if (!feature$$1) throw new Error('No feature passed');
|
1845 | if (!name) throw new Error('.featureOf() requires a name');
|
1846 | if (!feature$$1 || feature$$1.type !== 'Feature' || !feature$$1.geometry) {
|
1847 | throw new Error('Invalid input to ' + name + ', Feature with geometry required');
|
1848 | }
|
1849 | if (!feature$$1.geometry || feature$$1.geometry.type !== type) {
|
1850 | throw new Error('Invalid input to ' + name + ': must be a ' + type + ', given ' + feature$$1.geometry.type);
|
1851 | }
|
1852 | }
|
1853 |
|
1854 |
|
1855 |
|
1856 |
|
1857 |
|
1858 |
|
1859 |
|
1860 |
|
1861 |
|
1862 |
|
1863 |
|
1864 | function collectionOf(featureCollection$$1, type, name) {
|
1865 | if (!featureCollection$$1) throw new Error('No featureCollection passed');
|
1866 | if (!name) throw new Error('.collectionOf() requires a name');
|
1867 | if (!featureCollection$$1 || featureCollection$$1.type !== 'FeatureCollection') {
|
1868 | throw new Error('Invalid input to ' + name + ', FeatureCollection required');
|
1869 | }
|
1870 | for (var i = 0; i < featureCollection$$1.features.length; i++) {
|
1871 | var feature$$1 = featureCollection$$1.features[i];
|
1872 | if (!feature$$1 || feature$$1.type !== 'Feature' || !feature$$1.geometry) {
|
1873 | throw new Error('Invalid input to ' + name + ', Feature with geometry required');
|
1874 | }
|
1875 | if (!feature$$1.geometry || feature$$1.geometry.type !== type) {
|
1876 | throw new Error('Invalid input to ' + name + ': must be a ' + type + ', given ' + feature$$1.geometry.type);
|
1877 | }
|
1878 | }
|
1879 | }
|
1880 |
|
1881 |
|
1882 |
|
1883 |
|
1884 |
|
1885 |
|
1886 |
|
1887 |
|
1888 |
|
1889 |
|
1890 |
|
1891 |
|
1892 |
|
1893 |
|
1894 |
|
1895 |
|
1896 |
|
1897 |
|
1898 |
|
1899 | function getGeom(geojson) {
|
1900 | if (!geojson) throw new Error('geojson is required');
|
1901 | if (geojson.geometry !== undefined) return geojson.geometry;
|
1902 | if (geojson.coordinates || geojson.geometries) return geojson;
|
1903 | throw new Error('geojson must be a valid Feature or Geometry Object');
|
1904 | }
|
1905 |
|
1906 |
|
1907 |
|
1908 |
|
1909 |
|
1910 |
|
1911 | function getGeomType() {
|
1912 | throw new Error('invariant.getGeomType has been deprecated in v5.0 in favor of invariant.getType');
|
1913 | }
|
1914 |
|
1915 |
|
1916 |
|
1917 |
|
1918 |
|
1919 |
|
1920 |
|
1921 |
|
1922 |
|
1923 |
|
1924 |
|
1925 |
|
1926 |
|
1927 |
|
1928 |
|
1929 |
|
1930 |
|
1931 |
|
1932 |
|
1933 | function getType(geojson, name) {
|
1934 | if (!geojson) throw new Error((name || 'geojson') + ' is required');
|
1935 |
|
1936 | if (geojson.geometry && geojson.geometry.type) return geojson.geometry.type;
|
1937 |
|
1938 | if (geojson.type) return geojson.type;
|
1939 | throw new Error((name || 'geojson') + ' is invalid');
|
1940 | }
|
1941 |
|
1942 |
|
1943 |
|
1944 |
|
1945 | var main_es$2 = Object.freeze({
|
1946 | getCoord: getCoord,
|
1947 | getCoords: getCoords,
|
1948 | containsNumber: containsNumber,
|
1949 | geojsonType: geojsonType,
|
1950 | featureOf: featureOf,
|
1951 | collectionOf: collectionOf,
|
1952 | getGeom: getGeom,
|
1953 | getGeomType: getGeomType,
|
1954 | getType: getType
|
1955 | });
|
1956 |
|
1957 |
|
1958 |
|
1959 |
|
1960 |
|
1961 |
|
1962 |
|
1963 |
|
1964 |
|
1965 |
|
1966 |
|
1967 |
|
1968 |
|
1969 | var defaultSettings = {
|
1970 | successCallback: null,
|
1971 | verbose: false
|
1972 | };
|
1973 |
|
1974 | var settings = {};
|
1975 |
|
1976 | function isoContours(data, threshold, options) {
|
1977 |
|
1978 | options = options ? options : {};
|
1979 |
|
1980 | var optionKeys = Object.keys(defaultSettings);
|
1981 |
|
1982 | for (var i = 0; i < optionKeys.length; i++) {
|
1983 | var key = optionKeys[i];
|
1984 | var val = options[key];
|
1985 | val = ((typeof val !== 'undefined') && (val !== null)) ? val : defaultSettings[key];
|
1986 |
|
1987 | settings[key] = val;
|
1988 | }
|
1989 |
|
1990 | if (settings.verbose)
|
1991 | console.log('MarchingSquaresJS-isoContours: computing isocontour for ' + threshold);
|
1992 |
|
1993 | var ret = contourGrid2Paths(computeContourGrid(data, threshold));
|
1994 |
|
1995 | if (typeof settings.successCallback === 'function')
|
1996 | settings.successCallback(ret);
|
1997 |
|
1998 | return ret;
|
1999 | }
|
2000 |
|
2001 |
|
2002 |
|
2003 |
|
2004 |
|
2005 |
|
2006 |
|
2007 |
|
2008 |
|
2009 |
|
2010 |
|
2011 |
|
2012 |
|
2013 | function interpolateX(y, y0, y1) {
|
2014 | return (y - y0) / (y1 - y0);
|
2015 | }
|
2016 |
|
2017 |
|
2018 | function computeContourGrid(data, threshold) {
|
2019 | var rows = data.length - 1;
|
2020 | var cols = data[0].length - 1;
|
2021 | var ContourGrid = { rows: rows, cols: cols, cells: [] };
|
2022 |
|
2023 | for (var j = 0; j < rows; ++j) {
|
2024 | ContourGrid.cells[j] = [];
|
2025 | for (var i = 0; i < cols; ++i) {
|
2026 |
|
2027 | var cval = 0;
|
2028 |
|
2029 | var tl = data[j + 1][i];
|
2030 | var tr = data[j + 1][i + 1];
|
2031 | var br = data[j][i + 1];
|
2032 | var bl = data[j][i];
|
2033 |
|
2034 | if (isNaN(tl) || isNaN(tr) || isNaN(br) || isNaN(bl)) {
|
2035 | continue;
|
2036 | }
|
2037 | cval |= ((tl >= threshold) ? 8 : 0);
|
2038 | cval |= ((tr >= threshold) ? 4 : 0);
|
2039 | cval |= ((br >= threshold) ? 2 : 0);
|
2040 | cval |= ((bl >= threshold) ? 1 : 0);
|
2041 |
|
2042 |
|
2043 | var flipped = false;
|
2044 | if (cval === 5 || cval === 10) {
|
2045 | var average = (tl + tr + br + bl) / 4;
|
2046 | if (cval === 5 && (average < threshold)) {
|
2047 | cval = 10;
|
2048 | flipped = true;
|
2049 | } else if (cval === 10 && (average < threshold)) {
|
2050 | cval = 5;
|
2051 | flipped = true;
|
2052 | }
|
2053 | }
|
2054 |
|
2055 |
|
2056 | if (cval !== 0 && cval !== 15) {
|
2057 | var top, bottom, left, right;
|
2058 | top = bottom = left = right = 0.5;
|
2059 |
|
2060 | if (cval === 1) {
|
2061 | left = 1 - interpolateX(threshold, tl, bl);
|
2062 | bottom = 1 - interpolateX(threshold, br, bl);
|
2063 | } else if (cval === 2) {
|
2064 | bottom = interpolateX(threshold, bl, br);
|
2065 | right = 1 - interpolateX(threshold, tr, br);
|
2066 | } else if (cval === 3) {
|
2067 | left = 1 - interpolateX(threshold, tl, bl);
|
2068 | right = 1 - interpolateX(threshold, tr, br);
|
2069 | } else if (cval === 4) {
|
2070 | top = interpolateX(threshold, tl, tr);
|
2071 | right = interpolateX(threshold, br, tr);
|
2072 | } else if (cval === 5) {
|
2073 | top = interpolateX(threshold, tl, tr);
|
2074 | right = interpolateX(threshold, br, tr);
|
2075 | bottom = 1 - interpolateX(threshold, br, bl);
|
2076 | left = 1 - interpolateX(threshold, tl, bl);
|
2077 | } else if (cval === 6) {
|
2078 | bottom = interpolateX(threshold, bl, br);
|
2079 | top = interpolateX(threshold, tl, tr);
|
2080 | } else if (cval === 7) {
|
2081 | left = 1 - interpolateX(threshold, tl, bl);
|
2082 | top = interpolateX(threshold, tl, tr);
|
2083 | } else if (cval === 8) {
|
2084 | left = interpolateX(threshold, bl, tl);
|
2085 | top = 1 - interpolateX(threshold, tr, tl);
|
2086 | } else if (cval === 9) {
|
2087 | bottom = 1 - interpolateX(threshold, br, bl);
|
2088 | top = 1 - interpolateX(threshold, tr, tl);
|
2089 | } else if (cval === 10) {
|
2090 | top = 1 - interpolateX(threshold, tr, tl);
|
2091 | right = 1 - interpolateX(threshold, tr, br);
|
2092 | bottom = interpolateX(threshold, bl, br);
|
2093 | left = interpolateX(threshold, bl, tl);
|
2094 | } else if (cval === 11) {
|
2095 | top = 1 - interpolateX(threshold, tr, tl);
|
2096 | right = 1 - interpolateX(threshold, tr, br);
|
2097 | } else if (cval === 12) {
|
2098 | left = interpolateX(threshold, bl, tl);
|
2099 | right = interpolateX(threshold, br, tr);
|
2100 | } else if (cval === 13) {
|
2101 | bottom = 1 - interpolateX(threshold, br, bl);
|
2102 | right = interpolateX(threshold, br, tr);
|
2103 | } else if (cval === 14) {
|
2104 | left = interpolateX(threshold, bl, tl);
|
2105 | bottom = interpolateX(threshold, bl, br);
|
2106 | } else {
|
2107 | console.log('MarchingSquaresJS-isoContours: Illegal cval detected: ' + cval);
|
2108 | }
|
2109 | ContourGrid.cells[j][i] = {
|
2110 | cval: cval,
|
2111 | flipped: flipped,
|
2112 | top: top,
|
2113 | right: right,
|
2114 | bottom: bottom,
|
2115 | left: left
|
2116 | };
|
2117 | }
|
2118 |
|
2119 | }
|
2120 | }
|
2121 |
|
2122 | return ContourGrid;
|
2123 | }
|
2124 |
|
2125 | function isSaddle(cell) {
|
2126 | return cell.cval === 5 || cell.cval === 10;
|
2127 | }
|
2128 |
|
2129 | function isTrivial(cell) {
|
2130 | return cell.cval === 0 || cell.cval === 15;
|
2131 | }
|
2132 |
|
2133 | function clearCell(cell) {
|
2134 | if ((!isTrivial(cell)) && (cell.cval !== 5) && (cell.cval !== 10)) {
|
2135 | cell.cval = 15;
|
2136 | }
|
2137 | }
|
2138 |
|
2139 | function getXY(cell, edge) {
|
2140 | if (edge === 'top') {
|
2141 | return [cell.top, 1.0];
|
2142 | } else if (edge === 'bottom') {
|
2143 | return [cell.bottom, 0.0];
|
2144 | } else if (edge === 'right') {
|
2145 | return [1.0, cell.right];
|
2146 | } else if (edge === 'left') {
|
2147 | return [0.0, cell.left];
|
2148 | }
|
2149 | }
|
2150 |
|
2151 | function contourGrid2Paths(grid) {
|
2152 | var paths = [];
|
2153 | var path_idx = 0;
|
2154 | var rows = grid.rows;
|
2155 | var cols = grid.cols;
|
2156 | var epsilon = 1e-7;
|
2157 |
|
2158 | grid.cells.forEach(function (g, j) {
|
2159 | g.forEach(function (gg, i) {
|
2160 | if ((typeof gg !== 'undefined') && (!isSaddle(gg)) && (!isTrivial(gg))) {
|
2161 | var p = tracePath(grid.cells, j, i);
|
2162 | var merged = false;
|
2163 |
|
2164 | if (p.info === 'mergeable') {
|
2165 | |
2166 |
|
2167 |
|
2168 |
|
2169 | var x = p.path[p.path.length - 1][0],
|
2170 | y = p.path[p.path.length - 1][1];
|
2171 |
|
2172 | for (var k = path_idx - 1; k >= 0; k--) {
|
2173 | if ((Math.abs(paths[k][0][0] - x) <= epsilon) && (Math.abs(paths[k][0][1] - y) <= epsilon)) {
|
2174 | for (var l = p.path.length - 2; l >= 0; --l) {
|
2175 | paths[k].unshift(p.path[l]);
|
2176 | }
|
2177 | merged = true;
|
2178 | break;
|
2179 | }
|
2180 | }
|
2181 | }
|
2182 | if (!merged)
|
2183 | paths[path_idx++] = p.path;
|
2184 | }
|
2185 | });
|
2186 | });
|
2187 |
|
2188 | return paths;
|
2189 | }
|
2190 |
|
2191 |
|
2192 |
|
2193 |
|
2194 |
|
2195 | function tracePath(grid, j, i) {
|
2196 | var maxj = grid.length;
|
2197 | var p = [];
|
2198 | var dxContour = [0, 0, 1, 1, 0, 0, 0, 0, -1, 0, 1, 1, -1, 0, -1, 0];
|
2199 | var dyContour = [0, -1, 0, 0, 1, 1, 1, 1, 0, -1, 0, 0, 0, -1, 0, 0];
|
2200 | var dx, dy;
|
2201 | var startEdge = ['none', 'left', 'bottom', 'left', 'right', 'none', 'bottom', 'left', 'top', 'top', 'none', 'top', 'right', 'right', 'bottom', 'none'];
|
2202 | var nextEdge = ['none', 'bottom', 'right', 'right', 'top', 'top', 'top', 'top', 'left', 'bottom', 'right', 'right', 'left', 'bottom', 'left', 'none'];
|
2203 | var edge;
|
2204 |
|
2205 | var startCell = grid[j][i];
|
2206 | var currentCell = grid[j][i];
|
2207 |
|
2208 | var cval = currentCell.cval;
|
2209 | var edge = startEdge[cval];
|
2210 |
|
2211 | var pt = getXY(currentCell, edge);
|
2212 |
|
2213 |
|
2214 | p.push([i + pt[0], j + pt[1]]);
|
2215 | edge = nextEdge[cval];
|
2216 | pt = getXY(currentCell, edge);
|
2217 | p.push([i + pt[0], j + pt[1]]);
|
2218 | clearCell(currentCell);
|
2219 |
|
2220 |
|
2221 | var k = i + dxContour[cval];
|
2222 | var l = j + dyContour[cval];
|
2223 | var prev_cval = cval;
|
2224 |
|
2225 | while ((k >= 0) && (l >= 0) && (l < maxj) && ((k != i) || (l != j))) {
|
2226 | currentCell = grid[l][k];
|
2227 | if (typeof currentCell === 'undefined') {
|
2228 |
|
2229 | break;
|
2230 | }
|
2231 | cval = currentCell.cval;
|
2232 | if ((cval === 0) || (cval === 15)) {
|
2233 | return { path: p, info: 'mergeable' };
|
2234 | }
|
2235 | edge = nextEdge[cval];
|
2236 | dx = dxContour[cval];
|
2237 | dy = dyContour[cval];
|
2238 | if ((cval === 5) || (cval === 10)) {
|
2239 |
|
2240 | if (cval === 5) {
|
2241 | if (currentCell.flipped) {
|
2242 | if (dyContour[prev_cval] === -1) {
|
2243 | edge = 'left';
|
2244 | dx = -1;
|
2245 | dy = 0;
|
2246 | } else {
|
2247 | edge = 'right';
|
2248 | dx = 1;
|
2249 | dy = 0;
|
2250 | }
|
2251 | } else {
|
2252 | if (dxContour[prev_cval] === -1) {
|
2253 | edge = 'bottom';
|
2254 | dx = 0;
|
2255 | dy = -1;
|
2256 | }
|
2257 | }
|
2258 | } else if (cval === 10) {
|
2259 | if (currentCell.flipped) {
|
2260 | if (dxContour[prev_cval] === -1) {
|
2261 | edge = 'top';
|
2262 | dx = 0;
|
2263 | dy = 1;
|
2264 | } else {
|
2265 | edge = 'bottom';
|
2266 | dx = 0;
|
2267 | dy = -1;
|
2268 | }
|
2269 | } else {
|
2270 | if (dyContour[prev_cval] === 1) {
|
2271 | edge = 'left';
|
2272 | dx = -1;
|
2273 | dy = 0;
|
2274 | }
|
2275 | }
|
2276 | }
|
2277 | }
|
2278 | pt = getXY(currentCell, edge);
|
2279 | p.push([k + pt[0], l + pt[1]]);
|
2280 | clearCell(currentCell);
|
2281 | k += dx;
|
2282 | l += dy;
|
2283 | prev_cval = cval;
|
2284 | }
|
2285 |
|
2286 | return { path: p, info: 'closed' };
|
2287 | }
|
2288 |
|
2289 |
|
2290 |
|
2291 |
|
2292 |
|
2293 |
|
2294 |
|
2295 |
|
2296 |
|
2297 |
|
2298 |
|
2299 |
|
2300 |
|
2301 |
|
2302 |
|
2303 |
|
2304 |
|
2305 |
|
2306 |
|
2307 |
|
2308 |
|
2309 |
|
2310 |
|
2311 |
|
2312 |
|
2313 |
|
2314 |
|
2315 |
|
2316 |
|
2317 |
|
2318 |
|
2319 |
|
2320 |
|
2321 | function gridToMatrix(grid, options) {
|
2322 |
|
2323 | options = options || {};
|
2324 | if (!isObject(options)) throw new Error('options is invalid');
|
2325 | var zProperty = options.zProperty || 'elevation';
|
2326 | var flip = options.flip;
|
2327 | var flags = options.flags;
|
2328 |
|
2329 |
|
2330 | collectionOf(grid, 'Point', 'input must contain Points');
|
2331 |
|
2332 | var pointsMatrix = sortPointsByLatLng(grid, flip);
|
2333 |
|
2334 | var matrix = [];
|
2335 |
|
2336 |
|
2337 | for (var r = 0; r < pointsMatrix.length; r++) {
|
2338 | var pointRow = pointsMatrix[r];
|
2339 | var row = [];
|
2340 | for (var c = 0; c < pointRow.length; c++) {
|
2341 | var point$$1 = pointRow[c];
|
2342 |
|
2343 | if (point$$1.properties[zProperty]) row.push(point$$1.properties[zProperty]);
|
2344 | else row.push(0);
|
2345 |
|
2346 | if (flags === true) point$$1.properties.matrixPosition = [r, c];
|
2347 | }
|
2348 | matrix.push(row);
|
2349 | }
|
2350 |
|
2351 | return matrix;
|
2352 | }
|
2353 |
|
2354 |
|
2355 |
|
2356 |
|
2357 |
|
2358 |
|
2359 |
|
2360 |
|
2361 |
|
2362 | function sortPointsByLatLng(points$$1, flip) {
|
2363 | var pointsByLatitude = {};
|
2364 |
|
2365 |
|
2366 | featureEach(points$$1, function (point$$1) {
|
2367 | var lat = getCoords(point$$1)[1];
|
2368 | if (!pointsByLatitude[lat]) pointsByLatitude[lat] = [];
|
2369 | pointsByLatitude[lat].push(point$$1);
|
2370 | });
|
2371 |
|
2372 |
|
2373 | var orderedRowsByLatitude = Object.keys(pointsByLatitude).map(function (lat) {
|
2374 | var row = pointsByLatitude[lat];
|
2375 | var rowOrderedByLongitude = row.sort(function (a, b) {
|
2376 | return getCoords(a)[0] - getCoords(b)[0];
|
2377 | });
|
2378 | return rowOrderedByLongitude;
|
2379 | });
|
2380 |
|
2381 |
|
2382 | var pointMatrix = orderedRowsByLatitude.sort(function (a, b) {
|
2383 | if (flip) return getCoords(a[0])[1] - getCoords(b[0])[1];
|
2384 | else return getCoords(b[0])[1] - getCoords(a[0])[1];
|
2385 | });
|
2386 |
|
2387 | return pointMatrix;
|
2388 | }
|
2389 |
|
2390 |
|
2391 |
|
2392 |
|
2393 |
|
2394 |
|
2395 |
|
2396 |
|
2397 |
|
2398 |
|
2399 |
|
2400 |
|
2401 |
|
2402 |
|
2403 |
|
2404 |
|
2405 |
|
2406 |
|
2407 |
|
2408 |
|
2409 |
|
2410 |
|
2411 |
|
2412 |
|
2413 |
|
2414 |
|
2415 |
|
2416 |
|
2417 |
|
2418 |
|
2419 | function isolines(pointGrid, breaks, options) {
|
2420 |
|
2421 | options = options || {};
|
2422 | if (!isObject(options)) throw new Error('options is invalid');
|
2423 | var zProperty = options.zProperty || 'elevation';
|
2424 | var commonProperties = options.commonProperties || {};
|
2425 | var breaksProperties = options.breaksProperties || [];
|
2426 |
|
2427 |
|
2428 | collectionOf(pointGrid, 'Point', 'Input must contain Points');
|
2429 | if (!breaks) throw new Error('breaks is required');
|
2430 | if (!Array.isArray(breaks)) throw new Error('breaks must be an Array');
|
2431 | if (!isObject(commonProperties)) throw new Error('commonProperties must be an Object');
|
2432 | if (!Array.isArray(breaksProperties)) throw new Error('breaksProperties must be an Array');
|
2433 |
|
2434 |
|
2435 | var matrix = gridToMatrix(pointGrid, {zProperty: zProperty, flip: true});
|
2436 | var createdIsoLines = createIsoLines(matrix, breaks, zProperty, commonProperties, breaksProperties);
|
2437 | var scaledIsolines = rescaleIsolines(createdIsoLines, matrix, pointGrid);
|
2438 |
|
2439 | return featureCollection(scaledIsolines);
|
2440 | }
|
2441 |
|
2442 |
|
2443 |
|
2444 |
|
2445 |
|
2446 |
|
2447 |
|
2448 |
|
2449 |
|
2450 |
|
2451 |
|
2452 |
|
2453 |
|
2454 |
|
2455 |
|
2456 |
|
2457 | function createIsoLines(matrix, breaks, zProperty, commonProperties, breaksProperties) {
|
2458 | var results = [];
|
2459 | for (var i = 1; i < breaks.length; i++) {
|
2460 | var threshold = +breaks[i];
|
2461 |
|
2462 | var properties = Object.assign(
|
2463 | {},
|
2464 | commonProperties,
|
2465 | breaksProperties[i]
|
2466 | );
|
2467 | properties[zProperty] = threshold;
|
2468 | var isoline = multiLineString(isoContours(matrix, threshold), properties);
|
2469 |
|
2470 | results.push(isoline);
|
2471 | }
|
2472 | return results;
|
2473 | }
|
2474 |
|
2475 |
|
2476 |
|
2477 |
|
2478 |
|
2479 |
|
2480 |
|
2481 |
|
2482 |
|
2483 |
|
2484 | function rescaleIsolines(createdIsoLines, matrix, points$$1) {
|
2485 |
|
2486 |
|
2487 | var gridBbox = bbox(points$$1);
|
2488 | var originalWidth = gridBbox[2] - gridBbox[0];
|
2489 | var originalHeigth = gridBbox[3] - gridBbox[1];
|
2490 |
|
2491 |
|
2492 | var x0 = gridBbox[0];
|
2493 | var y0 = gridBbox[1];
|
2494 |
|
2495 |
|
2496 | var matrixWidth = matrix[0].length - 1;
|
2497 | var matrixHeight = matrix.length - 1;
|
2498 |
|
2499 |
|
2500 | var scaleX = originalWidth / matrixWidth;
|
2501 | var scaleY = originalHeigth / matrixHeight;
|
2502 |
|
2503 | var resize = function (point$$1) {
|
2504 | point$$1[0] = point$$1[0] * scaleX + x0;
|
2505 | point$$1[1] = point$$1[1] * scaleY + y0;
|
2506 | };
|
2507 |
|
2508 |
|
2509 | createdIsoLines.forEach(function (isoline) {
|
2510 | coordEach(isoline, resize);
|
2511 | });
|
2512 | return createdIsoLines;
|
2513 | }
|
2514 |
|
2515 | var quickselect = partialSort;
|
2516 |
|
2517 |
|
2518 |
|
2519 |
|
2520 |
|
2521 | function partialSort(arr, k, left, right, compare) {
|
2522 | left = left || 0;
|
2523 | right = right || (arr.length - 1);
|
2524 | compare = compare || defaultCompare;
|
2525 |
|
2526 | while (right > left) {
|
2527 | if (right - left > 600) {
|
2528 | var n = right - left + 1;
|
2529 | var m = k - left + 1;
|
2530 | var z = Math.log(n);
|
2531 | var s = 0.5 * Math.exp(2 * z / 3);
|
2532 | var sd = 0.5 * Math.sqrt(z * s * (n - s) / n) * (m - n / 2 < 0 ? -1 : 1);
|
2533 | var newLeft = Math.max(left, Math.floor(k - m * s / n + sd));
|
2534 | var newRight = Math.min(right, Math.floor(k + (n - m) * s / n + sd));
|
2535 | partialSort(arr, k, newLeft, newRight, compare);
|
2536 | }
|
2537 |
|
2538 | var t = arr[k];
|
2539 | var i = left;
|
2540 | var j = right;
|
2541 |
|
2542 | swap(arr, left, k);
|
2543 | if (compare(arr[right], t) > 0) swap(arr, left, right);
|
2544 |
|
2545 | while (i < j) {
|
2546 | swap(arr, i, j);
|
2547 | i++;
|
2548 | j--;
|
2549 | while (compare(arr[i], t) < 0) i++;
|
2550 | while (compare(arr[j], t) > 0) j--;
|
2551 | }
|
2552 |
|
2553 | if (compare(arr[left], t) === 0) swap(arr, left, j);
|
2554 | else {
|
2555 | j++;
|
2556 | swap(arr, j, right);
|
2557 | }
|
2558 |
|
2559 | if (j <= k) left = j + 1;
|
2560 | if (k <= j) right = j - 1;
|
2561 | }
|
2562 | }
|
2563 |
|
2564 | function swap(arr, i, j) {
|
2565 | var tmp = arr[i];
|
2566 | arr[i] = arr[j];
|
2567 | arr[j] = tmp;
|
2568 | }
|
2569 |
|
2570 | function defaultCompare(a, b) {
|
2571 | return a < b ? -1 : a > b ? 1 : 0;
|
2572 | }
|
2573 |
|
2574 | var rbush_1 = rbush;
|
2575 |
|
2576 |
|
2577 |
|
2578 | function rbush(maxEntries, format) {
|
2579 | if (!(this instanceof rbush)) return new rbush(maxEntries, format);
|
2580 |
|
2581 |
|
2582 | this._maxEntries = Math.max(4, maxEntries || 9);
|
2583 | this._minEntries = Math.max(2, Math.ceil(this._maxEntries * 0.4));
|
2584 |
|
2585 | if (format) {
|
2586 | this._initFormat(format);
|
2587 | }
|
2588 |
|
2589 | this.clear();
|
2590 | }
|
2591 |
|
2592 | rbush.prototype = {
|
2593 |
|
2594 | all: function () {
|
2595 | return this._all(this.data, []);
|
2596 | },
|
2597 |
|
2598 | search: function (bbox) {
|
2599 |
|
2600 | var node = this.data,
|
2601 | result = [],
|
2602 | toBBox = this.toBBox;
|
2603 |
|
2604 | if (!intersects$1(bbox, node)) return result;
|
2605 |
|
2606 | var nodesToSearch = [],
|
2607 | i, len, child, childBBox;
|
2608 |
|
2609 | while (node) {
|
2610 | for (i = 0, len = node.children.length; i < len; i++) {
|
2611 |
|
2612 | child = node.children[i];
|
2613 | childBBox = node.leaf ? toBBox(child) : child;
|
2614 |
|
2615 | if (intersects$1(bbox, childBBox)) {
|
2616 | if (node.leaf) result.push(child);
|
2617 | else if (contains(bbox, childBBox)) this._all(child, result);
|
2618 | else nodesToSearch.push(child);
|
2619 | }
|
2620 | }
|
2621 | node = nodesToSearch.pop();
|
2622 | }
|
2623 |
|
2624 | return result;
|
2625 | },
|
2626 |
|
2627 | collides: function (bbox) {
|
2628 |
|
2629 | var node = this.data,
|
2630 | toBBox = this.toBBox;
|
2631 |
|
2632 | if (!intersects$1(bbox, node)) return false;
|
2633 |
|
2634 | var nodesToSearch = [],
|
2635 | i, len, child, childBBox;
|
2636 |
|
2637 | while (node) {
|
2638 | for (i = 0, len = node.children.length; i < len; i++) {
|
2639 |
|
2640 | child = node.children[i];
|
2641 | childBBox = node.leaf ? toBBox(child) : child;
|
2642 |
|
2643 | if (intersects$1(bbox, childBBox)) {
|
2644 | if (node.leaf || contains(bbox, childBBox)) return true;
|
2645 | nodesToSearch.push(child);
|
2646 | }
|
2647 | }
|
2648 | node = nodesToSearch.pop();
|
2649 | }
|
2650 |
|
2651 | return false;
|
2652 | },
|
2653 |
|
2654 | load: function (data) {
|
2655 | if (!(data && data.length)) return this;
|
2656 |
|
2657 | if (data.length < this._minEntries) {
|
2658 | for (var i = 0, len = data.length; i < len; i++) {
|
2659 | this.insert(data[i]);
|
2660 | }
|
2661 | return this;
|
2662 | }
|
2663 |
|
2664 |
|
2665 | var node = this._build(data.slice(), 0, data.length - 1, 0);
|
2666 |
|
2667 | if (!this.data.children.length) {
|
2668 |
|
2669 | this.data = node;
|
2670 |
|
2671 | } else if (this.data.height === node.height) {
|
2672 |
|
2673 | this._splitRoot(this.data, node);
|
2674 |
|
2675 | } else {
|
2676 | if (this.data.height < node.height) {
|
2677 |
|
2678 | var tmpNode = this.data;
|
2679 | this.data = node;
|
2680 | node = tmpNode;
|
2681 | }
|
2682 |
|
2683 |
|
2684 | this._insert(node, this.data.height - node.height - 1, true);
|
2685 | }
|
2686 |
|
2687 | return this;
|
2688 | },
|
2689 |
|
2690 | insert: function (item) {
|
2691 | if (item) this._insert(item, this.data.height - 1);
|
2692 | return this;
|
2693 | },
|
2694 |
|
2695 | clear: function () {
|
2696 | this.data = createNode([]);
|
2697 | return this;
|
2698 | },
|
2699 |
|
2700 | remove: function (item, equalsFn) {
|
2701 | if (!item) return this;
|
2702 |
|
2703 | var node = this.data,
|
2704 | bbox = this.toBBox(item),
|
2705 | path = [],
|
2706 | indexes = [],
|
2707 | i, parent, index, goingUp;
|
2708 |
|
2709 |
|
2710 | while (node || path.length) {
|
2711 |
|
2712 | if (!node) {
|
2713 | node = path.pop();
|
2714 | parent = path[path.length - 1];
|
2715 | i = indexes.pop();
|
2716 | goingUp = true;
|
2717 | }
|
2718 |
|
2719 | if (node.leaf) {
|
2720 | index = findItem(item, node.children, equalsFn);
|
2721 |
|
2722 | if (index !== -1) {
|
2723 |
|
2724 | node.children.splice(index, 1);
|
2725 | path.push(node);
|
2726 | this._condense(path);
|
2727 | return this;
|
2728 | }
|
2729 | }
|
2730 |
|
2731 | if (!goingUp && !node.leaf && contains(node, bbox)) {
|
2732 | path.push(node);
|
2733 | indexes.push(i);
|
2734 | i = 0;
|
2735 | parent = node;
|
2736 | node = node.children[0];
|
2737 |
|
2738 | } else if (parent) {
|
2739 | i++;
|
2740 | node = parent.children[i];
|
2741 | goingUp = false;
|
2742 |
|
2743 | } else node = null;
|
2744 | }
|
2745 |
|
2746 | return this;
|
2747 | },
|
2748 |
|
2749 | toBBox: function (item) { return item; },
|
2750 |
|
2751 | compareMinX: compareNodeMinX,
|
2752 | compareMinY: compareNodeMinY,
|
2753 |
|
2754 | toJSON: function () { return this.data; },
|
2755 |
|
2756 | fromJSON: function (data) {
|
2757 | this.data = data;
|
2758 | return this;
|
2759 | },
|
2760 |
|
2761 | _all: function (node, result) {
|
2762 | var nodesToSearch = [];
|
2763 | while (node) {
|
2764 | if (node.leaf) result.push.apply(result, node.children);
|
2765 | else nodesToSearch.push.apply(nodesToSearch, node.children);
|
2766 |
|
2767 | node = nodesToSearch.pop();
|
2768 | }
|
2769 | return result;
|
2770 | },
|
2771 |
|
2772 | _build: function (items, left, right, height) {
|
2773 |
|
2774 | var N = right - left + 1,
|
2775 | M = this._maxEntries,
|
2776 | node;
|
2777 |
|
2778 | if (N <= M) {
|
2779 |
|
2780 | node = createNode(items.slice(left, right + 1));
|
2781 | calcBBox(node, this.toBBox);
|
2782 | return node;
|
2783 | }
|
2784 |
|
2785 | if (!height) {
|
2786 |
|
2787 | height = Math.ceil(Math.log(N) / Math.log(M));
|
2788 |
|
2789 |
|
2790 | M = Math.ceil(N / Math.pow(M, height - 1));
|
2791 | }
|
2792 |
|
2793 | node = createNode([]);
|
2794 | node.leaf = false;
|
2795 | node.height = height;
|
2796 |
|
2797 |
|
2798 |
|
2799 | var N2 = Math.ceil(N / M),
|
2800 | N1 = N2 * Math.ceil(Math.sqrt(M)),
|
2801 | i, j, right2, right3;
|
2802 |
|
2803 | multiSelect(items, left, right, N1, this.compareMinX);
|
2804 |
|
2805 | for (i = left; i <= right; i += N1) {
|
2806 |
|
2807 | right2 = Math.min(i + N1 - 1, right);
|
2808 |
|
2809 | multiSelect(items, i, right2, N2, this.compareMinY);
|
2810 |
|
2811 | for (j = i; j <= right2; j += N2) {
|
2812 |
|
2813 | right3 = Math.min(j + N2 - 1, right2);
|
2814 |
|
2815 |
|
2816 | node.children.push(this._build(items, j, right3, height - 1));
|
2817 | }
|
2818 | }
|
2819 |
|
2820 | calcBBox(node, this.toBBox);
|
2821 |
|
2822 | return node;
|
2823 | },
|
2824 |
|
2825 | _chooseSubtree: function (bbox, node, level, path) {
|
2826 |
|
2827 | var i, len, child, targetNode, area, enlargement, minArea, minEnlargement;
|
2828 |
|
2829 | while (true) {
|
2830 | path.push(node);
|
2831 |
|
2832 | if (node.leaf || path.length - 1 === level) break;
|
2833 |
|
2834 | minArea = minEnlargement = Infinity;
|
2835 |
|
2836 | for (i = 0, len = node.children.length; i < len; i++) {
|
2837 | child = node.children[i];
|
2838 | area = bboxArea(child);
|
2839 | enlargement = enlargedArea(bbox, child) - area;
|
2840 |
|
2841 |
|
2842 | if (enlargement < minEnlargement) {
|
2843 | minEnlargement = enlargement;
|
2844 | minArea = area < minArea ? area : minArea;
|
2845 | targetNode = child;
|
2846 |
|
2847 | } else if (enlargement === minEnlargement) {
|
2848 |
|
2849 | if (area < minArea) {
|
2850 | minArea = area;
|
2851 | targetNode = child;
|
2852 | }
|
2853 | }
|
2854 | }
|
2855 |
|
2856 | node = targetNode || node.children[0];
|
2857 | }
|
2858 |
|
2859 | return node;
|
2860 | },
|
2861 |
|
2862 | _insert: function (item, level, isNode) {
|
2863 |
|
2864 | var toBBox = this.toBBox,
|
2865 | bbox = isNode ? item : toBBox(item),
|
2866 | insertPath = [];
|
2867 |
|
2868 |
|
2869 | var node = this._chooseSubtree(bbox, this.data, level, insertPath);
|
2870 |
|
2871 |
|
2872 | node.children.push(item);
|
2873 | extend(node, bbox);
|
2874 |
|
2875 |
|
2876 | while (level >= 0) {
|
2877 | if (insertPath[level].children.length > this._maxEntries) {
|
2878 | this._split(insertPath, level);
|
2879 | level--;
|
2880 | } else break;
|
2881 | }
|
2882 |
|
2883 |
|
2884 | this._adjustParentBBoxes(bbox, insertPath, level);
|
2885 | },
|
2886 |
|
2887 |
|
2888 | _split: function (insertPath, level) {
|
2889 |
|
2890 | var node = insertPath[level],
|
2891 | M = node.children.length,
|
2892 | m = this._minEntries;
|
2893 |
|
2894 | this._chooseSplitAxis(node, m, M);
|
2895 |
|
2896 | var splitIndex = this._chooseSplitIndex(node, m, M);
|
2897 |
|
2898 | var newNode = createNode(node.children.splice(splitIndex, node.children.length - splitIndex));
|
2899 | newNode.height = node.height;
|
2900 | newNode.leaf = node.leaf;
|
2901 |
|
2902 | calcBBox(node, this.toBBox);
|
2903 | calcBBox(newNode, this.toBBox);
|
2904 |
|
2905 | if (level) insertPath[level - 1].children.push(newNode);
|
2906 | else this._splitRoot(node, newNode);
|
2907 | },
|
2908 |
|
2909 | _splitRoot: function (node, newNode) {
|
2910 |
|
2911 | this.data = createNode([node, newNode]);
|
2912 | this.data.height = node.height + 1;
|
2913 | this.data.leaf = false;
|
2914 | calcBBox(this.data, this.toBBox);
|
2915 | },
|
2916 |
|
2917 | _chooseSplitIndex: function (node, m, M) {
|
2918 |
|
2919 | var i, bbox1, bbox2, overlap, area, minOverlap, minArea, index;
|
2920 |
|
2921 | minOverlap = minArea = Infinity;
|
2922 |
|
2923 | for (i = m; i <= M - m; i++) {
|
2924 | bbox1 = distBBox(node, 0, i, this.toBBox);
|
2925 | bbox2 = distBBox(node, i, M, this.toBBox);
|
2926 |
|
2927 | overlap = intersectionArea(bbox1, bbox2);
|
2928 | area = bboxArea(bbox1) + bboxArea(bbox2);
|
2929 |
|
2930 |
|
2931 | if (overlap < minOverlap) {
|
2932 | minOverlap = overlap;
|
2933 | index = i;
|
2934 |
|
2935 | minArea = area < minArea ? area : minArea;
|
2936 |
|
2937 | } else if (overlap === minOverlap) {
|
2938 |
|
2939 | if (area < minArea) {
|
2940 | minArea = area;
|
2941 | index = i;
|
2942 | }
|
2943 | }
|
2944 | }
|
2945 |
|
2946 | return index;
|
2947 | },
|
2948 |
|
2949 |
|
2950 | _chooseSplitAxis: function (node, m, M) {
|
2951 |
|
2952 | var compareMinX = node.leaf ? this.compareMinX : compareNodeMinX,
|
2953 | compareMinY = node.leaf ? this.compareMinY : compareNodeMinY,
|
2954 | xMargin = this._allDistMargin(node, m, M, compareMinX),
|
2955 | yMargin = this._allDistMargin(node, m, M, compareMinY);
|
2956 |
|
2957 |
|
2958 |
|
2959 | if (xMargin < yMargin) node.children.sort(compareMinX);
|
2960 | },
|
2961 |
|
2962 |
|
2963 | _allDistMargin: function (node, m, M, compare) {
|
2964 |
|
2965 | node.children.sort(compare);
|
2966 |
|
2967 | var toBBox = this.toBBox,
|
2968 | leftBBox = distBBox(node, 0, m, toBBox),
|
2969 | rightBBox = distBBox(node, M - m, M, toBBox),
|
2970 | margin = bboxMargin(leftBBox) + bboxMargin(rightBBox),
|
2971 | i, child;
|
2972 |
|
2973 | for (i = m; i < M - m; i++) {
|
2974 | child = node.children[i];
|
2975 | extend(leftBBox, node.leaf ? toBBox(child) : child);
|
2976 | margin += bboxMargin(leftBBox);
|
2977 | }
|
2978 |
|
2979 | for (i = M - m - 1; i >= m; i--) {
|
2980 | child = node.children[i];
|
2981 | extend(rightBBox, node.leaf ? toBBox(child) : child);
|
2982 | margin += bboxMargin(rightBBox);
|
2983 | }
|
2984 |
|
2985 | return margin;
|
2986 | },
|
2987 |
|
2988 | _adjustParentBBoxes: function (bbox, path, level) {
|
2989 |
|
2990 | for (var i = level; i >= 0; i--) {
|
2991 | extend(path[i], bbox);
|
2992 | }
|
2993 | },
|
2994 |
|
2995 | _condense: function (path) {
|
2996 |
|
2997 | for (var i = path.length - 1, siblings; i >= 0; i--) {
|
2998 | if (path[i].children.length === 0) {
|
2999 | if (i > 0) {
|
3000 | siblings = path[i - 1].children;
|
3001 | siblings.splice(siblings.indexOf(path[i]), 1);
|
3002 |
|
3003 | } else this.clear();
|
3004 |
|
3005 | } else calcBBox(path[i], this.toBBox);
|
3006 | }
|
3007 | },
|
3008 |
|
3009 | _initFormat: function (format) {
|
3010 |
|
3011 |
|
3012 |
|
3013 |
|
3014 |
|
3015 |
|
3016 | var compareArr = ['return a', ' - b', ';'];
|
3017 |
|
3018 | this.compareMinX = new Function('a', 'b', compareArr.join(format[0]));
|
3019 | this.compareMinY = new Function('a', 'b', compareArr.join(format[1]));
|
3020 |
|
3021 | this.toBBox = new Function('a',
|
3022 | 'return {minX: a' + format[0] +
|
3023 | ', minY: a' + format[1] +
|
3024 | ', maxX: a' + format[2] +
|
3025 | ', maxY: a' + format[3] + '};');
|
3026 | }
|
3027 | };
|
3028 |
|
3029 | function findItem(item, items, equalsFn) {
|
3030 | if (!equalsFn) return items.indexOf(item);
|
3031 |
|
3032 | for (var i = 0; i < items.length; i++) {
|
3033 | if (equalsFn(item, items[i])) return i;
|
3034 | }
|
3035 | return -1;
|
3036 | }
|
3037 |
|
3038 |
|
3039 | function calcBBox(node, toBBox) {
|
3040 | distBBox(node, 0, node.children.length, toBBox, node);
|
3041 | }
|
3042 |
|
3043 |
|
3044 | function distBBox(node, k, p, toBBox, destNode) {
|
3045 | if (!destNode) destNode = createNode(null);
|
3046 | destNode.minX = Infinity;
|
3047 | destNode.minY = Infinity;
|
3048 | destNode.maxX = -Infinity;
|
3049 | destNode.maxY = -Infinity;
|
3050 |
|
3051 | for (var i = k, child; i < p; i++) {
|
3052 | child = node.children[i];
|
3053 | extend(destNode, node.leaf ? toBBox(child) : child);
|
3054 | }
|
3055 |
|
3056 | return destNode;
|
3057 | }
|
3058 |
|
3059 | function extend(a, b) {
|
3060 | a.minX = Math.min(a.minX, b.minX);
|
3061 | a.minY = Math.min(a.minY, b.minY);
|
3062 | a.maxX = Math.max(a.maxX, b.maxX);
|
3063 | a.maxY = Math.max(a.maxY, b.maxY);
|
3064 | return a;
|
3065 | }
|
3066 |
|
3067 | function compareNodeMinX(a, b) { return a.minX - b.minX; }
|
3068 | function compareNodeMinY(a, b) { return a.minY - b.minY; }
|
3069 |
|
3070 | function bboxArea(a) { return (a.maxX - a.minX) * (a.maxY - a.minY); }
|
3071 | function bboxMargin(a) { return (a.maxX - a.minX) + (a.maxY - a.minY); }
|
3072 |
|
3073 | function enlargedArea(a, b) {
|
3074 | return (Math.max(b.maxX, a.maxX) - Math.min(b.minX, a.minX)) *
|
3075 | (Math.max(b.maxY, a.maxY) - Math.min(b.minY, a.minY));
|
3076 | }
|
3077 |
|
3078 | function intersectionArea(a, b) {
|
3079 | var minX = Math.max(a.minX, b.minX),
|
3080 | minY = Math.max(a.minY, b.minY),
|
3081 | maxX = Math.min(a.maxX, b.maxX),
|
3082 | maxY = Math.min(a.maxY, b.maxY);
|
3083 |
|
3084 | return Math.max(0, maxX - minX) *
|
3085 | Math.max(0, maxY - minY);
|
3086 | }
|
3087 |
|
3088 | function contains(a, b) {
|
3089 | return a.minX <= b.minX &&
|
3090 | a.minY <= b.minY &&
|
3091 | b.maxX <= a.maxX &&
|
3092 | b.maxY <= a.maxY;
|
3093 | }
|
3094 |
|
3095 | function intersects$1(a, b) {
|
3096 | return b.minX <= a.maxX &&
|
3097 | b.minY <= a.maxY &&
|
3098 | b.maxX >= a.minX &&
|
3099 | b.maxY >= a.minY;
|
3100 | }
|
3101 |
|
3102 | function createNode(children) {
|
3103 | return {
|
3104 | children: children,
|
3105 | height: 1,
|
3106 | leaf: true,
|
3107 | minX: Infinity,
|
3108 | minY: Infinity,
|
3109 | maxX: -Infinity,
|
3110 | maxY: -Infinity
|
3111 | };
|
3112 | }
|
3113 |
|
3114 |
|
3115 |
|
3116 |
|
3117 | function multiSelect(arr, left, right, n, compare) {
|
3118 | var stack = [left, right],
|
3119 | mid;
|
3120 |
|
3121 | while (stack.length) {
|
3122 | right = stack.pop();
|
3123 | left = stack.pop();
|
3124 |
|
3125 | if (right - left <= n) continue;
|
3126 |
|
3127 | mid = left + Math.ceil((right - left) / n / 2) * n;
|
3128 | quickselect(arr, mid, left, right, compare);
|
3129 |
|
3130 | stack.push(left, mid, mid, right);
|
3131 | }
|
3132 | }
|
3133 |
|
3134 | function createCommonjsModule(fn, module) {
|
3135 | return module = { exports: {} }, fn(module, module.exports), module.exports;
|
3136 | }
|
3137 |
|
3138 | var twoProduct_1 = twoProduct;
|
3139 |
|
3140 | var SPLITTER = +(Math.pow(2, 27) + 1.0);
|
3141 |
|
3142 | function twoProduct(a, b, result) {
|
3143 | var x = a * b;
|
3144 |
|
3145 | var c = SPLITTER * a;
|
3146 | var abig = c - a;
|
3147 | var ahi = c - abig;
|
3148 | var alo = a - ahi;
|
3149 |
|
3150 | var d = SPLITTER * b;
|
3151 | var bbig = d - b;
|
3152 | var bhi = d - bbig;
|
3153 | var blo = b - bhi;
|
3154 |
|
3155 | var err1 = x - (ahi * bhi);
|
3156 | var err2 = err1 - (alo * bhi);
|
3157 | var err3 = err2 - (ahi * blo);
|
3158 |
|
3159 | var y = alo * blo - err3;
|
3160 |
|
3161 | if(result) {
|
3162 | result[0] = y;
|
3163 | result[1] = x;
|
3164 | return result
|
3165 | }
|
3166 |
|
3167 | return [ y, x ]
|
3168 | }
|
3169 |
|
3170 | var robustSum = linearExpansionSum;
|
3171 |
|
3172 |
|
3173 | function scalarScalar(a, b) {
|
3174 | var x = a + b;
|
3175 | var bv = x - a;
|
3176 | var av = x - bv;
|
3177 | var br = b - bv;
|
3178 | var ar = a - av;
|
3179 | var y = ar + br;
|
3180 | if(y) {
|
3181 | return [y, x]
|
3182 | }
|
3183 | return [x]
|
3184 | }
|
3185 |
|
3186 | function linearExpansionSum(e, f) {
|
3187 | var ne = e.length|0;
|
3188 | var nf = f.length|0;
|
3189 | if(ne === 1 && nf === 1) {
|
3190 | return scalarScalar(e[0], f[0])
|
3191 | }
|
3192 | var n = ne + nf;
|
3193 | var g = new Array(n);
|
3194 | var count = 0;
|
3195 | var eptr = 0;
|
3196 | var fptr = 0;
|
3197 | var abs = Math.abs;
|
3198 | var ei = e[eptr];
|
3199 | var ea = abs(ei);
|
3200 | var fi = f[fptr];
|
3201 | var fa = abs(fi);
|
3202 | var a, b;
|
3203 | if(ea < fa) {
|
3204 | b = ei;
|
3205 | eptr += 1;
|
3206 | if(eptr < ne) {
|
3207 | ei = e[eptr];
|
3208 | ea = abs(ei);
|
3209 | }
|
3210 | } else {
|
3211 | b = fi;
|
3212 | fptr += 1;
|
3213 | if(fptr < nf) {
|
3214 | fi = f[fptr];
|
3215 | fa = abs(fi);
|
3216 | }
|
3217 | }
|
3218 | if((eptr < ne && ea < fa) || (fptr >= nf)) {
|
3219 | a = ei;
|
3220 | eptr += 1;
|
3221 | if(eptr < ne) {
|
3222 | ei = e[eptr];
|
3223 | ea = abs(ei);
|
3224 | }
|
3225 | } else {
|
3226 | a = fi;
|
3227 | fptr += 1;
|
3228 | if(fptr < nf) {
|
3229 | fi = f[fptr];
|
3230 | fa = abs(fi);
|
3231 | }
|
3232 | }
|
3233 | var x = a + b;
|
3234 | var bv = x - a;
|
3235 | var y = b - bv;
|
3236 | var q0 = y;
|
3237 | var q1 = x;
|
3238 | var _x, _bv, _av, _br, _ar;
|
3239 | while(eptr < ne && fptr < nf) {
|
3240 | if(ea < fa) {
|
3241 | a = ei;
|
3242 | eptr += 1;
|
3243 | if(eptr < ne) {
|
3244 | ei = e[eptr];
|
3245 | ea = abs(ei);
|
3246 | }
|
3247 | } else {
|
3248 | a = fi;
|
3249 | fptr += 1;
|
3250 | if(fptr < nf) {
|
3251 | fi = f[fptr];
|
3252 | fa = abs(fi);
|
3253 | }
|
3254 | }
|
3255 | b = q0;
|
3256 | x = a + b;
|
3257 | bv = x - a;
|
3258 | y = b - bv;
|
3259 | if(y) {
|
3260 | g[count++] = y;
|
3261 | }
|
3262 | _x = q1 + x;
|
3263 | _bv = _x - q1;
|
3264 | _av = _x - _bv;
|
3265 | _br = x - _bv;
|
3266 | _ar = q1 - _av;
|
3267 | q0 = _ar + _br;
|
3268 | q1 = _x;
|
3269 | }
|
3270 | while(eptr < ne) {
|
3271 | a = ei;
|
3272 | b = q0;
|
3273 | x = a + b;
|
3274 | bv = x - a;
|
3275 | y = b - bv;
|
3276 | if(y) {
|
3277 | g[count++] = y;
|
3278 | }
|
3279 | _x = q1 + x;
|
3280 | _bv = _x - q1;
|
3281 | _av = _x - _bv;
|
3282 | _br = x - _bv;
|
3283 | _ar = q1 - _av;
|
3284 | q0 = _ar + _br;
|
3285 | q1 = _x;
|
3286 | eptr += 1;
|
3287 | if(eptr < ne) {
|
3288 | ei = e[eptr];
|
3289 | }
|
3290 | }
|
3291 | while(fptr < nf) {
|
3292 | a = fi;
|
3293 | b = q0;
|
3294 | x = a + b;
|
3295 | bv = x - a;
|
3296 | y = b - bv;
|
3297 | if(y) {
|
3298 | g[count++] = y;
|
3299 | }
|
3300 | _x = q1 + x;
|
3301 | _bv = _x - q1;
|
3302 | _av = _x - _bv;
|
3303 | _br = x - _bv;
|
3304 | _ar = q1 - _av;
|
3305 | q0 = _ar + _br;
|
3306 | q1 = _x;
|
3307 | fptr += 1;
|
3308 | if(fptr < nf) {
|
3309 | fi = f[fptr];
|
3310 | }
|
3311 | }
|
3312 | if(q0) {
|
3313 | g[count++] = q0;
|
3314 | }
|
3315 | if(q1) {
|
3316 | g[count++] = q1;
|
3317 | }
|
3318 | if(!count) {
|
3319 | g[count++] = 0.0;
|
3320 | }
|
3321 | g.length = count;
|
3322 | return g
|
3323 | }
|
3324 |
|
3325 | var twoSum = fastTwoSum;
|
3326 |
|
3327 | function fastTwoSum(a, b, result) {
|
3328 | var x = a + b;
|
3329 | var bv = x - a;
|
3330 | var av = x - bv;
|
3331 | var br = b - bv;
|
3332 | var ar = a - av;
|
3333 | if(result) {
|
3334 | result[0] = ar + br;
|
3335 | result[1] = x;
|
3336 | return result
|
3337 | }
|
3338 | return [ar+br, x]
|
3339 | }
|
3340 |
|
3341 | var robustScale = scaleLinearExpansion;
|
3342 |
|
3343 | function scaleLinearExpansion(e, scale) {
|
3344 | var n = e.length;
|
3345 | if(n === 1) {
|
3346 | var ts = twoProduct_1(e[0], scale);
|
3347 | if(ts[0]) {
|
3348 | return ts
|
3349 | }
|
3350 | return [ ts[1] ]
|
3351 | }
|
3352 | var g = new Array(2 * n);
|
3353 | var q = [0.1, 0.1];
|
3354 | var t = [0.1, 0.1];
|
3355 | var count = 0;
|
3356 | twoProduct_1(e[0], scale, q);
|
3357 | if(q[0]) {
|
3358 | g[count++] = q[0];
|
3359 | }
|
3360 | for(var i=1; i<n; ++i) {
|
3361 | twoProduct_1(e[i], scale, t);
|
3362 | var pq = q[1];
|
3363 | twoSum(pq, t[0], q);
|
3364 | if(q[0]) {
|
3365 | g[count++] = q[0];
|
3366 | }
|
3367 | var a = t[1];
|
3368 | var b = q[1];
|
3369 | var x = a + b;
|
3370 | var bv = x - a;
|
3371 | var y = b - bv;
|
3372 | q[1] = x;
|
3373 | if(y) {
|
3374 | g[count++] = y;
|
3375 | }
|
3376 | }
|
3377 | if(q[1]) {
|
3378 | g[count++] = q[1];
|
3379 | }
|
3380 | if(count === 0) {
|
3381 | g[count++] = 0.0;
|
3382 | }
|
3383 | g.length = count;
|
3384 | return g
|
3385 | }
|
3386 |
|
3387 | var robustDiff = robustSubtract;
|
3388 |
|
3389 |
|
3390 | function scalarScalar$1(a, b) {
|
3391 | var x = a + b;
|
3392 | var bv = x - a;
|
3393 | var av = x - bv;
|
3394 | var br = b - bv;
|
3395 | var ar = a - av;
|
3396 | var y = ar + br;
|
3397 | if(y) {
|
3398 | return [y, x]
|
3399 | }
|
3400 | return [x]
|
3401 | }
|
3402 |
|
3403 | function robustSubtract(e, f) {
|
3404 | var ne = e.length|0;
|
3405 | var nf = f.length|0;
|
3406 | if(ne === 1 && nf === 1) {
|
3407 | return scalarScalar$1(e[0], -f[0])
|
3408 | }
|
3409 | var n = ne + nf;
|
3410 | var g = new Array(n);
|
3411 | var count = 0;
|
3412 | var eptr = 0;
|
3413 | var fptr = 0;
|
3414 | var abs = Math.abs;
|
3415 | var ei = e[eptr];
|
3416 | var ea = abs(ei);
|
3417 | var fi = -f[fptr];
|
3418 | var fa = abs(fi);
|
3419 | var a, b;
|
3420 | if(ea < fa) {
|
3421 | b = ei;
|
3422 | eptr += 1;
|
3423 | if(eptr < ne) {
|
3424 | ei = e[eptr];
|
3425 | ea = abs(ei);
|
3426 | }
|
3427 | } else {
|
3428 | b = fi;
|
3429 | fptr += 1;
|
3430 | if(fptr < nf) {
|
3431 | fi = -f[fptr];
|
3432 | fa = abs(fi);
|
3433 | }
|
3434 | }
|
3435 | if((eptr < ne && ea < fa) || (fptr >= nf)) {
|
3436 | a = ei;
|
3437 | eptr += 1;
|
3438 | if(eptr < ne) {
|
3439 | ei = e[eptr];
|
3440 | ea = abs(ei);
|
3441 | }
|
3442 | } else {
|
3443 | a = fi;
|
3444 | fptr += 1;
|
3445 | if(fptr < nf) {
|
3446 | fi = -f[fptr];
|
3447 | fa = abs(fi);
|
3448 | }
|
3449 | }
|
3450 | var x = a + b;
|
3451 | var bv = x - a;
|
3452 | var y = b - bv;
|
3453 | var q0 = y;
|
3454 | var q1 = x;
|
3455 | var _x, _bv, _av, _br, _ar;
|
3456 | while(eptr < ne && fptr < nf) {
|
3457 | if(ea < fa) {
|
3458 | a = ei;
|
3459 | eptr += 1;
|
3460 | if(eptr < ne) {
|
3461 | ei = e[eptr];
|
3462 | ea = abs(ei);
|
3463 | }
|
3464 | } else {
|
3465 | a = fi;
|
3466 | fptr += 1;
|
3467 | if(fptr < nf) {
|
3468 | fi = -f[fptr];
|
3469 | fa = abs(fi);
|
3470 | }
|
3471 | }
|
3472 | b = q0;
|
3473 | x = a + b;
|
3474 | bv = x - a;
|
3475 | y = b - bv;
|
3476 | if(y) {
|
3477 | g[count++] = y;
|
3478 | }
|
3479 | _x = q1 + x;
|
3480 | _bv = _x - q1;
|
3481 | _av = _x - _bv;
|
3482 | _br = x - _bv;
|
3483 | _ar = q1 - _av;
|
3484 | q0 = _ar + _br;
|
3485 | q1 = _x;
|
3486 | }
|
3487 | while(eptr < ne) {
|
3488 | a = ei;
|
3489 | b = q0;
|
3490 | x = a + b;
|
3491 | bv = x - a;
|
3492 | y = b - bv;
|
3493 | if(y) {
|
3494 | g[count++] = y;
|
3495 | }
|
3496 | _x = q1 + x;
|
3497 | _bv = _x - q1;
|
3498 | _av = _x - _bv;
|
3499 | _br = x - _bv;
|
3500 | _ar = q1 - _av;
|
3501 | q0 = _ar + _br;
|
3502 | q1 = _x;
|
3503 | eptr += 1;
|
3504 | if(eptr < ne) {
|
3505 | ei = e[eptr];
|
3506 | }
|
3507 | }
|
3508 | while(fptr < nf) {
|
3509 | a = fi;
|
3510 | b = q0;
|
3511 | x = a + b;
|
3512 | bv = x - a;
|
3513 | y = b - bv;
|
3514 | if(y) {
|
3515 | g[count++] = y;
|
3516 | }
|
3517 | _x = q1 + x;
|
3518 | _bv = _x - q1;
|
3519 | _av = _x - _bv;
|
3520 | _br = x - _bv;
|
3521 | _ar = q1 - _av;
|
3522 | q0 = _ar + _br;
|
3523 | q1 = _x;
|
3524 | fptr += 1;
|
3525 | if(fptr < nf) {
|
3526 | fi = -f[fptr];
|
3527 | }
|
3528 | }
|
3529 | if(q0) {
|
3530 | g[count++] = q0;
|
3531 | }
|
3532 | if(q1) {
|
3533 | g[count++] = q1;
|
3534 | }
|
3535 | if(!count) {
|
3536 | g[count++] = 0.0;
|
3537 | }
|
3538 | g.length = count;
|
3539 | return g
|
3540 | }
|
3541 |
|
3542 | var orientation_1 = createCommonjsModule(function (module) {
|
3543 | var NUM_EXPAND = 5;
|
3544 |
|
3545 | var EPSILON = 1.1102230246251565e-16;
|
3546 | var ERRBOUND3 = (3.0 + 16.0 * EPSILON) * EPSILON;
|
3547 | var ERRBOUND4 = (7.0 + 56.0 * EPSILON) * EPSILON;
|
3548 |
|
3549 | function cofactor(m, c) {
|
3550 | var result = new Array(m.length-1);
|
3551 | for(var i=1; i<m.length; ++i) {
|
3552 | var r = result[i-1] = new Array(m.length-1);
|
3553 | for(var j=0,k=0; j<m.length; ++j) {
|
3554 | if(j === c) {
|
3555 | continue
|
3556 | }
|
3557 | r[k++] = m[i][j];
|
3558 | }
|
3559 | }
|
3560 | return result
|
3561 | }
|
3562 |
|
3563 | function matrix(n) {
|
3564 | var result = new Array(n);
|
3565 | for(var i=0; i<n; ++i) {
|
3566 | result[i] = new Array(n);
|
3567 | for(var j=0; j<n; ++j) {
|
3568 | result[i][j] = ["m", j, "[", (n-i-1), "]"].join("");
|
3569 | }
|
3570 | }
|
3571 | return result
|
3572 | }
|
3573 |
|
3574 | function sign(n) {
|
3575 | if(n & 1) {
|
3576 | return "-"
|
3577 | }
|
3578 | return ""
|
3579 | }
|
3580 |
|
3581 | function generateSum(expr) {
|
3582 | if(expr.length === 1) {
|
3583 | return expr[0]
|
3584 | } else if(expr.length === 2) {
|
3585 | return ["sum(", expr[0], ",", expr[1], ")"].join("")
|
3586 | } else {
|
3587 | var m = expr.length>>1;
|
3588 | return ["sum(", generateSum(expr.slice(0, m)), ",", generateSum(expr.slice(m)), ")"].join("")
|
3589 | }
|
3590 | }
|
3591 |
|
3592 | function determinant(m) {
|
3593 | if(m.length === 2) {
|
3594 | return [["sum(prod(", m[0][0], ",", m[1][1], "),prod(-", m[0][1], ",", m[1][0], "))"].join("")]
|
3595 | } else {
|
3596 | var expr = [];
|
3597 | for(var i=0; i<m.length; ++i) {
|
3598 | expr.push(["scale(", generateSum(determinant(cofactor(m, i))), ",", sign(i), m[0][i], ")"].join(""));
|
3599 | }
|
3600 | return expr
|
3601 | }
|
3602 | }
|
3603 |
|
3604 | function orientation(n) {
|
3605 | var pos = [];
|
3606 | var neg = [];
|
3607 | var m = matrix(n);
|
3608 | var args = [];
|
3609 | for(var i=0; i<n; ++i) {
|
3610 | if((i&1)===0) {
|
3611 | pos.push.apply(pos, determinant(cofactor(m, i)));
|
3612 | } else {
|
3613 | neg.push.apply(neg, determinant(cofactor(m, i)));
|
3614 | }
|
3615 | args.push("m" + i);
|
3616 | }
|
3617 | var posExpr = generateSum(pos);
|
3618 | var negExpr = generateSum(neg);
|
3619 | var funcName = "orientation" + n + "Exact";
|
3620 | var code = ["function ", funcName, "(", args.join(), "){var p=", posExpr, ",n=", negExpr, ",d=sub(p,n);\
|
3621 | return d[d.length-1];};return ", funcName].join("");
|
3622 | var proc = new Function("sum", "prod", "scale", "sub", code);
|
3623 | return proc(robustSum, twoProduct_1, robustScale, robustDiff)
|
3624 | }
|
3625 |
|
3626 | var orientation3Exact = orientation(3);
|
3627 | var orientation4Exact = orientation(4);
|
3628 |
|
3629 | var CACHED = [
|
3630 | function orientation0() { return 0 },
|
3631 | function orientation1() { return 0 },
|
3632 | function orientation2(a, b) {
|
3633 | return b[0] - a[0]
|
3634 | },
|
3635 | function orientation3(a, b, c) {
|
3636 | var l = (a[1] - c[1]) * (b[0] - c[0]);
|
3637 | var r = (a[0] - c[0]) * (b[1] - c[1]);
|
3638 | var det = l - r;
|
3639 | var s;
|
3640 | if(l > 0) {
|
3641 | if(r <= 0) {
|
3642 | return det
|
3643 | } else {
|
3644 | s = l + r;
|
3645 | }
|
3646 | } else if(l < 0) {
|
3647 | if(r >= 0) {
|
3648 | return det
|
3649 | } else {
|
3650 | s = -(l + r);
|
3651 | }
|
3652 | } else {
|
3653 | return det
|
3654 | }
|
3655 | var tol = ERRBOUND3 * s;
|
3656 | if(det >= tol || det <= -tol) {
|
3657 | return det
|
3658 | }
|
3659 | return orientation3Exact(a, b, c)
|
3660 | },
|
3661 | function orientation4(a,b,c,d) {
|
3662 | var adx = a[0] - d[0];
|
3663 | var bdx = b[0] - d[0];
|
3664 | var cdx = c[0] - d[0];
|
3665 | var ady = a[1] - d[1];
|
3666 | var bdy = b[1] - d[1];
|
3667 | var cdy = c[1] - d[1];
|
3668 | var adz = a[2] - d[2];
|
3669 | var bdz = b[2] - d[2];
|
3670 | var cdz = c[2] - d[2];
|
3671 | var bdxcdy = bdx * cdy;
|
3672 | var cdxbdy = cdx * bdy;
|
3673 | var cdxady = cdx * ady;
|
3674 | var adxcdy = adx * cdy;
|
3675 | var adxbdy = adx * bdy;
|
3676 | var bdxady = bdx * ady;
|
3677 | var det = adz * (bdxcdy - cdxbdy)
|
3678 | + bdz * (cdxady - adxcdy)
|
3679 | + cdz * (adxbdy - bdxady);
|
3680 | var permanent = (Math.abs(bdxcdy) + Math.abs(cdxbdy)) * Math.abs(adz)
|
3681 | + (Math.abs(cdxady) + Math.abs(adxcdy)) * Math.abs(bdz)
|
3682 | + (Math.abs(adxbdy) + Math.abs(bdxady)) * Math.abs(cdz);
|
3683 | var tol = ERRBOUND4 * permanent;
|
3684 | if ((det > tol) || (-det > tol)) {
|
3685 | return det
|
3686 | }
|
3687 | return orientation4Exact(a,b,c,d)
|
3688 | }
|
3689 | ];
|
3690 |
|
3691 | function slowOrient(args) {
|
3692 | var proc = CACHED[args.length];
|
3693 | if(!proc) {
|
3694 | proc = CACHED[args.length] = orientation(args.length);
|
3695 | }
|
3696 | return proc.apply(undefined, args)
|
3697 | }
|
3698 |
|
3699 | function generateOrientationProc() {
|
3700 | while(CACHED.length <= NUM_EXPAND) {
|
3701 | CACHED.push(orientation(CACHED.length));
|
3702 | }
|
3703 | var args = [];
|
3704 | var procArgs = ["slow"];
|
3705 | for(var i=0; i<=NUM_EXPAND; ++i) {
|
3706 | args.push("a" + i);
|
3707 | procArgs.push("o" + i);
|
3708 | }
|
3709 | var code = [
|
3710 | "function getOrientation(", args.join(), "){switch(arguments.length){case 0:case 1:return 0;"
|
3711 | ];
|
3712 | for(var i=2; i<=NUM_EXPAND; ++i) {
|
3713 | code.push("case ", i, ":return o", i, "(", args.slice(0, i).join(), ");");
|
3714 | }
|
3715 | code.push("}var s=new Array(arguments.length);for(var i=0;i<arguments.length;++i){s[i]=arguments[i]};return slow(s);}return getOrientation");
|
3716 | procArgs.push(code.join(""));
|
3717 |
|
3718 | var proc = Function.apply(undefined, procArgs);
|
3719 | module.exports = proc.apply(undefined, [slowOrient].concat(CACHED));
|
3720 | for(var i=0; i<=NUM_EXPAND; ++i) {
|
3721 | module.exports[i] = CACHED[i];
|
3722 | }
|
3723 | }
|
3724 |
|
3725 | generateOrientationProc();
|
3726 | });
|
3727 |
|
3728 | var monotoneConvexHull2d = monotoneConvexHull2D;
|
3729 |
|
3730 | var orient$1 = orientation_1[3];
|
3731 |
|
3732 | function monotoneConvexHull2D(points) {
|
3733 | var n = points.length;
|
3734 |
|
3735 | if(n < 3) {
|
3736 | var result = new Array(n);
|
3737 | for(var i=0; i<n; ++i) {
|
3738 | result[i] = i;
|
3739 | }
|
3740 |
|
3741 | if(n === 2 &&
|
3742 | points[0][0] === points[1][0] &&
|
3743 | points[0][1] === points[1][1]) {
|
3744 | return [0]
|
3745 | }
|
3746 |
|
3747 | return result
|
3748 | }
|
3749 |
|
3750 |
|
3751 | var sorted = new Array(n);
|
3752 | for(var i=0; i<n; ++i) {
|
3753 | sorted[i] = i;
|
3754 | }
|
3755 | sorted.sort(function(a,b) {
|
3756 | var d = points[a][0]-points[b][0];
|
3757 | if(d) {
|
3758 | return d
|
3759 | }
|
3760 | return points[a][1] - points[b][1]
|
3761 | });
|
3762 |
|
3763 |
|
3764 | var lower = [sorted[0], sorted[1]];
|
3765 | var upper = [sorted[0], sorted[1]];
|
3766 |
|
3767 | for(var i=2; i<n; ++i) {
|
3768 | var idx = sorted[i];
|
3769 | var p = points[idx];
|
3770 |
|
3771 |
|
3772 | var m = lower.length;
|
3773 | while(m > 1 && orient$1(
|
3774 | points[lower[m-2]],
|
3775 | points[lower[m-1]],
|
3776 | p) <= 0) {
|
3777 | m -= 1;
|
3778 | lower.pop();
|
3779 | }
|
3780 | lower.push(idx);
|
3781 |
|
3782 |
|
3783 | m = upper.length;
|
3784 | while(m > 1 && orient$1(
|
3785 | points[upper[m-2]],
|
3786 | points[upper[m-1]],
|
3787 | p) >= 0) {
|
3788 | m -= 1;
|
3789 | upper.pop();
|
3790 | }
|
3791 | upper.push(idx);
|
3792 | }
|
3793 |
|
3794 |
|
3795 | var result = new Array(upper.length + lower.length - 2);
|
3796 | var ptr = 0;
|
3797 | for(var i=0, nl=lower.length; i<nl; ++i) {
|
3798 | result[ptr++] = lower[i];
|
3799 | }
|
3800 | for(var j=upper.length-2; j>0; --j) {
|
3801 | result[ptr++] = upper[j];
|
3802 | }
|
3803 |
|
3804 |
|
3805 | return result
|
3806 | }
|
3807 |
|
3808 | var tinyqueue = TinyQueue;
|
3809 | var default_1$1 = TinyQueue;
|
3810 |
|
3811 | function TinyQueue(data, compare) {
|
3812 | if (!(this instanceof TinyQueue)) return new TinyQueue(data, compare);
|
3813 |
|
3814 | this.data = data || [];
|
3815 | this.length = this.data.length;
|
3816 | this.compare = compare || defaultCompare$1;
|
3817 |
|
3818 | if (this.length > 0) {
|
3819 | for (var i = (this.length >> 1) - 1; i >= 0; i--) this._down(i);
|
3820 | }
|
3821 | }
|
3822 |
|
3823 | function defaultCompare$1(a, b) {
|
3824 | return a < b ? -1 : a > b ? 1 : 0;
|
3825 | }
|
3826 |
|
3827 | TinyQueue.prototype = {
|
3828 |
|
3829 | push: function (item) {
|
3830 | this.data.push(item);
|
3831 | this.length++;
|
3832 | this._up(this.length - 1);
|
3833 | },
|
3834 |
|
3835 | pop: function () {
|
3836 | if (this.length === 0) return undefined;
|
3837 |
|
3838 | var top = this.data[0];
|
3839 | this.length--;
|
3840 |
|
3841 | if (this.length > 0) {
|
3842 | this.data[0] = this.data[this.length];
|
3843 | this._down(0);
|
3844 | }
|
3845 | this.data.pop();
|
3846 |
|
3847 | return top;
|
3848 | },
|
3849 |
|
3850 | peek: function () {
|
3851 | return this.data[0];
|
3852 | },
|
3853 |
|
3854 | _up: function (pos) {
|
3855 | var data = this.data;
|
3856 | var compare = this.compare;
|
3857 | var item = data[pos];
|
3858 |
|
3859 | while (pos > 0) {
|
3860 | var parent = (pos - 1) >> 1;
|
3861 | var current = data[parent];
|
3862 | if (compare(item, current) >= 0) break;
|
3863 | data[pos] = current;
|
3864 | pos = parent;
|
3865 | }
|
3866 |
|
3867 | data[pos] = item;
|
3868 | },
|
3869 |
|
3870 | _down: function (pos) {
|
3871 | var data = this.data;
|
3872 | var compare = this.compare;
|
3873 | var halfLength = this.length >> 1;
|
3874 | var item = data[pos];
|
3875 |
|
3876 | while (pos < halfLength) {
|
3877 | var left = (pos << 1) + 1;
|
3878 | var right = left + 1;
|
3879 | var best = data[left];
|
3880 |
|
3881 | if (right < this.length && compare(data[right], best) < 0) {
|
3882 | left = right;
|
3883 | best = data[right];
|
3884 | }
|
3885 | if (compare(best, item) >= 0) break;
|
3886 |
|
3887 | data[pos] = best;
|
3888 | pos = left;
|
3889 | }
|
3890 |
|
3891 | data[pos] = item;
|
3892 | }
|
3893 | };
|
3894 |
|
3895 | tinyqueue.default = default_1$1;
|
3896 |
|
3897 | var pointInPolygon = function (point, vs) {
|
3898 |
|
3899 |
|
3900 |
|
3901 | var x = point[0], y = point[1];
|
3902 |
|
3903 | var inside = false;
|
3904 | for (var i = 0, j = vs.length - 1; i < vs.length; j = i++) {
|
3905 | var xi = vs[i][0], yi = vs[i][1];
|
3906 | var xj = vs[j][0], yj = vs[j][1];
|
3907 |
|
3908 | var intersect = ((yi > y) != (yj > y))
|
3909 | && (x < (xj - xi) * (y - yi) / (yj - yi) + xi);
|
3910 | if (intersect) inside = !inside;
|
3911 | }
|
3912 |
|
3913 | return inside;
|
3914 | };
|
3915 |
|
3916 | var orient = orientation_1[3];
|
3917 |
|
3918 | var concaveman_1 = concaveman;
|
3919 | var default_1 = concaveman;
|
3920 |
|
3921 | function concaveman(points, concavity, lengthThreshold) {
|
3922 |
|
3923 | concavity = Math.max(0, concavity === undefined ? 2 : concavity);
|
3924 |
|
3925 |
|
3926 | lengthThreshold = lengthThreshold || 0;
|
3927 |
|
3928 |
|
3929 | var hull = fastConvexHull(points);
|
3930 |
|
3931 |
|
3932 | var tree = rbush_1(16, ['[0]', '[1]', '[0]', '[1]']).load(points);
|
3933 |
|
3934 |
|
3935 | var queue = [];
|
3936 | for (var i = 0, last; i < hull.length; i++) {
|
3937 | var p = hull[i];
|
3938 | tree.remove(p);
|
3939 | last = insertNode(p, last);
|
3940 | queue.push(last);
|
3941 | }
|
3942 |
|
3943 |
|
3944 | var segTree = rbush_1(16);
|
3945 | for (i = 0; i < queue.length; i++) segTree.insert(updateBBox(queue[i]));
|
3946 |
|
3947 | var sqConcavity = concavity * concavity;
|
3948 | var sqLenThreshold = lengthThreshold * lengthThreshold;
|
3949 |
|
3950 |
|
3951 | while (queue.length) {
|
3952 | var node = queue.shift();
|
3953 | var a = node.p;
|
3954 | var b = node.next.p;
|
3955 |
|
3956 |
|
3957 | var sqLen = getSqDist(a, b);
|
3958 | if (sqLen < sqLenThreshold) continue;
|
3959 |
|
3960 | var maxSqLen = sqLen / sqConcavity;
|
3961 |
|
3962 |
|
3963 | p = findCandidate(tree, node.prev.p, a, b, node.next.next.p, maxSqLen, segTree);
|
3964 |
|
3965 |
|
3966 | if (p && Math.min(getSqDist(p, a), getSqDist(p, b)) <= maxSqLen) {
|
3967 |
|
3968 | queue.push(node);
|
3969 | queue.push(insertNode(p, node));
|
3970 |
|
3971 |
|
3972 | tree.remove(p);
|
3973 | segTree.remove(node);
|
3974 | segTree.insert(updateBBox(node));
|
3975 | segTree.insert(updateBBox(node.next));
|
3976 | }
|
3977 | }
|
3978 |
|
3979 |
|
3980 | node = last;
|
3981 | var concave = [];
|
3982 | do {
|
3983 | concave.push(node.p);
|
3984 | node = node.next;
|
3985 | } while (node !== last);
|
3986 |
|
3987 | concave.push(node.p);
|
3988 |
|
3989 | return concave;
|
3990 | }
|
3991 |
|
3992 | function findCandidate(tree, a, b, c, d, maxDist, segTree) {
|
3993 | var queue = new tinyqueue(null, compareDist);
|
3994 | var node = tree.data;
|
3995 |
|
3996 |
|
3997 |
|
3998 | while (node) {
|
3999 | for (var i = 0; i < node.children.length; i++) {
|
4000 | var child = node.children[i];
|
4001 |
|
4002 | var dist = node.leaf ? sqSegDist(child, b, c) : sqSegBoxDist(b, c, child);
|
4003 | if (dist > maxDist) continue;
|
4004 |
|
4005 | queue.push({
|
4006 | node: child,
|
4007 | dist: dist
|
4008 | });
|
4009 | }
|
4010 |
|
4011 | while (queue.length && !queue.peek().node.children) {
|
4012 | var item = queue.pop();
|
4013 | var p = item.node;
|
4014 |
|
4015 |
|
4016 |
|
4017 | var d0 = sqSegDist(p, a, b);
|
4018 | var d1 = sqSegDist(p, c, d);
|
4019 | if (item.dist < d0 && item.dist < d1 &&
|
4020 | noIntersections(b, p, segTree) &&
|
4021 | noIntersections(c, p, segTree)) return p;
|
4022 | }
|
4023 |
|
4024 | node = queue.pop();
|
4025 | if (node) node = node.node;
|
4026 | }
|
4027 |
|
4028 | return null;
|
4029 | }
|
4030 |
|
4031 | function compareDist(a, b) {
|
4032 | return a.dist - b.dist;
|
4033 | }
|
4034 |
|
4035 |
|
4036 | function sqSegBoxDist(a, b, bbox) {
|
4037 | if (inside(a, bbox) || inside(b, bbox)) return 0;
|
4038 | var d1 = sqSegSegDist(a[0], a[1], b[0], b[1], bbox.minX, bbox.minY, bbox.maxX, bbox.minY);
|
4039 | if (d1 === 0) return 0;
|
4040 | var d2 = sqSegSegDist(a[0], a[1], b[0], b[1], bbox.minX, bbox.minY, bbox.minX, bbox.maxY);
|
4041 | if (d2 === 0) return 0;
|
4042 | var d3 = sqSegSegDist(a[0], a[1], b[0], b[1], bbox.maxX, bbox.minY, bbox.maxX, bbox.maxY);
|
4043 | if (d3 === 0) return 0;
|
4044 | var d4 = sqSegSegDist(a[0], a[1], b[0], b[1], bbox.minX, bbox.maxY, bbox.maxX, bbox.maxY);
|
4045 | if (d4 === 0) return 0;
|
4046 | return Math.min(d1, d2, d3, d4);
|
4047 | }
|
4048 |
|
4049 | function inside(a, bbox) {
|
4050 | return a[0] >= bbox.minX &&
|
4051 | a[0] <= bbox.maxX &&
|
4052 | a[1] >= bbox.minY &&
|
4053 | a[1] <= bbox.maxY;
|
4054 | }
|
4055 |
|
4056 |
|
4057 | function noIntersections(a, b, segTree) {
|
4058 | var minX = Math.min(a[0], b[0]);
|
4059 | var minY = Math.min(a[1], b[1]);
|
4060 | var maxX = Math.max(a[0], b[0]);
|
4061 | var maxY = Math.max(a[1], b[1]);
|
4062 |
|
4063 | var edges = segTree.search({minX: minX, minY: minY, maxX: maxX, maxY: maxY});
|
4064 | for (var i = 0; i < edges.length; i++) {
|
4065 | if (intersects(edges[i].p, edges[i].next.p, a, b)) return false;
|
4066 | }
|
4067 | return true;
|
4068 | }
|
4069 |
|
4070 |
|
4071 | function intersects(p1, q1, p2, q2) {
|
4072 | return p1 !== q2 && q1 !== p2 &&
|
4073 | orient(p1, q1, p2) > 0 !== orient(p1, q1, q2) > 0 &&
|
4074 | orient(p2, q2, p1) > 0 !== orient(p2, q2, q1) > 0;
|
4075 | }
|
4076 |
|
4077 |
|
4078 | function updateBBox(node) {
|
4079 | var p1 = node.p;
|
4080 | var p2 = node.next.p;
|
4081 | node.minX = Math.min(p1[0], p2[0]);
|
4082 | node.minY = Math.min(p1[1], p2[1]);
|
4083 | node.maxX = Math.max(p1[0], p2[0]);
|
4084 | node.maxY = Math.max(p1[1], p2[1]);
|
4085 | return node;
|
4086 | }
|
4087 |
|
4088 |
|
4089 | function fastConvexHull(points) {
|
4090 | var left = points[0];
|
4091 | var top = points[0];
|
4092 | var right = points[0];
|
4093 | var bottom = points[0];
|
4094 |
|
4095 |
|
4096 | for (var i = 0; i < points.length; i++) {
|
4097 | var p = points[i];
|
4098 | if (p[0] < left[0]) left = p;
|
4099 | if (p[0] > right[0]) right = p;
|
4100 | if (p[1] < top[1]) top = p;
|
4101 | if (p[1] > bottom[1]) bottom = p;
|
4102 | }
|
4103 |
|
4104 |
|
4105 | var cull = [left, top, right, bottom];
|
4106 | var filtered = cull.slice();
|
4107 | for (i = 0; i < points.length; i++) {
|
4108 | if (!pointInPolygon(points[i], cull)) filtered.push(points[i]);
|
4109 | }
|
4110 |
|
4111 |
|
4112 | var indices = monotoneConvexHull2d(filtered);
|
4113 |
|
4114 |
|
4115 | var hull = [];
|
4116 | for (i = 0; i < indices.length; i++) hull.push(filtered[indices[i]]);
|
4117 | return hull;
|
4118 | }
|
4119 |
|
4120 |
|
4121 | function insertNode(p, prev) {
|
4122 | var node = {
|
4123 | p: p,
|
4124 | prev: null,
|
4125 | next: null,
|
4126 | minX: 0,
|
4127 | minY: 0,
|
4128 | maxX: 0,
|
4129 | maxY: 0
|
4130 | };
|
4131 |
|
4132 | if (!prev) {
|
4133 | node.prev = node;
|
4134 | node.next = node;
|
4135 |
|
4136 | } else {
|
4137 | node.next = prev.next;
|
4138 | node.prev = prev;
|
4139 | prev.next.prev = node;
|
4140 | prev.next = node;
|
4141 | }
|
4142 | return node;
|
4143 | }
|
4144 |
|
4145 |
|
4146 | function getSqDist(p1, p2) {
|
4147 |
|
4148 | var dx = p1[0] - p2[0],
|
4149 | dy = p1[1] - p2[1];
|
4150 |
|
4151 | return dx * dx + dy * dy;
|
4152 | }
|
4153 |
|
4154 |
|
4155 | function sqSegDist(p, p1, p2) {
|
4156 |
|
4157 | var x = p1[0],
|
4158 | y = p1[1],
|
4159 | dx = p2[0] - x,
|
4160 | dy = p2[1] - y;
|
4161 |
|
4162 | if (dx !== 0 || dy !== 0) {
|
4163 |
|
4164 | var t = ((p[0] - x) * dx + (p[1] - y) * dy) / (dx * dx + dy * dy);
|
4165 |
|
4166 | if (t > 1) {
|
4167 | x = p2[0];
|
4168 | y = p2[1];
|
4169 |
|
4170 | } else if (t > 0) {
|
4171 | x += dx * t;
|
4172 | y += dy * t;
|
4173 | }
|
4174 | }
|
4175 |
|
4176 | dx = p[0] - x;
|
4177 | dy = p[1] - y;
|
4178 |
|
4179 | return dx * dx + dy * dy;
|
4180 | }
|
4181 |
|
4182 |
|
4183 | function sqSegSegDist(x0, y0, x1, y1, x2, y2, x3, y3) {
|
4184 | var ux = x1 - x0;
|
4185 | var uy = y1 - y0;
|
4186 | var vx = x3 - x2;
|
4187 | var vy = y3 - y2;
|
4188 | var wx = x0 - x2;
|
4189 | var wy = y0 - y2;
|
4190 | var a = ux * ux + uy * uy;
|
4191 | var b = ux * vx + uy * vy;
|
4192 | var c = vx * vx + vy * vy;
|
4193 | var d = ux * wx + uy * wy;
|
4194 | var e = vx * wx + vy * wy;
|
4195 | var D = a * c - b * b;
|
4196 |
|
4197 | var sc, sN, tc, tN;
|
4198 | var sD = D;
|
4199 | var tD = D;
|
4200 |
|
4201 | if (D === 0) {
|
4202 | sN = 0;
|
4203 | sD = 1;
|
4204 | tN = e;
|
4205 | tD = c;
|
4206 | } else {
|
4207 | sN = b * e - c * d;
|
4208 | tN = a * e - b * d;
|
4209 | if (sN < 0) {
|
4210 | sN = 0;
|
4211 | tN = e;
|
4212 | tD = c;
|
4213 | } else if (sN > sD) {
|
4214 | sN = sD;
|
4215 | tN = e + b;
|
4216 | tD = c;
|
4217 | }
|
4218 | }
|
4219 |
|
4220 | if (tN < 0.0) {
|
4221 | tN = 0.0;
|
4222 | if (-d < 0.0) sN = 0.0;
|
4223 | else if (-d > a) sN = sD;
|
4224 | else {
|
4225 | sN = -d;
|
4226 | sD = a;
|
4227 | }
|
4228 | } else if (tN > tD) {
|
4229 | tN = tD;
|
4230 | if ((-d + b) < 0.0) sN = 0;
|
4231 | else if (-d + b > a) sN = sD;
|
4232 | else {
|
4233 | sN = -d + b;
|
4234 | sD = a;
|
4235 | }
|
4236 | }
|
4237 |
|
4238 | sc = sN === 0 ? 0 : sN / sD;
|
4239 | tc = tN === 0 ? 0 : tN / tD;
|
4240 |
|
4241 | var cx = (1 - sc) * x0 + sc * x1;
|
4242 | var cy = (1 - sc) * y0 + sc * y1;
|
4243 | var cx2 = (1 - tc) * x2 + tc * x3;
|
4244 | var cy2 = (1 - tc) * y2 + tc * y3;
|
4245 | var dx = cx2 - cx;
|
4246 | var dy = cy2 - cy;
|
4247 |
|
4248 | return dx * dx + dy * dy;
|
4249 | }
|
4250 |
|
4251 | concaveman_1.default = default_1;
|
4252 |
|
4253 |
|
4254 |
|
4255 |
|
4256 |
|
4257 |
|
4258 |
|
4259 |
|
4260 |
|
4261 |
|
4262 |
|
4263 |
|
4264 |
|
4265 |
|
4266 |
|
4267 |
|
4268 |
|
4269 |
|
4270 |
|
4271 |
|
4272 |
|
4273 |
|
4274 |
|
4275 |
|
4276 |
|
4277 |
|
4278 |
|
4279 |
|
4280 | function convex(geojson, options) {
|
4281 |
|
4282 | options = options || {};
|
4283 | if (!isObject(options)) throw new Error('options is invalid');
|
4284 | var concavity = options.concavity || Infinity;
|
4285 | var points$$1 = [];
|
4286 |
|
4287 |
|
4288 | coordEach(geojson, function (coord) {
|
4289 | points$$1.push([coord[0], coord[1]]);
|
4290 | });
|
4291 | if (!points$$1.length) return null;
|
4292 |
|
4293 | var convexHull = concaveman_1(points$$1, concavity);
|
4294 |
|
4295 |
|
4296 | if (convexHull.length > 3) {
|
4297 | return polygon([convexHull]);
|
4298 | }
|
4299 | return null;
|
4300 | }
|
4301 |
|
4302 |
|
4303 |
|
4304 |
|
4305 |
|
4306 |
|
4307 |
|
4308 |
|
4309 |
|
4310 |
|
4311 |
|
4312 |
|
4313 |
|
4314 |
|
4315 |
|
4316 |
|
4317 |
|
4318 |
|
4319 |
|
4320 |
|
4321 |
|
4322 |
|
4323 |
|
4324 |
|
4325 |
|
4326 |
|
4327 |
|
4328 |
|
4329 | function booleanPointInPolygon(point, polygon, options) {
|
4330 |
|
4331 | options = options || {};
|
4332 | if (typeof options !== 'object') throw new Error('options is invalid');
|
4333 | var ignoreBoundary = options.ignoreBoundary;
|
4334 |
|
4335 |
|
4336 | if (!point) throw new Error('point is required');
|
4337 | if (!polygon) throw new Error('polygon is required');
|
4338 |
|
4339 | var pt = getCoord(point);
|
4340 | var polys = getCoords(polygon);
|
4341 | var type = (polygon.geometry) ? polygon.geometry.type : polygon.type;
|
4342 | var bbox = polygon.bbox;
|
4343 |
|
4344 |
|
4345 | if (bbox && inBBox(pt, bbox) === false) return false;
|
4346 |
|
4347 |
|
4348 | if (type === 'Polygon') polys = [polys];
|
4349 |
|
4350 | for (var i = 0, insidePoly = false; i < polys.length && !insidePoly; i++) {
|
4351 |
|
4352 | if (inRing(pt, polys[i][0], ignoreBoundary)) {
|
4353 | var inHole = false;
|
4354 | var k = 1;
|
4355 |
|
4356 | while (k < polys[i].length && !inHole) {
|
4357 | if (inRing(pt, polys[i][k], !ignoreBoundary)) {
|
4358 | inHole = true;
|
4359 | }
|
4360 | k++;
|
4361 | }
|
4362 | if (!inHole) insidePoly = true;
|
4363 | }
|
4364 | }
|
4365 | return insidePoly;
|
4366 | }
|
4367 |
|
4368 |
|
4369 |
|
4370 |
|
4371 |
|
4372 |
|
4373 |
|
4374 |
|
4375 |
|
4376 |
|
4377 | function inRing(pt, ring, ignoreBoundary) {
|
4378 | var isInside = false;
|
4379 | if (ring[0][0] === ring[ring.length - 1][0] && ring[0][1] === ring[ring.length - 1][1]) ring = ring.slice(0, ring.length - 1);
|
4380 |
|
4381 | for (var i = 0, j = ring.length - 1; i < ring.length; j = i++) {
|
4382 | var xi = ring[i][0], yi = ring[i][1];
|
4383 | var xj = ring[j][0], yj = ring[j][1];
|
4384 | var onBoundary = (pt[1] * (xi - xj) + yi * (xj - pt[0]) + yj * (pt[0] - xi) === 0) &&
|
4385 | ((xi - pt[0]) * (xj - pt[0]) <= 0) && ((yi - pt[1]) * (yj - pt[1]) <= 0);
|
4386 | if (onBoundary) return !ignoreBoundary;
|
4387 | var intersect = ((yi > pt[1]) !== (yj > pt[1])) &&
|
4388 | (pt[0] < (xj - xi) * (pt[1] - yi) / (yj - yi) + xi);
|
4389 | if (intersect) isInside = !isInside;
|
4390 | }
|
4391 | return isInside;
|
4392 | }
|
4393 |
|
4394 |
|
4395 |
|
4396 |
|
4397 |
|
4398 |
|
4399 |
|
4400 |
|
4401 |
|
4402 | function inBBox(pt, bbox) {
|
4403 | return bbox[0] <= pt[0] &&
|
4404 | bbox[1] <= pt[1] &&
|
4405 | bbox[2] >= pt[0] &&
|
4406 | bbox[3] >= pt[1];
|
4407 | }
|
4408 |
|
4409 |
|
4410 |
|
4411 |
|
4412 |
|
4413 |
|
4414 |
|
4415 |
|
4416 |
|
4417 |
|
4418 |
|
4419 |
|
4420 |
|
4421 |
|
4422 |
|
4423 |
|
4424 |
|
4425 |
|
4426 |
|
4427 |
|
4428 |
|
4429 |
|
4430 |
|
4431 |
|
4432 |
|
4433 |
|
4434 |
|
4435 |
|
4436 |
|
4437 |
|
4438 |
|
4439 |
|
4440 |
|
4441 |
|
4442 |
|
4443 |
|
4444 | function pointsWithinPolygon(points$$1, polygons$$1) {
|
4445 | var results = [];
|
4446 | geomEach(polygons$$1, function (polygon$$1) {
|
4447 | featureEach(points$$1, function (point$$1) {
|
4448 | if (booleanPointInPolygon(point$$1, polygon$$1)) results.push(point$$1);
|
4449 | });
|
4450 | });
|
4451 | return featureCollection(results);
|
4452 | }
|
4453 |
|
4454 |
|
4455 |
|
4456 |
|
4457 |
|
4458 |
|
4459 |
|
4460 |
|
4461 |
|
4462 |
|
4463 |
|
4464 |
|
4465 |
|
4466 |
|
4467 |
|
4468 |
|
4469 |
|
4470 |
|
4471 |
|
4472 |
|
4473 |
|
4474 |
|
4475 |
|
4476 |
|
4477 |
|
4478 |
|
4479 |
|
4480 |
|
4481 |
|
4482 |
|
4483 |
|
4484 |
|
4485 |
|
4486 |
|
4487 |
|
4488 | function tin(points$$1, z) {
|
4489 | if (points$$1.type !== 'FeatureCollection') throw new Error('points must be a FeatureCollection');
|
4490 |
|
4491 | var isPointZ = false;
|
4492 | return featureCollection(triangulate(points$$1.features.map(function (p) {
|
4493 | var point$$1 = {
|
4494 | x: p.geometry.coordinates[0],
|
4495 | y: p.geometry.coordinates[1]
|
4496 | };
|
4497 | if (z) {
|
4498 | point$$1.z = p.properties[z];
|
4499 | } else if (p.geometry.coordinates.length === 3) {
|
4500 | isPointZ = true;
|
4501 | point$$1.z = p.geometry.coordinates[2];
|
4502 | }
|
4503 | return point$$1;
|
4504 | })).map(function (triangle) {
|
4505 |
|
4506 | var a = [triangle.a.x, triangle.a.y];
|
4507 | var b = [triangle.b.x, triangle.b.y];
|
4508 | var c = [triangle.c.x, triangle.c.y];
|
4509 | var properties = {};
|
4510 |
|
4511 |
|
4512 |
|
4513 | if (isPointZ) {
|
4514 | a.push(triangle.a.z);
|
4515 | b.push(triangle.b.z);
|
4516 | c.push(triangle.c.z);
|
4517 | } else {
|
4518 | properties = {
|
4519 | a: triangle.a.z,
|
4520 | b: triangle.b.z,
|
4521 | c: triangle.c.z
|
4522 | };
|
4523 | }
|
4524 |
|
4525 | return polygon([[a, b, c, a]], properties);
|
4526 |
|
4527 | }));
|
4528 | }
|
4529 |
|
4530 | function Triangle(a, b, c) {
|
4531 | this.a = a;
|
4532 | this.b = b;
|
4533 | this.c = c;
|
4534 |
|
4535 | var A = b.x - a.x,
|
4536 | B = b.y - a.y,
|
4537 | C = c.x - a.x,
|
4538 | D = c.y - a.y,
|
4539 | E = A * (a.x + b.x) + B * (a.y + b.y),
|
4540 | F = C * (a.x + c.x) + D * (a.y + c.y),
|
4541 | G = 2 * (A * (c.y - b.y) - B * (c.x - b.x)),
|
4542 | dx, dy;
|
4543 |
|
4544 |
|
4545 |
|
4546 | this.x = (D * E - B * F) / G;
|
4547 | this.y = (A * F - C * E) / G;
|
4548 | dx = this.x - a.x;
|
4549 | dy = this.y - a.y;
|
4550 | this.r = dx * dx + dy * dy;
|
4551 | }
|
4552 |
|
4553 | function byX(a, b) {
|
4554 | return b.x - a.x;
|
4555 | }
|
4556 |
|
4557 | function dedup(edges) {
|
4558 | var j = edges.length,
|
4559 | a, b, i, m, n;
|
4560 |
|
4561 | outer:
|
4562 | while (j) {
|
4563 | b = edges[--j];
|
4564 | a = edges[--j];
|
4565 | i = j;
|
4566 | while (i) {
|
4567 | n = edges[--i];
|
4568 | m = edges[--i];
|
4569 | if ((a === m && b === n) || (a === n && b === m)) {
|
4570 | edges.splice(j, 2);
|
4571 | edges.splice(i, 2);
|
4572 | j -= 2;
|
4573 | continue outer;
|
4574 | }
|
4575 | }
|
4576 | }
|
4577 | }
|
4578 |
|
4579 | function triangulate(vertices) {
|
4580 |
|
4581 | if (vertices.length < 3)
|
4582 | return [];
|
4583 |
|
4584 |
|
4585 |
|
4586 |
|
4587 | vertices.sort(byX);
|
4588 |
|
4589 | var i = vertices.length - 1,
|
4590 | xmin = vertices[i].x,
|
4591 | xmax = vertices[0].x,
|
4592 | ymin = vertices[i].y,
|
4593 | ymax = ymin,
|
4594 | epsilon = 1e-12;
|
4595 |
|
4596 | var a,
|
4597 | b,
|
4598 | c,
|
4599 | A,
|
4600 | B,
|
4601 | G;
|
4602 |
|
4603 | while (i--) {
|
4604 | if (vertices[i].y < ymin)
|
4605 | ymin = vertices[i].y;
|
4606 | if (vertices[i].y > ymax)
|
4607 | ymax = vertices[i].y;
|
4608 | }
|
4609 |
|
4610 |
|
4611 |
|
4612 |
|
4613 |
|
4614 |
|
4615 |
|
4616 |
|
4617 |
|
4618 | var dx = xmax - xmin,
|
4619 | dy = ymax - ymin,
|
4620 | dmax = (dx > dy) ? dx : dy,
|
4621 | xmid = (xmax + xmin) * 0.5,
|
4622 | ymid = (ymax + ymin) * 0.5,
|
4623 | open = [
|
4624 | new Triangle({
|
4625 | x: xmid - 20 * dmax,
|
4626 | y: ymid - dmax,
|
4627 | __sentinel: true
|
4628 | }, {
|
4629 | x: xmid,
|
4630 | y: ymid + 20 * dmax,
|
4631 | __sentinel: true
|
4632 | }, {
|
4633 | x: xmid + 20 * dmax,
|
4634 | y: ymid - dmax,
|
4635 | __sentinel: true
|
4636 | }
|
4637 | )],
|
4638 | closed = [],
|
4639 | edges = [],
|
4640 | j;
|
4641 |
|
4642 |
|
4643 | i = vertices.length;
|
4644 | while (i--) {
|
4645 |
|
4646 |
|
4647 |
|
4648 | edges.length = 0;
|
4649 | j = open.length;
|
4650 | while (j--) {
|
4651 |
|
4652 |
|
4653 |
|
4654 | dx = vertices[i].x - open[j].x;
|
4655 | if (dx > 0 && dx * dx > open[j].r) {
|
4656 | closed.push(open[j]);
|
4657 | open.splice(j, 1);
|
4658 | continue;
|
4659 | }
|
4660 |
|
4661 |
|
4662 | dy = vertices[i].y - open[j].y;
|
4663 | if (dx * dx + dy * dy > open[j].r)
|
4664 | continue;
|
4665 |
|
4666 |
|
4667 | edges.push(
|
4668 | open[j].a, open[j].b,
|
4669 | open[j].b, open[j].c,
|
4670 | open[j].c, open[j].a
|
4671 | );
|
4672 | open.splice(j, 1);
|
4673 | }
|
4674 |
|
4675 |
|
4676 | dedup(edges);
|
4677 |
|
4678 |
|
4679 | j = edges.length;
|
4680 | while (j) {
|
4681 | b = edges[--j];
|
4682 | a = edges[--j];
|
4683 | c = vertices[i];
|
4684 |
|
4685 |
|
4686 | A = b.x - a.x;
|
4687 | B = b.y - a.y;
|
4688 | G = 2 * (A * (c.y - b.y) - B * (c.x - b.x));
|
4689 | if (Math.abs(G) > epsilon) {
|
4690 | open.push(new Triangle(a, b, c));
|
4691 | }
|
4692 | }
|
4693 | }
|
4694 |
|
4695 |
|
4696 |
|
4697 | Array.prototype.push.apply(closed, open);
|
4698 |
|
4699 | i = closed.length;
|
4700 | while (i--)
|
4701 | if (closed[i].a.__sentinel ||
|
4702 | closed[i].b.__sentinel ||
|
4703 | closed[i].c.__sentinel)
|
4704 | closed.splice(i, 1);
|
4705 |
|
4706 | return closed;
|
4707 | }
|
4708 |
|
4709 |
|
4710 |
|
4711 |
|
4712 |
|
4713 |
|
4714 |
|
4715 |
|
4716 |
|
4717 |
|
4718 |
|
4719 |
|
4720 |
|
4721 |
|
4722 |
|
4723 |
|
4724 |
|
4725 |
|
4726 |
|
4727 |
|
4728 |
|
4729 |
|
4730 |
|
4731 |
|
4732 |
|
4733 |
|
4734 |
|
4735 |
|
4736 | function distance(from, to, options) {
|
4737 |
|
4738 | options = options || {};
|
4739 | if (!isObject(options)) throw new Error('options is invalid');
|
4740 | var units = options.units;
|
4741 |
|
4742 | var coordinates1 = getCoord(from);
|
4743 | var coordinates2 = getCoord(to);
|
4744 | var dLat = degreesToRadians((coordinates2[1] - coordinates1[1]));
|
4745 | var dLon = degreesToRadians((coordinates2[0] - coordinates1[0]));
|
4746 | var lat1 = degreesToRadians(coordinates1[1]);
|
4747 | var lat2 = degreesToRadians(coordinates2[1]);
|
4748 |
|
4749 | var a = Math.pow(Math.sin(dLat / 2), 2) +
|
4750 | Math.pow(Math.sin(dLon / 2), 2) * Math.cos(lat1) * Math.cos(lat2);
|
4751 |
|
4752 | return radiansToLength(2 * Math.atan2(Math.sqrt(a), Math.sqrt(1 - a)), units);
|
4753 | }
|
4754 |
|
4755 |
|
4756 |
|
4757 |
|
4758 |
|
4759 |
|
4760 |
|
4761 |
|
4762 |
|
4763 |
|
4764 |
|
4765 |
|
4766 |
|
4767 | function clone(geojson) {
|
4768 | if (!geojson) throw new Error('geojson is required');
|
4769 |
|
4770 | switch (geojson.type) {
|
4771 | case 'Feature':
|
4772 | return cloneFeature(geojson);
|
4773 | case 'FeatureCollection':
|
4774 | return cloneFeatureCollection(geojson);
|
4775 | case 'Point':
|
4776 | case 'LineString':
|
4777 | case 'Polygon':
|
4778 | case 'MultiPoint':
|
4779 | case 'MultiLineString':
|
4780 | case 'MultiPolygon':
|
4781 | case 'GeometryCollection':
|
4782 | return cloneGeometry(geojson);
|
4783 | default:
|
4784 | throw new Error('unknown GeoJSON type');
|
4785 | }
|
4786 | }
|
4787 |
|
4788 |
|
4789 |
|
4790 |
|
4791 |
|
4792 |
|
4793 |
|
4794 |
|
4795 | function cloneFeature(geojson) {
|
4796 | var cloned = {type: 'Feature'};
|
4797 |
|
4798 | Object.keys(geojson).forEach(function (key) {
|
4799 | switch (key) {
|
4800 | case 'type':
|
4801 | case 'properties':
|
4802 | case 'geometry':
|
4803 | return;
|
4804 | default:
|
4805 | cloned[key] = geojson[key];
|
4806 | }
|
4807 | });
|
4808 |
|
4809 | cloned.properties = cloneProperties(geojson.properties);
|
4810 | cloned.geometry = cloneGeometry(geojson.geometry);
|
4811 | return cloned;
|
4812 | }
|
4813 |
|
4814 |
|
4815 |
|
4816 |
|
4817 |
|
4818 |
|
4819 |
|
4820 |
|
4821 | function cloneProperties(properties) {
|
4822 | var cloned = {};
|
4823 | if (!properties) return cloned;
|
4824 | Object.keys(properties).forEach(function (key) {
|
4825 | var value = properties[key];
|
4826 | if (typeof value === 'object') {
|
4827 | if (value === null) {
|
4828 |
|
4829 | cloned[key] = null;
|
4830 | } else if (value.length) {
|
4831 |
|
4832 | cloned[key] = value.map(function (item) {
|
4833 | return item;
|
4834 | });
|
4835 | } else {
|
4836 |
|
4837 | cloned[key] = cloneProperties(value);
|
4838 | }
|
4839 | } else cloned[key] = value;
|
4840 | });
|
4841 | return cloned;
|
4842 | }
|
4843 |
|
4844 |
|
4845 |
|
4846 |
|
4847 |
|
4848 |
|
4849 |
|
4850 |
|
4851 | function cloneFeatureCollection(geojson) {
|
4852 | var cloned = {type: 'FeatureCollection'};
|
4853 |
|
4854 |
|
4855 | Object.keys(geojson).forEach(function (key) {
|
4856 | switch (key) {
|
4857 | case 'type':
|
4858 | case 'features':
|
4859 | return;
|
4860 | default:
|
4861 | cloned[key] = geojson[key];
|
4862 | }
|
4863 | });
|
4864 |
|
4865 | cloned.features = geojson.features.map(function (feature) {
|
4866 | return cloneFeature(feature);
|
4867 | });
|
4868 | return cloned;
|
4869 | }
|
4870 |
|
4871 |
|
4872 |
|
4873 |
|
4874 |
|
4875 |
|
4876 |
|
4877 |
|
4878 | function cloneGeometry(geometry) {
|
4879 | var geom = {type: geometry.type};
|
4880 | if (geometry.bbox) geom.bbox = geometry.bbox;
|
4881 |
|
4882 | if (geometry.type === 'GeometryCollection') {
|
4883 | geom.geometries = geometry.geometries.map(function (geom) {
|
4884 | return cloneGeometry(geom);
|
4885 | });
|
4886 | return geom;
|
4887 | }
|
4888 | geom.coordinates = deepSlice(geometry.coordinates);
|
4889 | return geom;
|
4890 | }
|
4891 |
|
4892 |
|
4893 |
|
4894 |
|
4895 |
|
4896 |
|
4897 |
|
4898 |
|
4899 | function deepSlice(coords) {
|
4900 | if (typeof coords[0] !== 'object') { return coords.slice(); }
|
4901 | return coords.map(function (coord) {
|
4902 | return deepSlice(coord);
|
4903 | });
|
4904 | }
|
4905 |
|
4906 | var identity = function(x) {
|
4907 | return x;
|
4908 | };
|
4909 |
|
4910 | var transform = function(transform) {
|
4911 | if (transform == null) return identity;
|
4912 | var x0,
|
4913 | y0,
|
4914 | kx = transform.scale[0],
|
4915 | ky = transform.scale[1],
|
4916 | dx = transform.translate[0],
|
4917 | dy = transform.translate[1];
|
4918 | return function(input, i) {
|
4919 | if (!i) x0 = y0 = 0;
|
4920 | var j = 2, n = input.length, output = new Array(n);
|
4921 | output[0] = (x0 += input[0]) * kx + dx;
|
4922 | output[1] = (y0 += input[1]) * ky + dy;
|
4923 | while (j < n) output[j] = input[j], ++j;
|
4924 | return output;
|
4925 | };
|
4926 | };
|
4927 |
|
4928 | var reverse = function(array, n) {
|
4929 | var t, j = array.length, i = j - n;
|
4930 | while (i < --j) t = array[i], array[i++] = array[j], array[j] = t;
|
4931 | };
|
4932 |
|
4933 | function object(topology, o) {
|
4934 | var transformPoint = transform(topology.transform),
|
4935 | arcs = topology.arcs;
|
4936 |
|
4937 | function arc(i, points) {
|
4938 | if (points.length) points.pop();
|
4939 | for (var a = arcs[i < 0 ? ~i : i], k = 0, n = a.length; k < n; ++k) {
|
4940 | points.push(transformPoint(a[k], k));
|
4941 | }
|
4942 | if (i < 0) reverse(points, n);
|
4943 | }
|
4944 |
|
4945 | function point(p) {
|
4946 | return transformPoint(p);
|
4947 | }
|
4948 |
|
4949 | function line(arcs) {
|
4950 | var points = [];
|
4951 | for (var i = 0, n = arcs.length; i < n; ++i) arc(arcs[i], points);
|
4952 | if (points.length < 2) points.push(points[0]);
|
4953 | return points;
|
4954 | }
|
4955 |
|
4956 | function ring(arcs) {
|
4957 | var points = line(arcs);
|
4958 | while (points.length < 4) points.push(points[0]);
|
4959 | return points;
|
4960 | }
|
4961 |
|
4962 | function polygon(arcs) {
|
4963 | return arcs.map(ring);
|
4964 | }
|
4965 |
|
4966 | function geometry(o) {
|
4967 | var type = o.type, coordinates;
|
4968 | switch (type) {
|
4969 | case "GeometryCollection": return {type: type, geometries: o.geometries.map(geometry)};
|
4970 | case "Point": coordinates = point(o.coordinates); break;
|
4971 | case "MultiPoint": coordinates = o.coordinates.map(point); break;
|
4972 | case "LineString": coordinates = line(o.arcs); break;
|
4973 | case "MultiLineString": coordinates = o.arcs.map(line); break;
|
4974 | case "Polygon": coordinates = polygon(o.arcs); break;
|
4975 | case "MultiPolygon": coordinates = o.arcs.map(polygon); break;
|
4976 | default: return null;
|
4977 | }
|
4978 | return {type: type, coordinates: coordinates};
|
4979 | }
|
4980 |
|
4981 | return geometry(o);
|
4982 | }
|
4983 |
|
4984 | var stitch = function(topology, arcs) {
|
4985 | var stitchedArcs = {},
|
4986 | fragmentByStart = {},
|
4987 | fragmentByEnd = {},
|
4988 | fragments = [],
|
4989 | emptyIndex = -1;
|
4990 |
|
4991 |
|
4992 | arcs.forEach(function(i, j) {
|
4993 | var arc = topology.arcs[i < 0 ? ~i : i], t;
|
4994 | if (arc.length < 3 && !arc[1][0] && !arc[1][1]) {
|
4995 | t = arcs[++emptyIndex], arcs[emptyIndex] = i, arcs[j] = t;
|
4996 | }
|
4997 | });
|
4998 |
|
4999 | arcs.forEach(function(i) {
|
5000 | var e = ends(i),
|
5001 | start = e[0],
|
5002 | end = e[1],
|
5003 | f, g;
|
5004 |
|
5005 | if (f = fragmentByEnd[start]) {
|
5006 | delete fragmentByEnd[f.end];
|
5007 | f.push(i);
|
5008 | f.end = end;
|
5009 | if (g = fragmentByStart[end]) {
|
5010 | delete fragmentByStart[g.start];
|
5011 | var fg = g === f ? f : f.concat(g);
|
5012 | fragmentByStart[fg.start = f.start] = fragmentByEnd[fg.end = g.end] = fg;
|
5013 | } else {
|
5014 | fragmentByStart[f.start] = fragmentByEnd[f.end] = f;
|
5015 | }
|
5016 | } else if (f = fragmentByStart[end]) {
|
5017 | delete fragmentByStart[f.start];
|
5018 | f.unshift(i);
|
5019 | f.start = start;
|
5020 | if (g = fragmentByEnd[start]) {
|
5021 | delete fragmentByEnd[g.end];
|
5022 | var gf = g === f ? f : g.concat(f);
|
5023 | fragmentByStart[gf.start = g.start] = fragmentByEnd[gf.end = f.end] = gf;
|
5024 | } else {
|
5025 | fragmentByStart[f.start] = fragmentByEnd[f.end] = f;
|
5026 | }
|
5027 | } else {
|
5028 | f = [i];
|
5029 | fragmentByStart[f.start = start] = fragmentByEnd[f.end = end] = f;
|
5030 | }
|
5031 | });
|
5032 |
|
5033 | function ends(i) {
|
5034 | var arc = topology.arcs[i < 0 ? ~i : i], p0 = arc[0], p1;
|
5035 | if (topology.transform) p1 = [0, 0], arc.forEach(function(dp) { p1[0] += dp[0], p1[1] += dp[1]; });
|
5036 | else p1 = arc[arc.length - 1];
|
5037 | return i < 0 ? [p1, p0] : [p0, p1];
|
5038 | }
|
5039 |
|
5040 | function flush(fragmentByEnd, fragmentByStart) {
|
5041 | for (var k in fragmentByEnd) {
|
5042 | var f = fragmentByEnd[k];
|
5043 | delete fragmentByStart[f.start];
|
5044 | delete f.start;
|
5045 | delete f.end;
|
5046 | f.forEach(function(i) { stitchedArcs[i < 0 ? ~i : i] = 1; });
|
5047 | fragments.push(f);
|
5048 | }
|
5049 | }
|
5050 |
|
5051 | flush(fragmentByEnd, fragmentByStart);
|
5052 | flush(fragmentByStart, fragmentByEnd);
|
5053 | arcs.forEach(function(i) { if (!stitchedArcs[i < 0 ? ~i : i]) fragments.push([i]); });
|
5054 |
|
5055 | return fragments;
|
5056 | };
|
5057 |
|
5058 | function planarRingArea(ring) {
|
5059 | var i = -1, n = ring.length, a, b = ring[n - 1], area = 0;
|
5060 | while (++i < n) a = b, b = ring[i], area += a[0] * b[1] - a[1] * b[0];
|
5061 | return Math.abs(area);
|
5062 | }
|
5063 |
|
5064 | var merge = function(topology) {
|
5065 | return object(topology, mergeArcs.apply(this, arguments));
|
5066 | };
|
5067 |
|
5068 | function mergeArcs(topology, objects) {
|
5069 | var polygonsByArc = {},
|
5070 | polygons = [],
|
5071 | groups = [];
|
5072 |
|
5073 | objects.forEach(geometry);
|
5074 |
|
5075 | function geometry(o) {
|
5076 | switch (o.type) {
|
5077 | case "GeometryCollection": o.geometries.forEach(geometry); break;
|
5078 | case "Polygon": extract(o.arcs); break;
|
5079 | case "MultiPolygon": o.arcs.forEach(extract); break;
|
5080 | }
|
5081 | }
|
5082 |
|
5083 | function extract(polygon) {
|
5084 | polygon.forEach(function(ring) {
|
5085 | ring.forEach(function(arc) {
|
5086 | (polygonsByArc[arc = arc < 0 ? ~arc : arc] || (polygonsByArc[arc] = [])).push(polygon);
|
5087 | });
|
5088 | });
|
5089 | polygons.push(polygon);
|
5090 | }
|
5091 |
|
5092 | function area(ring) {
|
5093 | return planarRingArea(object(topology, {type: "Polygon", arcs: [ring]}).coordinates[0]);
|
5094 | }
|
5095 |
|
5096 | polygons.forEach(function(polygon) {
|
5097 | if (!polygon._) {
|
5098 | var group = [],
|
5099 | neighbors = [polygon];
|
5100 | polygon._ = 1;
|
5101 | groups.push(group);
|
5102 | while (polygon = neighbors.pop()) {
|
5103 | group.push(polygon);
|
5104 | polygon.forEach(function(ring) {
|
5105 | ring.forEach(function(arc) {
|
5106 | polygonsByArc[arc < 0 ? ~arc : arc].forEach(function(polygon) {
|
5107 | if (!polygon._) {
|
5108 | polygon._ = 1;
|
5109 | neighbors.push(polygon);
|
5110 | }
|
5111 | });
|
5112 | });
|
5113 | });
|
5114 | }
|
5115 | }
|
5116 | });
|
5117 |
|
5118 | polygons.forEach(function(polygon) {
|
5119 | delete polygon._;
|
5120 | });
|
5121 |
|
5122 | return {
|
5123 | type: "MultiPolygon",
|
5124 | arcs: groups.map(function(polygons) {
|
5125 | var arcs = [], n;
|
5126 |
|
5127 |
|
5128 | polygons.forEach(function(polygon) {
|
5129 | polygon.forEach(function(ring) {
|
5130 | ring.forEach(function(arc) {
|
5131 | if (polygonsByArc[arc < 0 ? ~arc : arc].length < 2) {
|
5132 | arcs.push(arc);
|
5133 | }
|
5134 | });
|
5135 | });
|
5136 | });
|
5137 |
|
5138 |
|
5139 | arcs = stitch(topology, arcs);
|
5140 |
|
5141 |
|
5142 |
|
5143 |
|
5144 | if ((n = arcs.length) > 1) {
|
5145 | for (var i = 1, k = area(arcs[0]), ki, t; i < n; ++i) {
|
5146 | if ((ki = area(arcs[i])) > k) {
|
5147 | t = arcs[0], arcs[0] = arcs[i], arcs[i] = t, k = ki;
|
5148 | }
|
5149 | }
|
5150 | }
|
5151 |
|
5152 | return arcs;
|
5153 | })
|
5154 | };
|
5155 | }
|
5156 |
|
5157 |
|
5158 | var bounds = function(objects) {
|
5159 | var x0 = Infinity,
|
5160 | y0 = Infinity,
|
5161 | x1 = -Infinity,
|
5162 | y1 = -Infinity;
|
5163 |
|
5164 | function boundGeometry(geometry) {
|
5165 | if (geometry != null && boundGeometryType.hasOwnProperty(geometry.type)) boundGeometryType[geometry.type](geometry);
|
5166 | }
|
5167 |
|
5168 | var boundGeometryType = {
|
5169 | GeometryCollection: function(o) { o.geometries.forEach(boundGeometry); },
|
5170 | Point: function(o) { boundPoint(o.coordinates); },
|
5171 | MultiPoint: function(o) { o.coordinates.forEach(boundPoint); },
|
5172 | LineString: function(o) { boundLine(o.arcs); },
|
5173 | MultiLineString: function(o) { o.arcs.forEach(boundLine); },
|
5174 | Polygon: function(o) { o.arcs.forEach(boundLine); },
|
5175 | MultiPolygon: function(o) { o.arcs.forEach(boundMultiLine); }
|
5176 | };
|
5177 |
|
5178 | function boundPoint(coordinates) {
|
5179 | var x = coordinates[0],
|
5180 | y = coordinates[1];
|
5181 | if (x < x0) x0 = x;
|
5182 | if (x > x1) x1 = x;
|
5183 | if (y < y0) y0 = y;
|
5184 | if (y > y1) y1 = y;
|
5185 | }
|
5186 |
|
5187 | function boundLine(coordinates) {
|
5188 | coordinates.forEach(boundPoint);
|
5189 | }
|
5190 |
|
5191 | function boundMultiLine(coordinates) {
|
5192 | coordinates.forEach(boundLine);
|
5193 | }
|
5194 |
|
5195 | for (var key in objects) {
|
5196 | boundGeometry(objects[key]);
|
5197 | }
|
5198 |
|
5199 | return x1 >= x0 && y1 >= y0 ? [x0, y0, x1, y1] : undefined;
|
5200 | };
|
5201 |
|
5202 | var hashset = function(size, hash, equal, type, empty) {
|
5203 | if (arguments.length === 3) {
|
5204 | type = Array;
|
5205 | empty = null;
|
5206 | }
|
5207 |
|
5208 | var store = new type(size = 1 << Math.max(4, Math.ceil(Math.log(size) / Math.LN2))),
|
5209 | mask = size - 1;
|
5210 |
|
5211 | for (var i = 0; i < size; ++i) {
|
5212 | store[i] = empty;
|
5213 | }
|
5214 |
|
5215 | function add(value) {
|
5216 | var index = hash(value) & mask,
|
5217 | match = store[index],
|
5218 | collisions = 0;
|
5219 | while (match != empty) {
|
5220 | if (equal(match, value)) return true;
|
5221 | if (++collisions >= size) throw new Error("full hashset");
|
5222 | match = store[index = (index + 1) & mask];
|
5223 | }
|
5224 | store[index] = value;
|
5225 | return true;
|
5226 | }
|
5227 |
|
5228 | function has(value) {
|
5229 | var index = hash(value) & mask,
|
5230 | match = store[index],
|
5231 | collisions = 0;
|
5232 | while (match != empty) {
|
5233 | if (equal(match, value)) return true;
|
5234 | if (++collisions >= size) break;
|
5235 | match = store[index = (index + 1) & mask];
|
5236 | }
|
5237 | return false;
|
5238 | }
|
5239 |
|
5240 | function values() {
|
5241 | var values = [];
|
5242 | for (var i = 0, n = store.length; i < n; ++i) {
|
5243 | var match = store[i];
|
5244 | if (match != empty) values.push(match);
|
5245 | }
|
5246 | return values;
|
5247 | }
|
5248 |
|
5249 | return {
|
5250 | add: add,
|
5251 | has: has,
|
5252 | values: values
|
5253 | };
|
5254 | };
|
5255 |
|
5256 | var hashmap = function(size, hash, equal, keyType, keyEmpty, valueType) {
|
5257 | if (arguments.length === 3) {
|
5258 | keyType = valueType = Array;
|
5259 | keyEmpty = null;
|
5260 | }
|
5261 |
|
5262 | var keystore = new keyType(size = 1 << Math.max(4, Math.ceil(Math.log(size) / Math.LN2))),
|
5263 | valstore = new valueType(size),
|
5264 | mask = size - 1;
|
5265 |
|
5266 | for (var i = 0; i < size; ++i) {
|
5267 | keystore[i] = keyEmpty;
|
5268 | }
|
5269 |
|
5270 | function set(key, value) {
|
5271 | var index = hash(key) & mask,
|
5272 | matchKey = keystore[index],
|
5273 | collisions = 0;
|
5274 | while (matchKey != keyEmpty) {
|
5275 | if (equal(matchKey, key)) return valstore[index] = value;
|
5276 | if (++collisions >= size) throw new Error("full hashmap");
|
5277 | matchKey = keystore[index = (index + 1) & mask];
|
5278 | }
|
5279 | keystore[index] = key;
|
5280 | valstore[index] = value;
|
5281 | return value;
|
5282 | }
|
5283 |
|
5284 | function maybeSet(key, value) {
|
5285 | var index = hash(key) & mask,
|
5286 | matchKey = keystore[index],
|
5287 | collisions = 0;
|
5288 | while (matchKey != keyEmpty) {
|
5289 | if (equal(matchKey, key)) return valstore[index];
|
5290 | if (++collisions >= size) throw new Error("full hashmap");
|
5291 | matchKey = keystore[index = (index + 1) & mask];
|
5292 | }
|
5293 | keystore[index] = key;
|
5294 | valstore[index] = value;
|
5295 | return value;
|
5296 | }
|
5297 |
|
5298 | function get(key, missingValue) {
|
5299 | var index = hash(key) & mask,
|
5300 | matchKey = keystore[index],
|
5301 | collisions = 0;
|
5302 | while (matchKey != keyEmpty) {
|
5303 | if (equal(matchKey, key)) return valstore[index];
|
5304 | if (++collisions >= size) break;
|
5305 | matchKey = keystore[index = (index + 1) & mask];
|
5306 | }
|
5307 | return missingValue;
|
5308 | }
|
5309 |
|
5310 | function keys() {
|
5311 | var keys = [];
|
5312 | for (var i = 0, n = keystore.length; i < n; ++i) {
|
5313 | var matchKey = keystore[i];
|
5314 | if (matchKey != keyEmpty) keys.push(matchKey);
|
5315 | }
|
5316 | return keys;
|
5317 | }
|
5318 |
|
5319 | return {
|
5320 | set: set,
|
5321 | maybeSet: maybeSet, // set if unset
|
5322 | get: get,
|
5323 | keys: keys
|
5324 | };
|
5325 | };
|
5326 |
|
5327 | var equalPoint = function(pointA, pointB) {
|
5328 | return pointA[0] === pointB[0] && pointA[1] === pointB[1];
|
5329 | };
|
5330 |
|
5331 |
|
5332 |
|
5333 | var buffer = new ArrayBuffer(16);
|
5334 | var floats = new Float64Array(buffer);
|
5335 | var uints = new Uint32Array(buffer);
|
5336 |
|
5337 | var hashPoint = function(point) {
|
5338 | floats[0] = point[0];
|
5339 | floats[1] = point[1];
|
5340 | var hash = uints[0] ^ uints[1];
|
5341 | hash = hash << 5 ^ hash >> 7 ^ uints[2] ^ uints[3];
|
5342 | return hash & 0x7fffffff;
|
5343 | };
|
5344 |
|
5345 |
|
5346 |
|
5347 |
|
5348 |
|
5349 |
|
5350 |
|
5351 |
|
5352 |
|
5353 |
|
5354 |
|
5355 |
|
5356 |
|
5357 |
|
5358 |
|
5359 | var join = function(topology) {
|
5360 | var coordinates = topology.coordinates,
|
5361 | lines = topology.lines,
|
5362 | rings = topology.rings,
|
5363 | indexes = index(),
|
5364 | visitedByIndex = new Int32Array(coordinates.length),
|
5365 | leftByIndex = new Int32Array(coordinates.length),
|
5366 | rightByIndex = new Int32Array(coordinates.length),
|
5367 | junctionByIndex = new Int8Array(coordinates.length),
|
5368 | junctionCount = 0,
|
5369 | i, n,
|
5370 | previousIndex,
|
5371 | currentIndex,
|
5372 | nextIndex;
|
5373 |
|
5374 | for (i = 0, n = coordinates.length; i < n; ++i) {
|
5375 | visitedByIndex[i] = leftByIndex[i] = rightByIndex[i] = -1;
|
5376 | }
|
5377 |
|
5378 | for (i = 0, n = lines.length; i < n; ++i) {
|
5379 | var line = lines[i],
|
5380 | lineStart = line[0],
|
5381 | lineEnd = line[1];
|
5382 | currentIndex = indexes[lineStart];
|
5383 | nextIndex = indexes[++lineStart];
|
5384 | ++junctionCount, junctionByIndex[currentIndex] = 1;
|
5385 | while (++lineStart <= lineEnd) {
|
5386 | sequence(i, previousIndex = currentIndex, currentIndex = nextIndex, nextIndex = indexes[lineStart]);
|
5387 | }
|
5388 | ++junctionCount, junctionByIndex[nextIndex] = 1;
|
5389 | }
|
5390 |
|
5391 | for (i = 0, n = coordinates.length; i < n; ++i) {
|
5392 | visitedByIndex[i] = -1;
|
5393 | }
|
5394 |
|
5395 | for (i = 0, n = rings.length; i < n; ++i) {
|
5396 | var ring = rings[i],
|
5397 | ringStart = ring[0] + 1,
|
5398 | ringEnd = ring[1];
|
5399 | previousIndex = indexes[ringEnd - 1];
|
5400 | currentIndex = indexes[ringStart - 1];
|
5401 | nextIndex = indexes[ringStart];
|
5402 | sequence(i, previousIndex, currentIndex, nextIndex);
|
5403 | while (++ringStart <= ringEnd) {
|
5404 | sequence(i, previousIndex = currentIndex, currentIndex = nextIndex, nextIndex = indexes[ringStart]);
|
5405 | }
|
5406 | }
|
5407 |
|
5408 | function sequence(i, previousIndex, currentIndex, nextIndex) {
|
5409 | if (visitedByIndex[currentIndex] === i) return;
|
5410 | visitedByIndex[currentIndex] = i;
|
5411 | var leftIndex = leftByIndex[currentIndex];
|
5412 | if (leftIndex >= 0) {
|
5413 | var rightIndex = rightByIndex[currentIndex];
|
5414 | if ((leftIndex !== previousIndex || rightIndex !== nextIndex)
|
5415 | && (leftIndex !== nextIndex || rightIndex !== previousIndex)) {
|
5416 | ++junctionCount, junctionByIndex[currentIndex] = 1;
|
5417 | }
|
5418 | } else {
|
5419 | leftByIndex[currentIndex] = previousIndex;
|
5420 | rightByIndex[currentIndex] = nextIndex;
|
5421 | }
|
5422 | }
|
5423 |
|
5424 | function index() {
|
5425 | var indexByPoint = hashmap(coordinates.length * 1.4, hashIndex, equalIndex, Int32Array, -1, Int32Array),
|
5426 | indexes = new Int32Array(coordinates.length);
|
5427 |
|
5428 | for (var i = 0, n = coordinates.length; i < n; ++i) {
|
5429 | indexes[i] = indexByPoint.maybeSet(i, i);
|
5430 | }
|
5431 |
|
5432 | return indexes;
|
5433 | }
|
5434 |
|
5435 | function hashIndex(i) {
|
5436 | return hashPoint(coordinates[i]);
|
5437 | }
|
5438 |
|
5439 | function equalIndex(i, j) {
|
5440 | return equalPoint(coordinates[i], coordinates[j]);
|
5441 | }
|
5442 |
|
5443 | visitedByIndex = leftByIndex = rightByIndex = null;
|
5444 |
|
5445 | var junctionByPoint = hashset(junctionCount * 1.4, hashPoint, equalPoint), j;
|
5446 |
|
5447 |
|
5448 | for (i = 0, n = coordinates.length; i < n; ++i) {
|
5449 | if (junctionByIndex[j = indexes[i]]) {
|
5450 | junctionByPoint.add(coordinates[j]);
|
5451 | }
|
5452 | }
|
5453 |
|
5454 | return junctionByPoint;
|
5455 | };
|
5456 |
|
5457 |
|
5458 |
|
5459 |
|
5460 | var cut = function(topology) {
|
5461 | var junctions = join(topology),
|
5462 | coordinates = topology.coordinates,
|
5463 | lines = topology.lines,
|
5464 | rings = topology.rings,
|
5465 | next,
|
5466 | i, n;
|
5467 |
|
5468 | for (i = 0, n = lines.length; i < n; ++i) {
|
5469 | var line = lines[i],
|
5470 | lineMid = line[0],
|
5471 | lineEnd = line[1];
|
5472 | while (++lineMid < lineEnd) {
|
5473 | if (junctions.has(coordinates[lineMid])) {
|
5474 | next = {0: lineMid, 1: line[1]};
|
5475 | line[1] = lineMid;
|
5476 | line = line.next = next;
|
5477 | }
|
5478 | }
|
5479 | }
|
5480 |
|
5481 | for (i = 0, n = rings.length; i < n; ++i) {
|
5482 | var ring = rings[i],
|
5483 | ringStart = ring[0],
|
5484 | ringMid = ringStart,
|
5485 | ringEnd = ring[1],
|
5486 | ringFixed = junctions.has(coordinates[ringStart]);
|
5487 | while (++ringMid < ringEnd) {
|
5488 | if (junctions.has(coordinates[ringMid])) {
|
5489 | if (ringFixed) {
|
5490 | next = {0: ringMid, 1: ring[1]};
|
5491 | ring[1] = ringMid;
|
5492 | ring = ring.next = next;
|
5493 | } else {
|
5494 | rotateArray(coordinates, ringStart, ringEnd, ringEnd - ringMid);
|
5495 | coordinates[ringEnd] = coordinates[ringStart];
|
5496 | ringFixed = true;
|
5497 | ringMid = ringStart;
|
5498 | }
|
5499 | }
|
5500 | }
|
5501 | }
|
5502 |
|
5503 | return topology;
|
5504 | };
|
5505 |
|
5506 | function rotateArray(array, start, end, offset) {
|
5507 | reverse$1(array, start, end);
|
5508 | reverse$1(array, start, start + offset);
|
5509 | reverse$1(array, start + offset, end);
|
5510 | }
|
5511 |
|
5512 | function reverse$1(array, start, end) {
|
5513 | for (var mid = start + ((end-- - start) >> 1), t; start < mid; ++start, --end) {
|
5514 | t = array[start], array[start] = array[end], array[end] = t;
|
5515 | }
|
5516 | }
|
5517 |
|
5518 |
|
5519 | var dedup$1 = function(topology) {
|
5520 | var coordinates = topology.coordinates,
|
5521 | lines = topology.lines, line,
|
5522 | rings = topology.rings, ring,
|
5523 | arcCount = lines.length + rings.length,
|
5524 | i, n;
|
5525 |
|
5526 | delete topology.lines;
|
5527 | delete topology.rings;
|
5528 |
|
5529 |
|
5530 | for (i = 0, n = lines.length; i < n; ++i) {
|
5531 | line = lines[i]; while (line = line.next) ++arcCount;
|
5532 | }
|
5533 | for (i = 0, n = rings.length; i < n; ++i) {
|
5534 | ring = rings[i]; while (ring = ring.next) ++arcCount;
|
5535 | }
|
5536 |
|
5537 | var arcsByEnd = hashmap(arcCount * 2 * 1.4, hashPoint, equalPoint),
|
5538 | arcs = topology.arcs = [];
|
5539 |
|
5540 | for (i = 0, n = lines.length; i < n; ++i) {
|
5541 | line = lines[i];
|
5542 | do {
|
5543 | dedupLine(line);
|
5544 | } while (line = line.next);
|
5545 | }
|
5546 |
|
5547 | for (i = 0, n = rings.length; i < n; ++i) {
|
5548 | ring = rings[i];
|
5549 | if (ring.next) {
|
5550 | do {
|
5551 | dedupLine(ring);
|
5552 | } while (ring = ring.next);
|
5553 | } else {
|
5554 | dedupRing(ring);
|
5555 | }
|
5556 | }
|
5557 |
|
5558 | function dedupLine(arc) {
|
5559 | var startPoint,
|
5560 | endPoint,
|
5561 | startArcs, startArc,
|
5562 | endArcs, endArc,
|
5563 | i, n;
|
5564 |
|
5565 |
|
5566 | if (startArcs = arcsByEnd.get(startPoint = coordinates[arc[0]])) {
|
5567 | for (i = 0, n = startArcs.length; i < n; ++i) {
|
5568 | startArc = startArcs[i];
|
5569 | if (equalLine(startArc, arc)) {
|
5570 | arc[0] = startArc[0];
|
5571 | arc[1] = startArc[1];
|
5572 | return;
|
5573 | }
|
5574 | }
|
5575 | }
|
5576 |
|
5577 |
|
5578 | if (endArcs = arcsByEnd.get(endPoint = coordinates[arc[1]])) {
|
5579 | for (i = 0, n = endArcs.length; i < n; ++i) {
|
5580 | endArc = endArcs[i];
|
5581 | if (reverseEqualLine(endArc, arc)) {
|
5582 | arc[1] = endArc[0];
|
5583 | arc[0] = endArc[1];
|
5584 | return;
|
5585 | }
|
5586 | }
|
5587 | }
|
5588 |
|
5589 | if (startArcs) startArcs.push(arc); else arcsByEnd.set(startPoint, [arc]);
|
5590 | if (endArcs) endArcs.push(arc); else arcsByEnd.set(endPoint, [arc]);
|
5591 | arcs.push(arc);
|
5592 | }
|
5593 |
|
5594 | function dedupRing(arc) {
|
5595 | var endPoint,
|
5596 | endArcs,
|
5597 | endArc,
|
5598 | i, n;
|
5599 |
|
5600 |
|
5601 |
|
5602 | if (endArcs = arcsByEnd.get(endPoint = coordinates[arc[0]])) {
|
5603 | for (i = 0, n = endArcs.length; i < n; ++i) {
|
5604 | endArc = endArcs[i];
|
5605 | if (equalRing(endArc, arc)) {
|
5606 | arc[0] = endArc[0];
|
5607 | arc[1] = endArc[1];
|
5608 | return;
|
5609 | }
|
5610 | if (reverseEqualRing(endArc, arc)) {
|
5611 | arc[0] = endArc[1];
|
5612 | arc[1] = endArc[0];
|
5613 | return;
|
5614 | }
|
5615 | }
|
5616 | }
|
5617 |
|
5618 |
|
5619 | if (endArcs = arcsByEnd.get(endPoint = coordinates[arc[0] + findMinimumOffset(arc)])) {
|
5620 | for (i = 0, n = endArcs.length; i < n; ++i) {
|
5621 | endArc = endArcs[i];
|
5622 | if (equalRing(endArc, arc)) {
|
5623 | arc[0] = endArc[0];
|
5624 | arc[1] = endArc[1];
|
5625 | return;
|
5626 | }
|
5627 | if (reverseEqualRing(endArc, arc)) {
|
5628 | arc[0] = endArc[1];
|
5629 | arc[1] = endArc[0];
|
5630 | return;
|
5631 | }
|
5632 | }
|
5633 | }
|
5634 |
|
5635 | if (endArcs) endArcs.push(arc); else arcsByEnd.set(endPoint, [arc]);
|
5636 | arcs.push(arc);
|
5637 | }
|
5638 |
|
5639 | function equalLine(arcA, arcB) {
|
5640 | var ia = arcA[0], ib = arcB[0],
|
5641 | ja = arcA[1], jb = arcB[1];
|
5642 | if (ia - ja !== ib - jb) return false;
|
5643 | for (; ia <= ja; ++ia, ++ib) if (!equalPoint(coordinates[ia], coordinates[ib])) return false;
|
5644 | return true;
|
5645 | }
|
5646 |
|
5647 | function reverseEqualLine(arcA, arcB) {
|
5648 | var ia = arcA[0], ib = arcB[0],
|
5649 | ja = arcA[1], jb = arcB[1];
|
5650 | if (ia - ja !== ib - jb) return false;
|
5651 | for (; ia <= ja; ++ia, --jb) if (!equalPoint(coordinates[ia], coordinates[jb])) return false;
|
5652 | return true;
|
5653 | }
|
5654 |
|
5655 | function equalRing(arcA, arcB) {
|
5656 | var ia = arcA[0], ib = arcB[0],
|
5657 | ja = arcA[1], jb = arcB[1],
|
5658 | n = ja - ia;
|
5659 | if (n !== jb - ib) return false;
|
5660 | var ka = findMinimumOffset(arcA),
|
5661 | kb = findMinimumOffset(arcB);
|
5662 | for (var i = 0; i < n; ++i) {
|
5663 | if (!equalPoint(coordinates[ia + (i + ka) % n], coordinates[ib + (i + kb) % n])) return false;
|
5664 | }
|
5665 | return true;
|
5666 | }
|
5667 |
|
5668 | function reverseEqualRing(arcA, arcB) {
|
5669 | var ia = arcA[0], ib = arcB[0],
|
5670 | ja = arcA[1], jb = arcB[1],
|
5671 | n = ja - ia;
|
5672 | if (n !== jb - ib) return false;
|
5673 | var ka = findMinimumOffset(arcA),
|
5674 | kb = n - findMinimumOffset(arcB);
|
5675 | for (var i = 0; i < n; ++i) {
|
5676 | if (!equalPoint(coordinates[ia + (i + ka) % n], coordinates[jb - (i + kb) % n])) return false;
|
5677 | }
|
5678 | return true;
|
5679 | }
|
5680 |
|
5681 |
|
5682 |
|
5683 | function findMinimumOffset(arc) {
|
5684 | var start = arc[0],
|
5685 | end = arc[1],
|
5686 | mid = start,
|
5687 | minimum = mid,
|
5688 | minimumPoint = coordinates[mid];
|
5689 | while (++mid < end) {
|
5690 | var point = coordinates[mid];
|
5691 | if (point[0] < minimumPoint[0] || point[0] === minimumPoint[0] && point[1] < minimumPoint[1]) {
|
5692 | minimum = mid;
|
5693 | minimumPoint = point;
|
5694 | }
|
5695 | }
|
5696 | return minimum - start;
|
5697 | }
|
5698 |
|
5699 | return topology;
|
5700 | };
|
5701 |
|
5702 |
|
5703 |
|
5704 |
|
5705 | var delta = function(arcs) {
|
5706 | var i = -1,
|
5707 | n = arcs.length;
|
5708 |
|
5709 | while (++i < n) {
|
5710 | var arc = arcs[i],
|
5711 | j = 0,
|
5712 | k = 1,
|
5713 | m = arc.length,
|
5714 | point = arc[0],
|
5715 | x0 = point[0],
|
5716 | y0 = point[1],
|
5717 | x1,
|
5718 | y1;
|
5719 |
|
5720 | while (++j < m) {
|
5721 | point = arc[j], x1 = point[0], y1 = point[1];
|
5722 | if (x1 !== x0 || y1 !== y0) arc[k++] = [x1 - x0, y1 - y0], x0 = x1, y0 = y1;
|
5723 | }
|
5724 |
|
5725 | if (k === 1) arc[k++] = [0, 0];
|
5726 |
|
5727 | arc.length = k;
|
5728 | }
|
5729 |
|
5730 | return arcs;
|
5731 | };
|
5732 |
|
5733 |
|
5734 |
|
5735 |
|
5736 |
|
5737 |
|
5738 |
|
5739 |
|
5740 |
|
5741 |
|
5742 |
|
5743 |
|
5744 |
|
5745 |
|
5746 |
|
5747 |
|
5748 |
|
5749 |
|
5750 | var extract = function(objects) {
|
5751 | var index = -1,
|
5752 | lines = [],
|
5753 | rings = [],
|
5754 | coordinates = [];
|
5755 |
|
5756 | function extractGeometry(geometry) {
|
5757 | if (geometry && extractGeometryType.hasOwnProperty(geometry.type)) extractGeometryType[geometry.type](geometry);
|
5758 | }
|
5759 |
|
5760 | var extractGeometryType = {
|
5761 | GeometryCollection: function(o) { o.geometries.forEach(extractGeometry); },
|
5762 | LineString: function(o) { o.arcs = extractLine(o.arcs); },
|
5763 | MultiLineString: function(o) { o.arcs = o.arcs.map(extractLine); },
|
5764 | Polygon: function(o) { o.arcs = o.arcs.map(extractRing); },
|
5765 | MultiPolygon: function(o) { o.arcs = o.arcs.map(extractMultiRing); }
|
5766 | };
|
5767 |
|
5768 | function extractLine(line) {
|
5769 | for (var i = 0, n = line.length; i < n; ++i) coordinates[++index] = line[i];
|
5770 | var arc = {0: index - n + 1, 1: index};
|
5771 | lines.push(arc);
|
5772 | return arc;
|
5773 | }
|
5774 |
|
5775 | function extractRing(ring) {
|
5776 | for (var i = 0, n = ring.length; i < n; ++i) coordinates[++index] = ring[i];
|
5777 | var arc = {0: index - n + 1, 1: index};
|
5778 | rings.push(arc);
|
5779 | return arc;
|
5780 | }
|
5781 |
|
5782 | function extractMultiRing(rings) {
|
5783 | return rings.map(extractRing);
|
5784 | }
|
5785 |
|
5786 | for (var key in objects) {
|
5787 | extractGeometry(objects[key]);
|
5788 | }
|
5789 |
|
5790 | return {
|
5791 | type: "Topology",
|
5792 | coordinates: coordinates,
|
5793 | lines: lines,
|
5794 | rings: rings,
|
5795 | objects: objects
|
5796 | };
|
5797 | };
|
5798 |
|
5799 |
|
5800 |
|
5801 |
|
5802 |
|
5803 | var geometry$1 = function(inputs) {
|
5804 | var outputs = {}, key;
|
5805 | for (key in inputs) outputs[key] = geomifyObject(inputs[key]);
|
5806 | return outputs;
|
5807 | };
|
5808 |
|
5809 | function geomifyObject(input) {
|
5810 | return input == null ? {type: null}
|
5811 | : (input.type === "FeatureCollection" ? geomifyFeatureCollection
|
5812 | : input.type === "Feature" ? geomifyFeature
|
5813 | : geomifyGeometry)(input);
|
5814 | }
|
5815 |
|
5816 | function geomifyFeatureCollection(input) {
|
5817 | var output = {type: "GeometryCollection", geometries: input.features.map(geomifyFeature)};
|
5818 | if (input.bbox != null) output.bbox = input.bbox;
|
5819 | return output;
|
5820 | }
|
5821 |
|
5822 | function geomifyFeature(input) {
|
5823 | var output = geomifyGeometry(input.geometry), key;
|
5824 | if (input.id != null) output.id = input.id;
|
5825 | if (input.bbox != null) output.bbox = input.bbox;
|
5826 | for (key in input.properties) { output.properties = input.properties; break; }
|
5827 | return output;
|
5828 | }
|
5829 |
|
5830 | function geomifyGeometry(input) {
|
5831 | if (input == null) return {type: null};
|
5832 | var output = input.type === "GeometryCollection" ? {type: "GeometryCollection", geometries: input.geometries.map(geomifyGeometry)}
|
5833 | : input.type === "Point" || input.type === "MultiPoint" ? {type: input.type, coordinates: input.coordinates}
|
5834 | : {type: input.type, arcs: input.coordinates};
|
5835 | if (input.bbox != null) output.bbox = input.bbox;
|
5836 | return output;
|
5837 | }
|
5838 |
|
5839 | var prequantize = function(objects, bbox, n) {
|
5840 | var x0 = bbox[0],
|
5841 | y0 = bbox[1],
|
5842 | x1 = bbox[2],
|
5843 | y1 = bbox[3],
|
5844 | kx = x1 - x0 ? (n - 1) / (x1 - x0) : 1,
|
5845 | ky = y1 - y0 ? (n - 1) / (y1 - y0) : 1;
|
5846 |
|
5847 | function quantizePoint(input) {
|
5848 | return [Math.round((input[0] - x0) * kx), Math.round((input[1] - y0) * ky)];
|
5849 | }
|
5850 |
|
5851 | function quantizePoints(input, m) {
|
5852 | var i = -1,
|
5853 | j = 0,
|
5854 | n = input.length,
|
5855 | output = new Array(n),
|
5856 | pi,
|
5857 | px,
|
5858 | py,
|
5859 | x,
|
5860 | y;
|
5861 |
|
5862 | while (++i < n) {
|
5863 | pi = input[i];
|
5864 | x = Math.round((pi[0] - x0) * kx);
|
5865 | y = Math.round((pi[1] - y0) * ky);
|
5866 | if (x !== px || y !== py) output[j++] = [px = x, py = y];
|
5867 | }
|
5868 |
|
5869 | output.length = j;
|
5870 | while (j < m) j = output.push([output[0][0], output[0][1]]);
|
5871 | return output;
|
5872 | }
|
5873 |
|
5874 | function quantizeLine(input) {
|
5875 | return quantizePoints(input, 2);
|
5876 | }
|
5877 |
|
5878 | function quantizeRing(input) {
|
5879 | return quantizePoints(input, 4);
|
5880 | }
|
5881 |
|
5882 | function quantizePolygon(input) {
|
5883 | return input.map(quantizeRing);
|
5884 | }
|
5885 |
|
5886 | function quantizeGeometry(o) {
|
5887 | if (o != null && quantizeGeometryType.hasOwnProperty(o.type)) quantizeGeometryType[o.type](o);
|
5888 | }
|
5889 |
|
5890 | var quantizeGeometryType = {
|
5891 | GeometryCollection: function(o) { o.geometries.forEach(quantizeGeometry); },
|
5892 | Point: function(o) { o.coordinates = quantizePoint(o.coordinates); },
|
5893 | MultiPoint: function(o) { o.coordinates = o.coordinates.map(quantizePoint); },
|
5894 | LineString: function(o) { o.arcs = quantizeLine(o.arcs); },
|
5895 | MultiLineString: function(o) { o.arcs = o.arcs.map(quantizeLine); },
|
5896 | Polygon: function(o) { o.arcs = quantizePolygon(o.arcs); },
|
5897 | MultiPolygon: function(o) { o.arcs = o.arcs.map(quantizePolygon); }
|
5898 | };
|
5899 |
|
5900 | for (var key in objects) {
|
5901 | quantizeGeometry(objects[key]);
|
5902 | }
|
5903 |
|
5904 | return {
|
5905 | scale: [1 / kx, 1 / ky],
|
5906 | translate: [x0, y0]
|
5907 | };
|
5908 | };
|
5909 |
|
5910 |
|
5911 |
|
5912 |
|
5913 | var topology = function(objects, quantization) {
|
5914 | var bbox = bounds(objects = geometry$1(objects)),
|
5915 | transform = quantization > 0 && bbox && prequantize(objects, bbox, quantization),
|
5916 | topology = dedup$1(cut(extract(objects))),
|
5917 | coordinates = topology.coordinates,
|
5918 | indexByArc = hashmap(topology.arcs.length * 1.4, hashArc, equalArc);
|
5919 |
|
5920 | objects = topology.objects;
|
5921 | topology.bbox = bbox;
|
5922 | topology.arcs = topology.arcs.map(function(arc, i) {
|
5923 | indexByArc.set(arc, i);
|
5924 | return coordinates.slice(arc[0], arc[1] + 1);
|
5925 | });
|
5926 |
|
5927 | delete topology.coordinates;
|
5928 | coordinates = null;
|
5929 |
|
5930 | function indexGeometry(geometry) {
|
5931 | if (geometry && indexGeometryType.hasOwnProperty(geometry.type)) indexGeometryType[geometry.type](geometry);
|
5932 | }
|
5933 |
|
5934 | var indexGeometryType = {
|
5935 | GeometryCollection: function(o) { o.geometries.forEach(indexGeometry); },
|
5936 | LineString: function(o) { o.arcs = indexArcs(o.arcs); },
|
5937 | MultiLineString: function(o) { o.arcs = o.arcs.map(indexArcs); },
|
5938 | Polygon: function(o) { o.arcs = o.arcs.map(indexArcs); },
|
5939 | MultiPolygon: function(o) { o.arcs = o.arcs.map(indexMultiArcs); }
|
5940 | };
|
5941 |
|
5942 | function indexArcs(arc) {
|
5943 | var indexes = [];
|
5944 | do {
|
5945 | var index = indexByArc.get(arc);
|
5946 | indexes.push(arc[0] < arc[1] ? index : ~index);
|
5947 | } while (arc = arc.next);
|
5948 | return indexes;
|
5949 | }
|
5950 |
|
5951 | function indexMultiArcs(arcs) {
|
5952 | return arcs.map(indexArcs);
|
5953 | }
|
5954 |
|
5955 | for (var key in objects) {
|
5956 | indexGeometry(objects[key]);
|
5957 | }
|
5958 |
|
5959 | if (transform) {
|
5960 | topology.transform = transform;
|
5961 | topology.arcs = delta(topology.arcs);
|
5962 | }
|
5963 |
|
5964 | return topology;
|
5965 | };
|
5966 |
|
5967 | function hashArc(arc) {
|
5968 | var i = arc[0], j = arc[1], t;
|
5969 | if (j < i) t = i, i = j, j = t;
|
5970 | return i + 31 * j;
|
5971 | }
|
5972 |
|
5973 | function equalArc(arcA, arcB) {
|
5974 | var ia = arcA[0], ja = arcA[1],
|
5975 | ib = arcB[0], jb = arcB[1], t;
|
5976 | if (ja < ia) t = ia, ia = ja, ja = t;
|
5977 | if (jb < ib) t = ib, ib = jb, jb = t;
|
5978 | return ia === ib && ja === jb;
|
5979 | }
|
5980 |
|
5981 |
|
5982 |
|
5983 |
|
5984 |
|
5985 |
|
5986 |
|
5987 |
|
5988 |
|
5989 |
|
5990 | function lineDissolve(geojson, options) {
|
5991 |
|
5992 | options = options || {};
|
5993 | if (!isObject(options)) throw new Error('options is invalid');
|
5994 | var mutate = options.mutate;
|
5995 |
|
5996 |
|
5997 | if (getType(geojson) !== 'FeatureCollection') throw new Error('geojson must be a FeatureCollection');
|
5998 | if (!geojson.features.length) throw new Error('geojson is empty');
|
5999 |
|
6000 |
|
6001 | if (mutate === false || mutate === undefined) geojson = clone(geojson);
|
6002 |
|
6003 | var result = [];
|
6004 | var lastLine = lineReduce(geojson, function (previousLine, currentLine) {
|
6005 |
|
6006 |
|
6007 | var merged = mergeLineStrings(previousLine, currentLine);
|
6008 |
|
6009 |
|
6010 | if (merged) return merged;
|
6011 |
|
6012 |
|
6013 | else {
|
6014 | result.push(previousLine);
|
6015 | return currentLine;
|
6016 | }
|
6017 | });
|
6018 |
|
6019 | if (lastLine) result.push(lastLine);
|
6020 |
|
6021 |
|
6022 | if (!result.length) return null;
|
6023 |
|
6024 | else if (result.length === 1) return result[0];
|
6025 |
|
6026 | else return multiLineString(result.map(function (line) { return line.coordinates; }));
|
6027 | }
|
6028 |
|
6029 |
|
6030 | function coordId(coord) {
|
6031 | return coord[0].toString() + ',' + coord[1].toString();
|
6032 | }
|
6033 |
|
6034 |
|
6035 |
|
6036 |
|
6037 |
|
6038 |
|
6039 |
|
6040 |
|
6041 |
|
6042 | function mergeLineStrings(a, b) {
|
6043 | var coords1 = a.geometry.coordinates;
|
6044 | var coords2 = b.geometry.coordinates;
|
6045 |
|
6046 | var s1 = coordId(coords1[0]);
|
6047 | var e1 = coordId(coords1[coords1.length - 1]);
|
6048 | var s2 = coordId(coords2[0]);
|
6049 | var e2 = coordId(coords2[coords2.length - 1]);
|
6050 |
|
6051 |
|
6052 | var coords;
|
6053 | if (s1 === e2) coords = coords2.concat(coords1.slice(1));
|
6054 | else if (s2 === e1) coords = coords1.concat(coords2.slice(1));
|
6055 | else if (s1 === s2) coords = coords1.slice(1).reverse().concat(coords2);
|
6056 | else if (e1 === e2) coords = coords1.concat(coords2.reverse().slice(1));
|
6057 | else return null;
|
6058 |
|
6059 | return lineString(coords);
|
6060 | }
|
6061 |
|
6062 |
|
6063 |
|
6064 |
|
6065 |
|
6066 |
|
6067 |
|
6068 |
|
6069 |
|
6070 | function polygonDissolve(geojson, options) {
|
6071 |
|
6072 | options = options || {};
|
6073 | if (!isObject(options)) throw new Error('options is invalid');
|
6074 | var mutate = options.mutate;
|
6075 |
|
6076 |
|
6077 | if (getType(geojson) !== 'FeatureCollection') throw new Error('geojson must be a FeatureCollection');
|
6078 | if (!geojson.features.length) throw new Error('geojson is empty');
|
6079 |
|
6080 |
|
6081 |
|
6082 | if (mutate === false || mutate === undefined) geojson = clone(geojson);
|
6083 |
|
6084 | var geoms = [];
|
6085 | flattenEach(geojson, function (feature$$1) {
|
6086 | geoms.push(feature$$1.geometry);
|
6087 | });
|
6088 | var topo = topology({geoms: geometryCollection(geoms).geometry});
|
6089 | return merge(topo, topo.objects.geoms.geometries);
|
6090 | }
|
6091 |
|
6092 |
|
6093 |
|
6094 |
|
6095 |
|
6096 |
|
6097 |
|
6098 |
|
6099 |
|
6100 |
|
6101 |
|
6102 | function dissolve(geojson, options) {
|
6103 |
|
6104 | options = options || {};
|
6105 | if (!isObject(options)) throw new Error('options is invalid');
|
6106 | var mutate = options.mutate;
|
6107 |
|
6108 |
|
6109 | if (getType(geojson) !== 'FeatureCollection') throw new Error('geojson must be a FeatureCollection');
|
6110 | if (!geojson.features.length) throw new Error('geojson is empty');
|
6111 |
|
6112 |
|
6113 |
|
6114 | if (mutate === false || mutate === undefined) geojson = clone(geojson);
|
6115 |
|
6116 |
|
6117 | var type = getHomogenousType(geojson);
|
6118 | if (!type) throw new Error('geojson must be homogenous');
|
6119 |
|
6120 | switch (type) {
|
6121 | case 'LineString':
|
6122 | return lineDissolve(geojson, options);
|
6123 | case 'Polygon':
|
6124 | return polygonDissolve(geojson, options);
|
6125 | default:
|
6126 | throw new Error(type + ' is not supported');
|
6127 | }
|
6128 | }
|
6129 |
|
6130 |
|
6131 |
|
6132 |
|
6133 |
|
6134 |
|
6135 |
|
6136 |
|
6137 | function getHomogenousType(geojson) {
|
6138 | var types = {};
|
6139 | flattenEach(geojson, function (feature$$1) {
|
6140 | types[feature$$1.geometry.type] = true;
|
6141 | });
|
6142 | var keys = Object.keys(types);
|
6143 | if (keys.length === 1) return keys[0];
|
6144 | return null;
|
6145 | }
|
6146 |
|
6147 |
|
6148 |
|
6149 |
|
6150 |
|
6151 |
|
6152 |
|
6153 |
|
6154 |
|
6155 |
|
6156 |
|
6157 |
|
6158 |
|
6159 |
|
6160 |
|
6161 |
|
6162 |
|
6163 |
|
6164 |
|
6165 |
|
6166 |
|
6167 |
|
6168 |
|
6169 |
|
6170 |
|
6171 |
|
6172 |
|
6173 | function concave(points$$1, options) {
|
6174 |
|
6175 | options = options || {};
|
6176 | if (!isObject(options)) throw new Error('options is invalid');
|
6177 |
|
6178 |
|
6179 | if (!points$$1) throw new Error('points is required');
|
6180 | var maxEdge = options.maxEdge || Infinity;
|
6181 | if (!isNumber(maxEdge)) throw new Error('maxEdge is invalid');
|
6182 |
|
6183 | var cleaned = removeDuplicates(points$$1);
|
6184 |
|
6185 | var tinPolys = tin(cleaned);
|
6186 |
|
6187 |
|
6188 | tinPolys.features = tinPolys.features.filter(function (triangle) {
|
6189 | var pt1 = triangle.geometry.coordinates[0][0];
|
6190 | var pt2 = triangle.geometry.coordinates[0][1];
|
6191 | var pt3 = triangle.geometry.coordinates[0][2];
|
6192 | var dist1 = distance(pt1, pt2, options);
|
6193 | var dist2 = distance(pt2, pt3, options);
|
6194 | var dist3 = distance(pt1, pt3, options);
|
6195 | return (dist1 <= maxEdge && dist2 <= maxEdge && dist3 <= maxEdge);
|
6196 | });
|
6197 |
|
6198 | if (tinPolys.features.length < 1) return null;
|
6199 |
|
6200 |
|
6201 | var dissolved = dissolve(tinPolys, options);
|
6202 |
|
6203 |
|
6204 | if (dissolved.coordinates.length === 1) {
|
6205 | dissolved.coordinates = dissolved.coordinates[0];
|
6206 | dissolved.type = 'Polygon';
|
6207 | }
|
6208 | return feature(dissolved);
|
6209 | }
|
6210 |
|
6211 |
|
6212 |
|
6213 |
|
6214 |
|
6215 |
|
6216 |
|
6217 |
|
6218 | function removeDuplicates(points$$1) {
|
6219 | var cleaned = [];
|
6220 | var existing = {};
|
6221 |
|
6222 | featureEach(points$$1, function (pt) {
|
6223 | if (!pt.geometry) return;
|
6224 | var key = pt.geometry.coordinates.join('-');
|
6225 | if (!existing.hasOwnProperty(key)) {
|
6226 | cleaned.push(pt);
|
6227 | existing[key] = true;
|
6228 | }
|
6229 | });
|
6230 | return featureCollection(cleaned);
|
6231 | }
|
6232 |
|
6233 |
|
6234 |
|
6235 |
|
6236 |
|
6237 |
|
6238 |
|
6239 |
|
6240 |
|
6241 |
|
6242 |
|
6243 |
|
6244 |
|
6245 |
|
6246 |
|
6247 |
|
6248 |
|
6249 |
|
6250 |
|
6251 |
|
6252 |
|
6253 |
|
6254 |
|
6255 |
|
6256 |
|
6257 |
|
6258 |
|
6259 |
|
6260 |
|
6261 |
|
6262 |
|
6263 | function collect(polygons, points, inProperty, outProperty) {
|
6264 | var rtree = rbush_1(6);
|
6265 |
|
6266 | var treeItems = points.features.map(function (item) {
|
6267 | return {
|
6268 | minX: item.geometry.coordinates[0],
|
6269 | minY: item.geometry.coordinates[1],
|
6270 | maxX: item.geometry.coordinates[0],
|
6271 | maxY: item.geometry.coordinates[1],
|
6272 | property: item.properties[inProperty]
|
6273 | };
|
6274 | });
|
6275 |
|
6276 | rtree.load(treeItems);
|
6277 | polygons.features.forEach(function (poly) {
|
6278 |
|
6279 | if (!poly.properties) {
|
6280 | poly.properties = {};
|
6281 | }
|
6282 | var bbox$$1 = bbox(poly);
|
6283 | var potentialPoints = rtree.search({minX: bbox$$1[0], minY: bbox$$1[1], maxX: bbox$$1[2], maxY: bbox$$1[3]});
|
6284 | var values = [];
|
6285 | potentialPoints.forEach(function (pt) {
|
6286 | if (booleanPointInPolygon([pt.minX, pt.minY], poly)) {
|
6287 | values.push(pt.property);
|
6288 | }
|
6289 | });
|
6290 |
|
6291 | poly.properties[outProperty] = values;
|
6292 | });
|
6293 |
|
6294 | return polygons;
|
6295 | }
|
6296 |
|
6297 |
|
6298 |
|
6299 |
|
6300 |
|
6301 |
|
6302 |
|
6303 |
|
6304 |
|
6305 |
|
6306 |
|
6307 |
|
6308 |
|
6309 |
|
6310 |
|
6311 |
|
6312 |
|
6313 | function flip(geojson, options) {
|
6314 |
|
6315 | options = options || {};
|
6316 | if (!isObject(options)) throw new Error('options is invalid');
|
6317 | var mutate = options.mutate;
|
6318 |
|
6319 | if (!geojson) throw new Error('geojson is required');
|
6320 |
|
6321 |
|
6322 |
|
6323 | if (mutate === false || mutate === undefined) geojson = clone(geojson);
|
6324 |
|
6325 | coordEach(geojson, function (coord) {
|
6326 | var x = coord[0];
|
6327 | var y = coord[1];
|
6328 | coord[0] = y;
|
6329 | coord[1] = x;
|
6330 | });
|
6331 | return geojson;
|
6332 | }
|
6333 |
|
6334 |
|
6335 |
|
6336 |
|
6337 |
|
6338 |
|
6339 |
|
6340 |
|
6341 |
|
6342 |
|
6343 |
|
6344 |
|
6345 |
|
6346 |
|
6347 |
|
6348 |
|
6349 |
|
6350 |
|
6351 |
|
6352 | function cleanCoords(geojson, options) {
|
6353 |
|
6354 | var mutate = (typeof options === 'object') ? options.mutate : options;
|
6355 | if (!geojson) throw new Error('geojson is required');
|
6356 | var type = getType(geojson);
|
6357 |
|
6358 |
|
6359 | var newCoords = [];
|
6360 |
|
6361 | switch (type) {
|
6362 | case 'LineString':
|
6363 | newCoords = cleanLine(geojson);
|
6364 | break;
|
6365 | case 'MultiLineString':
|
6366 | case 'Polygon':
|
6367 | getCoords(geojson).forEach(function (line) {
|
6368 | newCoords.push(cleanLine(line));
|
6369 | });
|
6370 | break;
|
6371 | case 'MultiPolygon':
|
6372 | getCoords(geojson).forEach(function (polygons$$1) {
|
6373 | var polyPoints = [];
|
6374 | polygons$$1.forEach(function (ring) {
|
6375 | polyPoints.push(cleanLine(ring));
|
6376 | });
|
6377 | newCoords.push(polyPoints);
|
6378 | });
|
6379 | break;
|
6380 | case 'Point':
|
6381 | return geojson;
|
6382 | case 'MultiPoint':
|
6383 | var existing = {};
|
6384 | getCoords(geojson).forEach(function (coord) {
|
6385 | var key = coord.join('-');
|
6386 | if (!existing.hasOwnProperty(key)) {
|
6387 | newCoords.push(coord);
|
6388 | existing[key] = true;
|
6389 | }
|
6390 | });
|
6391 | break;
|
6392 | default:
|
6393 | throw new Error(type + ' geometry not supported');
|
6394 | }
|
6395 |
|
6396 |
|
6397 | if (geojson.coordinates) {
|
6398 | if (mutate === true) {
|
6399 | geojson.coordinates = newCoords;
|
6400 | return geojson;
|
6401 | }
|
6402 | return {type: type, coordinates: newCoords};
|
6403 | } else {
|
6404 | if (mutate === true) {
|
6405 | geojson.geometry.coordinates = newCoords;
|
6406 | return geojson;
|
6407 | }
|
6408 | return feature({type: type, coordinates: newCoords}, geojson.properties, geojson.bbox, geojson.id);
|
6409 | }
|
6410 | }
|
6411 |
|
6412 |
|
6413 |
|
6414 |
|
6415 |
|
6416 |
|
6417 |
|
6418 |
|
6419 | function cleanLine(line) {
|
6420 | var points$$1 = getCoords(line);
|
6421 |
|
6422 | if (points$$1.length === 2 && !equals(points$$1[0], points$$1[1])) return points$$1;
|
6423 |
|
6424 | var prevPoint, point$$1, nextPoint;
|
6425 | var newPoints = [];
|
6426 | var secondToLast = points$$1.length - 1;
|
6427 |
|
6428 | newPoints.push(points$$1[0]);
|
6429 | for (var i = 1; i < secondToLast; i++) {
|
6430 | prevPoint = points$$1[i - 1];
|
6431 | point$$1 = points$$1[i];
|
6432 | nextPoint = points$$1[i + 1];
|
6433 |
|
6434 | if (!isPointOnLineSegment(prevPoint, nextPoint, point$$1)) {
|
6435 | newPoints.push(point$$1);
|
6436 | }
|
6437 | }
|
6438 | newPoints.push(nextPoint);
|
6439 | return newPoints;
|
6440 | }
|
6441 |
|
6442 |
|
6443 |
|
6444 |
|
6445 |
|
6446 |
|
6447 |
|
6448 |
|
6449 |
|
6450 | function equals(pt1, pt2) {
|
6451 | return pt1[0] === pt2[0] && pt1[1] === pt2[1];
|
6452 | }
|
6453 |
|
6454 |
|
6455 |
|
6456 |
|
6457 |
|
6458 |
|
6459 |
|
6460 |
|
6461 |
|
6462 |
|
6463 |
|
6464 | function isPointOnLineSegment(start, end, point$$1) {
|
6465 | var x = point$$1[0], y = point$$1[1];
|
6466 | var startX = start[0], startY = start[1];
|
6467 | var endX = end[0], endY = end[1];
|
6468 |
|
6469 | var dxc = x - startX;
|
6470 | var dyc = y - startY;
|
6471 | var dxl = endX - startX;
|
6472 | var dyl = endY - startY;
|
6473 | var cross = dxc * dyl - dyc * dxl;
|
6474 |
|
6475 | if (cross !== 0) return false;
|
6476 | else if (Math.abs(dxl) >= Math.abs(dyl)) return dxl > 0 ? startX <= x && x <= endX : endX <= x && x <= startX;
|
6477 | else return dyl > 0 ? startY <= y && y <= endY : endY <= y && y <= startY;
|
6478 | }
|
6479 |
|
6480 |
|
6481 |
|
6482 |
|
6483 |
|
6484 |
|
6485 |
|
6486 |
|
6487 |
|
6488 |
|
6489 |
|
6490 | function getSqDist$1(p1, p2) {
|
6491 |
|
6492 | var dx = p1.x - p2.x,
|
6493 | dy = p1.y - p2.y;
|
6494 |
|
6495 | return dx * dx + dy * dy;
|
6496 | }
|
6497 |
|
6498 |
|
6499 | function getSqSegDist(p, p1, p2) {
|
6500 |
|
6501 | var x = p1.x,
|
6502 | y = p1.y,
|
6503 | dx = p2.x - x,
|
6504 | dy = p2.y - y;
|
6505 |
|
6506 | if (dx !== 0 || dy !== 0) {
|
6507 |
|
6508 | var t = ((p.x - x) * dx + (p.y - y) * dy) / (dx * dx + dy * dy);
|
6509 |
|
6510 | if (t > 1) {
|
6511 | x = p2.x;
|
6512 | y = p2.y;
|
6513 |
|
6514 | } else if (t > 0) {
|
6515 | x += dx * t;
|
6516 | y += dy * t;
|
6517 | }
|
6518 | }
|
6519 |
|
6520 | dx = p.x - x;
|
6521 | dy = p.y - y;
|
6522 |
|
6523 | return dx * dx + dy * dy;
|
6524 | }
|
6525 |
|
6526 |
|
6527 |
|
6528 | function simplifyRadialDist(points$$1, sqTolerance) {
|
6529 |
|
6530 | var prevPoint = points$$1[0],
|
6531 | newPoints = [prevPoint],
|
6532 | point$$1;
|
6533 |
|
6534 | for (var i = 1, len = points$$1.length; i < len; i++) {
|
6535 | point$$1 = points$$1[i];
|
6536 |
|
6537 | if (getSqDist$1(point$$1, prevPoint) > sqTolerance) {
|
6538 | newPoints.push(point$$1);
|
6539 | prevPoint = point$$1;
|
6540 | }
|
6541 | }
|
6542 |
|
6543 | if (prevPoint !== point$$1) newPoints.push(point$$1);
|
6544 |
|
6545 | return newPoints;
|
6546 | }
|
6547 |
|
6548 | function simplifyDPStep(points$$1, first, last, sqTolerance, simplified) {
|
6549 | var maxSqDist = sqTolerance,
|
6550 | index;
|
6551 |
|
6552 | for (var i = first + 1; i < last; i++) {
|
6553 | var sqDist = getSqSegDist(points$$1[i], points$$1[first], points$$1[last]);
|
6554 |
|
6555 | if (sqDist > maxSqDist) {
|
6556 | index = i;
|
6557 | maxSqDist = sqDist;
|
6558 | }
|
6559 | }
|
6560 |
|
6561 | if (maxSqDist > sqTolerance) {
|
6562 | if (index - first > 1) simplifyDPStep(points$$1, first, index, sqTolerance, simplified);
|
6563 | simplified.push(points$$1[index]);
|
6564 | if (last - index > 1) simplifyDPStep(points$$1, index, last, sqTolerance, simplified);
|
6565 | }
|
6566 | }
|
6567 |
|
6568 |
|
6569 | function simplifyDouglasPeucker(points$$1, sqTolerance) {
|
6570 | var last = points$$1.length - 1;
|
6571 |
|
6572 | var simplified = [points$$1[0]];
|
6573 | simplifyDPStep(points$$1, 0, last, sqTolerance, simplified);
|
6574 | simplified.push(points$$1[last]);
|
6575 |
|
6576 | return simplified;
|
6577 | }
|
6578 |
|
6579 |
|
6580 | function simplify$2(points$$1, tolerance, highestQuality) {
|
6581 |
|
6582 | if (points$$1.length <= 2) return points$$1;
|
6583 |
|
6584 | var sqTolerance = tolerance !== undefined ? tolerance * tolerance : 1;
|
6585 |
|
6586 | points$$1 = highestQuality ? points$$1 : simplifyRadialDist(points$$1, sqTolerance);
|
6587 | points$$1 = simplifyDouglasPeucker(points$$1, sqTolerance);
|
6588 |
|
6589 | return points$$1;
|
6590 | }
|
6591 |
|
6592 |
|
6593 |
|
6594 |
|
6595 |
|
6596 |
|
6597 |
|
6598 |
|
6599 |
|
6600 |
|
6601 |
|
6602 |
|
6603 |
|
6604 |
|
6605 |
|
6606 |
|
6607 |
|
6608 |
|
6609 |
|
6610 |
|
6611 |
|
6612 |
|
6613 |
|
6614 |
|
6615 |
|
6616 |
|
6617 |
|
6618 |
|
6619 |
|
6620 |
|
6621 |
|
6622 |
|
6623 |
|
6624 |
|
6625 |
|
6626 |
|
6627 |
|
6628 |
|
6629 |
|
6630 |
|
6631 |
|
6632 | function simplify(geojson, options) {
|
6633 |
|
6634 | options = options || {};
|
6635 | if (!isObject(options)) throw new Error('options is invalid');
|
6636 | var tolerance = options.tolerance !== undefined ? options.tolerance : 1;
|
6637 | var highQuality = options.highQuality || false;
|
6638 | var mutate = options.mutate || false;
|
6639 |
|
6640 | if (!geojson) throw new Error('geojson is required');
|
6641 | if (tolerance && tolerance < 0) throw new Error('invalid tolerance');
|
6642 |
|
6643 |
|
6644 | if (mutate !== true) geojson = clone(geojson);
|
6645 |
|
6646 | geomEach(geojson, function (geom) {
|
6647 | simplifyGeom(geom, tolerance, highQuality);
|
6648 | });
|
6649 | return geojson;
|
6650 | }
|
6651 |
|
6652 |
|
6653 |
|
6654 |
|
6655 |
|
6656 |
|
6657 |
|
6658 |
|
6659 |
|
6660 |
|
6661 | function simplifyGeom(geometry$$1, tolerance, highQuality) {
|
6662 | var type = geometry$$1.type;
|
6663 |
|
6664 |
|
6665 | if (type === 'Point' || type === 'MultiPoint') return geometry$$1;
|
6666 |
|
6667 |
|
6668 | cleanCoords(geometry$$1, true);
|
6669 |
|
6670 | var coordinates = geometry$$1.coordinates;
|
6671 | switch (type) {
|
6672 | case 'LineString':
|
6673 | geometry$$1['coordinates'] = simplifyLine(coordinates, tolerance, highQuality);
|
6674 | break;
|
6675 | case 'MultiLineString':
|
6676 | geometry$$1['coordinates'] = coordinates.map(function (lines) {
|
6677 | return simplifyLine(lines, tolerance, highQuality);
|
6678 | });
|
6679 | break;
|
6680 | case 'Polygon':
|
6681 | geometry$$1['coordinates'] = simplifyPolygon(coordinates, tolerance, highQuality);
|
6682 | break;
|
6683 | case 'MultiPolygon':
|
6684 | geometry$$1['coordinates'] = coordinates.map(function (rings) {
|
6685 | return simplifyPolygon(rings, tolerance, highQuality);
|
6686 | });
|
6687 | }
|
6688 | return geometry$$1;
|
6689 | }
|
6690 |
|
6691 |
|
6692 |
|
6693 |
|
6694 |
|
6695 |
|
6696 |
|
6697 |
|
6698 |
|
6699 |
|
6700 |
|
6701 | function simplifyLine(coordinates, tolerance, highQuality) {
|
6702 | return simplify$2(coordinates.map(function (coord) {
|
6703 | return {x: coord[0], y: coord[1], z: coord[2]};
|
6704 | }), tolerance, highQuality).map(function (coords) {
|
6705 | return (coords.z) ? [coords.x, coords.y, coords.z] : [coords.x, coords.y];
|
6706 | });
|
6707 | }
|
6708 |
|
6709 |
|
6710 |
|
6711 |
|
6712 |
|
6713 |
|
6714 |
|
6715 |
|
6716 |
|
6717 |
|
6718 |
|
6719 | function simplifyPolygon(coordinates, tolerance, highQuality) {
|
6720 | return coordinates.map(function (ring) {
|
6721 | var pts = ring.map(function (coord) {
|
6722 | return {x: coord[0], y: coord[1]};
|
6723 | });
|
6724 | if (pts.length < 4) {
|
6725 | throw new Error('invalid polygon');
|
6726 | }
|
6727 | var simpleRing = simplify$2(pts, tolerance, highQuality).map(function (coords) {
|
6728 | return [coords.x, coords.y];
|
6729 | });
|
6730 |
|
6731 | while (!checkValidity(simpleRing)) {
|
6732 | tolerance -= tolerance * 0.01;
|
6733 | simpleRing = simplify$2(pts, tolerance, highQuality).map(function (coords) {
|
6734 | return [coords.x, coords.y];
|
6735 | });
|
6736 | }
|
6737 | if (
|
6738 | (simpleRing[simpleRing.length - 1][0] !== simpleRing[0][0]) ||
|
6739 | (simpleRing[simpleRing.length - 1][1] !== simpleRing[0][1])) {
|
6740 | simpleRing.push(simpleRing[0]);
|
6741 | }
|
6742 | return simpleRing;
|
6743 | });
|
6744 | }
|
6745 |
|
6746 |
|
6747 |
|
6748 |
|
6749 |
|
6750 |
|
6751 |
|
6752 |
|
6753 |
|
6754 | function checkValidity(ring) {
|
6755 | if (ring.length < 3) return false;
|
6756 |
|
6757 | return !(ring.length === 3 && ((ring[2][0] === ring[0][0]) && (ring[2][1] === ring[0][1])));
|
6758 | }
|
6759 |
|
6760 |
|
6761 |
|
6762 | |
6763 |
|
6764 |
|
6765 |
|
6766 |
|
6767 |
|
6768 |
|
6769 |
|
6770 |
|
6771 |
|
6772 |
|
6773 |
|
6774 |
|
6775 |
|
6776 |
|
6777 |
|
6778 |
|
6779 |
|
6780 |
|
6781 |
|
6782 |
|
6783 |
|
6784 |
|
6785 |
|
6786 |
|
6787 |
|
6788 | var Spline = function (options) {
|
6789 | this.points = options.points || [];
|
6790 | this.duration = options.duration || 10000;
|
6791 | this.sharpness = options.sharpness || 0.85;
|
6792 | this.centers = [];
|
6793 | this.controls = [];
|
6794 | this.stepLength = options.stepLength || 60;
|
6795 | this.length = this.points.length;
|
6796 | this.delay = 0;
|
6797 |
|
6798 | for (var i = 0; i < this.length; i++) this.points[i].z = this.points[i].z || 0;
|
6799 | for (var i = 0; i < this.length - 1; i++) {
|
6800 | var p1 = this.points[i];
|
6801 | var p2 = this.points[i + 1];
|
6802 | this.centers.push({
|
6803 | x: (p1.x + p2.x) / 2,
|
6804 | y: (p1.y + p2.y) / 2,
|
6805 | z: (p1.z + p2.z) / 2
|
6806 | });
|
6807 | }
|
6808 | this.controls.push([this.points[0], this.points[0]]);
|
6809 | for (var i = 0; i < this.centers.length - 1; i++) {
|
6810 | var p1 = this.centers[i];
|
6811 | var p2 = this.centers[i + 1];
|
6812 | var dx = this.points[i + 1].x - (this.centers[i].x + this.centers[i + 1].x) / 2;
|
6813 | var dy = this.points[i + 1].y - (this.centers[i].y + this.centers[i + 1].y) / 2;
|
6814 | var dz = this.points[i + 1].z - (this.centers[i].y + this.centers[i + 1].z) / 2;
|
6815 | this.controls.push([{
|
6816 | x: (1.0 - this.sharpness) * this.points[i + 1].x + this.sharpness * (this.centers[i].x + dx),
|
6817 | y: (1.0 - this.sharpness) * this.points[i + 1].y + this.sharpness * (this.centers[i].y + dy),
|
6818 | z: (1.0 - this.sharpness) * this.points[i + 1].z + this.sharpness * (this.centers[i].z + dz)},
|
6819 | {
|
6820 | x: (1.0 - this.sharpness) * this.points[i + 1].x + this.sharpness * (this.centers[i + 1].x + dx),
|
6821 | y: (1.0 - this.sharpness) * this.points[i + 1].y + this.sharpness * (this.centers[i + 1].y + dy),
|
6822 | z: (1.0 - this.sharpness) * this.points[i + 1].z + this.sharpness * (this.centers[i + 1].z + dz)}]);
|
6823 | }
|
6824 | this.controls.push([this.points[this.length - 1], this.points[this.length - 1]]);
|
6825 | this.steps = this.cacheSteps(this.stepLength);
|
6826 | return this;
|
6827 | };
|
6828 |
|
6829 | |
6830 |
|
6831 |
|
6832 | Spline.prototype.cacheSteps = function (mindist) {
|
6833 | var steps = [];
|
6834 | var laststep = this.pos(0);
|
6835 | steps.push(0);
|
6836 | for (var t = 0; t < this.duration; t += 10) {
|
6837 | var step = this.pos(t);
|
6838 | var dist = Math.sqrt((step.x - laststep.x) * (step.x - laststep.x) + (step.y - laststep.y) * (step.y - laststep.y) + (step.z - laststep.z) * (step.z - laststep.z));
|
6839 | if (dist > mindist) {
|
6840 | steps.push(t);
|
6841 | laststep = step;
|
6842 | }
|
6843 | }
|
6844 | return steps;
|
6845 | };
|
6846 |
|
6847 | |
6848 |
|
6849 |
|
6850 | Spline.prototype.vector = function (t) {
|
6851 | var p1 = this.pos(t + 10);
|
6852 | var p2 = this.pos(t - 10);
|
6853 | return {
|
6854 | angle:180 * Math.atan2(p1.y - p2.y, p1.x - p2.x) / 3.14,
|
6855 | speed:Math.sqrt((p2.x - p1.x) * (p2.x - p1.x) + (p2.y - p1.y) * (p2.y - p1.y) + (p2.z - p1.z) * (p2.z - p1.z))
|
6856 | };
|
6857 | };
|
6858 |
|
6859 | |
6860 |
|
6861 |
|
6862 |
|
6863 |
|
6864 |
|
6865 |
|
6866 | Spline.prototype.pos = function (time) {
|
6867 |
|
6868 | function bezier(t, p1, c1, c2, p2) {
|
6869 | var B = function (t) {
|
6870 | var t2 = t * t, t3 = t2 * t;
|
6871 | return [(t3), (3 * t2 * (1 - t)), (3 * t * (1 - t) * (1 - t)), ((1 - t) * (1 - t) * (1 - t))];
|
6872 | };
|
6873 | var b = B(t);
|
6874 | var pos = {
|
6875 | x : p2.x * b[0] + c2.x * b[1] + c1.x * b[2] + p1.x * b[3],
|
6876 | y : p2.y * b[0] + c2.y * b[1] + c1.y * b[2] + p1.y * b[3],
|
6877 | z : p2.z * b[0] + c2.z * b[1] + c1.z * b[2] + p1.z * b[3]
|
6878 | };
|
6879 | return pos;
|
6880 | }
|
6881 | var t = time - this.delay;
|
6882 | if (t < 0) t = 0;
|
6883 | if (t > this.duration) t = this.duration - 1;
|
6884 |
|
6885 | var t2 = (t) / this.duration;
|
6886 | if (t2 >= 1) return this.points[this.length - 1];
|
6887 |
|
6888 | var n = Math.floor((this.points.length - 1) * t2);
|
6889 | var t1 = (this.length - 1) * t2 - n;
|
6890 | return bezier(t1, this.points[n], this.controls[n][1], this.controls[n + 1][0], this.points[n + 1]);
|
6891 | };
|
6892 |
|
6893 |
|
6894 |
|
6895 |
|
6896 |
|
6897 |
|
6898 |
|
6899 |
|
6900 |
|
6901 |
|
6902 |
|
6903 |
|
6904 |
|
6905 |
|
6906 |
|
6907 |
|
6908 |
|
6909 |
|
6910 |
|
6911 |
|
6912 |
|
6913 |
|
6914 |
|
6915 |
|
6916 |
|
6917 |
|
6918 |
|
6919 |
|
6920 |
|
6921 |
|
6922 | function bezier(line, options) {
|
6923 |
|
6924 | options = options || {};
|
6925 | if (!isObject(options)) throw new Error('options is invalid');
|
6926 | var resolution = options.resolution || 10000;
|
6927 | var sharpness = options.sharpness || 0.85;
|
6928 |
|
6929 |
|
6930 | if (!line) throw new Error('line is required');
|
6931 | if (!isNumber(resolution)) throw new Error('resolution must be an number');
|
6932 | if (!isNumber(sharpness)) throw new Error('sharpness must be an number');
|
6933 |
|
6934 | var coords = [];
|
6935 | var spline = new Spline({
|
6936 | points: getGeom(line).coordinates.map(function (pt) {
|
6937 | return {x: pt[0], y: pt[1]};
|
6938 | }),
|
6939 | duration: resolution,
|
6940 | sharpness: sharpness
|
6941 | });
|
6942 |
|
6943 | for (var i = 0; i < spline.duration; i += 10) {
|
6944 | var pos = spline.pos(i);
|
6945 | if (Math.floor(i / 100) % 2 === 0) {
|
6946 | coords.push([pos.x, pos.y]);
|
6947 | }
|
6948 | }
|
6949 |
|
6950 | return lineString(coords, line.properties);
|
6951 | }
|
6952 |
|
6953 |
|
6954 |
|
6955 |
|
6956 |
|
6957 |
|
6958 |
|
6959 |
|
6960 |
|
6961 |
|
6962 |
|
6963 |
|
6964 |
|
6965 |
|
6966 |
|
6967 |
|
6968 |
|
6969 |
|
6970 |
|
6971 |
|
6972 |
|
6973 |
|
6974 |
|
6975 |
|
6976 |
|
6977 |
|
6978 |
|
6979 |
|
6980 |
|
6981 |
|
6982 |
|
6983 |
|
6984 |
|
6985 |
|
6986 |
|
6987 |
|
6988 | function tag(points, polygons, field, outField) {
|
6989 |
|
6990 | points = clone(points);
|
6991 | polygons = clone(polygons);
|
6992 | featureEach(points, function (pt) {
|
6993 | if (!pt.properties) pt.properties = {};
|
6994 | featureEach(polygons, function (poly) {
|
6995 | if (pt.properties[outField] === undefined) {
|
6996 | if (booleanPointInPolygon(pt, poly)) pt.properties[outField] = poly.properties[field];
|
6997 | }
|
6998 | });
|
6999 | });
|
7000 | return points;
|
7001 | }
|
7002 |
|
7003 |
|
7004 |
|
7005 |
|
7006 |
|
7007 |
|
7008 |
|
7009 |
|
7010 |
|
7011 |
|
7012 |
|
7013 |
|
7014 |
|
7015 |
|
7016 |
|
7017 |
|
7018 |
|
7019 |
|
7020 |
|
7021 |
|
7022 |
|
7023 | function sample(featurecollection, num) {
|
7024 | if (!featurecollection) throw new Error('featurecollection is required');
|
7025 | if (num === null || num === undefined) throw new Error('num is required');
|
7026 | if (typeof num !== 'number') throw new Error('num must be a number');
|
7027 |
|
7028 | var outFC = featureCollection(getRandomSubarray(featurecollection.features, num));
|
7029 | return outFC;
|
7030 | }
|
7031 |
|
7032 | function getRandomSubarray(arr, size) {
|
7033 | var shuffled = arr.slice(0), i = arr.length, min = i - size, temp, index;
|
7034 | while (i-- > min) {
|
7035 | index = Math.floor((i + 1) * Math.random());
|
7036 | temp = shuffled[index];
|
7037 | shuffled[index] = shuffled[i];
|
7038 | shuffled[i] = temp;
|
7039 | }
|
7040 | return shuffled.slice(min);
|
7041 | }
|
7042 |
|
7043 |
|
7044 |
|
7045 |
|
7046 |
|
7047 |
|
7048 |
|
7049 |
|
7050 |
|
7051 |
|
7052 |
|
7053 |
|
7054 |
|
7055 |
|
7056 |
|
7057 | function bboxPolygon(bbox) {
|
7058 | validateBBox(bbox);
|
7059 |
|
7060 |
|
7061 |
|
7062 | var west = Number(bbox[0]);
|
7063 | var south = Number(bbox[1]);
|
7064 | var east = Number(bbox[2]);
|
7065 | var north = Number(bbox[3]);
|
7066 |
|
7067 | if (bbox.length === 6) throw new Error('@turf/bbox-polygon does not support BBox with 6 positions');
|
7068 |
|
7069 | var lowLeft = [west, south];
|
7070 | var topLeft = [west, north];
|
7071 | var topRight = [east, north];
|
7072 | var lowRight = [east, south];
|
7073 |
|
7074 | return polygon([[
|
7075 | lowLeft,
|
7076 | lowRight,
|
7077 | topRight,
|
7078 | topLeft,
|
7079 | lowLeft
|
7080 | ]]);
|
7081 | }
|
7082 |
|
7083 |
|
7084 |
|
7085 |
|
7086 |
|
7087 |
|
7088 |
|
7089 |
|
7090 |
|
7091 |
|
7092 |
|
7093 |
|
7094 |
|
7095 |
|
7096 |
|
7097 |
|
7098 |
|
7099 |
|
7100 |
|
7101 | function envelope(geojson) {
|
7102 | return bboxPolygon(bbox(geojson));
|
7103 | }
|
7104 |
|
7105 |
|
7106 |
|
7107 |
|
7108 |
|
7109 |
|
7110 |
|
7111 |
|
7112 |
|
7113 |
|
7114 |
|
7115 |
|
7116 |
|
7117 |
|
7118 |
|
7119 | function square(bbox) {
|
7120 | var west = bbox[0];
|
7121 | var south = bbox[1];
|
7122 | var east = bbox[2];
|
7123 | var north = bbox[3];
|
7124 |
|
7125 | var horizontalDistance = distance(bbox.slice(0, 2), [east, south]);
|
7126 | var verticalDistance = distance(bbox.slice(0, 2), [west, north]);
|
7127 | if (horizontalDistance >= verticalDistance) {
|
7128 | var verticalMidpoint = (south + north) / 2;
|
7129 | return [
|
7130 | west,
|
7131 | verticalMidpoint - ((east - west) / 2),
|
7132 | east,
|
7133 | verticalMidpoint + ((east - west) / 2)
|
7134 | ];
|
7135 | } else {
|
7136 | var horizontalMidpoint = (west + east) / 2;
|
7137 | return [
|
7138 | horizontalMidpoint - ((north - south) / 2),
|
7139 | south,
|
7140 | horizontalMidpoint + ((north - south) / 2),
|
7141 | north
|
7142 | ];
|
7143 | }
|
7144 | }
|
7145 |
|
7146 |
|
7147 |
|
7148 |
|
7149 |
|
7150 |
|
7151 |
|
7152 |
|
7153 |
|
7154 |
|
7155 |
|
7156 |
|
7157 |
|
7158 |
|
7159 |
|
7160 |
|
7161 |
|
7162 |
|
7163 |
|
7164 |
|
7165 |
|
7166 |
|
7167 |
|
7168 |
|
7169 |
|
7170 |
|
7171 |
|
7172 | function destination(origin, distance, bearing, options) {
|
7173 |
|
7174 | options = options || {};
|
7175 | if (!isObject(options)) throw new Error('options is invalid');
|
7176 | var units = options.units;
|
7177 | var properties = options.properties;
|
7178 |
|
7179 |
|
7180 | var coordinates1 = getCoord(origin);
|
7181 | var longitude1 = degreesToRadians(coordinates1[0]);
|
7182 | var latitude1 = degreesToRadians(coordinates1[1]);
|
7183 | var bearing_rad = degreesToRadians(bearing);
|
7184 | var radians = lengthToRadians(distance, units);
|
7185 |
|
7186 |
|
7187 | var latitude2 = Math.asin(Math.sin(latitude1) * Math.cos(radians) +
|
7188 | Math.cos(latitude1) * Math.sin(radians) * Math.cos(bearing_rad));
|
7189 | var longitude2 = longitude1 + Math.atan2(Math.sin(bearing_rad) * Math.sin(radians) * Math.cos(latitude1),
|
7190 | Math.cos(radians) - Math.sin(latitude1) * Math.sin(latitude2));
|
7191 | var lng = radiansToDegrees(longitude2);
|
7192 | var lat = radiansToDegrees(latitude2);
|
7193 |
|
7194 | return point([lng, lat], properties);
|
7195 | }
|
7196 |
|
7197 |
|
7198 |
|
7199 |
|
7200 |
|
7201 |
|
7202 |
|
7203 |
|
7204 |
|
7205 |
|
7206 |
|
7207 |
|
7208 |
|
7209 |
|
7210 |
|
7211 |
|
7212 |
|
7213 |
|
7214 |
|
7215 |
|
7216 |
|
7217 | function circle(center, radius, options) {
|
7218 |
|
7219 | options = options || {};
|
7220 | var steps = options.steps || 64;
|
7221 | var properties = options.properties;
|
7222 |
|
7223 |
|
7224 | if (!center) throw new Error('center is required');
|
7225 | if (!radius) throw new Error('radius is required');
|
7226 | if (typeof options !== 'object') throw new Error('options must be an object');
|
7227 | if (typeof steps !== 'number') throw new Error('steps must be a number');
|
7228 |
|
7229 |
|
7230 | steps = steps || 64;
|
7231 | properties = properties || center.properties || {};
|
7232 |
|
7233 | var coordinates = [];
|
7234 | for (var i = 0; i < steps; i++) {
|
7235 | coordinates.push(destination(center, radius, i * -360 / steps, options).geometry.coordinates);
|
7236 | }
|
7237 | coordinates.push(coordinates[0]);
|
7238 |
|
7239 | return polygon([coordinates], properties);
|
7240 | }
|
7241 |
|
7242 |
|
7243 |
|
7244 |
|
7245 |
|
7246 |
|
7247 |
|
7248 |
|
7249 |
|
7250 |
|
7251 |
|
7252 |
|
7253 |
|
7254 |
|
7255 |
|
7256 |
|
7257 |
|
7258 |
|
7259 |
|
7260 |
|
7261 |
|
7262 |
|
7263 |
|
7264 |
|
7265 |
|
7266 |
|
7267 | function bearing(start, end, options) {
|
7268 |
|
7269 | options = options || {};
|
7270 | if (!isObject(options)) throw new Error('options is invalid');
|
7271 | var final = options.final;
|
7272 |
|
7273 |
|
7274 | if (final === true) return calculateFinalBearing(start, end);
|
7275 |
|
7276 | var coordinates1 = getCoord(start);
|
7277 | var coordinates2 = getCoord(end);
|
7278 |
|
7279 | var lon1 = degreesToRadians(coordinates1[0]);
|
7280 | var lon2 = degreesToRadians(coordinates2[0]);
|
7281 | var lat1 = degreesToRadians(coordinates1[1]);
|
7282 | var lat2 = degreesToRadians(coordinates2[1]);
|
7283 | var a = Math.sin(lon2 - lon1) * Math.cos(lat2);
|
7284 | var b = Math.cos(lat1) * Math.sin(lat2) -
|
7285 | Math.sin(lat1) * Math.cos(lat2) * Math.cos(lon2 - lon1);
|
7286 |
|
7287 | return radiansToDegrees(Math.atan2(a, b));
|
7288 | }
|
7289 |
|
7290 |
|
7291 |
|
7292 |
|
7293 |
|
7294 |
|
7295 |
|
7296 |
|
7297 |
|
7298 | function calculateFinalBearing(start, end) {
|
7299 |
|
7300 | var bear = bearing(end, start);
|
7301 | bear = (bear + 180) % 360;
|
7302 | return bear;
|
7303 | }
|
7304 |
|
7305 |
|
7306 |
|
7307 |
|
7308 |
|
7309 |
|
7310 |
|
7311 |
|
7312 |
|
7313 |
|
7314 |
|
7315 |
|
7316 |
|
7317 |
|
7318 |
|
7319 |
|
7320 |
|
7321 |
|
7322 |
|
7323 | function midpoint(point1, point2) {
|
7324 | var dist = distance(point1, point2);
|
7325 | var heading = bearing(point1, point2);
|
7326 | var midpoint = destination(point1, dist / 2, heading);
|
7327 |
|
7328 | return midpoint;
|
7329 | }
|
7330 |
|
7331 |
|
7332 |
|
7333 |
|
7334 |
|
7335 |
|
7336 |
|
7337 |
|
7338 |
|
7339 |
|
7340 |
|
7341 |
|
7342 |
|
7343 |
|
7344 |
|
7345 |
|
7346 |
|
7347 |
|
7348 |
|
7349 |
|
7350 |
|
7351 |
|
7352 |
|
7353 | function center(geojson, options) {
|
7354 |
|
7355 | options = options || {};
|
7356 | if (!isObject(options)) throw new Error('options is invalid');
|
7357 | var properties = options.properties;
|
7358 |
|
7359 |
|
7360 | if (!geojson) throw new Error('geojson is required');
|
7361 |
|
7362 | var ext = bbox(geojson);
|
7363 | var x = (ext[0] + ext[2]) / 2;
|
7364 | var y = (ext[1] + ext[3]) / 2;
|
7365 | return point([x, y], properties);
|
7366 | }
|
7367 |
|
7368 |
|
7369 |
|
7370 |
|
7371 |
|
7372 |
|
7373 |
|
7374 |
|
7375 |
|
7376 |
|
7377 |
|
7378 |
|
7379 |
|
7380 |
|
7381 |
|
7382 |
|
7383 |
|
7384 | function centroid(geojson, properties) {
|
7385 | var xSum = 0;
|
7386 | var ySum = 0;
|
7387 | var len = 0;
|
7388 | coordEach(geojson, function (coord) {
|
7389 | xSum += coord[0];
|
7390 | ySum += coord[1];
|
7391 | len++;
|
7392 | }, true);
|
7393 | return point([xSum / len, ySum / len], properties);
|
7394 | }
|
7395 |
|
7396 |
|
7397 |
|
7398 |
|
7399 |
|
7400 |
|
7401 |
|
7402 |
|
7403 |
|
7404 |
|
7405 |
|
7406 |
|
7407 |
|
7408 |
|
7409 |
|
7410 |
|
7411 | function centerOfMass(geojson, properties) {
|
7412 | switch (getType(geojson)) {
|
7413 | case 'Point':
|
7414 | return geojson;
|
7415 | case 'Polygon':
|
7416 | var coords = [];
|
7417 | coordEach(geojson, function (coord) {
|
7418 | coords.push(coord);
|
7419 | });
|
7420 |
|
7421 |
|
7422 |
|
7423 | var centre = centroid(geojson, properties);
|
7424 | var translation = centre.geometry.coordinates;
|
7425 | var sx = 0;
|
7426 | var sy = 0;
|
7427 | var sArea = 0;
|
7428 | var i, pi, pj, xi, xj, yi, yj, a;
|
7429 |
|
7430 | var neutralizedPoints = coords.map(function (point$$1) {
|
7431 | return [
|
7432 | point$$1[0] - translation[0],
|
7433 | point$$1[1] - translation[1]
|
7434 | ];
|
7435 | });
|
7436 |
|
7437 | for (i = 0; i < coords.length - 1; i++) {
|
7438 |
|
7439 | pi = neutralizedPoints[i];
|
7440 | xi = pi[0];
|
7441 | yi = pi[1];
|
7442 |
|
7443 |
|
7444 | pj = neutralizedPoints[i + 1];
|
7445 | xj = pj[0];
|
7446 | yj = pj[1];
|
7447 |
|
7448 |
|
7449 | a = xi * yj - xj * yi;
|
7450 |
|
7451 |
|
7452 | sArea += a;
|
7453 |
|
7454 |
|
7455 | sx += (xi + xj) * a;
|
7456 | sy += (yi + yj) * a;
|
7457 | }
|
7458 |
|
7459 |
|
7460 | if (sArea === 0) {
|
7461 | return centre;
|
7462 | } else {
|
7463 |
|
7464 | var area = sArea * 0.5;
|
7465 | var areaFactor = 1 / (6 * area);
|
7466 |
|
7467 |
|
7468 | return point([
|
7469 | translation[0] + areaFactor * sx,
|
7470 | translation[1] + areaFactor * sy
|
7471 | ], properties);
|
7472 | }
|
7473 | default:
|
7474 |
|
7475 | var hull = convex(geojson);
|
7476 |
|
7477 | if (hull) return centerOfMass(hull, properties);
|
7478 |
|
7479 | else return centroid(geojson, properties);
|
7480 | }
|
7481 | }
|
7482 |
|
7483 |
|
7484 |
|
7485 |
|
7486 |
|
7487 |
|
7488 |
|
7489 |
|
7490 |
|
7491 |
|
7492 |
|
7493 |
|
7494 |
|
7495 |
|
7496 |
|
7497 |
|
7498 |
|
7499 |
|
7500 |
|
7501 | function combine(fc) {
|
7502 | var groups = {
|
7503 | MultiPoint: {coordinates: [], properties: []},
|
7504 | MultiLineString: {coordinates: [], properties: []},
|
7505 | MultiPolygon: {coordinates: [], properties: []}
|
7506 | };
|
7507 |
|
7508 | var multiMapping = Object.keys(groups).reduce(function (memo, item) {
|
7509 | memo[item.replace('Multi', '')] = item;
|
7510 | return memo;
|
7511 | }, {});
|
7512 |
|
7513 | function addToGroup(feature$$1, key, multi) {
|
7514 | if (!multi) {
|
7515 | groups[key].coordinates.push(feature$$1.geometry.coordinates);
|
7516 | } else {
|
7517 | groups[key].coordinates = groups[key].coordinates.concat(feature$$1.geometry.coordinates);
|
7518 | }
|
7519 | groups[key].properties.push(feature$$1.properties);
|
7520 | }
|
7521 |
|
7522 | featureEach(fc, function (feature$$1) {
|
7523 | if (!feature$$1.geometry) return;
|
7524 | if (groups[feature$$1.geometry.type]) {
|
7525 | addToGroup(feature$$1, feature$$1.geometry.type, true);
|
7526 | } else if (multiMapping[feature$$1.geometry.type]) {
|
7527 | addToGroup(feature$$1, multiMapping[feature$$1.geometry.type], false);
|
7528 | }
|
7529 | });
|
7530 |
|
7531 | return featureCollection(Object.keys(groups)
|
7532 | .filter(function (key) {
|
7533 | return groups[key].coordinates.length;
|
7534 | })
|
7535 | .sort()
|
7536 | .map(function (key) {
|
7537 | var geometry$$1 = { type: key, coordinates: groups[key].coordinates };
|
7538 | var properties = { collectedProperties: groups[key].properties };
|
7539 | return feature(geometry$$1, properties);
|
7540 | }));
|
7541 | }
|
7542 |
|
7543 |
|
7544 |
|
7545 |
|
7546 |
|
7547 |
|
7548 |
|
7549 |
|
7550 |
|
7551 |
|
7552 |
|
7553 |
|
7554 |
|
7555 |
|
7556 |
|
7557 |
|
7558 | function explode(geojson) {
|
7559 | var points$$1 = [];
|
7560 | if (geojson.type === 'FeatureCollection') {
|
7561 | featureEach(geojson, function (feature$$1) {
|
7562 | coordEach(feature$$1, function (coord) {
|
7563 | points$$1.push(point(coord, feature$$1.properties));
|
7564 | });
|
7565 | });
|
7566 | } else {
|
7567 | coordEach(geojson, function (coord) {
|
7568 | points$$1.push(point(coord, geojson.properties));
|
7569 | });
|
7570 | }
|
7571 | return featureCollection(points$$1);
|
7572 | }
|
7573 |
|
7574 | var earcut_1 = earcut;
|
7575 | var default_1$2 = earcut;
|
7576 |
|
7577 | function earcut(data, holeIndices, dim) {
|
7578 |
|
7579 | dim = dim || 2;
|
7580 |
|
7581 | var hasHoles = holeIndices && holeIndices.length,
|
7582 | outerLen = hasHoles ? holeIndices[0] * dim : data.length,
|
7583 | outerNode = linkedList(data, 0, outerLen, dim, true),
|
7584 | triangles = [];
|
7585 |
|
7586 | if (!outerNode) return triangles;
|
7587 |
|
7588 | var minX, minY, maxX, maxY, x, y, invSize;
|
7589 |
|
7590 | if (hasHoles) outerNode = eliminateHoles(data, holeIndices, outerNode, dim);
|
7591 |
|
7592 |
|
7593 | if (data.length > 80 * dim) {
|
7594 | minX = maxX = data[0];
|
7595 | minY = maxY = data[1];
|
7596 |
|
7597 | for (var i = dim; i < outerLen; i += dim) {
|
7598 | x = data[i];
|
7599 | y = data[i + 1];
|
7600 | if (x < minX) minX = x;
|
7601 | if (y < minY) minY = y;
|
7602 | if (x > maxX) maxX = x;
|
7603 | if (y > maxY) maxY = y;
|
7604 | }
|
7605 |
|
7606 |
|
7607 | invSize = Math.max(maxX - minX, maxY - minY);
|
7608 | invSize = invSize !== 0 ? 1 / invSize : 0;
|
7609 | }
|
7610 |
|
7611 | earcutLinked(outerNode, triangles, dim, minX, minY, invSize);
|
7612 |
|
7613 | return triangles;
|
7614 | }
|
7615 |
|
7616 |
|
7617 | function linkedList(data, start, end, dim, clockwise) {
|
7618 | var i, last;
|
7619 |
|
7620 | if (clockwise === (signedArea(data, start, end, dim) > 0)) {
|
7621 | for (i = start; i < end; i += dim) last = insertNode$1(i, data[i], data[i + 1], last);
|
7622 | } else {
|
7623 | for (i = end - dim; i >= start; i -= dim) last = insertNode$1(i, data[i], data[i + 1], last);
|
7624 | }
|
7625 |
|
7626 | if (last && equals$1(last, last.next)) {
|
7627 | removeNode(last);
|
7628 | last = last.next;
|
7629 | }
|
7630 |
|
7631 | return last;
|
7632 | }
|
7633 |
|
7634 |
|
7635 | function filterPoints(start, end) {
|
7636 | if (!start) return start;
|
7637 | if (!end) end = start;
|
7638 |
|
7639 | var p = start,
|
7640 | again;
|
7641 | do {
|
7642 | again = false;
|
7643 |
|
7644 | if (!p.steiner && (equals$1(p, p.next) || area(p.prev, p, p.next) === 0)) {
|
7645 | removeNode(p);
|
7646 | p = end = p.prev;
|
7647 | if (p === p.next) break;
|
7648 | again = true;
|
7649 |
|
7650 | } else {
|
7651 | p = p.next;
|
7652 | }
|
7653 | } while (again || p !== end);
|
7654 |
|
7655 | return end;
|
7656 | }
|
7657 |
|
7658 |
|
7659 | function earcutLinked(ear, triangles, dim, minX, minY, invSize, pass) {
|
7660 | if (!ear) return;
|
7661 |
|
7662 |
|
7663 | if (!pass && invSize) indexCurve(ear, minX, minY, invSize);
|
7664 |
|
7665 | var stop = ear,
|
7666 | prev, next;
|
7667 |
|
7668 |
|
7669 | while (ear.prev !== ear.next) {
|
7670 | prev = ear.prev;
|
7671 | next = ear.next;
|
7672 |
|
7673 | if (invSize ? isEarHashed(ear, minX, minY, invSize) : isEar(ear)) {
|
7674 |
|
7675 | triangles.push(prev.i / dim);
|
7676 | triangles.push(ear.i / dim);
|
7677 | triangles.push(next.i / dim);
|
7678 |
|
7679 | removeNode(ear);
|
7680 |
|
7681 |
|
7682 | ear = next.next;
|
7683 | stop = next.next;
|
7684 |
|
7685 | continue;
|
7686 | }
|
7687 |
|
7688 | ear = next;
|
7689 |
|
7690 |
|
7691 | if (ear === stop) {
|
7692 |
|
7693 | if (!pass) {
|
7694 | earcutLinked(filterPoints(ear), triangles, dim, minX, minY, invSize, 1);
|
7695 |
|
7696 |
|
7697 | } else if (pass === 1) {
|
7698 | ear = cureLocalIntersections(ear, triangles, dim);
|
7699 | earcutLinked(ear, triangles, dim, minX, minY, invSize, 2);
|
7700 |
|
7701 |
|
7702 | } else if (pass === 2) {
|
7703 | splitEarcut(ear, triangles, dim, minX, minY, invSize);
|
7704 | }
|
7705 |
|
7706 | break;
|
7707 | }
|
7708 | }
|
7709 | }
|
7710 |
|
7711 |
|
7712 | function isEar(ear) {
|
7713 | var a = ear.prev,
|
7714 | b = ear,
|
7715 | c = ear.next;
|
7716 |
|
7717 | if (area(a, b, c) >= 0) return false;
|
7718 |
|
7719 |
|
7720 | var p = ear.next.next;
|
7721 |
|
7722 | while (p !== ear.prev) {
|
7723 | if (pointInTriangle(a.x, a.y, b.x, b.y, c.x, c.y, p.x, p.y) &&
|
7724 | area(p.prev, p, p.next) >= 0) return false;
|
7725 | p = p.next;
|
7726 | }
|
7727 |
|
7728 | return true;
|
7729 | }
|
7730 |
|
7731 | function isEarHashed(ear, minX, minY, invSize) {
|
7732 | var a = ear.prev,
|
7733 | b = ear,
|
7734 | c = ear.next;
|
7735 |
|
7736 | if (area(a, b, c) >= 0) return false;
|
7737 |
|
7738 |
|
7739 | var minTX = a.x < b.x ? (a.x < c.x ? a.x : c.x) : (b.x < c.x ? b.x : c.x),
|
7740 | minTY = a.y < b.y ? (a.y < c.y ? a.y : c.y) : (b.y < c.y ? b.y : c.y),
|
7741 | maxTX = a.x > b.x ? (a.x > c.x ? a.x : c.x) : (b.x > c.x ? b.x : c.x),
|
7742 | maxTY = a.y > b.y ? (a.y > c.y ? a.y : c.y) : (b.y > c.y ? b.y : c.y);
|
7743 |
|
7744 |
|
7745 | var minZ = zOrder(minTX, minTY, minX, minY, invSize),
|
7746 | maxZ = zOrder(maxTX, maxTY, minX, minY, invSize);
|
7747 |
|
7748 |
|
7749 | var p = ear.nextZ;
|
7750 |
|
7751 | while (p && p.z <= maxZ) {
|
7752 | if (p !== ear.prev && p !== ear.next &&
|
7753 | pointInTriangle(a.x, a.y, b.x, b.y, c.x, c.y, p.x, p.y) &&
|
7754 | area(p.prev, p, p.next) >= 0) return false;
|
7755 | p = p.nextZ;
|
7756 | }
|
7757 |
|
7758 |
|
7759 | p = ear.prevZ;
|
7760 |
|
7761 | while (p && p.z >= minZ) {
|
7762 | if (p !== ear.prev && p !== ear.next &&
|
7763 | pointInTriangle(a.x, a.y, b.x, b.y, c.x, c.y, p.x, p.y) &&
|
7764 | area(p.prev, p, p.next) >= 0) return false;
|
7765 | p = p.prevZ;
|
7766 | }
|
7767 |
|
7768 | return true;
|
7769 | }
|
7770 |
|
7771 |
|
7772 | function cureLocalIntersections(start, triangles, dim) {
|
7773 | var p = start;
|
7774 | do {
|
7775 | var a = p.prev,
|
7776 | b = p.next.next;
|
7777 |
|
7778 | if (!equals$1(a, b) && intersects$2(a, p, p.next, b) && locallyInside(a, b) && locallyInside(b, a)) {
|
7779 |
|
7780 | triangles.push(a.i / dim);
|
7781 | triangles.push(p.i / dim);
|
7782 | triangles.push(b.i / dim);
|
7783 |
|
7784 |
|
7785 | removeNode(p);
|
7786 | removeNode(p.next);
|
7787 |
|
7788 | p = start = b;
|
7789 | }
|
7790 | p = p.next;
|
7791 | } while (p !== start);
|
7792 |
|
7793 | return p;
|
7794 | }
|
7795 |
|
7796 |
|
7797 | function splitEarcut(start, triangles, dim, minX, minY, invSize) {
|
7798 |
|
7799 | var a = start;
|
7800 | do {
|
7801 | var b = a.next.next;
|
7802 | while (b !== a.prev) {
|
7803 | if (a.i !== b.i && isValidDiagonal(a, b)) {
|
7804 |
|
7805 | var c = splitPolygon(a, b);
|
7806 |
|
7807 |
|
7808 | a = filterPoints(a, a.next);
|
7809 | c = filterPoints(c, c.next);
|
7810 |
|
7811 |
|
7812 | earcutLinked(a, triangles, dim, minX, minY, invSize);
|
7813 | earcutLinked(c, triangles, dim, minX, minY, invSize);
|
7814 | return;
|
7815 | }
|
7816 | b = b.next;
|
7817 | }
|
7818 | a = a.next;
|
7819 | } while (a !== start);
|
7820 | }
|
7821 |
|
7822 |
|
7823 | function eliminateHoles(data, holeIndices, outerNode, dim) {
|
7824 | var queue = [],
|
7825 | i, len, start, end, list;
|
7826 |
|
7827 | for (i = 0, len = holeIndices.length; i < len; i++) {
|
7828 | start = holeIndices[i] * dim;
|
7829 | end = i < len - 1 ? holeIndices[i + 1] * dim : data.length;
|
7830 | list = linkedList(data, start, end, dim, false);
|
7831 | if (list === list.next) list.steiner = true;
|
7832 | queue.push(getLeftmost(list));
|
7833 | }
|
7834 |
|
7835 | queue.sort(compareX);
|
7836 |
|
7837 |
|
7838 | for (i = 0; i < queue.length; i++) {
|
7839 | eliminateHole(queue[i], outerNode);
|
7840 | outerNode = filterPoints(outerNode, outerNode.next);
|
7841 | }
|
7842 |
|
7843 | return outerNode;
|
7844 | }
|
7845 |
|
7846 | function compareX(a, b) {
|
7847 | return a.x - b.x;
|
7848 | }
|
7849 |
|
7850 |
|
7851 | function eliminateHole(hole, outerNode) {
|
7852 | outerNode = findHoleBridge(hole, outerNode);
|
7853 | if (outerNode) {
|
7854 | var b = splitPolygon(outerNode, hole);
|
7855 | filterPoints(b, b.next);
|
7856 | }
|
7857 | }
|
7858 |
|
7859 |
|
7860 | function findHoleBridge(hole, outerNode) {
|
7861 | var p = outerNode,
|
7862 | hx = hole.x,
|
7863 | hy = hole.y,
|
7864 | qx = -Infinity,
|
7865 | m;
|
7866 |
|
7867 |
|
7868 |
|
7869 | do {
|
7870 | if (hy <= p.y && hy >= p.next.y && p.next.y !== p.y) {
|
7871 | var x = p.x + (hy - p.y) * (p.next.x - p.x) / (p.next.y - p.y);
|
7872 | if (x <= hx && x > qx) {
|
7873 | qx = x;
|
7874 | if (x === hx) {
|
7875 | if (hy === p.y) return p;
|
7876 | if (hy === p.next.y) return p.next;
|
7877 | }
|
7878 | m = p.x < p.next.x ? p : p.next;
|
7879 | }
|
7880 | }
|
7881 | p = p.next;
|
7882 | } while (p !== outerNode);
|
7883 |
|
7884 | if (!m) return null;
|
7885 |
|
7886 | if (hx === qx) return m.prev;
|
7887 |
|
7888 |
|
7889 |
|
7890 |
|
7891 |
|
7892 | var stop = m,
|
7893 | mx = m.x,
|
7894 | my = m.y,
|
7895 | tanMin = Infinity,
|
7896 | tan;
|
7897 |
|
7898 | p = m.next;
|
7899 |
|
7900 | while (p !== stop) {
|
7901 | if (hx >= p.x && p.x >= mx && hx !== p.x &&
|
7902 | pointInTriangle(hy < my ? hx : qx, hy, mx, my, hy < my ? qx : hx, hy, p.x, p.y)) {
|
7903 |
|
7904 | tan = Math.abs(hy - p.y) / (hx - p.x);
|
7905 |
|
7906 | if ((tan < tanMin || (tan === tanMin && p.x > m.x)) && locallyInside(p, hole)) {
|
7907 | m = p;
|
7908 | tanMin = tan;
|
7909 | }
|
7910 | }
|
7911 |
|
7912 | p = p.next;
|
7913 | }
|
7914 |
|
7915 | return m;
|
7916 | }
|
7917 |
|
7918 |
|
7919 | function indexCurve(start, minX, minY, invSize) {
|
7920 | var p = start;
|
7921 | do {
|
7922 | if (p.z === null) p.z = zOrder(p.x, p.y, minX, minY, invSize);
|
7923 | p.prevZ = p.prev;
|
7924 | p.nextZ = p.next;
|
7925 | p = p.next;
|
7926 | } while (p !== start);
|
7927 |
|
7928 | p.prevZ.nextZ = null;
|
7929 | p.prevZ = null;
|
7930 |
|
7931 | sortLinked(p);
|
7932 | }
|
7933 |
|
7934 |
|
7935 |
|
7936 | function sortLinked(list) {
|
7937 | var i, p, q, e, tail, numMerges, pSize, qSize,
|
7938 | inSize = 1;
|
7939 |
|
7940 | do {
|
7941 | p = list;
|
7942 | list = null;
|
7943 | tail = null;
|
7944 | numMerges = 0;
|
7945 |
|
7946 | while (p) {
|
7947 | numMerges++;
|
7948 | q = p;
|
7949 | pSize = 0;
|
7950 | for (i = 0; i < inSize; i++) {
|
7951 | pSize++;
|
7952 | q = q.nextZ;
|
7953 | if (!q) break;
|
7954 | }
|
7955 | qSize = inSize;
|
7956 |
|
7957 | while (pSize > 0 || (qSize > 0 && q)) {
|
7958 |
|
7959 | if (pSize !== 0 && (qSize === 0 || !q || p.z <= q.z)) {
|
7960 | e = p;
|
7961 | p = p.nextZ;
|
7962 | pSize--;
|
7963 | } else {
|
7964 | e = q;
|
7965 | q = q.nextZ;
|
7966 | qSize--;
|
7967 | }
|
7968 |
|
7969 | if (tail) tail.nextZ = e;
|
7970 | else list = e;
|
7971 |
|
7972 | e.prevZ = tail;
|
7973 | tail = e;
|
7974 | }
|
7975 |
|
7976 | p = q;
|
7977 | }
|
7978 |
|
7979 | tail.nextZ = null;
|
7980 | inSize *= 2;
|
7981 |
|
7982 | } while (numMerges > 1);
|
7983 |
|
7984 | return list;
|
7985 | }
|
7986 |
|
7987 |
|
7988 | function zOrder(x, y, minX, minY, invSize) {
|
7989 |
|
7990 | x = 32767 * (x - minX) * invSize;
|
7991 | y = 32767 * (y - minY) * invSize;
|
7992 |
|
7993 | x = (x | (x << 8)) & 0x00FF00FF;
|
7994 | x = (x | (x << 4)) & 0x0F0F0F0F;
|
7995 | x = (x | (x << 2)) & 0x33333333;
|
7996 | x = (x | (x << 1)) & 0x55555555;
|
7997 |
|
7998 | y = (y | (y << 8)) & 0x00FF00FF;
|
7999 | y = (y | (y << 4)) & 0x0F0F0F0F;
|
8000 | y = (y | (y << 2)) & 0x33333333;
|
8001 | y = (y | (y << 1)) & 0x55555555;
|
8002 |
|
8003 | return x | (y << 1);
|
8004 | }
|
8005 |
|
8006 |
|
8007 | function getLeftmost(start) {
|
8008 | var p = start,
|
8009 | leftmost = start;
|
8010 | do {
|
8011 | if (p.x < leftmost.x) leftmost = p;
|
8012 | p = p.next;
|
8013 | } while (p !== start);
|
8014 |
|
8015 | return leftmost;
|
8016 | }
|
8017 |
|
8018 |
|
8019 | function pointInTriangle(ax, ay, bx, by, cx, cy, px, py) {
|
8020 | return (cx - px) * (ay - py) - (ax - px) * (cy - py) >= 0 &&
|
8021 | (ax - px) * (by - py) - (bx - px) * (ay - py) >= 0 &&
|
8022 | (bx - px) * (cy - py) - (cx - px) * (by - py) >= 0;
|
8023 | }
|
8024 |
|
8025 |
|
8026 | function isValidDiagonal(a, b) {
|
8027 | return a.next.i !== b.i && a.prev.i !== b.i && !intersectsPolygon(a, b) &&
|
8028 | locallyInside(a, b) && locallyInside(b, a) && middleInside(a, b);
|
8029 | }
|
8030 |
|
8031 |
|
8032 | function area(p, q, r) {
|
8033 | return (q.y - p.y) * (r.x - q.x) - (q.x - p.x) * (r.y - q.y);
|
8034 | }
|
8035 |
|
8036 |
|
8037 | function equals$1(p1, p2) {
|
8038 | return p1.x === p2.x && p1.y === p2.y;
|
8039 | }
|
8040 |
|
8041 |
|
8042 | function intersects$2(p1, q1, p2, q2) {
|
8043 | if ((equals$1(p1, q1) && equals$1(p2, q2)) ||
|
8044 | (equals$1(p1, q2) && equals$1(p2, q1))) return true;
|
8045 | return area(p1, q1, p2) > 0 !== area(p1, q1, q2) > 0 &&
|
8046 | area(p2, q2, p1) > 0 !== area(p2, q2, q1) > 0;
|
8047 | }
|
8048 |
|
8049 |
|
8050 | function intersectsPolygon(a, b) {
|
8051 | var p = a;
|
8052 | do {
|
8053 | if (p.i !== a.i && p.next.i !== a.i && p.i !== b.i && p.next.i !== b.i &&
|
8054 | intersects$2(p, p.next, a, b)) return true;
|
8055 | p = p.next;
|
8056 | } while (p !== a);
|
8057 |
|
8058 | return false;
|
8059 | }
|
8060 |
|
8061 |
|
8062 | function locallyInside(a, b) {
|
8063 | return area(a.prev, a, a.next) < 0 ?
|
8064 | area(a, b, a.next) >= 0 && area(a, a.prev, b) >= 0 :
|
8065 | area(a, b, a.prev) < 0 || area(a, a.next, b) < 0;
|
8066 | }
|
8067 |
|
8068 |
|
8069 | function middleInside(a, b) {
|
8070 | var p = a,
|
8071 | inside = false,
|
8072 | px = (a.x + b.x) / 2,
|
8073 | py = (a.y + b.y) / 2;
|
8074 | do {
|
8075 | if (((p.y > py) !== (p.next.y > py)) && p.next.y !== p.y &&
|
8076 | (px < (p.next.x - p.x) * (py - p.y) / (p.next.y - p.y) + p.x))
|
8077 | inside = !inside;
|
8078 | p = p.next;
|
8079 | } while (p !== a);
|
8080 |
|
8081 | return inside;
|
8082 | }
|
8083 |
|
8084 |
|
8085 |
|
8086 | function splitPolygon(a, b) {
|
8087 | var a2 = new Node(a.i, a.x, a.y),
|
8088 | b2 = new Node(b.i, b.x, b.y),
|
8089 | an = a.next,
|
8090 | bp = b.prev;
|
8091 |
|
8092 | a.next = b;
|
8093 | b.prev = a;
|
8094 |
|
8095 | a2.next = an;
|
8096 | an.prev = a2;
|
8097 |
|
8098 | b2.next = a2;
|
8099 | a2.prev = b2;
|
8100 |
|
8101 | bp.next = b2;
|
8102 | b2.prev = bp;
|
8103 |
|
8104 | return b2;
|
8105 | }
|
8106 |
|
8107 |
|
8108 | function insertNode$1(i, x, y, last) {
|
8109 | var p = new Node(i, x, y);
|
8110 |
|
8111 | if (!last) {
|
8112 | p.prev = p;
|
8113 | p.next = p;
|
8114 |
|
8115 | } else {
|
8116 | p.next = last.next;
|
8117 | p.prev = last;
|
8118 | last.next.prev = p;
|
8119 | last.next = p;
|
8120 | }
|
8121 | return p;
|
8122 | }
|
8123 |
|
8124 | function removeNode(p) {
|
8125 | p.next.prev = p.prev;
|
8126 | p.prev.next = p.next;
|
8127 |
|
8128 | if (p.prevZ) p.prevZ.nextZ = p.nextZ;
|
8129 | if (p.nextZ) p.nextZ.prevZ = p.prevZ;
|
8130 | }
|
8131 |
|
8132 | function Node(i, x, y) {
|
8133 |
|
8134 | this.i = i;
|
8135 |
|
8136 |
|
8137 | this.x = x;
|
8138 | this.y = y;
|
8139 |
|
8140 |
|
8141 | this.prev = null;
|
8142 | this.next = null;
|
8143 |
|
8144 |
|
8145 | this.z = null;
|
8146 |
|
8147 |
|
8148 | this.prevZ = null;
|
8149 | this.nextZ = null;
|
8150 |
|
8151 |
|
8152 | this.steiner = false;
|
8153 | }
|
8154 |
|
8155 |
|
8156 |
|
8157 | earcut.deviation = function (data, holeIndices, dim, triangles) {
|
8158 | var hasHoles = holeIndices && holeIndices.length;
|
8159 | var outerLen = hasHoles ? holeIndices[0] * dim : data.length;
|
8160 |
|
8161 | var polygonArea = Math.abs(signedArea(data, 0, outerLen, dim));
|
8162 | if (hasHoles) {
|
8163 | for (var i = 0, len = holeIndices.length; i < len; i++) {
|
8164 | var start = holeIndices[i] * dim;
|
8165 | var end = i < len - 1 ? holeIndices[i + 1] * dim : data.length;
|
8166 | polygonArea -= Math.abs(signedArea(data, start, end, dim));
|
8167 | }
|
8168 | }
|
8169 |
|
8170 | var trianglesArea = 0;
|
8171 | for (i = 0; i < triangles.length; i += 3) {
|
8172 | var a = triangles[i] * dim;
|
8173 | var b = triangles[i + 1] * dim;
|
8174 | var c = triangles[i + 2] * dim;
|
8175 | trianglesArea += Math.abs(
|
8176 | (data[a] - data[c]) * (data[b + 1] - data[a + 1]) -
|
8177 | (data[a] - data[b]) * (data[c + 1] - data[a + 1]));
|
8178 | }
|
8179 |
|
8180 | return polygonArea === 0 && trianglesArea === 0 ? 0 :
|
8181 | Math.abs((trianglesArea - polygonArea) / polygonArea);
|
8182 | };
|
8183 |
|
8184 | function signedArea(data, start, end, dim) {
|
8185 | var sum = 0;
|
8186 | for (var i = start, j = end - dim; i < end; i += dim) {
|
8187 | sum += (data[j] - data[i]) * (data[i + 1] + data[j + 1]);
|
8188 | j = i;
|
8189 | }
|
8190 | return sum;
|
8191 | }
|
8192 |
|
8193 |
|
8194 | earcut.flatten = function (data) {
|
8195 | var dim = data[0][0].length,
|
8196 | result = {vertices: [], holes: [], dimensions: dim},
|
8197 | holeIndex = 0;
|
8198 |
|
8199 | for (var i = 0; i < data.length; i++) {
|
8200 | for (var j = 0; j < data[i].length; j++) {
|
8201 | for (var d = 0; d < dim; d++) result.vertices.push(data[i][j][d]);
|
8202 | }
|
8203 | if (i > 0) {
|
8204 | holeIndex += data[i - 1].length;
|
8205 | result.holes.push(holeIndex);
|
8206 | }
|
8207 | }
|
8208 | return result;
|
8209 | };
|
8210 |
|
8211 | earcut_1.default = default_1$2;
|
8212 |
|
8213 |
|
8214 |
|
8215 |
|
8216 |
|
8217 |
|
8218 |
|
8219 |
|
8220 |
|
8221 |
|
8222 |
|
8223 |
|
8224 |
|
8225 |
|
8226 |
|
8227 | function tesselate(poly) {
|
8228 | if (!poly.geometry || (poly.geometry.type !== 'Polygon' && poly.geometry.type !== 'MultiPolygon')) {
|
8229 | throw new Error('input must be a Polygon or MultiPolygon');
|
8230 | }
|
8231 |
|
8232 | var fc = {type: 'FeatureCollection', features: []};
|
8233 |
|
8234 | if (poly.geometry.type === 'Polygon') {
|
8235 | fc.features = processPolygon(poly.geometry.coordinates);
|
8236 | } else {
|
8237 | poly.geometry.coordinates.forEach(function (coordinates) {
|
8238 | fc.features = fc.features.concat(processPolygon(coordinates));
|
8239 | });
|
8240 | }
|
8241 |
|
8242 | return fc;
|
8243 | }
|
8244 |
|
8245 | function processPolygon(coordinates) {
|
8246 | var data = flattenCoords(coordinates);
|
8247 | var dim = 2;
|
8248 | var result = earcut_1(data.vertices, data.holes, dim);
|
8249 |
|
8250 | var features = [];
|
8251 | var vertices = [];
|
8252 |
|
8253 | result.forEach(function (vert, i) {
|
8254 | var index = result[i];
|
8255 | vertices.push([data.vertices[index * dim], data.vertices[index * dim + 1]]);
|
8256 | });
|
8257 |
|
8258 | for (var i = 0; i < vertices.length; i += 3) {
|
8259 | var coords = vertices.slice(i, i + 3);
|
8260 | coords.push(vertices[i]);
|
8261 | features.push(polygon([coords]));
|
8262 | }
|
8263 |
|
8264 | return features;
|
8265 | }
|
8266 |
|
8267 | function flattenCoords(data) {
|
8268 | var dim = data[0][0].length,
|
8269 | result = {vertices: [], holes: [], dimensions: dim},
|
8270 | holeIndex = 0;
|
8271 |
|
8272 | for (var i = 0; i < data.length; i++) {
|
8273 | for (var j = 0; j < data[i].length; j++) {
|
8274 | for (var d = 0; d < dim; d++) result.vertices.push(data[i][j][d]);
|
8275 | }
|
8276 | if (i > 0) {
|
8277 | holeIndex += data[i - 1].length;
|
8278 | result.holes.push(holeIndex);
|
8279 | }
|
8280 | }
|
8281 |
|
8282 | return result;
|
8283 | }
|
8284 |
|
8285 |
|
8286 |
|
8287 |
|
8288 |
|
8289 |
|
8290 |
|
8291 |
|
8292 |
|
8293 |
|
8294 |
|
8295 |
|
8296 |
|
8297 |
|
8298 |
|
8299 |
|
8300 |
|
8301 |
|
8302 |
|
8303 |
|
8304 |
|
8305 |
|
8306 |
|
8307 |
|
8308 |
|
8309 | function nearestPoint(targetPoint, points) {
|
8310 |
|
8311 | if (!targetPoint) throw new Error('targetPoint is required');
|
8312 | if (!points) throw new Error('points is required');
|
8313 |
|
8314 | var nearest;
|
8315 | var minDist = Infinity;
|
8316 | featureEach(points, function (pt, featureIndex) {
|
8317 | var distanceToPoint = distance(targetPoint, pt);
|
8318 | if (distanceToPoint < minDist) {
|
8319 | nearest = clone(pt);
|
8320 | nearest.properties.featureIndex = featureIndex;
|
8321 | nearest.properties.distanceToPoint = distanceToPoint;
|
8322 | minDist = distanceToPoint;
|
8323 | }
|
8324 |
|
8325 | });
|
8326 | return nearest;
|
8327 | }
|
8328 |
|
8329 | function quickselect$3(arr, k, left, right, compare) {
|
8330 | quickselectStep(arr, k, left || 0, right || (arr.length - 1), compare || defaultCompare$2);
|
8331 | }
|
8332 |
|
8333 | function quickselectStep(arr, k, left, right, compare) {
|
8334 |
|
8335 | while (right > left) {
|
8336 | if (right - left > 600) {
|
8337 | var n = right - left + 1;
|
8338 | var m = k - left + 1;
|
8339 | var z = Math.log(n);
|
8340 | var s = 0.5 * Math.exp(2 * z / 3);
|
8341 | var sd = 0.5 * Math.sqrt(z * s * (n - s) / n) * (m - n / 2 < 0 ? -1 : 1);
|
8342 | var newLeft = Math.max(left, Math.floor(k - m * s / n + sd));
|
8343 | var newRight = Math.min(right, Math.floor(k + (n - m) * s / n + sd));
|
8344 | quickselectStep(arr, k, newLeft, newRight, compare);
|
8345 | }
|
8346 |
|
8347 | var t = arr[k];
|
8348 | var i = left;
|
8349 | var j = right;
|
8350 |
|
8351 | swap$1(arr, left, k);
|
8352 | if (compare(arr[right], t) > 0) swap$1(arr, left, right);
|
8353 |
|
8354 | while (i < j) {
|
8355 | swap$1(arr, i, j);
|
8356 | i++;
|
8357 | j--;
|
8358 | while (compare(arr[i], t) < 0) i++;
|
8359 | while (compare(arr[j], t) > 0) j--;
|
8360 | }
|
8361 |
|
8362 | if (compare(arr[left], t) === 0) swap$1(arr, left, j);
|
8363 | else {
|
8364 | j++;
|
8365 | swap$1(arr, j, right);
|
8366 | }
|
8367 |
|
8368 | if (j <= k) left = j + 1;
|
8369 | if (k <= j) right = j - 1;
|
8370 | }
|
8371 | }
|
8372 |
|
8373 | function swap$1(arr, i, j) {
|
8374 | var tmp = arr[i];
|
8375 | arr[i] = arr[j];
|
8376 | arr[j] = tmp;
|
8377 | }
|
8378 |
|
8379 | function defaultCompare$2(a, b) {
|
8380 | return a < b ? -1 : a > b ? 1 : 0;
|
8381 | }
|
8382 |
|
8383 | function rbush$4(maxEntries, format) {
|
8384 | if (!(this instanceof rbush$4)) return new rbush$4(maxEntries, format);
|
8385 |
|
8386 |
|
8387 | this._maxEntries = Math.max(4, maxEntries || 9);
|
8388 | this._minEntries = Math.max(2, Math.ceil(this._maxEntries * 0.4));
|
8389 |
|
8390 | if (format) {
|
8391 | this._initFormat(format);
|
8392 | }
|
8393 |
|
8394 | this.clear();
|
8395 | }
|
8396 |
|
8397 | rbush$4.prototype = {
|
8398 |
|
8399 | all: function () {
|
8400 | return this._all(this.data, []);
|
8401 | },
|
8402 |
|
8403 | search: function (bbox) {
|
8404 |
|
8405 | var node = this.data,
|
8406 | result = [],
|
8407 | toBBox = this.toBBox;
|
8408 |
|
8409 | if (!intersects$4(bbox, node)) return result;
|
8410 |
|
8411 | var nodesToSearch = [],
|
8412 | i, len, child, childBBox;
|
8413 |
|
8414 | while (node) {
|
8415 | for (i = 0, len = node.children.length; i < len; i++) {
|
8416 |
|
8417 | child = node.children[i];
|
8418 | childBBox = node.leaf ? toBBox(child) : child;
|
8419 |
|
8420 | if (intersects$4(bbox, childBBox)) {
|
8421 | if (node.leaf) result.push(child);
|
8422 | else if (contains$1(bbox, childBBox)) this._all(child, result);
|
8423 | else nodesToSearch.push(child);
|
8424 | }
|
8425 | }
|
8426 | node = nodesToSearch.pop();
|
8427 | }
|
8428 |
|
8429 | return result;
|
8430 | },
|
8431 |
|
8432 | collides: function (bbox) {
|
8433 |
|
8434 | var node = this.data,
|
8435 | toBBox = this.toBBox;
|
8436 |
|
8437 | if (!intersects$4(bbox, node)) return false;
|
8438 |
|
8439 | var nodesToSearch = [],
|
8440 | i, len, child, childBBox;
|
8441 |
|
8442 | while (node) {
|
8443 | for (i = 0, len = node.children.length; i < len; i++) {
|
8444 |
|
8445 | child = node.children[i];
|
8446 | childBBox = node.leaf ? toBBox(child) : child;
|
8447 |
|
8448 | if (intersects$4(bbox, childBBox)) {
|
8449 | if (node.leaf || contains$1(bbox, childBBox)) return true;
|
8450 | nodesToSearch.push(child);
|
8451 | }
|
8452 | }
|
8453 | node = nodesToSearch.pop();
|
8454 | }
|
8455 |
|
8456 | return false;
|
8457 | },
|
8458 |
|
8459 | load: function (data) {
|
8460 | if (!(data && data.length)) return this;
|
8461 |
|
8462 | if (data.length < this._minEntries) {
|
8463 | for (var i = 0, len = data.length; i < len; i++) {
|
8464 | this.insert(data[i]);
|
8465 | }
|
8466 | return this;
|
8467 | }
|
8468 |
|
8469 |
|
8470 | var node = this._build(data.slice(), 0, data.length - 1, 0);
|
8471 |
|
8472 | if (!this.data.children.length) {
|
8473 |
|
8474 | this.data = node;
|
8475 |
|
8476 | } else if (this.data.height === node.height) {
|
8477 |
|
8478 | this._splitRoot(this.data, node);
|
8479 |
|
8480 | } else {
|
8481 | if (this.data.height < node.height) {
|
8482 |
|
8483 | var tmpNode = this.data;
|
8484 | this.data = node;
|
8485 | node = tmpNode;
|
8486 | }
|
8487 |
|
8488 |
|
8489 | this._insert(node, this.data.height - node.height - 1, true);
|
8490 | }
|
8491 |
|
8492 | return this;
|
8493 | },
|
8494 |
|
8495 | insert: function (item) {
|
8496 | if (item) this._insert(item, this.data.height - 1);
|
8497 | return this;
|
8498 | },
|
8499 |
|
8500 | clear: function () {
|
8501 | this.data = createNode$1([]);
|
8502 | return this;
|
8503 | },
|
8504 |
|
8505 | remove: function (item, equalsFn) {
|
8506 | if (!item) return this;
|
8507 |
|
8508 | var node = this.data,
|
8509 | bbox = this.toBBox(item),
|
8510 | path = [],
|
8511 | indexes = [],
|
8512 | i, parent, index, goingUp;
|
8513 |
|
8514 |
|
8515 | while (node || path.length) {
|
8516 |
|
8517 | if (!node) {
|
8518 | node = path.pop();
|
8519 | parent = path[path.length - 1];
|
8520 | i = indexes.pop();
|
8521 | goingUp = true;
|
8522 | }
|
8523 |
|
8524 | if (node.leaf) {
|
8525 | index = findItem$1(item, node.children, equalsFn);
|
8526 |
|
8527 | if (index !== -1) {
|
8528 |
|
8529 | node.children.splice(index, 1);
|
8530 | path.push(node);
|
8531 | this._condense(path);
|
8532 | return this;
|
8533 | }
|
8534 | }
|
8535 |
|
8536 | if (!goingUp && !node.leaf && contains$1(node, bbox)) {
|
8537 | path.push(node);
|
8538 | indexes.push(i);
|
8539 | i = 0;
|
8540 | parent = node;
|
8541 | node = node.children[0];
|
8542 |
|
8543 | } else if (parent) {
|
8544 | i++;
|
8545 | node = parent.children[i];
|
8546 | goingUp = false;
|
8547 |
|
8548 | } else node = null;
|
8549 | }
|
8550 |
|
8551 | return this;
|
8552 | },
|
8553 |
|
8554 | toBBox: function (item) { return item; },
|
8555 |
|
8556 | compareMinX: compareNodeMinX$1,
|
8557 | compareMinY: compareNodeMinY$1,
|
8558 |
|
8559 | toJSON: function () { return this.data; },
|
8560 |
|
8561 | fromJSON: function (data) {
|
8562 | this.data = data;
|
8563 | return this;
|
8564 | },
|
8565 |
|
8566 | _all: function (node, result) {
|
8567 | var nodesToSearch = [];
|
8568 | while (node) {
|
8569 | if (node.leaf) result.push.apply(result, node.children);
|
8570 | else nodesToSearch.push.apply(nodesToSearch, node.children);
|
8571 |
|
8572 | node = nodesToSearch.pop();
|
8573 | }
|
8574 | return result;
|
8575 | },
|
8576 |
|
8577 | _build: function (items, left, right, height) {
|
8578 |
|
8579 | var N = right - left + 1,
|
8580 | M = this._maxEntries,
|
8581 | node;
|
8582 |
|
8583 | if (N <= M) {
|
8584 |
|
8585 | node = createNode$1(items.slice(left, right + 1));
|
8586 | calcBBox$1(node, this.toBBox);
|
8587 | return node;
|
8588 | }
|
8589 |
|
8590 | if (!height) {
|
8591 |
|
8592 | height = Math.ceil(Math.log(N) / Math.log(M));
|
8593 |
|
8594 |
|
8595 | M = Math.ceil(N / Math.pow(M, height - 1));
|
8596 | }
|
8597 |
|
8598 | node = createNode$1([]);
|
8599 | node.leaf = false;
|
8600 | node.height = height;
|
8601 |
|
8602 |
|
8603 |
|
8604 | var N2 = Math.ceil(N / M),
|
8605 | N1 = N2 * Math.ceil(Math.sqrt(M)),
|
8606 | i, j, right2, right3;
|
8607 |
|
8608 | multiSelect$1(items, left, right, N1, this.compareMinX);
|
8609 |
|
8610 | for (i = left; i <= right; i += N1) {
|
8611 |
|
8612 | right2 = Math.min(i + N1 - 1, right);
|
8613 |
|
8614 | multiSelect$1(items, i, right2, N2, this.compareMinY);
|
8615 |
|
8616 | for (j = i; j <= right2; j += N2) {
|
8617 |
|
8618 | right3 = Math.min(j + N2 - 1, right2);
|
8619 |
|
8620 |
|
8621 | node.children.push(this._build(items, j, right3, height - 1));
|
8622 | }
|
8623 | }
|
8624 |
|
8625 | calcBBox$1(node, this.toBBox);
|
8626 |
|
8627 | return node;
|
8628 | },
|
8629 |
|
8630 | _chooseSubtree: function (bbox, node, level, path) {
|
8631 |
|
8632 | var i, len, child, targetNode, area, enlargement, minArea, minEnlargement;
|
8633 |
|
8634 | while (true) {
|
8635 | path.push(node);
|
8636 |
|
8637 | if (node.leaf || path.length - 1 === level) break;
|
8638 |
|
8639 | minArea = minEnlargement = Infinity;
|
8640 |
|
8641 | for (i = 0, len = node.children.length; i < len; i++) {
|
8642 | child = node.children[i];
|
8643 | area = bboxArea$1(child);
|
8644 | enlargement = enlargedArea$1(bbox, child) - area;
|
8645 |
|
8646 |
|
8647 | if (enlargement < minEnlargement) {
|
8648 | minEnlargement = enlargement;
|
8649 | minArea = area < minArea ? area : minArea;
|
8650 | targetNode = child;
|
8651 |
|
8652 | } else if (enlargement === minEnlargement) {
|
8653 |
|
8654 | if (area < minArea) {
|
8655 | minArea = area;
|
8656 | targetNode = child;
|
8657 | }
|
8658 | }
|
8659 | }
|
8660 |
|
8661 | node = targetNode || node.children[0];
|
8662 | }
|
8663 |
|
8664 | return node;
|
8665 | },
|
8666 |
|
8667 | _insert: function (item, level, isNode) {
|
8668 |
|
8669 | var toBBox = this.toBBox,
|
8670 | bbox = isNode ? item : toBBox(item),
|
8671 | insertPath = [];
|
8672 |
|
8673 |
|
8674 | var node = this._chooseSubtree(bbox, this.data, level, insertPath);
|
8675 |
|
8676 |
|
8677 | node.children.push(item);
|
8678 | extend$1(node, bbox);
|
8679 |
|
8680 |
|
8681 | while (level >= 0) {
|
8682 | if (insertPath[level].children.length > this._maxEntries) {
|
8683 | this._split(insertPath, level);
|
8684 | level--;
|
8685 | } else break;
|
8686 | }
|
8687 |
|
8688 |
|
8689 | this._adjustParentBBoxes(bbox, insertPath, level);
|
8690 | },
|
8691 |
|
8692 |
|
8693 | _split: function (insertPath, level) {
|
8694 |
|
8695 | var node = insertPath[level],
|
8696 | M = node.children.length,
|
8697 | m = this._minEntries;
|
8698 |
|
8699 | this._chooseSplitAxis(node, m, M);
|
8700 |
|
8701 | var splitIndex = this._chooseSplitIndex(node, m, M);
|
8702 |
|
8703 | var newNode = createNode$1(node.children.splice(splitIndex, node.children.length - splitIndex));
|
8704 | newNode.height = node.height;
|
8705 | newNode.leaf = node.leaf;
|
8706 |
|
8707 | calcBBox$1(node, this.toBBox);
|
8708 | calcBBox$1(newNode, this.toBBox);
|
8709 |
|
8710 | if (level) insertPath[level - 1].children.push(newNode);
|
8711 | else this._splitRoot(node, newNode);
|
8712 | },
|
8713 |
|
8714 | _splitRoot: function (node, newNode) {
|
8715 |
|
8716 | this.data = createNode$1([node, newNode]);
|
8717 | this.data.height = node.height + 1;
|
8718 | this.data.leaf = false;
|
8719 | calcBBox$1(this.data, this.toBBox);
|
8720 | },
|
8721 |
|
8722 | _chooseSplitIndex: function (node, m, M) {
|
8723 |
|
8724 | var i, bbox1, bbox2, overlap, area, minOverlap, minArea, index;
|
8725 |
|
8726 | minOverlap = minArea = Infinity;
|
8727 |
|
8728 | for (i = m; i <= M - m; i++) {
|
8729 | bbox1 = distBBox$1(node, 0, i, this.toBBox);
|
8730 | bbox2 = distBBox$1(node, i, M, this.toBBox);
|
8731 |
|
8732 | overlap = intersectionArea$1(bbox1, bbox2);
|
8733 | area = bboxArea$1(bbox1) + bboxArea$1(bbox2);
|
8734 |
|
8735 |
|
8736 | if (overlap < minOverlap) {
|
8737 | minOverlap = overlap;
|
8738 | index = i;
|
8739 |
|
8740 | minArea = area < minArea ? area : minArea;
|
8741 |
|
8742 | } else if (overlap === minOverlap) {
|
8743 |
|
8744 | if (area < minArea) {
|
8745 | minArea = area;
|
8746 | index = i;
|
8747 | }
|
8748 | }
|
8749 | }
|
8750 |
|
8751 | return index;
|
8752 | },
|
8753 |
|
8754 |
|
8755 | _chooseSplitAxis: function (node, m, M) {
|
8756 |
|
8757 | var compareMinX = node.leaf ? this.compareMinX : compareNodeMinX$1,
|
8758 | compareMinY = node.leaf ? this.compareMinY : compareNodeMinY$1,
|
8759 | xMargin = this._allDistMargin(node, m, M, compareMinX),
|
8760 | yMargin = this._allDistMargin(node, m, M, compareMinY);
|
8761 |
|
8762 |
|
8763 |
|
8764 | if (xMargin < yMargin) node.children.sort(compareMinX);
|
8765 | },
|
8766 |
|
8767 |
|
8768 | _allDistMargin: function (node, m, M, compare) {
|
8769 |
|
8770 | node.children.sort(compare);
|
8771 |
|
8772 | var toBBox = this.toBBox,
|
8773 | leftBBox = distBBox$1(node, 0, m, toBBox),
|
8774 | rightBBox = distBBox$1(node, M - m, M, toBBox),
|
8775 | margin = bboxMargin$1(leftBBox) + bboxMargin$1(rightBBox),
|
8776 | i, child;
|
8777 |
|
8778 | for (i = m; i < M - m; i++) {
|
8779 | child = node.children[i];
|
8780 | extend$1(leftBBox, node.leaf ? toBBox(child) : child);
|
8781 | margin += bboxMargin$1(leftBBox);
|
8782 | }
|
8783 |
|
8784 | for (i = M - m - 1; i >= m; i--) {
|
8785 | child = node.children[i];
|
8786 | extend$1(rightBBox, node.leaf ? toBBox(child) : child);
|
8787 | margin += bboxMargin$1(rightBBox);
|
8788 | }
|
8789 |
|
8790 | return margin;
|
8791 | },
|
8792 |
|
8793 | _adjustParentBBoxes: function (bbox, path, level) {
|
8794 |
|
8795 | for (var i = level; i >= 0; i--) {
|
8796 | extend$1(path[i], bbox);
|
8797 | }
|
8798 | },
|
8799 |
|
8800 | _condense: function (path) {
|
8801 |
|
8802 | for (var i = path.length - 1, siblings; i >= 0; i--) {
|
8803 | if (path[i].children.length === 0) {
|
8804 | if (i > 0) {
|
8805 | siblings = path[i - 1].children;
|
8806 | siblings.splice(siblings.indexOf(path[i]), 1);
|
8807 |
|
8808 | } else this.clear();
|
8809 |
|
8810 | } else calcBBox$1(path[i], this.toBBox);
|
8811 | }
|
8812 | },
|
8813 |
|
8814 | _initFormat: function (format) {
|
8815 |
|
8816 |
|
8817 |
|
8818 |
|
8819 |
|
8820 |
|
8821 | var compareArr = ['return a', ' - b', ';'];
|
8822 |
|
8823 | this.compareMinX = new Function('a', 'b', compareArr.join(format[0]));
|
8824 | this.compareMinY = new Function('a', 'b', compareArr.join(format[1]));
|
8825 |
|
8826 | this.toBBox = new Function('a',
|
8827 | 'return {minX: a' + format[0] +
|
8828 | ', minY: a' + format[1] +
|
8829 | ', maxX: a' + format[2] +
|
8830 | ', maxY: a' + format[3] + '};');
|
8831 | }
|
8832 | };
|
8833 |
|
8834 | function findItem$1(item, items, equalsFn) {
|
8835 | if (!equalsFn) return items.indexOf(item);
|
8836 |
|
8837 | for (var i = 0; i < items.length; i++) {
|
8838 | if (equalsFn(item, items[i])) return i;
|
8839 | }
|
8840 | return -1;
|
8841 | }
|
8842 |
|
8843 |
|
8844 | function calcBBox$1(node, toBBox) {
|
8845 | distBBox$1(node, 0, node.children.length, toBBox, node);
|
8846 | }
|
8847 |
|
8848 |
|
8849 | function distBBox$1(node, k, p, toBBox, destNode) {
|
8850 | if (!destNode) destNode = createNode$1(null);
|
8851 | destNode.minX = Infinity;
|
8852 | destNode.minY = Infinity;
|
8853 | destNode.maxX = -Infinity;
|
8854 | destNode.maxY = -Infinity;
|
8855 |
|
8856 | for (var i = k, child; i < p; i++) {
|
8857 | child = node.children[i];
|
8858 | extend$1(destNode, node.leaf ? toBBox(child) : child);
|
8859 | }
|
8860 |
|
8861 | return destNode;
|
8862 | }
|
8863 |
|
8864 | function extend$1(a, b) {
|
8865 | a.minX = Math.min(a.minX, b.minX);
|
8866 | a.minY = Math.min(a.minY, b.minY);
|
8867 | a.maxX = Math.max(a.maxX, b.maxX);
|
8868 | a.maxY = Math.max(a.maxY, b.maxY);
|
8869 | return a;
|
8870 | }
|
8871 |
|
8872 | function compareNodeMinX$1(a, b) { return a.minX - b.minX; }
|
8873 | function compareNodeMinY$1(a, b) { return a.minY - b.minY; }
|
8874 |
|
8875 | function bboxArea$1(a) { return (a.maxX - a.minX) * (a.maxY - a.minY); }
|
8876 | function bboxMargin$1(a) { return (a.maxX - a.minX) + (a.maxY - a.minY); }
|
8877 |
|
8878 | function enlargedArea$1(a, b) {
|
8879 | return (Math.max(b.maxX, a.maxX) - Math.min(b.minX, a.minX)) *
|
8880 | (Math.max(b.maxY, a.maxY) - Math.min(b.minY, a.minY));
|
8881 | }
|
8882 |
|
8883 | function intersectionArea$1(a, b) {
|
8884 | var minX = Math.max(a.minX, b.minX),
|
8885 | minY = Math.max(a.minY, b.minY),
|
8886 | maxX = Math.min(a.maxX, b.maxX),
|
8887 | maxY = Math.min(a.maxY, b.maxY);
|
8888 |
|
8889 | return Math.max(0, maxX - minX) *
|
8890 | Math.max(0, maxY - minY);
|
8891 | }
|
8892 |
|
8893 | function contains$1(a, b) {
|
8894 | return a.minX <= b.minX &&
|
8895 | a.minY <= b.minY &&
|
8896 | b.maxX <= a.maxX &&
|
8897 | b.maxY <= a.maxY;
|
8898 | }
|
8899 |
|
8900 | function intersects$4(a, b) {
|
8901 | return b.minX <= a.maxX &&
|
8902 | b.minY <= a.maxY &&
|
8903 | b.maxX >= a.minX &&
|
8904 | b.maxY >= a.minY;
|
8905 | }
|
8906 |
|
8907 | function createNode$1(children) {
|
8908 | return {
|
8909 | children: children,
|
8910 | height: 1,
|
8911 | leaf: true,
|
8912 | minX: Infinity,
|
8913 | minY: Infinity,
|
8914 | maxX: -Infinity,
|
8915 | maxY: -Infinity
|
8916 | };
|
8917 | }
|
8918 |
|
8919 |
|
8920 |
|
8921 |
|
8922 | function multiSelect$1(arr, left, right, n, compare) {
|
8923 | var stack = [left, right],
|
8924 | mid;
|
8925 |
|
8926 | while (stack.length) {
|
8927 | right = stack.pop();
|
8928 | left = stack.pop();
|
8929 |
|
8930 | if (right - left <= n) continue;
|
8931 |
|
8932 | mid = left + Math.ceil((right - left) / n / 2) * n;
|
8933 | quickselect$3(arr, mid, left, right, compare);
|
8934 |
|
8935 | stack.push(left, mid, mid, right);
|
8936 | }
|
8937 | }
|
8938 |
|
8939 |
|
8940 |
|
8941 |
|
8942 |
|
8943 |
|
8944 |
|
8945 |
|
8946 |
|
8947 |
|
8948 |
|
8949 |
|
8950 | function geojsonRbush(maxEntries) {
|
8951 | var tree = rbush$4(maxEntries);
|
8952 | |
8953 |
|
8954 |
|
8955 |
|
8956 |
|
8957 |
|
8958 |
|
8959 |
|
8960 |
|
8961 |
|
8962 |
|
8963 |
|
8964 |
|
8965 |
|
8966 |
|
8967 |
|
8968 | tree.insert = function (feature) {
|
8969 | if (Array.isArray(feature)) {
|
8970 | var bbox = feature;
|
8971 | feature = bboxPolygon$2(bbox);
|
8972 | feature.bbox = bbox;
|
8973 | } else {
|
8974 | feature.bbox = feature.bbox ? feature.bbox : turfBBox(feature);
|
8975 | }
|
8976 | return rbush$4.prototype.insert.call(this, feature);
|
8977 | };
|
8978 |
|
8979 | |
8980 |
|
8981 |
|
8982 |
|
8983 |
|
8984 |
|
8985 |
|
8986 |
|
8987 |
|
8988 |
|
8989 |
|
8990 |
|
8991 |
|
8992 |
|
8993 |
|
8994 |
|
8995 |
|
8996 |
|
8997 |
|
8998 |
|
8999 |
|
9000 |
|
9001 |
|
9002 |
|
9003 |
|
9004 |
|
9005 |
|
9006 |
|
9007 |
|
9008 | tree.load = function (features) {
|
9009 | var load = [];
|
9010 |
|
9011 | if (Array.isArray(features)) {
|
9012 | features.forEach(function (bbox) {
|
9013 | var feature = bboxPolygon$2(bbox);
|
9014 | feature.bbox = bbox;
|
9015 | load.push(feature);
|
9016 | });
|
9017 | } else {
|
9018 |
|
9019 | featureEach(features, function (feature) {
|
9020 | feature.bbox = feature.bbox ? feature.bbox : turfBBox(feature);
|
9021 | load.push(feature);
|
9022 | });
|
9023 | }
|
9024 | return rbush$4.prototype.load.call(this, load);
|
9025 | };
|
9026 |
|
9027 | |
9028 |
|
9029 |
|
9030 |
|
9031 |
|
9032 |
|
9033 |
|
9034 |
|
9035 |
|
9036 |
|
9037 |
|
9038 |
|
9039 |
|
9040 |
|
9041 |
|
9042 |
|
9043 | tree.remove = function (feature) {
|
9044 | if (Array.isArray(feature)) {
|
9045 | var bbox = feature;
|
9046 | feature = bboxPolygon$2(bbox);
|
9047 | feature.bbox = bbox;
|
9048 | }
|
9049 | return rbush$4.prototype.remove.call(this, feature);
|
9050 | };
|
9051 |
|
9052 | |
9053 |
|
9054 |
|
9055 |
|
9056 |
|
9057 |
|
9058 |
|
9059 | tree.clear = function () {
|
9060 | return rbush$4.prototype.clear.call(this);
|
9061 | };
|
9062 |
|
9063 | |
9064 |
|
9065 |
|
9066 |
|
9067 |
|
9068 |
|
9069 |
|
9070 |
|
9071 |
|
9072 |
|
9073 |
|
9074 |
|
9075 |
|
9076 |
|
9077 |
|
9078 |
|
9079 | tree.search = function (geojson) {
|
9080 | var features = rbush$4.prototype.search.call(this, this.toBBox(geojson));
|
9081 | return {
|
9082 | type: 'FeatureCollection',
|
9083 | features: features
|
9084 | };
|
9085 | };
|
9086 |
|
9087 | |
9088 |
|
9089 |
|
9090 |
|
9091 |
|
9092 |
|
9093 |
|
9094 |
|
9095 |
|
9096 |
|
9097 |
|
9098 |
|
9099 |
|
9100 |
|
9101 |
|
9102 |
|
9103 | tree.collides = function (geojson) {
|
9104 | return rbush$4.prototype.collides.call(this, this.toBBox(geojson));
|
9105 | };
|
9106 |
|
9107 | |
9108 |
|
9109 |
|
9110 |
|
9111 |
|
9112 |
|
9113 |
|
9114 |
|
9115 | tree.all = function () {
|
9116 | var features = rbush$4.prototype.all.call(this);
|
9117 | return {
|
9118 | type: 'FeatureCollection',
|
9119 | features: features
|
9120 | };
|
9121 | };
|
9122 |
|
9123 | |
9124 |
|
9125 |
|
9126 |
|
9127 |
|
9128 |
|
9129 |
|
9130 |
|
9131 | tree.toJSON = function () {
|
9132 | return rbush$4.prototype.toJSON.call(this);
|
9133 | };
|
9134 |
|
9135 | |
9136 |
|
9137 |
|
9138 |
|
9139 |
|
9140 |
|
9141 |
|
9142 |
|
9143 |
|
9144 |
|
9145 |
|
9146 |
|
9147 |
|
9148 |
|
9149 |
|
9150 |
|
9151 |
|
9152 |
|
9153 |
|
9154 |
|
9155 |
|
9156 |
|
9157 |
|
9158 |
|
9159 |
|
9160 |
|
9161 |
|
9162 | tree.fromJSON = function (json) {
|
9163 | return rbush$4.prototype.fromJSON.call(this, json);
|
9164 | };
|
9165 |
|
9166 | |
9167 |
|
9168 |
|
9169 |
|
9170 |
|
9171 |
|
9172 |
|
9173 | tree.toBBox = function (geojson) {
|
9174 | var bbox;
|
9175 | if (geojson.bbox) bbox = geojson.bbox;
|
9176 | else if (Array.isArray(geojson) && geojson.length === 4) bbox = geojson;
|
9177 | else bbox = turfBBox(geojson);
|
9178 |
|
9179 | return {
|
9180 | minX: bbox[0],
|
9181 | minY: bbox[1],
|
9182 | maxX: bbox[2],
|
9183 | maxY: bbox[3]
|
9184 | };
|
9185 | };
|
9186 | return tree;
|
9187 | }
|
9188 |
|
9189 |
|
9190 |
|
9191 |
|
9192 |
|
9193 |
|
9194 |
|
9195 |
|
9196 |
|
9197 |
|
9198 |
|
9199 |
|
9200 |
|
9201 |
|
9202 |
|
9203 |
|
9204 | function bboxPolygon$2(bbox) {
|
9205 | var lowLeft = [bbox[0], bbox[1]];
|
9206 | var topLeft = [bbox[0], bbox[3]];
|
9207 | var topRight = [bbox[2], bbox[3]];
|
9208 | var lowRight = [bbox[2], bbox[1]];
|
9209 | var coordinates = [[lowLeft, lowRight, topRight, topLeft, lowLeft]];
|
9210 |
|
9211 | return {
|
9212 | type: 'Feature',
|
9213 | bbox: bbox,
|
9214 | properties: {},
|
9215 | geometry: {
|
9216 | type: 'Polygon',
|
9217 | coordinates: coordinates
|
9218 | }
|
9219 | };
|
9220 | }
|
9221 |
|
9222 |
|
9223 |
|
9224 |
|
9225 |
|
9226 |
|
9227 |
|
9228 |
|
9229 |
|
9230 |
|
9231 |
|
9232 |
|
9233 |
|
9234 |
|
9235 |
|
9236 |
|
9237 | function turfBBox(geojson) {
|
9238 | var bbox = [Infinity, Infinity, -Infinity, -Infinity];
|
9239 | coordEach(geojson, function (coord) {
|
9240 | if (bbox[0] > coord[0]) bbox[0] = coord[0];
|
9241 | if (bbox[1] > coord[1]) bbox[1] = coord[1];
|
9242 | if (bbox[2] < coord[0]) bbox[2] = coord[0];
|
9243 | if (bbox[3] < coord[1]) bbox[3] = coord[1];
|
9244 | });
|
9245 | return bbox;
|
9246 | }
|
9247 |
|
9248 |
|
9249 |
|
9250 |
|
9251 |
|
9252 |
|
9253 |
|
9254 |
|
9255 |
|
9256 |
|
9257 |
|
9258 |
|
9259 |
|
9260 |
|
9261 | function lineSegment(geojson) {
|
9262 | if (!geojson) throw new Error('geojson is required');
|
9263 |
|
9264 | var results = [];
|
9265 | flattenEach(geojson, function (feature$$1) {
|
9266 | lineSegmentFeature(feature$$1, results);
|
9267 | });
|
9268 | return featureCollection(results);
|
9269 | }
|
9270 |
|
9271 |
|
9272 |
|
9273 |
|
9274 |
|
9275 |
|
9276 |
|
9277 |
|
9278 |
|
9279 | function lineSegmentFeature(geojson, results) {
|
9280 | var coords = [];
|
9281 | var geometry$$1 = geojson.geometry;
|
9282 | switch (geometry$$1.type) {
|
9283 | case 'Polygon':
|
9284 | coords = getCoords(geometry$$1);
|
9285 | break;
|
9286 | case 'LineString':
|
9287 | coords = [getCoords(geometry$$1)];
|
9288 | }
|
9289 | coords.forEach(function (coord) {
|
9290 | var segments = createSegments(coord, geojson.properties);
|
9291 | segments.forEach(function (segment) {
|
9292 | segment.id = results.length;
|
9293 | results.push(segment);
|
9294 | });
|
9295 | });
|
9296 | }
|
9297 |
|
9298 |
|
9299 |
|
9300 |
|
9301 |
|
9302 |
|
9303 |
|
9304 |
|
9305 |
|
9306 | function createSegments(coords, properties) {
|
9307 | var segments = [];
|
9308 | coords.reduce(function (previousCoords, currentCoords) {
|
9309 | var segment = lineString([previousCoords, currentCoords], properties);
|
9310 | segment.bbox = bbox$3(previousCoords, currentCoords);
|
9311 | segments.push(segment);
|
9312 | return currentCoords;
|
9313 | });
|
9314 | return segments;
|
9315 | }
|
9316 |
|
9317 |
|
9318 |
|
9319 |
|
9320 |
|
9321 |
|
9322 |
|
9323 |
|
9324 |
|
9325 | function bbox$3(coords1, coords2) {
|
9326 | var x1 = coords1[0];
|
9327 | var y1 = coords1[1];
|
9328 | var x2 = coords2[0];
|
9329 | var y2 = coords2[1];
|
9330 | var west = (x1 < x2) ? x1 : x2;
|
9331 | var south = (y1 < y2) ? y1 : y2;
|
9332 | var east = (x1 > x2) ? x1 : x2;
|
9333 | var north = (y1 > y2) ? y1 : y2;
|
9334 | return [west, south, east, north];
|
9335 | }
|
9336 |
|
9337 |
|
9338 |
|
9339 |
|
9340 |
|
9341 |
|
9342 |
|
9343 |
|
9344 |
|
9345 |
|
9346 |
|
9347 |
|
9348 |
|
9349 |
|
9350 |
|
9351 |
|
9352 | function lineIntersect(line1, line2) {
|
9353 | var unique = {};
|
9354 | var results = [];
|
9355 |
|
9356 |
|
9357 |
|
9358 | if (line1.type === 'LineString') line1 = feature(line1);
|
9359 | if (line2.type === 'LineString') line2 = feature(line2);
|
9360 | if (line1.type === 'Feature' &&
|
9361 | line2.type === 'Feature' &&
|
9362 | line1.geometry.type === 'LineString' &&
|
9363 | line2.geometry.type === 'LineString' &&
|
9364 | line1.geometry.coordinates.length === 2 &&
|
9365 | line2.geometry.coordinates.length === 2) {
|
9366 | var intersect = intersects$3(line1, line2);
|
9367 | if (intersect) results.push(intersect);
|
9368 | return featureCollection(results);
|
9369 | }
|
9370 |
|
9371 |
|
9372 | var tree = geojsonRbush();
|
9373 | tree.load(lineSegment(line2));
|
9374 | featureEach(lineSegment(line1), function (segment) {
|
9375 | featureEach(tree.search(segment), function (match) {
|
9376 | var intersect = intersects$3(segment, match);
|
9377 | if (intersect) {
|
9378 |
|
9379 | var key = getCoords(intersect).join(',');
|
9380 | if (!unique[key]) {
|
9381 | unique[key] = true;
|
9382 | results.push(intersect);
|
9383 | }
|
9384 | }
|
9385 | });
|
9386 | });
|
9387 | return featureCollection(results);
|
9388 | }
|
9389 |
|
9390 |
|
9391 |
|
9392 |
|
9393 |
|
9394 |
|
9395 |
|
9396 |
|
9397 |
|
9398 | function intersects$3(line1, line2) {
|
9399 | var coords1 = getCoords(line1);
|
9400 | var coords2 = getCoords(line2);
|
9401 | if (coords1.length !== 2) {
|
9402 | throw new Error('<intersects> line1 must only contain 2 coordinates');
|
9403 | }
|
9404 | if (coords2.length !== 2) {
|
9405 | throw new Error('<intersects> line2 must only contain 2 coordinates');
|
9406 | }
|
9407 | var x1 = coords1[0][0];
|
9408 | var y1 = coords1[0][1];
|
9409 | var x2 = coords1[1][0];
|
9410 | var y2 = coords1[1][1];
|
9411 | var x3 = coords2[0][0];
|
9412 | var y3 = coords2[0][1];
|
9413 | var x4 = coords2[1][0];
|
9414 | var y4 = coords2[1][1];
|
9415 | var denom = ((y4 - y3) * (x2 - x1)) - ((x4 - x3) * (y2 - y1));
|
9416 | var numeA = ((x4 - x3) * (y1 - y3)) - ((y4 - y3) * (x1 - x3));
|
9417 | var numeB = ((x2 - x1) * (y1 - y3)) - ((y2 - y1) * (x1 - x3));
|
9418 |
|
9419 | if (denom === 0) {
|
9420 | if (numeA === 0 && numeB === 0) {
|
9421 | return null;
|
9422 | }
|
9423 | return null;
|
9424 | }
|
9425 |
|
9426 | var uA = numeA / denom;
|
9427 | var uB = numeB / denom;
|
9428 |
|
9429 | if (uA >= 0 && uA <= 1 && uB >= 0 && uB <= 1) {
|
9430 | var x = x1 + (uA * (x2 - x1));
|
9431 | var y = y1 + (uA * (y2 - y1));
|
9432 | return point([x, y]);
|
9433 | }
|
9434 | return null;
|
9435 | }
|
9436 |
|
9437 |
|
9438 |
|
9439 |
|
9440 |
|
9441 |
|
9442 |
|
9443 |
|
9444 |
|
9445 |
|
9446 |
|
9447 |
|
9448 |
|
9449 |
|
9450 |
|
9451 |
|
9452 |
|
9453 |
|
9454 |
|
9455 |
|
9456 |
|
9457 |
|
9458 |
|
9459 |
|
9460 |
|
9461 |
|
9462 |
|
9463 | function nearestPointOnLine(lines, pt, options) {
|
9464 |
|
9465 | options = options || {};
|
9466 | if (!isObject(options)) throw new Error('options is invalid');
|
9467 |
|
9468 |
|
9469 | var type = (lines.geometry) ? lines.geometry.type : lines.type;
|
9470 | if (type !== 'LineString' && type !== 'MultiLineString') {
|
9471 | throw new Error('lines must be LineString or MultiLineString');
|
9472 | }
|
9473 |
|
9474 | var closestPt = point([Infinity, Infinity], {
|
9475 | dist: Infinity
|
9476 | });
|
9477 |
|
9478 | var length = 0.0;
|
9479 | flattenEach(lines, function (line) {
|
9480 | var coords = getCoords(line);
|
9481 |
|
9482 | for (var i = 0; i < coords.length - 1; i++) {
|
9483 |
|
9484 | var start = point(coords[i]);
|
9485 | start.properties.dist = distance(pt, start, options);
|
9486 |
|
9487 | var stop = point(coords[i + 1]);
|
9488 | stop.properties.dist = distance(pt, stop, options);
|
9489 |
|
9490 | var sectionLength = distance(start, stop, options);
|
9491 |
|
9492 | var heightDistance = Math.max(start.properties.dist, stop.properties.dist);
|
9493 | var direction = bearing(start, stop);
|
9494 | var perpendicularPt1 = destination(pt, heightDistance, direction + 90, options);
|
9495 | var perpendicularPt2 = destination(pt, heightDistance, direction - 90, options);
|
9496 | var intersect = lineIntersect(
|
9497 | lineString([perpendicularPt1.geometry.coordinates, perpendicularPt2.geometry.coordinates]),
|
9498 | lineString([start.geometry.coordinates, stop.geometry.coordinates])
|
9499 | );
|
9500 | var intersectPt = null;
|
9501 | if (intersect.features.length > 0) {
|
9502 | intersectPt = intersect.features[0];
|
9503 | intersectPt.properties.dist = distance(pt, intersectPt, options);
|
9504 | intersectPt.properties.location = length + distance(start, intersectPt, options);
|
9505 | }
|
9506 |
|
9507 | if (start.properties.dist < closestPt.properties.dist) {
|
9508 | closestPt = start;
|
9509 | closestPt.properties.index = i;
|
9510 | closestPt.properties.location = length;
|
9511 | }
|
9512 | if (stop.properties.dist < closestPt.properties.dist) {
|
9513 | closestPt = stop;
|
9514 | closestPt.properties.index = i + 1;
|
9515 | closestPt.properties.location = length + sectionLength;
|
9516 | }
|
9517 | if (intersectPt && intersectPt.properties.dist < closestPt.properties.dist) {
|
9518 | closestPt = intersectPt;
|
9519 | closestPt.properties.index = i;
|
9520 | }
|
9521 |
|
9522 | length += sectionLength;
|
9523 | }
|
9524 |
|
9525 | });
|
9526 |
|
9527 | return closestPt;
|
9528 | }
|
9529 |
|
9530 |
|
9531 |
|
9532 |
|
9533 |
|
9534 |
|
9535 |
|
9536 |
|
9537 |
|
9538 |
|
9539 |
|
9540 |
|
9541 |
|
9542 |
|
9543 |
|
9544 |
|
9545 |
|
9546 |
|
9547 |
|
9548 |
|
9549 |
|
9550 |
|
9551 |
|
9552 | function rhumbBearing(start, end, options) {
|
9553 |
|
9554 | options = options || {};
|
9555 | if (!isObject(options)) throw new Error('options is invalid');
|
9556 | var final = options.final;
|
9557 |
|
9558 |
|
9559 | if (!start) throw new Error('start point is required');
|
9560 | if (!end) throw new Error('end point is required');
|
9561 |
|
9562 | var bear360;
|
9563 |
|
9564 | if (final) bear360 = calculateRhumbBearing(getCoord(end), getCoord(start));
|
9565 | else bear360 = calculateRhumbBearing(getCoord(start), getCoord(end));
|
9566 |
|
9567 | var bear180 = (bear360 > 180) ? -(360 - bear360) : bear360;
|
9568 |
|
9569 | return bear180;
|
9570 | }
|
9571 |
|
9572 |
|
9573 |
|
9574 |
|
9575 |
|
9576 |
|
9577 |
|
9578 |
|
9579 |
|
9580 |
|
9581 |
|
9582 |
|
9583 |
|
9584 |
|
9585 | function calculateRhumbBearing(from, to) {
|
9586 |
|
9587 |
|
9588 |
|
9589 |
|
9590 | var phi1 = degreesToRadians(from[1]);
|
9591 | var phi2 = degreesToRadians(to[1]);
|
9592 | var deltaLambda = degreesToRadians((to[0] - from[0]));
|
9593 |
|
9594 | if (deltaLambda > Math.PI) deltaLambda -= 2 * Math.PI;
|
9595 | if (deltaLambda < -Math.PI) deltaLambda += 2 * Math.PI;
|
9596 |
|
9597 | var deltaPsi = Math.log(Math.tan(phi2 / 2 + Math.PI / 4) / Math.tan(phi1 / 2 + Math.PI / 4));
|
9598 |
|
9599 | var theta = Math.atan2(deltaLambda, deltaPsi);
|
9600 |
|
9601 | return (radiansToDegrees(theta) + 360) % 360;
|
9602 | }
|
9603 |
|
9604 |
|
9605 |
|
9606 |
|
9607 |
|
9608 |
|
9609 |
|
9610 |
|
9611 |
|
9612 |
|
9613 |
|
9614 |
|
9615 |
|
9616 |
|
9617 |
|
9618 |
|
9619 |
|
9620 |
|
9621 |
|
9622 |
|
9623 |
|
9624 |
|
9625 |
|
9626 |
|
9627 | function rhumbDistance(from, to, options) {
|
9628 |
|
9629 | options = options || {};
|
9630 | if (!isObject(options)) throw new Error('options is invalid');
|
9631 | var units = options.units;
|
9632 |
|
9633 |
|
9634 | if (!from) throw new Error('from point is required');
|
9635 | if (!to) throw new Error('to point is required');
|
9636 |
|
9637 | var origin = getCoord(from);
|
9638 | var destination = getCoord(to);
|
9639 |
|
9640 |
|
9641 |
|
9642 | destination[0] += (destination[0] - origin[0] > 180) ? -360 : (origin[0] - destination[0] > 180) ? 360 : 0;
|
9643 | var distanceInMeters = calculateRhumbDistance(origin, destination);
|
9644 | var distance = convertLength(distanceInMeters, 'meters', units);
|
9645 | return distance;
|
9646 | }
|
9647 |
|
9648 |
|
9649 |
|
9650 |
|
9651 |
|
9652 |
|
9653 |
|
9654 |
|
9655 |
|
9656 |
|
9657 |
|
9658 |
|
9659 |
|
9660 |
|
9661 |
|
9662 |
|
9663 | function calculateRhumbDistance(origin, destination, radius) {
|
9664 |
|
9665 |
|
9666 |
|
9667 |
|
9668 |
|
9669 |
|
9670 |
|
9671 | radius = (radius === undefined) ? earthRadius : Number(radius);
|
9672 |
|
9673 |
|
9674 | var R = radius;
|
9675 | var phi1 = origin[1] * Math.PI / 180;
|
9676 | var phi2 = destination[1] * Math.PI / 180;
|
9677 | var DeltaPhi = phi2 - phi1;
|
9678 | var DeltaLambda = Math.abs(destination[0] - origin[0]) * Math.PI / 180;
|
9679 |
|
9680 | if (DeltaLambda > Math.PI) DeltaLambda -= 2 * Math.PI;
|
9681 |
|
9682 |
|
9683 |
|
9684 | var DeltaPsi = Math.log(Math.tan(phi2 / 2 + Math.PI / 4) / Math.tan(phi1 / 2 + Math.PI / 4));
|
9685 | var q = Math.abs(DeltaPsi) > 10e-12 ? DeltaPhi / DeltaPsi : Math.cos(phi1);
|
9686 |
|
9687 |
|
9688 | var delta = Math.sqrt(DeltaPhi * DeltaPhi + q * q * DeltaLambda * DeltaLambda);
|
9689 | var dist = delta * R;
|
9690 |
|
9691 | return dist;
|
9692 | }
|
9693 |
|
9694 |
|
9695 |
|
9696 |
|
9697 |
|
9698 |
|
9699 |
|
9700 |
|
9701 |
|
9702 |
|
9703 |
|
9704 |
|
9705 |
|
9706 |
|
9707 |
|
9708 |
|
9709 | function toMercator(geojson, options) {
|
9710 | return convert(geojson, 'mercator', options);
|
9711 | }
|
9712 |
|
9713 |
|
9714 |
|
9715 |
|
9716 |
|
9717 |
|
9718 |
|
9719 |
|
9720 |
|
9721 |
|
9722 |
|
9723 |
|
9724 |
|
9725 |
|
9726 |
|
9727 |
|
9728 | function toWgs84(geojson, options) {
|
9729 | return convert(geojson, 'wgs84', options);
|
9730 | }
|
9731 |
|
9732 |
|
9733 |
|
9734 |
|
9735 |
|
9736 |
|
9737 |
|
9738 |
|
9739 |
|
9740 |
|
9741 |
|
9742 |
|
9743 | function convert(geojson, projection, options) {
|
9744 |
|
9745 | options = options || {};
|
9746 | if (!isObject(options)) throw new Error('options is invalid');
|
9747 | var mutate = options.mutate;
|
9748 |
|
9749 |
|
9750 | if (!geojson) throw new Error('geojson is required');
|
9751 |
|
9752 |
|
9753 | if (Array.isArray(geojson) && isNumber(geojson[0])) geojson = (projection === 'mercator') ? convertToMercator(geojson) : convertToWgs84(geojson);
|
9754 |
|
9755 |
|
9756 | else {
|
9757 |
|
9758 | if (mutate !== true) geojson = clone(geojson);
|
9759 |
|
9760 | coordEach(geojson, function (coord) {
|
9761 | var newCoord = (projection === 'mercator') ? convertToMercator(coord) : convertToWgs84(coord);
|
9762 | coord[0] = newCoord[0];
|
9763 | coord[1] = newCoord[1];
|
9764 | });
|
9765 | }
|
9766 | return geojson;
|
9767 | }
|
9768 |
|
9769 |
|
9770 |
|
9771 |
|
9772 |
|
9773 |
|
9774 |
|
9775 |
|
9776 |
|
9777 | function convertToMercator(lonLat) {
|
9778 | var D2R = Math.PI / 180,
|
9779 |
|
9780 | A = 6378137.0,
|
9781 | MAXEXTENT = 20037508.342789244;
|
9782 |
|
9783 |
|
9784 |
|
9785 | var adjusted = (Math.abs(lonLat[0]) <= 180) ? lonLat[0] : (lonLat[0] - (sign(lonLat[0]) * 360));
|
9786 | var xy = [
|
9787 | A * adjusted * D2R,
|
9788 | A * Math.log(Math.tan((Math.PI * 0.25) + (0.5 * lonLat[1] * D2R)))
|
9789 | ];
|
9790 |
|
9791 |
|
9792 | if (xy[0] > MAXEXTENT) xy[0] = MAXEXTENT;
|
9793 | if (xy[0] < -MAXEXTENT) xy[0] = -MAXEXTENT;
|
9794 | if (xy[1] > MAXEXTENT) xy[1] = MAXEXTENT;
|
9795 | if (xy[1] < -MAXEXTENT) xy[1] = -MAXEXTENT;
|
9796 |
|
9797 | return xy;
|
9798 | }
|
9799 |
|
9800 |
|
9801 |
|
9802 |
|
9803 |
|
9804 |
|
9805 |
|
9806 |
|
9807 |
|
9808 | function convertToWgs84(xy) {
|
9809 |
|
9810 | var R2D = 180 / Math.PI;
|
9811 | var A = 6378137.0;
|
9812 |
|
9813 | return [
|
9814 | (xy[0] * R2D / A),
|
9815 | ((Math.PI * 0.5) - 2.0 * Math.atan(Math.exp(-xy[1] / A))) * R2D
|
9816 | ];
|
9817 | }
|
9818 |
|
9819 |
|
9820 |
|
9821 |
|
9822 |
|
9823 |
|
9824 |
|
9825 |
|
9826 | function sign(x) {
|
9827 | return (x < 0) ? -1 : (x > 0) ? 1 : 0;
|
9828 | }
|
9829 |
|
9830 |
|
9831 |
|
9832 |
|
9833 | var main_es$3 = Object.freeze({
|
9834 | toMercator: toMercator,
|
9835 | toWgs84: toWgs84
|
9836 | });
|
9837 |
|
9838 |
|
9839 |
|
9840 |
|
9841 |
|
9842 |
|
9843 |
|
9844 |
|
9845 |
|
9846 |
|
9847 |
|
9848 |
|
9849 |
|
9850 |
|
9851 |
|
9852 |
|
9853 |
|
9854 |
|
9855 |
|
9856 |
|
9857 |
|
9858 |
|
9859 | function pointToLineDistance(pt, line, options) {
|
9860 |
|
9861 | options = options || {};
|
9862 | if (!isObject(options)) throw new Error('options is invalid');
|
9863 |
|
9864 |
|
9865 | if (!pt) throw new Error('pt is required');
|
9866 | if (Array.isArray(pt)) pt = point(pt);
|
9867 | else if (pt.type === 'Point') pt = feature(pt);
|
9868 | else featureOf(pt, 'Point', 'point');
|
9869 |
|
9870 | if (!line) throw new Error('line is required');
|
9871 | if (Array.isArray(line)) line = lineString(line);
|
9872 | else if (line.type === 'LineString') line = feature(line);
|
9873 | else featureOf(line, 'LineString', 'line');
|
9874 |
|
9875 | var distance$$1 = Infinity;
|
9876 | var p = pt.geometry.coordinates;
|
9877 | segmentEach(line, function (segment) {
|
9878 | var a = segment.geometry.coordinates[0];
|
9879 | var b = segment.geometry.coordinates[1];
|
9880 | var d = distanceToSegment(p, a, b, options);
|
9881 | if (distance$$1 > d) distance$$1 = d;
|
9882 | });
|
9883 | return distance$$1;
|
9884 | }
|
9885 |
|
9886 |
|
9887 |
|
9888 |
|
9889 |
|
9890 |
|
9891 |
|
9892 |
|
9893 |
|
9894 |
|
9895 |
|
9896 |
|
9897 |
|
9898 |
|
9899 | function distanceToSegment(p, a, b, options) {
|
9900 | var mercator = options.mercator;
|
9901 | var distanceAP = (mercator !== true) ? distance(a, p, options) : euclideanDistance(a, p, options);
|
9902 | var azimuthAP = bearingToAzimuth((mercator !== true) ? bearing(a, p) : rhumbBearing(a, p));
|
9903 | var azimuthAB = bearingToAzimuth((mercator !== true) ? bearing(a, b) : rhumbBearing(a, b));
|
9904 | var angleA = Math.abs(azimuthAP - azimuthAB);
|
9905 |
|
9906 |
|
9907 |
|
9908 | |
9909 |
|
9910 |
|
9911 |
|
9912 |
|
9913 |
|
9914 |
|
9915 |
|
9916 | if (angleA > 90) return distanceAP;
|
9917 |
|
9918 | var azimuthBA = (azimuthAB + 180) % 360;
|
9919 | var azimuthBP = bearingToAzimuth((mercator !== true) ? bearing(b, p) : rhumbBearing(b, p));
|
9920 | var angleB = Math.abs(azimuthBP - azimuthBA);
|
9921 | if (angleB > 180) angleB = Math.abs(angleB - 360);
|
9922 |
|
9923 |
|
9924 | |
9925 |
|
9926 |
|
9927 |
|
9928 |
|
9929 |
|
9930 |
|
9931 |
|
9932 | if (angleB > 90) return (mercator !== true) ? distance(p, b, options) : euclideanDistance(p, b, options);
|
9933 |
|
9934 |
|
9935 | |
9936 |
|
9937 |
|
9938 |
|
9939 |
|
9940 |
|
9941 |
|
9942 |
|
9943 |
|
9944 | if (mercator !== true) return distanceAP * Math.sin(degreesToRadians(angleA));
|
9945 | return mercatorPH(a, b, p, options);
|
9946 | }
|
9947 |
|
9948 |
|
9949 |
|
9950 |
|
9951 |
|
9952 |
|
9953 |
|
9954 |
|
9955 |
|
9956 |
|
9957 |
|
9958 |
|
9959 | function mercatorPH(a, b, p, options) {
|
9960 | var delta = 0;
|
9961 |
|
9962 | if (Math.abs(a[0]) >= 180 || Math.abs(b[0]) >= 180 || Math.abs(p[0]) >= 180) {
|
9963 | delta = (a[0] > 0 || b[0] > 0 || p[0] > 0) ? -180 : 180;
|
9964 | }
|
9965 |
|
9966 | var origin = point(p);
|
9967 | var A = toMercator([a[0] + delta, a[1]]);
|
9968 | var B = toMercator([b[0] + delta, b[1]]);
|
9969 | var P = toMercator([p[0] + delta, p[1]]);
|
9970 | var h = toWgs84(euclideanIntersection(A, B, P));
|
9971 |
|
9972 | if (delta !== 0) h[0] -= delta;
|
9973 | var distancePH = rhumbDistance(origin, h, options);
|
9974 | return distancePH;
|
9975 | }
|
9976 |
|
9977 |
|
9978 |
|
9979 |
|
9980 |
|
9981 |
|
9982 |
|
9983 |
|
9984 |
|
9985 |
|
9986 |
|
9987 |
|
9988 |
|
9989 |
|
9990 |
|
9991 |
|
9992 | function euclideanIntersection(a, b, p) {
|
9993 | var x1 = a[0], y1 = a[1],
|
9994 | x2 = b[0], y2 = b[1],
|
9995 | x3 = p[0], y3 = p[1];
|
9996 | var px = x2 - x1, py = y2 - y1;
|
9997 | var dab = px * px + py * py;
|
9998 | var u = ((x3 - x1) * px + (y3 - y1) * py) / dab;
|
9999 | var x = x1 + u * px, y = y1 + u * py;
|
10000 | return [x, y];
|
10001 | }
|
10002 |
|
10003 |
|
10004 |
|
10005 |
|
10006 |
|
10007 |
|
10008 |
|
10009 |
|
10010 |
|
10011 |
|
10012 |
|
10013 | function euclideanDistance(from, to, options) {
|
10014 | var units = options.units;
|
10015 |
|
10016 | var delta = 0;
|
10017 | if (Math.abs(from[0]) >= 180) {
|
10018 | delta = (from[0] > 0) ? -180 : 180;
|
10019 | }
|
10020 | if (Math.abs(to[0]) >= 180) {
|
10021 | delta = (to[0] > 0) ? -180 : 180;
|
10022 | }
|
10023 | var p1 = toMercator([from[0] + delta, from[1]]);
|
10024 | var p2 = toMercator([to[0] + delta, to[1]]);
|
10025 |
|
10026 | var sqr = function (n) { return n * n; };
|
10027 | var squareD = sqr(p1[0] - p2[0]) + sqr(p1[1] - p2[1]);
|
10028 | var d = Math.sqrt(squareD);
|
10029 | return convertLength(d, 'meters', units);
|
10030 | }
|
10031 |
|
10032 |
|
10033 |
|
10034 |
|
10035 |
|
10036 |
|
10037 |
|
10038 |
|
10039 |
|
10040 |
|
10041 |
|
10042 |
|
10043 |
|
10044 |
|
10045 |
|
10046 |
|
10047 |
|
10048 |
|
10049 |
|
10050 |
|
10051 |
|
10052 |
|
10053 |
|
10054 | function nearestPointToLine(points$$1, line, options) {
|
10055 | options = options || {};
|
10056 | if (!isObject(options)) throw new Error('options is invalid');
|
10057 | var units = options.units;
|
10058 | var properties = options.properties || {};
|
10059 |
|
10060 |
|
10061 | if (!points$$1) throw new Error('points is required');
|
10062 | points$$1 = normalize(points$$1);
|
10063 | if (!points$$1.features.length) throw new Error('points must contain features');
|
10064 |
|
10065 | if (!line) throw new Error('line is required');
|
10066 | if (getType(line) !== 'LineString') throw new Error('line must be a LineString');
|
10067 |
|
10068 | var dist = Infinity;
|
10069 | var pt = null;
|
10070 |
|
10071 | featureEach(points$$1, function (point$$1) {
|
10072 | var d = pointToLineDistance(point$$1, line, { units: units });
|
10073 | if (d < dist) {
|
10074 | dist = d;
|
10075 | pt = point$$1;
|
10076 | }
|
10077 | });
|
10078 | |
10079 |
|
10080 |
|
10081 |
|
10082 |
|
10083 |
|
10084 | if (pt) pt.properties = Object.assign({dist: dist}, pt.properties, properties);
|
10085 | return pt;
|
10086 | }
|
10087 |
|
10088 |
|
10089 |
|
10090 |
|
10091 |
|
10092 |
|
10093 |
|
10094 |
|
10095 | function normalize(points$$1) {
|
10096 | var features = [];
|
10097 | var type = points$$1.geometry ? points$$1.geometry.type : points$$1.type;
|
10098 | switch (type) {
|
10099 | case 'GeometryCollection':
|
10100 | geomEach(points$$1, function (geom) {
|
10101 | if (geom.type === 'Point') features.push({type: 'Feature', properties: {}, geometry: geom});
|
10102 | });
|
10103 | return {type: 'FeatureCollection', features: features};
|
10104 | case 'FeatureCollection':
|
10105 | points$$1.features = points$$1.features.filter(function (feature$$1) {
|
10106 | return feature$$1.geometry.type === 'Point';
|
10107 | });
|
10108 | return points$$1;
|
10109 | default:
|
10110 | throw new Error('points must be a Point Collection');
|
10111 | }
|
10112 | }
|
10113 |
|
10114 |
|
10115 |
|
10116 |
|
10117 |
|
10118 |
|
10119 |
|
10120 |
|
10121 |
|
10122 |
|
10123 |
|
10124 |
|
10125 |
|
10126 |
|
10127 |
|
10128 |
|
10129 |
|
10130 |
|
10131 |
|
10132 |
|
10133 |
|
10134 |
|
10135 |
|
10136 |
|
10137 |
|
10138 |
|
10139 |
|
10140 |
|
10141 |
|
10142 |
|
10143 |
|
10144 |
|
10145 |
|
10146 | function planepoint(point, triangle) {
|
10147 |
|
10148 | var coord = getCoord(point);
|
10149 | var geom = getGeom(triangle);
|
10150 | var coords = geom.coordinates;
|
10151 | var outer = coords[0];
|
10152 | if (outer.length < 4) throw new Error('OuterRing of a Polygon must have 4 or more Positions.');
|
10153 | var properties = triangle.properties || {};
|
10154 | var a = properties.a;
|
10155 | var b = properties.b;
|
10156 | var c = properties.c;
|
10157 |
|
10158 |
|
10159 | var x = coord[0];
|
10160 | var y = coord[1];
|
10161 | var x1 = outer[0][0];
|
10162 | var y1 = outer[0][1];
|
10163 | var z1 = (a !== undefined ? a : outer[0][2]);
|
10164 | var x2 = outer[1][0];
|
10165 | var y2 = outer[1][1];
|
10166 | var z2 = (b !== undefined ? b : outer[1][2]);
|
10167 | var x3 = outer[2][0];
|
10168 | var y3 = outer[2][1];
|
10169 | var z3 = (c !== undefined ? c : outer[2][2]);
|
10170 | var z = (z3 * (x - x1) * (y - y2) + z1 * (x - x2) * (y - y3) + z2 * (x - x3) * (y - y1) -
|
10171 | z2 * (x - x1) * (y - y3) - z3 * (x - x2) * (y - y1) - z1 * (x - x3) * (y - y2)) /
|
10172 | ((x - x1) * (y - y2) + (x - x2) * (y - y3) + (x - x3) * (y - y1) -
|
10173 | (x - x1) * (y - y3) - (x - x2) * (y - y1) - (x - x3) * (y - y2));
|
10174 |
|
10175 | return z;
|
10176 | }
|
10177 |
|
10178 |
|
10179 |
|
10180 |
|
10181 |
|
10182 |
|
10183 |
|
10184 |
|
10185 |
|
10186 |
|
10187 |
|
10188 |
|
10189 |
|
10190 |
|
10191 |
|
10192 |
|
10193 |
|
10194 |
|
10195 |
|
10196 |
|
10197 |
|
10198 | function kinks(featureIn) {
|
10199 | var coordinates;
|
10200 | var feature$$1;
|
10201 | var results = {
|
10202 | type: 'FeatureCollection',
|
10203 | features: []
|
10204 | };
|
10205 | if (featureIn.type === 'Feature') {
|
10206 | feature$$1 = featureIn.geometry;
|
10207 | } else {
|
10208 | feature$$1 = featureIn;
|
10209 | }
|
10210 | if (feature$$1.type === 'LineString') {
|
10211 | coordinates = [feature$$1.coordinates];
|
10212 | } else if (feature$$1.type === 'MultiLineString') {
|
10213 | coordinates = feature$$1.coordinates;
|
10214 | } else if (feature$$1.type === 'MultiPolygon') {
|
10215 | coordinates = [].concat.apply([], feature$$1.coordinates);
|
10216 | } else if (feature$$1.type === 'Polygon') {
|
10217 | coordinates = feature$$1.coordinates;
|
10218 | } else {
|
10219 | throw new Error('Input must be a LineString, MultiLineString, ' +
|
10220 | 'Polygon, or MultiPolygon Feature or Geometry');
|
10221 | }
|
10222 | coordinates.forEach(function (line1) {
|
10223 | coordinates.forEach(function (line2) {
|
10224 | for (var i = 0; i < line1.length - 1; i++) {
|
10225 |
|
10226 | for (var k = i; k < line2.length - 1; k++) {
|
10227 | if (line1 === line2) {
|
10228 |
|
10229 | if (Math.abs(i - k) === 1) {
|
10230 | continue;
|
10231 | }
|
10232 |
|
10233 | if (
|
10234 |
|
10235 | i === 0 &&
|
10236 | k === line1.length - 2 &&
|
10237 |
|
10238 | line1[i][0] === line1[line1.length - 1][0] &&
|
10239 | line1[i][1] === line1[line1.length - 1][1]
|
10240 | ) {
|
10241 | continue;
|
10242 | }
|
10243 | }
|
10244 |
|
10245 | var intersection = lineIntersects(line1[i][0], line1[i][1], line1[i + 1][0], line1[i + 1][1],
|
10246 | line2[k][0], line2[k][1], line2[k + 1][0], line2[k + 1][1]);
|
10247 | if (intersection) {
|
10248 | results.features.push(point([intersection[0], intersection[1]]));
|
10249 | }
|
10250 | }
|
10251 | }
|
10252 | });
|
10253 | });
|
10254 | return results;
|
10255 | }
|
10256 |
|
10257 |
|
10258 |
|
10259 | function lineIntersects(line1StartX, line1StartY, line1EndX, line1EndY, line2StartX, line2StartY, line2EndX, line2EndY) {
|
10260 |
|
10261 | var denominator, a, b, numerator1, numerator2,
|
10262 | result = {
|
10263 | x: null,
|
10264 | y: null,
|
10265 | onLine1: false,
|
10266 | onLine2: false
|
10267 | };
|
10268 | denominator = ((line2EndY - line2StartY) * (line1EndX - line1StartX)) - ((line2EndX - line2StartX) * (line1EndY - line1StartY));
|
10269 | if (denominator === 0) {
|
10270 | if (result.x !== null && result.y !== null) {
|
10271 | return result;
|
10272 | } else {
|
10273 | return false;
|
10274 | }
|
10275 | }
|
10276 | a = line1StartY - line2StartY;
|
10277 | b = line1StartX - line2StartX;
|
10278 | numerator1 = ((line2EndX - line2StartX) * a) - ((line2EndY - line2StartY) * b);
|
10279 | numerator2 = ((line1EndX - line1StartX) * a) - ((line1EndY - line1StartY) * b);
|
10280 | a = numerator1 / denominator;
|
10281 | b = numerator2 / denominator;
|
10282 |
|
10283 |
|
10284 | result.x = line1StartX + (a * (line1EndX - line1StartX));
|
10285 | result.y = line1StartY + (a * (line1EndY - line1StartY));
|
10286 |
|
10287 |
|
10288 | if (a >= 0 && a <= 1) {
|
10289 | result.onLine1 = true;
|
10290 | }
|
10291 |
|
10292 | if (b >= 0 && b <= 1) {
|
10293 | result.onLine2 = true;
|
10294 | }
|
10295 |
|
10296 | if (result.onLine1 && result.onLine2) {
|
10297 | return [result.x, result.y];
|
10298 | } else {
|
10299 | return false;
|
10300 | }
|
10301 | }
|
10302 |
|
10303 |
|
10304 |
|
10305 |
|
10306 |
|
10307 |
|
10308 |
|
10309 |
|
10310 |
|
10311 |
|
10312 |
|
10313 |
|
10314 |
|
10315 |
|
10316 |
|
10317 |
|
10318 |
|
10319 |
|
10320 |
|
10321 |
|
10322 |
|
10323 |
|
10324 |
|
10325 |
|
10326 |
|
10327 |
|
10328 |
|
10329 | function pointOnFeature(geojson) {
|
10330 |
|
10331 | var fc = normalize$1(geojson);
|
10332 |
|
10333 |
|
10334 | var cent = center(fc);
|
10335 |
|
10336 |
|
10337 | var onSurface = false;
|
10338 | var i = 0;
|
10339 | while (!onSurface && i < fc.features.length) {
|
10340 | var geom = fc.features[i].geometry;
|
10341 | var x, y, x1, y1, x2, y2, k;
|
10342 | var onLine = false;
|
10343 | if (geom.type === 'Point') {
|
10344 | if (cent.geometry.coordinates[0] === geom.coordinates[0] &&
|
10345 | cent.geometry.coordinates[1] === geom.coordinates[1]) {
|
10346 | onSurface = true;
|
10347 | }
|
10348 | } else if (geom.type === 'MultiPoint') {
|
10349 | var onMultiPoint = false;
|
10350 | k = 0;
|
10351 | while (!onMultiPoint && k < geom.coordinates.length) {
|
10352 | if (cent.geometry.coordinates[0] === geom.coordinates[k][0] &&
|
10353 | cent.geometry.coordinates[1] === geom.coordinates[k][1]) {
|
10354 | onSurface = true;
|
10355 | onMultiPoint = true;
|
10356 | }
|
10357 | k++;
|
10358 | }
|
10359 | } else if (geom.type === 'LineString') {
|
10360 | k = 0;
|
10361 | while (!onLine && k < geom.coordinates.length - 1) {
|
10362 | x = cent.geometry.coordinates[0];
|
10363 | y = cent.geometry.coordinates[1];
|
10364 | x1 = geom.coordinates[k][0];
|
10365 | y1 = geom.coordinates[k][1];
|
10366 | x2 = geom.coordinates[k + 1][0];
|
10367 | y2 = geom.coordinates[k + 1][1];
|
10368 | if (pointOnSegment(x, y, x1, y1, x2, y2)) {
|
10369 | onLine = true;
|
10370 | onSurface = true;
|
10371 | }
|
10372 | k++;
|
10373 | }
|
10374 | } else if (geom.type === 'MultiLineString') {
|
10375 | var j = 0;
|
10376 | while (j < geom.coordinates.length) {
|
10377 | onLine = false;
|
10378 | k = 0;
|
10379 | var line = geom.coordinates[j];
|
10380 | while (!onLine && k < line.length - 1) {
|
10381 | x = cent.geometry.coordinates[0];
|
10382 | y = cent.geometry.coordinates[1];
|
10383 | x1 = line[k][0];
|
10384 | y1 = line[k][1];
|
10385 | x2 = line[k + 1][0];
|
10386 | y2 = line[k + 1][1];
|
10387 | if (pointOnSegment(x, y, x1, y1, x2, y2)) {
|
10388 | onLine = true;
|
10389 | onSurface = true;
|
10390 | }
|
10391 | k++;
|
10392 | }
|
10393 | j++;
|
10394 | }
|
10395 | } else if (geom.type === 'Polygon' || geom.type === 'MultiPolygon') {
|
10396 | if (booleanPointInPolygon(cent, geom)) {
|
10397 | onSurface = true;
|
10398 | }
|
10399 | }
|
10400 | i++;
|
10401 | }
|
10402 | if (onSurface) {
|
10403 | return cent;
|
10404 | } else {
|
10405 | var vertices = featureCollection([]);
|
10406 | for (i = 0; i < fc.features.length; i++) {
|
10407 | vertices.features = vertices.features.concat(explode(fc.features[i]).features);
|
10408 | }
|
10409 |
|
10410 | return point(nearestPoint(cent, vertices).geometry.coordinates);
|
10411 | }
|
10412 | }
|
10413 |
|
10414 |
|
10415 |
|
10416 |
|
10417 |
|
10418 |
|
10419 |
|
10420 |
|
10421 |
|
10422 | function normalize$1(geojson) {
|
10423 | if (geojson.type !== 'FeatureCollection') {
|
10424 | if (geojson.type !== 'Feature') {
|
10425 | return featureCollection([feature(geojson)]);
|
10426 | }
|
10427 | return featureCollection([geojson]);
|
10428 | }
|
10429 | return geojson;
|
10430 | }
|
10431 |
|
10432 | function pointOnSegment(x, y, x1, y1, x2, y2) {
|
10433 | var ab = Math.sqrt((x2 - x1) * (x2 - x1) + (y2 - y1) * (y2 - y1));
|
10434 | var ap = Math.sqrt((x - x1) * (x - x1) + (y - y1) * (y - y1));
|
10435 | var pb = Math.sqrt((x2 - x) * (x2 - x) + (y2 - y) * (y2 - y));
|
10436 | return ab === ap + pb;
|
10437 | }
|
10438 |
|
10439 |
|
10440 |
|
10441 |
|
10442 |
|
10443 |
|
10444 |
|
10445 |
|
10446 |
|
10447 |
|
10448 |
|
10449 |
|
10450 |
|
10451 |
|
10452 |
|
10453 |
|
10454 | function area$1(geojson) {
|
10455 | return geomReduce(geojson, function (value, geom) {
|
10456 | return value + calculateArea(geom);
|
10457 | }, 0);
|
10458 | }
|
10459 |
|
10460 | var RADIUS = 6378137;
|
10461 |
|
10462 |
|
10463 |
|
10464 |
|
10465 |
|
10466 |
|
10467 |
|
10468 |
|
10469 |
|
10470 |
|
10471 |
|
10472 | function calculateArea(geojson) {
|
10473 | var area = 0, i;
|
10474 | switch (geojson.type) {
|
10475 | case 'Polygon':
|
10476 | return polygonArea(geojson.coordinates);
|
10477 | case 'MultiPolygon':
|
10478 | for (i = 0; i < geojson.coordinates.length; i++) {
|
10479 | area += polygonArea(geojson.coordinates[i]);
|
10480 | }
|
10481 | return area;
|
10482 | case 'Point':
|
10483 | case 'MultiPoint':
|
10484 | case 'LineString':
|
10485 | case 'MultiLineString':
|
10486 | return 0;
|
10487 | case 'GeometryCollection':
|
10488 | for (i = 0; i < geojson.geometries.length; i++) {
|
10489 | area += calculateArea(geojson.geometries[i]);
|
10490 | }
|
10491 | return area;
|
10492 | }
|
10493 | }
|
10494 |
|
10495 | function polygonArea(coords) {
|
10496 | var area = 0;
|
10497 | if (coords && coords.length > 0) {
|
10498 | area += Math.abs(ringArea(coords[0]));
|
10499 | for (var i = 1; i < coords.length; i++) {
|
10500 | area -= Math.abs(ringArea(coords[i]));
|
10501 | }
|
10502 | }
|
10503 | return area;
|
10504 | }
|
10505 |
|
10506 |
|
10507 |
|
10508 |
|
10509 |
|
10510 |
|
10511 |
|
10512 |
|
10513 |
|
10514 |
|
10515 |
|
10516 |
|
10517 |
|
10518 | function ringArea(coords) {
|
10519 | var p1;
|
10520 | var p2;
|
10521 | var p3;
|
10522 | var lowerIndex;
|
10523 | var middleIndex;
|
10524 | var upperIndex;
|
10525 | var i;
|
10526 | var area = 0;
|
10527 | var coordsLength = coords.length;
|
10528 |
|
10529 | if (coordsLength > 2) {
|
10530 | for (i = 0; i < coordsLength; i++) {
|
10531 | if (i === coordsLength - 2) {
|
10532 | lowerIndex = coordsLength - 2;
|
10533 | middleIndex = coordsLength - 1;
|
10534 | upperIndex = 0;
|
10535 | } else if (i === coordsLength - 1) {
|
10536 | lowerIndex = coordsLength - 1;
|
10537 | middleIndex = 0;
|
10538 | upperIndex = 1;
|
10539 | } else {
|
10540 | lowerIndex = i;
|
10541 | middleIndex = i + 1;
|
10542 | upperIndex = i + 2;
|
10543 | }
|
10544 | p1 = coords[lowerIndex];
|
10545 | p2 = coords[middleIndex];
|
10546 | p3 = coords[upperIndex];
|
10547 | area += (rad(p3[0]) - rad(p1[0])) * Math.sin(rad(p2[1]));
|
10548 | }
|
10549 |
|
10550 | area = area * RADIUS * RADIUS / 2;
|
10551 | }
|
10552 |
|
10553 | return area;
|
10554 | }
|
10555 |
|
10556 | function rad(_) {
|
10557 | return _ * Math.PI / 180;
|
10558 | }
|
10559 |
|
10560 |
|
10561 |
|
10562 |
|
10563 |
|
10564 |
|
10565 |
|
10566 |
|
10567 |
|
10568 |
|
10569 |
|
10570 |
|
10571 |
|
10572 |
|
10573 |
|
10574 |
|
10575 |
|
10576 |
|
10577 |
|
10578 | function along(line, distance$$1, options) {
|
10579 |
|
10580 | options = options || {};
|
10581 | if (!isObject(options)) throw new Error('options is invalid');
|
10582 |
|
10583 |
|
10584 | var coords;
|
10585 | if (line.type === 'Feature') coords = line.geometry.coordinates;
|
10586 | else if (line.type === 'LineString') coords = line.coordinates;
|
10587 | else throw new Error('input must be a LineString Feature or Geometry');
|
10588 | if (!isNumber(distance$$1)) throw new Error('distance must be a number');
|
10589 |
|
10590 | var travelled = 0;
|
10591 | for (var i = 0; i < coords.length; i++) {
|
10592 | if (distance$$1 >= travelled && i === coords.length - 1) break;
|
10593 | else if (travelled >= distance$$1) {
|
10594 | var overshot = distance$$1 - travelled;
|
10595 | if (!overshot) return point(coords[i]);
|
10596 | else {
|
10597 | var direction = bearing(coords[i], coords[i - 1]) - 180;
|
10598 | var interpolated = destination(coords[i], overshot, direction, options);
|
10599 | return interpolated;
|
10600 | }
|
10601 | } else {
|
10602 | travelled += distance(coords[i], coords[i + 1], options);
|
10603 | }
|
10604 | }
|
10605 | return point(coords[coords.length - 1]);
|
10606 | }
|
10607 |
|
10608 |
|
10609 |
|
10610 |
|
10611 |
|
10612 |
|
10613 |
|
10614 |
|
10615 |
|
10616 |
|
10617 |
|
10618 |
|
10619 |
|
10620 |
|
10621 |
|
10622 |
|
10623 |
|
10624 | function length(geojson, options) {
|
10625 |
|
10626 | options = options || {};
|
10627 | if (!isObject(options)) throw new Error('options is invalid');
|
10628 |
|
10629 |
|
10630 | if (!geojson) throw new Error('geojson is required');
|
10631 |
|
10632 |
|
10633 | return segmentReduce(geojson, function (previousValue, segment) {
|
10634 | var coords = segment.geometry.coordinates;
|
10635 | return previousValue + distance(coords[0], coords[1], options);
|
10636 | }, 0);
|
10637 | }
|
10638 |
|
10639 |
|
10640 |
|
10641 |
|
10642 |
|
10643 |
|
10644 |
|
10645 |
|
10646 |
|
10647 |
|
10648 |
|
10649 |
|
10650 |
|
10651 |
|
10652 |
|
10653 |
|
10654 |
|
10655 |
|
10656 |
|
10657 |
|
10658 |
|
10659 |
|
10660 |
|
10661 |
|
10662 |
|
10663 |
|
10664 |
|
10665 |
|
10666 |
|
10667 |
|
10668 | function lineSlice(startPt, stopPt, line) {
|
10669 |
|
10670 | var coords = getCoords(line);
|
10671 | if (getType(line) !== 'LineString') throw new Error('line must be a LineString');
|
10672 |
|
10673 | var startVertex = nearestPointOnLine(line, startPt);
|
10674 | var stopVertex = nearestPointOnLine(line, stopPt);
|
10675 | var ends;
|
10676 | if (startVertex.properties.index <= stopVertex.properties.index) {
|
10677 | ends = [startVertex, stopVertex];
|
10678 | } else {
|
10679 | ends = [stopVertex, startVertex];
|
10680 | }
|
10681 | var clipCoords = [ends[0].geometry.coordinates];
|
10682 | for (var i = ends[0].properties.index + 1; i < ends[1].properties.index + 1; i++) {
|
10683 | clipCoords.push(coords[i]);
|
10684 | }
|
10685 | clipCoords.push(ends[1].geometry.coordinates);
|
10686 | return lineString(clipCoords, line.properties);
|
10687 | }
|
10688 |
|
10689 |
|
10690 |
|
10691 |
|
10692 |
|
10693 |
|
10694 |
|
10695 |
|
10696 |
|
10697 |
|
10698 |
|
10699 |
|
10700 |
|
10701 |
|
10702 |
|
10703 |
|
10704 |
|
10705 |
|
10706 |
|
10707 |
|
10708 |
|
10709 |
|
10710 |
|
10711 |
|
10712 | function lineSliceAlong(line, startDist, stopDist, options) {
|
10713 |
|
10714 | options = options || {};
|
10715 | if (!isObject(options)) throw new Error('options is invalid');
|
10716 |
|
10717 | var coords;
|
10718 | var slice = [];
|
10719 |
|
10720 |
|
10721 | if (line.type === 'Feature') coords = line.geometry.coordinates;
|
10722 | else if (line.type === 'LineString') coords = line.coordinates;
|
10723 | else throw new Error('input must be a LineString Feature or Geometry');
|
10724 |
|
10725 | var travelled = 0;
|
10726 | var overshot, direction, interpolated;
|
10727 | for (var i = 0; i < coords.length; i++) {
|
10728 | if (startDist >= travelled && i === coords.length - 1) break;
|
10729 | else if (travelled > startDist && slice.length === 0) {
|
10730 | overshot = startDist - travelled;
|
10731 | if (!overshot) {
|
10732 | slice.push(coords[i]);
|
10733 | return lineString(slice);
|
10734 | }
|
10735 | direction = bearing(coords[i], coords[i - 1]) - 180;
|
10736 | interpolated = destination(coords[i], overshot, direction, options);
|
10737 | slice.push(interpolated.geometry.coordinates);
|
10738 | }
|
10739 |
|
10740 | if (travelled >= stopDist) {
|
10741 | overshot = stopDist - travelled;
|
10742 | if (!overshot) {
|
10743 | slice.push(coords[i]);
|
10744 | return lineString(slice);
|
10745 | }
|
10746 | direction = bearing(coords[i], coords[i - 1]) - 180;
|
10747 | interpolated = destination(coords[i], overshot, direction, options);
|
10748 | slice.push(interpolated.geometry.coordinates);
|
10749 | return lineString(slice);
|
10750 | }
|
10751 |
|
10752 | if (travelled >= startDist) {
|
10753 | slice.push(coords[i]);
|
10754 | }
|
10755 |
|
10756 | if (i === coords.length - 1) {
|
10757 | return lineString(slice);
|
10758 | }
|
10759 |
|
10760 | travelled += distance(coords[i], coords[i + 1], options);
|
10761 | }
|
10762 | return lineString(coords[coords.length - 1]);
|
10763 | }
|
10764 |
|
10765 |
|
10766 |
|
10767 |
|
10768 |
|
10769 |
|
10770 |
|
10771 |
|
10772 |
|
10773 |
|
10774 |
|
10775 |
|
10776 |
|
10777 |
|
10778 |
|
10779 |
|
10780 | function booleanPointOnLine(pt, line, options) {
|
10781 |
|
10782 | options = options || {};
|
10783 | var ignoreEndVertices = options.ignoreEndVertices;
|
10784 | if (!isObject(options)) throw new Error('invalid options');
|
10785 |
|
10786 |
|
10787 | if (!pt) throw new Error('pt is required');
|
10788 | if (!line) throw new Error('line is required');
|
10789 |
|
10790 |
|
10791 | var ptCoords = getCoord(pt);
|
10792 | var lineCoords = getCoords(line);
|
10793 |
|
10794 |
|
10795 | for (var i = 0; i < lineCoords.length - 1; i++) {
|
10796 | var ignoreBoundary = false;
|
10797 | if (ignoreEndVertices) {
|
10798 | if (i === 0) ignoreBoundary = 'start';
|
10799 | if (i === lineCoords.length - 2) ignoreBoundary = 'end';
|
10800 | if (i === 0 && i + 1 === lineCoords.length - 1) ignoreBoundary = 'both';
|
10801 | }
|
10802 | if (isPointOnLineSegment$1(lineCoords[i], lineCoords[i + 1], ptCoords, ignoreBoundary)) return true;
|
10803 | }
|
10804 | return false;
|
10805 | }
|
10806 |
|
10807 |
|
10808 |
|
10809 |
|
10810 |
|
10811 |
|
10812 |
|
10813 |
|
10814 |
|
10815 |
|
10816 | function isPointOnLineSegment$1(lineSegmentStart, lineSegmentEnd, pt, excludeBoundary) {
|
10817 | var x = pt[0];
|
10818 | var y = pt[1];
|
10819 | var x1 = lineSegmentStart[0];
|
10820 | var y1 = lineSegmentStart[1];
|
10821 | var x2 = lineSegmentEnd[0];
|
10822 | var y2 = lineSegmentEnd[1];
|
10823 | var dxc = pt[0] - x1;
|
10824 | var dyc = pt[1] - y1;
|
10825 | var dxl = x2 - x1;
|
10826 | var dyl = y2 - y1;
|
10827 | var cross = dxc * dyl - dyc * dxl;
|
10828 | if (cross !== 0) {
|
10829 | return false;
|
10830 | }
|
10831 | if (!excludeBoundary) {
|
10832 | if (Math.abs(dxl) >= Math.abs(dyl)) {
|
10833 | return dxl > 0 ? x1 <= x && x <= x2 : x2 <= x && x <= x1;
|
10834 | }
|
10835 | return dyl > 0 ? y1 <= y && y <= y2 : y2 <= y && y <= y1;
|
10836 | } else if (excludeBoundary === 'start') {
|
10837 | if (Math.abs(dxl) >= Math.abs(dyl)) {
|
10838 | return dxl > 0 ? x1 < x && x <= x2 : x2 <= x && x < x1;
|
10839 | }
|
10840 | return dyl > 0 ? y1 < y && y <= y2 : y2 <= y && y < y1;
|
10841 | } else if (excludeBoundary === 'end') {
|
10842 | if (Math.abs(dxl) >= Math.abs(dyl)) {
|
10843 | return dxl > 0 ? x1 <= x && x < x2 : x2 < x && x <= x1;
|
10844 | }
|
10845 | return dyl > 0 ? y1 <= y && y < y2 : y2 < y && y <= y1;
|
10846 | } else if (excludeBoundary === 'both') {
|
10847 | if (Math.abs(dxl) >= Math.abs(dyl)) {
|
10848 | return dxl > 0 ? x1 < x && x < x2 : x2 < x && x < x1;
|
10849 | }
|
10850 | return dyl > 0 ? y1 < y && y < y2 : y2 < y && y < y1;
|
10851 | }
|
10852 | }
|
10853 |
|
10854 |
|
10855 |
|
10856 |
|
10857 |
|
10858 |
|
10859 |
|
10860 |
|
10861 |
|
10862 |
|
10863 |
|
10864 |
|
10865 |
|
10866 |
|
10867 |
|
10868 |
|
10869 |
|
10870 |
|
10871 | function booleanWithin(feature1, feature2) {
|
10872 | var type1 = getType(feature1);
|
10873 | var type2 = getType(feature2);
|
10874 | var geom1 = getGeom(feature1);
|
10875 | var geom2 = getGeom(feature2);
|
10876 |
|
10877 | switch (type1) {
|
10878 | case 'Point':
|
10879 | switch (type2) {
|
10880 | case 'MultiPoint':
|
10881 | return isPointInMultiPoint(geom1, geom2);
|
10882 | case 'LineString':
|
10883 | return booleanPointOnLine(geom1, geom2, {ignoreEndVertices: true});
|
10884 | case 'Polygon':
|
10885 | return booleanPointInPolygon(geom1, geom2, {ignoreBoundary: true});
|
10886 | default:
|
10887 | throw new Error('feature2 ' + type2 + ' geometry not supported');
|
10888 | }
|
10889 | case 'MultiPoint':
|
10890 | switch (type2) {
|
10891 | case 'MultiPoint':
|
10892 | return isMultiPointInMultiPoint(geom1, geom2);
|
10893 | case 'LineString':
|
10894 | return isMultiPointOnLine(geom1, geom2);
|
10895 | case 'Polygon':
|
10896 | return isMultiPointInPoly(geom1, geom2);
|
10897 | default:
|
10898 | throw new Error('feature2 ' + type2 + ' geometry not supported');
|
10899 | }
|
10900 | case 'LineString':
|
10901 | switch (type2) {
|
10902 | case 'LineString':
|
10903 | return isLineOnLine(geom1, geom2);
|
10904 | case 'Polygon':
|
10905 | return isLineInPoly(geom1, geom2);
|
10906 | default:
|
10907 | throw new Error('feature2 ' + type2 + ' geometry not supported');
|
10908 | }
|
10909 | case 'Polygon':
|
10910 | switch (type2) {
|
10911 | case 'Polygon':
|
10912 | return isPolyInPoly(geom1, geom2);
|
10913 | default:
|
10914 | throw new Error('feature2 ' + type2 + ' geometry not supported');
|
10915 | }
|
10916 | default:
|
10917 | throw new Error('feature1 ' + type1 + ' geometry not supported');
|
10918 | }
|
10919 | }
|
10920 |
|
10921 | function isPointInMultiPoint(point, multiPoint) {
|
10922 | var i;
|
10923 | var output = false;
|
10924 | for (i = 0; i < multiPoint.coordinates.length; i++) {
|
10925 | if (compareCoords(multiPoint.coordinates[i], point.coordinates)) {
|
10926 | output = true;
|
10927 | break;
|
10928 | }
|
10929 | }
|
10930 | return output;
|
10931 | }
|
10932 |
|
10933 | function isMultiPointInMultiPoint(multiPoint1, multiPoint2) {
|
10934 | for (var i = 0; i < multiPoint1.coordinates.length; i++) {
|
10935 | var anyMatch = false;
|
10936 | for (var i2 = 0; i2 < multiPoint2.coordinates.length; i2++) {
|
10937 | if (compareCoords(multiPoint1.coordinates[i], multiPoint2.coordinates[i2])) {
|
10938 | anyMatch = true;
|
10939 | }
|
10940 | }
|
10941 | if (!anyMatch) {
|
10942 | return false;
|
10943 | }
|
10944 | }
|
10945 | return true;
|
10946 | }
|
10947 |
|
10948 | function isMultiPointOnLine(multiPoint, lineString) {
|
10949 | var foundInsidePoint = false;
|
10950 |
|
10951 | for (var i = 0; i < multiPoint.coordinates.length; i++) {
|
10952 | if (!booleanPointOnLine(multiPoint.coordinates[i], lineString)) {
|
10953 | return false;
|
10954 | }
|
10955 | if (!foundInsidePoint) {
|
10956 | foundInsidePoint = booleanPointOnLine(multiPoint.coordinates[i], lineString, {ignoreEndVertices: true});
|
10957 | }
|
10958 | }
|
10959 | return foundInsidePoint;
|
10960 | }
|
10961 |
|
10962 | function isMultiPointInPoly(multiPoint, polygon) {
|
10963 | var output = true;
|
10964 | var oneInside = false;
|
10965 | for (var i = 0; i < multiPoint.coordinates.length; i++) {
|
10966 | var isInside = booleanPointInPolygon(multiPoint.coordinates[1], polygon);
|
10967 | if (!isInside) {
|
10968 | output = false;
|
10969 | break;
|
10970 | }
|
10971 | if (!oneInside) {
|
10972 | isInside = booleanPointInPolygon(multiPoint.coordinates[1], polygon, {ignoreBoundary: true});
|
10973 | }
|
10974 | }
|
10975 | return output && isInside;
|
10976 | }
|
10977 |
|
10978 | function isLineOnLine(lineString1, lineString2) {
|
10979 | for (var i = 0; i < lineString1.coordinates.length; i++) {
|
10980 | if (!booleanPointOnLine(lineString1.coordinates[i], lineString2)) {
|
10981 | return false;
|
10982 | }
|
10983 | }
|
10984 | return true;
|
10985 | }
|
10986 |
|
10987 | function isLineInPoly(linestring, polygon) {
|
10988 | var polyBbox = bbox(polygon);
|
10989 | var lineBbox = bbox(linestring);
|
10990 | if (!doBBoxOverlap(polyBbox, lineBbox)) {
|
10991 | return false;
|
10992 | }
|
10993 | var foundInsidePoint = false;
|
10994 |
|
10995 | for (var i = 0; i < linestring.coordinates.length - 1; i++) {
|
10996 | if (!booleanPointInPolygon(linestring.coordinates[i], polygon)) {
|
10997 | return false;
|
10998 | }
|
10999 | if (!foundInsidePoint) {
|
11000 | foundInsidePoint = booleanPointInPolygon(linestring.coordinates[i], polygon, {ignoreBoundary: true});
|
11001 | }
|
11002 | if (!foundInsidePoint) {
|
11003 | var midpoint = getMidpoint(linestring.coordinates[i], linestring.coordinates[i + 1]);
|
11004 | foundInsidePoint = booleanPointInPolygon(midpoint, polygon, {ignoreBoundary: true});
|
11005 |
|
11006 | }
|
11007 | }
|
11008 | return foundInsidePoint;
|
11009 | }
|
11010 |
|
11011 |
|
11012 |
|
11013 |
|
11014 |
|
11015 |
|
11016 |
|
11017 |
|
11018 |
|
11019 |
|
11020 | function isPolyInPoly(feature1, feature2) {
|
11021 | var poly1Bbox = bbox(feature1);
|
11022 | var poly2Bbox = bbox(feature2);
|
11023 | if (!doBBoxOverlap(poly2Bbox, poly1Bbox)) {
|
11024 | return false;
|
11025 | }
|
11026 | for (var i = 0; i < feature1.coordinates[0].length; i++) {
|
11027 | if (!booleanPointInPolygon(feature1.coordinates[0][i], feature2)) {
|
11028 | return false;
|
11029 | }
|
11030 | }
|
11031 | return true;
|
11032 | }
|
11033 |
|
11034 | function doBBoxOverlap(bbox1, bbox2) {
|
11035 | if (bbox1[0] > bbox2[0]) return false;
|
11036 | if (bbox1[2] < bbox2[2]) return false;
|
11037 | if (bbox1[1] > bbox2[1]) return false;
|
11038 | if (bbox1[3] < bbox2[3]) return false;
|
11039 | return true;
|
11040 | }
|
11041 |
|
11042 |
|
11043 |
|
11044 |
|
11045 |
|
11046 |
|
11047 |
|
11048 |
|
11049 |
|
11050 | function compareCoords(pair1, pair2) {
|
11051 | return pair1[0] === pair2[0] && pair1[1] === pair2[1];
|
11052 | }
|
11053 |
|
11054 |
|
11055 |
|
11056 |
|
11057 |
|
11058 |
|
11059 |
|
11060 |
|
11061 |
|
11062 | function getMidpoint(pair1, pair2) {
|
11063 | return [(pair1[0] + pair2[0]) / 2, (pair1[1] + pair2[1]) / 2];
|
11064 | }
|
11065 |
|
11066 |
|
11067 |
|
11068 |
|
11069 |
|
11070 |
|
11071 |
|
11072 |
|
11073 |
|
11074 |
|
11075 |
|
11076 |
|
11077 |
|
11078 |
|
11079 |
|
11080 |
|
11081 |
|
11082 |
|
11083 |
|
11084 |
|
11085 |
|
11086 |
|
11087 | function pointGrid(bbox, cellSide, options) {
|
11088 |
|
11089 | options = options || {};
|
11090 | if (!isObject(options)) throw new Error('options is invalid');
|
11091 |
|
11092 | var mask = options.mask;
|
11093 | var properties = options.properties;
|
11094 |
|
11095 |
|
11096 | var results = [];
|
11097 |
|
11098 |
|
11099 | if (cellSide === null || cellSide === undefined) throw new Error('cellSide is required');
|
11100 | if (!isNumber(cellSide)) throw new Error('cellSide is invalid');
|
11101 | if (!bbox) throw new Error('bbox is required');
|
11102 | if (!Array.isArray(bbox)) throw new Error('bbox must be array');
|
11103 | if (bbox.length !== 4) throw new Error('bbox must contain 4 numbers');
|
11104 | if (mask && ['Polygon', 'MultiPolygon'].indexOf(getType(mask)) === -1) throw new Error('options.mask must be a (Multi)Polygon');
|
11105 |
|
11106 | var west = bbox[0];
|
11107 | var south = bbox[1];
|
11108 | var east = bbox[2];
|
11109 | var north = bbox[3];
|
11110 |
|
11111 | var xFraction = cellSide / (distance([west, south], [east, south], options));
|
11112 | var cellWidth = xFraction * (east - west);
|
11113 | var yFraction = cellSide / (distance([west, south], [west, north], options));
|
11114 | var cellHeight = yFraction * (north - south);
|
11115 |
|
11116 | var bboxWidth = (east - west);
|
11117 | var bboxHeight = (north - south);
|
11118 | var columns = Math.floor(bboxWidth / cellWidth);
|
11119 | var rows = Math.floor(bboxHeight / cellHeight);
|
11120 |
|
11121 | var deltaX = (bboxWidth - columns * cellWidth) / 2;
|
11122 | var deltaY = (bboxHeight - rows * cellHeight) / 2;
|
11123 |
|
11124 | var currentX = west + deltaX;
|
11125 | while (currentX <= east) {
|
11126 | var currentY = south + deltaY;
|
11127 | while (currentY <= north) {
|
11128 | var cellPt = point([currentX, currentY], properties);
|
11129 | if (mask) {
|
11130 | if (booleanWithin(cellPt, mask)) results.push(cellPt);
|
11131 | } else {
|
11132 | results.push(cellPt);
|
11133 | }
|
11134 | currentY += cellHeight;
|
11135 | }
|
11136 | currentX += cellWidth;
|
11137 | }
|
11138 |
|
11139 | return featureCollection(results);
|
11140 | }
|
11141 |
|
11142 |
|
11143 |
|
11144 |
|
11145 |
|
11146 |
|
11147 |
|
11148 |
|
11149 |
|
11150 |
|
11151 |
|
11152 |
|
11153 |
|
11154 |
|
11155 |
|
11156 |
|
11157 |
|
11158 |
|
11159 |
|
11160 |
|
11161 |
|
11162 |
|
11163 |
|
11164 |
|
11165 | function truncate(geojson, options) {
|
11166 |
|
11167 | options = options || {};
|
11168 | if (!isObject(options)) throw new Error('options is invalid');
|
11169 | var precision = options.precision;
|
11170 | var coordinates = options.coordinates;
|
11171 | var mutate = options.mutate;
|
11172 |
|
11173 |
|
11174 | precision = (precision === undefined || precision === null || isNaN(precision)) ? 6 : precision;
|
11175 | coordinates = (coordinates === undefined || coordinates === null || isNaN(coordinates)) ? 3 : coordinates;
|
11176 |
|
11177 |
|
11178 | if (!geojson) throw new Error('<geojson> is required');
|
11179 | if (typeof precision !== 'number') throw new Error('<precision> must be a number');
|
11180 | if (typeof coordinates !== 'number') throw new Error('<coordinates> must be a number');
|
11181 |
|
11182 |
|
11183 | if (mutate === false || mutate === undefined) geojson = JSON.parse(JSON.stringify(geojson));
|
11184 |
|
11185 | var factor = Math.pow(10, precision);
|
11186 |
|
11187 |
|
11188 | coordEach(geojson, function (coords) {
|
11189 | truncateCoords(coords, factor, coordinates);
|
11190 | });
|
11191 | return geojson;
|
11192 | }
|
11193 |
|
11194 |
|
11195 |
|
11196 |
|
11197 |
|
11198 |
|
11199 |
|
11200 |
|
11201 |
|
11202 |
|
11203 | function truncateCoords(coords, factor, coordinates) {
|
11204 |
|
11205 | if (coords.length > coordinates) coords.splice(coordinates, coords.length);
|
11206 |
|
11207 |
|
11208 | for (var i = 0; i < coords.length; i++) {
|
11209 | coords[i] = Math.round(coords[i] * factor) / factor;
|
11210 | }
|
11211 | return coords;
|
11212 | }
|
11213 |
|
11214 |
|
11215 |
|
11216 |
|
11217 |
|
11218 |
|
11219 |
|
11220 |
|
11221 |
|
11222 |
|
11223 |
|
11224 |
|
11225 |
|
11226 |
|
11227 |
|
11228 |
|
11229 |
|
11230 |
|
11231 |
|
11232 | function flatten(geojson) {
|
11233 | if (!geojson) throw new Error('geojson is required');
|
11234 |
|
11235 | var results = [];
|
11236 | flattenEach(geojson, function (feature$$1) {
|
11237 | results.push(feature$$1);
|
11238 | });
|
11239 | return featureCollection(results);
|
11240 | }
|
11241 |
|
11242 |
|
11243 |
|
11244 |
|
11245 |
|
11246 |
|
11247 |
|
11248 |
|
11249 |
|
11250 |
|
11251 |
|
11252 |
|
11253 |
|
11254 |
|
11255 |
|
11256 |
|
11257 |
|
11258 |
|
11259 |
|
11260 |
|
11261 | function lineChunk(geojson, segmentLength, options) {
|
11262 |
|
11263 | options = options || {};
|
11264 | if (!isObject(options)) throw new Error('options is invalid');
|
11265 | var units = options.units;
|
11266 | var reverse = options.reverse;
|
11267 |
|
11268 |
|
11269 | if (!geojson) throw new Error('geojson is required');
|
11270 | if (segmentLength <= 0) throw new Error('segmentLength must be greater than 0');
|
11271 |
|
11272 |
|
11273 | var results = [];
|
11274 |
|
11275 |
|
11276 | flattenEach(geojson, function (feature$$1) {
|
11277 |
|
11278 | if (reverse) feature$$1.geometry.coordinates = feature$$1.geometry.coordinates.reverse();
|
11279 |
|
11280 | sliceLineSegments(feature$$1, segmentLength, units, function (segment) {
|
11281 | results.push(segment);
|
11282 | });
|
11283 | });
|
11284 | return featureCollection(results);
|
11285 | }
|
11286 |
|
11287 |
|
11288 |
|
11289 |
|
11290 |
|
11291 |
|
11292 |
|
11293 |
|
11294 |
|
11295 |
|
11296 |
|
11297 | function sliceLineSegments(line, segmentLength, units, callback) {
|
11298 | var lineLength = length(line, {units: units});
|
11299 |
|
11300 |
|
11301 | if (lineLength <= segmentLength) return callback(line);
|
11302 |
|
11303 | var numberOfSegments = lineLength / segmentLength;
|
11304 |
|
11305 |
|
11306 | if (!Number.isInteger(numberOfSegments)) {
|
11307 | numberOfSegments = Math.floor(numberOfSegments) + 1;
|
11308 | }
|
11309 |
|
11310 | for (var i = 0; i < numberOfSegments; i++) {
|
11311 | var outline = lineSliceAlong(line, segmentLength * i, segmentLength * (i + 1), {units: units});
|
11312 | callback(outline, i);
|
11313 | }
|
11314 | }
|
11315 |
|
11316 |
|
11317 | var isects = function (feature$$1, filterFn, useSpatialIndex) {
|
11318 | if (feature$$1.geometry.type !== 'Polygon') throw new Error('The input feature must be a Polygon');
|
11319 | if (useSpatialIndex === undefined) useSpatialIndex = 1;
|
11320 |
|
11321 | var coord = feature$$1.geometry.coordinates;
|
11322 |
|
11323 | var output = [];
|
11324 | var seen = {};
|
11325 |
|
11326 | if (useSpatialIndex) {
|
11327 | var allEdgesAsRbushTreeItems = [];
|
11328 | for (var ring0 = 0; ring0 < coord.length; ring0++) {
|
11329 | for (var edge0 = 0; edge0 < coord[ring0].length - 1; edge0++) {
|
11330 | allEdgesAsRbushTreeItems.push(rbushTreeItem(ring0, edge0));
|
11331 | }
|
11332 | }
|
11333 | var tree = rbush_1();
|
11334 | tree.load(allEdgesAsRbushTreeItems);
|
11335 | }
|
11336 |
|
11337 | for (var ringA = 0; ringA < coord.length; ringA++) {
|
11338 | for (var edgeA = 0; edgeA < coord[ringA].length - 1; edgeA++) {
|
11339 | if (useSpatialIndex) {
|
11340 | var bboxOverlaps = tree.search(rbushTreeItem(ringA, edgeA));
|
11341 | bboxOverlaps.forEach(function (bboxIsect) {
|
11342 | var ring1 = bboxIsect.ring;
|
11343 | var edge1 = bboxIsect.edge;
|
11344 | ifIsectAddToOutput(ringA, edgeA, ring1, edge1);
|
11345 | });
|
11346 | } else {
|
11347 | for (var ring1 = 0; ring1 < coord.length; ring1++) {
|
11348 | for (var edge1 = 0; edge1 < coord[ring1].length - 1; edge1++) {
|
11349 |
|
11350 | ifIsectAddToOutput(ringA, edgeA, ring1, edge1);
|
11351 | }
|
11352 | }
|
11353 | }
|
11354 | }
|
11355 | }
|
11356 |
|
11357 | if (!filterFn) output = {type: 'Feature', geometry: {type: 'MultiPoint', coordinates: output}};
|
11358 | return output;
|
11359 |
|
11360 |
|
11361 | function ifIsectAddToOutput(ring0, edge0, ring1, edge1) {
|
11362 | var start0 = coord[ring0][edge0];
|
11363 | var end0 = coord[ring0][edge0 + 1];
|
11364 | var start1 = coord[ring1][edge1];
|
11365 | var end1 = coord[ring1][edge1 + 1];
|
11366 |
|
11367 | var isect = intersect(start0, end0, start1, end1);
|
11368 |
|
11369 | if (isect === null) return;
|
11370 | var frac0;
|
11371 | var frac1;
|
11372 | if (end0[0] !== start0[0]) {
|
11373 | frac0 = (isect[0] - start0[0]) / (end0[0] - start0[0]);
|
11374 | } else {
|
11375 | frac0 = (isect[1] - start0[1]) / (end0[1] - start0[1]);
|
11376 | }
|
11377 | if (end1[0] !== start1[0]) {
|
11378 | frac1 = (isect[0] - start1[0]) / (end1[0] - start1[0]);
|
11379 | } else {
|
11380 | frac1 = (isect[1] - start1[1]) / (end1[1] - start1[1]);
|
11381 | }
|
11382 | if (frac0 >= 1 || frac0 <= 0 || frac1 >= 1 || frac1 <= 0) return;
|
11383 |
|
11384 | var key = isect;
|
11385 | var unique = !seen[key];
|
11386 | if (unique) {
|
11387 | seen[key] = true;
|
11388 | }
|
11389 |
|
11390 | if (filterFn) {
|
11391 | output.push(filterFn(isect, ring0, edge0, start0, end0, frac0, ring1, edge1, start1, end1, frac1, unique));
|
11392 | } else {
|
11393 | output.push(isect);
|
11394 | }
|
11395 | }
|
11396 |
|
11397 |
|
11398 | function rbushTreeItem(ring, edge) {
|
11399 |
|
11400 | var start = coord[ring][edge];
|
11401 | var end = coord[ring][edge + 1];
|
11402 | var minX;
|
11403 | var maxX;
|
11404 | var minY;
|
11405 | var maxY;
|
11406 | if (start[0] < end[0]) {
|
11407 | minX = start[0];
|
11408 | maxX = end[0];
|
11409 | } else {
|
11410 | minX = end[0];
|
11411 | maxX = start[0];
|
11412 | }
|
11413 | if (start[1] < end[1]) {
|
11414 | minY = start[1];
|
11415 | maxY = end[1];
|
11416 | } else {
|
11417 | minY = end[1];
|
11418 | maxY = start[1];
|
11419 | }
|
11420 | return {minX: minX, minY: minY, maxX: maxX, maxY: maxY, ring: ring, edge: edge};
|
11421 | }
|
11422 | };
|
11423 |
|
11424 |
|
11425 | function intersect(start0, end0, start1, end1) {
|
11426 | if (equalArrays$1(start0, start1) || equalArrays$1(start0, end1) || equalArrays$1(end0, start1) || equalArrays$1(end1, start1)) return null;
|
11427 | var x0 = start0[0],
|
11428 | y0 = start0[1],
|
11429 | x1 = end0[0],
|
11430 | y1 = end0[1],
|
11431 | x2 = start1[0],
|
11432 | y2 = start1[1],
|
11433 | x3 = end1[0],
|
11434 | y3 = end1[1];
|
11435 | var denom = (x0 - x1) * (y2 - y3) - (y0 - y1) * (x2 - x3);
|
11436 | if (denom === 0) return null;
|
11437 | var x4 = ((x0 * y1 - y0 * x1) * (x2 - x3) - (x0 - x1) * (x2 * y3 - y2 * x3)) / denom;
|
11438 | var y4 = ((x0 * y1 - y0 * x1) * (y2 - y3) - (y0 - y1) * (x2 * y3 - y2 * x3)) / denom;
|
11439 | return [x4, y4];
|
11440 | }
|
11441 |
|
11442 |
|
11443 | function equalArrays$1(array1, array2) {
|
11444 |
|
11445 | if (!array1 || !array2)
|
11446 | return false;
|
11447 |
|
11448 |
|
11449 | if (array1.length !== array2.length)
|
11450 | return false;
|
11451 |
|
11452 | for (var i = 0, l = array1.length; i < l; i++) {
|
11453 |
|
11454 | if (array1[i] instanceof Array && array2[i] instanceof Array) {
|
11455 |
|
11456 | if (!equalArrays$1(array1[i], array2[i]))
|
11457 | return false;
|
11458 | } else if (array1[i] !== array2[i]) {
|
11459 |
|
11460 | return false;
|
11461 | }
|
11462 | }
|
11463 | return true;
|
11464 | }
|
11465 |
|
11466 |
|
11467 |
|
11468 |
|
11469 |
|
11470 |
|
11471 |
|
11472 |
|
11473 |
|
11474 |
|
11475 |
|
11476 |
|
11477 |
|
11478 |
|
11479 |
|
11480 |
|
11481 |
|
11482 |
|
11483 |
|
11484 |
|
11485 |
|
11486 |
|
11487 | var simplepolygon = function (feature$$1) {
|
11488 |
|
11489 | if (feature$$1.type != 'Feature') throw new Error('The input must a geojson object of type Feature');
|
11490 | if ((feature$$1.geometry === undefined) || (feature$$1.geometry == null)) throw new Error('The input must a geojson object with a non-empty geometry');
|
11491 | if (feature$$1.geometry.type != 'Polygon') throw new Error('The input must be a geojson Polygon');
|
11492 |
|
11493 |
|
11494 | var numRings = feature$$1.geometry.coordinates.length;
|
11495 | var vertices = [];
|
11496 | for (var i = 0; i < numRings; i++) {
|
11497 | var ring = feature$$1.geometry.coordinates[i];
|
11498 | if (!equalArrays(ring[0], ring[ring.length - 1])) {
|
11499 | ring.push(ring[0]);
|
11500 | }
|
11501 | vertices.push.apply(vertices, ring.slice(0, ring.length - 1));
|
11502 | }
|
11503 | if (!isUnique(vertices)) throw new Error('The input polygon may not have duplicate vertices (except for the first and last vertex of each ring)');
|
11504 | var numvertices = vertices.length;
|
11505 |
|
11506 |
|
11507 | var selfIsectsData = isects(feature$$1, function filterFn(isect, ring0, edge0, start0, end0, frac0, ring1, edge1, start1, end1, frac1, unique) {
|
11508 | return [isect, ring0, edge0, start0, end0, frac0, ring1, edge1, start1, end1, frac1, unique];
|
11509 | });
|
11510 | var numSelfIsect = selfIsectsData.length;
|
11511 |
|
11512 |
|
11513 | if (numSelfIsect == 0) {
|
11514 | var outputFeatureArray = [];
|
11515 | for (var i = 0; i < numRings; i++) {
|
11516 | outputFeatureArray.push(polygon([feature$$1.geometry.coordinates[i]], {parent: -1, winding: windingOfRing(feature$$1.geometry.coordinates[i])}));
|
11517 | }
|
11518 | var output = featureCollection(outputFeatureArray);
|
11519 | determineParents();
|
11520 | setNetWinding();
|
11521 |
|
11522 | return output;
|
11523 | }
|
11524 |
|
11525 |
|
11526 |
|
11527 |
|
11528 | var pseudoVtxListByRingAndEdge = [];
|
11529 |
|
11530 | var isectList = [];
|
11531 |
|
11532 | for (var i = 0; i < numRings; i++) {
|
11533 | pseudoVtxListByRingAndEdge.push([]);
|
11534 | for (var j = 0; j < feature$$1.geometry.coordinates[i].length - 1; j++) {
|
11535 |
|
11536 | pseudoVtxListByRingAndEdge[i].push([new PseudoVtx(feature$$1.geometry.coordinates[i][(j + 1).modulo(feature$$1.geometry.coordinates[i].length - 1)], 1, [i, j], [i, (j + 1).modulo(feature$$1.geometry.coordinates[i].length - 1)], undefined)]);
|
11537 |
|
11538 | isectList.push(new Isect(feature$$1.geometry.coordinates[i][j], [i, (j - 1).modulo(feature$$1.geometry.coordinates[i].length - 1)], [i, j], undefined, undefined, false, true));
|
11539 | }
|
11540 | }
|
11541 |
|
11542 | for (var i = 0; i < numSelfIsect; i++) {
|
11543 |
|
11544 | pseudoVtxListByRingAndEdge[selfIsectsData[i][1]][selfIsectsData[i][2]].push(new PseudoVtx(selfIsectsData[i][0], selfIsectsData[i][5], [selfIsectsData[i][1], selfIsectsData[i][2]], [selfIsectsData[i][6], selfIsectsData[i][7]], undefined));
|
11545 |
|
11546 | if (selfIsectsData[i][11]) isectList.push(new Isect(selfIsectsData[i][0], [selfIsectsData[i][1], selfIsectsData[i][2]], [selfIsectsData[i][6], selfIsectsData[i][7]], undefined, undefined, true, true));
|
11547 | }
|
11548 | var numIsect = isectList.length;
|
11549 |
|
11550 | for (var i = 0; i < pseudoVtxListByRingAndEdge.length; i++) {
|
11551 | for (var j = 0; j < pseudoVtxListByRingAndEdge[i].length; j++) {
|
11552 | pseudoVtxListByRingAndEdge[i][j].sort(function (a, b) { return (a.param < b.param) ? -1 : 1; });
|
11553 | }
|
11554 | }
|
11555 |
|
11556 |
|
11557 | var allIsectsAsIsectRbushTreeItem = [];
|
11558 | for (var i = 0; i < numIsect; i++) {
|
11559 | allIsectsAsIsectRbushTreeItem.push({minX: isectList[i].coord[0], minY: isectList[i].coord[1], maxX: isectList[i].coord[0], maxY: isectList[i].coord[1], index: i});
|
11560 | }
|
11561 | var isectRbushTree = rbush_1();
|
11562 | isectRbushTree.load(allIsectsAsIsectRbushTreeItem);
|
11563 |
|
11564 |
|
11565 |
|
11566 |
|
11567 | for (var i = 0; i < pseudoVtxListByRingAndEdge.length; i++) {
|
11568 | for (var j = 0; j < pseudoVtxListByRingAndEdge[i].length; j++) {
|
11569 | for (var k = 0; k < pseudoVtxListByRingAndEdge[i][j].length; k++) {
|
11570 | var coordToFind;
|
11571 | if (k == pseudoVtxListByRingAndEdge[i][j].length - 1) {
|
11572 | coordToFind = pseudoVtxListByRingAndEdge[i][(j + 1).modulo(feature$$1.geometry.coordinates[i].length - 1)][0].coord;
|
11573 | } else {
|
11574 | coordToFind = pseudoVtxListByRingAndEdge[i][j][k + 1].coord;
|
11575 | }
|
11576 | var IsectRbushTreeItemFound = isectRbushTree.search({minX: coordToFind[0], minY: coordToFind[1], maxX: coordToFind[0], maxY: coordToFind[1]})[0];
|
11577 | pseudoVtxListByRingAndEdge[i][j][k].nxtIsectAlongEdgeIn = IsectRbushTreeItemFound.index;
|
11578 | }
|
11579 | }
|
11580 | }
|
11581 |
|
11582 |
|
11583 | for (var i = 0; i < pseudoVtxListByRingAndEdge.length; i++) {
|
11584 | for (var j = 0; j < pseudoVtxListByRingAndEdge[i].length; j++) {
|
11585 | for (var k = 0; k < pseudoVtxListByRingAndEdge[i][j].length; k++) {
|
11586 | var coordToFind = pseudoVtxListByRingAndEdge[i][j][k].coord;
|
11587 | var IsectRbushTreeItemFound = isectRbushTree.search({minX: coordToFind[0], minY: coordToFind[1], maxX: coordToFind[0], maxY: coordToFind[1]})[0];
|
11588 | var l = IsectRbushTreeItemFound.index;
|
11589 | if (l < numvertices) {
|
11590 | isectList[l].nxtIsectAlongRingAndEdge2 = pseudoVtxListByRingAndEdge[i][j][k].nxtIsectAlongEdgeIn;
|
11591 | } else {
|
11592 | if (equalArrays(isectList[l].ringAndEdge1, pseudoVtxListByRingAndEdge[i][j][k].ringAndEdgeIn)) {
|
11593 | isectList[l].nxtIsectAlongRingAndEdge1 = pseudoVtxListByRingAndEdge[i][j][k].nxtIsectAlongEdgeIn;
|
11594 | } else {
|
11595 | isectList[l].nxtIsectAlongRingAndEdge2 = pseudoVtxListByRingAndEdge[i][j][k].nxtIsectAlongEdgeIn;
|
11596 | }
|
11597 | }
|
11598 | }
|
11599 | }
|
11600 | }
|
11601 |
|
11602 |
|
11603 |
|
11604 |
|
11605 | var queue = [];
|
11606 |
|
11607 | var i = 0;
|
11608 | for (var j = 0; j < numRings; j++) {
|
11609 | var leftIsect = i;
|
11610 | for (var k = 0; k < feature$$1.geometry.coordinates[j].length - 1; k++) {
|
11611 | if (isectList[i].coord[0] < isectList[leftIsect].coord[0]) {
|
11612 | leftIsect = i;
|
11613 | }
|
11614 | i++;
|
11615 | }
|
11616 |
|
11617 |
|
11618 | var isectAfterLeftIsect = isectList[leftIsect].nxtIsectAlongRingAndEdge2;
|
11619 | for (var k = 0; k < isectList.length; k++) {
|
11620 | if ((isectList[k].nxtIsectAlongRingAndEdge1 == leftIsect) || (isectList[k].nxtIsectAlongRingAndEdge2 == leftIsect)) {
|
11621 | var isectBeforeLeftIsect = k;
|
11622 | break;
|
11623 | }
|
11624 | }
|
11625 | var windingAtIsect = isConvex([isectList[isectBeforeLeftIsect].coord, isectList[leftIsect].coord, isectList[isectAfterLeftIsect].coord], true) ? 1 : -1;
|
11626 |
|
11627 | queue.push({isect: leftIsect, parent: -1, winding: windingAtIsect});
|
11628 | }
|
11629 |
|
11630 | queue.sort(function (a, b) { return (isectList[a.isect].coord > isectList[b.isect].coord) ? -1 : 1; });
|
11631 |
|
11632 |
|
11633 | var outputFeatureArray = [];
|
11634 |
|
11635 |
|
11636 | while (queue.length > 0) {
|
11637 |
|
11638 | var popped = queue.pop();
|
11639 | var startIsect = popped.isect;
|
11640 | var currentOutputRingParent = popped.parent;
|
11641 | var currentOutputRingWinding = popped.winding;
|
11642 |
|
11643 | var currentOutputRing = outputFeatureArray.length;
|
11644 | var currentOutputRingCoords = [isectList[startIsect].coord];
|
11645 |
|
11646 | var currentIsect = startIsect;
|
11647 | if (isectList[startIsect].ringAndEdge1Walkable) {
|
11648 | var walkingRingAndEdge = isectList[startIsect].ringAndEdge1;
|
11649 | var nxtIsect = isectList[startIsect].nxtIsectAlongRingAndEdge1;
|
11650 | } else {
|
11651 | var walkingRingAndEdge = isectList[startIsect].ringAndEdge2;
|
11652 | var nxtIsect = isectList[startIsect].nxtIsectAlongRingAndEdge2;
|
11653 | }
|
11654 |
|
11655 | while (!equalArrays(isectList[startIsect].coord, isectList[nxtIsect].coord)) {
|
11656 | currentOutputRingCoords.push(isectList[nxtIsect].coord);
|
11657 |
|
11658 | var nxtIsectInQueue = undefined;
|
11659 | for (var i = 0; i < queue.length; i++) { if (queue[i].isect == nxtIsect) { nxtIsectInQueue = i; break; } }
|
11660 | if (nxtIsectInQueue != undefined) {
|
11661 | queue.splice(nxtIsectInQueue, 1);
|
11662 | }
|
11663 |
|
11664 |
|
11665 |
|
11666 |
|
11667 |
|
11668 | if (equalArrays(walkingRingAndEdge, isectList[nxtIsect].ringAndEdge1)) {
|
11669 | walkingRingAndEdge = isectList[nxtIsect].ringAndEdge2;
|
11670 | isectList[nxtIsect].ringAndEdge2Walkable = false;
|
11671 | if (isectList[nxtIsect].ringAndEdge1Walkable) {
|
11672 | var pushing = {isect: nxtIsect};
|
11673 | if (isConvex([isectList[currentIsect].coord, isectList[nxtIsect].coord, isectList[isectList[nxtIsect].nxtIsectAlongRingAndEdge2].coord], currentOutputRingWinding == 1)) {
|
11674 | pushing.parent = currentOutputRingParent;
|
11675 | pushing.winding = -currentOutputRingWinding;
|
11676 | } else {
|
11677 | pushing.parent = currentOutputRing;
|
11678 | pushing.winding = currentOutputRingWinding;
|
11679 | }
|
11680 | queue.push(pushing);
|
11681 | }
|
11682 | currentIsect = nxtIsect;
|
11683 | nxtIsect = isectList[nxtIsect].nxtIsectAlongRingAndEdge2;
|
11684 | } else {
|
11685 | walkingRingAndEdge = isectList[nxtIsect].ringAndEdge1;
|
11686 | isectList[nxtIsect].ringAndEdge1Walkable = false;
|
11687 | if (isectList[nxtIsect].ringAndEdge2Walkable) {
|
11688 | var pushing = {isect: nxtIsect};
|
11689 | if (isConvex([isectList[currentIsect].coord, isectList[nxtIsect].coord, isectList[isectList[nxtIsect].nxtIsectAlongRingAndEdge1].coord], currentOutputRingWinding == 1)) {
|
11690 | pushing.parent = currentOutputRingParent;
|
11691 | pushing.winding = -currentOutputRingWinding;
|
11692 | } else {
|
11693 | pushing.parent = currentOutputRing;
|
11694 | pushing.winding = currentOutputRingWinding;
|
11695 | }
|
11696 | queue.push(pushing);
|
11697 | }
|
11698 | currentIsect = nxtIsect;
|
11699 | nxtIsect = isectList[nxtIsect].nxtIsectAlongRingAndEdge1;
|
11700 | }
|
11701 | }
|
11702 |
|
11703 | currentOutputRingCoords.push(isectList[nxtIsect].coord);
|
11704 |
|
11705 | outputFeatureArray.push(polygon([currentOutputRingCoords], {index: currentOutputRing, parent: currentOutputRingParent, winding: currentOutputRingWinding, netWinding: undefined}));
|
11706 | }
|
11707 |
|
11708 | var output = featureCollection(outputFeatureArray);
|
11709 |
|
11710 | determineParents();
|
11711 |
|
11712 | setNetWinding();
|
11713 |
|
11714 |
|
11715 | function determineParents() {
|
11716 | var featuresWithoutParent = [];
|
11717 | for (var i = 0; i < output.features.length; i++) {
|
11718 | if (output.features[i].properties.parent == -1) featuresWithoutParent.push(i);
|
11719 | }
|
11720 | if (featuresWithoutParent.length > 1) {
|
11721 | for (var i = 0; i < featuresWithoutParent.length; i++) {
|
11722 | var parent = -1;
|
11723 | var parentArea = Infinity;
|
11724 | for (var j = 0; j < output.features.length; j++) {
|
11725 | if (featuresWithoutParent[i] == j) continue;
|
11726 | if (booleanPointInPolygon(output.features[featuresWithoutParent[i]].geometry.coordinates[0][0], output.features[j], {ignoreBoundary: true})) {
|
11727 | if (area$1(output.features[j]) < parentArea) {
|
11728 | parent = j;
|
11729 | }
|
11730 | }
|
11731 | }
|
11732 | output.features[featuresWithoutParent[i]].properties.parent = parent;
|
11733 | }
|
11734 | }
|
11735 | }
|
11736 |
|
11737 | function setNetWinding() {
|
11738 | for (var i = 0; i < output.features.length; i++) {
|
11739 | if (output.features[i].properties.parent == -1) {
|
11740 | var netWinding = output.features[i].properties.winding;
|
11741 | output.features[i].properties.netWinding = netWinding;
|
11742 | setNetWindingOfChildren(i, netWinding);
|
11743 | }
|
11744 | }
|
11745 | }
|
11746 |
|
11747 | function setNetWindingOfChildren(parent, ParentNetWinding) {
|
11748 | for (var i = 0; i < output.features.length; i++) {
|
11749 | if (output.features[i].properties.parent == parent) {
|
11750 | var netWinding = ParentNetWinding + output.features[i].properties.winding;
|
11751 | output.features[i].properties.netWinding = netWinding;
|
11752 | setNetWindingOfChildren(i, netWinding);
|
11753 | }
|
11754 | }
|
11755 | }
|
11756 |
|
11757 |
|
11758 | return output;
|
11759 | };
|
11760 |
|
11761 |
|
11762 |
|
11763 |
|
11764 | var PseudoVtx = function (coord, param, ringAndEdgeIn, ringAndEdgeOut, nxtIsectAlongEdgeIn) {
|
11765 | this.coord = coord;
|
11766 | this.param = param;
|
11767 | this.ringAndEdgeIn = ringAndEdgeIn;
|
11768 | this.ringAndEdgeOut = ringAndEdgeOut;
|
11769 | this.nxtIsectAlongEdgeIn = nxtIsectAlongEdgeIn;
|
11770 | };
|
11771 |
|
11772 |
|
11773 | var Isect = function (coord, ringAndEdge1, ringAndEdge2, nxtIsectAlongRingAndEdge1, nxtIsectAlongRingAndEdge2, ringAndEdge1Walkable, ringAndEdge2Walkable) {
|
11774 | this.coord = coord;
|
11775 | this.ringAndEdge1 = ringAndEdge1;
|
11776 | this.ringAndEdge2 = ringAndEdge2;
|
11777 | this.nxtIsectAlongRingAndEdge1 = nxtIsectAlongRingAndEdge1;
|
11778 | this.nxtIsectAlongRingAndEdge2 = nxtIsectAlongRingAndEdge2;
|
11779 | this.ringAndEdge1Walkable = ringAndEdge1Walkable;
|
11780 | this.ringAndEdge2Walkable = ringAndEdge2Walkable;
|
11781 | };
|
11782 |
|
11783 |
|
11784 | function isConvex(pts, righthanded) {
|
11785 |
|
11786 |
|
11787 | if (typeof (righthanded) === 'undefined') righthanded = true;
|
11788 | if (pts.length != 3) throw new Error('This function requires an array of three points [x,y]');
|
11789 | var d = (pts[1][0] - pts[0][0]) * (pts[2][1] - pts[0][1]) - (pts[1][1] - pts[0][1]) * (pts[2][0] - pts[0][0]);
|
11790 | return (d >= 0) == righthanded;
|
11791 | }
|
11792 |
|
11793 |
|
11794 | function windingOfRing(ring) {
|
11795 |
|
11796 |
|
11797 | var leftVtx = 0;
|
11798 | for (var i = 0; i < ring.length - 1; i++) { if (ring[i][0] < ring[leftVtx][0]) leftVtx = i; }
|
11799 | if (isConvex([ring[(leftVtx - 1).modulo(ring.length - 1)], ring[leftVtx], ring[(leftVtx + 1).modulo(ring.length - 1)]], true)) {
|
11800 | var winding = 1;
|
11801 | } else {
|
11802 | var winding = -1;
|
11803 | }
|
11804 | return winding;
|
11805 | }
|
11806 |
|
11807 |
|
11808 | function equalArrays(array1, array2) {
|
11809 |
|
11810 | if (!array1 || !array2)
|
11811 | return false;
|
11812 |
|
11813 |
|
11814 | if (array1.length != array2.length)
|
11815 | return false;
|
11816 |
|
11817 | for (var i = 0, l = array1.length; i < l; i++) {
|
11818 |
|
11819 | if (array1[i] instanceof Array && array2[i] instanceof Array) {
|
11820 |
|
11821 | if (!equalArrays(array1[i], array2[i]))
|
11822 | return false;
|
11823 | } else if (array1[i] != array2[i]) {
|
11824 |
|
11825 | return false;
|
11826 | }
|
11827 | }
|
11828 | return true;
|
11829 | }
|
11830 |
|
11831 |
|
11832 | Number.prototype.modulo = function (n) {
|
11833 | return ((this % n) + n) % n;
|
11834 | };
|
11835 |
|
11836 |
|
11837 | function isUnique(array) {
|
11838 | var u = {};
|
11839 | var isUnique = 1;
|
11840 | for (var i = 0, l = array.length; i < l; ++i) {
|
11841 | if (u.hasOwnProperty(array[i])) {
|
11842 | isUnique = 0;
|
11843 | break;
|
11844 | }
|
11845 | u[array[i]] = 1;
|
11846 | }
|
11847 | return isUnique;
|
11848 | }
|
11849 |
|
11850 |
|
11851 |
|
11852 |
|
11853 |
|
11854 |
|
11855 |
|
11856 |
|
11857 |
|
11858 |
|
11859 |
|
11860 |
|
11861 |
|
11862 |
|
11863 |
|
11864 |
|
11865 | function unkinkPolygon(geojson) {
|
11866 | var features = [];
|
11867 | flattenEach(geojson, function (feature$$1) {
|
11868 | if (feature$$1.geometry.type !== 'Polygon') return;
|
11869 | featureEach(simplepolygon(feature$$1), function (poly) {
|
11870 | features.push(polygon(poly.geometry.coordinates, feature$$1.properties));
|
11871 | });
|
11872 | });
|
11873 | return featureCollection(features);
|
11874 | }
|
11875 |
|
11876 | var D2R = Math.PI / 180;
|
11877 | var R2D = 180 / Math.PI;
|
11878 |
|
11879 | var Coord = function (lon, lat) {
|
11880 | this.lon = lon;
|
11881 | this.lat = lat;
|
11882 | this.x = D2R * lon;
|
11883 | this.y = D2R * lat;
|
11884 | };
|
11885 |
|
11886 | Coord.prototype.view = function () {
|
11887 | return String(this.lon).slice(0, 4) + ',' + String(this.lat).slice(0, 4);
|
11888 | };
|
11889 |
|
11890 | Coord.prototype.antipode = function () {
|
11891 | var anti_lat = -1 * this.lat;
|
11892 | var anti_lon = (this.lon < 0) ? 180 + this.lon : (180 - this.lon) * -1;
|
11893 | return new Coord(anti_lon, anti_lat);
|
11894 | };
|
11895 |
|
11896 | var LineString = function () {
|
11897 | this.coords = [];
|
11898 | this.length = 0;
|
11899 | };
|
11900 |
|
11901 | LineString.prototype.move_to = function (coord) {
|
11902 | this.length++;
|
11903 | this.coords.push(coord);
|
11904 | };
|
11905 |
|
11906 | var Arc = function (properties) {
|
11907 | this.properties = properties || {};
|
11908 | this.geometries = [];
|
11909 | };
|
11910 |
|
11911 | Arc.prototype.json = function () {
|
11912 | if (this.geometries.length <= 0) {
|
11913 | return {'geometry': { 'type': 'LineString', 'coordinates': null },
|
11914 | 'type': 'Feature', 'properties': this.properties
|
11915 | };
|
11916 | } else if (this.geometries.length === 1) {
|
11917 | return {'geometry': { 'type': 'LineString', 'coordinates': this.geometries[0].coords },
|
11918 | 'type': 'Feature', 'properties': this.properties
|
11919 | };
|
11920 | } else {
|
11921 | var multiline = [];
|
11922 | for (var i = 0; i < this.geometries.length; i++) {
|
11923 | multiline.push(this.geometries[i].coords);
|
11924 | }
|
11925 | return {'geometry': { 'type': 'MultiLineString', 'coordinates': multiline },
|
11926 | 'type': 'Feature', 'properties': this.properties
|
11927 | };
|
11928 | }
|
11929 | };
|
11930 |
|
11931 |
|
11932 | Arc.prototype.wkt = function () {
|
11933 | var wkt_string = '';
|
11934 | var wkt = 'LINESTRING(';
|
11935 | var collect = function (c) { wkt += c[0] + ' ' + c[1] + ','; };
|
11936 | for (var i = 0; i < this.geometries.length; i++) {
|
11937 | if (this.geometries[i].coords.length === 0) {
|
11938 | return 'LINESTRING(empty)';
|
11939 | } else {
|
11940 | var coords = this.geometries[i].coords;
|
11941 | coords.forEach(collect);
|
11942 | wkt_string += wkt.substring(0, wkt.length - 1) + ')';
|
11943 | }
|
11944 | }
|
11945 | return wkt_string;
|
11946 | };
|
11947 |
|
11948 |
|
11949 |
|
11950 |
|
11951 |
|
11952 | var GreatCircle = function (start, end, properties) {
|
11953 | if (!start || start.x === undefined || start.y === undefined) {
|
11954 | throw new Error('GreatCircle constructor expects two args: start and end objects with x and y properties');
|
11955 | }
|
11956 | if (!end || end.x === undefined || end.y === undefined) {
|
11957 | throw new Error('GreatCircle constructor expects two args: start and end objects with x and y properties');
|
11958 | }
|
11959 | this.start = new Coord(start.x, start.y);
|
11960 | this.end = new Coord(end.x, end.y);
|
11961 | this.properties = properties || {};
|
11962 |
|
11963 | var w = this.start.x - this.end.x;
|
11964 | var h = this.start.y - this.end.y;
|
11965 | var z = Math.pow(Math.sin(h / 2.0), 2) +
|
11966 | Math.cos(this.start.y) *
|
11967 | Math.cos(this.end.y) *
|
11968 | Math.pow(Math.sin(w / 2.0), 2);
|
11969 | this.g = 2.0 * Math.asin(Math.sqrt(z));
|
11970 |
|
11971 | if (this.g === Math.PI) {
|
11972 | throw new Error('it appears ' + start.view() + ' and ' + end.view() + ' are \'antipodal\', e.g diametrically opposite, thus there is no single route but rather infinite');
|
11973 | } else if (isNaN(this.g)) {
|
11974 | throw new Error('could not calculate great circle between ' + start + ' and ' + end);
|
11975 | }
|
11976 | };
|
11977 |
|
11978 |
|
11979 |
|
11980 |
|
11981 | GreatCircle.prototype.interpolate = function (f) {
|
11982 | var A = Math.sin((1 - f) * this.g) / Math.sin(this.g);
|
11983 | var B = Math.sin(f * this.g) / Math.sin(this.g);
|
11984 | var x = A * Math.cos(this.start.y) * Math.cos(this.start.x) + B * Math.cos(this.end.y) * Math.cos(this.end.x);
|
11985 | var y = A * Math.cos(this.start.y) * Math.sin(this.start.x) + B * Math.cos(this.end.y) * Math.sin(this.end.x);
|
11986 | var z = A * Math.sin(this.start.y) + B * Math.sin(this.end.y);
|
11987 | var lat = R2D * Math.atan2(z, Math.sqrt(Math.pow(x, 2) + Math.pow(y, 2)));
|
11988 | var lon = R2D * Math.atan2(y, x);
|
11989 | return [lon, lat];
|
11990 | };
|
11991 |
|
11992 |
|
11993 |
|
11994 |
|
11995 |
|
11996 |
|
11997 | GreatCircle.prototype.Arc = function (npoints, options) {
|
11998 | var first_pass = [];
|
11999 | if (!npoints || npoints <= 2) {
|
12000 | first_pass.push([this.start.lon, this.start.lat]);
|
12001 | first_pass.push([this.end.lon, this.end.lat]);
|
12002 | } else {
|
12003 | var delta = 1.0 / (npoints - 1);
|
12004 | for (var i = 0; i < npoints; ++i) {
|
12005 | var step = delta * i;
|
12006 | var pair = this.interpolate(step);
|
12007 | first_pass.push(pair);
|
12008 | }
|
12009 | }
|
12010 | |
12011 |
|
12012 |
|
12013 |
|
12014 |
|
12015 | var bHasBigDiff = false;
|
12016 | var dfMaxSmallDiffLong = 0;
|
12017 |
|
12018 |
|
12019 |
|
12020 | var dfDateLineOffset = options && options.offset ? options.offset : 10;
|
12021 | var dfLeftBorderX = 180 - dfDateLineOffset;
|
12022 | var dfRightBorderX = -180 + dfDateLineOffset;
|
12023 | var dfDiffSpace = 360 - dfDateLineOffset;
|
12024 |
|
12025 |
|
12026 | for (var j = 1; j < first_pass.length; ++j) {
|
12027 | var dfPrevX = first_pass[j - 1][0];
|
12028 | var dfX = first_pass[j][0];
|
12029 | var dfDiffLong = Math.abs(dfX - dfPrevX);
|
12030 | if (dfDiffLong > dfDiffSpace &&
|
12031 | ((dfX > dfLeftBorderX && dfPrevX < dfRightBorderX) || (dfPrevX > dfLeftBorderX && dfX < dfRightBorderX))) {
|
12032 | bHasBigDiff = true;
|
12033 | } else if (dfDiffLong > dfMaxSmallDiffLong) {
|
12034 | dfMaxSmallDiffLong = dfDiffLong;
|
12035 | }
|
12036 | }
|
12037 |
|
12038 | var poMulti = [];
|
12039 | if (bHasBigDiff && dfMaxSmallDiffLong < dfDateLineOffset) {
|
12040 | var poNewLS = [];
|
12041 | poMulti.push(poNewLS);
|
12042 | for (var k = 0; k < first_pass.length; ++k) {
|
12043 | var dfX0 = parseFloat(first_pass[k][0]);
|
12044 | if (k > 0 && Math.abs(dfX0 - first_pass[k - 1][0]) > dfDiffSpace) {
|
12045 | var dfX1 = parseFloat(first_pass[k - 1][0]);
|
12046 | var dfY1 = parseFloat(first_pass[k - 1][1]);
|
12047 | var dfX2 = parseFloat(first_pass[k][0]);
|
12048 | var dfY2 = parseFloat(first_pass[k][1]);
|
12049 | if (dfX1 > -180 && dfX1 < dfRightBorderX && dfX2 === 180 &&
|
12050 | k + 1 < first_pass.length &&
|
12051 | first_pass[k - 1][0] > -180 && first_pass[k - 1][0] < dfRightBorderX) {
|
12052 | poNewLS.push([-180, first_pass[k][1]]);
|
12053 | k++;
|
12054 | poNewLS.push([first_pass[k][0], first_pass[k][1]]);
|
12055 | continue;
|
12056 | } else if (dfX1 > dfLeftBorderX && dfX1 < 180 && dfX2 === -180 &&
|
12057 | k + 1 < first_pass.length &&
|
12058 | first_pass[k - 1][0] > dfLeftBorderX && first_pass[k - 1][0] < 180) {
|
12059 | poNewLS.push([180, first_pass[k][1]]);
|
12060 | k++;
|
12061 | poNewLS.push([first_pass[k][0], first_pass[k][1]]);
|
12062 | continue;
|
12063 | }
|
12064 |
|
12065 | if (dfX1 < dfRightBorderX && dfX2 > dfLeftBorderX) {
|
12066 |
|
12067 | var tmpX = dfX1;
|
12068 | dfX1 = dfX2;
|
12069 | dfX2 = tmpX;
|
12070 |
|
12071 | var tmpY = dfY1;
|
12072 | dfY1 = dfY2;
|
12073 | dfY2 = tmpY;
|
12074 | }
|
12075 | if (dfX1 > dfLeftBorderX && dfX2 < dfRightBorderX) {
|
12076 | dfX2 += 360;
|
12077 | }
|
12078 |
|
12079 | if (dfX1 <= 180 && dfX2 >= 180 && dfX1 < dfX2) {
|
12080 | var dfRatio = (180 - dfX1) / (dfX2 - dfX1);
|
12081 | var dfY = dfRatio * dfY2 + (1 - dfRatio) * dfY1;
|
12082 | poNewLS.push([first_pass[k - 1][0] > dfLeftBorderX ? 180 : -180, dfY]);
|
12083 | poNewLS = [];
|
12084 | poNewLS.push([first_pass[k - 1][0] > dfLeftBorderX ? -180 : 180, dfY]);
|
12085 | poMulti.push(poNewLS);
|
12086 | } else {
|
12087 | poNewLS = [];
|
12088 | poMulti.push(poNewLS);
|
12089 | }
|
12090 | poNewLS.push([dfX0, first_pass[k][1]]);
|
12091 | } else {
|
12092 | poNewLS.push([first_pass[k][0], first_pass[k][1]]);
|
12093 | }
|
12094 | }
|
12095 | } else {
|
12096 |
|
12097 | var poNewLS0 = [];
|
12098 | poMulti.push(poNewLS0);
|
12099 | for (var l = 0; l < first_pass.length; ++l) {
|
12100 | poNewLS0.push([first_pass[l][0], first_pass[l][1]]);
|
12101 | }
|
12102 | }
|
12103 |
|
12104 | var arc = new Arc(this.properties);
|
12105 | for (var m = 0; m < poMulti.length; ++m) {
|
12106 | var line = new LineString();
|
12107 | arc.geometries.push(line);
|
12108 | var points = poMulti[m];
|
12109 | for (var j0 = 0; j0 < points.length; ++j0) {
|
12110 | line.move_to(points[j0]);
|
12111 | }
|
12112 | }
|
12113 | return arc;
|
12114 | };
|
12115 |
|
12116 |
|
12117 |
|
12118 |
|
12119 |
|
12120 |
|
12121 |
|
12122 |
|
12123 |
|
12124 |
|
12125 |
|
12126 |
|
12127 |
|
12128 |
|
12129 |
|
12130 |
|
12131 |
|
12132 |
|
12133 |
|
12134 |
|
12135 |
|
12136 |
|
12137 | function greatCircle(start, end, options) {
|
12138 |
|
12139 | options = options || {};
|
12140 | if (typeof options !== 'object') throw new Error('options is invalid');
|
12141 | var properties = options.properties;
|
12142 | var npoints = options.npoints;
|
12143 | var offset = options.offset;
|
12144 |
|
12145 | start = getCoord(start);
|
12146 | end = getCoord(end);
|
12147 | properties = properties || {};
|
12148 | npoints = npoints || 100;
|
12149 | offset = offset || 10;
|
12150 |
|
12151 | var generator = new GreatCircle({x: start[0], y: start[1]}, {x: end[0], y: end[1]}, properties);
|
12152 |
|
12153 |
|
12154 | var line = generator.Arc(npoints, {offset: offset});
|
12155 |
|
12156 |
|
12157 | return line.json();
|
12158 | }
|
12159 |
|
12160 |
|
12161 |
|
12162 |
|
12163 |
|
12164 |
|
12165 |
|
12166 |
|
12167 |
|
12168 |
|
12169 |
|
12170 |
|
12171 |
|
12172 |
|
12173 |
|
12174 |
|
12175 |
|
12176 | function lineSplit(line, splitter) {
|
12177 | if (!line) throw new Error('line is required');
|
12178 | if (!splitter) throw new Error('splitter is required');
|
12179 |
|
12180 | var lineType = getType(line);
|
12181 | var splitterType = getType(splitter);
|
12182 |
|
12183 | if (lineType !== 'LineString') throw new Error('line must be LineString');
|
12184 | if (splitterType === 'FeatureCollection') throw new Error('splitter cannot be a FeatureCollection');
|
12185 | if (splitterType === 'GeometryCollection') throw new Error('splitter cannot be a GeometryCollection');
|
12186 |
|
12187 |
|
12188 |
|
12189 | var truncatedSplitter = truncate(splitter, {precision: 7});
|
12190 |
|
12191 | switch (splitterType) {
|
12192 | case 'Point':
|
12193 | return splitLineWithPoint(line, truncatedSplitter);
|
12194 | case 'MultiPoint':
|
12195 | return splitLineWithPoints(line, truncatedSplitter);
|
12196 | case 'LineString':
|
12197 | case 'MultiLineString':
|
12198 | case 'Polygon':
|
12199 | case 'MultiPolygon':
|
12200 | return splitLineWithPoints(line, lineIntersect(line, truncatedSplitter));
|
12201 | }
|
12202 | }
|
12203 |
|
12204 |
|
12205 |
|
12206 |
|
12207 |
|
12208 |
|
12209 |
|
12210 |
|
12211 |
|
12212 | function splitLineWithPoints(line, splitter) {
|
12213 | var results = [];
|
12214 | var tree = geojsonRbush();
|
12215 |
|
12216 | flattenEach(splitter, function (point$$1) {
|
12217 |
|
12218 | results.forEach(function (feature$$1, index) {
|
12219 | feature$$1.id = index;
|
12220 | });
|
12221 |
|
12222 | if (!results.length) {
|
12223 | results = splitLineWithPoint(line, point$$1).features;
|
12224 |
|
12225 |
|
12226 | results.forEach(function (feature$$1) {
|
12227 | if (!feature$$1.bbox) feature$$1.bbox = square(bbox(feature$$1));
|
12228 | });
|
12229 | tree.load(featureCollection(results));
|
12230 |
|
12231 | } else {
|
12232 |
|
12233 | var search = tree.search(point$$1);
|
12234 |
|
12235 | if (search.features.length) {
|
12236 |
|
12237 | var closestLine = findClosestFeature(point$$1, search);
|
12238 |
|
12239 |
|
12240 |
|
12241 | results = results.filter(function (feature$$1) { return feature$$1.id !== closestLine.id; });
|
12242 | tree.remove(closestLine);
|
12243 |
|
12244 |
|
12245 | featureEach(splitLineWithPoint(closestLine, point$$1), function (line) {
|
12246 | results.push(line);
|
12247 | tree.insert(line);
|
12248 | });
|
12249 | }
|
12250 | }
|
12251 | });
|
12252 | return featureCollection(results);
|
12253 | }
|
12254 |
|
12255 |
|
12256 |
|
12257 |
|
12258 |
|
12259 |
|
12260 |
|
12261 |
|
12262 |
|
12263 | function splitLineWithPoint(line, splitter) {
|
12264 | var results = [];
|
12265 |
|
12266 |
|
12267 | var startPoint = getCoords(line)[0];
|
12268 | var endPoint = getCoords(line)[line.geometry.coordinates.length - 1];
|
12269 | if (pointsEquals(startPoint, getCoord(splitter)) ||
|
12270 | pointsEquals(endPoint, getCoord(splitter))) return featureCollection([line]);
|
12271 |
|
12272 |
|
12273 | var tree = geojsonRbush();
|
12274 | var segments = lineSegment(line);
|
12275 | tree.load(segments);
|
12276 |
|
12277 |
|
12278 | var search = tree.search(splitter);
|
12279 |
|
12280 |
|
12281 | if (!search.features.length) return featureCollection([line]);
|
12282 |
|
12283 |
|
12284 | var closestSegment = findClosestFeature(splitter, search);
|
12285 |
|
12286 |
|
12287 | var initialValue = [startPoint];
|
12288 | var lastCoords = featureReduce(segments, function (previous, current, index) {
|
12289 | var currentCoords = getCoords(current)[1];
|
12290 | var splitterCoords = getCoord(splitter);
|
12291 |
|
12292 |
|
12293 | if (index === closestSegment.id) {
|
12294 | previous.push(splitterCoords);
|
12295 | results.push(lineString(previous));
|
12296 |
|
12297 | if (pointsEquals(splitterCoords, currentCoords)) return [splitterCoords];
|
12298 | return [splitterCoords, currentCoords];
|
12299 |
|
12300 |
|
12301 | } else {
|
12302 | previous.push(currentCoords);
|
12303 | return previous;
|
12304 | }
|
12305 | }, initialValue);
|
12306 |
|
12307 | if (lastCoords.length > 1) {
|
12308 | results.push(lineString(lastCoords));
|
12309 | }
|
12310 | return featureCollection(results);
|
12311 | }
|
12312 |
|
12313 |
|
12314 |
|
12315 |
|
12316 |
|
12317 |
|
12318 |
|
12319 |
|
12320 |
|
12321 |
|
12322 | function findClosestFeature(point$$1, lines) {
|
12323 | if (!lines.features.length) throw new Error('lines must contain features');
|
12324 |
|
12325 | if (lines.features.length === 1) return lines.features[0];
|
12326 |
|
12327 | var closestFeature;
|
12328 | var closestDistance = Infinity;
|
12329 | featureEach(lines, function (segment) {
|
12330 | var pt = nearestPointOnLine(segment, point$$1);
|
12331 | var dist = pt.properties.dist;
|
12332 | if (dist < closestDistance) {
|
12333 | closestFeature = segment;
|
12334 | closestDistance = dist;
|
12335 | }
|
12336 | });
|
12337 | return closestFeature;
|
12338 | }
|
12339 |
|
12340 |
|
12341 |
|
12342 |
|
12343 |
|
12344 |
|
12345 |
|
12346 |
|
12347 |
|
12348 | function pointsEquals(pt1, pt2) {
|
12349 | return pt1[0] === pt2[0] && pt1[1] === pt2[1];
|
12350 | }
|
12351 |
|
12352 |
|
12353 |
|
12354 |
|
12355 |
|
12356 |
|
12357 |
|
12358 |
|
12359 |
|
12360 |
|
12361 |
|
12362 |
|
12363 |
|
12364 |
|
12365 |
|
12366 |
|
12367 |
|
12368 |
|
12369 |
|
12370 |
|
12371 |
|
12372 |
|
12373 |
|
12374 |
|
12375 |
|
12376 | function lineArc(center, radius, bearing1, bearing2, options) {
|
12377 |
|
12378 | options = options || {};
|
12379 | if (!isObject(options)) throw new Error('options is invalid');
|
12380 | var steps = options.steps;
|
12381 | var units = options.units;
|
12382 |
|
12383 |
|
12384 | if (!center) throw new Error('center is required');
|
12385 | if (!radius) throw new Error('radius is required');
|
12386 | if (bearing1 === undefined || bearing1 === null) throw new Error('bearing1 is required');
|
12387 | if (bearing2 === undefined || bearing2 === null) throw new Error('bearing2 is required');
|
12388 | if (typeof options !== 'object') throw new Error('options must be an object');
|
12389 |
|
12390 |
|
12391 | steps = steps || 64;
|
12392 |
|
12393 | var angle1 = convertAngleTo360(bearing1);
|
12394 | var angle2 = convertAngleTo360(bearing2);
|
12395 | var properties = center.properties;
|
12396 |
|
12397 |
|
12398 | if (angle1 === angle2) {
|
12399 | return lineString(circle(center, radius, options).geometry.coordinates[0], properties);
|
12400 | }
|
12401 | var arcStartDegree = angle1;
|
12402 | var arcEndDegree = (angle1 < angle2) ? angle2 : angle2 + 360;
|
12403 |
|
12404 | var alfa = arcStartDegree;
|
12405 | var coordinates = [];
|
12406 | var i = 0;
|
12407 |
|
12408 | while (alfa < arcEndDegree) {
|
12409 | coordinates.push(destination(center, radius, alfa, units).geometry.coordinates);
|
12410 | i++;
|
12411 | alfa = arcStartDegree + i * 360 / steps;
|
12412 | }
|
12413 | if (alfa > arcEndDegree) {
|
12414 | coordinates.push(destination(center, radius, arcEndDegree, units).geometry.coordinates);
|
12415 | }
|
12416 | return lineString(coordinates, properties);
|
12417 | }
|
12418 |
|
12419 |
|
12420 |
|
12421 |
|
12422 |
|
12423 |
|
12424 |
|
12425 |
|
12426 |
|
12427 |
|
12428 | function convertAngleTo360(alfa) {
|
12429 | var beta = alfa % 360;
|
12430 | if (beta < 0) {
|
12431 | beta += 360;
|
12432 | }
|
12433 | return beta;
|
12434 | }
|
12435 |
|
12436 |
|
12437 |
|
12438 |
|
12439 |
|
12440 |
|
12441 |
|
12442 |
|
12443 |
|
12444 |
|
12445 |
|
12446 |
|
12447 |
|
12448 |
|
12449 |
|
12450 |
|
12451 |
|
12452 | function polygonToLine(polygon$$1, options) {
|
12453 |
|
12454 | options = options || {};
|
12455 | if (!isObject(options)) throw new Error('options is invalid');
|
12456 | var properties = options.properties;
|
12457 |
|
12458 |
|
12459 | var geom = getType(polygon$$1);
|
12460 | var coords = getCoords(polygon$$1);
|
12461 | properties = properties || polygon$$1.properties || {};
|
12462 |
|
12463 | if (!coords.length) throw new Error('polygon must contain coordinates');
|
12464 |
|
12465 | switch (geom) {
|
12466 | case 'Polygon':
|
12467 | return coordsToLine(coords, properties);
|
12468 | case 'MultiPolygon':
|
12469 | var lines = [];
|
12470 | coords.forEach(function (coord) {
|
12471 | lines.push(coordsToLine(coord, properties));
|
12472 | });
|
12473 | return featureCollection(lines);
|
12474 | default:
|
12475 | throw new Error('geom ' + geom + ' not supported');
|
12476 | }
|
12477 | }
|
12478 |
|
12479 | function coordsToLine(coords, properties) {
|
12480 | if (coords.length > 1) return multiLineString(coords, properties);
|
12481 | return lineString(coords[0], properties);
|
12482 | }
|
12483 |
|
12484 |
|
12485 |
|
12486 |
|
12487 |
|
12488 |
|
12489 |
|
12490 |
|
12491 |
|
12492 |
|
12493 |
|
12494 |
|
12495 |
|
12496 |
|
12497 |
|
12498 |
|
12499 |
|
12500 |
|
12501 |
|
12502 | function lineToPolygon(lines, options) {
|
12503 |
|
12504 | options = options || {};
|
12505 | if (!isObject(options)) throw new Error('options is invalid');
|
12506 | var properties = options.properties;
|
12507 | var autoComplete = options.autoComplete;
|
12508 | var orderCoords = options.orderCoords;
|
12509 |
|
12510 |
|
12511 | if (!lines) throw new Error('lines is required');
|
12512 |
|
12513 |
|
12514 | autoComplete = (autoComplete !== undefined) ? autoComplete : true;
|
12515 | orderCoords = (orderCoords !== undefined) ? orderCoords : true;
|
12516 | var type = getType(lines);
|
12517 |
|
12518 | switch (type) {
|
12519 | case 'FeatureCollection':
|
12520 | case 'GeometryCollection':
|
12521 | var coords = [];
|
12522 | var features = (lines.features) ? lines.features : lines.geometries;
|
12523 | features.forEach(function (line) {
|
12524 | coords.push(getCoords(lineStringToPolygon(line, {}, autoComplete, orderCoords)));
|
12525 | });
|
12526 | return multiPolygon(coords, properties);
|
12527 | }
|
12528 | return lineStringToPolygon(lines, properties, autoComplete, orderCoords);
|
12529 | }
|
12530 |
|
12531 |
|
12532 |
|
12533 |
|
12534 |
|
12535 |
|
12536 |
|
12537 |
|
12538 |
|
12539 |
|
12540 |
|
12541 | function lineStringToPolygon(line, properties, autoComplete, orderCoords) {
|
12542 | properties = properties || line.properties || {};
|
12543 | var coords = getCoords(line);
|
12544 | var type = getType(line);
|
12545 |
|
12546 | if (!coords.length) throw new Error('line must contain coordinates');
|
12547 |
|
12548 | switch (type) {
|
12549 | case 'LineString':
|
12550 | if (autoComplete) coords = autoCompleteCoords(coords);
|
12551 | return polygon([coords], properties);
|
12552 | case 'MultiLineString':
|
12553 | var multiCoords = [];
|
12554 | var largestArea = 0;
|
12555 |
|
12556 | coords.forEach(function (coord) {
|
12557 | if (autoComplete) coord = autoCompleteCoords(coord);
|
12558 |
|
12559 |
|
12560 | if (orderCoords) {
|
12561 | var area = calculateArea$1(bbox(lineString(coord)));
|
12562 | if (area > largestArea) {
|
12563 | multiCoords.unshift(coord);
|
12564 | largestArea = area;
|
12565 | } else multiCoords.push(coord);
|
12566 | } else {
|
12567 | multiCoords.push(coord);
|
12568 | }
|
12569 | });
|
12570 | return polygon(multiCoords, properties);
|
12571 | default:
|
12572 | throw new Error('geometry type ' + type + ' is not supported');
|
12573 | }
|
12574 | }
|
12575 |
|
12576 |
|
12577 |
|
12578 |
|
12579 |
|
12580 |
|
12581 |
|
12582 |
|
12583 | function autoCompleteCoords(coords) {
|
12584 | var first = coords[0];
|
12585 | var x1 = first[0];
|
12586 | var y1 = first[1];
|
12587 | var last = coords[coords.length - 1];
|
12588 | var x2 = last[0];
|
12589 | var y2 = last[1];
|
12590 | if (x1 !== x2 || y1 !== y2) {
|
12591 | coords.push(first);
|
12592 | }
|
12593 | return coords;
|
12594 | }
|
12595 |
|
12596 |
|
12597 |
|
12598 |
|
12599 |
|
12600 |
|
12601 |
|
12602 |
|
12603 | function calculateArea$1(bbox$$1) {
|
12604 | var west = bbox$$1[0];
|
12605 | var south = bbox$$1[1];
|
12606 | var east = bbox$$1[2];
|
12607 | var north = bbox$$1[3];
|
12608 | return Math.abs(west - east) * Math.abs(south - north);
|
12609 | }
|
12610 |
|
12611 | var lineclip_1 = lineclip;
|
12612 |
|
12613 | lineclip.polyline = lineclip;
|
12614 | lineclip.polygon = polygonclip;
|
12615 |
|
12616 |
|
12617 |
|
12618 |
|
12619 |
|
12620 | function lineclip(points, bbox, result) {
|
12621 |
|
12622 | var len = points.length,
|
12623 | codeA = bitCode(points[0], bbox),
|
12624 | part = [],
|
12625 | i, a, b, codeB, lastCode;
|
12626 |
|
12627 | if (!result) result = [];
|
12628 |
|
12629 | for (i = 1; i < len; i++) {
|
12630 | a = points[i - 1];
|
12631 | b = points[i];
|
12632 | codeB = lastCode = bitCode(b, bbox);
|
12633 |
|
12634 | while (true) {
|
12635 |
|
12636 | if (!(codeA | codeB)) {
|
12637 | part.push(a);
|
12638 |
|
12639 | if (codeB !== lastCode) {
|
12640 | part.push(b);
|
12641 |
|
12642 | if (i < len - 1) {
|
12643 | result.push(part);
|
12644 | part = [];
|
12645 | }
|
12646 | } else if (i === len - 1) {
|
12647 | part.push(b);
|
12648 | }
|
12649 | break;
|
12650 |
|
12651 | } else if (codeA & codeB) {
|
12652 | break;
|
12653 |
|
12654 | } else if (codeA) {
|
12655 | a = intersect$1(a, b, codeA, bbox);
|
12656 | codeA = bitCode(a, bbox);
|
12657 |
|
12658 | } else {
|
12659 | b = intersect$1(a, b, codeB, bbox);
|
12660 | codeB = bitCode(b, bbox);
|
12661 | }
|
12662 | }
|
12663 |
|
12664 | codeA = lastCode;
|
12665 | }
|
12666 |
|
12667 | if (part.length) result.push(part);
|
12668 |
|
12669 | return result;
|
12670 | }
|
12671 |
|
12672 |
|
12673 |
|
12674 | function polygonclip(points, bbox) {
|
12675 |
|
12676 | var result, edge, prev, prevInside, i, p, inside;
|
12677 |
|
12678 |
|
12679 | for (edge = 1; edge <= 8; edge *= 2) {
|
12680 | result = [];
|
12681 | prev = points[points.length - 1];
|
12682 | prevInside = !(bitCode(prev, bbox) & edge);
|
12683 |
|
12684 | for (i = 0; i < points.length; i++) {
|
12685 | p = points[i];
|
12686 | inside = !(bitCode(p, bbox) & edge);
|
12687 |
|
12688 |
|
12689 | if (inside !== prevInside) result.push(intersect$1(prev, p, edge, bbox));
|
12690 |
|
12691 | if (inside) result.push(p);
|
12692 |
|
12693 | prev = p;
|
12694 | prevInside = inside;
|
12695 | }
|
12696 |
|
12697 | points = result;
|
12698 |
|
12699 | if (!points.length) break;
|
12700 | }
|
12701 |
|
12702 | return result;
|
12703 | }
|
12704 |
|
12705 |
|
12706 |
|
12707 | function intersect$1(a, b, edge, bbox) {
|
12708 | return edge & 8 ? [a[0] + (b[0] - a[0]) * (bbox[3] - a[1]) / (b[1] - a[1]), bbox[3]] :
|
12709 | edge & 4 ? [a[0] + (b[0] - a[0]) * (bbox[1] - a[1]) / (b[1] - a[1]), bbox[1]] :
|
12710 | edge & 2 ? [bbox[2], a[1] + (b[1] - a[1]) * (bbox[2] - a[0]) / (b[0] - a[0])] :
|
12711 | edge & 1 ? [bbox[0], a[1] + (b[1] - a[1]) * (bbox[0] - a[0]) / (b[0] - a[0])] :
|
12712 | null;
|
12713 | }
|
12714 |
|
12715 |
|
12716 |
|
12717 |
|
12718 |
|
12719 |
|
12720 |
|
12721 |
|
12722 | function bitCode(p, bbox) {
|
12723 | var code = 0;
|
12724 |
|
12725 | if (p[0] < bbox[0]) code |= 1;
|
12726 | else if (p[0] > bbox[2]) code |= 2;
|
12727 |
|
12728 | if (p[1] < bbox[1]) code |= 4;
|
12729 | else if (p[1] > bbox[3]) code |= 8;
|
12730 |
|
12731 | return code;
|
12732 | }
|
12733 |
|
12734 |
|
12735 |
|
12736 |
|
12737 |
|
12738 |
|
12739 |
|
12740 |
|
12741 |
|
12742 |
|
12743 |
|
12744 |
|
12745 |
|
12746 |
|
12747 |
|
12748 |
|
12749 |
|
12750 |
|
12751 | function bboxClip(feature$$1, bbox) {
|
12752 | var geom = getGeom$1(feature$$1);
|
12753 | var coords = getCoords(feature$$1);
|
12754 | var properties = feature$$1.properties;
|
12755 |
|
12756 | switch (geom) {
|
12757 | case 'LineString':
|
12758 | case 'MultiLineString':
|
12759 | var lines = [];
|
12760 | if (geom === 'LineString') coords = [coords];
|
12761 | coords.forEach(function (line) {
|
12762 | lineclip_1(line, bbox, lines);
|
12763 | });
|
12764 | if (lines.length === 1) return lineString(lines[0], properties);
|
12765 | return multiLineString(lines, properties);
|
12766 | case 'Polygon':
|
12767 | return polygon(clipPolygon(coords, bbox), properties);
|
12768 | case 'MultiPolygon':
|
12769 | return multiPolygon(coords.map(function (polygon$$1) {
|
12770 | return clipPolygon(polygon$$1, bbox);
|
12771 | }), properties);
|
12772 | default:
|
12773 | throw new Error('geometry ' + geom + ' not supported');
|
12774 | }
|
12775 | }
|
12776 |
|
12777 | function clipPolygon(rings, bbox) {
|
12778 | var outRings = [];
|
12779 | for (var i = 0; i < rings.length; i++) {
|
12780 | var clipped = lineclip_1.polygon(rings[i], bbox);
|
12781 | if (clipped.length > 0) {
|
12782 | if (clipped[0][0] !== clipped[clipped.length - 1][0] || clipped[0][1] !== clipped[clipped.length - 1][1]) {
|
12783 | clipped.push(clipped[0]);
|
12784 | }
|
12785 | if (clipped.length >= 4) {
|
12786 | outRings.push(clipped);
|
12787 | }
|
12788 | }
|
12789 | }
|
12790 | return outRings;
|
12791 | }
|
12792 |
|
12793 | function getGeom$1(feature$$1) {
|
12794 | return (feature$$1.geometry) ? feature$$1.geometry.type : feature$$1.type;
|
12795 | }
|
12796 |
|
12797 | var pSlice = Array.prototype.slice;
|
12798 |
|
12799 | function isArguments(object) {
|
12800 | return Object.prototype.toString.call(object) === '[object Arguments]';
|
12801 | }
|
12802 |
|
12803 | function deepEqual(actual, expected, opts) {
|
12804 | if (!opts) opts = {};
|
12805 |
|
12806 | if (actual === expected) {
|
12807 | return true;
|
12808 |
|
12809 | } else if (actual instanceof Date && expected instanceof Date) {
|
12810 | return actual.getTime() === expected.getTime();
|
12811 |
|
12812 |
|
12813 |
|
12814 | } else if (!actual || !expected || typeof actual != 'object' && typeof expected != 'object') {
|
12815 | return opts.strict ? actual === expected : actual === expected;
|
12816 |
|
12817 |
|
12818 |
|
12819 |
|
12820 |
|
12821 |
|
12822 |
|
12823 | } else {
|
12824 | return objEquiv(actual, expected, opts);
|
12825 | }
|
12826 | }
|
12827 |
|
12828 | function isUndefinedOrNull(value) {
|
12829 | return value === null || value === undefined;
|
12830 | }
|
12831 |
|
12832 | function isBuffer(x) {
|
12833 | if (!x || typeof x !== 'object' || typeof x.length !== 'number') return false;
|
12834 | if (typeof x.copy !== 'function' || typeof x.slice !== 'function') {
|
12835 | return false;
|
12836 | }
|
12837 | if (x.length > 0 && typeof x[0] !== 'number') return false;
|
12838 | return true;
|
12839 | }
|
12840 |
|
12841 | function objEquiv(a, b, opts) {
|
12842 | var i, key;
|
12843 | if (isUndefinedOrNull(a) || isUndefinedOrNull(b))
|
12844 | return false;
|
12845 |
|
12846 | if (a.prototype !== b.prototype) return false;
|
12847 |
|
12848 |
|
12849 | if (isArguments(a)) {
|
12850 | if (!isArguments(b)) {
|
12851 | return false;
|
12852 | }
|
12853 | a = pSlice.call(a);
|
12854 | b = pSlice.call(b);
|
12855 | return deepEqual(a, b, opts);
|
12856 | }
|
12857 | if (isBuffer(a)) {
|
12858 | if (!isBuffer(b)) {
|
12859 | return false;
|
12860 | }
|
12861 | if (a.length !== b.length) return false;
|
12862 | for (i = 0; i < a.length; i++) {
|
12863 | if (a[i] !== b[i]) return false;
|
12864 | }
|
12865 | return true;
|
12866 | }
|
12867 | try {
|
12868 | var ka = Object.keys(a),
|
12869 | kb = Object.keys(b);
|
12870 | } catch (e) {
|
12871 | return false;
|
12872 | }
|
12873 |
|
12874 |
|
12875 | if (ka.length !== kb.length)
|
12876 | return false;
|
12877 |
|
12878 | ka.sort();
|
12879 | kb.sort();
|
12880 |
|
12881 | for (i = ka.length - 1; i >= 0; i--) {
|
12882 | if (ka[i] !== kb[i])
|
12883 | return false;
|
12884 | }
|
12885 |
|
12886 |
|
12887 | for (i = ka.length - 1; i >= 0; i--) {
|
12888 | key = ka[i];
|
12889 | if (!deepEqual(a[key], b[key], opts)) return false;
|
12890 | }
|
12891 | return typeof a === typeof b;
|
12892 | }
|
12893 |
|
12894 |
|
12895 |
|
12896 |
|
12897 |
|
12898 |
|
12899 |
|
12900 |
|
12901 |
|
12902 |
|
12903 |
|
12904 |
|
12905 |
|
12906 |
|
12907 |
|
12908 |
|
12909 |
|
12910 |
|
12911 |
|
12912 | function lineOverlap(line1, line2, options) {
|
12913 |
|
12914 | options = options || {};
|
12915 | if (!isObject(options)) throw new Error('options is invalid');
|
12916 | var tolerance = options.tolerance || 0;
|
12917 |
|
12918 |
|
12919 | var features = [];
|
12920 |
|
12921 |
|
12922 | var tree = geojsonRbush();
|
12923 | tree.load(lineSegment(line1));
|
12924 | var overlapSegment;
|
12925 |
|
12926 |
|
12927 |
|
12928 |
|
12929 | segmentEach(line2, function (segment) {
|
12930 | var doesOverlaps = false;
|
12931 |
|
12932 |
|
12933 | featureEach(tree.search(segment), function (match) {
|
12934 | if (doesOverlaps === false) {
|
12935 | var coordsSegment = getCoords(segment).sort();
|
12936 | var coordsMatch = getCoords(match).sort();
|
12937 |
|
12938 |
|
12939 | if (deepEqual(coordsSegment, coordsMatch)) {
|
12940 | doesOverlaps = true;
|
12941 |
|
12942 | if (overlapSegment) overlapSegment = concatSegment(overlapSegment, segment);
|
12943 | else overlapSegment = segment;
|
12944 |
|
12945 | } else if (
|
12946 | (tolerance === 0) ?
|
12947 | booleanPointOnLine(coordsSegment[0], match) && booleanPointOnLine(coordsSegment[1], match) :
|
12948 | nearestPointOnLine(match, coordsSegment[0]).properties.dist <= tolerance &&
|
12949 | nearestPointOnLine(match, coordsSegment[1]).properties.dist <= tolerance) {
|
12950 | doesOverlaps = true;
|
12951 | if (overlapSegment) overlapSegment = concatSegment(overlapSegment, segment);
|
12952 | else overlapSegment = segment;
|
12953 | } else if (
|
12954 | (tolerance === 0) ?
|
12955 | booleanPointOnLine(coordsMatch[0], segment) && booleanPointOnLine(coordsMatch[1], segment) :
|
12956 | nearestPointOnLine(segment, coordsMatch[0]).properties.dist <= tolerance &&
|
12957 | nearestPointOnLine(segment, coordsMatch[1]).properties.dist <= tolerance) {
|
12958 |
|
12959 |
|
12960 | if (overlapSegment) overlapSegment = concatSegment(overlapSegment, match);
|
12961 | else overlapSegment = match;
|
12962 | }
|
12963 | }
|
12964 | });
|
12965 |
|
12966 |
|
12967 | if (doesOverlaps === false && overlapSegment) {
|
12968 | features.push(overlapSegment);
|
12969 | overlapSegment = undefined;
|
12970 | }
|
12971 | });
|
12972 |
|
12973 | if (overlapSegment) features.push(overlapSegment);
|
12974 |
|
12975 | return featureCollection(features);
|
12976 | }
|
12977 |
|
12978 |
|
12979 |
|
12980 |
|
12981 |
|
12982 |
|
12983 |
|
12984 |
|
12985 |
|
12986 |
|
12987 | function concatSegment(line, segment) {
|
12988 | var coords = getCoords(segment);
|
12989 | var lineCoords = getCoords(line);
|
12990 | var start = lineCoords[0];
|
12991 | var end = lineCoords[lineCoords.length - 1];
|
12992 | var geom = line.geometry.coordinates;
|
12993 |
|
12994 | if (deepEqual(coords[0], start)) geom.unshift(coords[1]);
|
12995 | else if (deepEqual(coords[0], end)) geom.push(coords[1]);
|
12996 | else if (deepEqual(coords[1], start)) geom.unshift(coords[0]);
|
12997 | else if (deepEqual(coords[1], end)) geom.push(coords[0]);
|
12998 | return line;
|
12999 | }
|
13000 |
|
13001 |
|
13002 |
|
13003 |
|
13004 |
|
13005 |
|
13006 |
|
13007 |
|
13008 |
|
13009 |
|
13010 |
|
13011 |
|
13012 |
|
13013 |
|
13014 |
|
13015 |
|
13016 |
|
13017 |
|
13018 |
|
13019 |
|
13020 |
|
13021 |
|
13022 |
|
13023 |
|
13024 |
|
13025 | function sector(center, radius, bearing1, bearing2, options) {
|
13026 |
|
13027 | options = options || {};
|
13028 | if (!isObject(options)) throw new Error('options is invalid');
|
13029 |
|
13030 |
|
13031 | if (!center) throw new Error('center is required');
|
13032 | if (bearing1 === undefined || bearing1 === null) throw new Error('bearing1 is required');
|
13033 | if (bearing2 === undefined || bearing2 === null) throw new Error('bearing2 is required');
|
13034 | if (!radius) throw new Error('radius is required');
|
13035 | if (typeof options !== 'object') throw new Error('options must be an object');
|
13036 |
|
13037 | if (convertAngleTo360$1(bearing1) === convertAngleTo360$1(bearing2)) {
|
13038 | return circle(center, radius, options);
|
13039 | }
|
13040 | var coords = getCoords(center);
|
13041 | var arc = lineArc(center, radius, bearing1, bearing2, options);
|
13042 | var sliceCoords = [[coords]];
|
13043 | coordEach(arc, function (currentCoords) {
|
13044 | sliceCoords[0].push(currentCoords);
|
13045 | });
|
13046 | sliceCoords[0].push(coords);
|
13047 |
|
13048 | return polygon(sliceCoords);
|
13049 | }
|
13050 |
|
13051 |
|
13052 |
|
13053 |
|
13054 |
|
13055 |
|
13056 |
|
13057 |
|
13058 |
|
13059 | function convertAngleTo360$1(alfa) {
|
13060 | var beta = alfa % 360;
|
13061 | if (beta < 0) beta += 360;
|
13062 | return beta;
|
13063 | }
|
13064 |
|
13065 |
|
13066 |
|
13067 |
|
13068 |
|
13069 |
|
13070 |
|
13071 |
|
13072 |
|
13073 |
|
13074 |
|
13075 |
|
13076 |
|
13077 |
|
13078 |
|
13079 |
|
13080 |
|
13081 |
|
13082 |
|
13083 |
|
13084 |
|
13085 |
|
13086 |
|
13087 |
|
13088 |
|
13089 |
|
13090 | function rhumbDestination(origin, distance, bearing, options) {
|
13091 |
|
13092 | options = options || {};
|
13093 | if (!isObject(options)) throw new Error('options is invalid');
|
13094 | var units = options.units;
|
13095 | var properties = options.properties;
|
13096 |
|
13097 |
|
13098 | if (!origin) throw new Error('origin is required');
|
13099 | if (distance === undefined || distance === null) throw new Error('distance is required');
|
13100 | if (bearing === undefined || bearing === null) throw new Error('bearing is required');
|
13101 | if (!(distance >= 0)) throw new Error('distance must be greater than 0');
|
13102 |
|
13103 | var distanceInMeters = convertLength(distance, units, 'meters');
|
13104 | var coords = getCoord(origin);
|
13105 | var destination = calculateRhumbDestination(coords, distanceInMeters, bearing);
|
13106 |
|
13107 |
|
13108 |
|
13109 | destination[0] += (destination[0] - coords[0] > 180) ? -360 : (coords[0] - destination[0] > 180) ? 360 : 0;
|
13110 | return point(destination, properties);
|
13111 | }
|
13112 |
|
13113 |
|
13114 |
|
13115 |
|
13116 |
|
13117 |
|
13118 |
|
13119 |
|
13120 |
|
13121 |
|
13122 |
|
13123 |
|
13124 |
|
13125 | function calculateRhumbDestination(origin, distance, bearing, radius) {
|
13126 |
|
13127 |
|
13128 |
|
13129 |
|
13130 |
|
13131 |
|
13132 |
|
13133 | radius = (radius === undefined) ? earthRadius : Number(radius);
|
13134 |
|
13135 | var delta = distance / radius;
|
13136 | var lambda1 = origin[0] * Math.PI / 180;
|
13137 | var phi1 = degreesToRadians(origin[1]);
|
13138 | var theta = degreesToRadians(bearing);
|
13139 |
|
13140 | var DeltaPhi = delta * Math.cos(theta);
|
13141 | var phi2 = phi1 + DeltaPhi;
|
13142 |
|
13143 |
|
13144 | if (Math.abs(phi2) > Math.PI / 2) phi2 = phi2 > 0 ? Math.PI - phi2 : -Math.PI - phi2;
|
13145 |
|
13146 | var DeltaPsi = Math.log(Math.tan(phi2 / 2 + Math.PI / 4) / Math.tan(phi1 / 2 + Math.PI / 4));
|
13147 | var q = Math.abs(DeltaPsi) > 10e-12 ? DeltaPhi / DeltaPsi : Math.cos(phi1);
|
13148 |
|
13149 | var DeltaLambda = delta * Math.sin(theta) / q;
|
13150 | var lambda2 = lambda1 + DeltaLambda;
|
13151 |
|
13152 | return [((lambda2 * 180 / Math.PI) + 540) % 360 - 180, phi2 * 180 / Math.PI];
|
13153 | }
|
13154 |
|
13155 |
|
13156 |
|
13157 |
|
13158 |
|
13159 |
|
13160 |
|
13161 |
|
13162 |
|
13163 |
|
13164 |
|
13165 |
|
13166 |
|
13167 |
|
13168 |
|
13169 |
|
13170 |
|
13171 | function polygonTangents(pt, polygon$$1) {
|
13172 | var pointCoords = getCoords(pt);
|
13173 | var polyCoords = getCoords(polygon$$1);
|
13174 |
|
13175 | var rtan;
|
13176 | var ltan;
|
13177 | var enext;
|
13178 | var eprev;
|
13179 |
|
13180 | var type = getType(polygon$$1);
|
13181 | switch (type) {
|
13182 | case 'Polygon':
|
13183 | rtan = polyCoords[0][0];
|
13184 | ltan = polyCoords[0][0];
|
13185 | eprev = isLeft(polyCoords[0][0], polyCoords[0][polyCoords[0].length - 1], pointCoords);
|
13186 | var out = processPolygon$1(polyCoords[0], pointCoords, eprev, enext, rtan, ltan);
|
13187 | rtan = out[0];
|
13188 | ltan = out[1];
|
13189 | break;
|
13190 | case 'MultiPolygon':
|
13191 | rtan = polyCoords[0][0][0];
|
13192 | ltan = polyCoords[0][0][0];
|
13193 | eprev = isLeft(polyCoords[0][0][0], polyCoords[0][0][polyCoords[0][0].length - 1], pointCoords);
|
13194 | polyCoords.forEach(function (ring) {
|
13195 | var out = processPolygon$1(ring[0], pointCoords, eprev, enext, rtan, ltan);
|
13196 | rtan = out[0];
|
13197 | ltan = out[1];
|
13198 | });
|
13199 | break;
|
13200 | }
|
13201 | return featureCollection([point(rtan), point(ltan)]);
|
13202 | }
|
13203 |
|
13204 | function processPolygon$1(polygonCoords, ptCoords, eprev, enext, rtan, ltan) {
|
13205 | for (var i = 0; i < polygonCoords.length; i++) {
|
13206 | var currentCoords = polygonCoords[i];
|
13207 | var nextCoordPair = polygonCoords[i + 1];
|
13208 | if (i === polygonCoords.length - 1) {
|
13209 | nextCoordPair = polygonCoords[0];
|
13210 | }
|
13211 | enext = isLeft(currentCoords, nextCoordPair, ptCoords);
|
13212 | if (eprev <= 0 && enext > 0) {
|
13213 | if (!isBelow(ptCoords, currentCoords, rtan)) {
|
13214 | rtan = currentCoords;
|
13215 | }
|
13216 | } else if (eprev > 0 && enext <= 0) {
|
13217 | if (!isAbove(ptCoords, currentCoords, ltan)) {
|
13218 | ltan = currentCoords;
|
13219 | }
|
13220 | }
|
13221 | eprev = enext;
|
13222 | }
|
13223 | return [rtan, ltan];
|
13224 | }
|
13225 |
|
13226 | function isAbove(point1, point2, point3) {
|
13227 | return isLeft(point1, point2, point3) > 0;
|
13228 | }
|
13229 |
|
13230 | function isBelow(point1, point2, point3) {
|
13231 | return isLeft(point1, point2, point3) < 0;
|
13232 | }
|
13233 |
|
13234 | function isLeft(point1, point2, point3) {
|
13235 | return (point2[0] - point1[0]) * (point3[1] - point1[1]) - (point3[0] - point1[0]) * (point2[1] - point1[1]);
|
13236 | }
|
13237 |
|
13238 |
|
13239 |
|
13240 |
|
13241 |
|
13242 |
|
13243 |
|
13244 |
|
13245 |
|
13246 |
|
13247 |
|
13248 |
|
13249 |
|
13250 |
|
13251 |
|
13252 |
|
13253 | function booleanClockwise(line) {
|
13254 |
|
13255 | if (!line) throw new Error('line is required');
|
13256 | var type = (line.geometry) ? line.geometry.type : line.type;
|
13257 | if (!Array.isArray(line) && type !== 'LineString') throw new Error('geometry must be a LineString');
|
13258 |
|
13259 | var ring = getCoords(line);
|
13260 | var sum = 0;
|
13261 | var i = 1;
|
13262 | var prev, cur;
|
13263 | while (i < ring.length) {
|
13264 | prev = cur || ring[0];
|
13265 | cur = ring[i];
|
13266 | sum += ((cur[0] - prev[0]) * (cur[1] + prev[1]));
|
13267 | i++;
|
13268 | }
|
13269 | return sum > 0;
|
13270 | }
|
13271 |
|
13272 |
|
13273 |
|
13274 |
|
13275 |
|
13276 |
|
13277 |
|
13278 |
|
13279 |
|
13280 |
|
13281 |
|
13282 |
|
13283 |
|
13284 |
|
13285 |
|
13286 |
|
13287 |
|
13288 |
|
13289 | function rewind(geojson, options) {
|
13290 |
|
13291 | options = options || {};
|
13292 | if (!isObject(options)) throw new Error('options is invalid');
|
13293 | var reverse = options.reverse || false;
|
13294 | var mutate = options.mutate || false;
|
13295 |
|
13296 |
|
13297 | if (!geojson) throw new Error('<geojson> is required');
|
13298 | if (typeof reverse !== 'boolean') throw new Error('<reverse> must be a boolean');
|
13299 | if (typeof mutate !== 'boolean') throw new Error('<mutate> must be a boolean');
|
13300 |
|
13301 |
|
13302 | if (mutate === false) geojson = clone(geojson);
|
13303 |
|
13304 |
|
13305 | var results = [];
|
13306 | switch (geojson.type) {
|
13307 | case 'GeometryCollection':
|
13308 | geomEach(geojson, function (geometry$$1) {
|
13309 | rewindFeature(geometry$$1, reverse);
|
13310 | });
|
13311 | return geojson;
|
13312 | case 'FeatureCollection':
|
13313 | featureEach(geojson, function (feature$$1) {
|
13314 | featureEach(rewindFeature(feature$$1, reverse), function (result) {
|
13315 | results.push(result);
|
13316 | });
|
13317 | });
|
13318 | return featureCollection(results);
|
13319 | }
|
13320 |
|
13321 | return rewindFeature(geojson, reverse);
|
13322 | }
|
13323 |
|
13324 |
|
13325 |
|
13326 |
|
13327 |
|
13328 |
|
13329 |
|
13330 |
|
13331 |
|
13332 | function rewindFeature(geojson, reverse) {
|
13333 | var type = (geojson.type === 'Feature') ? geojson.geometry.type : geojson.type;
|
13334 |
|
13335 |
|
13336 | switch (type) {
|
13337 | case 'GeometryCollection':
|
13338 | geomEach(geojson, function (geometry$$1) {
|
13339 | rewindFeature(geometry$$1, reverse);
|
13340 | });
|
13341 | return geojson;
|
13342 | case 'LineString':
|
13343 | rewindLineString(getCoords(geojson), reverse);
|
13344 | return geojson;
|
13345 | case 'Polygon':
|
13346 | rewindPolygon(getCoords(geojson), reverse);
|
13347 | return geojson;
|
13348 | case 'MultiLineString':
|
13349 | getCoords(geojson).forEach(function (lineCoords) {
|
13350 | rewindLineString(lineCoords, reverse);
|
13351 | });
|
13352 | return geojson;
|
13353 | case 'MultiPolygon':
|
13354 | getCoords(geojson).forEach(function (lineCoords) {
|
13355 | rewindPolygon(lineCoords, reverse);
|
13356 | });
|
13357 | return geojson;
|
13358 | case 'Point':
|
13359 | case 'MultiPoint':
|
13360 | return geojson;
|
13361 | }
|
13362 | }
|
13363 |
|
13364 |
|
13365 |
|
13366 |
|
13367 |
|
13368 |
|
13369 |
|
13370 |
|
13371 |
|
13372 | function rewindLineString(coords, reverse) {
|
13373 | if (booleanClockwise(coords) === reverse) coords.reverse();
|
13374 | }
|
13375 |
|
13376 |
|
13377 |
|
13378 |
|
13379 |
|
13380 |
|
13381 |
|
13382 |
|
13383 |
|
13384 | function rewindPolygon(coords, reverse) {
|
13385 |
|
13386 | if (booleanClockwise(coords[0]) !== reverse) {
|
13387 | coords[0].reverse();
|
13388 | }
|
13389 |
|
13390 | for (var i = 1; i < coords.length; i++) {
|
13391 | if (booleanClockwise(coords[i]) === reverse) {
|
13392 | coords[i].reverse();
|
13393 | }
|
13394 | }
|
13395 | }
|
13396 |
|
13397 |
|
13398 |
|
13399 |
|
13400 |
|
13401 |
|
13402 |
|
13403 |
|
13404 |
|
13405 |
|
13406 |
|
13407 |
|
13408 |
|
13409 |
|
13410 |
|
13411 |
|
13412 |
|
13413 |
|
13414 |
|
13415 |
|
13416 |
|
13417 |
|
13418 |
|
13419 |
|
13420 |
|
13421 |
|
13422 |
|
13423 |
|
13424 |
|
13425 |
|
13426 |
|
13427 |
|
13428 |
|
13429 | function gridToMatrix$1(grid, options) {
|
13430 |
|
13431 | options = options || {};
|
13432 | if (!isObject(options)) throw new Error('options is invalid');
|
13433 | var zProperty = options.zProperty || 'elevation';
|
13434 | var flip = options.flip;
|
13435 | var flags = options.flags;
|
13436 |
|
13437 |
|
13438 | collectionOf(grid, 'Point', 'input must contain Points');
|
13439 |
|
13440 | var pointsMatrix = sortPointsByLatLng$1(grid, flip);
|
13441 |
|
13442 | var matrix = [];
|
13443 |
|
13444 |
|
13445 | for (var r = 0; r < pointsMatrix.length; r++) {
|
13446 | var pointRow = pointsMatrix[r];
|
13447 | var row = [];
|
13448 | for (var c = 0; c < pointRow.length; c++) {
|
13449 | var point$$1 = pointRow[c];
|
13450 |
|
13451 | if (point$$1.properties[zProperty]) row.push(point$$1.properties[zProperty]);
|
13452 | else row.push(0);
|
13453 |
|
13454 | if (flags === true) point$$1.properties.matrixPosition = [r, c];
|
13455 | }
|
13456 | matrix.push(row);
|
13457 | }
|
13458 |
|
13459 | return matrix;
|
13460 | }
|
13461 |
|
13462 |
|
13463 |
|
13464 |
|
13465 |
|
13466 |
|
13467 |
|
13468 |
|
13469 |
|
13470 | function sortPointsByLatLng$1(points$$1, flip) {
|
13471 | var pointsByLatitude = {};
|
13472 |
|
13473 |
|
13474 | featureEach(points$$1, function (point$$1) {
|
13475 | var lat = getCoords(point$$1)[1];
|
13476 | if (!pointsByLatitude[lat]) pointsByLatitude[lat] = [];
|
13477 | pointsByLatitude[lat].push(point$$1);
|
13478 | });
|
13479 |
|
13480 |
|
13481 | var orderedRowsByLatitude = Object.keys(pointsByLatitude).map(function (lat) {
|
13482 | var row = pointsByLatitude[lat];
|
13483 | var rowOrderedByLongitude = row.sort(function (a, b) {
|
13484 | return getCoords(a)[0] - getCoords(b)[0];
|
13485 | });
|
13486 | return rowOrderedByLongitude;
|
13487 | });
|
13488 |
|
13489 |
|
13490 | var pointMatrix = orderedRowsByLatitude.sort(function (a, b) {
|
13491 | if (flip) return getCoords(a[0])[1] - getCoords(b[0])[1];
|
13492 | else return getCoords(b[0])[1] - getCoords(a[0])[1];
|
13493 | });
|
13494 |
|
13495 | return pointMatrix;
|
13496 | }
|
13497 |
|
13498 |
|
13499 |
|
13500 |
|
13501 |
|
13502 |
|
13503 |
|
13504 |
|
13505 | var defaultSettings$1 = {
|
13506 | successCallback: null,
|
13507 | verbose: false,
|
13508 | polygons: false
|
13509 | };
|
13510 |
|
13511 | var settings$1 = {};
|
13512 |
|
13513 |
|
13514 |
|
13515 |
|
13516 |
|
13517 |
|
13518 |
|
13519 |
|
13520 | function isoBands(data, minV, bandwidth, options) {
|
13521 |
|
13522 | options = options ? options : {};
|
13523 |
|
13524 | var optionKeys = Object.keys(defaultSettings$1);
|
13525 |
|
13526 | for (var i = 0; i < optionKeys.length; i++) {
|
13527 | var key = optionKeys[i];
|
13528 | var val = options[key];
|
13529 | val = ((typeof val !== 'undefined') && (val !== null)) ? val : defaultSettings$1[key];
|
13530 |
|
13531 | settings$1[key] = val;
|
13532 | }
|
13533 |
|
13534 | if (settings$1.verbose)
|
13535 | console.log('MarchingSquaresJS-isoBands: computing isobands for [' + minV + ':' + (minV + bandwidth) + ']');
|
13536 |
|
13537 | var grid = computeBandGrid(data, minV, bandwidth);
|
13538 |
|
13539 | var ret;
|
13540 | if (settings$1.polygons) {
|
13541 | if (settings$1.verbose)
|
13542 | console.log('MarchingSquaresJS-isoBands: returning single polygons for each grid cell');
|
13543 | ret = BandGrid2Areas(grid);
|
13544 | } else {
|
13545 | if (settings$1.verbose)
|
13546 | console.log('MarchingSquaresJS-isoBands: returning polygon paths for entire data grid');
|
13547 | ret = BandGrid2AreaPaths(grid);
|
13548 | }
|
13549 |
|
13550 | if (typeof settings$1.successCallback === 'function')
|
13551 | settings$1.successCallback(ret);
|
13552 |
|
13553 | return ret;
|
13554 | }
|
13555 |
|
13556 |
|
13557 |
|
13558 |
|
13559 |
|
13560 |
|
13561 |
|
13562 | var Node0 = 64;
|
13563 | var Node1 = 16;
|
13564 | var Node2 = 4;
|
13565 | var Node3 = 1;
|
13566 |
|
13567 |
|
13568 |
|
13569 |
|
13570 |
|
13571 |
|
13572 | var isoBandNextXTL = [];
|
13573 | var isoBandNextYTL = [];
|
13574 | var isoBandNextOTL = [];
|
13575 |
|
13576 | var isoBandNextXTR = [];
|
13577 | var isoBandNextYTR = [];
|
13578 | var isoBandNextOTR = [];
|
13579 |
|
13580 | var isoBandNextXRT = [];
|
13581 | var isoBandNextYRT = [];
|
13582 | var isoBandNextORT = [];
|
13583 |
|
13584 | var isoBandNextXRB = [];
|
13585 | var isoBandNextYRB = [];
|
13586 | var isoBandNextORB = [];
|
13587 |
|
13588 | var isoBandNextXBL = [];
|
13589 | var isoBandNextYBL = [];
|
13590 | var isoBandNextOBL = [];
|
13591 |
|
13592 | var isoBandNextXBR = [];
|
13593 | var isoBandNextYBR = [];
|
13594 | var isoBandNextOBR = [];
|
13595 |
|
13596 | var isoBandNextXLT = [];
|
13597 | var isoBandNextYLT = [];
|
13598 | var isoBandNextOLT = [];
|
13599 |
|
13600 | var isoBandNextXLB = [];
|
13601 | var isoBandNextYLB = [];
|
13602 | var isoBandNextOLB = [];
|
13603 |
|
13604 | isoBandNextXRT[85] = isoBandNextXRB[85] = -1;
|
13605 | isoBandNextYRT[85] = isoBandNextYRB[85] = 0;
|
13606 | isoBandNextORT[85] = isoBandNextORB[85] = 1;
|
13607 | isoBandNextXLT[85] = isoBandNextXLB[85] = 1;
|
13608 | isoBandNextYLT[85] = isoBandNextYLB[85] = 0;
|
13609 | isoBandNextOLT[85] = isoBandNextOLB[85] = 1;
|
13610 |
|
13611 | isoBandNextXTL[85] = isoBandNextXTR[85] = 0;
|
13612 | isoBandNextYTL[85] = isoBandNextYTR[85] = -1;
|
13613 | isoBandNextOTL[85] = isoBandNextOBL[85] = 0;
|
13614 | isoBandNextXBR[85] = isoBandNextXBL[85] = 0;
|
13615 | isoBandNextYBR[85] = isoBandNextYBL[85] = 1;
|
13616 | isoBandNextOTR[85] = isoBandNextOBR[85] = 1;
|
13617 |
|
13618 |
|
13619 |
|
13620 | isoBandNextXLB[1] = isoBandNextXLB[169] = 0;
|
13621 | isoBandNextYLB[1] = isoBandNextYLB[169] = -1;
|
13622 | isoBandNextOLB[1] = isoBandNextOLB[169] = 0;
|
13623 | isoBandNextXBL[1] = isoBandNextXBL[169] = -1;
|
13624 | isoBandNextYBL[1] = isoBandNextYBL[169] = 0;
|
13625 | isoBandNextOBL[1] = isoBandNextOBL[169] = 0;
|
13626 |
|
13627 | isoBandNextXRB[4] = isoBandNextXRB[166] = 0;
|
13628 | isoBandNextYRB[4] = isoBandNextYRB[166] = -1;
|
13629 | isoBandNextORB[4] = isoBandNextORB[166] = 1;
|
13630 | isoBandNextXBR[4] = isoBandNextXBR[166] = 1;
|
13631 | isoBandNextYBR[4] = isoBandNextYBR[166] = 0;
|
13632 | isoBandNextOBR[4] = isoBandNextOBR[166] = 0;
|
13633 |
|
13634 | isoBandNextXRT[16] = isoBandNextXRT[154] = 0;
|
13635 | isoBandNextYRT[16] = isoBandNextYRT[154] = 1;
|
13636 | isoBandNextORT[16] = isoBandNextORT[154] = 1;
|
13637 | isoBandNextXTR[16] = isoBandNextXTR[154] = 1;
|
13638 | isoBandNextYTR[16] = isoBandNextYTR[154] = 0;
|
13639 | isoBandNextOTR[16] = isoBandNextOTR[154] = 1;
|
13640 |
|
13641 | isoBandNextXLT[64] = isoBandNextXLT[106] = 0;
|
13642 | isoBandNextYLT[64] = isoBandNextYLT[106] = 1;
|
13643 | isoBandNextOLT[64] = isoBandNextOLT[106] = 0;
|
13644 | isoBandNextXTL[64] = isoBandNextXTL[106] = -1;
|
13645 | isoBandNextYTL[64] = isoBandNextYTL[106] = 0;
|
13646 | isoBandNextOTL[64] = isoBandNextOTL[106] = 1;
|
13647 |
|
13648 |
|
13649 | isoBandNextXLT[2] = isoBandNextXLT[168] = 0;
|
13650 | isoBandNextYLT[2] = isoBandNextYLT[168] = -1;
|
13651 | isoBandNextOLT[2] = isoBandNextOLT[168] = 1;
|
13652 | isoBandNextXLB[2] = isoBandNextXLB[168] = 0;
|
13653 | isoBandNextYLB[2] = isoBandNextYLB[168] = -1;
|
13654 | isoBandNextOLB[2] = isoBandNextOLB[168] = 0;
|
13655 | isoBandNextXBL[2] = isoBandNextXBL[168] = -1;
|
13656 | isoBandNextYBL[2] = isoBandNextYBL[168] = 0;
|
13657 | isoBandNextOBL[2] = isoBandNextOBL[168] = 0;
|
13658 | isoBandNextXBR[2] = isoBandNextXBR[168] = -1;
|
13659 | isoBandNextYBR[2] = isoBandNextYBR[168] = 0;
|
13660 | isoBandNextOBR[2] = isoBandNextOBR[168] = 1;
|
13661 |
|
13662 | isoBandNextXRT[8] = isoBandNextXRT[162] = 0;
|
13663 | isoBandNextYRT[8] = isoBandNextYRT[162] = -1;
|
13664 | isoBandNextORT[8] = isoBandNextORT[162] = 0;
|
13665 | isoBandNextXRB[8] = isoBandNextXRB[162] = 0;
|
13666 | isoBandNextYRB[8] = isoBandNextYRB[162] = -1;
|
13667 | isoBandNextORB[8] = isoBandNextORB[162] = 1;
|
13668 | isoBandNextXBL[8] = isoBandNextXBL[162] = 1;
|
13669 | isoBandNextYBL[8] = isoBandNextYBL[162] = 0;
|
13670 | isoBandNextOBL[8] = isoBandNextOBL[162] = 1;
|
13671 | isoBandNextXBR[8] = isoBandNextXBR[162] = 1;
|
13672 | isoBandNextYBR[8] = isoBandNextYBR[162] = 0;
|
13673 | isoBandNextOBR[8] = isoBandNextOBR[162] = 0;
|
13674 |
|
13675 | isoBandNextXRT[32] = isoBandNextXRT[138] = 0;
|
13676 | isoBandNextYRT[32] = isoBandNextYRT[138] = 1;
|
13677 | isoBandNextORT[32] = isoBandNextORT[138] = 1;
|
13678 | isoBandNextXRB[32] = isoBandNextXRB[138] = 0;
|
13679 | isoBandNextYRB[32] = isoBandNextYRB[138] = 1;
|
13680 | isoBandNextORB[32] = isoBandNextORB[138] = 0;
|
13681 | isoBandNextXTL[32] = isoBandNextXTL[138] = 1;
|
13682 | isoBandNextYTL[32] = isoBandNextYTL[138] = 0;
|
13683 | isoBandNextOTL[32] = isoBandNextOTL[138] = 0;
|
13684 | isoBandNextXTR[32] = isoBandNextXTR[138] = 1;
|
13685 | isoBandNextYTR[32] = isoBandNextYTR[138] = 0;
|
13686 | isoBandNextOTR[32] = isoBandNextOTR[138] = 1;
|
13687 |
|
13688 | isoBandNextXLB[128] = isoBandNextXLB[42] = 0;
|
13689 | isoBandNextYLB[128] = isoBandNextYLB[42] = 1;
|
13690 | isoBandNextOLB[128] = isoBandNextOLB[42] = 1;
|
13691 | isoBandNextXLT[128] = isoBandNextXLT[42] = 0;
|
13692 | isoBandNextYLT[128] = isoBandNextYLT[42] = 1;
|
13693 | isoBandNextOLT[128] = isoBandNextOLT[42] = 0;
|
13694 | isoBandNextXTL[128] = isoBandNextXTL[42] = -1;
|
13695 | isoBandNextYTL[128] = isoBandNextYTL[42] = 0;
|
13696 | isoBandNextOTL[128] = isoBandNextOTL[42] = 1;
|
13697 | isoBandNextXTR[128] = isoBandNextXTR[42] = -1;
|
13698 | isoBandNextYTR[128] = isoBandNextYTR[42] = 0;
|
13699 | isoBandNextOTR[128] = isoBandNextOTR[42] = 0;
|
13700 |
|
13701 |
|
13702 | isoBandNextXRB[5] = isoBandNextXRB[165] = -1;
|
13703 | isoBandNextYRB[5] = isoBandNextYRB[165] = 0;
|
13704 | isoBandNextORB[5] = isoBandNextORB[165] = 0;
|
13705 | isoBandNextXLB[5] = isoBandNextXLB[165] = 1;
|
13706 | isoBandNextYLB[5] = isoBandNextYLB[165] = 0;
|
13707 | isoBandNextOLB[5] = isoBandNextOLB[165] = 0;
|
13708 |
|
13709 | isoBandNextXBR[20] = isoBandNextXBR[150] = 0;
|
13710 | isoBandNextYBR[20] = isoBandNextYBR[150] = 1;
|
13711 | isoBandNextOBR[20] = isoBandNextOBR[150] = 1;
|
13712 | isoBandNextXTR[20] = isoBandNextXTR[150] = 0;
|
13713 | isoBandNextYTR[20] = isoBandNextYTR[150] = -1;
|
13714 | isoBandNextOTR[20] = isoBandNextOTR[150] = 1;
|
13715 |
|
13716 | isoBandNextXRT[80] = isoBandNextXRT[90] = -1;
|
13717 | isoBandNextYRT[80] = isoBandNextYRT[90] = 0;
|
13718 | isoBandNextORT[80] = isoBandNextORT[90] = 1;
|
13719 | isoBandNextXLT[80] = isoBandNextXLT[90] = 1;
|
13720 | isoBandNextYLT[80] = isoBandNextYLT[90] = 0;
|
13721 | isoBandNextOLT[80] = isoBandNextOLT[90] = 1;
|
13722 |
|
13723 | isoBandNextXBL[65] = isoBandNextXBL[105] = 0;
|
13724 | isoBandNextYBL[65] = isoBandNextYBL[105] = 1;
|
13725 | isoBandNextOBL[65] = isoBandNextOBL[105] = 0;
|
13726 | isoBandNextXTL[65] = isoBandNextXTL[105] = 0;
|
13727 | isoBandNextYTL[65] = isoBandNextYTL[105] = -1;
|
13728 | isoBandNextOTL[65] = isoBandNextOTL[105] = 0;
|
13729 |
|
13730 | isoBandNextXRT[160] = isoBandNextXRT[10] = -1;
|
13731 | isoBandNextYRT[160] = isoBandNextYRT[10] = 0;
|
13732 | isoBandNextORT[160] = isoBandNextORT[10] = 1;
|
13733 | isoBandNextXRB[160] = isoBandNextXRB[10] = -1;
|
13734 | isoBandNextYRB[160] = isoBandNextYRB[10] = 0;
|
13735 | isoBandNextORB[160] = isoBandNextORB[10] = 0;
|
13736 | isoBandNextXLB[160] = isoBandNextXLB[10] = 1;
|
13737 | isoBandNextYLB[160] = isoBandNextYLB[10] = 0;
|
13738 | isoBandNextOLB[160] = isoBandNextOLB[10] = 0;
|
13739 | isoBandNextXLT[160] = isoBandNextXLT[10] = 1;
|
13740 | isoBandNextYLT[160] = isoBandNextYLT[10] = 0;
|
13741 | isoBandNextOLT[160] = isoBandNextOLT[10] = 1;
|
13742 |
|
13743 | isoBandNextXBR[130] = isoBandNextXBR[40] = 0;
|
13744 | isoBandNextYBR[130] = isoBandNextYBR[40] = 1;
|
13745 | isoBandNextOBR[130] = isoBandNextOBR[40] = 1;
|
13746 | isoBandNextXBL[130] = isoBandNextXBL[40] = 0;
|
13747 | isoBandNextYBL[130] = isoBandNextYBL[40] = 1;
|
13748 | isoBandNextOBL[130] = isoBandNextOBL[40] = 0;
|
13749 | isoBandNextXTL[130] = isoBandNextXTL[40] = 0;
|
13750 | isoBandNextYTL[130] = isoBandNextYTL[40] = -1;
|
13751 | isoBandNextOTL[130] = isoBandNextOTL[40] = 0;
|
13752 | isoBandNextXTR[130] = isoBandNextXTR[40] = 0;
|
13753 | isoBandNextYTR[130] = isoBandNextYTR[40] = -1;
|
13754 | isoBandNextOTR[130] = isoBandNextOTR[40] = 1;
|
13755 |
|
13756 |
|
13757 | isoBandNextXRB[37] = isoBandNextXRB[133] = 0;
|
13758 | isoBandNextYRB[37] = isoBandNextYRB[133] = 1;
|
13759 | isoBandNextORB[37] = isoBandNextORB[133] = 1;
|
13760 | isoBandNextXLB[37] = isoBandNextXLB[133] = 0;
|
13761 | isoBandNextYLB[37] = isoBandNextYLB[133] = 1;
|
13762 | isoBandNextOLB[37] = isoBandNextOLB[133] = 0;
|
13763 | isoBandNextXTL[37] = isoBandNextXTL[133] = -1;
|
13764 | isoBandNextYTL[37] = isoBandNextYTL[133] = 0;
|
13765 | isoBandNextOTL[37] = isoBandNextOTL[133] = 0;
|
13766 | isoBandNextXTR[37] = isoBandNextXTR[133] = 1;
|
13767 | isoBandNextYTR[37] = isoBandNextYTR[133] = 0;
|
13768 | isoBandNextOTR[37] = isoBandNextOTR[133] = 0;
|
13769 |
|
13770 | isoBandNextXBR[148] = isoBandNextXBR[22] = -1;
|
13771 | isoBandNextYBR[148] = isoBandNextYBR[22] = 0;
|
13772 | isoBandNextOBR[148] = isoBandNextOBR[22] = 0;
|
13773 | isoBandNextXLB[148] = isoBandNextXLB[22] = 0;
|
13774 | isoBandNextYLB[148] = isoBandNextYLB[22] = -1;
|
13775 | isoBandNextOLB[148] = isoBandNextOLB[22] = 1;
|
13776 | isoBandNextXLT[148] = isoBandNextXLT[22] = 0;
|
13777 | isoBandNextYLT[148] = isoBandNextYLT[22] = 1;
|
13778 | isoBandNextOLT[148] = isoBandNextOLT[22] = 1;
|
13779 | isoBandNextXTR[148] = isoBandNextXTR[22] = -1;
|
13780 | isoBandNextYTR[148] = isoBandNextYTR[22] = 0;
|
13781 | isoBandNextOTR[148] = isoBandNextOTR[22] = 1;
|
13782 |
|
13783 | isoBandNextXRT[82] = isoBandNextXRT[88] = 0;
|
13784 | isoBandNextYRT[82] = isoBandNextYRT[88] = -1;
|
13785 | isoBandNextORT[82] = isoBandNextORT[88] = 1;
|
13786 | isoBandNextXBR[82] = isoBandNextXBR[88] = 1;
|
13787 | isoBandNextYBR[82] = isoBandNextYBR[88] = 0;
|
13788 | isoBandNextOBR[82] = isoBandNextOBR[88] = 1;
|
13789 | isoBandNextXBL[82] = isoBandNextXBL[88] = -1;
|
13790 | isoBandNextYBL[82] = isoBandNextYBL[88] = 0;
|
13791 | isoBandNextOBL[82] = isoBandNextOBL[88] = 1;
|
13792 | isoBandNextXLT[82] = isoBandNextXLT[88] = 0;
|
13793 | isoBandNextYLT[82] = isoBandNextYLT[88] = -1;
|
13794 | isoBandNextOLT[82] = isoBandNextOLT[88] = 0;
|
13795 |
|
13796 | isoBandNextXRT[73] = isoBandNextXRT[97] = 0;
|
13797 | isoBandNextYRT[73] = isoBandNextYRT[97] = 1;
|
13798 | isoBandNextORT[73] = isoBandNextORT[97] = 0;
|
13799 | isoBandNextXRB[73] = isoBandNextXRB[97] = 0;
|
13800 | isoBandNextYRB[73] = isoBandNextYRB[97] = -1;
|
13801 | isoBandNextORB[73] = isoBandNextORB[97] = 0;
|
13802 | isoBandNextXBL[73] = isoBandNextXBL[97] = 1;
|
13803 | isoBandNextYBL[73] = isoBandNextYBL[97] = 0;
|
13804 | isoBandNextOBL[73] = isoBandNextOBL[97] = 0;
|
13805 | isoBandNextXTL[73] = isoBandNextXTL[97] = 1;
|
13806 | isoBandNextYTL[73] = isoBandNextYTL[97] = 0;
|
13807 | isoBandNextOTL[73] = isoBandNextOTL[97] = 1;
|
13808 |
|
13809 | isoBandNextXRT[145] = isoBandNextXRT[25] = 0;
|
13810 | isoBandNextYRT[145] = isoBandNextYRT[25] = -1;
|
13811 | isoBandNextORT[145] = isoBandNextORT[25] = 0;
|
13812 | isoBandNextXBL[145] = isoBandNextXBL[25] = 1;
|
13813 | isoBandNextYBL[145] = isoBandNextYBL[25] = 0;
|
13814 | isoBandNextOBL[145] = isoBandNextOBL[25] = 1;
|
13815 | isoBandNextXLB[145] = isoBandNextXLB[25] = 0;
|
13816 | isoBandNextYLB[145] = isoBandNextYLB[25] = 1;
|
13817 | isoBandNextOLB[145] = isoBandNextOLB[25] = 1;
|
13818 | isoBandNextXTR[145] = isoBandNextXTR[25] = -1;
|
13819 | isoBandNextYTR[145] = isoBandNextYTR[25] = 0;
|
13820 | isoBandNextOTR[145] = isoBandNextOTR[25] = 0;
|
13821 |
|
13822 | isoBandNextXRB[70] = isoBandNextXRB[100] = 0;
|
13823 | isoBandNextYRB[70] = isoBandNextYRB[100] = 1;
|
13824 | isoBandNextORB[70] = isoBandNextORB[100] = 0;
|
13825 | isoBandNextXBR[70] = isoBandNextXBR[100] = -1;
|
13826 | isoBandNextYBR[70] = isoBandNextYBR[100] = 0;
|
13827 | isoBandNextOBR[70] = isoBandNextOBR[100] = 1;
|
13828 | isoBandNextXLT[70] = isoBandNextXLT[100] = 0;
|
13829 | isoBandNextYLT[70] = isoBandNextYLT[100] = -1;
|
13830 | isoBandNextOLT[70] = isoBandNextOLT[100] = 1;
|
13831 | isoBandNextXTL[70] = isoBandNextXTL[100] = 1;
|
13832 | isoBandNextYTL[70] = isoBandNextYTL[100] = 0;
|
13833 | isoBandNextOTL[70] = isoBandNextOTL[100] = 0;
|
13834 |
|
13835 |
|
13836 | isoBandNextXRB[101] = isoBandNextXRB[69] = 0;
|
13837 | isoBandNextYRB[101] = isoBandNextYRB[69] = 1;
|
13838 | isoBandNextORB[101] = isoBandNextORB[69] = 0;
|
13839 | isoBandNextXTL[101] = isoBandNextXTL[69] = 1;
|
13840 | isoBandNextYTL[101] = isoBandNextYTL[69] = 0;
|
13841 | isoBandNextOTL[101] = isoBandNextOTL[69] = 0;
|
13842 |
|
13843 | isoBandNextXLB[149] = isoBandNextXLB[21] = 0;
|
13844 | isoBandNextYLB[149] = isoBandNextYLB[21] = 1;
|
13845 | isoBandNextOLB[149] = isoBandNextOLB[21] = 1;
|
13846 | isoBandNextXTR[149] = isoBandNextXTR[21] = -1;
|
13847 | isoBandNextYTR[149] = isoBandNextYTR[21] = 0;
|
13848 | isoBandNextOTR[149] = isoBandNextOTR[21] = 0;
|
13849 |
|
13850 | isoBandNextXBR[86] = isoBandNextXBR[84] = -1;
|
13851 | isoBandNextYBR[86] = isoBandNextYBR[84] = 0;
|
13852 | isoBandNextOBR[86] = isoBandNextOBR[84] = 1;
|
13853 | isoBandNextXLT[86] = isoBandNextXLT[84] = 0;
|
13854 | isoBandNextYLT[86] = isoBandNextYLT[84] = -1;
|
13855 | isoBandNextOLT[86] = isoBandNextOLT[84] = 1;
|
13856 |
|
13857 | isoBandNextXRT[89] = isoBandNextXRT[81] = 0;
|
13858 | isoBandNextYRT[89] = isoBandNextYRT[81] = -1;
|
13859 | isoBandNextORT[89] = isoBandNextORT[81] = 0;
|
13860 | isoBandNextXBL[89] = isoBandNextXBL[81] = 1;
|
13861 | isoBandNextYBL[89] = isoBandNextYBL[81] = 0;
|
13862 | isoBandNextOBL[89] = isoBandNextOBL[81] = 1;
|
13863 |
|
13864 | isoBandNextXRT[96] = isoBandNextXRT[74] = 0;
|
13865 | isoBandNextYRT[96] = isoBandNextYRT[74] = 1;
|
13866 | isoBandNextORT[96] = isoBandNextORT[74] = 0;
|
13867 | isoBandNextXRB[96] = isoBandNextXRB[74] = -1;
|
13868 | isoBandNextYRB[96] = isoBandNextYRB[74] = 0;
|
13869 | isoBandNextORB[96] = isoBandNextORB[74] = 1;
|
13870 | isoBandNextXLT[96] = isoBandNextXLT[74] = 1;
|
13871 | isoBandNextYLT[96] = isoBandNextYLT[74] = 0;
|
13872 | isoBandNextOLT[96] = isoBandNextOLT[74] = 0;
|
13873 | isoBandNextXTL[96] = isoBandNextXTL[74] = 1;
|
13874 | isoBandNextYTL[96] = isoBandNextYTL[74] = 0;
|
13875 | isoBandNextOTL[96] = isoBandNextOTL[74] = 1;
|
13876 |
|
13877 | isoBandNextXRT[24] = isoBandNextXRT[146] = 0;
|
13878 | isoBandNextYRT[24] = isoBandNextYRT[146] = -1;
|
13879 | isoBandNextORT[24] = isoBandNextORT[146] = 1;
|
13880 | isoBandNextXBR[24] = isoBandNextXBR[146] = 1;
|
13881 | isoBandNextYBR[24] = isoBandNextYBR[146] = 0;
|
13882 | isoBandNextOBR[24] = isoBandNextOBR[146] = 1;
|
13883 | isoBandNextXBL[24] = isoBandNextXBL[146] = 0;
|
13884 | isoBandNextYBL[24] = isoBandNextYBL[146] = 1;
|
13885 | isoBandNextOBL[24] = isoBandNextOBL[146] = 1;
|
13886 | isoBandNextXTR[24] = isoBandNextXTR[146] = 0;
|
13887 | isoBandNextYTR[24] = isoBandNextYTR[146] = -1;
|
13888 | isoBandNextOTR[24] = isoBandNextOTR[146] = 0;
|
13889 |
|
13890 | isoBandNextXRB[6] = isoBandNextXRB[164] = -1;
|
13891 | isoBandNextYRB[6] = isoBandNextYRB[164] = 0;
|
13892 | isoBandNextORB[6] = isoBandNextORB[164] = 1;
|
13893 | isoBandNextXBR[6] = isoBandNextXBR[164] = -1;
|
13894 | isoBandNextYBR[6] = isoBandNextYBR[164] = 0;
|
13895 | isoBandNextOBR[6] = isoBandNextOBR[164] = 0;
|
13896 | isoBandNextXLB[6] = isoBandNextXLB[164] = 0;
|
13897 | isoBandNextYLB[6] = isoBandNextYLB[164] = -1;
|
13898 | isoBandNextOLB[6] = isoBandNextOLB[164] = 1;
|
13899 | isoBandNextXLT[6] = isoBandNextXLT[164] = 1;
|
13900 | isoBandNextYLT[6] = isoBandNextYLT[164] = 0;
|
13901 | isoBandNextOLT[6] = isoBandNextOLT[164] = 0;
|
13902 |
|
13903 | isoBandNextXBL[129] = isoBandNextXBL[41] = 0;
|
13904 | isoBandNextYBL[129] = isoBandNextYBL[41] = 1;
|
13905 | isoBandNextOBL[129] = isoBandNextOBL[41] = 1;
|
13906 | isoBandNextXLB[129] = isoBandNextXLB[41] = 0;
|
13907 | isoBandNextYLB[129] = isoBandNextYLB[41] = 1;
|
13908 | isoBandNextOLB[129] = isoBandNextOLB[41] = 0;
|
13909 | isoBandNextXTL[129] = isoBandNextXTL[41] = -1;
|
13910 | isoBandNextYTL[129] = isoBandNextYTL[41] = 0;
|
13911 | isoBandNextOTL[129] = isoBandNextOTL[41] = 0;
|
13912 | isoBandNextXTR[129] = isoBandNextXTR[41] = 0;
|
13913 | isoBandNextYTR[129] = isoBandNextYTR[41] = -1;
|
13914 | isoBandNextOTR[129] = isoBandNextOTR[41] = 0;
|
13915 |
|
13916 | isoBandNextXBR[66] = isoBandNextXBR[104] = 0;
|
13917 | isoBandNextYBR[66] = isoBandNextYBR[104] = 1;
|
13918 | isoBandNextOBR[66] = isoBandNextOBR[104] = 0;
|
13919 | isoBandNextXBL[66] = isoBandNextXBL[104] = -1;
|
13920 | isoBandNextYBL[66] = isoBandNextYBL[104] = 0;
|
13921 | isoBandNextOBL[66] = isoBandNextOBL[104] = 1;
|
13922 | isoBandNextXLT[66] = isoBandNextXLT[104] = 0;
|
13923 | isoBandNextYLT[66] = isoBandNextYLT[104] = -1;
|
13924 | isoBandNextOLT[66] = isoBandNextOLT[104] = 0;
|
13925 | isoBandNextXTL[66] = isoBandNextXTL[104] = 0;
|
13926 | isoBandNextYTL[66] = isoBandNextYTL[104] = -1;
|
13927 | isoBandNextOTL[66] = isoBandNextOTL[104] = 1;
|
13928 |
|
13929 | isoBandNextXRT[144] = isoBandNextXRT[26] = -1;
|
13930 | isoBandNextYRT[144] = isoBandNextYRT[26] = 0;
|
13931 | isoBandNextORT[144] = isoBandNextORT[26] = 0;
|
13932 | isoBandNextXLB[144] = isoBandNextXLB[26] = 1;
|
13933 | isoBandNextYLB[144] = isoBandNextYLB[26] = 0;
|
13934 | isoBandNextOLB[144] = isoBandNextOLB[26] = 1;
|
13935 | isoBandNextXLT[144] = isoBandNextXLT[26] = 0;
|
13936 | isoBandNextYLT[144] = isoBandNextYLT[26] = 1;
|
13937 | isoBandNextOLT[144] = isoBandNextOLT[26] = 1;
|
13938 | isoBandNextXTR[144] = isoBandNextXTR[26] = -1;
|
13939 | isoBandNextYTR[144] = isoBandNextYTR[26] = 0;
|
13940 | isoBandNextOTR[144] = isoBandNextOTR[26] = 1;
|
13941 |
|
13942 | isoBandNextXRB[36] = isoBandNextXRB[134] = 0;
|
13943 | isoBandNextYRB[36] = isoBandNextYRB[134] = 1;
|
13944 | isoBandNextORB[36] = isoBandNextORB[134] = 1;
|
13945 | isoBandNextXBR[36] = isoBandNextXBR[134] = 0;
|
13946 | isoBandNextYBR[36] = isoBandNextYBR[134] = 1;
|
13947 | isoBandNextOBR[36] = isoBandNextOBR[134] = 0;
|
13948 | isoBandNextXTL[36] = isoBandNextXTL[134] = 0;
|
13949 | isoBandNextYTL[36] = isoBandNextYTL[134] = -1;
|
13950 | isoBandNextOTL[36] = isoBandNextOTL[134] = 1;
|
13951 | isoBandNextXTR[36] = isoBandNextXTR[134] = 1;
|
13952 | isoBandNextYTR[36] = isoBandNextYTR[134] = 0;
|
13953 | isoBandNextOTR[36] = isoBandNextOTR[134] = 0;
|
13954 |
|
13955 | isoBandNextXRT[9] = isoBandNextXRT[161] = -1;
|
13956 | isoBandNextYRT[9] = isoBandNextYRT[161] = 0;
|
13957 | isoBandNextORT[9] = isoBandNextORT[161] = 0;
|
13958 | isoBandNextXRB[9] = isoBandNextXRB[161] = 0;
|
13959 | isoBandNextYRB[9] = isoBandNextYRB[161] = -1;
|
13960 | isoBandNextORB[9] = isoBandNextORB[161] = 0;
|
13961 | isoBandNextXBL[9] = isoBandNextXBL[161] = 1;
|
13962 | isoBandNextYBL[9] = isoBandNextYBL[161] = 0;
|
13963 | isoBandNextOBL[9] = isoBandNextOBL[161] = 0;
|
13964 | isoBandNextXLB[9] = isoBandNextXLB[161] = 1;
|
13965 | isoBandNextYLB[9] = isoBandNextYLB[161] = 0;
|
13966 | isoBandNextOLB[9] = isoBandNextOLB[161] = 1;
|
13967 |
|
13968 |
|
13969 | isoBandNextXRT[136] = 0;
|
13970 | isoBandNextYRT[136] = 1;
|
13971 | isoBandNextORT[136] = 1;
|
13972 | isoBandNextXRB[136] = 0;
|
13973 | isoBandNextYRB[136] = 1;
|
13974 | isoBandNextORB[136] = 0;
|
13975 | isoBandNextXBR[136] = -1;
|
13976 | isoBandNextYBR[136] = 0;
|
13977 | isoBandNextOBR[136] = 1;
|
13978 | isoBandNextXBL[136] = -1;
|
13979 | isoBandNextYBL[136] = 0;
|
13980 | isoBandNextOBL[136] = 0;
|
13981 | isoBandNextXLB[136] = 0;
|
13982 | isoBandNextYLB[136] = -1;
|
13983 | isoBandNextOLB[136] = 0;
|
13984 | isoBandNextXLT[136] = 0;
|
13985 | isoBandNextYLT[136] = -1;
|
13986 | isoBandNextOLT[136] = 1;
|
13987 | isoBandNextXTL[136] = 1;
|
13988 | isoBandNextYTL[136] = 0;
|
13989 | isoBandNextOTL[136] = 0;
|
13990 | isoBandNextXTR[136] = 1;
|
13991 | isoBandNextYTR[136] = 0;
|
13992 | isoBandNextOTR[136] = 1;
|
13993 |
|
13994 | isoBandNextXRT[34] = 0;
|
13995 | isoBandNextYRT[34] = -1;
|
13996 | isoBandNextORT[34] = 0;
|
13997 | isoBandNextXRB[34] = 0;
|
13998 | isoBandNextYRB[34] = -1;
|
13999 | isoBandNextORB[34] = 1;
|
14000 | isoBandNextXBR[34] = 1;
|
14001 | isoBandNextYBR[34] = 0;
|
14002 | isoBandNextOBR[34] = 0;
|
14003 | isoBandNextXBL[34] = 1;
|
14004 | isoBandNextYBL[34] = 0;
|
14005 | isoBandNextOBL[34] = 1;
|
14006 | isoBandNextXLB[34] = 0;
|
14007 | isoBandNextYLB[34] = 1;
|
14008 | isoBandNextOLB[34] = 1;
|
14009 | isoBandNextXLT[34] = 0;
|
14010 | isoBandNextYLT[34] = 1;
|
14011 | isoBandNextOLT[34] = 0;
|
14012 | isoBandNextXTL[34] = -1;
|
14013 | isoBandNextYTL[34] = 0;
|
14014 | isoBandNextOTL[34] = 1;
|
14015 | isoBandNextXTR[34] = -1;
|
14016 | isoBandNextYTR[34] = 0;
|
14017 | isoBandNextOTR[34] = 0;
|
14018 |
|
14019 | isoBandNextXRT[35] = 0;
|
14020 | isoBandNextYRT[35] = 1;
|
14021 | isoBandNextORT[35] = 1;
|
14022 | isoBandNextXRB[35] = 0;
|
14023 | isoBandNextYRB[35] = -1;
|
14024 | isoBandNextORB[35] = 1;
|
14025 | isoBandNextXBR[35] = 1;
|
14026 | isoBandNextYBR[35] = 0;
|
14027 | isoBandNextOBR[35] = 0;
|
14028 | isoBandNextXBL[35] = -1;
|
14029 | isoBandNextYBL[35] = 0;
|
14030 | isoBandNextOBL[35] = 0;
|
14031 | isoBandNextXLB[35] = 0;
|
14032 | isoBandNextYLB[35] = -1;
|
14033 | isoBandNextOLB[35] = 0;
|
14034 | isoBandNextXLT[35] = 0;
|
14035 | isoBandNextYLT[35] = 1;
|
14036 | isoBandNextOLT[35] = 0;
|
14037 | isoBandNextXTL[35] = -1;
|
14038 | isoBandNextYTL[35] = 0;
|
14039 | isoBandNextOTL[35] = 1;
|
14040 | isoBandNextXTR[35] = 1;
|
14041 | isoBandNextYTR[35] = 0;
|
14042 | isoBandNextOTR[35] = 1;
|
14043 |
|
14044 |
|
14045 | isoBandNextXRT[153] = 0;
|
14046 | isoBandNextYRT[153] = 1;
|
14047 | isoBandNextORT[153] = 1;
|
14048 | isoBandNextXBL[153] = -1;
|
14049 | isoBandNextYBL[153] = 0;
|
14050 | isoBandNextOBL[153] = 0;
|
14051 | isoBandNextXLB[153] = 0;
|
14052 | isoBandNextYLB[153] = -1;
|
14053 | isoBandNextOLB[153] = 0;
|
14054 | isoBandNextXTR[153] = 1;
|
14055 | isoBandNextYTR[153] = 0;
|
14056 | isoBandNextOTR[153] = 1;
|
14057 |
|
14058 | isoBandNextXRB[102] = 0;
|
14059 | isoBandNextYRB[102] = -1;
|
14060 | isoBandNextORB[102] = 1;
|
14061 | isoBandNextXBR[102] = 1;
|
14062 | isoBandNextYBR[102] = 0;
|
14063 | isoBandNextOBR[102] = 0;
|
14064 | isoBandNextXLT[102] = 0;
|
14065 | isoBandNextYLT[102] = 1;
|
14066 | isoBandNextOLT[102] = 0;
|
14067 | isoBandNextXTL[102] = -1;
|
14068 | isoBandNextYTL[102] = 0;
|
14069 | isoBandNextOTL[102] = 1;
|
14070 |
|
14071 | isoBandNextXRT[155] = 0;
|
14072 | isoBandNextYRT[155] = -1;
|
14073 | isoBandNextORT[155] = 0;
|
14074 | isoBandNextXBL[155] = 1;
|
14075 | isoBandNextYBL[155] = 0;
|
14076 | isoBandNextOBL[155] = 1;
|
14077 | isoBandNextXLB[155] = 0;
|
14078 | isoBandNextYLB[155] = 1;
|
14079 | isoBandNextOLB[155] = 1;
|
14080 | isoBandNextXTR[155] = -1;
|
14081 | isoBandNextYTR[155] = 0;
|
14082 | isoBandNextOTR[155] = 0;
|
14083 |
|
14084 | isoBandNextXRB[103] = 0;
|
14085 | isoBandNextYRB[103] = 1;
|
14086 | isoBandNextORB[103] = 0;
|
14087 | isoBandNextXBR[103] = -1;
|
14088 | isoBandNextYBR[103] = 0;
|
14089 | isoBandNextOBR[103] = 1;
|
14090 | isoBandNextXLT[103] = 0;
|
14091 | isoBandNextYLT[103] = -1;
|
14092 | isoBandNextOLT[103] = 1;
|
14093 | isoBandNextXTL[103] = 1;
|
14094 | isoBandNextYTL[103] = 0;
|
14095 | isoBandNextOTL[103] = 0;
|
14096 |
|
14097 |
|
14098 | isoBandNextXRT[152] = 0;
|
14099 | isoBandNextYRT[152] = 1;
|
14100 | isoBandNextORT[152] = 1;
|
14101 | isoBandNextXBR[152] = -1;
|
14102 | isoBandNextYBR[152] = 0;
|
14103 | isoBandNextOBR[152] = 1;
|
14104 | isoBandNextXBL[152] = -1;
|
14105 | isoBandNextYBL[152] = 0;
|
14106 | isoBandNextOBL[152] = 0;
|
14107 | isoBandNextXLB[152] = 0;
|
14108 | isoBandNextYLB[152] = -1;
|
14109 | isoBandNextOLB[152] = 0;
|
14110 | isoBandNextXLT[152] = 0;
|
14111 | isoBandNextYLT[152] = -1;
|
14112 | isoBandNextOLT[152] = 1;
|
14113 | isoBandNextXTR[152] = 1;
|
14114 | isoBandNextYTR[152] = 0;
|
14115 | isoBandNextOTR[152] = 1;
|
14116 |
|
14117 | isoBandNextXRT[156] = 0;
|
14118 | isoBandNextYRT[156] = -1;
|
14119 | isoBandNextORT[156] = 1;
|
14120 | isoBandNextXBR[156] = 1;
|
14121 | isoBandNextYBR[156] = 0;
|
14122 | isoBandNextOBR[156] = 1;
|
14123 | isoBandNextXBL[156] = -1;
|
14124 | isoBandNextYBL[156] = 0;
|
14125 | isoBandNextOBL[156] = 0;
|
14126 | isoBandNextXLB[156] = 0;
|
14127 | isoBandNextYLB[156] = -1;
|
14128 | isoBandNextOLB[156] = 0;
|
14129 | isoBandNextXLT[156] = 0;
|
14130 | isoBandNextYLT[156] = 1;
|
14131 | isoBandNextOLT[156] = 1;
|
14132 | isoBandNextXTR[156] = -1;
|
14133 | isoBandNextYTR[156] = 0;
|
14134 | isoBandNextOTR[156] = 1;
|
14135 |
|
14136 | isoBandNextXRT[137] = 0;
|
14137 | isoBandNextYRT[137] = 1;
|
14138 | isoBandNextORT[137] = 1;
|
14139 | isoBandNextXRB[137] = 0;
|
14140 | isoBandNextYRB[137] = 1;
|
14141 | isoBandNextORB[137] = 0;
|
14142 | isoBandNextXBL[137] = -1;
|
14143 | isoBandNextYBL[137] = 0;
|
14144 | isoBandNextOBL[137] = 0;
|
14145 | isoBandNextXLB[137] = 0;
|
14146 | isoBandNextYLB[137] = -1;
|
14147 | isoBandNextOLB[137] = 0;
|
14148 | isoBandNextXTL[137] = 1;
|
14149 | isoBandNextYTL[137] = 0;
|
14150 | isoBandNextOTL[137] = 0;
|
14151 | isoBandNextXTR[137] = 1;
|
14152 | isoBandNextYTR[137] = 0;
|
14153 | isoBandNextOTR[137] = 1;
|
14154 |
|
14155 | isoBandNextXRT[139] = 0;
|
14156 | isoBandNextYRT[139] = 1;
|
14157 | isoBandNextORT[139] = 1;
|
14158 | isoBandNextXRB[139] = 0;
|
14159 | isoBandNextYRB[139] = -1;
|
14160 | isoBandNextORB[139] = 0;
|
14161 | isoBandNextXBL[139] = 1;
|
14162 | isoBandNextYBL[139] = 0;
|
14163 | isoBandNextOBL[139] = 0;
|
14164 | isoBandNextXLB[139] = 0;
|
14165 | isoBandNextYLB[139] = 1;
|
14166 | isoBandNextOLB[139] = 0;
|
14167 | isoBandNextXTL[139] = -1;
|
14168 | isoBandNextYTL[139] = 0;
|
14169 | isoBandNextOTL[139] = 0;
|
14170 | isoBandNextXTR[139] = 1;
|
14171 | isoBandNextYTR[139] = 0;
|
14172 | isoBandNextOTR[139] = 1;
|
14173 |
|
14174 | isoBandNextXRT[98] = 0;
|
14175 | isoBandNextYRT[98] = -1;
|
14176 | isoBandNextORT[98] = 0;
|
14177 | isoBandNextXRB[98] = 0;
|
14178 | isoBandNextYRB[98] = -1;
|
14179 | isoBandNextORB[98] = 1;
|
14180 | isoBandNextXBR[98] = 1;
|
14181 | isoBandNextYBR[98] = 0;
|
14182 | isoBandNextOBR[98] = 0;
|
14183 | isoBandNextXBL[98] = 1;
|
14184 | isoBandNextYBL[98] = 0;
|
14185 | isoBandNextOBL[98] = 1;
|
14186 | isoBandNextXLT[98] = 0;
|
14187 | isoBandNextYLT[98] = 1;
|
14188 | isoBandNextOLT[98] = 0;
|
14189 | isoBandNextXTL[98] = -1;
|
14190 | isoBandNextYTL[98] = 0;
|
14191 | isoBandNextOTL[98] = 1;
|
14192 |
|
14193 | isoBandNextXRT[99] = 0;
|
14194 | isoBandNextYRT[99] = 1;
|
14195 | isoBandNextORT[99] = 0;
|
14196 | isoBandNextXRB[99] = 0;
|
14197 | isoBandNextYRB[99] = -1;
|
14198 | isoBandNextORB[99] = 1;
|
14199 | isoBandNextXBR[99] = 1;
|
14200 | isoBandNextYBR[99] = 0;
|
14201 | isoBandNextOBR[99] = 0;
|
14202 | isoBandNextXBL[99] = -1;
|
14203 | isoBandNextYBL[99] = 0;
|
14204 | isoBandNextOBL[99] = 1;
|
14205 | isoBandNextXLT[99] = 0;
|
14206 | isoBandNextYLT[99] = -1;
|
14207 | isoBandNextOLT[99] = 0;
|
14208 | isoBandNextXTL[99] = 1;
|
14209 | isoBandNextYTL[99] = 0;
|
14210 | isoBandNextOTL[99] = 1;
|
14211 |
|
14212 | isoBandNextXRB[38] = 0;
|
14213 | isoBandNextYRB[38] = -1;
|
14214 | isoBandNextORB[38] = 1;
|
14215 | isoBandNextXBR[38] = 1;
|
14216 | isoBandNextYBR[38] = 0;
|
14217 | isoBandNextOBR[38] = 0;
|
14218 | isoBandNextXLB[38] = 0;
|
14219 | isoBandNextYLB[38] = 1;
|
14220 | isoBandNextOLB[38] = 1;
|
14221 | isoBandNextXLT[38] = 0;
|
14222 | isoBandNextYLT[38] = 1;
|
14223 | isoBandNextOLT[38] = 0;
|
14224 | isoBandNextXTL[38] = -1;
|
14225 | isoBandNextYTL[38] = 0;
|
14226 | isoBandNextOTL[38] = 1;
|
14227 | isoBandNextXTR[38] = -1;
|
14228 | isoBandNextYTR[38] = 0;
|
14229 | isoBandNextOTR[38] = 0;
|
14230 |
|
14231 | isoBandNextXRB[39] = 0;
|
14232 | isoBandNextYRB[39] = 1;
|
14233 | isoBandNextORB[39] = 1;
|
14234 | isoBandNextXBR[39] = -1;
|
14235 | isoBandNextYBR[39] = 0;
|
14236 | isoBandNextOBR[39] = 0;
|
14237 | isoBandNextXLB[39] = 0;
|
14238 | isoBandNextYLB[39] = -1;
|
14239 | isoBandNextOLB[39] = 1;
|
14240 | isoBandNextXLT[39] = 0;
|
14241 | isoBandNextYLT[39] = 1;
|
14242 | isoBandNextOLT[39] = 0;
|
14243 | isoBandNextXTL[39] = -1;
|
14244 | isoBandNextYTL[39] = 0;
|
14245 | isoBandNextOTL[39] = 1;
|
14246 | isoBandNextXTR[39] = 1;
|
14247 | isoBandNextYTR[39] = 0;
|
14248 | isoBandNextOTR[39] = 0;
|
14249 |
|
14250 |
|
14251 |
|
14252 |
|
14253 |
|
14254 |
|
14255 |
|
14256 | var p00 = function (cell) {
|
14257 | return [[cell.bottomleft, 0], [0, 0], [0, cell.leftbottom]];
|
14258 | };
|
14259 | var p01 = function (cell) {
|
14260 | return [[1, cell.rightbottom], [1, 0], [cell.bottomright, 0]];
|
14261 | };
|
14262 | var p02 = function (cell) {
|
14263 | return [[cell.topright, 1], [1, 1], [1, cell.righttop]];
|
14264 | };
|
14265 | var p03 = function (cell) {
|
14266 | return [[0, cell.lefttop], [0, 1], [cell.topleft, 1]];
|
14267 | };
|
14268 |
|
14269 | var p04 = function (cell) {
|
14270 | return [[cell.bottomright, 0], [cell.bottomleft, 0], [0, cell.leftbottom], [0, cell.lefttop]];
|
14271 | };
|
14272 | var p05 = function (cell) {
|
14273 | return [[cell.bottomright, 0], [cell.bottomleft, 0], [1, cell.righttop], [1, cell.rightbottom]];
|
14274 | };
|
14275 | var p06 = function (cell) {
|
14276 | return [[1, cell.righttop], [1, cell.rightbottom], [cell.topleft, 1], [cell.topright, 1]];
|
14277 | };
|
14278 | var p07 = function (cell) {
|
14279 | return [[0, cell.leftbottom], [0, cell.lefttop], [cell.topleft, 1], [cell.topright, 1]];
|
14280 | };
|
14281 |
|
14282 | var p08 = function (cell) {
|
14283 | return [[0, 0], [0, cell.leftbottom], [1, cell.rightbottom], [1, 0]];
|
14284 | };
|
14285 | var p09 = function (cell) {
|
14286 | return [[1, 0], [cell.bottomright, 0], [cell.topright, 1], [1, 1]];
|
14287 | };
|
14288 | var p10 = function (cell) {
|
14289 | return [[1, 1], [1, cell.righttop], [0, cell.lefttop], [0, 1]];
|
14290 | };
|
14291 | var p11 = function (cell) {
|
14292 | return [[cell.bottomleft, 0], [0, 0], [0, 1], [cell.topleft, 1]];
|
14293 | };
|
14294 | var p12 = function (cell) {
|
14295 | return [[1, cell.righttop], [1, cell.rightbottom], [0, cell.leftbottom], [0, cell.lefttop]];
|
14296 | };
|
14297 | var p13 = function (cell) {
|
14298 | return [[cell.topleft, 1], [cell.topright, 1], [cell.bottomright, 0], [cell.bottomleft, 0]];
|
14299 | };
|
14300 |
|
14301 | var p14 = function () {
|
14302 | return [[0, 0], [0, 1], [1, 1], [1, 0]];
|
14303 | };
|
14304 |
|
14305 | var p15 = function (cell) {
|
14306 | return [[1, cell.rightbottom], [1, 0], [0, 0], [0, 1], [cell.topleft, 1]];
|
14307 | };
|
14308 |
|
14309 | var p16 = function (cell) {
|
14310 | return [[cell.topright, 1], [1, 1], [1, 0], [0, 0], [0, cell.leftbottom]];
|
14311 | };
|
14312 |
|
14313 | var p17 = function (cell) {
|
14314 | return [[1, 0], [cell.bottomright, 0], [0, cell.lefttop], [0, 1], [1, 1]];
|
14315 | };
|
14316 |
|
14317 | var p18 = function (cell) {
|
14318 | return [[1, 1], [1, cell.righttop], [cell.bottomleft, 0], [0, 0], [0, 1]];
|
14319 | };
|
14320 |
|
14321 | var p19 = function (cell) {
|
14322 | return [[1, cell.righttop], [1, cell.rightbottom], [0, cell.lefttop], [0, 1], [cell.topleft, 1]];
|
14323 | };
|
14324 |
|
14325 | var p20 = function (cell) {
|
14326 | return [[1, 1], [1, cell.righttop], [cell.bottomright, 0], [cell.bottomleft, 0], [cell.topright, 1]];
|
14327 | };
|
14328 |
|
14329 | var p21 = function (cell) {
|
14330 | return [[1, cell.rightbottom], [1, 0], [cell.bottomright, 0], [0, cell.leftbottom], [0, cell.lefttop]];
|
14331 | };
|
14332 |
|
14333 | var p22 = function (cell) {
|
14334 | return [[cell.topright, 1], [cell.bottomleft, 0], [0, 0], [0, cell.leftbottom], [cell.topleft, 1]];
|
14335 | };
|
14336 |
|
14337 | var p23 = function (cell) {
|
14338 | return [[cell.bottomright, 0], [cell.bottomleft, 0], [0, cell.lefttop], [0, 1], [cell.topleft, 1]];
|
14339 | };
|
14340 |
|
14341 | var p24 = function (cell) {
|
14342 | return [[1, 1], [1, cell.righttop], [0, cell.leftbottom], [0, cell.lefttop], [cell.topright, 1]];
|
14343 | };
|
14344 |
|
14345 | var p25 = function (cell) {
|
14346 | return [[1, cell.rightbottom], [1, 0], [cell.bottomright, 0], [cell.topleft, 1], [cell.topright, 1]];
|
14347 | };
|
14348 |
|
14349 | var p26 = function (cell) {
|
14350 | return [[1, cell.righttop], [1, cell.rightbottom], [cell.bottomleft, 0], [0, 0], [0, cell.leftbottom]];
|
14351 | };
|
14352 |
|
14353 |
|
14354 | var p27 = function (cell) {
|
14355 | return [[1, cell.rightbottom], [1, 0], [0, 0], [0, cell.leftbottom], [cell.topleft, 1], [cell.topright, 1]];
|
14356 | };
|
14357 |
|
14358 | var p28 = function (cell) {
|
14359 | return [[1, 1], [1, 0], [cell.bottomright, 0], [0, cell.leftbottom], [0, cell.lefttop], [cell.topright, 1]];
|
14360 | };
|
14361 |
|
14362 | var p29 = function (cell) {
|
14363 | return [[1, 1], [1, cell.righttop], [cell.bottomright, 0], [cell.bottomleft, 0], [0, cell.lefttop], [0, 1]];
|
14364 | };
|
14365 |
|
14366 | var p30 = function (cell) {
|
14367 | return [[1, cell.righttop], [1, cell.rightbottom], [cell.bottomleft, 0], [0, 0], [0, 1], [cell.topleft, 1]];
|
14368 | };
|
14369 |
|
14370 | var p31 = function (cell) {
|
14371 | return [[1, 1], [1, cell.righttop], [cell.bottomleft, 0], [0, 0], [0, cell.leftbottom], [cell.topright, 1]];
|
14372 | };
|
14373 |
|
14374 | var p32 = function (cell) {
|
14375 | return [[1, cell.rightbottom], [1, 0], [cell.bottomright, 0], [0, cell.lefttop], [0, 1], [cell.topleft, 1]];
|
14376 | };
|
14377 |
|
14378 |
|
14379 | var p33 = function (cell) {
|
14380 | return [[1, cell.righttop], [1, cell.rightbottom], [cell.bottomright, 0], [cell.bottomleft, 0], [0, cell.leftbottom], [0, cell.lefttop], [cell.topleft, 1], [cell.topright, 1]];
|
14381 | };
|
14382 |
|
14383 |
|
14384 | var p34 = function (cell) {
|
14385 | return [[1, 1], [1, cell.righttop], [cell.bottomleft, 0], [0, 0], [0, cell.leftbottom], [cell.topright, 1]];
|
14386 | };
|
14387 |
|
14388 | var p35 = function (cell) {
|
14389 | return [[1, cell.rightbottom], [1, 0], [cell.bottomright, 0], [0, cell.lefttop], [0, 1], [cell.topleft, 1]];
|
14390 | };
|
14391 |
|
14392 |
|
14393 | var p36 = function (cell) {
|
14394 | return [[1, 1], [1, cell.righttop], [cell.bottomright, 0], [cell.bottomleft, 0], [0, cell.leftbottom], [0, cell.lefttop], [cell.topright, 1]];
|
14395 | };
|
14396 |
|
14397 | var p37 = function (cell) {
|
14398 | return [[1, cell.righttop], [1, cell.rightbottom], [cell.bottomleft, 0], [0, 0], [0, cell.leftbottom], [cell.topleft, 1], [cell.topright, 1]];
|
14399 | };
|
14400 |
|
14401 | var p38 = function (cell) {
|
14402 | return [[1, cell.righttop], [1, cell.rightbottom], [cell.bottomright, 0], [cell.bottomleft, 0], [0, cell.lefttop], [0, 1], [cell.topleft, 1]];
|
14403 | };
|
14404 |
|
14405 | var p39 = function (cell) {
|
14406 | return [[1, cell.rightbottom], [1, 0], [cell.bottomright, 0], [0, cell.leftbottom], [0, cell.lefttop], [cell.topleft, 1], [cell.topright, 1]];
|
14407 | };
|
14408 |
|
14409 |
|
14410 |
|
14411 |
|
14412 |
|
14413 |
|
14414 |
|
14415 |
|
14416 |
|
14417 | var isoBandEdgeRT = [];
|
14418 | var isoBandEdgeRB = [];
|
14419 | var isoBandEdgeBR = [];
|
14420 | var isoBandEdgeBL = [];
|
14421 | var isoBandEdgeLB = [];
|
14422 | var isoBandEdgeLT = [];
|
14423 | var isoBandEdgeTL = [];
|
14424 | var isoBandEdgeTR = [];
|
14425 |
|
14426 |
|
14427 | isoBandEdgeBL[1] = isoBandEdgeLB[1] = 18;
|
14428 | isoBandEdgeBL[169] = isoBandEdgeLB[169] = 18;
|
14429 | isoBandEdgeBR[4] = isoBandEdgeRB[4] = 12;
|
14430 | isoBandEdgeBR[166] = isoBandEdgeRB[166] = 12;
|
14431 | isoBandEdgeRT[16] = isoBandEdgeTR[16] = 4;
|
14432 | isoBandEdgeRT[154] = isoBandEdgeTR[154] = 4;
|
14433 | isoBandEdgeLT[64] = isoBandEdgeTL[64] = 22;
|
14434 | isoBandEdgeLT[106] = isoBandEdgeTL[106] = 22;
|
14435 |
|
14436 |
|
14437 | isoBandEdgeBR[2] = isoBandEdgeLT[2] = 17;
|
14438 | isoBandEdgeBL[2] = isoBandEdgeLB[2] = 18;
|
14439 | isoBandEdgeBR[168] = isoBandEdgeLT[168] = 17;
|
14440 | isoBandEdgeBL[168] = isoBandEdgeLB[168] = 18;
|
14441 | isoBandEdgeRT[8] = isoBandEdgeBL[8] = 9;
|
14442 | isoBandEdgeRB[8] = isoBandEdgeBR[8] = 12;
|
14443 | isoBandEdgeRT[162] = isoBandEdgeBL[162] = 9;
|
14444 | isoBandEdgeRB[162] = isoBandEdgeBR[162] = 12;
|
14445 | isoBandEdgeRT[32] = isoBandEdgeTR[32] = 4;
|
14446 | isoBandEdgeRB[32] = isoBandEdgeTL[32] = 1;
|
14447 | isoBandEdgeRT[138] = isoBandEdgeTR[138] = 4;
|
14448 | isoBandEdgeRB[138] = isoBandEdgeTL[138] = 1;
|
14449 | isoBandEdgeLB[128] = isoBandEdgeTR[128] = 21;
|
14450 | isoBandEdgeLT[128] = isoBandEdgeTL[128] = 22;
|
14451 | isoBandEdgeLB[42] = isoBandEdgeTR[42] = 21;
|
14452 | isoBandEdgeLT[42] = isoBandEdgeTL[42] = 22;
|
14453 |
|
14454 |
|
14455 | isoBandEdgeRB[5] = isoBandEdgeLB[5] = 14;
|
14456 | isoBandEdgeRB[165] = isoBandEdgeLB[165] = 14;
|
14457 | isoBandEdgeBR[20] = isoBandEdgeTR[20] = 6;
|
14458 | isoBandEdgeBR[150] = isoBandEdgeTR[150] = 6;
|
14459 | isoBandEdgeRT[80] = isoBandEdgeLT[80] = 11;
|
14460 | isoBandEdgeRT[90] = isoBandEdgeLT[90] = 11;
|
14461 | isoBandEdgeBL[65] = isoBandEdgeTL[65] = 3;
|
14462 | isoBandEdgeBL[105] = isoBandEdgeTL[105] = 3;
|
14463 | isoBandEdgeRT[160] = isoBandEdgeLT[160] = 11;
|
14464 | isoBandEdgeRB[160] = isoBandEdgeLB[160] = 14;
|
14465 | isoBandEdgeRT[10] = isoBandEdgeLT[10] = 11;
|
14466 | isoBandEdgeRB[10] = isoBandEdgeLB[10] = 14;
|
14467 | isoBandEdgeBR[130] = isoBandEdgeTR[130] = 6;
|
14468 | isoBandEdgeBL[130] = isoBandEdgeTL[130] = 3;
|
14469 | isoBandEdgeBR[40] = isoBandEdgeTR[40] = 6;
|
14470 | isoBandEdgeBL[40] = isoBandEdgeTL[40] = 3;
|
14471 |
|
14472 |
|
14473 | isoBandEdgeRB[101] = isoBandEdgeTL[101] = 1;
|
14474 | isoBandEdgeRB[69] = isoBandEdgeTL[69] = 1;
|
14475 | isoBandEdgeLB[149] = isoBandEdgeTR[149] = 21;
|
14476 | isoBandEdgeLB[21] = isoBandEdgeTR[21] = 21;
|
14477 | isoBandEdgeBR[86] = isoBandEdgeLT[86] = 17;
|
14478 | isoBandEdgeBR[84] = isoBandEdgeLT[84] = 17;
|
14479 | isoBandEdgeRT[89] = isoBandEdgeBL[89] = 9;
|
14480 | isoBandEdgeRT[81] = isoBandEdgeBL[81] = 9;
|
14481 | isoBandEdgeRT[96] = isoBandEdgeTL[96] = 0;
|
14482 | isoBandEdgeRB[96] = isoBandEdgeLT[96] = 15;
|
14483 | isoBandEdgeRT[74] = isoBandEdgeTL[74] = 0;
|
14484 | isoBandEdgeRB[74] = isoBandEdgeLT[74] = 15;
|
14485 | isoBandEdgeRT[24] = isoBandEdgeBR[24] = 8;
|
14486 | isoBandEdgeBL[24] = isoBandEdgeTR[24] = 7;
|
14487 | isoBandEdgeRT[146] = isoBandEdgeBR[146] = 8;
|
14488 | isoBandEdgeBL[146] = isoBandEdgeTR[146] = 7;
|
14489 | isoBandEdgeRB[6] = isoBandEdgeLT[6] = 15;
|
14490 | isoBandEdgeBR[6] = isoBandEdgeLB[6] = 16;
|
14491 | isoBandEdgeRB[164] = isoBandEdgeLT[164] = 15;
|
14492 | isoBandEdgeBR[164] = isoBandEdgeLB[164] = 16;
|
14493 | isoBandEdgeBL[129] = isoBandEdgeTR[129] = 7;
|
14494 | isoBandEdgeLB[129] = isoBandEdgeTL[129] = 20;
|
14495 | isoBandEdgeBL[41] = isoBandEdgeTR[41] = 7;
|
14496 | isoBandEdgeLB[41] = isoBandEdgeTL[41] = 20;
|
14497 | isoBandEdgeBR[66] = isoBandEdgeTL[66] = 2;
|
14498 | isoBandEdgeBL[66] = isoBandEdgeLT[66] = 19;
|
14499 | isoBandEdgeBR[104] = isoBandEdgeTL[104] = 2;
|
14500 | isoBandEdgeBL[104] = isoBandEdgeLT[104] = 19;
|
14501 | isoBandEdgeRT[144] = isoBandEdgeLB[144] = 10;
|
14502 | isoBandEdgeLT[144] = isoBandEdgeTR[144] = 23;
|
14503 | isoBandEdgeRT[26] = isoBandEdgeLB[26] = 10;
|
14504 | isoBandEdgeLT[26] = isoBandEdgeTR[26] = 23;
|
14505 | isoBandEdgeRB[36] = isoBandEdgeTR[36] = 5;
|
14506 | isoBandEdgeBR[36] = isoBandEdgeTL[36] = 2;
|
14507 | isoBandEdgeRB[134] = isoBandEdgeTR[134] = 5;
|
14508 | isoBandEdgeBR[134] = isoBandEdgeTL[134] = 2;
|
14509 | isoBandEdgeRT[9] = isoBandEdgeLB[9] = 10;
|
14510 | isoBandEdgeRB[9] = isoBandEdgeBL[9] = 13;
|
14511 | isoBandEdgeRT[161] = isoBandEdgeLB[161] = 10;
|
14512 | isoBandEdgeRB[161] = isoBandEdgeBL[161] = 13;
|
14513 |
|
14514 |
|
14515 | isoBandEdgeRB[37] = isoBandEdgeTR[37] = 5;
|
14516 | isoBandEdgeLB[37] = isoBandEdgeTL[37] = 20;
|
14517 | isoBandEdgeRB[133] = isoBandEdgeTR[133] = 5;
|
14518 | isoBandEdgeLB[133] = isoBandEdgeTL[133] = 20;
|
14519 | isoBandEdgeBR[148] = isoBandEdgeLB[148] = 16;
|
14520 | isoBandEdgeLT[148] = isoBandEdgeTR[148] = 23;
|
14521 | isoBandEdgeBR[22] = isoBandEdgeLB[22] = 16;
|
14522 | isoBandEdgeLT[22] = isoBandEdgeTR[22] = 23;
|
14523 | isoBandEdgeRT[82] = isoBandEdgeBR[82] = 8;
|
14524 | isoBandEdgeBL[82] = isoBandEdgeLT[82] = 19;
|
14525 | isoBandEdgeRT[88] = isoBandEdgeBR[88] = 8;
|
14526 | isoBandEdgeBL[88] = isoBandEdgeLT[88] = 19;
|
14527 | isoBandEdgeRT[73] = isoBandEdgeTL[73] = 0;
|
14528 | isoBandEdgeRB[73] = isoBandEdgeBL[73] = 13;
|
14529 | isoBandEdgeRT[97] = isoBandEdgeTL[97] = 0;
|
14530 | isoBandEdgeRB[97] = isoBandEdgeBL[97] = 13;
|
14531 | isoBandEdgeRT[145] = isoBandEdgeBL[145] = 9;
|
14532 | isoBandEdgeLB[145] = isoBandEdgeTR[145] = 21;
|
14533 | isoBandEdgeRT[25] = isoBandEdgeBL[25] = 9;
|
14534 | isoBandEdgeLB[25] = isoBandEdgeTR[25] = 21;
|
14535 | isoBandEdgeRB[70] = isoBandEdgeTL[70] = 1;
|
14536 | isoBandEdgeBR[70] = isoBandEdgeLT[70] = 17;
|
14537 | isoBandEdgeRB[100] = isoBandEdgeTL[100] = 1;
|
14538 | isoBandEdgeBR[100] = isoBandEdgeLT[100] = 17;
|
14539 |
|
14540 |
|
14541 | isoBandEdgeRT[34] = isoBandEdgeBL[34] = 9;
|
14542 | isoBandEdgeRB[34] = isoBandEdgeBR[34] = 12;
|
14543 | isoBandEdgeLB[34] = isoBandEdgeTR[34] = 21;
|
14544 | isoBandEdgeLT[34] = isoBandEdgeTL[34] = 22;
|
14545 | isoBandEdgeRT[136] = isoBandEdgeTR[136] = 4;
|
14546 | isoBandEdgeRB[136] = isoBandEdgeTL[136] = 1;
|
14547 | isoBandEdgeBR[136] = isoBandEdgeLT[136] = 17;
|
14548 | isoBandEdgeBL[136] = isoBandEdgeLB[136] = 18;
|
14549 | isoBandEdgeRT[35] = isoBandEdgeTR[35] = 4;
|
14550 | isoBandEdgeRB[35] = isoBandEdgeBR[35] = 12;
|
14551 | isoBandEdgeBL[35] = isoBandEdgeLB[35] = 18;
|
14552 | isoBandEdgeLT[35] = isoBandEdgeTL[35] = 22;
|
14553 |
|
14554 |
|
14555 | isoBandEdgeRT[153] = isoBandEdgeTR[153] = 4;
|
14556 | isoBandEdgeBL[153] = isoBandEdgeLB[153] = 18;
|
14557 | isoBandEdgeRB[102] = isoBandEdgeBR[102] = 12;
|
14558 | isoBandEdgeLT[102] = isoBandEdgeTL[102] = 22;
|
14559 | isoBandEdgeRT[155] = isoBandEdgeBL[155] = 9;
|
14560 | isoBandEdgeLB[155] = isoBandEdgeTR[155] = 23;
|
14561 | isoBandEdgeRB[103] = isoBandEdgeTL[103] = 1;
|
14562 | isoBandEdgeBR[103] = isoBandEdgeLT[103] = 17;
|
14563 |
|
14564 |
|
14565 | isoBandEdgeRT[152] = isoBandEdgeTR[152] = 4;
|
14566 | isoBandEdgeBR[152] = isoBandEdgeLT[152] = 17;
|
14567 | isoBandEdgeBL[152] = isoBandEdgeLB[152] = 18;
|
14568 | isoBandEdgeRT[156] = isoBandEdgeBR[156] = 8;
|
14569 | isoBandEdgeBL[156] = isoBandEdgeLB[156] = 18;
|
14570 | isoBandEdgeLT[156] = isoBandEdgeTR[156] = 23;
|
14571 | isoBandEdgeRT[137] = isoBandEdgeTR[137] = 4;
|
14572 | isoBandEdgeRB[137] = isoBandEdgeTL[137] = 1;
|
14573 | isoBandEdgeBL[137] = isoBandEdgeLB[137] = 18;
|
14574 | isoBandEdgeRT[139] = isoBandEdgeTR[139] = 4;
|
14575 | isoBandEdgeRB[139] = isoBandEdgeBL[139] = 13;
|
14576 | isoBandEdgeLB[139] = isoBandEdgeTL[139] = 20;
|
14577 | isoBandEdgeRT[98] = isoBandEdgeBL[98] = 9;
|
14578 | isoBandEdgeRB[98] = isoBandEdgeBR[98] = 12;
|
14579 | isoBandEdgeLT[98] = isoBandEdgeTL[98] = 22;
|
14580 | isoBandEdgeRT[99] = isoBandEdgeTL[99] = 0;
|
14581 | isoBandEdgeRB[99] = isoBandEdgeBR[99] = 12;
|
14582 | isoBandEdgeBL[99] = isoBandEdgeLT[99] = 19;
|
14583 | isoBandEdgeRB[38] = isoBandEdgeBR[38] = 12;
|
14584 | isoBandEdgeLB[38] = isoBandEdgeTR[38] = 21;
|
14585 | isoBandEdgeLT[38] = isoBandEdgeTL[38] = 22;
|
14586 | isoBandEdgeRB[39] = isoBandEdgeTR[39] = 5;
|
14587 | isoBandEdgeBR[39] = isoBandEdgeLB[39] = 16;
|
14588 | isoBandEdgeLT[39] = isoBandEdgeTL[39] = 22;
|
14589 |
|
14590 |
|
14591 |
|
14592 |
|
14593 |
|
14594 |
|
14595 | var polygon_table = [];
|
14596 |
|
14597 |
|
14598 | polygon_table[1] = polygon_table[169] = p00;
|
14599 | polygon_table[4] = polygon_table[166] = p01;
|
14600 | polygon_table[16] = polygon_table[154] = p02;
|
14601 | polygon_table[64] = polygon_table[106] = p03;
|
14602 |
|
14603 |
|
14604 | polygon_table[168] = polygon_table[2] = p04;
|
14605 | polygon_table[162] = polygon_table[8] = p05;
|
14606 | polygon_table[138] = polygon_table[32] = p06;
|
14607 | polygon_table[42] = polygon_table[128] = p07;
|
14608 |
|
14609 |
|
14610 | polygon_table[5] = polygon_table[165] = p08;
|
14611 | polygon_table[20] = polygon_table[150] = p09;
|
14612 | polygon_table[80] = polygon_table[90] = p10;
|
14613 | polygon_table[65] = polygon_table[105] = p11;
|
14614 | polygon_table[160] = polygon_table[10] = p12;
|
14615 | polygon_table[130] = polygon_table[40] = p13;
|
14616 |
|
14617 |
|
14618 | polygon_table[85] = p14;
|
14619 |
|
14620 |
|
14621 | polygon_table[101] = polygon_table[69] = p15;
|
14622 | polygon_table[149] = polygon_table[21] = p16;
|
14623 | polygon_table[86] = polygon_table[84] = p17;
|
14624 | polygon_table[89] = polygon_table[81] = p18;
|
14625 | polygon_table[96] = polygon_table[74] = p19;
|
14626 | polygon_table[24] = polygon_table[146] = p20;
|
14627 | polygon_table[6] = polygon_table[164] = p21;
|
14628 | polygon_table[129] = polygon_table[41] = p22;
|
14629 | polygon_table[66] = polygon_table[104] = p23;
|
14630 | polygon_table[144] = polygon_table[26] = p24;
|
14631 | polygon_table[36] = polygon_table[134] = p25;
|
14632 | polygon_table[9] = polygon_table[161] = p26;
|
14633 |
|
14634 |
|
14635 | polygon_table[37] = polygon_table[133] = p27;
|
14636 | polygon_table[148] = polygon_table[22] = p28;
|
14637 | polygon_table[82] = polygon_table[88] = p29;
|
14638 | polygon_table[73] = polygon_table[97] = p30;
|
14639 | polygon_table[145] = polygon_table[25] = p31;
|
14640 | polygon_table[70] = polygon_table[100] = p32;
|
14641 |
|
14642 |
|
14643 | polygon_table[34] = function (c) { return [p07(c), p05(c)]; };
|
14644 | polygon_table[35] = p33;
|
14645 | polygon_table[136] = function (c) { return [p06(c), p04(c)]; };
|
14646 |
|
14647 |
|
14648 | polygon_table[153] = function (c) { return [p02(c), p00(c)]; };
|
14649 | polygon_table[102] = function (c) { return [p01(c), p03(c)]; };
|
14650 | polygon_table[155] = p34;
|
14651 | polygon_table[103] = p35;
|
14652 |
|
14653 |
|
14654 | polygon_table[152] = function (c) { return [p02(c), p04(c)]; };
|
14655 | polygon_table[156] = p36;
|
14656 | polygon_table[137] = function (c) { return [p06(c), p00(c)]; };
|
14657 | polygon_table[139] = p37;
|
14658 | polygon_table[98] = function (c) { return [p05(c), p03(c)]; };
|
14659 | polygon_table[99] = p38;
|
14660 | polygon_table[38] = function (c) { return [p01(c), p07(c)]; };
|
14661 | polygon_table[39] = p39;
|
14662 |
|
14663 |
|
14664 |
|
14665 |
|
14666 |
|
14667 |
|
14668 |
|
14669 |
|
14670 |
|
14671 | function interpolateX$1(y, y0, y1) {
|
14672 | return (y - y0) / (y1 - y0);
|
14673 | }
|
14674 |
|
14675 | function isArray(myArray) {
|
14676 | return myArray.constructor.toString().indexOf('Array') > -1;
|
14677 | }
|
14678 |
|
14679 |
|
14680 |
|
14681 |
|
14682 |
|
14683 |
|
14684 |
|
14685 | function computeBandGrid(data, minV, bandwidth) {
|
14686 | var rows = data.length - 1;
|
14687 | var cols = data[0].length - 1;
|
14688 | var BandGrid = { rows: rows, cols: cols, cells: [] };
|
14689 |
|
14690 | var maxV = minV + Math.abs(bandwidth);
|
14691 |
|
14692 | for (var j = 0; j < rows; ++j) {
|
14693 | BandGrid.cells[j] = [];
|
14694 | for (var i = 0; i < cols; ++i) {
|
14695 |
|
14696 | var cval = 0;
|
14697 |
|
14698 | var tl = data[j + 1][i];
|
14699 | var tr = data[j + 1][i + 1];
|
14700 | var br = data[j][i + 1];
|
14701 | var bl = data[j][i];
|
14702 |
|
14703 | if (isNaN(tl) || isNaN(tr) || isNaN(br) || isNaN(bl)) {
|
14704 | continue;
|
14705 | }
|
14706 |
|
14707 | cval |= (tl < minV) ? 0 : (tl > maxV) ? 128 : 64;
|
14708 | cval |= (tr < minV) ? 0 : (tr > maxV) ? 32 : 16;
|
14709 | cval |= (br < minV) ? 0 : (br > maxV) ? 8 : 4;
|
14710 | cval |= (bl < minV) ? 0 : (bl > maxV) ? 2 : 1;
|
14711 |
|
14712 | var cval_real = +cval;
|
14713 |
|
14714 |
|
14715 | var flipped = 0;
|
14716 | if ((cval === 17) ||
|
14717 | (cval === 18) ||
|
14718 | (cval === 33) ||
|
14719 | (cval === 34) ||
|
14720 | (cval === 38) ||
|
14721 | (cval === 68) ||
|
14722 | (cval === 72) ||
|
14723 | (cval === 98) ||
|
14724 | (cval === 102) ||
|
14725 | (cval === 132) ||
|
14726 | (cval === 136) ||
|
14727 | (cval === 137) ||
|
14728 | (cval === 152) ||
|
14729 | (cval === 153)
|
14730 | ) {
|
14731 | var average = (tl + tr + br + bl) / 4;
|
14732 |
|
14733 | flipped = (average > maxV) ? 2 : (average < minV) ? 0 : 1;
|
14734 |
|
14735 |
|
14736 |
|
14737 |
|
14738 | if (cval === 34) {
|
14739 | if (flipped === 1) {
|
14740 | cval = 35;
|
14741 | } else if (flipped === 0) {
|
14742 | cval = 136;
|
14743 | }
|
14744 | } else if (cval === 136) {
|
14745 | if (flipped === 1) {
|
14746 | cval = 35;
|
14747 | flipped = 4;
|
14748 | } else if (flipped === 0) {
|
14749 | cval = 34;
|
14750 | }
|
14751 | }
|
14752 |
|
14753 |
|
14754 | else if (cval === 17) {
|
14755 | if (flipped === 1) {
|
14756 | cval = 155;
|
14757 | flipped = 4;
|
14758 | } else if (flipped === 0) {
|
14759 | cval = 153;
|
14760 | }
|
14761 | } else if (cval === 68) {
|
14762 | if (flipped === 1) {
|
14763 | cval = 103;
|
14764 | flipped = 4;
|
14765 | } else if (flipped === 0) {
|
14766 | cval = 102;
|
14767 | }
|
14768 | } else if (cval === 153) {
|
14769 | if (flipped === 1)
|
14770 | cval = 155;
|
14771 | } else if (cval === 102) {
|
14772 | if (flipped === 1)
|
14773 | cval = 103;
|
14774 | }
|
14775 |
|
14776 |
|
14777 | else if (cval === 152) {
|
14778 | if (flipped < 2) {
|
14779 | cval = 156;
|
14780 | flipped = 1;
|
14781 | }
|
14782 | } else if (cval === 137) {
|
14783 | if (flipped < 2) {
|
14784 | cval = 139;
|
14785 | flipped = 1;
|
14786 | }
|
14787 | } else if (cval === 98) {
|
14788 | if (flipped < 2) {
|
14789 | cval = 99;
|
14790 | flipped = 1;
|
14791 | }
|
14792 | } else if (cval === 38) {
|
14793 | if (flipped < 2) {
|
14794 | cval = 39;
|
14795 | flipped = 1;
|
14796 | }
|
14797 | } else if (cval === 18) {
|
14798 | if (flipped > 0) {
|
14799 | cval = 156;
|
14800 | flipped = 4;
|
14801 | } else {
|
14802 | cval = 152;
|
14803 | }
|
14804 | } else if (cval === 33) {
|
14805 | if (flipped > 0) {
|
14806 | cval = 139;
|
14807 | flipped = 4;
|
14808 | } else {
|
14809 | cval = 137;
|
14810 | }
|
14811 | } else if (cval === 72) {
|
14812 | if (flipped > 0) {
|
14813 | cval = 99;
|
14814 | flipped = 4;
|
14815 | } else {
|
14816 | cval = 98;
|
14817 | }
|
14818 | } else if (cval === 132) {
|
14819 | if (flipped > 0) {
|
14820 | cval = 39;
|
14821 | flipped = 4;
|
14822 | } else {
|
14823 | cval = 38;
|
14824 | }
|
14825 | }
|
14826 | }
|
14827 |
|
14828 |
|
14829 | if ((cval != 0) && (cval != 170)) {
|
14830 | var topleft, topright, bottomleft, bottomright,
|
14831 | righttop, rightbottom, lefttop, leftbottom;
|
14832 |
|
14833 | topleft = topright = bottomleft = bottomright = righttop =
|
14834 | rightbottom = lefttop = leftbottom = 0.5;
|
14835 |
|
14836 | var edges = [];
|
14837 |
|
14838 |
|
14839 |
|
14840 | if (cval === 1) {
|
14841 | bottomleft = 1 - interpolateX$1(minV, br, bl);
|
14842 | leftbottom = 1 - interpolateX$1(minV, tl, bl);
|
14843 | edges.push(isoBandEdgeBL[cval]);
|
14844 | } else if (cval === 169) {
|
14845 | bottomleft = interpolateX$1(maxV, bl, br);
|
14846 | leftbottom = interpolateX$1(maxV, bl, tl);
|
14847 | edges.push(isoBandEdgeBL[cval]);
|
14848 | } else if (cval === 4) {
|
14849 | rightbottom = 1 - interpolateX$1(minV, tr, br);
|
14850 | bottomright = interpolateX$1(minV, bl, br);
|
14851 | edges.push(isoBandEdgeRB[cval]);
|
14852 | } else if (cval === 166) {
|
14853 | rightbottom = interpolateX$1(maxV, br, tr);
|
14854 | bottomright = 1 - interpolateX$1(maxV, br, bl);
|
14855 | edges.push(isoBandEdgeRB[cval]);
|
14856 | } else if (cval === 16) {
|
14857 | righttop = interpolateX$1(minV, br, tr);
|
14858 | topright = interpolateX$1(minV, tl, tr);
|
14859 | edges.push(isoBandEdgeRT[cval]);
|
14860 | } else if (cval === 154) {
|
14861 | righttop = 1 - interpolateX$1(maxV, tr, br);
|
14862 | topright = 1 - interpolateX$1(maxV, tr, tl);
|
14863 | edges.push(isoBandEdgeRT[cval]);
|
14864 | } else if (cval === 64) {
|
14865 | lefttop = interpolateX$1(minV, bl, tl);
|
14866 | topleft = 1 - interpolateX$1(minV, tr, tl);
|
14867 | edges.push(isoBandEdgeLT[cval]);
|
14868 | } else if (cval === 106) {
|
14869 | lefttop = 1 - interpolateX$1(maxV, tl, bl);
|
14870 | topleft = interpolateX$1(maxV, tl, tr);
|
14871 | edges.push(isoBandEdgeLT[cval]);
|
14872 | }
|
14873 |
|
14874 | else if (cval === 168) {
|
14875 | bottomright = interpolateX$1(maxV, bl, br);
|
14876 | bottomleft = interpolateX$1(minV, bl, br);
|
14877 | leftbottom = interpolateX$1(minV, bl, tl);
|
14878 | lefttop = interpolateX$1(maxV, bl, tl);
|
14879 | edges.push(isoBandEdgeBR[cval]);
|
14880 | edges.push(isoBandEdgeBL[cval]);
|
14881 | } else if (cval === 2) {
|
14882 | bottomright = 1 - interpolateX$1(minV, br, bl);
|
14883 | bottomleft = 1 - interpolateX$1(maxV, br, bl);
|
14884 | leftbottom = 1 - interpolateX$1(maxV, tl, bl);
|
14885 | lefttop = 1 - interpolateX$1(minV, tl, bl);
|
14886 | edges.push(isoBandEdgeBR[cval]);
|
14887 | edges.push(isoBandEdgeBL[cval]);
|
14888 | } else if (cval === 162) {
|
14889 | righttop = interpolateX$1(maxV, br, tr);
|
14890 | rightbottom = interpolateX$1(minV, br, tr);
|
14891 | bottomright = 1 - interpolateX$1(minV, br, bl);
|
14892 | bottomleft = 1 - interpolateX$1(maxV, br, bl);
|
14893 | edges.push(isoBandEdgeBR[cval]);
|
14894 | edges.push(isoBandEdgeBL[cval]);
|
14895 | } else if (cval === 8) {
|
14896 | righttop = 1 - interpolateX$1(minV, tr, br);
|
14897 | rightbottom = 1 - interpolateX$1(maxV, tr, br);
|
14898 | bottomright = interpolateX$1(maxV, bl, br);
|
14899 | bottomleft = interpolateX$1(minV, bl, br);
|
14900 | edges.push(isoBandEdgeRT[cval]);
|
14901 | edges.push(isoBandEdgeRB[cval]);
|
14902 | } else if (cval === 138) {
|
14903 | righttop = 1 - interpolateX$1(minV, tr, br);
|
14904 | rightbottom = 1 - interpolateX$1(maxV, tr, br);
|
14905 | topleft = 1 - interpolateX$1(maxV, tr, tl);
|
14906 | topright = 1 - interpolateX$1(minV, tr, tl);
|
14907 | edges.push(isoBandEdgeRT[cval]);
|
14908 | edges.push(isoBandEdgeRB[cval]);
|
14909 | } else if (cval === 32) {
|
14910 | righttop = interpolateX$1(maxV, br, tr);
|
14911 | rightbottom = interpolateX$1(minV, br, tr);
|
14912 | topleft = interpolateX$1(minV, tl, tr);
|
14913 | topright = interpolateX$1(maxV, tl, tr);
|
14914 | edges.push(isoBandEdgeRT[cval]);
|
14915 | edges.push(isoBandEdgeRB[cval]);
|
14916 | } else if (cval === 42) {
|
14917 | leftbottom = 1 - interpolateX$1(maxV, tl, bl);
|
14918 | lefttop = 1 - interpolateX$1(minV, tl, bl);
|
14919 | topleft = interpolateX$1(minV, tl, tr);
|
14920 | topright = interpolateX$1(maxV, tl, tr);
|
14921 | edges.push(isoBandEdgeLB[cval]);
|
14922 | edges.push(isoBandEdgeLT[cval]);
|
14923 | } else if (cval === 128) {
|
14924 | leftbottom = interpolateX$1(minV, bl, tl);
|
14925 | lefttop = interpolateX$1(maxV, bl, tl);
|
14926 | topleft = 1 - interpolateX$1(maxV, tr, tl);
|
14927 | topright = 1 - interpolateX$1(minV, tr, tl);
|
14928 | edges.push(isoBandEdgeLB[cval]);
|
14929 | edges.push(isoBandEdgeLT[cval]);
|
14930 | }
|
14931 |
|
14932 |
|
14933 | if (cval === 5) {
|
14934 | rightbottom = 1 - interpolateX$1(minV, tr, br);
|
14935 | leftbottom = 1 - interpolateX$1(minV, tl, bl);
|
14936 | edges.push(isoBandEdgeRB[cval]);
|
14937 | } else if (cval === 165) {
|
14938 | rightbottom = interpolateX$1(maxV, br, tr);
|
14939 | leftbottom = interpolateX$1(maxV, bl, tl);
|
14940 | edges.push(isoBandEdgeRB[cval]);
|
14941 | } else if (cval === 20) {
|
14942 | bottomright = interpolateX$1(minV, bl, br);
|
14943 | topright = interpolateX$1(minV, tl, tr);
|
14944 | edges.push(isoBandEdgeBR[cval]);
|
14945 | } else if (cval === 150) {
|
14946 | bottomright = 1 - interpolateX$1(maxV, br, bl);
|
14947 | topright = 1 - interpolateX$1(maxV, tr, tl);
|
14948 | edges.push(isoBandEdgeBR[cval]);
|
14949 | } else if (cval === 80) {
|
14950 | righttop = interpolateX$1(minV, br, tr);
|
14951 | lefttop = interpolateX$1(minV, bl, tl);
|
14952 | edges.push(isoBandEdgeRT[cval]);
|
14953 | } else if (cval === 90) {
|
14954 | righttop = 1 - interpolateX$1(maxV, tr, br);
|
14955 | lefttop = 1 - interpolateX$1(maxV, tl, bl);
|
14956 | edges.push(isoBandEdgeRT[cval]);
|
14957 | } else if (cval === 65) {
|
14958 | bottomleft = 1 - interpolateX$1(minV, br, bl);
|
14959 | topleft = 1 - interpolateX$1(minV, tr, tl);
|
14960 | edges.push(isoBandEdgeBL[cval]);
|
14961 | } else if (cval === 105) {
|
14962 | bottomleft = interpolateX$1(maxV, bl, br);
|
14963 | topleft = interpolateX$1(maxV, tl, tr);
|
14964 | edges.push(isoBandEdgeBL[cval]);
|
14965 | } else if (cval === 160) {
|
14966 | righttop = interpolateX$1(maxV, br, tr);
|
14967 | rightbottom = interpolateX$1(minV, br, tr);
|
14968 | leftbottom = interpolateX$1(minV, bl, tl);
|
14969 | lefttop = interpolateX$1(maxV, bl, tl);
|
14970 | edges.push(isoBandEdgeRT[cval]);
|
14971 | edges.push(isoBandEdgeRB[cval]);
|
14972 | } else if (cval === 10) {
|
14973 | righttop = 1 - interpolateX$1(minV, tr, br);
|
14974 | rightbottom = 1 - interpolateX$1(maxV, tr, br);
|
14975 | leftbottom = 1 - interpolateX$1(maxV, tl, bl);
|
14976 | lefttop = 1 - interpolateX$1(minV, tl, bl);
|
14977 | edges.push(isoBandEdgeRT[cval]);
|
14978 | edges.push(isoBandEdgeRB[cval]);
|
14979 | } else if (cval === 130) {
|
14980 | bottomright = 1 - interpolateX$1(minV, br, bl);
|
14981 | bottomleft = 1 - interpolateX$1(maxV, br, bl);
|
14982 | topleft = 1 - interpolateX$1(maxV, tr, tl);
|
14983 | topright = 1 - interpolateX$1(minV, tr, tl);
|
14984 | edges.push(isoBandEdgeBR[cval]);
|
14985 | edges.push(isoBandEdgeBL[cval]);
|
14986 | } else if (cval === 40) {
|
14987 | bottomright = interpolateX$1(maxV, bl, br);
|
14988 | bottomleft = interpolateX$1(minV, bl, br);
|
14989 | topleft = interpolateX$1(minV, tl, tr);
|
14990 | topright = interpolateX$1(maxV, tl, tr);
|
14991 | edges.push(isoBandEdgeBR[cval]);
|
14992 | edges.push(isoBandEdgeBL[cval]);
|
14993 | }
|
14994 |
|
14995 |
|
14996 | else if (cval === 101) {
|
14997 | rightbottom = interpolateX$1(maxV, br, tr);
|
14998 | topleft = interpolateX$1(maxV, tl, tr);
|
14999 | edges.push(isoBandEdgeRB[cval]);
|
15000 | } else if (cval === 69) {
|
15001 | rightbottom = 1 - interpolateX$1(minV, tr, br);
|
15002 | topleft = 1 - interpolateX$1(minV, tr, tl);
|
15003 | edges.push(isoBandEdgeRB[cval]);
|
15004 | } else if (cval === 149) {
|
15005 | leftbottom = interpolateX$1(maxV, bl, tl);
|
15006 | topright = 1 - interpolateX$1(maxV, tr, tl);
|
15007 | edges.push(isoBandEdgeLB[cval]);
|
15008 | } else if (cval === 21) {
|
15009 | leftbottom = 1 - interpolateX$1(minV, tl, bl);
|
15010 | topright = interpolateX$1(minV, tl, tr);
|
15011 | edges.push(isoBandEdgeLB[cval]);
|
15012 | } else if (cval === 86) {
|
15013 | bottomright = 1 - interpolateX$1(maxV, br, bl);
|
15014 | lefttop = 1 - interpolateX$1(maxV, tl, bl);
|
15015 | edges.push(isoBandEdgeBR[cval]);
|
15016 | } else if (cval === 84) {
|
15017 | bottomright = interpolateX$1(minV, bl, br);
|
15018 | lefttop = interpolateX$1(minV, bl, tl);
|
15019 | edges.push(isoBandEdgeBR[cval]);
|
15020 | } else if (cval === 89) {
|
15021 | righttop = 1 - interpolateX$1(maxV, tr, br);
|
15022 | bottomleft = interpolateX$1(maxV, bl, br);
|
15023 | edges.push(isoBandEdgeBL[cval]);
|
15024 | } else if (cval === 81) {
|
15025 | righttop = interpolateX$1(minV, br, tr);
|
15026 | bottomleft = 1 - interpolateX$1(minV, br, bl);
|
15027 | edges.push(isoBandEdgeBL[cval]);
|
15028 | } else if (cval === 96) {
|
15029 | righttop = interpolateX$1(maxV, br, tr);
|
15030 | rightbottom = interpolateX$1(minV, br, tr);
|
15031 | lefttop = interpolateX$1(minV, bl, tl);
|
15032 | topleft = interpolateX$1(maxV, tl, tr);
|
15033 | edges.push(isoBandEdgeRT[cval]);
|
15034 | edges.push(isoBandEdgeRB[cval]);
|
15035 | } else if (cval === 74) {
|
15036 | righttop = 1 - interpolateX$1(minV, tr, br);
|
15037 | rightbottom = 1 - interpolateX$1(maxV, tr, br);
|
15038 | lefttop = 1 - interpolateX$1(maxV, tl, bl);
|
15039 | topleft = 1 - interpolateX$1(minV, tr, tl);
|
15040 | edges.push(isoBandEdgeRT[cval]);
|
15041 | edges.push(isoBandEdgeRB[cval]);
|
15042 | } else if (cval === 24) {
|
15043 | righttop = 1 - interpolateX$1(maxV, tr, br);
|
15044 | bottomright = interpolateX$1(maxV, bl, br);
|
15045 | bottomleft = interpolateX$1(minV, bl, br);
|
15046 | topright = interpolateX$1(minV, tl, tr);
|
15047 | edges.push(isoBandEdgeRT[cval]);
|
15048 | edges.push(isoBandEdgeBL[cval]);
|
15049 | } else if (cval === 146) {
|
15050 | righttop = interpolateX$1(minV, br, tr);
|
15051 | bottomright = 1 - interpolateX$1(minV, br, bl);
|
15052 | bottomleft = 1 - interpolateX$1(maxV, br, bl);
|
15053 | topright = 1 - interpolateX$1(maxV, tr, tl);
|
15054 | edges.push(isoBandEdgeRT[cval]);
|
15055 | edges.push(isoBandEdgeBL[cval]);
|
15056 | } else if (cval === 6) {
|
15057 | rightbottom = 1 - interpolateX$1(minV, tr, br);
|
15058 | bottomright = 1 - interpolateX$1(maxV, br, bl);
|
15059 | leftbottom = 1 - interpolateX$1(maxV, tl, bl);
|
15060 | lefttop = 1 - interpolateX$1(minV, tl, bl);
|
15061 | edges.push(isoBandEdgeRB[cval]);
|
15062 | edges.push(isoBandEdgeBR[cval]);
|
15063 | } else if (cval === 164) {
|
15064 | rightbottom = interpolateX$1(maxV, br, tr);
|
15065 | bottomright = interpolateX$1(minV, bl, br);
|
15066 | leftbottom = interpolateX$1(minV, bl, tl);
|
15067 | lefttop = interpolateX$1(maxV, bl, tl);
|
15068 | edges.push(isoBandEdgeRB[cval]);
|
15069 | edges.push(isoBandEdgeBR[cval]);
|
15070 | } else if (cval === 129) {
|
15071 | bottomleft = 1 - interpolateX$1(minV, br, bl);
|
15072 | leftbottom = interpolateX$1(maxV, bl, tl);
|
15073 | topleft = 1 - interpolateX$1(maxV, tr, tl);
|
15074 | topright = 1 - interpolateX$1(minV, tr, tl);
|
15075 | edges.push(isoBandEdgeBL[cval]);
|
15076 | edges.push(isoBandEdgeLB[cval]);
|
15077 | } else if (cval === 41) {
|
15078 | bottomleft = interpolateX$1(maxV, bl, br);
|
15079 | leftbottom = 1 - interpolateX$1(minV, tl, bl);
|
15080 | topleft = interpolateX$1(minV, tl, tr);
|
15081 | topright = interpolateX$1(maxV, tl, tr);
|
15082 | edges.push(isoBandEdgeBL[cval]);
|
15083 | edges.push(isoBandEdgeLB[cval]);
|
15084 | } else if (cval === 66) {
|
15085 | bottomright = 1 - interpolateX$1(minV, br, bl);
|
15086 | bottomleft = 1 - interpolateX$1(maxV, br, bl);
|
15087 | lefttop = 1 - interpolateX$1(maxV, tl, bl);
|
15088 | topleft = 1 - interpolateX$1(minV, tr, tl);
|
15089 | edges.push(isoBandEdgeBR[cval]);
|
15090 | edges.push(isoBandEdgeBL[cval]);
|
15091 | } else if (cval === 104) {
|
15092 | bottomright = interpolateX$1(maxV, bl, br);
|
15093 | bottomleft = interpolateX$1(minV, bl, br);
|
15094 | lefttop = interpolateX$1(minV, bl, tl);
|
15095 | topleft = interpolateX$1(maxV, tl, tr);
|
15096 | edges.push(isoBandEdgeBL[cval]);
|
15097 | edges.push(isoBandEdgeTL[cval]);
|
15098 | } else if (cval === 144) {
|
15099 | righttop = interpolateX$1(minV, br, tr);
|
15100 | leftbottom = interpolateX$1(minV, bl, tl);
|
15101 | lefttop = interpolateX$1(maxV, bl, tl);
|
15102 | topright = 1 - interpolateX$1(maxV, tr, tl);
|
15103 | edges.push(isoBandEdgeRT[cval]);
|
15104 | edges.push(isoBandEdgeLT[cval]);
|
15105 | } else if (cval === 26) {
|
15106 | righttop = 1 - interpolateX$1(maxV, tr, br);
|
15107 | leftbottom = 1 - interpolateX$1(maxV, tl, bl);
|
15108 | lefttop = 1 - interpolateX$1(minV, tl, bl);
|
15109 | topright = interpolateX$1(minV, tl, tr);
|
15110 | edges.push(isoBandEdgeRT[cval]);
|
15111 | edges.push(isoBandEdgeLT[cval]);
|
15112 | } else if (cval === 36) {
|
15113 | rightbottom = interpolateX$1(maxV, br, tr);
|
15114 | bottomright = interpolateX$1(minV, bl, br);
|
15115 | topleft = interpolateX$1(minV, tl, tr);
|
15116 | topright = interpolateX$1(maxV, tl, tr);
|
15117 | edges.push(isoBandEdgeRB[cval]);
|
15118 | edges.push(isoBandEdgeBR[cval]);
|
15119 | } else if (cval === 134) {
|
15120 | rightbottom = 1 - interpolateX$1(minV, tr, br);
|
15121 | bottomright = 1 - interpolateX$1(maxV, br, bl);
|
15122 | topleft = 1 - interpolateX$1(maxV, tr, tl);
|
15123 | topright = 1 - interpolateX$1(minV, tr, tl);
|
15124 | edges.push(isoBandEdgeRB[cval]);
|
15125 | edges.push(isoBandEdgeBR[cval]);
|
15126 | } else if (cval === 9) {
|
15127 | righttop = 1 - interpolateX$1(minV, tr, br);
|
15128 | rightbottom = 1 - interpolateX$1(maxV, tr, br);
|
15129 | bottomleft = interpolateX$1(maxV, bl, br);
|
15130 | leftbottom = 1 - interpolateX$1(minV, tl, bl);
|
15131 | edges.push(isoBandEdgeRT[cval]);
|
15132 | edges.push(isoBandEdgeRB[cval]);
|
15133 | } else if (cval === 161) {
|
15134 | righttop = interpolateX$1(maxV, br, tr);
|
15135 | rightbottom = interpolateX$1(minV, br, tr);
|
15136 | bottomleft = 1 - interpolateX$1(minV, br, bl);
|
15137 | leftbottom = interpolateX$1(maxV, bl, tl);
|
15138 | edges.push(isoBandEdgeRT[cval]);
|
15139 | edges.push(isoBandEdgeRB[cval]);
|
15140 | }
|
15141 |
|
15142 |
|
15143 | else if (cval === 37) {
|
15144 | rightbottom = interpolateX$1(maxV, br, tr);
|
15145 | leftbottom = 1 - interpolateX$1(minV, tl, bl);
|
15146 | topleft = interpolateX$1(minV, tl, tr);
|
15147 | topright = interpolateX$1(maxV, tl, tr);
|
15148 | edges.push(isoBandEdgeRB[cval]);
|
15149 | edges.push(isoBandEdgeLB[cval]);
|
15150 | } else if (cval === 133) {
|
15151 | rightbottom = 1 - interpolateX$1(minV, tr, br);
|
15152 | leftbottom = interpolateX$1(maxV, bl, tl);
|
15153 | topleft = 1 - interpolateX$1(maxV, tr, tl);
|
15154 | topright = 1 - interpolateX$1(minV, tr, tl);
|
15155 | edges.push(isoBandEdgeRB[cval]);
|
15156 | edges.push(isoBandEdgeLB[cval]);
|
15157 | } else if (cval === 148) {
|
15158 | bottomright = interpolateX$1(minV, bl, br);
|
15159 | leftbottom = interpolateX$1(minV, bl, tl);
|
15160 | lefttop = interpolateX$1(maxV, bl, tl);
|
15161 | topright = 1 - interpolateX$1(maxV, tr, tl);
|
15162 | edges.push(isoBandEdgeBR[cval]);
|
15163 | edges.push(isoBandEdgeLT[cval]);
|
15164 | } else if (cval === 22) {
|
15165 | bottomright = 1 - interpolateX$1(maxV, br, bl);
|
15166 | leftbottom = 1 - interpolateX$1(maxV, tl, bl);
|
15167 | lefttop = 1 - interpolateX$1(minV, tl, bl);
|
15168 | topright = interpolateX$1(minV, tl, tr);
|
15169 | edges.push(isoBandEdgeBR[cval]);
|
15170 | edges.push(isoBandEdgeLT[cval]);
|
15171 | } else if (cval === 82) {
|
15172 | righttop = interpolateX$1(minV, br, tr);
|
15173 | bottomright = 1 - interpolateX$1(minV, br, bl);
|
15174 | bottomleft = 1 - interpolateX$1(maxV, br, bl);
|
15175 | lefttop = 1 - interpolateX$1(maxV, tl, bl);
|
15176 | edges.push(isoBandEdgeRT[cval]);
|
15177 | edges.push(isoBandEdgeBL[cval]);
|
15178 | } else if (cval === 88) {
|
15179 | righttop = 1 - interpolateX$1(maxV, tr, br);
|
15180 | bottomright = interpolateX$1(maxV, bl, br);
|
15181 | bottomleft = interpolateX$1(minV, bl, br);
|
15182 | lefttop = interpolateX$1(minV, bl, tl);
|
15183 | edges.push(isoBandEdgeRT[cval]);
|
15184 | edges.push(isoBandEdgeBL[cval]);
|
15185 | } else if (cval === 73) {
|
15186 | righttop = 1 - interpolateX$1(minV, tr, br);
|
15187 | rightbottom = 1 - interpolateX$1(maxV, tr, br);
|
15188 | bottomleft = interpolateX$1(maxV, bl, br);
|
15189 | topleft = 1 - interpolateX$1(minV, tr, tl);
|
15190 | edges.push(isoBandEdgeRT[cval]);
|
15191 | edges.push(isoBandEdgeRB[cval]);
|
15192 | } else if (cval === 97) {
|
15193 | righttop = interpolateX$1(maxV, br, tr);
|
15194 | rightbottom = interpolateX$1(minV, br, tr);
|
15195 | bottomleft = 1 - interpolateX$1(minV, br, bl);
|
15196 | topleft = interpolateX$1(maxV, tl, tr);
|
15197 | edges.push(isoBandEdgeRT[cval]);
|
15198 | edges.push(isoBandEdgeRB[cval]);
|
15199 | } else if (cval === 145) {
|
15200 | righttop = interpolateX$1(minV, br, tr);
|
15201 | bottomleft = 1 - interpolateX$1(minV, br, bl);
|
15202 | leftbottom = interpolateX$1(maxV, bl, tl);
|
15203 | topright = 1 - interpolateX$1(maxV, tr, tl);
|
15204 | edges.push(isoBandEdgeRT[cval]);
|
15205 | edges.push(isoBandEdgeLB[cval]);
|
15206 | } else if (cval === 25) {
|
15207 | righttop = 1 - interpolateX$1(maxV, tr, br);
|
15208 | bottomleft = interpolateX$1(maxV, bl, br);
|
15209 | leftbottom = 1 - interpolateX$1(minV, tl, bl);
|
15210 | topright = interpolateX$1(minV, tl, tr);
|
15211 | edges.push(isoBandEdgeRT[cval]);
|
15212 | edges.push(isoBandEdgeLB[cval]);
|
15213 | } else if (cval === 70) {
|
15214 | rightbottom = 1 - interpolateX$1(minV, tr, br);
|
15215 | bottomright = 1 - interpolateX$1(maxV, br, bl);
|
15216 | lefttop = 1 - interpolateX$1(maxV, tl, bl);
|
15217 | topleft = 1 - interpolateX$1(minV, tr, tl);
|
15218 | edges.push(isoBandEdgeRB[cval]);
|
15219 | edges.push(isoBandEdgeBR[cval]);
|
15220 | } else if (cval === 100) {
|
15221 | rightbottom = interpolateX$1(maxV, br, tr);
|
15222 | bottomright = interpolateX$1(minV, bl, br);
|
15223 | lefttop = interpolateX$1(minV, bl, tl);
|
15224 | topleft = interpolateX$1(maxV, tl, tr);
|
15225 | edges.push(isoBandEdgeRB[cval]);
|
15226 | edges.push(isoBandEdgeBR[cval]);
|
15227 | }
|
15228 |
|
15229 |
|
15230 | else if (cval === 34) {
|
15231 | if (flipped === 0) {
|
15232 | righttop = 1 - interpolateX$1(minV, tr, br);
|
15233 | rightbottom = 1 - interpolateX$1(maxV, tr, br);
|
15234 | bottomright = interpolateX$1(maxV, bl, br);
|
15235 | bottomleft = interpolateX$1(minV, bl, br);
|
15236 | leftbottom = interpolateX$1(minV, bl, tl);
|
15237 | lefttop = interpolateX$1(maxV, bl, tl);
|
15238 | topleft = 1 - interpolateX$1(maxV, tr, tl);
|
15239 | topright = 1 - interpolateX$1(minV, tr, tl);
|
15240 | } else {
|
15241 | righttop = interpolateX$1(maxV, br, tr);
|
15242 | rightbottom = interpolateX$1(minV, br, tr);
|
15243 | bottomright = 1 - interpolateX$1(minV, br, bl);
|
15244 | bottomleft = 1 - interpolateX$1(maxV, br, bl);
|
15245 | leftbottom = 1 - interpolateX$1(maxV, tl, bl);
|
15246 | lefttop = 1 - interpolateX$1(minV, tl, bl);
|
15247 | topleft = interpolateX$1(minV, tl, tr);
|
15248 | topright = interpolateX$1(maxV, tl, tr);
|
15249 | }
|
15250 | edges.push(isoBandEdgeRT[cval]);
|
15251 | edges.push(isoBandEdgeRB[cval]);
|
15252 | edges.push(isoBandEdgeLB[cval]);
|
15253 | edges.push(isoBandEdgeLT[cval]);
|
15254 | } else if (cval === 35) {
|
15255 | if (flipped === 4) {
|
15256 | righttop = 1 - interpolateX$1(minV, tr, br);
|
15257 | rightbottom = 1 - interpolateX$1(maxV, tr, br);
|
15258 | bottomright = interpolateX$1(maxV, bl, br);
|
15259 | bottomleft = interpolateX$1(minV, bl, br);
|
15260 | leftbottom = interpolateX$1(minV, bl, tl);
|
15261 | lefttop = interpolateX$1(maxV, bl, tl);
|
15262 | topleft = 1 - interpolateX$1(maxV, tr, tl);
|
15263 | topright = 1 - interpolateX$1(minV, tr, tl);
|
15264 | } else {
|
15265 | righttop = interpolateX$1(maxV, br, tr);
|
15266 | rightbottom = interpolateX$1(minV, br, tr);
|
15267 | bottomright = 1 - interpolateX$1(minV, br, bl);
|
15268 | bottomleft = 1 - interpolateX$1(maxV, br, bl);
|
15269 | leftbottom = 1 - interpolateX$1(maxV, tl, bl);
|
15270 | lefttop = 1 - interpolateX$1(minV, tl, bl);
|
15271 | topleft = interpolateX$1(minV, tl, tr);
|
15272 | topright = interpolateX$1(maxV, tl, tr);
|
15273 | }
|
15274 | edges.push(isoBandEdgeRT[cval]);
|
15275 | edges.push(isoBandEdgeRB[cval]);
|
15276 | edges.push(isoBandEdgeBL[cval]);
|
15277 | edges.push(isoBandEdgeLT[cval]);
|
15278 | } else if (cval === 136) {
|
15279 | if (flipped === 0) {
|
15280 | righttop = interpolateX$1(maxV, br, tr);
|
15281 | rightbottom = interpolateX$1(minV, br, tr);
|
15282 | bottomright = 1 - interpolateX$1(minV, br, bl);
|
15283 | bottomleft = 1 - interpolateX$1(maxV, br, bl);
|
15284 | leftbottom = 1 - interpolateX$1(maxV, tl, bl);
|
15285 | lefttop = 1 - interpolateX$1(minV, tl, bl);
|
15286 | topleft = interpolateX$1(minV, tl, tr);
|
15287 | topright = interpolateX$1(maxV, tl, tr);
|
15288 | } else {
|
15289 | righttop = 1 - interpolateX$1(minV, tr, br);
|
15290 | rightbottom = 1 - interpolateX$1(maxV, tr, br);
|
15291 | bottomright = interpolateX$1(maxV, bl, br);
|
15292 | bottomleft = interpolateX$1(minV, bl, br);
|
15293 | leftbottom = interpolateX$1(minV, bl, tl);
|
15294 | lefttop = interpolateX$1(maxV, bl, tl);
|
15295 | topleft = 1 - interpolateX$1(maxV, tr, tl);
|
15296 | topright = 1 - interpolateX$1(minV, tr, tl);
|
15297 | }
|
15298 | edges.push(isoBandEdgeRT[cval]);
|
15299 | edges.push(isoBandEdgeRB[cval]);
|
15300 | edges.push(isoBandEdgeLB[cval]);
|
15301 | edges.push(isoBandEdgeLT[cval]);
|
15302 | }
|
15303 |
|
15304 |
|
15305 | else if (cval === 153) {
|
15306 | if (flipped === 0) {
|
15307 | righttop = interpolateX$1(minV, br, tr);
|
15308 | bottomleft = 1 - interpolateX$1(minV, br, bl);
|
15309 | leftbottom = 1 - interpolateX$1(minV, tl, bl);
|
15310 | topright = interpolateX$1(minV, tl, tr);
|
15311 | } else {
|
15312 | righttop = 1 - interpolateX$1(maxV, tr, br);
|
15313 | bottomleft = interpolateX$1(maxV, bl, br);
|
15314 | leftbottom = interpolateX$1(maxV, bl, tl);
|
15315 | topright = 1 - interpolateX$1(maxV, tr, tl);
|
15316 | }
|
15317 | edges.push(isoBandEdgeRT[cval]);
|
15318 | edges.push(isoBandEdgeBL[cval]);
|
15319 | } else if (cval === 102) {
|
15320 | if (flipped === 0) {
|
15321 | rightbottom = 1 - interpolateX$1(minV, tr, br);
|
15322 | bottomright = interpolateX$1(minV, bl, br);
|
15323 | lefttop = interpolateX$1(minV, bl, tl);
|
15324 | topleft = 1 - interpolateX$1(minV, tr, tl);
|
15325 | } else {
|
15326 | rightbottom = interpolateX$1(maxV, br, tr);
|
15327 | bottomright = 1 - interpolateX$1(maxV, br, bl);
|
15328 | lefttop = 1 - interpolateX$1(maxV, tl, bl);
|
15329 | topleft = interpolateX$1(maxV, tl, tr);
|
15330 | }
|
15331 | edges.push(isoBandEdgeRB[cval]);
|
15332 | edges.push(isoBandEdgeLT[cval]);
|
15333 | } else if (cval === 155) {
|
15334 | if (flipped === 4) {
|
15335 | righttop = interpolateX$1(minV, br, tr);
|
15336 | bottomleft = 1 - interpolateX$1(minV, br, bl);
|
15337 | leftbottom = 1 - interpolateX$1(minV, tl, bl);
|
15338 | topright = interpolateX$1(minV, tl, tr);
|
15339 | } else {
|
15340 | righttop = 1 - interpolateX$1(maxV, tr, br);
|
15341 | bottomleft = interpolateX$1(maxV, bl, br);
|
15342 | leftbottom = interpolateX$1(maxV, bl, tl);
|
15343 | topright = 1 - interpolateX$1(maxV, tr, tl);
|
15344 | }
|
15345 | edges.push(isoBandEdgeRT[cval]);
|
15346 | edges.push(isoBandEdgeLB[cval]);
|
15347 | } else if (cval === 103) {
|
15348 | if (flipped === 4) {
|
15349 | rightbottom = 1 - interpolateX$1(minV, tr, br);
|
15350 | bottomright = interpolateX$1(minV, bl, br);
|
15351 | lefttop = interpolateX$1(minV, bl, tl);
|
15352 | topleft = 1 - interpolateX$1(minV, tr, tl);
|
15353 | } else {
|
15354 | rightbottom = interpolateX$1(maxV, br, tr);
|
15355 | bottomright = 1 - interpolateX$1(maxV, br, bl);
|
15356 | lefttop = 1 - interpolateX$1(maxV, tl, bl);
|
15357 | topleft = interpolateX$1(maxV, tl, tr);
|
15358 | }
|
15359 | edges.push(isoBandEdgeRB[cval]);
|
15360 | edges.push(isoBandEdgeBR[cval]);
|
15361 | }
|
15362 |
|
15363 |
|
15364 | else if (cval === 152) {
|
15365 | if (flipped === 0) {
|
15366 | righttop = interpolateX$1(minV, br, tr);
|
15367 | bottomright = 1 - interpolateX$1(minV, br, bl);
|
15368 | bottomleft = 1 - interpolateX$1(maxV, br, bl);
|
15369 | leftbottom = 1 - interpolateX$1(maxV, tl, bl);
|
15370 | lefttop = 1 - interpolateX$1(minV, tl, bl);
|
15371 | topright = interpolateX$1(minV, tl, tr);
|
15372 | } else {
|
15373 | righttop = 1 - interpolateX$1(maxV, tr, br);
|
15374 | bottomright = interpolateX$1(maxV, bl, br);
|
15375 | bottomleft = interpolateX$1(minV, bl, br);
|
15376 | leftbottom = interpolateX$1(minV, bl, tl);
|
15377 | lefttop = interpolateX$1(maxV, bl, tl);
|
15378 | topright = 1 - interpolateX$1(maxV, tr, tl);
|
15379 | }
|
15380 | edges.push(isoBandEdgeRT[cval]);
|
15381 | edges.push(isoBandEdgeBR[cval]);
|
15382 | edges.push(isoBandEdgeBL[cval]);
|
15383 | } else if (cval === 156) {
|
15384 | if (flipped === 4) {
|
15385 | righttop = interpolateX$1(minV, br, tr);
|
15386 | bottomright = 1 - interpolateX$1(minV, br, bl);
|
15387 | bottomleft = 1 - interpolateX$1(maxV, br, bl);
|
15388 | leftbottom = 1 - interpolateX$1(maxV, tl, bl);
|
15389 | lefttop = 1 - interpolateX$1(minV, tl, bl);
|
15390 | topright = interpolateX$1(minV, tl, tr);
|
15391 | } else {
|
15392 | righttop = 1 - interpolateX$1(maxV, tr, br);
|
15393 | bottomright = interpolateX$1(maxV, bl, br);
|
15394 | bottomleft = interpolateX$1(minV, bl, br);
|
15395 | leftbottom = interpolateX$1(minV, bl, tl);
|
15396 | lefttop = interpolateX$1(maxV, bl, tl);
|
15397 | topright = 1 - interpolateX$1(maxV, tr, tl);
|
15398 | }
|
15399 | edges.push(isoBandEdgeRT[cval]);
|
15400 | edges.push(isoBandEdgeBL[cval]);
|
15401 | edges.push(isoBandEdgeLT[cval]);
|
15402 | } else if (cval === 137) {
|
15403 | if (flipped === 0) {
|
15404 | righttop = interpolateX$1(maxV, br, tr);
|
15405 | rightbottom = interpolateX$1(minV, br, tr);
|
15406 | bottomleft = 1 - interpolateX$1(minV, br, bl);
|
15407 | leftbottom = 1 - interpolateX$1(minV, tl, bl);
|
15408 | topleft = interpolateX$1(minV, tl, tr);
|
15409 | topright = interpolateX$1(maxV, tl, tr);
|
15410 | } else {
|
15411 | righttop = 1 - interpolateX$1(minV, tr, br);
|
15412 | rightbottom = 1 - interpolateX$1(maxV, tr, br);
|
15413 | bottomleft = interpolateX$1(maxV, bl, br);
|
15414 | leftbottom = interpolateX$1(maxV, bl, tl);
|
15415 | topleft = 1 - interpolateX$1(maxV, tr, tl);
|
15416 | topright = 1 - interpolateX$1(minV, tr, tl);
|
15417 | }
|
15418 | edges.push(isoBandEdgeRT[cval]);
|
15419 | edges.push(isoBandEdgeRB[cval]);
|
15420 | edges.push(isoBandEdgeBL[cval]);
|
15421 | } else if (cval === 139) {
|
15422 | if (flipped === 4) {
|
15423 | righttop = interpolateX$1(maxV, br, tr);
|
15424 | rightbottom = interpolateX$1(minV, br, tr);
|
15425 | bottomleft = 1 - interpolateX$1(minV, br, bl);
|
15426 | leftbottom = 1 - interpolateX$1(minV, tl, bl);
|
15427 | topleft = interpolateX$1(minV, tl, tr);
|
15428 | topright = interpolateX$1(maxV, tl, tr);
|
15429 | } else {
|
15430 | righttop = 1 - interpolateX$1(minV, tr, br);
|
15431 | rightbottom = 1 - interpolateX$1(maxV, tr, br);
|
15432 | bottomleft = interpolateX$1(maxV, bl, br);
|
15433 | leftbottom = interpolateX$1(maxV, bl, tl);
|
15434 | topleft = 1 - interpolateX$1(maxV, tr, tl);
|
15435 | topright = 1 - interpolateX$1(minV, tr, tl);
|
15436 | }
|
15437 | edges.push(isoBandEdgeRT[cval]);
|
15438 | edges.push(isoBandEdgeRB[cval]);
|
15439 | edges.push(isoBandEdgeLB[cval]);
|
15440 | } else if (cval === 98) {
|
15441 | if (flipped === 0) {
|
15442 | righttop = 1 - interpolateX$1(minV, tr, br);
|
15443 | rightbottom = 1 - interpolateX$1(maxV, tr, br);
|
15444 | bottomright = interpolateX$1(maxV, bl, br);
|
15445 | bottomleft = interpolateX$1(minV, bl, br);
|
15446 | lefttop = interpolateX$1(minV, bl, tl);
|
15447 | topleft = 1 - interpolateX$1(minV, tr, tl);
|
15448 | } else {
|
15449 | righttop = interpolateX$1(maxV, br, tr);
|
15450 | rightbottom = interpolateX$1(minV, br, tr);
|
15451 | bottomright = 1 - interpolateX$1(minV, br, bl);
|
15452 | bottomleft = 1 - interpolateX$1(maxV, br, bl);
|
15453 | lefttop = 1 - interpolateX$1(maxV, tl, bl);
|
15454 | topleft = interpolateX$1(maxV, tl, tr);
|
15455 | }
|
15456 | edges.push(isoBandEdgeRT[cval]);
|
15457 | edges.push(isoBandEdgeRB[cval]);
|
15458 | edges.push(isoBandEdgeLT[cval]);
|
15459 | } else if (cval === 99) {
|
15460 | if (flipped === 4) {
|
15461 | righttop = 1 - interpolateX$1(minV, tr, br);
|
15462 | rightbottom = 1 - interpolateX$1(maxV, tr, br);
|
15463 | bottomright = interpolateX$1(maxV, bl, br);
|
15464 | bottomleft = interpolateX$1(minV, bl, br);
|
15465 | lefttop = interpolateX$1(minV, bl, tl);
|
15466 | topleft = 1 - interpolateX$1(minV, tr, tl);
|
15467 | } else {
|
15468 | righttop = interpolateX$1(maxV, br, tr);
|
15469 | rightbottom = interpolateX$1(minV, br, tr);
|
15470 | bottomright = 1 - interpolateX$1(minV, br, bl);
|
15471 | bottomleft = 1 - interpolateX$1(maxV, br, bl);
|
15472 | lefttop = 1 - interpolateX$1(maxV, tl, bl);
|
15473 | topleft = interpolateX$1(maxV, tl, tr);
|
15474 | }
|
15475 | edges.push(isoBandEdgeRT[cval]);
|
15476 | edges.push(isoBandEdgeRB[cval]);
|
15477 | edges.push(isoBandEdgeBL[cval]);
|
15478 | } else if (cval === 38) {
|
15479 | if (flipped === 0) {
|
15480 | rightbottom = 1 - interpolateX$1(minV, tr, br);
|
15481 | bottomright = interpolateX$1(minV, bl, br);
|
15482 | leftbottom = interpolateX$1(minV, bl, tl);
|
15483 | lefttop = interpolateX$1(maxV, bl, tl);
|
15484 | topleft = 1 - interpolateX$1(maxV, tr, tl);
|
15485 | topright = 1 - interpolateX$1(minV, tr, tl);
|
15486 | } else {
|
15487 | rightbottom = interpolateX$1(maxV, br, tr);
|
15488 | bottomright = 1 - interpolateX$1(maxV, br, bl);
|
15489 | leftbottom = 1 - interpolateX$1(maxV, tl, bl);
|
15490 | lefttop = 1 - interpolateX$1(minV, tl, bl);
|
15491 | topleft = interpolateX$1(minV, tl, tr);
|
15492 | topright = interpolateX$1(maxV, tl, tr);
|
15493 | }
|
15494 | edges.push(isoBandEdgeRB[cval]);
|
15495 | edges.push(isoBandEdgeLB[cval]);
|
15496 | edges.push(isoBandEdgeLT[cval]);
|
15497 | } else if (cval === 39) {
|
15498 | if (flipped === 4) {
|
15499 | rightbottom = 1 - interpolateX$1(minV, tr, br);
|
15500 | bottomright = interpolateX$1(minV, bl, br);
|
15501 | leftbottom = interpolateX$1(minV, bl, tl);
|
15502 | lefttop = interpolateX$1(maxV, bl, tl);
|
15503 | topleft = 1 - interpolateX$1(maxV, tr, tl);
|
15504 | topright = 1 - interpolateX$1(minV, tr, tl);
|
15505 | } else {
|
15506 | rightbottom = interpolateX$1(maxV, br, tr);
|
15507 | bottomright = 1 - interpolateX$1(maxV, br, bl);
|
15508 | leftbottom = 1 - interpolateX$1(maxV, tl, bl);
|
15509 | lefttop = 1 - interpolateX$1(minV, tl, bl);
|
15510 | topleft = interpolateX$1(minV, tl, tr);
|
15511 | topright = interpolateX$1(maxV, tl, tr);
|
15512 | }
|
15513 | edges.push(isoBandEdgeRB[cval]);
|
15514 | edges.push(isoBandEdgeBR[cval]);
|
15515 | edges.push(isoBandEdgeLT[cval]);
|
15516 | } else if (cval === 85) {
|
15517 | righttop = 1;
|
15518 | rightbottom = 0;
|
15519 | bottomright = 1;
|
15520 | bottomleft = 0;
|
15521 | leftbottom = 0;
|
15522 | lefttop = 1;
|
15523 | topleft = 0;
|
15524 | topright = 1;
|
15525 | }
|
15526 |
|
15527 | if (topleft < 0 || topleft > 1 || topright < 0 || topright > 1 || righttop < 0 || righttop > 1 || bottomright < 0 || bottomright > 1 || leftbottom < 0 || leftbottom > 1 || lefttop < 0 || lefttop > 1) {
|
15528 | console.log('MarchingSquaresJS-isoBands: ' + cval + ' ' + cval_real + ' ' + tl + ',' + tr + ',' + br + ',' + bl + ' ' + flipped + ' ' + topleft + ' ' + topright + ' ' + righttop + ' ' + rightbottom + ' ' + bottomright + ' ' + bottomleft + ' ' + leftbottom + ' ' + lefttop);
|
15529 | }
|
15530 |
|
15531 | BandGrid.cells[j][i] = {
|
15532 | cval: cval,
|
15533 | cval_real: cval_real,
|
15534 | flipped: flipped,
|
15535 | topleft: topleft,
|
15536 | topright: topright,
|
15537 | righttop: righttop,
|
15538 | rightbottom: rightbottom,
|
15539 | bottomright: bottomright,
|
15540 | bottomleft: bottomleft,
|
15541 | leftbottom: leftbottom,
|
15542 | lefttop: lefttop,
|
15543 | edges: edges
|
15544 | };
|
15545 | }
|
15546 | }
|
15547 | }
|
15548 |
|
15549 | return BandGrid;
|
15550 | }
|
15551 |
|
15552 | function BandGrid2AreaPaths(grid) {
|
15553 | var areas = [];
|
15554 | var rows = grid.rows;
|
15555 | var cols = grid.cols;
|
15556 | var currentPolygon = [];
|
15557 |
|
15558 | for (var j = 0; j < rows; j++) {
|
15559 | for (var i = 0; i < cols; i++) {
|
15560 | if ((typeof grid.cells[j][i] !== 'undefined') && (grid.cells[j][i].edges.length > 0)) {
|
15561 |
|
15562 |
|
15563 | var cell = grid.cells[j][i];
|
15564 |
|
15565 |
|
15566 |
|
15567 | var prev = getStartXY(cell),
|
15568 | next = null,
|
15569 | p = i,
|
15570 | q = j;
|
15571 |
|
15572 | if (prev !== null) {
|
15573 | currentPolygon.push([prev.p[0] + p, prev.p[1] + q]);
|
15574 |
|
15575 |
|
15576 | }
|
15577 |
|
15578 | do {
|
15579 |
|
15580 |
|
15581 |
|
15582 |
|
15583 |
|
15584 | next = getExitXY(grid.cells[q][p], prev.x, prev.y, prev.o);
|
15585 | if (next !== null) {
|
15586 |
|
15587 | currentPolygon.push([next.p[0] + p, next.p[1] + q]);
|
15588 | p += next.x;
|
15589 | q += next.y;
|
15590 | prev = next;
|
15591 | } else {
|
15592 |
|
15593 | break;
|
15594 | }
|
15595 |
|
15596 |
|
15597 | if ((q < 0) || (q >= rows) || (p < 0) || (p >= cols) || (typeof grid.cells[q][p] === 'undefined')) {
|
15598 | |
15599 |
|
15600 |
|
15601 |
|
15602 |
|
15603 |
|
15604 | p -= next.x;
|
15605 | q -= next.y;
|
15606 |
|
15607 |
|
15608 |
|
15609 | var missing = traceOutOfGridPath(grid, p, q, next.x, next.y, next.o);
|
15610 | if (missing !== null) {
|
15611 | missing.path.forEach(function (pp) {
|
15612 |
|
15613 | currentPolygon.push(pp);
|
15614 | });
|
15615 | p = missing.i;
|
15616 | q = missing.j;
|
15617 | prev = missing;
|
15618 | } else {
|
15619 | break;
|
15620 | }
|
15621 |
|
15622 | }
|
15623 | } while ((typeof grid.cells[q][p] !== 'undefined') &&
|
15624 | (grid.cells[q][p].edges.length > 0));
|
15625 |
|
15626 | areas.push(currentPolygon);
|
15627 |
|
15628 |
|
15629 | currentPolygon = [];
|
15630 | if (grid.cells[j][i].edges.length > 0)
|
15631 | i--;
|
15632 | }
|
15633 | }
|
15634 | }
|
15635 | return areas;
|
15636 | }
|
15637 |
|
15638 | function traceOutOfGridPath(grid, i, j, d_x, d_y, d_o) {
|
15639 | var cell = grid.cells[j][i];
|
15640 | var cval = cell.cval_real;
|
15641 | var p = i + d_x,
|
15642 | q = j + d_y;
|
15643 | var path = [];
|
15644 | var closed = false;
|
15645 |
|
15646 | while (!closed) {
|
15647 |
|
15648 | if ((typeof grid.cells[q] === 'undefined') || (typeof grid.cells[q][p] === 'undefined')) {
|
15649 |
|
15650 |
|
15651 |
|
15652 |
|
15653 | q -= d_y;
|
15654 | p -= d_x;
|
15655 | cell = grid.cells[q][p];
|
15656 | cval = cell.cval_real;
|
15657 |
|
15658 |
|
15659 | if (d_y === -1) {
|
15660 | if (d_o === 0) {
|
15661 | if (cval & Node3) {
|
15662 | path.push([p, q]);
|
15663 | d_x = -1;
|
15664 | d_y = 0;
|
15665 | d_o = 0;
|
15666 | } else if (cval & Node2) {
|
15667 | path.push([p + 1, q]);
|
15668 | d_x = 1;
|
15669 | d_y = 0;
|
15670 | d_o = 0;
|
15671 | } else {
|
15672 | path.push([p + cell.bottomright, q]);
|
15673 | d_x = 0;
|
15674 | d_y = 1;
|
15675 | d_o = 1;
|
15676 | closed = true;
|
15677 | break;
|
15678 | }
|
15679 | } else if (cval & Node3) {
|
15680 | path.push([p, q]);
|
15681 | d_x = -1;
|
15682 | d_y = 0;
|
15683 | d_o = 0;
|
15684 | } else if (cval & Node2) {
|
15685 | path.push([p + cell.bottomright, q]);
|
15686 | d_x = 0;
|
15687 | d_y = 1;
|
15688 | d_o = 1;
|
15689 | closed = true;
|
15690 | break;
|
15691 | } else {
|
15692 | path.push([p + cell.bottomleft, q]);
|
15693 | d_x = 0;
|
15694 | d_y = 1;
|
15695 | d_o = 0;
|
15696 | closed = true;
|
15697 | break;
|
15698 | }
|
15699 | } else if (d_y === 1) {
|
15700 |
|
15701 | if (d_o === 0) {
|
15702 | if (cval & Node1) {
|
15703 | path.push([p + 1, q + 1]);
|
15704 | d_x = 1;
|
15705 | d_y = 0;
|
15706 | d_o = 1;
|
15707 | } else if (!(cval & Node0)) {
|
15708 | path.push([p + cell.topright, q + 1]);
|
15709 | d_x = 0;
|
15710 | d_y = -1;
|
15711 | d_o = 1;
|
15712 | closed = true;
|
15713 |
|
15714 | break;
|
15715 | } else {
|
15716 | path.push([p + cell.topleft, q + 1]);
|
15717 | d_x = 0;
|
15718 | d_y = -1;
|
15719 | d_o = 0;
|
15720 | closed = true;
|
15721 | break;
|
15722 | }
|
15723 | } else if (cval & Node1) {
|
15724 | path.push([p + 1, q + 1]);
|
15725 | d_x = 1;
|
15726 | d_y = 0;
|
15727 | d_o = 1;
|
15728 | } else {
|
15729 | path.push([p + 1, q + 1]);
|
15730 | d_x = 1;
|
15731 | d_y = 0;
|
15732 | d_o = 1;
|
15733 |
|
15734 |
|
15735 | }
|
15736 | } else if (d_x === -1) {
|
15737 |
|
15738 | if (d_o === 0) {
|
15739 |
|
15740 | if (cval & Node0) {
|
15741 | path.push([p, q + 1]);
|
15742 | d_x = 0;
|
15743 | d_y = 1;
|
15744 | d_o = 0;
|
15745 |
|
15746 | } else if (!(cval & Node3)) {
|
15747 |
|
15748 | path.push([p, q + cell.lefttop]);
|
15749 | d_x = 1;
|
15750 | d_y = 0;
|
15751 | d_o = 1;
|
15752 | closed = true;
|
15753 | break;
|
15754 | } else {
|
15755 |
|
15756 | path.push([p, q + cell.leftbottom]);
|
15757 | d_x = 1;
|
15758 | d_y = 0;
|
15759 | d_o = 0;
|
15760 | closed = true;
|
15761 | break;
|
15762 | }
|
15763 | } else {
|
15764 |
|
15765 | if (cval & Node0) {
|
15766 | path.push([p, q + 1]);
|
15767 | d_x = 0;
|
15768 | d_y = 1;
|
15769 | d_o = 0;
|
15770 |
|
15771 | } else {
|
15772 | console.log('MarchingSquaresJS-isoBands: wtf');
|
15773 | break;
|
15774 | }
|
15775 | }
|
15776 | } else if (d_x === 1) {
|
15777 |
|
15778 | if (d_o === 0) {
|
15779 | if (cval & Node2) {
|
15780 | path.push([p + 1, q]);
|
15781 | d_x = 0;
|
15782 | d_y = -1;
|
15783 | d_o = 1;
|
15784 | } else {
|
15785 | path.push([p + 1, q + cell.rightbottom]);
|
15786 | d_x = -1;
|
15787 | d_y = 0;
|
15788 | d_o = 0;
|
15789 | closed = true;
|
15790 | break;
|
15791 | }
|
15792 | } else {
|
15793 | if (cval & Node2) {
|
15794 | path.push([p + 1, q]);
|
15795 | d_x = 0;
|
15796 | d_y = -1;
|
15797 | d_o = 1;
|
15798 | } else if (!(cval & Node1)) {
|
15799 | path.push([p + 1, q + cell.rightbottom]);
|
15800 | d_x = -1;
|
15801 | d_y = 0;
|
15802 | d_o = 0;
|
15803 | closed = true;
|
15804 | break;
|
15805 | } else {
|
15806 | path.push([p + 1, q + cell.righttop]);
|
15807 | d_x = -1;
|
15808 | d_y = 0;
|
15809 | d_o = 1;
|
15810 | break;
|
15811 | }
|
15812 | }
|
15813 | } else {
|
15814 | console.log('MarchingSquaresJS-isoBands: we came from nowhere!');
|
15815 | break;
|
15816 | }
|
15817 |
|
15818 | } else {
|
15819 | cell = grid.cells[q][p];
|
15820 | cval = cell.cval_real;
|
15821 |
|
15822 |
|
15823 | if (d_x === -1) {
|
15824 | if (d_o === 0) {
|
15825 |
|
15826 | if ((typeof grid.cells[q - 1] !== 'undefined') && (typeof grid.cells[q - 1][p] !== 'undefined')) {
|
15827 | d_x = 0;
|
15828 | d_y = -1;
|
15829 | d_o = 1;
|
15830 | } else if (cval & Node3) {
|
15831 |
|
15832 | path.push([p, q]);
|
15833 | } else {
|
15834 | path.push([p + cell.bottomright, q]);
|
15835 | d_x = 0;
|
15836 | d_y = 1;
|
15837 | d_o = 1;
|
15838 | closed = true;
|
15839 |
|
15840 | break;
|
15841 | }
|
15842 | } else if (cval & Node0) {
|
15843 | console.log('MarchingSquaresJS-isoBands: proceeding in x-direction!');
|
15844 | } else {
|
15845 | console.log('MarchingSquaresJS-isoBands: found entry from top at ' + p + ',' + q);
|
15846 | break;
|
15847 | }
|
15848 | } else if (d_x === 1) {
|
15849 | if (d_o === 0) {
|
15850 | console.log('MarchingSquaresJS-isoBands: wtf');
|
15851 | break;
|
15852 | } else {
|
15853 |
|
15854 | if ((typeof grid.cells[q + 1] !== 'undefined') && (typeof grid.cells[q + 1][p] !== 'undefined')) {
|
15855 | d_x = 0;
|
15856 | d_y = 1;
|
15857 | d_o = 0;
|
15858 | } else if (cval & Node1) {
|
15859 | path.push([p + 1, q + 1]);
|
15860 | d_x = 1;
|
15861 | d_y = 0;
|
15862 | d_o = 1;
|
15863 | } else {
|
15864 | path.push([p + cell.topleft, q + 1]);
|
15865 | d_x = 0;
|
15866 | d_y = -1;
|
15867 | d_o = 0;
|
15868 | closed = true;
|
15869 |
|
15870 | break;
|
15871 | }
|
15872 | }
|
15873 | } else if (d_y === -1) {
|
15874 | if (d_o === 1) {
|
15875 |
|
15876 | if (typeof grid.cells[q][p + 1] !== 'undefined') {
|
15877 | d_x = 1;
|
15878 | d_y = 0;
|
15879 | d_o = 1;
|
15880 | } else if (cval & Node2) {
|
15881 | path.push([p + 1, q]);
|
15882 | d_x = 0;
|
15883 | d_y = -1;
|
15884 | d_o = 1;
|
15885 | } else {
|
15886 | path.push([p + 1, q + cell.righttop]);
|
15887 | d_x = -1;
|
15888 | d_y = 0;
|
15889 | d_o = 1;
|
15890 | closed = true;
|
15891 |
|
15892 | break;
|
15893 | }
|
15894 | } else {
|
15895 | console.log('MarchingSquaresJS-isoBands: wtf');
|
15896 | break;
|
15897 | }
|
15898 | } else if (d_y === 1) {
|
15899 | if (d_o === 0) {
|
15900 |
|
15901 |
|
15902 | if (typeof grid.cells[q][p - 1] !== 'undefined') {
|
15903 | d_x = -1;
|
15904 | d_y = 0;
|
15905 | d_o = 0;
|
15906 | } else if (cval & Node0) {
|
15907 | path.push([p, q + 1]);
|
15908 | d_x = 0;
|
15909 | d_y = 1;
|
15910 | d_o = 0;
|
15911 | } else {
|
15912 | path.push([p, q + cell.leftbottom]);
|
15913 | d_x = 1;
|
15914 | d_y = 0;
|
15915 | d_o = 0;
|
15916 | closed = true;
|
15917 |
|
15918 | break;
|
15919 | }
|
15920 | } else {
|
15921 |
|
15922 | console.log('MarchingSquaresJS-isoBands: wtf');
|
15923 | break;
|
15924 | }
|
15925 | } else {
|
15926 | console.log('MarchingSquaresJS-isoBands: where did we came from???');
|
15927 | break;
|
15928 | }
|
15929 |
|
15930 | }
|
15931 |
|
15932 | p += d_x;
|
15933 | q += d_y;
|
15934 |
|
15935 |
|
15936 | if ((p === i) && (q === j)) {
|
15937 | break;
|
15938 | }
|
15939 |
|
15940 | }
|
15941 |
|
15942 |
|
15943 | return { path: path, i: p, j: q, x: d_x, y: d_y, o: d_o };
|
15944 | }
|
15945 |
|
15946 | function deleteEdge(cell, edgeIdx) {
|
15947 | delete cell.edges[edgeIdx];
|
15948 | for (var k = edgeIdx + 1; k < cell.edges.length; k++) {
|
15949 | cell.edges[k - 1] = cell.edges[k];
|
15950 | }
|
15951 | cell.edges.pop();
|
15952 | }
|
15953 |
|
15954 | function getStartXY(cell) {
|
15955 |
|
15956 | if (cell.edges.length > 0) {
|
15957 | var e = cell.edges[cell.edges.length - 1];
|
15958 |
|
15959 | var cval = cell.cval_real;
|
15960 | switch (e) {
|
15961 | case 0: if (cval & Node1) {
|
15962 | return {p: [1, cell.righttop], x: -1, y: 0, o: 1};
|
15963 | } else {
|
15964 | return {p: [cell.topleft, 1], x: 0, y: -1, o: 0};
|
15965 | }
|
15966 | case 1: if (cval & Node2) {
|
15967 | return {p: [cell.topleft, 1], x: 0, y: -1, o: 0};
|
15968 | } else {
|
15969 | return {p: [1, cell.rightbottom], x: -1, y: 0, o: 0};
|
15970 | }
|
15971 | case 2: if (cval & Node2) {
|
15972 | return {p: [cell.bottomright, 0], x: 0, y: 1, o: 1};
|
15973 | } else {
|
15974 | return {p: [cell.topleft, 1], x: 0, y: -1, o: 0};
|
15975 | }
|
15976 | case 3: if (cval & Node3) {
|
15977 | return {p: [cell.topleft, 1], x: 0, y: -1, o: 0};
|
15978 | } else {
|
15979 | return {p: [cell.bottomleft, 0], x: 0, y: 1, o: 0};
|
15980 | }
|
15981 | case 4: if (cval & Node1) {
|
15982 | return {p: [1, cell.righttop], x: -1, y: 0, o: 1};
|
15983 | } else {
|
15984 | return {p: [cell.topright, 1], x: 0, y: -1, o: 1};
|
15985 | }
|
15986 | case 5: if (cval & Node2) {
|
15987 | return {p: [cell.topright, 1], x: 0, y: -1, o: 1};
|
15988 | } else {
|
15989 | return {p: [1, cell.rightbottom], x: -1, y: 0, o: 0};
|
15990 | }
|
15991 | case 6: if (cval & Node2) {
|
15992 | return {p: [cell.bottomright, 0], x: 0, y: 1, o: 1};
|
15993 | } else {
|
15994 | return {p: [cell.topright, 1], x: 0, y: -1, o: 1};
|
15995 | }
|
15996 | case 7: if (cval & Node3) {
|
15997 | return {p: [cell.topright, 1], x: 0, y: -1, o: 1};
|
15998 | } else {
|
15999 | return {p: [cell.bottomleft, 0], x: 0, y: 1, o: 0};
|
16000 | }
|
16001 | case 8: if (cval & Node2) {
|
16002 | return {p: [cell.bottomright, 0], x: 0, y: 1, o: 1};
|
16003 | } else {
|
16004 | return {p: [1, cell.righttop], x: -1, y: 0, o: 1};
|
16005 | }
|
16006 | case 9: if (cval & Node3) {
|
16007 | return {p: [1, cell.righttop], x: -1, y: 0, o: 1};
|
16008 | } else {
|
16009 | return {p: [cell.bottomleft, 0], x: 0, y: 1, o: 0};
|
16010 | }
|
16011 | case 10: if (cval & Node3) {
|
16012 | return {p: [0, cell.leftbottom], x: 1, y: 0, o: 0};
|
16013 | } else {
|
16014 | return {p: [1, cell.righttop], x: -1, y: 0, o: 1};
|
16015 | }
|
16016 | case 11: if (cval & Node0) {
|
16017 | return {p: [1, cell.righttop], x: -1, y: 0, o: 1};
|
16018 | } else {
|
16019 | return {p: [0, cell.lefttop], x: 1, y: 0, o: 1};
|
16020 | }
|
16021 | case 12: if (cval & Node2) {
|
16022 | return {p: [cell.bottomright, 0], x: 0, y: 1, o: 1};
|
16023 | } else {
|
16024 | return {p: [1, cell.rightbottom], x: -1, y: 0, o: 0};
|
16025 | }
|
16026 | case 13: if (cval & Node3) {
|
16027 | return {p: [1, cell.rightbottom], x: -1, y: 0, o: 0};
|
16028 | } else {
|
16029 | return {p: [cell.bottomleft, 0], x: 0, y: 1, o: 0};
|
16030 | }
|
16031 | case 14: if (cval & Node3) {
|
16032 | return {p: [0, cell.leftbottom], x: 1, y: 0, o: 0};
|
16033 | } else {
|
16034 | return {p: [1, cell.rightbottom], x: -1, y: 0, o: 0};
|
16035 | }
|
16036 | case 15: if (cval & Node0) {
|
16037 | return {p: [1, cell.rightbottom], x: -1, y: 0, o: 0};
|
16038 | } else {
|
16039 | return {p: [0, cell.lefttop], x: 1, y: 0, o: 1};
|
16040 | }
|
16041 | case 16: if (cval & Node2) {
|
16042 | return {p: [cell.bottomright, 0], x: 0, y: 1, o: 1};
|
16043 | } else {
|
16044 | return {p: [0, cell.leftbottom], x: 1, y: 0, o: 0};
|
16045 | }
|
16046 | case 17: if (cval & Node0) {
|
16047 | return {p: [cell.bottomright, 0], x: 0, y: 1, o: 1};
|
16048 | } else {
|
16049 | return {p: [0, cell.lefttop], x: 1, y: 0, o: 1};
|
16050 | }
|
16051 | case 18: if (cval & Node3) {
|
16052 | return {p: [0, cell.leftbottom], x: 1, y: 0, o: 0};
|
16053 | } else {
|
16054 | return {p: [cell.bottomleft, 0], x: 0, y: 1, o: 0};
|
16055 | }
|
16056 | case 19: if (cval & Node0) {
|
16057 | return {p: [cell.bottomleft, 0], x: 0, y: 1, o: 0};
|
16058 | } else {
|
16059 | return {p: [0, cell.lefttop], x: 1, y: 0, o: 1};
|
16060 | }
|
16061 | case 20: if (cval & Node0) {
|
16062 | return {p: [cell.topleft, 1], x: 0, y: -1, o: 0};
|
16063 | } else {
|
16064 | return {p: [0, cell.leftbottom], x: 1, y: 0, o: 0};
|
16065 | }
|
16066 | case 21: if (cval & Node1) {
|
16067 | return {p: [0, cell.leftbottom], x: 1, y: 0, o: 0};
|
16068 | } else {
|
16069 | return {p: [cell.topright, 1], x: 0, y: -1, o: 1};
|
16070 | }
|
16071 | case 22: if (cval & Node0) {
|
16072 | return {p: [cell.topleft, 1], x: 0, y: -1, o: 0};
|
16073 | } else {
|
16074 | return {p: [0, cell.lefttop], x: 1, y: 0, o: 1};
|
16075 | }
|
16076 | case 23: if (cval & Node1) {
|
16077 | return {p: [0, cell.lefttop], x: 1, y: 0, o: 1};
|
16078 | } else {
|
16079 | return {p: [cell.topright, 1], x: 0, y: -1, o: 1};
|
16080 | }
|
16081 | default: console.log('MarchingSquaresJS-isoBands: edge index out of range!');
|
16082 | console.log(cell);
|
16083 | break;
|
16084 | }
|
16085 | }
|
16086 |
|
16087 | return null;
|
16088 | }
|
16089 |
|
16090 | function getExitXY(cell, x, y, o) {
|
16091 |
|
16092 | var e, id_x, d_x, d_y, cval = cell.cval;
|
16093 | var d_o;
|
16094 |
|
16095 | switch (x) {
|
16096 | case -1: switch (o) {
|
16097 | case 0: e = isoBandEdgeRB[cval];
|
16098 | d_x = isoBandNextXRB[cval];
|
16099 | d_y = isoBandNextYRB[cval];
|
16100 | d_o = isoBandNextORB[cval];
|
16101 | break;
|
16102 | default: e = isoBandEdgeRT[cval];
|
16103 | d_x = isoBandNextXRT[cval];
|
16104 | d_y = isoBandNextYRT[cval];
|
16105 | d_o = isoBandNextORT[cval];
|
16106 | break;
|
16107 | }
|
16108 | break;
|
16109 | case 1: switch (o) {
|
16110 | case 0: e = isoBandEdgeLB[cval];
|
16111 | d_x = isoBandNextXLB[cval];
|
16112 | d_y = isoBandNextYLB[cval];
|
16113 | d_o = isoBandNextOLB[cval];
|
16114 | break;
|
16115 | default: e = isoBandEdgeLT[cval];
|
16116 | d_x = isoBandNextXLT[cval];
|
16117 | d_y = isoBandNextYLT[cval];
|
16118 | d_o = isoBandNextOLT[cval];
|
16119 | break;
|
16120 | }
|
16121 | break;
|
16122 | default: switch (y) {
|
16123 | case -1: switch (o) {
|
16124 | case 0: e = isoBandEdgeTL[cval];
|
16125 | d_x = isoBandNextXTL[cval];
|
16126 | d_y = isoBandNextYTL[cval];
|
16127 | d_o = isoBandNextOTL[cval];
|
16128 | break;
|
16129 | default: e = isoBandEdgeTR[cval];
|
16130 | d_x = isoBandNextXTR[cval];
|
16131 | d_y = isoBandNextYTR[cval];
|
16132 | d_o = isoBandNextOTR[cval];
|
16133 | break;
|
16134 | }
|
16135 | break;
|
16136 | case 1: switch (o) {
|
16137 | case 0: e = isoBandEdgeBL[cval];
|
16138 | d_x = isoBandNextXBL[cval];
|
16139 | d_y = isoBandNextYBL[cval];
|
16140 | d_o = isoBandNextOBL[cval];
|
16141 | break;
|
16142 | default: e = isoBandEdgeBR[cval];
|
16143 | d_x = isoBandNextXBR[cval];
|
16144 | d_y = isoBandNextYBR[cval];
|
16145 | d_o = isoBandNextOBR[cval];
|
16146 | break;
|
16147 | }
|
16148 | break;
|
16149 | default: break;
|
16150 | }
|
16151 | break;
|
16152 | }
|
16153 |
|
16154 | id_x = cell.edges.indexOf(e);
|
16155 | if (typeof cell.edges[id_x] !== 'undefined') {
|
16156 | deleteEdge(cell, id_x);
|
16157 | } else {
|
16158 |
|
16159 |
|
16160 |
|
16161 | return null;
|
16162 | }
|
16163 |
|
16164 | cval = cell.cval_real;
|
16165 |
|
16166 | switch (e) {
|
16167 | case 0: if (cval & Node1) {
|
16168 | x = cell.topleft;
|
16169 | y = 1;
|
16170 | } else {
|
16171 | x = 1;
|
16172 | y = cell.righttop;
|
16173 | }
|
16174 | break;
|
16175 | case 1: if (cval & Node2) {
|
16176 | x = 1;
|
16177 | y = cell.rightbottom;
|
16178 | } else {
|
16179 | x = cell.topleft;
|
16180 | y = 1;
|
16181 | }
|
16182 | break;
|
16183 | case 2: if (cval & Node2) {
|
16184 | x = cell.topleft;
|
16185 | y = 1;
|
16186 | } else {
|
16187 | x = cell.bottomright;
|
16188 | y = 0;
|
16189 | }
|
16190 | break;
|
16191 | case 3: if (cval & Node3) {
|
16192 | x = cell.bottomleft;
|
16193 | y = 0;
|
16194 | } else {
|
16195 | x = cell.topleft;
|
16196 | y = 1;
|
16197 | }
|
16198 | break;
|
16199 | case 4: if (cval & Node1) {
|
16200 | x = cell.topright;
|
16201 | y = 1;
|
16202 | } else {
|
16203 | x = 1;
|
16204 | y = cell.righttop;
|
16205 | }
|
16206 | break;
|
16207 | case 5: if (cval & Node2) {
|
16208 | x = 1;
|
16209 | y = cell.rightbottom;
|
16210 | } else {
|
16211 | x = cell.topright;
|
16212 | y = 1;
|
16213 | }
|
16214 | break;
|
16215 | case 6: if (cval & Node2) {
|
16216 | x = cell.topright;
|
16217 | y = 1;
|
16218 | } else {
|
16219 | x = cell.bottomright;
|
16220 | y = 0;
|
16221 | }
|
16222 | break;
|
16223 | case 7: if (cval & Node3) {
|
16224 | x = cell.bottomleft;
|
16225 | y = 0;
|
16226 | } else {
|
16227 | x = cell.topright;
|
16228 | y = 1;
|
16229 | }
|
16230 | break;
|
16231 | case 8: if (cval & Node2) {
|
16232 | x = 1;
|
16233 | y = cell.righttop;
|
16234 | } else {
|
16235 | x = cell.bottomright;
|
16236 | y = 0;
|
16237 | }
|
16238 | break;
|
16239 | case 9: if (cval & Node3) {
|
16240 | x = cell.bottomleft;
|
16241 | y = 0;
|
16242 | } else {
|
16243 | x = 1;
|
16244 | y = cell.righttop;
|
16245 | }
|
16246 | break;
|
16247 | case 10: if (cval & Node3) {
|
16248 | x = 1;
|
16249 | y = cell.righttop;
|
16250 | } else {
|
16251 | x = 0;
|
16252 | y = cell.leftbottom;
|
16253 | }
|
16254 | break;
|
16255 | case 11: if (cval & Node0) {
|
16256 | x = 0;
|
16257 | y = cell.lefttop;
|
16258 | } else {
|
16259 | x = 1;
|
16260 | y = cell.righttop;
|
16261 | }
|
16262 | break;
|
16263 | case 12: if (cval & Node2) {
|
16264 | x = 1;
|
16265 | y = cell.rightbottom;
|
16266 | } else {
|
16267 | x = cell.bottomright;
|
16268 | y = 0;
|
16269 | }
|
16270 | break;
|
16271 | case 13: if (cval & Node3) {
|
16272 | x = cell.bottomleft;
|
16273 | y = 0;
|
16274 | } else {
|
16275 | x = 1;
|
16276 | y = cell.rightbottom;
|
16277 | }
|
16278 | break;
|
16279 | case 14: if (cval & Node3) {
|
16280 | x = 1;
|
16281 | y = cell.rightbottom;
|
16282 | } else {
|
16283 | x = 0;
|
16284 | y = cell.leftbottom;
|
16285 | }
|
16286 | break;
|
16287 | case 15: if (cval & Node0) {
|
16288 | x = 0;
|
16289 | y = cell.lefttop;
|
16290 | } else {
|
16291 | x = 1;
|
16292 | y = cell.rightbottom;
|
16293 | }
|
16294 | break;
|
16295 | case 16: if (cval & Node2) {
|
16296 | x = 0;
|
16297 | y = cell.leftbottom;
|
16298 | } else {
|
16299 | x = cell.bottomright;
|
16300 | y = 0;
|
16301 | }
|
16302 | break;
|
16303 | case 17: if (cval & Node0) {
|
16304 | x = 0;
|
16305 | y = cell.lefttop;
|
16306 | } else {
|
16307 | x = cell.bottomright;
|
16308 | y = 0;
|
16309 | }
|
16310 | break;
|
16311 | case 18: if (cval & Node3) {
|
16312 | x = cell.bottomleft;
|
16313 | y = 0;
|
16314 | } else {
|
16315 | x = 0;
|
16316 | y = cell.leftbottom;
|
16317 | }
|
16318 | break;
|
16319 | case 19: if (cval & Node0) {
|
16320 | x = 0;
|
16321 | y = cell.lefttop;
|
16322 | } else {
|
16323 | x = cell.bottomleft;
|
16324 | y = 0;
|
16325 | }
|
16326 | break;
|
16327 | case 20: if (cval & Node0) {
|
16328 | x = 0;
|
16329 | y = cell.leftbottom;
|
16330 | } else {
|
16331 | x = cell.topleft;
|
16332 | y = 1;
|
16333 | }
|
16334 | break;
|
16335 | case 21: if (cval & Node1) {
|
16336 | x = cell.topright;
|
16337 | y = 1;
|
16338 | } else {
|
16339 | x = 0;
|
16340 | y = cell.leftbottom;
|
16341 | }
|
16342 | break;
|
16343 | case 22: if (cval & Node0) {
|
16344 | x = 0;
|
16345 | y = cell.lefttop;
|
16346 | } else {
|
16347 | x = cell.topleft;
|
16348 | y = 1;
|
16349 | }
|
16350 | break;
|
16351 | case 23: if (cval & Node1) {
|
16352 | x = cell.topright;
|
16353 | y = 1;
|
16354 | } else {
|
16355 | x = 0;
|
16356 | y = cell.lefttop;
|
16357 | }
|
16358 | break;
|
16359 | default: console.log('MarchingSquaresJS-isoBands: edge index out of range!');
|
16360 | console.log(cell);
|
16361 | return null;
|
16362 | }
|
16363 |
|
16364 | if ((typeof x === 'undefined') || (typeof y === 'undefined') ||
|
16365 | (typeof d_x === 'undefined') || (typeof d_y === 'undefined') ||
|
16366 | (typeof d_o === 'undefined')) {
|
16367 | console.log('MarchingSquaresJS-isoBands: undefined value!');
|
16368 | console.log(cell);
|
16369 | console.log(x + ' ' + y + ' ' + d_x + ' ' + d_y + ' ' + d_o);
|
16370 | }
|
16371 | return {p: [x, y], x: d_x, y: d_y, o: d_o};
|
16372 | }
|
16373 |
|
16374 | function BandGrid2Areas(grid) {
|
16375 | var areas = [];
|
16376 | var area_idx = 0;
|
16377 |
|
16378 | grid.cells.forEach(function (g, j) {
|
16379 | g.forEach(function (gg, i) {
|
16380 | if (typeof gg !== 'undefined') {
|
16381 | var a = polygon_table[gg.cval](gg);
|
16382 | if ((typeof a === 'object') && isArray(a)) {
|
16383 | if ((typeof a[0] === 'object') && isArray(a[0])) {
|
16384 | if ((typeof a[0][0] === 'object') && isArray(a[0][0])) {
|
16385 | a.forEach(function (aa) {
|
16386 | aa.forEach(function (aaa) {
|
16387 | aaa[0] += i;
|
16388 | aaa[1] += j;
|
16389 | });
|
16390 | areas[area_idx++] = aa;
|
16391 | });
|
16392 | } else {
|
16393 | a.forEach(function (aa) {
|
16394 | aa[0] += i;
|
16395 | aa[1] += j;
|
16396 | });
|
16397 | areas[area_idx++] = a;
|
16398 | }
|
16399 | } else {
|
16400 | console.log('MarchingSquaresJS-isoBands: bandcell polygon with malformed coordinates');
|
16401 | }
|
16402 | } else {
|
16403 | console.log('MarchingSquaresJS-isoBands: bandcell polygon with null coordinates');
|
16404 | }
|
16405 | }
|
16406 | });
|
16407 | });
|
16408 |
|
16409 | return areas;
|
16410 | }
|
16411 |
|
16412 |
|
16413 |
|
16414 |
|
16415 |
|
16416 |
|
16417 |
|
16418 |
|
16419 |
|
16420 |
|
16421 |
|
16422 |
|
16423 |
|
16424 |
|
16425 | function isobands(pointGrid, breaks, options) {
|
16426 |
|
16427 | options = options || {};
|
16428 | if (!isObject(options)) throw new Error('options is invalid');
|
16429 | var zProperty = options.zProperty || 'elevation';
|
16430 | var commonProperties = options.commonProperties || {};
|
16431 | var breaksProperties = options.breaksProperties || [];
|
16432 |
|
16433 |
|
16434 | collectionOf(pointGrid, 'Point', 'Input must contain Points');
|
16435 | if (!breaks) throw new Error('breaks is required');
|
16436 | if (!Array.isArray(breaks)) throw new Error('breaks is not an Array');
|
16437 | if (!isObject(commonProperties)) throw new Error('commonProperties is not an Object');
|
16438 | if (!Array.isArray(breaksProperties)) throw new Error('breaksProperties is not an Array');
|
16439 |
|
16440 |
|
16441 | var matrix = gridToMatrix$1(pointGrid, {zProperty: zProperty, flip: true});
|
16442 | var contours = createContourLines(matrix, breaks, zProperty);
|
16443 | contours = rescaleContours(contours, matrix, pointGrid);
|
16444 |
|
16445 | var multipolygons = contours.map(function (contour, index) {
|
16446 | if (breaksProperties[index] && !isObject(breaksProperties[index])) {
|
16447 | throw new Error('Each mappedProperty is required to be an Object');
|
16448 | }
|
16449 |
|
16450 | var contourProperties = Object.assign(
|
16451 | {},
|
16452 | commonProperties,
|
16453 | breaksProperties[index]
|
16454 | );
|
16455 | contourProperties[zProperty] = contour[zProperty];
|
16456 | var multiP = multiPolygon(contour.groupedRings, contourProperties);
|
16457 | return multiP;
|
16458 | });
|
16459 |
|
16460 | return featureCollection(multipolygons);
|
16461 | }
|
16462 |
|
16463 |
|
16464 |
|
16465 |
|
16466 |
|
16467 |
|
16468 |
|
16469 |
|
16470 |
|
16471 |
|
16472 |
|
16473 |
|
16474 |
|
16475 |
|
16476 | function createContourLines(matrix, breaks, property) {
|
16477 |
|
16478 | var contours = [];
|
16479 | for (var i = 1; i < breaks.length; i++) {
|
16480 | var lowerBand = +breaks[i - 1];
|
16481 | var upperBand = +breaks[i];
|
16482 |
|
16483 | var isobandsCoords = isoBands(matrix, lowerBand, upperBand - lowerBand);
|
16484 |
|
16485 |
|
16486 |
|
16487 |
|
16488 | var nestedRings = orderByArea(isobandsCoords);
|
16489 | var groupedRings = groupNestedRings(nestedRings);
|
16490 | var obj = {};
|
16491 | obj['groupedRings'] = groupedRings;
|
16492 | obj[property] = lowerBand + '-' + upperBand;
|
16493 | contours.push(obj);
|
16494 | }
|
16495 | return contours;
|
16496 | }
|
16497 |
|
16498 |
|
16499 |
|
16500 |
|
16501 |
|
16502 |
|
16503 |
|
16504 |
|
16505 |
|
16506 |
|
16507 | function rescaleContours(contours, matrix, points$$1) {
|
16508 |
|
16509 |
|
16510 | var gridBbox = bbox(points$$1);
|
16511 | var originalWidth = gridBbox[2] - gridBbox[0];
|
16512 | var originalHeigth = gridBbox[3] - gridBbox[1];
|
16513 |
|
16514 |
|
16515 | var x0 = gridBbox[0];
|
16516 | var y0 = gridBbox[1];
|
16517 |
|
16518 | var matrixWidth = matrix[0].length - 1;
|
16519 | var matrixHeight = matrix.length - 1;
|
16520 |
|
16521 | var scaleX = originalWidth / matrixWidth;
|
16522 | var scaleY = originalHeigth / matrixHeight;
|
16523 |
|
16524 | var resize = function (point$$1) {
|
16525 | point$$1[0] = point$$1[0] * scaleX + x0;
|
16526 | point$$1[1] = point$$1[1] * scaleY + y0;
|
16527 | };
|
16528 |
|
16529 |
|
16530 | contours.forEach(function (contour) {
|
16531 | contour.groupedRings.forEach(function (lineRingSet) {
|
16532 | lineRingSet.forEach(function (lineRing) {
|
16533 | lineRing.forEach(resize);
|
16534 | });
|
16535 | });
|
16536 | });
|
16537 | return contours;
|
16538 | }
|
16539 |
|
16540 |
|
16541 |
|
16542 |
|
16543 |
|
16544 |
|
16545 |
|
16546 |
|
16547 |
|
16548 |
|
16549 |
|
16550 |
|
16551 | function orderByArea(ringsCoords) {
|
16552 | var ringsWithArea = [];
|
16553 | var areas = [];
|
16554 | ringsCoords.forEach(function (coords) {
|
16555 |
|
16556 | var ringArea = area$1(polygon([coords]));
|
16557 |
|
16558 | areas.push(ringArea);
|
16559 |
|
16560 | ringsWithArea.push({ring: coords, area: ringArea});
|
16561 | });
|
16562 | areas.sort(function (a, b) {
|
16563 | return b - a;
|
16564 | });
|
16565 |
|
16566 | var orderedByArea = [];
|
16567 | areas.forEach(function (area$$1) {
|
16568 | for (var lr = 0; lr < ringsWithArea.length; lr++) {
|
16569 | if (ringsWithArea[lr].area === area$$1) {
|
16570 | orderedByArea.push(ringsWithArea[lr].ring);
|
16571 | ringsWithArea.splice(lr, 1);
|
16572 | break;
|
16573 | }
|
16574 | }
|
16575 | });
|
16576 | return orderedByArea;
|
16577 | }
|
16578 |
|
16579 |
|
16580 |
|
16581 |
|
16582 |
|
16583 |
|
16584 |
|
16585 |
|
16586 |
|
16587 |
|
16588 | function groupNestedRings(orderedLinearRings) {
|
16589 |
|
16590 | var lrList = orderedLinearRings.map(function (lr) {
|
16591 | return {lrCoordinates: lr, grouped: false};
|
16592 | });
|
16593 | var groupedLinearRingsCoords = [];
|
16594 | while (!allGrouped(lrList)) {
|
16595 | for (var i = 0; i < lrList.length; i++) {
|
16596 | if (!lrList[i].grouped) {
|
16597 |
|
16598 | var group = [];
|
16599 | group.push(lrList[i].lrCoordinates);
|
16600 | lrList[i].grouped = true;
|
16601 | var outerMostPoly = polygon([lrList[i].lrCoordinates]);
|
16602 |
|
16603 | for (var j = i + 1; j < lrList.length; j++) {
|
16604 | if (!lrList[j].grouped) {
|
16605 | var lrPoly = polygon([lrList[j].lrCoordinates]);
|
16606 | if (isInside(lrPoly, outerMostPoly)) {
|
16607 | group.push(lrList[j].lrCoordinates);
|
16608 | lrList[j].grouped = true;
|
16609 | }
|
16610 | }
|
16611 | }
|
16612 |
|
16613 | groupedLinearRingsCoords.push(group);
|
16614 | }
|
16615 | }
|
16616 | }
|
16617 | return groupedLinearRingsCoords;
|
16618 | }
|
16619 |
|
16620 |
|
16621 |
|
16622 |
|
16623 |
|
16624 |
|
16625 |
|
16626 | function isInside(testPolygon, targetPolygon) {
|
16627 | var points$$1 = explode(testPolygon);
|
16628 | for (var i = 0; i < points$$1.features.length; i++) {
|
16629 | if (!booleanPointInPolygon(points$$1.features[i], targetPolygon)) {
|
16630 | return false;
|
16631 | }
|
16632 | }
|
16633 | return true;
|
16634 | }
|
16635 |
|
16636 |
|
16637 |
|
16638 |
|
16639 |
|
16640 |
|
16641 | function allGrouped(list) {
|
16642 | for (var i = 0; i < list.length; i++) {
|
16643 | if (list[i].grouped === false) {
|
16644 | return false;
|
16645 | }
|
16646 | }
|
16647 | return true;
|
16648 | }
|
16649 |
|
16650 |
|
16651 |
|
16652 |
|
16653 |
|
16654 |
|
16655 |
|
16656 |
|
16657 |
|
16658 |
|
16659 |
|
16660 |
|
16661 |
|
16662 |
|
16663 |
|
16664 |
|
16665 |
|
16666 |
|
16667 |
|
16668 |
|
16669 |
|
16670 | function transformRotate(geojson, angle, options) {
|
16671 |
|
16672 | options = options || {};
|
16673 | if (!isObject(options)) throw new Error('options is invalid');
|
16674 | var pivot = options.pivot;
|
16675 | var mutate = options.mutate;
|
16676 |
|
16677 |
|
16678 | if (!geojson) throw new Error('geojson is required');
|
16679 | if (angle === undefined || angle === null || isNaN(angle)) throw new Error('angle is required');
|
16680 |
|
16681 |
|
16682 | if (angle === 0) return geojson;
|
16683 |
|
16684 |
|
16685 | if (!pivot) pivot = centroid(geojson);
|
16686 |
|
16687 |
|
16688 | if (mutate === false || mutate === undefined) geojson = clone(geojson);
|
16689 |
|
16690 |
|
16691 | coordEach(geojson, function (pointCoords) {
|
16692 | var initialAngle = rhumbBearing(pivot, pointCoords);
|
16693 | var finalAngle = initialAngle + angle;
|
16694 | var distance = rhumbDistance(pivot, pointCoords);
|
16695 | var newCoords = getCoords(rhumbDestination(pivot, distance, finalAngle));
|
16696 | pointCoords[0] = newCoords[0];
|
16697 | pointCoords[1] = newCoords[1];
|
16698 | });
|
16699 | return geojson;
|
16700 | }
|
16701 |
|
16702 |
|
16703 |
|
16704 |
|
16705 |
|
16706 |
|
16707 |
|
16708 |
|
16709 |
|
16710 |
|
16711 |
|
16712 |
|
16713 |
|
16714 |
|
16715 |
|
16716 |
|
16717 |
|
16718 |
|
16719 |
|
16720 |
|
16721 | function transformScale(geojson, factor, options) {
|
16722 |
|
16723 | options = options || {};
|
16724 | if (!isObject(options)) throw new Error('options is invalid');
|
16725 | var origin = options.origin;
|
16726 | var mutate = options.mutate;
|
16727 |
|
16728 |
|
16729 | if (!geojson) throw new Error('geojson required');
|
16730 | if (typeof factor !== 'number' || factor === 0) throw new Error('invalid factor');
|
16731 | var originIsPoint = Array.isArray(origin) || typeof origin === 'object';
|
16732 |
|
16733 |
|
16734 | if (mutate !== true) geojson = clone(geojson);
|
16735 |
|
16736 |
|
16737 | if (geojson.type === 'FeatureCollection' && !originIsPoint) {
|
16738 | featureEach(geojson, function (feature$$1, index) {
|
16739 | geojson.features[index] = scale(feature$$1, factor, origin);
|
16740 | });
|
16741 | return geojson;
|
16742 | }
|
16743 |
|
16744 | return scale(geojson, factor, origin);
|
16745 | }
|
16746 |
|
16747 |
|
16748 |
|
16749 |
|
16750 |
|
16751 |
|
16752 |
|
16753 |
|
16754 |
|
16755 |
|
16756 | function scale(feature$$1, factor, origin) {
|
16757 |
|
16758 | var isPoint = getType(feature$$1) === 'Point';
|
16759 | origin = defineOrigin(feature$$1, origin);
|
16760 |
|
16761 |
|
16762 | if (factor === 1 || isPoint) return feature$$1;
|
16763 |
|
16764 |
|
16765 | coordEach(feature$$1, function (coord) {
|
16766 | var originalDistance = rhumbDistance(origin, coord);
|
16767 | var bearing = rhumbBearing(origin, coord);
|
16768 | var newDistance = originalDistance * factor;
|
16769 | var newCoord = getCoords(rhumbDestination(origin, newDistance, bearing));
|
16770 | coord[0] = newCoord[0];
|
16771 | coord[1] = newCoord[1];
|
16772 | if (coord.length === 3) coord[2] *= factor;
|
16773 | });
|
16774 |
|
16775 | return feature$$1;
|
16776 | }
|
16777 |
|
16778 |
|
16779 |
|
16780 |
|
16781 |
|
16782 |
|
16783 |
|
16784 |
|
16785 |
|
16786 | function defineOrigin(geojson, origin) {
|
16787 |
|
16788 | if (origin === undefined || origin === null) origin = 'centroid';
|
16789 |
|
16790 |
|
16791 | if (Array.isArray(origin) || typeof origin === 'object') return getCoord(origin);
|
16792 |
|
16793 |
|
16794 | var bbox$$1 = (geojson.bbox) ? geojson.bbox : bbox(geojson);
|
16795 | var west = bbox$$1[0];
|
16796 | var south = bbox$$1[1];
|
16797 | var east = bbox$$1[2];
|
16798 | var north = bbox$$1[3];
|
16799 |
|
16800 | switch (origin) {
|
16801 | case 'sw':
|
16802 | case 'southwest':
|
16803 | case 'westsouth':
|
16804 | case 'bottomleft':
|
16805 | return point([west, south]);
|
16806 | case 'se':
|
16807 | case 'southeast':
|
16808 | case 'eastsouth':
|
16809 | case 'bottomright':
|
16810 | return point([east, south]);
|
16811 | case 'nw':
|
16812 | case 'northwest':
|
16813 | case 'westnorth':
|
16814 | case 'topleft':
|
16815 | return point([west, north]);
|
16816 | case 'ne':
|
16817 | case 'northeast':
|
16818 | case 'eastnorth':
|
16819 | case 'topright':
|
16820 | return point([east, north]);
|
16821 | case 'center':
|
16822 | return center(geojson);
|
16823 | case undefined:
|
16824 | case null:
|
16825 | case 'centroid':
|
16826 | return centroid(geojson);
|
16827 | default:
|
16828 | throw new Error('invalid origin');
|
16829 | }
|
16830 | }
|
16831 |
|
16832 |
|
16833 |
|
16834 |
|
16835 |
|
16836 |
|
16837 |
|
16838 |
|
16839 |
|
16840 |
|
16841 |
|
16842 |
|
16843 |
|
16844 |
|
16845 |
|
16846 |
|
16847 |
|
16848 |
|
16849 |
|
16850 |
|
16851 |
|
16852 |
|
16853 | function transformTranslate(geojson, distance, direction, options) {
|
16854 |
|
16855 | options = options || {};
|
16856 | if (!isObject(options)) throw new Error('options is invalid');
|
16857 | var units = options.units;
|
16858 | var zTranslation = options.zTranslation;
|
16859 | var mutate = options.mutate;
|
16860 |
|
16861 |
|
16862 | if (!geojson) throw new Error('geojson is required');
|
16863 | if (distance === undefined || distance === null || isNaN(distance)) throw new Error('distance is required');
|
16864 | if (zTranslation && typeof zTranslation !== 'number' && isNaN(zTranslation)) throw new Error('zTranslation is not a number');
|
16865 |
|
16866 |
|
16867 | zTranslation = (zTranslation !== undefined) ? zTranslation : 0;
|
16868 | if (distance === 0 && zTranslation === 0) return geojson;
|
16869 |
|
16870 | if (direction === undefined || direction === null || isNaN(direction)) throw new Error('direction is required');
|
16871 |
|
16872 |
|
16873 | if (distance < 0) {
|
16874 | distance = -distance;
|
16875 | direction = -direction;
|
16876 | }
|
16877 |
|
16878 |
|
16879 | if (mutate === false || mutate === undefined) geojson = clone(geojson);
|
16880 |
|
16881 |
|
16882 | coordEach(geojson, function (pointCoords) {
|
16883 | var newCoords = getCoords(rhumbDestination(pointCoords, distance, direction, {units: units}));
|
16884 | pointCoords[0] = newCoords[0];
|
16885 | pointCoords[1] = newCoords[1];
|
16886 | if (zTranslation && pointCoords.length === 3) pointCoords[2] += zTranslation;
|
16887 | });
|
16888 | return geojson;
|
16889 | }
|
16890 |
|
16891 |
|
16892 |
|
16893 |
|
16894 |
|
16895 |
|
16896 |
|
16897 |
|
16898 |
|
16899 |
|
16900 |
|
16901 |
|
16902 |
|
16903 |
|
16904 | function ab(segment) {
|
16905 | var start = segment[0];
|
16906 | var end = segment[1];
|
16907 | return [end[0] - start[0], end[1] - start[1]];
|
16908 | }
|
16909 |
|
16910 |
|
16911 |
|
16912 |
|
16913 |
|
16914 |
|
16915 |
|
16916 |
|
16917 |
|
16918 | function crossProduct(v1, v2) {
|
16919 | return (v1[0] * v2[1]) - (v2[0] * v1[1]);
|
16920 | }
|
16921 |
|
16922 |
|
16923 |
|
16924 |
|
16925 |
|
16926 |
|
16927 |
|
16928 |
|
16929 |
|
16930 | function add(v1, v2) {
|
16931 | return [v1[0] + v2[0], v1[1] + v2[1]];
|
16932 | }
|
16933 |
|
16934 |
|
16935 |
|
16936 |
|
16937 |
|
16938 |
|
16939 |
|
16940 |
|
16941 |
|
16942 | function sub(v1, v2) {
|
16943 | return [v1[0] - v2[0], v1[1] - v2[1]];
|
16944 | }
|
16945 |
|
16946 |
|
16947 |
|
16948 |
|
16949 |
|
16950 |
|
16951 |
|
16952 |
|
16953 |
|
16954 | function scalarMult(s, v) {
|
16955 | return [s * v[0], s * v[1]];
|
16956 | }
|
16957 |
|
16958 |
|
16959 |
|
16960 |
|
16961 |
|
16962 |
|
16963 |
|
16964 |
|
16965 |
|
16966 | function intersectSegments(a, b) {
|
16967 | var p = a[0];
|
16968 | var r = ab(a);
|
16969 | var q = b[0];
|
16970 | var s = ab(b);
|
16971 |
|
16972 | var cross = crossProduct(r, s);
|
16973 | var qmp = sub(q, p);
|
16974 | var numerator = crossProduct(qmp, s);
|
16975 | var t = numerator / cross;
|
16976 | var intersection = add(p, scalarMult(t, r));
|
16977 | return intersection;
|
16978 | }
|
16979 |
|
16980 |
|
16981 |
|
16982 |
|
16983 |
|
16984 |
|
16985 |
|
16986 |
|
16987 |
|
16988 | function isParallel(a, b) {
|
16989 | var r = ab(a);
|
16990 | var s = ab(b);
|
16991 | return (crossProduct(r, s) === 0);
|
16992 | }
|
16993 |
|
16994 |
|
16995 |
|
16996 |
|
16997 |
|
16998 |
|
16999 |
|
17000 |
|
17001 |
|
17002 | function intersection(a, b) {
|
17003 | if (isParallel(a, b)) return false;
|
17004 | return intersectSegments(a, b);
|
17005 | }
|
17006 |
|
17007 |
|
17008 |
|
17009 |
|
17010 |
|
17011 |
|
17012 |
|
17013 |
|
17014 |
|
17015 |
|
17016 |
|
17017 |
|
17018 |
|
17019 |
|
17020 |
|
17021 |
|
17022 |
|
17023 |
|
17024 |
|
17025 | function lineOffset(geojson, distance, options) {
|
17026 |
|
17027 | options = options || {};
|
17028 | if (!isObject(options)) throw new Error('options is invalid');
|
17029 | var units = options.units;
|
17030 |
|
17031 |
|
17032 | if (!geojson) throw new Error('geojson is required');
|
17033 | if (distance === undefined || distance === null || isNaN(distance)) throw new Error('distance is required');
|
17034 |
|
17035 | var type = getType(geojson);
|
17036 | var properties = geojson.properties;
|
17037 |
|
17038 | switch (type) {
|
17039 | case 'LineString':
|
17040 | return lineOffsetFeature(geojson, distance, units);
|
17041 | case 'MultiLineString':
|
17042 | var coords = [];
|
17043 | flattenEach(geojson, function (feature$$1) {
|
17044 | coords.push(lineOffsetFeature(feature$$1, distance, units).geometry.coordinates);
|
17045 | });
|
17046 | return multiLineString(coords, properties);
|
17047 | default:
|
17048 | throw new Error('geometry ' + type + ' is not supported');
|
17049 | }
|
17050 | }
|
17051 |
|
17052 |
|
17053 |
|
17054 |
|
17055 |
|
17056 |
|
17057 |
|
17058 |
|
17059 |
|
17060 |
|
17061 | function lineOffsetFeature(line, distance, units) {
|
17062 | var segments = [];
|
17063 | var offsetDegrees = lengthToDegrees(distance, units);
|
17064 | var coords = getCoords(line);
|
17065 | var finalCoords = [];
|
17066 | coords.forEach(function (currentCoords, index) {
|
17067 | if (index !== coords.length - 1) {
|
17068 | var segment = processSegment(currentCoords, coords[index + 1], offsetDegrees);
|
17069 | segments.push(segment);
|
17070 | if (index > 0) {
|
17071 | var seg2Coords = segments[index - 1];
|
17072 | var intersects = intersection(segment, seg2Coords);
|
17073 |
|
17074 |
|
17075 | if (intersects !== false) {
|
17076 | seg2Coords[1] = intersects;
|
17077 | segment[0] = intersects;
|
17078 | }
|
17079 |
|
17080 | finalCoords.push(seg2Coords[0]);
|
17081 | if (index === coords.length - 2) {
|
17082 | finalCoords.push(segment[0]);
|
17083 | finalCoords.push(segment[1]);
|
17084 | }
|
17085 | }
|
17086 |
|
17087 | if (coords.length === 2) {
|
17088 | finalCoords.push(segment[0]);
|
17089 | finalCoords.push(segment[1]);
|
17090 | }
|
17091 | }
|
17092 | });
|
17093 | return lineString(finalCoords, line.properties);
|
17094 | }
|
17095 |
|
17096 |
|
17097 |
|
17098 |
|
17099 |
|
17100 |
|
17101 |
|
17102 |
|
17103 |
|
17104 |
|
17105 |
|
17106 | function processSegment(point1, point2, offset) {
|
17107 | var L = Math.sqrt((point1[0] - point2[0]) * (point1[0] - point2[0]) + (point1[1] - point2[1]) * (point1[1] - point2[1]));
|
17108 |
|
17109 | var out1x = point1[0] + offset * (point2[1] - point1[1]) / L;
|
17110 | var out2x = point2[0] + offset * (point2[1] - point1[1]) / L;
|
17111 | var out1y = point1[1] + offset * (point1[0] - point2[0]) / L;
|
17112 | var out2y = point2[1] + offset * (point1[0] - point2[0]) / L;
|
17113 | return [[out1x, out1y], [out2x, out2y]];
|
17114 | }
|
17115 |
|
17116 |
|
17117 |
|
17118 |
|
17119 |
|
17120 |
|
17121 |
|
17122 |
|
17123 |
|
17124 |
|
17125 |
|
17126 |
|
17127 |
|
17128 |
|
17129 |
|
17130 | function orientationIndex(p1, p2, q) {
|
17131 | var dx1 = p2[0] - p1[0],
|
17132 | dy1 = p2[1] - p1[1],
|
17133 | dx2 = q[0] - p2[0],
|
17134 | dy2 = q[1] - p2[1];
|
17135 |
|
17136 | return Math.sign(dx1 * dy2 - dx2 * dy1);
|
17137 | }
|
17138 |
|
17139 |
|
17140 |
|
17141 |
|
17142 |
|
17143 |
|
17144 |
|
17145 |
|
17146 |
|
17147 |
|
17148 | function envelopeIsEqual(env1, env2) {
|
17149 | var envX1 = env1.geometry.coordinates.map(function (c) { return c[0]; }),
|
17150 | envY1 = env1.geometry.coordinates.map(function (c) { return c[1]; }),
|
17151 | envX2 = env2.geometry.coordinates.map(function (c) { return c[0]; }),
|
17152 | envY2 = env2.geometry.coordinates.map(function (c) { return c[1]; });
|
17153 |
|
17154 | return Math.max(null, envX1) === Math.max(null, envX2) &&
|
17155 | Math.max(null, envY1) === Math.max(null, envY2) &&
|
17156 | Math.min(null, envX1) === Math.min(null, envX2) &&
|
17157 | Math.min(null, envY1) === Math.min(null, envY2);
|
17158 | }
|
17159 |
|
17160 |
|
17161 |
|
17162 |
|
17163 |
|
17164 |
|
17165 |
|
17166 |
|
17167 |
|
17168 |
|
17169 |
|
17170 |
|
17171 | function envelopeContains(self, env) {
|
17172 | return env.geometry.coordinates[0].every(function (c) { return booleanPointInPolygon(point(c), self); });
|
17173 | }
|
17174 |
|
17175 |
|
17176 |
|
17177 |
|
17178 |
|
17179 |
|
17180 |
|
17181 |
|
17182 | function coordinatesEqual(coord1, coord2) {
|
17183 | return coord1[0] === coord2[0] && coord1[1] === coord2[1];
|
17184 | }
|
17185 |
|
17186 |
|
17187 |
|
17188 |
|
17189 | var Node$1 = function Node(coordinates) {
|
17190 | this.id = Node.buildId(coordinates);
|
17191 | this.coordinates = coordinates;
|
17192 | this.innerEdges = [];
|
17193 |
|
17194 |
|
17195 | this.outerEdges = [];
|
17196 | this.outerEdgesSorted = false;
|
17197 | };
|
17198 |
|
17199 | Node$1.buildId = function buildId (coordinates) {
|
17200 | return coordinates.join(',');
|
17201 | };
|
17202 |
|
17203 | Node$1.prototype.removeInnerEdge = function removeInnerEdge (edge) {
|
17204 | this.innerEdges = this.innerEdges.filter(function (e) { return e.from.id !== edge.from.id; });
|
17205 | };
|
17206 |
|
17207 | Node$1.prototype.removeOuterEdge = function removeOuterEdge (edge) {
|
17208 | this.outerEdges = this.outerEdges.filter(function (e) { return e.to.id !== edge.to.id; });
|
17209 | };
|
17210 |
|
17211 |
|
17212 |
|
17213 |
|
17214 |
|
17215 |
|
17216 |
|
17217 | Node$1.prototype.addOuterEdge = function addOuterEdge (edge) {
|
17218 | this.outerEdges.push(edge);
|
17219 | this.outerEdgesSorted = false;
|
17220 | };
|
17221 |
|
17222 |
|
17223 |
|
17224 |
|
17225 |
|
17226 |
|
17227 |
|
17228 | Node$1.prototype.sortOuterEdges = function sortOuterEdges () {
|
17229 | var this$1 = this;
|
17230 |
|
17231 | if (!this.outerEdgesSorted) {
|
17232 |
|
17233 |
|
17234 | this.outerEdges.sort(function (a, b) {
|
17235 | var aNode = a.to,
|
17236 | bNode = b.to;
|
17237 |
|
17238 | if (aNode.coordinates[0] - this$1.coordinates[0] >= 0 && bNode.coordinates[0] - this$1.coordinates[0] < 0)
|
17239 | { return 1; }
|
17240 | if (aNode.coordinates[0] - this$1.coordinates[0] < 0 && bNode.coordinates[0] - this$1.coordinates[0] >= 0)
|
17241 | { return -1; }
|
17242 |
|
17243 | if (aNode.coordinates[0] - this$1.coordinates[0] === 0 && bNode.coordinates[0] - this$1.coordinates[0] === 0) {
|
17244 | if (aNode.coordinates[1] - this$1.coordinates[1] >= 0 || bNode.coordinates[1] - this$1.coordinates[1] >= 0)
|
17245 | { return aNode.coordinates[1] - bNode.coordinates[1]; }
|
17246 | return bNode.coordinates[1] - aNode.coordinates[1];
|
17247 | }
|
17248 |
|
17249 | var det = orientationIndex(this$1.coordinates, aNode.coordinates, bNode.coordinates);
|
17250 | if (det < 0)
|
17251 | { return 1; }
|
17252 | if (det > 0)
|
17253 | { return -1; }
|
17254 |
|
17255 | var d1 = Math.pow(aNode.coordinates[0] - this$1.coordinates[0], 2) + Math.pow(aNode.coordinates[1] - this$1.coordinates[1], 2),
|
17256 | d2 = Math.pow(bNode.coordinates[0] - this$1.coordinates[0], 2) + Math.pow(bNode.coordinates[1] - this$1.coordinates[1], 2);
|
17257 |
|
17258 | return d1 - d2;
|
17259 | });
|
17260 | this.outerEdgesSorted = true;
|
17261 | }
|
17262 | };
|
17263 |
|
17264 |
|
17265 |
|
17266 |
|
17267 |
|
17268 |
|
17269 |
|
17270 |
|
17271 |
|
17272 | Node$1.prototype.getOuterEdges = function getOuterEdges () {
|
17273 | this.sortOuterEdges();
|
17274 | return this.outerEdges;
|
17275 | };
|
17276 |
|
17277 | Node$1.prototype.getOuterEdge = function getOuterEdge (i) {
|
17278 | this.sortOuterEdges();
|
17279 | return this.outerEdges[i];
|
17280 | };
|
17281 |
|
17282 | Node$1.prototype.addInnerEdge = function addInnerEdge (edge) {
|
17283 | this.innerEdges.push(edge);
|
17284 | };
|
17285 |
|
17286 |
|
17287 |
|
17288 |
|
17289 | var Edge = function Edge(from, to) {
|
17290 | this.from = from;
|
17291 | this.to = to;
|
17292 |
|
17293 | this.next = undefined;
|
17294 | this.label = undefined;
|
17295 | this.symetric = undefined;
|
17296 | this.ring = undefined;
|
17297 |
|
17298 | this.from.addOuterEdge(this);
|
17299 | this.to.addInnerEdge(this);
|
17300 | };
|
17301 |
|
17302 |
|
17303 |
|
17304 |
|
17305 | Edge.prototype.getSymetric = function getSymetric () {
|
17306 | if (!this.symetric) {
|
17307 | this.symetric = new Edge(this.to, this.from);
|
17308 | this.symetric.symetric = this;
|
17309 | }
|
17310 |
|
17311 | return this.symetric;
|
17312 | };
|
17313 |
|
17314 | Edge.prototype.deleteEdge = function deleteEdge () {
|
17315 | this.from.removeOuterEdge(this);
|
17316 | this.to.removeInnerEdge(this);
|
17317 | };
|
17318 |
|
17319 |
|
17320 |
|
17321 |
|
17322 |
|
17323 |
|
17324 |
|
17325 |
|
17326 |
|
17327 | Edge.prototype.isEqual = function isEqual (edge) {
|
17328 | return this.from.id === edge.from.id && this.to.id === edge.to.id;
|
17329 | };
|
17330 |
|
17331 | Edge.prototype.toString = function toString () {
|
17332 | return ("Edge { " + (this.from.id) + " -> " + (this.to.id) + " }");
|
17333 | };
|
17334 |
|
17335 |
|
17336 |
|
17337 |
|
17338 |
|
17339 |
|
17340 | Edge.prototype.toLineString = function toLineString () {
|
17341 | return lineString([this.from.coordinates, this.to.coordinates]);
|
17342 | };
|
17343 |
|
17344 |
|
17345 |
|
17346 |
|
17347 |
|
17348 |
|
17349 |
|
17350 |
|
17351 |
|
17352 |
|
17353 |
|
17354 | Edge.prototype.compareTo = function compareTo (edge) {
|
17355 | return orientationIndex(edge.from.coordinates, edge.to.coordinates, this.to.coordinates);
|
17356 | };
|
17357 |
|
17358 |
|
17359 |
|
17360 |
|
17361 |
|
17362 |
|
17363 |
|
17364 |
|
17365 | var EdgeRing = function EdgeRing() {
|
17366 | this.edges = [];
|
17367 | this.polygon = undefined;
|
17368 | this.envelope = undefined;
|
17369 | };
|
17370 |
|
17371 | var prototypeAccessors = { length: { configurable: true } };
|
17372 |
|
17373 |
|
17374 |
|
17375 |
|
17376 |
|
17377 |
|
17378 |
|
17379 | EdgeRing.prototype.push = function push (edge) {
|
17380 |
|
17381 | this[this.edges.length] = edge;
|
17382 | this.edges.push(edge);
|
17383 | this.polygon = this.envelope = undefined;
|
17384 | };
|
17385 |
|
17386 |
|
17387 |
|
17388 |
|
17389 |
|
17390 |
|
17391 |
|
17392 |
|
17393 | EdgeRing.prototype.get = function get (i) {
|
17394 | return this.edges[i];
|
17395 | };
|
17396 |
|
17397 |
|
17398 |
|
17399 |
|
17400 |
|
17401 |
|
17402 |
|
17403 | prototypeAccessors.length.get = function () {
|
17404 | return this.edges.length;
|
17405 | };
|
17406 |
|
17407 |
|
17408 |
|
17409 |
|
17410 |
|
17411 |
|
17412 |
|
17413 | EdgeRing.prototype.forEach = function forEach (f) {
|
17414 | this.edges.forEach(f);
|
17415 | };
|
17416 |
|
17417 |
|
17418 |
|
17419 |
|
17420 |
|
17421 |
|
17422 |
|
17423 |
|
17424 | EdgeRing.prototype.map = function map (f) {
|
17425 | return this.edges.map(f);
|
17426 | };
|
17427 |
|
17428 |
|
17429 |
|
17430 |
|
17431 |
|
17432 |
|
17433 |
|
17434 |
|
17435 | EdgeRing.prototype.some = function some (f) {
|
17436 | return this.edges.some(f);
|
17437 | };
|
17438 |
|
17439 |
|
17440 |
|
17441 |
|
17442 |
|
17443 |
|
17444 |
|
17445 |
|
17446 |
|
17447 |
|
17448 |
|
17449 | EdgeRing.prototype.isValid = function isValid () {
|
17450 |
|
17451 | return true;
|
17452 | };
|
17453 |
|
17454 |
|
17455 |
|
17456 |
|
17457 |
|
17458 |
|
17459 |
|
17460 |
|
17461 |
|
17462 |
|
17463 | EdgeRing.prototype.isHole = function isHole () {
|
17464 | var this$1 = this;
|
17465 |
|
17466 |
|
17467 |
|
17468 | var hiIndex = this.edges.reduce(function (high, edge, i) {
|
17469 | if (edge.from.coordinates[1] > this$1.edges[high].from.coordinates[1])
|
17470 | { high = i; }
|
17471 | return high;
|
17472 | }, 0),
|
17473 | iPrev = (hiIndex === 0 ? this.length : hiIndex) - 1,
|
17474 | iNext = (hiIndex + 1) % this.length,
|
17475 | disc = orientationIndex(this.edges[iPrev].from.coordinates, this.edges[hiIndex].from.coordinates, this.edges[iNext].from.coordinates);
|
17476 |
|
17477 | if (disc === 0)
|
17478 | { return this.edges[iPrev].from.coordinates[0] > this.edges[iNext].from.coordinates[0]; }
|
17479 | return disc > 0;
|
17480 | };
|
17481 |
|
17482 |
|
17483 |
|
17484 |
|
17485 |
|
17486 |
|
17487 |
|
17488 | EdgeRing.prototype.toMultiPoint = function toMultiPoint () {
|
17489 | return multiPoint(this.edges.map(function (edge) { return edge.from.coordinates; }));
|
17490 | };
|
17491 |
|
17492 |
|
17493 |
|
17494 |
|
17495 |
|
17496 |
|
17497 |
|
17498 | EdgeRing.prototype.toPolygon = function toPolygon () {
|
17499 | if (this.polygon)
|
17500 | { return this.polygon; }
|
17501 | var coordinates = this.edges.map(function (edge) { return edge.from.coordinates; });
|
17502 | coordinates.push(this.edges[0].from.coordinates);
|
17503 | return (this.polygon = polygon([coordinates]));
|
17504 | };
|
17505 |
|
17506 |
|
17507 |
|
17508 |
|
17509 |
|
17510 |
|
17511 |
|
17512 | EdgeRing.prototype.getEnvelope = function getEnvelope () {
|
17513 | if (this.envelope)
|
17514 | { return this.envelope; }
|
17515 | return (this.envelope = envelope(this.toPolygon()));
|
17516 | };
|
17517 |
|
17518 |
|
17519 |
|
17520 |
|
17521 |
|
17522 |
|
17523 |
|
17524 |
|
17525 |
|
17526 | EdgeRing.findEdgeRingContaining = function findEdgeRingContaining (testEdgeRing, shellList) {
|
17527 | var testEnvelope = testEdgeRing.getEnvelope();
|
17528 |
|
17529 | var minEnvelope,
|
17530 | minShell;
|
17531 | shellList.forEach(function (shell) {
|
17532 | var tryEnvelope = shell.getEnvelope();
|
17533 |
|
17534 | if (minShell)
|
17535 | { minEnvelope = minShell.getEnvelope(); }
|
17536 |
|
17537 |
|
17538 | if (envelopeIsEqual(tryEnvelope, testEnvelope))
|
17539 | { return; }
|
17540 |
|
17541 | if (envelopeContains(tryEnvelope, testEnvelope)) {
|
17542 | var testPoint = testEdgeRing.map(function (edge) { return edge.from.coordinates; })
|
17543 | .find(function (pt) { return !shell.some(function (edge) { return coordinatesEqual(pt, edge.from.coordinates); }); });
|
17544 |
|
17545 | if (testPoint && shell.inside(point(testPoint))) {
|
17546 | if (!minShell || envelopeContains(minEnvelope, tryEnvelope))
|
17547 | { minShell = shell; }
|
17548 | }
|
17549 | }
|
17550 | });
|
17551 |
|
17552 | return minShell;
|
17553 | };
|
17554 |
|
17555 |
|
17556 |
|
17557 |
|
17558 |
|
17559 |
|
17560 |
|
17561 | EdgeRing.prototype.inside = function inside (pt) {
|
17562 | return booleanPointInPolygon(pt, this.toPolygon());
|
17563 | };
|
17564 |
|
17565 | Object.defineProperties( EdgeRing.prototype, prototypeAccessors );
|
17566 |
|
17567 |
|
17568 |
|
17569 |
|
17570 |
|
17571 |
|
17572 |
|
17573 | function validateGeoJson(geoJson) {
|
17574 | if (!geoJson)
|
17575 | { throw new Error('No geojson passed'); }
|
17576 |
|
17577 | if (geoJson.type !== 'FeatureCollection' &&
|
17578 | geoJson.type !== 'GeometryCollection' &&
|
17579 | geoJson.type !== 'MultiLineString' &&
|
17580 | geoJson.type !== 'LineString' &&
|
17581 | geoJson.type !== 'Feature'
|
17582 | )
|
17583 | { throw new Error(("Invalid input type '" + (geoJson.type) + "'. Geojson must be FeatureCollection, GeometryCollection, LineString, MultiLineString or Feature")); }
|
17584 | }
|
17585 |
|
17586 |
|
17587 |
|
17588 |
|
17589 |
|
17590 |
|
17591 |
|
17592 |
|
17593 |
|
17594 |
|
17595 | var Graph = function Graph() {
|
17596 | this.edges = [];
|
17597 |
|
17598 |
|
17599 | this.nodes = {};
|
17600 | };
|
17601 |
|
17602 |
|
17603 |
|
17604 |
|
17605 | Graph.fromGeoJson = function fromGeoJson (geoJson) {
|
17606 | validateGeoJson(geoJson);
|
17607 |
|
17608 | var graph = new Graph();
|
17609 | flattenEach(geoJson, function (feature$$1) {
|
17610 | featureOf(feature$$1, 'LineString', 'Graph::fromGeoJson');
|
17611 |
|
17612 | coordReduce(feature$$1, function (prev, cur) {
|
17613 | if (prev) {
|
17614 | var start = graph.getNode(prev),
|
17615 | end = graph.getNode(cur);
|
17616 |
|
17617 | graph.addEdge(start, end);
|
17618 | }
|
17619 | return cur;
|
17620 | });
|
17621 | });
|
17622 |
|
17623 | return graph;
|
17624 | };
|
17625 |
|
17626 |
|
17627 |
|
17628 |
|
17629 |
|
17630 |
|
17631 |
|
17632 | Graph.prototype.getNode = function getNode (coordinates) {
|
17633 | var id = Node$1.buildId(coordinates);
|
17634 | var node = this.nodes[id];
|
17635 | if (!node)
|
17636 | { node = this.nodes[id] = new Node$1(coordinates); }
|
17637 |
|
17638 | return node;
|
17639 | };
|
17640 |
|
17641 |
|
17642 |
|
17643 |
|
17644 |
|
17645 |
|
17646 |
|
17647 |
|
17648 |
|
17649 | Graph.prototype.addEdge = function addEdge (from, to) {
|
17650 | var edge = new Edge(from, to),
|
17651 | symetricEdge = edge.getSymetric();
|
17652 |
|
17653 | this.edges.push(edge);
|
17654 | this.edges.push(symetricEdge);
|
17655 | };
|
17656 |
|
17657 | Graph.prototype.deleteDangles = function deleteDangles () {
|
17658 | var this$1 = this;
|
17659 |
|
17660 | Object.keys(this.nodes)
|
17661 | .map(function (id) { return this$1.nodes[id]; })
|
17662 | .forEach(function (node) { return this$1._removeIfDangle(node); });
|
17663 | };
|
17664 |
|
17665 |
|
17666 |
|
17667 |
|
17668 |
|
17669 |
|
17670 |
|
17671 |
|
17672 | Graph.prototype._removeIfDangle = function _removeIfDangle (node) {
|
17673 | var this$1 = this;
|
17674 |
|
17675 |
|
17676 | if (node.innerEdges.length <= 1) {
|
17677 | var outerNodes = node.getOuterEdges().map(function (e) { return e.to; });
|
17678 | this.removeNode(node);
|
17679 | outerNodes.forEach(function (n) { return this$1._removeIfDangle(n); });
|
17680 | }
|
17681 | };
|
17682 |
|
17683 |
|
17684 |
|
17685 |
|
17686 |
|
17687 |
|
17688 |
|
17689 |
|
17690 | Graph.prototype.deleteCutEdges = function deleteCutEdges () {
|
17691 | var this$1 = this;
|
17692 |
|
17693 | this._computeNextCWEdges();
|
17694 | this._findLabeledEdgeRings();
|
17695 |
|
17696 |
|
17697 | this.edges.forEach(function (edge) {
|
17698 | if (edge.label === edge.symetric.label) {
|
17699 | this$1.removeEdge(edge.symetric);
|
17700 | this$1.removeEdge(edge);
|
17701 | }
|
17702 | });
|
17703 | };
|
17704 |
|
17705 |
|
17706 |
|
17707 |
|
17708 |
|
17709 |
|
17710 |
|
17711 |
|
17712 |
|
17713 | Graph.prototype._computeNextCWEdges = function _computeNextCWEdges (node) {
|
17714 | var this$1 = this;
|
17715 |
|
17716 | if (typeof node === 'undefined') {
|
17717 | Object.keys(this.nodes)
|
17718 | .forEach(function (id) { return this$1._computeNextCWEdges(this$1.nodes[id]); });
|
17719 | } else {
|
17720 | node.getOuterEdges().forEach(function (edge, i) {
|
17721 | node.getOuterEdge((i === 0 ? node.getOuterEdges().length : i) - 1).symetric.next = edge;
|
17722 | });
|
17723 | }
|
17724 | };
|
17725 |
|
17726 |
|
17727 |
|
17728 |
|
17729 |
|
17730 |
|
17731 |
|
17732 |
|
17733 |
|
17734 |
|
17735 |
|
17736 |
|
17737 | Graph.prototype._computeNextCCWEdges = function _computeNextCCWEdges (node, label) {
|
17738 | var edges = node.getOuterEdges();
|
17739 | var firstOutDE,
|
17740 | prevInDE;
|
17741 |
|
17742 | for (var i = edges.length - 1; i >= 0; --i) {
|
17743 | var de = edges[i],
|
17744 | sym = de.symetric,
|
17745 | outDE = (void 0),
|
17746 | inDE = (void 0);
|
17747 |
|
17748 | if (de.label === label)
|
17749 | { outDE = de; }
|
17750 |
|
17751 | if (sym.label === label)
|
17752 | { inDE = sym; }
|
17753 |
|
17754 | if (!outDE || !inDE)
|
17755 | { continue; }
|
17756 |
|
17757 | if (inDE)
|
17758 | { prevInDE = inDE; }
|
17759 |
|
17760 | if (outDE) {
|
17761 | if (prevInDE) {
|
17762 | prevInDE.next = outDE;
|
17763 | prevInDE = undefined;
|
17764 | }
|
17765 |
|
17766 | if (!firstOutDE)
|
17767 | { firstOutDE = outDE; }
|
17768 | }
|
17769 | }
|
17770 |
|
17771 | if (prevInDE)
|
17772 | { prevInDE.next = firstOutDE; }
|
17773 | };
|
17774 |
|
17775 |
|
17776 |
|
17777 |
|
17778 |
|
17779 |
|
17780 |
|
17781 |
|
17782 |
|
17783 | Graph.prototype._findLabeledEdgeRings = function _findLabeledEdgeRings () {
|
17784 | var edgeRingStarts = [];
|
17785 | var label = 0;
|
17786 | this.edges.forEach(function (edge) {
|
17787 | if (edge.label >= 0)
|
17788 | { return; }
|
17789 |
|
17790 | edgeRingStarts.push(edge);
|
17791 |
|
17792 | var e = edge;
|
17793 | do {
|
17794 | e.label = label;
|
17795 | e = e.next;
|
17796 | } while (!edge.isEqual(e));
|
17797 |
|
17798 | label++;
|
17799 | });
|
17800 |
|
17801 | return edgeRingStarts;
|
17802 | };
|
17803 |
|
17804 |
|
17805 |
|
17806 |
|
17807 |
|
17808 |
|
17809 | Graph.prototype.getEdgeRings = function getEdgeRings () {
|
17810 | var this$1 = this;
|
17811 |
|
17812 | this._computeNextCWEdges();
|
17813 |
|
17814 |
|
17815 | this.edges.forEach(function (edge) {
|
17816 | edge.label = undefined;
|
17817 | });
|
17818 |
|
17819 | this._findLabeledEdgeRings().forEach(function (edge) {
|
17820 |
|
17821 | this$1._findIntersectionNodes(edge).forEach(function (node) {
|
17822 | this$1._computeNextCCWEdges(node, edge.label);
|
17823 | });
|
17824 | });
|
17825 |
|
17826 | var edgeRingList = [];
|
17827 |
|
17828 |
|
17829 | this.edges.forEach(function (edge) {
|
17830 | if (edge.ring)
|
17831 | { return; }
|
17832 | edgeRingList.push(this$1._findEdgeRing(edge));
|
17833 | });
|
17834 |
|
17835 | return edgeRingList;
|
17836 | };
|
17837 |
|
17838 |
|
17839 |
|
17840 |
|
17841 |
|
17842 |
|
17843 |
|
17844 | Graph.prototype._findIntersectionNodes = function _findIntersectionNodes (startEdge) {
|
17845 | var intersectionNodes = [];
|
17846 | var edge = startEdge;
|
17847 | var loop = function () {
|
17848 |
|
17849 | var degree = 0;
|
17850 | edge.from.getOuterEdges().forEach(function (e) {
|
17851 | if (e.label === startEdge.label)
|
17852 | { ++degree; }
|
17853 | });
|
17854 |
|
17855 | if (degree > 1)
|
17856 | { intersectionNodes.push(edge.from); }
|
17857 |
|
17858 | edge = edge.next;
|
17859 | };
|
17860 |
|
17861 | do {
|
17862 | loop();
|
17863 | } while (!startEdge.isEqual(edge));
|
17864 |
|
17865 | return intersectionNodes;
|
17866 | };
|
17867 |
|
17868 |
|
17869 |
|
17870 |
|
17871 |
|
17872 |
|
17873 |
|
17874 | Graph.prototype._findEdgeRing = function _findEdgeRing (startEdge) {
|
17875 | var edge = startEdge;
|
17876 | var edgeRing = new EdgeRing();
|
17877 |
|
17878 | do {
|
17879 | edgeRing.push(edge);
|
17880 | edge.ring = edgeRing;
|
17881 | edge = edge.next;
|
17882 | } while (!startEdge.isEqual(edge));
|
17883 |
|
17884 | return edgeRing;
|
17885 | };
|
17886 |
|
17887 |
|
17888 |
|
17889 |
|
17890 |
|
17891 |
|
17892 |
|
17893 | Graph.prototype.removeNode = function removeNode (node) {
|
17894 | var this$1 = this;
|
17895 |
|
17896 | node.getOuterEdges().forEach(function (edge) { return this$1.removeEdge(edge); });
|
17897 | node.innerEdges.forEach(function (edge) { return this$1.removeEdge(edge); });
|
17898 | delete this.nodes[node.id];
|
17899 | };
|
17900 |
|
17901 |
|
17902 |
|
17903 |
|
17904 |
|
17905 |
|
17906 | Graph.prototype.removeEdge = function removeEdge (edge) {
|
17907 | this.edges = this.edges.filter(function (e) { return !e.isEqual(edge); });
|
17908 | edge.deleteEdge();
|
17909 | };
|
17910 |
|
17911 |
|
17912 |
|
17913 |
|
17914 |
|
17915 |
|
17916 |
|
17917 |
|
17918 |
|
17919 |
|
17920 |
|
17921 |
|
17922 |
|
17923 |
|
17924 |
|
17925 |
|
17926 |
|
17927 |
|
17928 |
|
17929 | function polygonize$1(geoJson) {
|
17930 | var graph = Graph.fromGeoJson(geoJson);
|
17931 |
|
17932 |
|
17933 | graph.deleteDangles();
|
17934 |
|
17935 |
|
17936 | graph.deleteCutEdges();
|
17937 |
|
17938 |
|
17939 | var holes = [],
|
17940 | shells = [];
|
17941 |
|
17942 | graph.getEdgeRings()
|
17943 | .filter(function (edgeRing) { return edgeRing.isValid(); })
|
17944 | .forEach(function (edgeRing) {
|
17945 | if (edgeRing.isHole())
|
17946 | { holes.push(edgeRing); }
|
17947 | else
|
17948 | { shells.push(edgeRing); }
|
17949 | });
|
17950 |
|
17951 |
|
17952 | holes.forEach(function (hole) {
|
17953 | if (EdgeRing.findEdgeRingContaining(hole, shells))
|
17954 | { shells.push(hole); }
|
17955 | });
|
17956 |
|
17957 |
|
17958 | return featureCollection(shells.map(function (shell) { return shell.toPolygon(); }));
|
17959 | }
|
17960 |
|
17961 |
|
17962 |
|
17963 |
|
17964 |
|
17965 |
|
17966 |
|
17967 |
|
17968 |
|
17969 |
|
17970 |
|
17971 |
|
17972 |
|
17973 |
|
17974 |
|
17975 | function booleanDisjoint(feature1, feature2) {
|
17976 | var boolean;
|
17977 | flattenEach(feature1, function (flatten1) {
|
17978 | flattenEach(feature2, function (flatten2) {
|
17979 | if (boolean === false) return false;
|
17980 | boolean = disjoint(flatten1.geometry, flatten2.geometry);
|
17981 | });
|
17982 | });
|
17983 | return boolean;
|
17984 | }
|
17985 |
|
17986 |
|
17987 |
|
17988 |
|
17989 |
|
17990 |
|
17991 |
|
17992 |
|
17993 |
|
17994 | function disjoint(geom1, geom2) {
|
17995 | switch (geom1.type) {
|
17996 | case 'Point':
|
17997 | switch (geom2.type) {
|
17998 | case 'Point':
|
17999 | return !compareCoords$1(geom1.coordinates, geom2.coordinates);
|
18000 | case 'LineString':
|
18001 | return !isPointOnLine$1(geom2, geom1);
|
18002 | case 'Polygon':
|
18003 | return !booleanPointInPolygon(geom1, geom2);
|
18004 | }
|
18005 |
|
18006 | break;
|
18007 | case 'LineString':
|
18008 | switch (geom2.type) {
|
18009 | case 'Point':
|
18010 | return !isPointOnLine$1(geom1, geom2);
|
18011 | case 'LineString':
|
18012 | return !isLineOnLine$1(geom1, geom2);
|
18013 | case 'Polygon':
|
18014 | return !isLineInPoly$1(geom2, geom1);
|
18015 | }
|
18016 |
|
18017 | break;
|
18018 | case 'Polygon':
|
18019 | switch (geom2.type) {
|
18020 | case 'Point':
|
18021 | return !booleanPointInPolygon(geom2, geom1);
|
18022 | case 'LineString':
|
18023 | return !isLineInPoly$1(geom1, geom2);
|
18024 | case 'Polygon':
|
18025 | return !isPolyInPoly$1(geom2, geom1);
|
18026 | }
|
18027 | }
|
18028 | }
|
18029 |
|
18030 |
|
18031 | function isPointOnLine$1(lineString, point) {
|
18032 | for (var i = 0; i < lineString.coordinates.length - 1; i++) {
|
18033 | if (isPointOnLineSegment$2(lineString.coordinates[i], lineString.coordinates[i + 1], point.coordinates)) {
|
18034 | return true;
|
18035 | }
|
18036 | }
|
18037 | return false;
|
18038 | }
|
18039 |
|
18040 | function isLineOnLine$1(lineString1, lineString2) {
|
18041 | var doLinesIntersect = lineIntersect(lineString1, lineString2);
|
18042 | if (doLinesIntersect.features.length > 0) {
|
18043 | return true;
|
18044 | }
|
18045 | return false;
|
18046 | }
|
18047 |
|
18048 | function isLineInPoly$1(polygon, lineString) {
|
18049 | var doLinesIntersect = lineIntersect(lineString, polygonToLine(polygon));
|
18050 | if (doLinesIntersect.features.length > 0) {
|
18051 | return true;
|
18052 | }
|
18053 | return false;
|
18054 | }
|
18055 |
|
18056 |
|
18057 |
|
18058 |
|
18059 |
|
18060 |
|
18061 |
|
18062 |
|
18063 |
|
18064 |
|
18065 |
|
18066 | function isPolyInPoly$1(feature1, feature2) {
|
18067 | for (var i = 0; i < feature1.coordinates[0].length; i++) {
|
18068 | if (booleanPointInPolygon(feature1.coordinates[0][i], feature2)) {
|
18069 | return true;
|
18070 | }
|
18071 | }
|
18072 | for (var i2 = 0; i2 < feature2.coordinates[0].length; i2++) {
|
18073 | if (booleanPointInPolygon(feature2.coordinates[0][i2], feature1)) {
|
18074 | return true;
|
18075 | }
|
18076 | }
|
18077 | return false;
|
18078 | }
|
18079 |
|
18080 | function isPointOnLineSegment$2(LineSegmentStart, LineSegmentEnd, Point) {
|
18081 | var dxc = Point[0] - LineSegmentStart[0];
|
18082 | var dyc = Point[1] - LineSegmentStart[1];
|
18083 | var dxl = LineSegmentEnd[0] - LineSegmentStart[0];
|
18084 | var dyl = LineSegmentEnd[1] - LineSegmentStart[1];
|
18085 | var cross = dxc * dyl - dyc * dxl;
|
18086 | if (cross !== 0) {
|
18087 | return false;
|
18088 | }
|
18089 | if (Math.abs(dxl) >= Math.abs(dyl)) {
|
18090 | if (dxl > 0) {
|
18091 | return LineSegmentStart[0] <= Point[0] && Point[0] <= LineSegmentEnd[0];
|
18092 | } else {
|
18093 | return LineSegmentEnd[0] <= Point[0] && Point[0] <= LineSegmentStart[0];
|
18094 | }
|
18095 | } else if (dyl > 0) {
|
18096 | return LineSegmentStart[1] <= Point[1] && Point[1] <= LineSegmentEnd[1];
|
18097 | } else {
|
18098 | return LineSegmentEnd[1] <= Point[1] && Point[1] <= LineSegmentStart[1];
|
18099 | }
|
18100 | }
|
18101 |
|
18102 |
|
18103 |
|
18104 |
|
18105 |
|
18106 |
|
18107 |
|
18108 |
|
18109 |
|
18110 | function compareCoords$1(pair1, pair2) {
|
18111 | return pair1[0] === pair2[0] && pair1[1] === pair2[1];
|
18112 | }
|
18113 |
|
18114 |
|
18115 |
|
18116 |
|
18117 |
|
18118 |
|
18119 |
|
18120 |
|
18121 |
|
18122 |
|
18123 |
|
18124 |
|
18125 |
|
18126 |
|
18127 |
|
18128 |
|
18129 |
|
18130 |
|
18131 | function booleanContains(feature1, feature2) {
|
18132 | var type1 = getType(feature1);
|
18133 | var type2 = getType(feature2);
|
18134 | var geom1 = getGeom(feature1);
|
18135 | var geom2 = getGeom(feature2);
|
18136 | var coords1 = getCoords(feature1);
|
18137 | var coords2 = getCoords(feature2);
|
18138 |
|
18139 | switch (type1) {
|
18140 | case 'Point':
|
18141 | switch (type2) {
|
18142 | case 'Point':
|
18143 | return compareCoords$2(coords1, coords2);
|
18144 | default:
|
18145 | throw new Error('feature2 ' + type2 + ' geometry not supported');
|
18146 | }
|
18147 | case 'MultiPoint':
|
18148 | switch (type2) {
|
18149 | case 'Point':
|
18150 | return isPointInMultiPoint$1(geom1, geom2);
|
18151 | case 'MultiPoint':
|
18152 | return isMultiPointInMultiPoint$1(geom1, geom2);
|
18153 | default:
|
18154 | throw new Error('feature2 ' + type2 + ' geometry not supported');
|
18155 | }
|
18156 | case 'LineString':
|
18157 | switch (type2) {
|
18158 | case 'Point':
|
18159 | return booleanPointOnLine(geom2, geom1, {ignoreEndVertices: true});
|
18160 | case 'LineString':
|
18161 | return isLineOnLine$2(geom1, geom2);
|
18162 | case 'MultiPoint':
|
18163 | return isMultiPointOnLine$1(geom1, geom2);
|
18164 | default:
|
18165 | throw new Error('feature2 ' + type2 + ' geometry not supported');
|
18166 | }
|
18167 | case 'Polygon':
|
18168 | switch (type2) {
|
18169 | case 'Point':
|
18170 | return booleanPointInPolygon(geom2, geom1, {ignoreBoundary: true});
|
18171 | case 'LineString':
|
18172 | return isLineInPoly$2(geom1, geom2);
|
18173 | case 'Polygon':
|
18174 | return isPolyInPoly$2(geom1, geom2);
|
18175 | case 'MultiPoint':
|
18176 | return isMultiPointInPoly$1(geom1, geom2);
|
18177 | default:
|
18178 | throw new Error('feature2 ' + type2 + ' geometry not supported');
|
18179 | }
|
18180 | default:
|
18181 | throw new Error('feature1 ' + type1 + ' geometry not supported');
|
18182 | }
|
18183 | }
|
18184 |
|
18185 | function isPointInMultiPoint$1(multiPoint, point) {
|
18186 | var i;
|
18187 | var output = false;
|
18188 | for (i = 0; i < multiPoint.coordinates.length; i++) {
|
18189 | if (compareCoords$2(multiPoint.coordinates[i], point.coordinates)) {
|
18190 | output = true;
|
18191 | break;
|
18192 | }
|
18193 | }
|
18194 | return output;
|
18195 | }
|
18196 |
|
18197 | function isMultiPointInMultiPoint$1(multiPoint1, multiPoint2) {
|
18198 | for (var i = 0; i < multiPoint2.coordinates.length; i++) {
|
18199 | var matchFound = false;
|
18200 | for (var i2 = 0; i2 < multiPoint1.coordinates.length; i2++) {
|
18201 | if (compareCoords$2(multiPoint2.coordinates[i], multiPoint1.coordinates[i2])) {
|
18202 | matchFound = true;
|
18203 | break;
|
18204 | }
|
18205 | }
|
18206 | if (!matchFound) {
|
18207 | return false;
|
18208 | }
|
18209 | }
|
18210 | return true;
|
18211 | }
|
18212 |
|
18213 |
|
18214 | function isMultiPointOnLine$1(lineString, multiPoint) {
|
18215 | var haveFoundInteriorPoint = false;
|
18216 | for (var i = 0; i < multiPoint.coordinates.length; i++) {
|
18217 | if (booleanPointOnLine(multiPoint.coordinates[i], lineString, {ignoreEndVertices: true})) {
|
18218 | haveFoundInteriorPoint = true;
|
18219 | }
|
18220 | if (!booleanPointOnLine(multiPoint.coordinates[i], lineString)) {
|
18221 | return false;
|
18222 | }
|
18223 | }
|
18224 | if (haveFoundInteriorPoint) {
|
18225 | return true;
|
18226 | }
|
18227 | return false;
|
18228 | }
|
18229 |
|
18230 | function isMultiPointInPoly$1(polygon, multiPoint) {
|
18231 | for (var i = 0; i < multiPoint.coordinates.length; i++) {
|
18232 | if (!booleanPointInPolygon(multiPoint.coordinates[i], polygon, {ignoreBoundary: true})) {
|
18233 | return false;
|
18234 | }
|
18235 | }
|
18236 | return true;
|
18237 | }
|
18238 |
|
18239 | function isLineOnLine$2(lineString1, lineString2) {
|
18240 | var haveFoundInteriorPoint = false;
|
18241 | for (var i = 0; i < lineString2.coordinates.length; i++) {
|
18242 | if (booleanPointOnLine({type: 'Point', coordinates: lineString2.coordinates[i]}, lineString1, { ignoreEndVertices: true })) {
|
18243 | haveFoundInteriorPoint = true;
|
18244 | }
|
18245 | if (!booleanPointOnLine({type: 'Point', coordinates: lineString2.coordinates[i]}, lineString1, {ignoreEndVertices: false })) {
|
18246 | return false;
|
18247 | }
|
18248 | }
|
18249 | return haveFoundInteriorPoint;
|
18250 | }
|
18251 |
|
18252 | function isLineInPoly$2(polygon, linestring) {
|
18253 | var output = false;
|
18254 | var i = 0;
|
18255 |
|
18256 | var polyBbox = bbox(polygon);
|
18257 | var lineBbox = bbox(linestring);
|
18258 | if (!doBBoxOverlap$1(polyBbox, lineBbox)) {
|
18259 | return false;
|
18260 | }
|
18261 | for (i; i < linestring.coordinates.length - 1; i++) {
|
18262 | var midPoint = getMidpoint$1(linestring.coordinates[i], linestring.coordinates[i + 1]);
|
18263 | if (booleanPointInPolygon({type: 'Point', coordinates: midPoint}, polygon, { ignoreBoundary: true })) {
|
18264 | output = true;
|
18265 | break;
|
18266 | }
|
18267 | }
|
18268 | return output;
|
18269 | }
|
18270 |
|
18271 |
|
18272 |
|
18273 |
|
18274 |
|
18275 |
|
18276 |
|
18277 |
|
18278 |
|
18279 |
|
18280 | function isPolyInPoly$2(feature1, feature2) {
|
18281 | var poly1Bbox = bbox(feature1);
|
18282 | var poly2Bbox = bbox(feature2);
|
18283 | if (!doBBoxOverlap$1(poly1Bbox, poly2Bbox)) {
|
18284 | return false;
|
18285 | }
|
18286 | for (var i = 0; i < feature2.coordinates[0].length; i++) {
|
18287 | if (!booleanPointInPolygon(feature2.coordinates[0][i], feature1)) {
|
18288 | return false;
|
18289 | }
|
18290 | }
|
18291 | return true;
|
18292 | }
|
18293 |
|
18294 | function doBBoxOverlap$1(bbox1, bbox2) {
|
18295 | if (bbox1[0] > bbox2[0]) return false;
|
18296 | if (bbox1[2] < bbox2[2]) return false;
|
18297 | if (bbox1[1] > bbox2[1]) return false;
|
18298 | if (bbox1[3] < bbox2[3]) return false;
|
18299 | return true;
|
18300 | }
|
18301 |
|
18302 |
|
18303 |
|
18304 |
|
18305 |
|
18306 |
|
18307 |
|
18308 |
|
18309 |
|
18310 | function compareCoords$2(pair1, pair2) {
|
18311 | return pair1[0] === pair2[0] && pair1[1] === pair2[1];
|
18312 | }
|
18313 |
|
18314 | function getMidpoint$1(pair1, pair2) {
|
18315 | return [(pair1[0] + pair2[0]) / 2, (pair1[1] + pair2[1]) / 2];
|
18316 | }
|
18317 |
|
18318 |
|
18319 |
|
18320 |
|
18321 |
|
18322 |
|
18323 |
|
18324 |
|
18325 |
|
18326 |
|
18327 |
|
18328 |
|
18329 |
|
18330 |
|
18331 |
|
18332 |
|
18333 |
|
18334 |
|
18335 |
|
18336 | function booleanCrosses(feature1, feature2) {
|
18337 | var type1 = getType(feature1);
|
18338 | var type2 = getType(feature2);
|
18339 | var geom1 = getGeom(feature1);
|
18340 | var geom2 = getGeom(feature2);
|
18341 |
|
18342 | switch (type1) {
|
18343 | case 'MultiPoint':
|
18344 | switch (type2) {
|
18345 | case 'LineString':
|
18346 | return doMultiPointAndLineStringCross(geom1, geom2);
|
18347 | case 'Polygon':
|
18348 | return doesMultiPointCrossPoly(geom1, geom2);
|
18349 | default:
|
18350 | throw new Error('feature2 ' + type2 + ' geometry not supported');
|
18351 | }
|
18352 | case 'LineString':
|
18353 | switch (type2) {
|
18354 | case 'MultiPoint':
|
18355 | return doMultiPointAndLineStringCross(geom2, geom1);
|
18356 | case 'LineString':
|
18357 | return doLineStringsCross(geom1, geom2);
|
18358 | case 'Polygon':
|
18359 | return doLineStringAndPolygonCross(geom1, geom2);
|
18360 | default:
|
18361 | throw new Error('feature2 ' + type2 + ' geometry not supported');
|
18362 | }
|
18363 | case 'Polygon':
|
18364 | switch (type2) {
|
18365 | case 'MultiPoint':
|
18366 | return doesMultiPointCrossPoly(geom2, geom1);
|
18367 | case 'LineString':
|
18368 | return doLineStringAndPolygonCross(geom2, geom1);
|
18369 | default:
|
18370 | throw new Error('feature2 ' + type2 + ' geometry not supported');
|
18371 | }
|
18372 | default:
|
18373 | throw new Error('feature1 ' + type1 + ' geometry not supported');
|
18374 | }
|
18375 | }
|
18376 |
|
18377 | function doMultiPointAndLineStringCross(multiPoint$$1, lineString$$1) {
|
18378 | var foundIntPoint = false;
|
18379 | var foundExtPoint = false;
|
18380 | var pointLength = multiPoint$$1.coordinates.length;
|
18381 | var i = 0;
|
18382 | while (i < pointLength && !foundIntPoint && !foundExtPoint) {
|
18383 | for (var i2 = 0; i2 < lineString$$1.coordinates.length - 1; i2++) {
|
18384 | var incEndVertices = true;
|
18385 | if (i2 === 0 || i2 === lineString$$1.coordinates.length - 2) {
|
18386 | incEndVertices = false;
|
18387 | }
|
18388 | if (isPointOnLineSegment$3(lineString$$1.coordinates[i2], lineString$$1.coordinates[i2 + 1], multiPoint$$1.coordinates[i], incEndVertices)) {
|
18389 | foundIntPoint = true;
|
18390 | } else {
|
18391 | foundExtPoint = true;
|
18392 | }
|
18393 | }
|
18394 | i++;
|
18395 | }
|
18396 | return foundIntPoint && foundExtPoint;
|
18397 | }
|
18398 |
|
18399 | function doLineStringsCross(lineString1, lineString2) {
|
18400 | var doLinesIntersect = lineIntersect(lineString1, lineString2);
|
18401 | if (doLinesIntersect.features.length > 0) {
|
18402 | for (var i = 0; i < lineString1.coordinates.length - 1; i++) {
|
18403 | for (var i2 = 0; i2 < lineString2.coordinates.length - 1; i2++) {
|
18404 | var incEndVertices = true;
|
18405 | if (i2 === 0 || i2 === lineString2.coordinates.length - 2) {
|
18406 | incEndVertices = false;
|
18407 | }
|
18408 | if (isPointOnLineSegment$3(lineString1.coordinates[i], lineString1.coordinates[i + 1], lineString2.coordinates[i2], incEndVertices)) {
|
18409 | return true;
|
18410 | }
|
18411 | }
|
18412 | }
|
18413 | }
|
18414 | return false;
|
18415 | }
|
18416 |
|
18417 | function doLineStringAndPolygonCross(lineString$$1, polygon$$1) {
|
18418 | var doLinesIntersect = lineIntersect(lineString$$1, polygonToLine(polygon$$1));
|
18419 | if (doLinesIntersect.features.length > 0) {
|
18420 | return true;
|
18421 | }
|
18422 | return false;
|
18423 | }
|
18424 |
|
18425 | function doesMultiPointCrossPoly(multiPoint$$1, polygon$$1) {
|
18426 | var foundIntPoint = false;
|
18427 | var foundExtPoint = false;
|
18428 | var pointLength = multiPoint$$1.coordinates[0].length;
|
18429 | var i = 0;
|
18430 | while (i < pointLength && foundIntPoint && foundExtPoint) {
|
18431 | if (booleanPointInPolygon(point(multiPoint$$1.coordinates[0][i]), polygon$$1)) {
|
18432 | foundIntPoint = true;
|
18433 | } else {
|
18434 | foundExtPoint = true;
|
18435 | }
|
18436 | i++;
|
18437 | }
|
18438 |
|
18439 | return foundExtPoint && foundExtPoint;
|
18440 | }
|
18441 |
|
18442 |
|
18443 |
|
18444 |
|
18445 |
|
18446 |
|
18447 |
|
18448 |
|
18449 |
|
18450 |
|
18451 |
|
18452 |
|
18453 |
|
18454 | function isPointOnLineSegment$3(lineSegmentStart, lineSegmentEnd, pt, incEnd) {
|
18455 | var dxc = pt[0] - lineSegmentStart[0];
|
18456 | var dyc = pt[1] - lineSegmentStart[1];
|
18457 | var dxl = lineSegmentEnd[0] - lineSegmentStart[0];
|
18458 | var dyl = lineSegmentEnd[1] - lineSegmentStart[1];
|
18459 | var cross = dxc * dyl - dyc * dxl;
|
18460 | if (cross !== 0) {
|
18461 | return false;
|
18462 | }
|
18463 | if (incEnd) {
|
18464 | if (Math.abs(dxl) >= Math.abs(dyl)) {
|
18465 | return dxl > 0 ? lineSegmentStart[0] <= pt[0] && pt[0] <= lineSegmentEnd[0] : lineSegmentEnd[0] <= pt[0] && pt[0] <= lineSegmentStart[0];
|
18466 | }
|
18467 | return dyl > 0 ? lineSegmentStart[1] <= pt[1] && pt[1] <= lineSegmentEnd[1] : lineSegmentEnd[1] <= pt[1] && pt[1] <= lineSegmentStart[1];
|
18468 | } else {
|
18469 | if (Math.abs(dxl) >= Math.abs(dyl)) {
|
18470 | return dxl > 0 ? lineSegmentStart[0] < pt[0] && pt[0] < lineSegmentEnd[0] : lineSegmentEnd[0] < pt[0] && pt[0] < lineSegmentStart[0];
|
18471 | }
|
18472 | return dyl > 0 ? lineSegmentStart[1] < pt[1] && pt[1] < lineSegmentEnd[1] : lineSegmentEnd[1] < pt[1] && pt[1] < lineSegmentStart[1];
|
18473 | }
|
18474 | }
|
18475 |
|
18476 | var keys = createCommonjsModule(function (module, exports) {
|
18477 | exports = module.exports = typeof Object.keys === 'function'
|
18478 | ? Object.keys : shim;
|
18479 |
|
18480 | exports.shim = shim;
|
18481 | function shim (obj) {
|
18482 | var keys = [];
|
18483 | for (var key in obj) keys.push(key);
|
18484 | return keys;
|
18485 | }
|
18486 | });
|
18487 |
|
18488 | var keys_1 = keys.shim;
|
18489 |
|
18490 | var is_arguments = createCommonjsModule(function (module, exports) {
|
18491 | var supportsArgumentsClass = (function(){
|
18492 | return Object.prototype.toString.call(arguments)
|
18493 | })() == '[object Arguments]';
|
18494 |
|
18495 | exports = module.exports = supportsArgumentsClass ? supported : unsupported;
|
18496 |
|
18497 | exports.supported = supported;
|
18498 | function supported(object) {
|
18499 | return Object.prototype.toString.call(object) == '[object Arguments]';
|
18500 | }
|
18501 |
|
18502 | exports.unsupported = unsupported;
|
18503 | function unsupported(object){
|
18504 | return object &&
|
18505 | typeof object == 'object' &&
|
18506 | typeof object.length == 'number' &&
|
18507 | Object.prototype.hasOwnProperty.call(object, 'callee') &&
|
18508 | !Object.prototype.propertyIsEnumerable.call(object, 'callee') ||
|
18509 | false;
|
18510 | }
|
18511 | });
|
18512 |
|
18513 | var is_arguments_1 = is_arguments.supported;
|
18514 | var is_arguments_2 = is_arguments.unsupported;
|
18515 |
|
18516 | var deepEqual_1 = createCommonjsModule(function (module) {
|
18517 | var pSlice = Array.prototype.slice;
|
18518 |
|
18519 |
|
18520 |
|
18521 | var deepEqual = module.exports = function (actual, expected, opts) {
|
18522 | if (!opts) opts = {};
|
18523 |
|
18524 | if (actual === expected) {
|
18525 | return true;
|
18526 |
|
18527 | } else if (actual instanceof Date && expected instanceof Date) {
|
18528 | return actual.getTime() === expected.getTime();
|
18529 |
|
18530 |
|
18531 |
|
18532 | } else if (!actual || !expected || typeof actual != 'object' && typeof expected != 'object') {
|
18533 | return opts.strict ? actual === expected : actual == expected;
|
18534 |
|
18535 |
|
18536 |
|
18537 |
|
18538 |
|
18539 |
|
18540 |
|
18541 | } else {
|
18542 | return objEquiv(actual, expected, opts);
|
18543 | }
|
18544 | };
|
18545 |
|
18546 | function isUndefinedOrNull(value) {
|
18547 | return value === null || value === undefined;
|
18548 | }
|
18549 |
|
18550 | function isBuffer (x) {
|
18551 | if (!x || typeof x !== 'object' || typeof x.length !== 'number') return false;
|
18552 | if (typeof x.copy !== 'function' || typeof x.slice !== 'function') {
|
18553 | return false;
|
18554 | }
|
18555 | if (x.length > 0 && typeof x[0] !== 'number') return false;
|
18556 | return true;
|
18557 | }
|
18558 |
|
18559 | function objEquiv(a, b, opts) {
|
18560 | var i, key;
|
18561 | if (isUndefinedOrNull(a) || isUndefinedOrNull(b))
|
18562 | return false;
|
18563 |
|
18564 | if (a.prototype !== b.prototype) return false;
|
18565 |
|
18566 |
|
18567 | if (is_arguments(a)) {
|
18568 | if (!is_arguments(b)) {
|
18569 | return false;
|
18570 | }
|
18571 | a = pSlice.call(a);
|
18572 | b = pSlice.call(b);
|
18573 | return deepEqual(a, b, opts);
|
18574 | }
|
18575 | if (isBuffer(a)) {
|
18576 | if (!isBuffer(b)) {
|
18577 | return false;
|
18578 | }
|
18579 | if (a.length !== b.length) return false;
|
18580 | for (i = 0; i < a.length; i++) {
|
18581 | if (a[i] !== b[i]) return false;
|
18582 | }
|
18583 | return true;
|
18584 | }
|
18585 | try {
|
18586 | var ka = keys(a),
|
18587 | kb = keys(b);
|
18588 | } catch (e) {
|
18589 | return false;
|
18590 | }
|
18591 |
|
18592 |
|
18593 | if (ka.length != kb.length)
|
18594 | return false;
|
18595 |
|
18596 | ka.sort();
|
18597 | kb.sort();
|
18598 |
|
18599 | for (i = ka.length - 1; i >= 0; i--) {
|
18600 | if (ka[i] != kb[i])
|
18601 | return false;
|
18602 | }
|
18603 |
|
18604 |
|
18605 | for (i = ka.length - 1; i >= 0; i--) {
|
18606 | key = ka[i];
|
18607 | if (!deepEqual(a[key], b[key], opts)) return false;
|
18608 | }
|
18609 | return typeof a === typeof b;
|
18610 | }
|
18611 | });
|
18612 |
|
18613 |
|
18614 |
|
18615 |
|
18616 | var Equality = function(opt) {
|
18617 | this.precision = opt && opt.precision ? opt.precision : 17;
|
18618 | this.direction = opt && opt.direction ? opt.direction : false;
|
18619 | this.pseudoNode = opt && opt.pseudoNode ? opt.pseudoNode : false;
|
18620 | this.objectComparator = opt && opt.objectComparator ? opt.objectComparator : objectComparator;
|
18621 | };
|
18622 |
|
18623 | Equality.prototype.compare = function(g1,g2) {
|
18624 | if (g1.type !== g2.type || !sameLength(g1,g2)) return false;
|
18625 |
|
18626 | switch(g1.type) {
|
18627 | case 'Point':
|
18628 | return this.compareCoord(g1.coordinates, g2.coordinates);
|
18629 | break;
|
18630 | case 'LineString':
|
18631 | return this.compareLine(g1.coordinates, g2.coordinates,0,false);
|
18632 | break;
|
18633 | case 'Polygon':
|
18634 | return this.comparePolygon(g1,g2);
|
18635 | break;
|
18636 | case 'Feature':
|
18637 | return this.compareFeature(g1, g2);
|
18638 | default:
|
18639 | if (g1.type.indexOf('Multi') === 0) {
|
18640 | var context = this;
|
18641 | var g1s = explode$2(g1);
|
18642 | var g2s = explode$2(g2);
|
18643 | return g1s.every(function(g1part) {
|
18644 | return this.some(function(g2part) {
|
18645 | return context.compare(g1part,g2part);
|
18646 | });
|
18647 | },g2s);
|
18648 | }
|
18649 | }
|
18650 | return false;
|
18651 | };
|
18652 |
|
18653 | function explode$2(g) {
|
18654 | return g.coordinates.map(function(part) {
|
18655 | return {
|
18656 | type: g.type.replace('Multi', ''),
|
18657 | coordinates: part}
|
18658 | });
|
18659 | }
|
18660 |
|
18661 | function sameLength(g1,g2) {
|
18662 | return g1.hasOwnProperty('coordinates') ?
|
18663 | g1.coordinates.length === g2.coordinates.length
|
18664 | : g1.length === g2.length;
|
18665 | }
|
18666 |
|
18667 |
|
18668 | Equality.prototype.compareCoord = function(c1,c2) {
|
18669 | if (c1.length !== c2.length) {
|
18670 | return false;
|
18671 | }
|
18672 |
|
18673 | for (var i=0; i < c1.length; i++) {
|
18674 | if (c1[i].toFixed(this.precision) !== c2[i].toFixed(this.precision)) {
|
18675 | return false;
|
18676 | }
|
18677 | }
|
18678 | return true;
|
18679 | };
|
18680 |
|
18681 | Equality.prototype.compareLine = function(path1,path2,ind,isPoly) {
|
18682 | if (!sameLength(path1,path2)) return false;
|
18683 | var p1 = this.pseudoNode ? path1 : this.removePseudo(path1);
|
18684 | var p2 = this.pseudoNode ? path2 : this.removePseudo(path2);
|
18685 | if (isPoly && !this.compareCoord(p1[0],p2[0])) {
|
18686 |
|
18687 | p2 = this.fixStartIndex(p2,p1);
|
18688 | if(!p2) return;
|
18689 | }
|
18690 |
|
18691 | var sameDirection = this.compareCoord(p1[ind],p2[ind]);
|
18692 | if (this.direction || sameDirection
|
18693 | ) {
|
18694 | return this.comparePath(p1, p2);
|
18695 | } else {
|
18696 | if (this.compareCoord(p1[ind],p2[p2.length - (1+ind)])
|
18697 | ) {
|
18698 | return this.comparePath(p1.slice().reverse(), p2);
|
18699 | }
|
18700 | return false;
|
18701 | }
|
18702 | };
|
18703 | Equality.prototype.fixStartIndex = function(sourcePath,targetPath) {
|
18704 |
|
18705 | var correctPath,ind = -1;
|
18706 | for (var i=0; i< sourcePath.length; i++) {
|
18707 | if(this.compareCoord(sourcePath[i],targetPath[0])) {
|
18708 | ind = i;
|
18709 | break;
|
18710 | }
|
18711 | }
|
18712 | if (ind >= 0) {
|
18713 | correctPath = [].concat(
|
18714 | sourcePath.slice(ind,sourcePath.length),
|
18715 | sourcePath.slice(1,ind+1));
|
18716 | }
|
18717 | return correctPath;
|
18718 | };
|
18719 | Equality.prototype.comparePath = function (p1,p2) {
|
18720 | var cont = this;
|
18721 | return p1.every(function(c,i) {
|
18722 | return cont.compareCoord(c,this[i]);
|
18723 | },p2);
|
18724 | };
|
18725 |
|
18726 | Equality.prototype.comparePolygon = function(g1,g2) {
|
18727 | if (this.compareLine(g1.coordinates[0],g2.coordinates[0],1,true)) {
|
18728 | var holes1 = g1.coordinates.slice(1,g1.coordinates.length);
|
18729 | var holes2 = g2.coordinates.slice(1,g2.coordinates.length);
|
18730 | var cont = this;
|
18731 | return holes1.every(function(h1) {
|
18732 | return this.some(function(h2) {
|
18733 | return cont.compareLine(h1,h2,1,true);
|
18734 | });
|
18735 | },holes2);
|
18736 | } else {
|
18737 | return false;
|
18738 | }
|
18739 | };
|
18740 |
|
18741 | Equality.prototype.compareFeature = function(g1,g2) {
|
18742 | if (
|
18743 | g1.id !== g2.id ||
|
18744 | !this.objectComparator(g1.properties, g2.properties) ||
|
18745 | !this.compareBBox(g1,g2)
|
18746 | ) {
|
18747 | return false;
|
18748 | }
|
18749 | return this.compare(g1.geometry, g2.geometry);
|
18750 | };
|
18751 |
|
18752 | Equality.prototype.compareBBox = function(g1,g2) {
|
18753 | if (
|
18754 | (!g1.bbox && !g2.bbox) ||
|
18755 | (
|
18756 | g1.bbox && g2.bbox &&
|
18757 | this.compareCoord(g1.bbox, g2.bbox)
|
18758 | )
|
18759 | ) {
|
18760 | return true;
|
18761 | }
|
18762 | return false;
|
18763 | };
|
18764 | Equality.prototype.removePseudo = function(path) {
|
18765 |
|
18766 | return path;
|
18767 | };
|
18768 |
|
18769 | function objectComparator(obj1, obj2) {
|
18770 | return deepEqual_1(obj1, obj2, {strict: true});
|
18771 | }
|
18772 |
|
18773 | var geojsonEquality = Equality;
|
18774 |
|
18775 |
|
18776 |
|
18777 |
|
18778 |
|
18779 |
|
18780 |
|
18781 |
|
18782 |
|
18783 |
|
18784 |
|
18785 |
|
18786 |
|
18787 |
|
18788 |
|
18789 |
|
18790 |
|
18791 |
|
18792 |
|
18793 |
|
18794 | function booleanOverlap(feature1, feature2) {
|
18795 |
|
18796 | if (!feature1) throw new Error('feature1 is required');
|
18797 | if (!feature2) throw new Error('feature2 is required');
|
18798 | var type1 = getType(feature1);
|
18799 | var type2 = getType(feature2);
|
18800 | if (type1 !== type2) throw new Error('features must be of the same type');
|
18801 | if (type1 === 'Point') throw new Error('Point geometry not supported');
|
18802 |
|
18803 |
|
18804 | var equality = new geojsonEquality({precision: 6});
|
18805 | if (equality.compare(feature1, feature2)) return false;
|
18806 |
|
18807 | var overlap = 0;
|
18808 |
|
18809 | switch (type1) {
|
18810 | case 'MultiPoint':
|
18811 | var coords1 = coordAll(feature1);
|
18812 | var coords2 = coordAll(feature2);
|
18813 | coords1.forEach(function (coord1) {
|
18814 | coords2.forEach(function (coord2) {
|
18815 | if (coord1[0] === coord2[0] && coord1[1] === coord2[1]) overlap++;
|
18816 | });
|
18817 | });
|
18818 | break;
|
18819 |
|
18820 | case 'LineString':
|
18821 | case 'MultiLineString':
|
18822 | segmentEach(feature1, function (segment1) {
|
18823 | segmentEach(feature2, function (segment2) {
|
18824 | if (lineOverlap(segment1, segment2).features.length) overlap++;
|
18825 | });
|
18826 | });
|
18827 | break;
|
18828 |
|
18829 | case 'Polygon':
|
18830 | case 'MultiPolygon':
|
18831 | segmentEach(feature1, function (segment1) {
|
18832 | segmentEach(feature2, function (segment2) {
|
18833 | if (lineIntersect(segment1, segment2).features.length) overlap++;
|
18834 | });
|
18835 | });
|
18836 | break;
|
18837 | }
|
18838 |
|
18839 | return overlap > 0;
|
18840 | }
|
18841 |
|
18842 |
|
18843 |
|
18844 |
|
18845 |
|
18846 |
|
18847 |
|
18848 |
|
18849 |
|
18850 |
|
18851 |
|
18852 |
|
18853 |
|
18854 |
|
18855 |
|
18856 |
|
18857 |
|
18858 |
|
18859 |
|
18860 | function booleanEqual(feature1, feature2) {
|
18861 |
|
18862 | if (!feature1) throw new Error('feature1 is required');
|
18863 | if (!feature2) throw new Error('feature2 is required');
|
18864 | var type1 = getType(feature1);
|
18865 | var type2 = getType(feature2);
|
18866 | if (type1 !== type2) return false;
|
18867 |
|
18868 | var equality = new geojsonEquality({precision: 6});
|
18869 | return equality.compare(cleanCoords(feature1), cleanCoords(feature2));
|
18870 | }
|
18871 |
|
18872 | var DBSCAN_1 = createCommonjsModule(function (module) {
|
18873 |
|
18874 |
|
18875 |
|
18876 |
|
18877 |
|
18878 |
|
18879 |
|
18880 |
|
18881 |
|
18882 |
|
18883 |
|
18884 |
|
18885 |
|
18886 |
|
18887 |
|
18888 |
|
18889 |
|
18890 | function DBSCAN(dataset, epsilon, minPts, distanceFunction) {
|
18891 |
|
18892 | this.dataset = [];
|
18893 |
|
18894 | this.epsilon = 1;
|
18895 |
|
18896 | this.minPts = 2;
|
18897 |
|
18898 | this.distance = this._euclideanDistance;
|
18899 |
|
18900 | this.clusters = [];
|
18901 |
|
18902 | this.noise = [];
|
18903 |
|
18904 |
|
18905 |
|
18906 |
|
18907 | this._visited = [];
|
18908 |
|
18909 | this._assigned = [];
|
18910 |
|
18911 | this._datasetLength = 0;
|
18912 |
|
18913 | this._init(dataset, epsilon, minPts, distanceFunction);
|
18914 | }
|
18915 |
|
18916 |
|
18917 |
|
18918 |
|
18919 |
|
18920 |
|
18921 |
|
18922 |
|
18923 |
|
18924 |
|
18925 |
|
18926 |
|
18927 |
|
18928 |
|
18929 | DBSCAN.prototype.run = function(dataset, epsilon, minPts, distanceFunction) {
|
18930 | this._init(dataset, epsilon, minPts, distanceFunction);
|
18931 |
|
18932 | for (var pointId = 0; pointId < this._datasetLength; pointId++) {
|
18933 |
|
18934 | if (this._visited[pointId] !== 1) {
|
18935 | this._visited[pointId] = 1;
|
18936 |
|
18937 |
|
18938 | var neighbors = this._regionQuery(pointId);
|
18939 |
|
18940 | if (neighbors.length < this.minPts) {
|
18941 | this.noise.push(pointId);
|
18942 | } else {
|
18943 |
|
18944 | var clusterId = this.clusters.length;
|
18945 | this.clusters.push([]);
|
18946 | this._addToCluster(pointId, clusterId);
|
18947 |
|
18948 | this._expandCluster(clusterId, neighbors);
|
18949 | }
|
18950 | }
|
18951 | }
|
18952 |
|
18953 | return this.clusters;
|
18954 | };
|
18955 |
|
18956 |
|
18957 |
|
18958 |
|
18959 |
|
18960 |
|
18961 |
|
18962 |
|
18963 |
|
18964 |
|
18965 |
|
18966 |
|
18967 |
|
18968 |
|
18969 | DBSCAN.prototype._init = function(dataset, epsilon, minPts, distance) {
|
18970 |
|
18971 | if (dataset) {
|
18972 |
|
18973 | if (!(dataset instanceof Array)) {
|
18974 | throw Error('Dataset must be of type array, ' +
|
18975 | typeof dataset + ' given');
|
18976 | }
|
18977 |
|
18978 | this.dataset = dataset;
|
18979 | this.clusters = [];
|
18980 | this.noise = [];
|
18981 |
|
18982 | this._datasetLength = dataset.length;
|
18983 | this._visited = new Array(this._datasetLength);
|
18984 | this._assigned = new Array(this._datasetLength);
|
18985 | }
|
18986 |
|
18987 | if (epsilon) {
|
18988 | this.epsilon = epsilon;
|
18989 | }
|
18990 |
|
18991 | if (minPts) {
|
18992 | this.minPts = minPts;
|
18993 | }
|
18994 |
|
18995 | if (distance) {
|
18996 | this.distance = distance;
|
18997 | }
|
18998 | };
|
18999 |
|
19000 |
|
19001 |
|
19002 |
|
19003 |
|
19004 |
|
19005 |
|
19006 |
|
19007 |
|
19008 | DBSCAN.prototype._expandCluster = function(clusterId, neighbors) {
|
19009 |
|
19010 | |
19011 |
|
19012 |
|
19013 |
|
19014 | for (var i = 0; i < neighbors.length; i++) {
|
19015 | var pointId2 = neighbors[i];
|
19016 |
|
19017 | if (this._visited[pointId2] !== 1) {
|
19018 | this._visited[pointId2] = 1;
|
19019 | var neighbors2 = this._regionQuery(pointId2);
|
19020 |
|
19021 | if (neighbors2.length >= this.minPts) {
|
19022 | neighbors = this._mergeArrays(neighbors, neighbors2);
|
19023 | }
|
19024 | }
|
19025 |
|
19026 |
|
19027 | if (this._assigned[pointId2] !== 1) {
|
19028 | this._addToCluster(pointId2, clusterId);
|
19029 | }
|
19030 | }
|
19031 | };
|
19032 |
|
19033 |
|
19034 |
|
19035 |
|
19036 |
|
19037 |
|
19038 |
|
19039 | DBSCAN.prototype._addToCluster = function(pointId, clusterId) {
|
19040 | this.clusters[clusterId].push(pointId);
|
19041 | this._assigned[pointId] = 1;
|
19042 | };
|
19043 |
|
19044 |
|
19045 |
|
19046 |
|
19047 |
|
19048 |
|
19049 |
|
19050 |
|
19051 |
|
19052 | DBSCAN.prototype._regionQuery = function(pointId) {
|
19053 | var neighbors = [];
|
19054 |
|
19055 | for (var id = 0; id < this._datasetLength; id++) {
|
19056 | var dist = this.distance(this.dataset[pointId], this.dataset[id]);
|
19057 | if (dist < this.epsilon) {
|
19058 | neighbors.push(id);
|
19059 | }
|
19060 | }
|
19061 |
|
19062 | return neighbors;
|
19063 | };
|
19064 |
|
19065 |
|
19066 |
|
19067 |
|
19068 |
|
19069 |
|
19070 |
|
19071 |
|
19072 |
|
19073 |
|
19074 | DBSCAN.prototype._mergeArrays = function(a, b) {
|
19075 | var len = b.length;
|
19076 |
|
19077 | for (var i = 0; i < len; i++) {
|
19078 | var P = b[i];
|
19079 | if (a.indexOf(P) < 0) {
|
19080 | a.push(P);
|
19081 | }
|
19082 | }
|
19083 |
|
19084 | return a;
|
19085 | };
|
19086 |
|
19087 |
|
19088 |
|
19089 |
|
19090 |
|
19091 |
|
19092 |
|
19093 |
|
19094 |
|
19095 | DBSCAN.prototype._euclideanDistance = function(p, q) {
|
19096 | var sum = 0;
|
19097 | var i = Math.min(p.length, q.length);
|
19098 |
|
19099 | while (i--) {
|
19100 | sum += (p[i] - q[i]) * (p[i] - q[i]);
|
19101 | }
|
19102 |
|
19103 | return Math.sqrt(sum);
|
19104 | };
|
19105 |
|
19106 | if ('object' !== 'undefined' && module.exports) {
|
19107 | module.exports = DBSCAN;
|
19108 | }
|
19109 | });
|
19110 |
|
19111 | var KMEANS_1 = createCommonjsModule(function (module) {
|
19112 |
|
19113 |
|
19114 |
|
19115 |
|
19116 |
|
19117 |
|
19118 |
|
19119 |
|
19120 |
|
19121 |
|
19122 |
|
19123 |
|
19124 |
|
19125 |
|
19126 |
|
19127 |
|
19128 | function KMEANS(dataset, k, distance) {
|
19129 | this.k = 3;
|
19130 | this.dataset = [];
|
19131 | this.assignments = [];
|
19132 | this.centroids = [];
|
19133 |
|
19134 | this.init(dataset, k, distance);
|
19135 | }
|
19136 |
|
19137 |
|
19138 |
|
19139 |
|
19140 | KMEANS.prototype.init = function(dataset, k, distance) {
|
19141 | this.assignments = [];
|
19142 | this.centroids = [];
|
19143 |
|
19144 | if (typeof dataset !== 'undefined') {
|
19145 | this.dataset = dataset;
|
19146 | }
|
19147 |
|
19148 | if (typeof k !== 'undefined') {
|
19149 | this.k = k;
|
19150 | }
|
19151 |
|
19152 | if (typeof distance !== 'undefined') {
|
19153 | this.distance = distance;
|
19154 | }
|
19155 | };
|
19156 |
|
19157 |
|
19158 |
|
19159 |
|
19160 | KMEANS.prototype.run = function(dataset, k) {
|
19161 | this.init(dataset, k);
|
19162 |
|
19163 | var len = this.dataset.length;
|
19164 |
|
19165 |
|
19166 | for (var i = 0; i < this.k; i++) {
|
19167 | this.centroids[i] = this.randomCentroid();
|
19168 | }
|
19169 |
|
19170 | var change = true;
|
19171 | while(change) {
|
19172 |
|
19173 |
|
19174 | change = this.assign();
|
19175 |
|
19176 |
|
19177 | for (var centroidId = 0; centroidId < this.k; centroidId++) {
|
19178 | var mean = new Array(maxDim);
|
19179 | var count = 0;
|
19180 |
|
19181 |
|
19182 | for (var dim = 0; dim < maxDim; dim++) {
|
19183 | mean[dim] = 0;
|
19184 | }
|
19185 |
|
19186 | for (var j = 0; j < len; j++) {
|
19187 | var maxDim = this.dataset[j].length;
|
19188 |
|
19189 |
|
19190 | if (centroidId === this.assignments[j]) {
|
19191 | for (var dim = 0; dim < maxDim; dim++) {
|
19192 | mean[dim] += this.dataset[j][dim];
|
19193 | }
|
19194 | count++;
|
19195 | }
|
19196 | }
|
19197 |
|
19198 | if (count > 0) {
|
19199 |
|
19200 | for (var dim = 0; dim < maxDim; dim++) {
|
19201 | mean[dim] /= count;
|
19202 | }
|
19203 | this.centroids[centroidId] = mean;
|
19204 | } else {
|
19205 |
|
19206 | this.centroids[centroidId] = this.randomCentroid();
|
19207 | change = true;
|
19208 | }
|
19209 | }
|
19210 | }
|
19211 |
|
19212 | return this.getClusters();
|
19213 | };
|
19214 |
|
19215 |
|
19216 |
|
19217 |
|
19218 |
|
19219 |
|
19220 | KMEANS.prototype.randomCentroid = function() {
|
19221 | var maxId = this.dataset.length -1;
|
19222 | var centroid;
|
19223 | var id;
|
19224 |
|
19225 | do {
|
19226 | id = Math.round(Math.random() * maxId);
|
19227 | centroid = this.dataset[id];
|
19228 | } while (this.centroids.indexOf(centroid) >= 0);
|
19229 |
|
19230 | return centroid;
|
19231 | };
|
19232 |
|
19233 |
|
19234 |
|
19235 |
|
19236 |
|
19237 |
|
19238 | KMEANS.prototype.assign = function() {
|
19239 | var change = false;
|
19240 | var len = this.dataset.length;
|
19241 | var closestCentroid;
|
19242 |
|
19243 | for (var i = 0; i < len; i++) {
|
19244 | closestCentroid = this.argmin(this.dataset[i], this.centroids, this.distance);
|
19245 |
|
19246 | if (closestCentroid != this.assignments[i]) {
|
19247 | this.assignments[i] = closestCentroid;
|
19248 | change = true;
|
19249 | }
|
19250 | }
|
19251 |
|
19252 | return change;
|
19253 | };
|
19254 |
|
19255 |
|
19256 |
|
19257 |
|
19258 |
|
19259 |
|
19260 | KMEANS.prototype.getClusters = function() {
|
19261 | var clusters = new Array(this.k);
|
19262 | var centroidId;
|
19263 |
|
19264 | for (var pointId = 0; pointId < this.assignments.length; pointId++) {
|
19265 | centroidId = this.assignments[pointId];
|
19266 |
|
19267 |
|
19268 | if (typeof clusters[centroidId] === 'undefined') {
|
19269 | clusters[centroidId] = [];
|
19270 | }
|
19271 |
|
19272 | clusters[centroidId].push(pointId);
|
19273 | }
|
19274 |
|
19275 | return clusters;
|
19276 | };
|
19277 |
|
19278 |
|
19279 |
|
19280 |
|
19281 |
|
19282 |
|
19283 |
|
19284 |
|
19285 |
|
19286 | KMEANS.prototype.argmin = function(point, set, f) {
|
19287 | var min = Number.MAX_VALUE;
|
19288 | var arg = 0;
|
19289 | var len = set.length;
|
19290 | var d;
|
19291 |
|
19292 | for (var i = 0; i < len; i++) {
|
19293 | d = f(point, set[i]);
|
19294 | if (d < min) {
|
19295 | min = d;
|
19296 | arg = i;
|
19297 | }
|
19298 | }
|
19299 |
|
19300 | return arg;
|
19301 | };
|
19302 |
|
19303 |
|
19304 |
|
19305 |
|
19306 |
|
19307 |
|
19308 |
|
19309 |
|
19310 | KMEANS.prototype.distance = function(p, q) {
|
19311 | var sum = 0;
|
19312 | var i = Math.min(p.length, q.length);
|
19313 |
|
19314 | while (i--) {
|
19315 | var diff = p[i] - q[i];
|
19316 | sum += diff * diff;
|
19317 | }
|
19318 |
|
19319 | return Math.sqrt(sum);
|
19320 | };
|
19321 |
|
19322 | if ('object' !== 'undefined' && module.exports) {
|
19323 | module.exports = KMEANS;
|
19324 | }
|
19325 | });
|
19326 |
|
19327 | var PriorityQueue_1 = createCommonjsModule(function (module) {
|
19328 |
|
19329 |
|
19330 |
|
19331 |
|
19332 |
|
19333 |
|
19334 |
|
19335 |
|
19336 |
|
19337 |
|
19338 |
|
19339 |
|
19340 |
|
19341 |
|
19342 |
|
19343 |
|
19344 |
|
19345 |
|
19346 |
|
19347 |
|
19348 |
|
19349 |
|
19350 | function PriorityQueue(elements, priorities, sorting) {
|
19351 |
|
19352 | this._queue = [];
|
19353 |
|
19354 | this._priorities = [];
|
19355 |
|
19356 | this._sorting = 'desc';
|
19357 |
|
19358 | this._init(elements, priorities, sorting);
|
19359 | }
|
19360 |
|
19361 |
|
19362 |
|
19363 |
|
19364 |
|
19365 |
|
19366 |
|
19367 |
|
19368 |
|
19369 | PriorityQueue.prototype.insert = function(ele, priority) {
|
19370 | var indexToInsert = this._queue.length;
|
19371 | var index = indexToInsert;
|
19372 |
|
19373 | while (index--) {
|
19374 | var priority2 = this._priorities[index];
|
19375 | if (this._sorting === 'desc') {
|
19376 | if (priority > priority2) {
|
19377 | indexToInsert = index;
|
19378 | }
|
19379 | } else {
|
19380 | if (priority < priority2) {
|
19381 | indexToInsert = index;
|
19382 | }
|
19383 | }
|
19384 | }
|
19385 |
|
19386 | this._insertAt(ele, priority, indexToInsert);
|
19387 | };
|
19388 |
|
19389 |
|
19390 |
|
19391 |
|
19392 |
|
19393 |
|
19394 |
|
19395 |
|
19396 | PriorityQueue.prototype.remove = function(ele) {
|
19397 | var index = this._queue.length;
|
19398 |
|
19399 | while (index--) {
|
19400 | var ele2 = this._queue[index];
|
19401 | if (ele === ele2) {
|
19402 | this._queue.splice(index, 1);
|
19403 | this._priorities.splice(index, 1);
|
19404 | break;
|
19405 | }
|
19406 | }
|
19407 | };
|
19408 |
|
19409 |
|
19410 |
|
19411 |
|
19412 |
|
19413 |
|
19414 |
|
19415 |
|
19416 | PriorityQueue.prototype.forEach = function(func) {
|
19417 | this._queue.forEach(func);
|
19418 | };
|
19419 |
|
19420 |
|
19421 |
|
19422 |
|
19423 |
|
19424 | PriorityQueue.prototype.getElements = function() {
|
19425 | return this._queue;
|
19426 | };
|
19427 |
|
19428 |
|
19429 |
|
19430 |
|
19431 |
|
19432 |
|
19433 | PriorityQueue.prototype.getElementPriority = function(index) {
|
19434 | return this._priorities[index];
|
19435 | };
|
19436 |
|
19437 |
|
19438 |
|
19439 |
|
19440 |
|
19441 | PriorityQueue.prototype.getPriorities = function() {
|
19442 | return this._priorities;
|
19443 | };
|
19444 |
|
19445 |
|
19446 |
|
19447 |
|
19448 |
|
19449 | PriorityQueue.prototype.getElementsWithPriorities = function() {
|
19450 | var result = [];
|
19451 |
|
19452 | for (var i = 0, l = this._queue.length; i < l; i++) {
|
19453 | result.push([this._queue[i], this._priorities[i]]);
|
19454 | }
|
19455 |
|
19456 | return result;
|
19457 | };
|
19458 |
|
19459 |
|
19460 |
|
19461 |
|
19462 |
|
19463 |
|
19464 |
|
19465 |
|
19466 |
|
19467 | PriorityQueue.prototype._init = function(elements, priorities, sorting) {
|
19468 |
|
19469 | if (elements && priorities) {
|
19470 | this._queue = [];
|
19471 | this._priorities = [];
|
19472 |
|
19473 | if (elements.length !== priorities.length) {
|
19474 | throw new Error('Arrays must have the same length');
|
19475 | }
|
19476 |
|
19477 | for (var i = 0; i < elements.length; i++) {
|
19478 | this.insert(elements[i], priorities[i]);
|
19479 | }
|
19480 | }
|
19481 |
|
19482 | if (sorting) {
|
19483 | this._sorting = sorting;
|
19484 | }
|
19485 | };
|
19486 |
|
19487 |
|
19488 |
|
19489 |
|
19490 |
|
19491 |
|
19492 |
|
19493 |
|
19494 |
|
19495 | PriorityQueue.prototype._insertAt = function(ele, priority, index) {
|
19496 | if (this._queue.length === index) {
|
19497 | this._queue.push(ele);
|
19498 | this._priorities.push(priority);
|
19499 | } else {
|
19500 | this._queue.splice(index, 0, ele);
|
19501 | this._priorities.splice(index, 0, priority);
|
19502 | }
|
19503 | };
|
19504 |
|
19505 | if ('object' !== 'undefined' && module.exports) {
|
19506 | module.exports = PriorityQueue;
|
19507 | }
|
19508 | });
|
19509 |
|
19510 | var OPTICS_1 = createCommonjsModule(function (module) {
|
19511 |
|
19512 |
|
19513 |
|
19514 |
|
19515 | if ('object' !== 'undefined' && module.exports) {
|
19516 | var PriorityQueue = PriorityQueue_1;
|
19517 | }
|
19518 |
|
19519 |
|
19520 |
|
19521 |
|
19522 |
|
19523 |
|
19524 |
|
19525 |
|
19526 |
|
19527 |
|
19528 |
|
19529 |
|
19530 |
|
19531 |
|
19532 |
|
19533 |
|
19534 |
|
19535 |
|
19536 | function OPTICS(dataset, epsilon, minPts, distanceFunction) {
|
19537 |
|
19538 | this.epsilon = 1;
|
19539 |
|
19540 | this.minPts = 1;
|
19541 |
|
19542 | this.distance = this._euclideanDistance;
|
19543 |
|
19544 |
|
19545 |
|
19546 |
|
19547 | this._reachability = [];
|
19548 |
|
19549 | this._processed = [];
|
19550 |
|
19551 | this._coreDistance = 0;
|
19552 |
|
19553 | this._orderedList = [];
|
19554 |
|
19555 | this._init(dataset, epsilon, minPts, distanceFunction);
|
19556 | }
|
19557 |
|
19558 |
|
19559 |
|
19560 |
|
19561 |
|
19562 |
|
19563 |
|
19564 |
|
19565 |
|
19566 |
|
19567 |
|
19568 | OPTICS.prototype.run = function(dataset, epsilon, minPts, distanceFunction) {
|
19569 | this._init(dataset, epsilon, minPts, distanceFunction);
|
19570 |
|
19571 | for (var pointId = 0, l = this.dataset.length; pointId < l; pointId++) {
|
19572 | if (this._processed[pointId] !== 1) {
|
19573 | this._processed[pointId] = 1;
|
19574 | this.clusters.push([pointId]);
|
19575 | var clusterId = this.clusters.length - 1;
|
19576 |
|
19577 | this._orderedList.push(pointId);
|
19578 | var priorityQueue = new PriorityQueue(null, null, 'asc');
|
19579 | var neighbors = this._regionQuery(pointId);
|
19580 |
|
19581 |
|
19582 | if (this._distanceToCore(pointId) !== undefined) {
|
19583 | this._updateQueue(pointId, neighbors, priorityQueue);
|
19584 | this._expandCluster(clusterId, priorityQueue);
|
19585 | }
|
19586 | }
|
19587 | }
|
19588 |
|
19589 | return this.clusters;
|
19590 | };
|
19591 |
|
19592 |
|
19593 |
|
19594 |
|
19595 |
|
19596 |
|
19597 |
|
19598 | OPTICS.prototype.getReachabilityPlot = function() {
|
19599 | var reachabilityPlot = [];
|
19600 |
|
19601 | for (var i = 0, l = this._orderedList.length; i < l; i++) {
|
19602 | var pointId = this._orderedList[i];
|
19603 | var distance = this._reachability[pointId];
|
19604 |
|
19605 | reachabilityPlot.push([pointId, distance]);
|
19606 | }
|
19607 |
|
19608 | return reachabilityPlot;
|
19609 | };
|
19610 |
|
19611 |
|
19612 |
|
19613 |
|
19614 |
|
19615 |
|
19616 |
|
19617 |
|
19618 |
|
19619 |
|
19620 |
|
19621 |
|
19622 |
|
19623 |
|
19624 | OPTICS.prototype._init = function(dataset, epsilon, minPts, distance) {
|
19625 |
|
19626 | if (dataset) {
|
19627 |
|
19628 | if (!(dataset instanceof Array)) {
|
19629 | throw Error('Dataset must be of type array, ' +
|
19630 | typeof dataset + ' given');
|
19631 | }
|
19632 |
|
19633 | this.dataset = dataset;
|
19634 | this.clusters = [];
|
19635 | this._reachability = new Array(this.dataset.length);
|
19636 | this._processed = new Array(this.dataset.length);
|
19637 | this._coreDistance = 0;
|
19638 | this._orderedList = [];
|
19639 | }
|
19640 |
|
19641 | if (epsilon) {
|
19642 | this.epsilon = epsilon;
|
19643 | }
|
19644 |
|
19645 | if (minPts) {
|
19646 | this.minPts = minPts;
|
19647 | }
|
19648 |
|
19649 | if (distance) {
|
19650 | this.distance = distance;
|
19651 | }
|
19652 | };
|
19653 |
|
19654 |
|
19655 |
|
19656 |
|
19657 |
|
19658 |
|
19659 |
|
19660 |
|
19661 |
|
19662 |
|
19663 | OPTICS.prototype._updateQueue = function(pointId, neighbors, queue) {
|
19664 | var self = this;
|
19665 |
|
19666 | this._coreDistance = this._distanceToCore(pointId);
|
19667 | neighbors.forEach(function(pointId2) {
|
19668 | if (self._processed[pointId2] === undefined) {
|
19669 | var dist = self.distance(self.dataset[pointId], self.dataset[pointId2]);
|
19670 | var newReachableDistance = Math.max(self._coreDistance, dist);
|
19671 |
|
19672 | if (self._reachability[pointId2] === undefined) {
|
19673 | self._reachability[pointId2] = newReachableDistance;
|
19674 | queue.insert(pointId2, newReachableDistance);
|
19675 | } else {
|
19676 | if (newReachableDistance < self._reachability[pointId2]) {
|
19677 | self._reachability[pointId2] = newReachableDistance;
|
19678 | queue.remove(pointId2);
|
19679 | queue.insert(pointId2, newReachableDistance);
|
19680 | }
|
19681 | }
|
19682 | }
|
19683 | });
|
19684 | };
|
19685 |
|
19686 |
|
19687 |
|
19688 |
|
19689 |
|
19690 |
|
19691 |
|
19692 |
|
19693 |
|
19694 | OPTICS.prototype._expandCluster = function(clusterId, queue) {
|
19695 | var queueElements = queue.getElements();
|
19696 |
|
19697 | for (var p = 0, l = queueElements.length; p < l; p++) {
|
19698 | var pointId = queueElements[p];
|
19699 | if (this._processed[pointId] === undefined) {
|
19700 | var neighbors = this._regionQuery(pointId);
|
19701 | this._processed[pointId] = 1;
|
19702 |
|
19703 | this.clusters[clusterId].push(pointId);
|
19704 | this._orderedList.push(pointId);
|
19705 |
|
19706 | if (this._distanceToCore(pointId) !== undefined) {
|
19707 | this._updateQueue(pointId, neighbors, queue);
|
19708 | this._expandCluster(clusterId, queue);
|
19709 | }
|
19710 | }
|
19711 | }
|
19712 | };
|
19713 |
|
19714 |
|
19715 |
|
19716 |
|
19717 |
|
19718 |
|
19719 |
|
19720 |
|
19721 | OPTICS.prototype._distanceToCore = function(pointId) {
|
19722 | var l = this.epsilon;
|
19723 | for (var coreDistCand = 0; coreDistCand < l; coreDistCand++) {
|
19724 | var neighbors = this._regionQuery(pointId, coreDistCand);
|
19725 | if (neighbors.length >= this.minPts) {
|
19726 | return coreDistCand;
|
19727 | }
|
19728 | }
|
19729 |
|
19730 | return;
|
19731 | };
|
19732 |
|
19733 |
|
19734 |
|
19735 |
|
19736 |
|
19737 |
|
19738 |
|
19739 |
|
19740 |
|
19741 | OPTICS.prototype._regionQuery = function(pointId, epsilon) {
|
19742 | epsilon = epsilon || this.epsilon;
|
19743 | var neighbors = [];
|
19744 |
|
19745 | for (var id = 0, l = this.dataset.length; id < l; id++) {
|
19746 | if (this.distance(this.dataset[pointId], this.dataset[id]) < epsilon) {
|
19747 | neighbors.push(id);
|
19748 | }
|
19749 | }
|
19750 |
|
19751 | return neighbors;
|
19752 | };
|
19753 |
|
19754 |
|
19755 |
|
19756 |
|
19757 |
|
19758 |
|
19759 |
|
19760 |
|
19761 |
|
19762 |
|
19763 |
|
19764 |
|
19765 | OPTICS.prototype._euclideanDistance = function(p, q) {
|
19766 | var sum = 0;
|
19767 | var i = Math.min(p.length, q.length);
|
19768 |
|
19769 | while (i--) {
|
19770 | sum += (p[i] - q[i]) * (p[i] - q[i]);
|
19771 | }
|
19772 |
|
19773 | return Math.sqrt(sum);
|
19774 | };
|
19775 |
|
19776 | if ('object' !== 'undefined' && module.exports) {
|
19777 | module.exports = OPTICS;
|
19778 | }
|
19779 | });
|
19780 |
|
19781 | var lib = createCommonjsModule(function (module) {
|
19782 | if ('object' !== 'undefined' && module.exports) {
|
19783 | module.exports = {
|
19784 | DBSCAN: DBSCAN_1,
|
19785 | KMEANS: KMEANS_1,
|
19786 | OPTICS: OPTICS_1,
|
19787 | PriorityQueue: PriorityQueue_1
|
19788 | };
|
19789 | }
|
19790 | });
|
19791 |
|
19792 | var lib_1 = lib.DBSCAN;
|
19793 | var lib_2 = lib.KMEANS;
|
19794 | var lib_3 = lib.OPTICS;
|
19795 | var lib_4 = lib.PriorityQueue;
|
19796 |
|
19797 |
|
19798 |
|
19799 |
|
19800 |
|
19801 |
|
19802 |
|
19803 |
|
19804 |
|
19805 |
|
19806 |
|
19807 |
|
19808 |
|
19809 |
|
19810 |
|
19811 |
|
19812 |
|
19813 |
|
19814 |
|
19815 |
|
19816 |
|
19817 |
|
19818 |
|
19819 | function clustersDbscan(points$$1, maxDistance, options) {
|
19820 |
|
19821 | options = options || {};
|
19822 | if (typeof options !== 'object') throw new Error('options is invalid');
|
19823 | var minPoints = options.minPoints;
|
19824 | var units = options.units;
|
19825 |
|
19826 |
|
19827 | collectionOf(points$$1, 'Point', 'Input must contain Points');
|
19828 | if (maxDistance === null || maxDistance === undefined) throw new Error('maxDistance is required');
|
19829 | if (!(Math.sign(maxDistance) > 0)) throw new Error('Invalid maxDistance');
|
19830 | if (!(minPoints === undefined || minPoints === null || Math.sign(minPoints) > 0)) throw new Error('Invalid minPoints');
|
19831 |
|
19832 |
|
19833 | points$$1 = clone(points$$1, true);
|
19834 |
|
19835 |
|
19836 | minPoints = minPoints || 3;
|
19837 |
|
19838 |
|
19839 | var dbscan = new lib.DBSCAN();
|
19840 | var clusteredIds = dbscan.run(coordAll(points$$1), convertLength(maxDistance, units), minPoints, distance);
|
19841 |
|
19842 |
|
19843 | var clusterId = -1;
|
19844 | clusteredIds.forEach(function (clusterIds) {
|
19845 | clusterId++;
|
19846 |
|
19847 | clusterIds.forEach(function (idx) {
|
19848 | var clusterPoint = points$$1.features[idx];
|
19849 | if (!clusterPoint.properties) clusterPoint.properties = {};
|
19850 | clusterPoint.properties.cluster = clusterId;
|
19851 | clusterPoint.properties.dbscan = 'core';
|
19852 | });
|
19853 | });
|
19854 |
|
19855 |
|
19856 |
|
19857 | dbscan.noise.forEach(function (noiseId) {
|
19858 | var noisePoint = points$$1.features[noiseId];
|
19859 | if (!noisePoint.properties) noisePoint.properties = {};
|
19860 | if (noisePoint.properties.cluster) noisePoint.properties.dbscan = 'edge';
|
19861 | else noisePoint.properties.dbscan = 'noise';
|
19862 | });
|
19863 |
|
19864 | return points$$1;
|
19865 | }
|
19866 |
|
19867 | var distance$2 = {
|
19868 | |
19869 |
|
19870 |
|
19871 | eudist: function eudist(v1, v2, sqrt) {
|
19872 | var len = v1.length;
|
19873 | var sum = 0;
|
19874 |
|
19875 | for (var i = 0; i < len; i++) {
|
19876 | var d = (v1[i] || 0) - (v2[i] || 0);
|
19877 | sum += d * d;
|
19878 | }
|
19879 |
|
19880 | return sqrt ? Math.sqrt(sum) : sum;
|
19881 | },
|
19882 | mandist: function mandist(v1, v2, sqrt) {
|
19883 | var len = v1.length;
|
19884 | var sum = 0;
|
19885 |
|
19886 | for (var i = 0; i < len; i++) {
|
19887 | sum += Math.abs((v1[i] || 0) - (v2[i] || 0));
|
19888 | }
|
19889 |
|
19890 |
|
19891 | return sqrt ? Math.sqrt(sum) : sum;
|
19892 | },
|
19893 |
|
19894 |
|
19895 | |
19896 |
|
19897 |
|
19898 | dist: function dist(v1, v2, sqrt) {
|
19899 | var d = Math.abs(v1 - v2);
|
19900 | return sqrt ? d : d * d;
|
19901 | }
|
19902 | };
|
19903 |
|
19904 | var eudist$1 = distance$2.eudist;
|
19905 | var dist$1 = distance$2.dist;
|
19906 |
|
19907 | var kinit = {
|
19908 | kmrand: function kmrand(data, k) {
|
19909 | var map = {},
|
19910 | ks = [],
|
19911 | t = k << 2;
|
19912 | var len = data.length;
|
19913 | var multi = data[0].length > 0;
|
19914 |
|
19915 | while (ks.length < k && t-- > 0) {
|
19916 | var d = data[Math.floor(Math.random() * len)];
|
19917 | var key = multi ? d.join("_") : "" + d;
|
19918 | if (!map[key]) {
|
19919 | map[key] = true;
|
19920 | ks.push(d);
|
19921 | }
|
19922 | }
|
19923 |
|
19924 | if (ks.length < k) throw new Error("Error initializating clusters");else return ks;
|
19925 | },
|
19926 |
|
19927 |
|
19928 | |
19929 |
|
19930 |
|
19931 | kmpp: function kmpp(data, k) {
|
19932 | var distance = data[0].length ? eudist$1 : dist$1;
|
19933 | var ks = [],
|
19934 | len = data.length;
|
19935 | var multi = data[0].length > 0;
|
19936 | var c = data[Math.floor(Math.random() * len)];
|
19937 | var key = multi ? c.join("_") : "" + c;
|
19938 | ks.push(c);
|
19939 | while (ks.length < k) {
|
19940 |
|
19941 | var dists = [],
|
19942 | lk = ks.length;
|
19943 | var dsum = 0,
|
19944 | prs = [];
|
19945 |
|
19946 | for (var i = 0; i < len; i++) {
|
19947 | var min = Infinity;
|
19948 | for (var j = 0; j < lk; j++) {
|
19949 | var _dist = distance(data[i], ks[j]);
|
19950 | if (_dist <= min) min = _dist;
|
19951 | }
|
19952 | dists[i] = min;
|
19953 | }
|
19954 |
|
19955 |
|
19956 | for (var _i = 0; _i < len; _i++) {
|
19957 | dsum += dists[_i];
|
19958 | }
|
19959 |
|
19960 |
|
19961 | for (var _i2 = 0; _i2 < len; _i2++) {
|
19962 | prs[_i2] = { i: _i2, v: data[_i2], pr: dists[_i2] / dsum, cs: 0 };
|
19963 | }
|
19964 |
|
19965 |
|
19966 | prs.sort(function (a, b) {
|
19967 | return a.pr - b.pr;
|
19968 | });
|
19969 |
|
19970 |
|
19971 | prs[0].cs = prs[0].pr;
|
19972 | for (var _i3 = 1; _i3 < len; _i3++) {
|
19973 | prs[_i3].cs = prs[_i3 - 1].cs + prs[_i3].pr;
|
19974 | }
|
19975 |
|
19976 |
|
19977 | var rnd = Math.random();
|
19978 |
|
19979 |
|
19980 | var idx = 0;
|
19981 | while (idx < len - 1 && prs[idx++].cs < rnd) {}
|
19982 | ks.push(prs[idx - 1].v);
|
19983 | |
19984 |
|
19985 |
|
19986 |
|
19987 |
|
19988 |
|
19989 |
|
19990 |
|
19991 |
|
19992 |
|
19993 |
|
19994 |
|
19995 |
|
19996 |
|
19997 |
|
19998 |
|
19999 | }
|
20000 |
|
20001 | return ks;
|
20002 | }
|
20003 | };
|
20004 |
|
20005 |
|
20006 |
|
20007 | var eudist = distance$2.eudist;
|
20008 | var kmrand = kinit.kmrand;
|
20009 | var kmpp = kinit.kmpp;
|
20010 |
|
20011 | var MAX = 10000;
|
20012 |
|
20013 |
|
20014 |
|
20015 |
|
20016 | function init(len, val, v) {
|
20017 | v = v || [];
|
20018 | for (var i = 0; i < len; i++) {
|
20019 | v[i] = val;
|
20020 | }return v;
|
20021 | }
|
20022 |
|
20023 | function skmeans(data, k, initial, maxit) {
|
20024 | var ks = [],
|
20025 | old = [],
|
20026 | idxs = [],
|
20027 | dist = [];
|
20028 | var conv = false,
|
20029 | it = maxit || MAX;
|
20030 | var len = data.length,
|
20031 | vlen = data[0].length,
|
20032 | multi = vlen > 0;
|
20033 | var count = [];
|
20034 |
|
20035 | if (!initial) {
|
20036 | var _idxs = {};
|
20037 | while (ks.length < k) {
|
20038 | var idx = Math.floor(Math.random() * len);
|
20039 | if (!_idxs[idx]) {
|
20040 | _idxs[idx] = true;
|
20041 | ks.push(data[idx]);
|
20042 | }
|
20043 | }
|
20044 | } else if (initial == "kmrand") {
|
20045 | ks = kmrand(data, k);
|
20046 | } else if (initial == "kmpp") {
|
20047 | ks = kmpp(data, k);
|
20048 | } else {
|
20049 | ks = initial;
|
20050 | }
|
20051 |
|
20052 | do {
|
20053 |
|
20054 | init(k, 0, count);
|
20055 |
|
20056 |
|
20057 | for (var i = 0; i < len; i++) {
|
20058 | var min = Infinity,
|
20059 | _idx = 0;
|
20060 | for (var j = 0; j < k; j++) {
|
20061 |
|
20062 | var dist = multi ? eudist(data[i], ks[j]) : Math.abs(data[i] - ks[j]);
|
20063 | if (dist <= min) {
|
20064 | min = dist;
|
20065 | _idx = j;
|
20066 | }
|
20067 | }
|
20068 | idxs[i] = _idx;
|
20069 | count[_idx]++;
|
20070 | }
|
20071 |
|
20072 |
|
20073 | var sum = [],
|
20074 | old = [];
|
20075 | for (var _j = 0; _j < k; _j++) {
|
20076 |
|
20077 | sum[_j] = multi ? init(vlen, 0, sum[_j]) : 0;
|
20078 | old[_j] = ks[_j];
|
20079 | }
|
20080 |
|
20081 |
|
20082 | if (multi) {
|
20083 | for (var _j2 = 0; _j2 < k; _j2++) {
|
20084 | ks[_j2] = [];
|
20085 | }
|
20086 | for (var _i = 0; _i < len; _i++) {
|
20087 | var _idx2 = idxs[_i],
|
20088 |
|
20089 | vsum = sum[_idx2],
|
20090 |
|
20091 | vect = data[_i];
|
20092 |
|
20093 |
|
20094 | for (var h = 0; h < vlen; h++) {
|
20095 | vsum[h] += vect[h];
|
20096 | }
|
20097 | }
|
20098 |
|
20099 | conv = true;
|
20100 | for (var _j3 = 0; _j3 < k; _j3++) {
|
20101 | var ksj = ks[_j3],
|
20102 |
|
20103 | sumj = sum[_j3],
|
20104 |
|
20105 | oldj = old[_j3],
|
20106 |
|
20107 | cj = count[_j3];
|
20108 |
|
20109 |
|
20110 | for (var _h = 0; _h < vlen; _h++) {
|
20111 | ksj[_h] = sumj[_h] / cj || 0;
|
20112 | }
|
20113 |
|
20114 |
|
20115 | if (conv) {
|
20116 | for (var _h2 = 0; _h2 < vlen; _h2++) {
|
20117 | if (oldj[_h2] != ksj[_h2]) {
|
20118 | conv = false;
|
20119 | break;
|
20120 | }
|
20121 | }
|
20122 | }
|
20123 | }
|
20124 | }
|
20125 |
|
20126 | else {
|
20127 |
|
20128 | for (var _i2 = 0; _i2 < len; _i2++) {
|
20129 | var _idx3 = idxs[_i2];
|
20130 | sum[_idx3] += data[_i2];
|
20131 | }
|
20132 |
|
20133 | for (var _j4 = 0; _j4 < k; _j4++) {
|
20134 | ks[_j4] = sum[_j4] / count[_j4] || 0;
|
20135 | }
|
20136 |
|
20137 | conv = true;
|
20138 | for (var _j5 = 0; _j5 < k; _j5++) {
|
20139 | if (old[_j5] != ks[_j5]) {
|
20140 | conv = false;
|
20141 | break;
|
20142 | }
|
20143 | }
|
20144 | }
|
20145 |
|
20146 | conv = conv || --it <= 0;
|
20147 | } while (!conv);
|
20148 |
|
20149 | return {
|
20150 | it: MAX - it,
|
20151 | k: k,
|
20152 | idxs: idxs,
|
20153 | centroids: ks
|
20154 | };
|
20155 | }
|
20156 |
|
20157 | var main = skmeans;
|
20158 |
|
20159 |
|
20160 |
|
20161 |
|
20162 |
|
20163 |
|
20164 |
|
20165 |
|
20166 |
|
20167 |
|
20168 |
|
20169 |
|
20170 |
|
20171 |
|
20172 |
|
20173 |
|
20174 |
|
20175 |
|
20176 |
|
20177 |
|
20178 |
|
20179 |
|
20180 | function clustersKmeans(points, options) {
|
20181 |
|
20182 | options = options || {};
|
20183 | if (typeof options !== 'object') throw new Error('options is invalid');
|
20184 | var numberOfClusters = options.numberOfClusters;
|
20185 | var mutate = options.mutate;
|
20186 |
|
20187 |
|
20188 | collectionOf(points, 'Point', 'Input must contain Points');
|
20189 |
|
20190 |
|
20191 | var count = points.features.length;
|
20192 | numberOfClusters = numberOfClusters || Math.round(Math.sqrt(count / 2));
|
20193 |
|
20194 |
|
20195 |
|
20196 | if (numberOfClusters > count) numberOfClusters = count;
|
20197 |
|
20198 |
|
20199 | if (mutate === false || mutate === undefined) points = clone(points, true);
|
20200 |
|
20201 |
|
20202 | var data = coordAll(points);
|
20203 |
|
20204 |
|
20205 | var initialCentroids = data.slice(0, numberOfClusters);
|
20206 |
|
20207 |
|
20208 | var skmeansResult = main(data, numberOfClusters, initialCentroids);
|
20209 |
|
20210 |
|
20211 | var centroids = {};
|
20212 | skmeansResult.centroids.forEach(function (coord, idx) {
|
20213 | centroids[idx] = coord;
|
20214 | });
|
20215 |
|
20216 |
|
20217 | featureEach(points, function (point, index) {
|
20218 | var clusterId = skmeansResult.idxs[index];
|
20219 | point.properties.cluster = clusterId;
|
20220 | point.properties.centroid = centroids[clusterId];
|
20221 | });
|
20222 |
|
20223 | return points;
|
20224 | }
|
20225 |
|
20226 |
|
20227 |
|
20228 |
|
20229 |
|
20230 |
|
20231 |
|
20232 |
|
20233 |
|
20234 |
|
20235 |
|
20236 |
|
20237 |
|
20238 |
|
20239 |
|
20240 | function booleanParallel(line1, line2) {
|
20241 |
|
20242 | if (!line1) throw new Error('line1 is required');
|
20243 | if (!line2) throw new Error('line2 is required');
|
20244 | var type1 = getType$1(line1, 'line1');
|
20245 | if (type1 !== 'LineString') throw new Error('line1 must be a LineString');
|
20246 | var type2 = getType$1(line2, 'line2');
|
20247 | if (type2 !== 'LineString') throw new Error('line2 must be a LineString');
|
20248 |
|
20249 | var segments1 = lineSegment(cleanCoords(line1)).features;
|
20250 | var segments2 = lineSegment(cleanCoords(line2)).features;
|
20251 |
|
20252 | for (var i = 0; i < segments1.length; i++) {
|
20253 | var segment1 = segments1[i].geometry.coordinates;
|
20254 | if (!segments2[i]) break;
|
20255 | var segment2 = segments2[i].geometry.coordinates;
|
20256 | if (!isParallel$1(segment1, segment2)) return false;
|
20257 | }
|
20258 | return true;
|
20259 | }
|
20260 |
|
20261 |
|
20262 |
|
20263 |
|
20264 |
|
20265 |
|
20266 |
|
20267 |
|
20268 |
|
20269 |
|
20270 | function isParallel$1(segment1, segment2) {
|
20271 | var slope1 = bearingToAzimuth(rhumbBearing(segment1[0], segment1[1]));
|
20272 | var slope2 = bearingToAzimuth(rhumbBearing(segment2[0], segment2[1]));
|
20273 | return slope1 === slope2;
|
20274 | }
|
20275 |
|
20276 |
|
20277 |
|
20278 |
|
20279 |
|
20280 |
|
20281 |
|
20282 |
|
20283 |
|
20284 |
|
20285 | function getType$1(geojson, name) {
|
20286 | if (geojson.geometry && geojson.geometry.type) return geojson.geometry.type;
|
20287 | if (geojson.type) return geojson.type;
|
20288 | throw new Error('Invalid GeoJSON object for ' + name);
|
20289 | }
|
20290 |
|
20291 |
|
20292 |
|
20293 |
|
20294 |
|
20295 |
|
20296 |
|
20297 |
|
20298 | function pathTo(node) {
|
20299 | var curr = node,
|
20300 | path = [];
|
20301 | while (curr.parent) {
|
20302 | path.unshift(curr);
|
20303 | curr = curr.parent;
|
20304 | }
|
20305 | return path;
|
20306 | }
|
20307 |
|
20308 | function getHeap() {
|
20309 | return new BinaryHeap(function (node) {
|
20310 | return node.f;
|
20311 | });
|
20312 | }
|
20313 |
|
20314 |
|
20315 |
|
20316 |
|
20317 |
|
20318 | var astar = {
|
20319 | |
20320 |
|
20321 |
|
20322 |
|
20323 |
|
20324 |
|
20325 |
|
20326 |
|
20327 |
|
20328 |
|
20329 |
|
20330 |
|
20331 |
|
20332 | search: function (graph, start, end, options) {
|
20333 | graph.cleanDirty();
|
20334 | options = options || {};
|
20335 | var heuristic = options.heuristic || astar.heuristics.manhattan,
|
20336 | closest = options.closest || false;
|
20337 |
|
20338 | var openHeap = getHeap(),
|
20339 | closestNode = start;
|
20340 |
|
20341 | start.h = heuristic(start, end);
|
20342 |
|
20343 | openHeap.push(start);
|
20344 |
|
20345 | while (openHeap.size() > 0) {
|
20346 |
|
20347 |
|
20348 | var currentNode = openHeap.pop();
|
20349 |
|
20350 |
|
20351 | if (currentNode === end) {
|
20352 | return pathTo(currentNode);
|
20353 | }
|
20354 |
|
20355 |
|
20356 | currentNode.closed = true;
|
20357 |
|
20358 |
|
20359 | var neighbors = graph.neighbors(currentNode);
|
20360 |
|
20361 | for (var i = 0, il = neighbors.length; i < il; ++i) {
|
20362 | var neighbor = neighbors[i];
|
20363 |
|
20364 | if (neighbor.closed || neighbor.isWall()) {
|
20365 |
|
20366 | continue;
|
20367 | }
|
20368 |
|
20369 |
|
20370 |
|
20371 | var gScore = currentNode.g + neighbor.getCost(currentNode),
|
20372 | beenVisited = neighbor.visited;
|
20373 |
|
20374 | if (!beenVisited || gScore < neighbor.g) {
|
20375 |
|
20376 |
|
20377 | neighbor.visited = true;
|
20378 | neighbor.parent = currentNode;
|
20379 | neighbor.h = neighbor.h || heuristic(neighbor, end);
|
20380 | neighbor.g = gScore;
|
20381 | neighbor.f = neighbor.g + neighbor.h;
|
20382 | graph.markDirty(neighbor);
|
20383 | if (closest) {
|
20384 |
|
20385 |
|
20386 | if (neighbor.h < closestNode.h || (neighbor.h === closestNode.h && neighbor.g < closestNode.g)) {
|
20387 | closestNode = neighbor;
|
20388 | }
|
20389 | }
|
20390 |
|
20391 | if (!beenVisited) {
|
20392 |
|
20393 | openHeap.push(neighbor);
|
20394 | } else {
|
20395 |
|
20396 | openHeap.rescoreElement(neighbor);
|
20397 | }
|
20398 | }
|
20399 | }
|
20400 | }
|
20401 |
|
20402 | if (closest) {
|
20403 | return pathTo(closestNode);
|
20404 | }
|
20405 |
|
20406 |
|
20407 | return [];
|
20408 | },
|
20409 |
|
20410 | heuristics: {
|
20411 | manhattan: function (pos0, pos1) {
|
20412 | var d1 = Math.abs(pos1.x - pos0.x);
|
20413 | var d2 = Math.abs(pos1.y - pos0.y);
|
20414 | return d1 + d2;
|
20415 | },
|
20416 | diagonal: function (pos0, pos1) {
|
20417 | var D = 1;
|
20418 | var D2 = Math.sqrt(2);
|
20419 | var d1 = Math.abs(pos1.x - pos0.x);
|
20420 | var d2 = Math.abs(pos1.y - pos0.y);
|
20421 | return (D * (d1 + d2)) + ((D2 - (2 * D)) * Math.min(d1, d2));
|
20422 | }
|
20423 | },
|
20424 | cleanNode: function (node) {
|
20425 | node.f = 0;
|
20426 | node.g = 0;
|
20427 | node.h = 0;
|
20428 | node.visited = false;
|
20429 | node.closed = false;
|
20430 | node.parent = null;
|
20431 | }
|
20432 | };
|
20433 |
|
20434 |
|
20435 |
|
20436 |
|
20437 |
|
20438 |
|
20439 |
|
20440 |
|
20441 |
|
20442 |
|
20443 | function Graph$1(gridIn, options) {
|
20444 | options = options || {};
|
20445 | this.nodes = [];
|
20446 | this.diagonal = !!options.diagonal;
|
20447 | this.grid = [];
|
20448 | for (var x = 0; x < gridIn.length; x++) {
|
20449 | this.grid[x] = [];
|
20450 |
|
20451 | for (var y = 0, row = gridIn[x]; y < row.length; y++) {
|
20452 | var node = new GridNode(x, y, row[y]);
|
20453 | this.grid[x][y] = node;
|
20454 | this.nodes.push(node);
|
20455 | }
|
20456 | }
|
20457 | this.init();
|
20458 | }
|
20459 |
|
20460 | Graph$1.prototype.init = function () {
|
20461 | this.dirtyNodes = [];
|
20462 | for (var i = 0; i < this.nodes.length; i++) {
|
20463 | astar.cleanNode(this.nodes[i]);
|
20464 | }
|
20465 | };
|
20466 |
|
20467 | Graph$1.prototype.cleanDirty = function () {
|
20468 | for (var i = 0; i < this.dirtyNodes.length; i++) {
|
20469 | astar.cleanNode(this.dirtyNodes[i]);
|
20470 | }
|
20471 | this.dirtyNodes = [];
|
20472 | };
|
20473 |
|
20474 | Graph$1.prototype.markDirty = function (node) {
|
20475 | this.dirtyNodes.push(node);
|
20476 | };
|
20477 |
|
20478 | Graph$1.prototype.neighbors = function (node) {
|
20479 | var ret = [],
|
20480 | x = node.x,
|
20481 | y = node.y,
|
20482 | grid = this.grid;
|
20483 |
|
20484 |
|
20485 | if (grid[x - 1] && grid[x - 1][y]) {
|
20486 | ret.push(grid[x - 1][y]);
|
20487 | }
|
20488 |
|
20489 |
|
20490 | if (grid[x + 1] && grid[x + 1][y]) {
|
20491 | ret.push(grid[x + 1][y]);
|
20492 | }
|
20493 |
|
20494 |
|
20495 | if (grid[x] && grid[x][y - 1]) {
|
20496 | ret.push(grid[x][y - 1]);
|
20497 | }
|
20498 |
|
20499 |
|
20500 | if (grid[x] && grid[x][y + 1]) {
|
20501 | ret.push(grid[x][y + 1]);
|
20502 | }
|
20503 |
|
20504 | if (this.diagonal) {
|
20505 |
|
20506 | if (grid[x - 1] && grid[x - 1][y - 1]) {
|
20507 | ret.push(grid[x - 1][y - 1]);
|
20508 | }
|
20509 |
|
20510 |
|
20511 | if (grid[x + 1] && grid[x + 1][y - 1]) {
|
20512 | ret.push(grid[x + 1][y - 1]);
|
20513 | }
|
20514 |
|
20515 |
|
20516 | if (grid[x - 1] && grid[x - 1][y + 1]) {
|
20517 | ret.push(grid[x - 1][y + 1]);
|
20518 | }
|
20519 |
|
20520 |
|
20521 | if (grid[x + 1] && grid[x + 1][y + 1]) {
|
20522 | ret.push(grid[x + 1][y + 1]);
|
20523 | }
|
20524 | }
|
20525 |
|
20526 | return ret;
|
20527 | };
|
20528 |
|
20529 | Graph$1.prototype.toString = function () {
|
20530 | var graphString = [],
|
20531 | nodes = this.grid,
|
20532 | rowDebug, row, y, l;
|
20533 | for (var x = 0, len = nodes.length; x < len; x++) {
|
20534 | rowDebug = [];
|
20535 | row = nodes[x];
|
20536 | for (y = 0, l = row.length; y < l; y++) {
|
20537 | rowDebug.push(row[y].weight);
|
20538 | }
|
20539 | graphString.push(rowDebug.join(' '));
|
20540 | }
|
20541 | return graphString.join('\n');
|
20542 | };
|
20543 |
|
20544 | function GridNode(x, y, weight) {
|
20545 | this.x = x;
|
20546 | this.y = y;
|
20547 | this.weight = weight;
|
20548 | }
|
20549 |
|
20550 | GridNode.prototype.toString = function () {
|
20551 | return '[' + this.x + ' ' + this.y + ']';
|
20552 | };
|
20553 |
|
20554 | GridNode.prototype.getCost = function (fromNeighbor) {
|
20555 |
|
20556 | if (fromNeighbor && fromNeighbor.x !== this.x && fromNeighbor.y !== this.y) {
|
20557 | return this.weight * 1.41421;
|
20558 | }
|
20559 | return this.weight;
|
20560 | };
|
20561 |
|
20562 | GridNode.prototype.isWall = function () {
|
20563 | return this.weight === 0;
|
20564 | };
|
20565 |
|
20566 | function BinaryHeap(scoreFunction) {
|
20567 | this.content = [];
|
20568 | this.scoreFunction = scoreFunction;
|
20569 | }
|
20570 |
|
20571 | BinaryHeap.prototype = {
|
20572 | push: function (element) {
|
20573 |
|
20574 | this.content.push(element);
|
20575 |
|
20576 |
|
20577 | this.sinkDown(this.content.length - 1);
|
20578 | },
|
20579 | pop: function () {
|
20580 |
|
20581 | var result = this.content[0];
|
20582 |
|
20583 | var end = this.content.pop();
|
20584 |
|
20585 |
|
20586 | if (this.content.length > 0) {
|
20587 | this.content[0] = end;
|
20588 | this.bubbleUp(0);
|
20589 | }
|
20590 | return result;
|
20591 | },
|
20592 | remove: function (node) {
|
20593 | var i = this.content.indexOf(node);
|
20594 |
|
20595 |
|
20596 |
|
20597 | var end = this.content.pop();
|
20598 |
|
20599 | if (i !== this.content.length - 1) {
|
20600 | this.content[i] = end;
|
20601 |
|
20602 | if (this.scoreFunction(end) < this.scoreFunction(node)) {
|
20603 | this.sinkDown(i);
|
20604 | } else {
|
20605 | this.bubbleUp(i);
|
20606 | }
|
20607 | }
|
20608 | },
|
20609 | size: function () {
|
20610 | return this.content.length;
|
20611 | },
|
20612 | rescoreElement: function (node) {
|
20613 | this.sinkDown(this.content.indexOf(node));
|
20614 | },
|
20615 | sinkDown: function (n) {
|
20616 |
|
20617 | var element = this.content[n];
|
20618 |
|
20619 |
|
20620 | while (n > 0) {
|
20621 |
|
20622 |
|
20623 | var parentN = ((n + 1) >> 1) - 1,
|
20624 | parent = this.content[parentN];
|
20625 |
|
20626 | if (this.scoreFunction(element) < this.scoreFunction(parent)) {
|
20627 | this.content[parentN] = element;
|
20628 | this.content[n] = parent;
|
20629 |
|
20630 | n = parentN;
|
20631 |
|
20632 | } else {
|
20633 | break;
|
20634 | }
|
20635 | }
|
20636 | },
|
20637 | bubbleUp: function (n) {
|
20638 |
|
20639 | var length = this.content.length,
|
20640 | element = this.content[n],
|
20641 | elemScore = this.scoreFunction(element);
|
20642 |
|
20643 | while (true) {
|
20644 |
|
20645 | var child2N = (n + 1) << 1,
|
20646 | child1N = child2N - 1;
|
20647 |
|
20648 | var swap = null,
|
20649 | child1Score;
|
20650 |
|
20651 | if (child1N < length) {
|
20652 |
|
20653 | var child1 = this.content[child1N];
|
20654 | child1Score = this.scoreFunction(child1);
|
20655 |
|
20656 |
|
20657 | if (child1Score < elemScore) {
|
20658 | swap = child1N;
|
20659 | }
|
20660 | }
|
20661 |
|
20662 |
|
20663 | if (child2N < length) {
|
20664 | var child2 = this.content[child2N],
|
20665 | child2Score = this.scoreFunction(child2);
|
20666 | if (child2Score < (swap === null ? elemScore : child1Score)) {
|
20667 | swap = child2N;
|
20668 | }
|
20669 | }
|
20670 |
|
20671 |
|
20672 | if (swap !== null) {
|
20673 | this.content[n] = this.content[swap];
|
20674 | this.content[swap] = element;
|
20675 | n = swap;
|
20676 |
|
20677 | } else {
|
20678 | break;
|
20679 | }
|
20680 | }
|
20681 | }
|
20682 | };
|
20683 |
|
20684 |
|
20685 |
|
20686 |
|
20687 |
|
20688 |
|
20689 |
|
20690 |
|
20691 |
|
20692 |
|
20693 |
|
20694 |
|
20695 |
|
20696 |
|
20697 |
|
20698 |
|
20699 |
|
20700 |
|
20701 |
|
20702 |
|
20703 |
|
20704 |
|
20705 |
|
20706 |
|
20707 |
|
20708 |
|
20709 | function shortestPath(start, end, options) {
|
20710 |
|
20711 | options = options || {};
|
20712 | if (!isObject(options)) throw new Error('options is invalid');
|
20713 | var resolution = options.resolution;
|
20714 | var minDistance = options.minDistance;
|
20715 | var obstacles = options.obstacles || featureCollection([]);
|
20716 |
|
20717 |
|
20718 | if (!start) throw new Error('start is required');
|
20719 | if (!end) throw new Error('end is required');
|
20720 | if (resolution && !isNumber(resolution) || resolution <= 0) throw new Error('options.resolution must be a number, greater than 0');
|
20721 | if (minDistance) throw new Error('options.minDistance is not yet implemented');
|
20722 |
|
20723 |
|
20724 | var startCoord = getCoord(start);
|
20725 | var endCoord = getCoord(end);
|
20726 | start = point(startCoord);
|
20727 | end = point(endCoord);
|
20728 |
|
20729 |
|
20730 | switch (getType(obstacles)) {
|
20731 | case 'FeatureCollection':
|
20732 | if (obstacles.features.length === 0) return lineString([startCoord, endCoord]);
|
20733 | break;
|
20734 | case 'Polygon':
|
20735 | obstacles = featureCollection([feature(getGeom(obstacles))]);
|
20736 | break;
|
20737 | default:
|
20738 | throw new Error('invalid obstacles');
|
20739 | }
|
20740 |
|
20741 |
|
20742 | var collection = obstacles;
|
20743 | collection.features.push(start);
|
20744 | collection.features.push(end);
|
20745 | var box = bbox(transformScale(bboxPolygon(bbox(collection)), 1.15));
|
20746 | if (!resolution) {
|
20747 | var width = distance([box[0], box[1]], [box[2], box[1]], options);
|
20748 | resolution = width / 100;
|
20749 | }
|
20750 | collection.features.pop();
|
20751 | collection.features.pop();
|
20752 |
|
20753 | var west = box[0];
|
20754 | var south = box[1];
|
20755 | var east = box[2];
|
20756 | var north = box[3];
|
20757 |
|
20758 | var xFraction = resolution / (distance([west, south], [east, south], options));
|
20759 | var cellWidth = xFraction * (east - west);
|
20760 | var yFraction = resolution / (distance([west, south], [west, north], options));
|
20761 | var cellHeight = yFraction * (north - south);
|
20762 |
|
20763 | var bboxHorizontalSide = (east - west);
|
20764 | var bboxVerticalSide = (north - south);
|
20765 | var columns = Math.floor(bboxHorizontalSide / cellWidth);
|
20766 | var rows = Math.floor(bboxVerticalSide / cellHeight);
|
20767 |
|
20768 | var deltaX = (bboxHorizontalSide - columns * cellWidth) / 2;
|
20769 | var deltaY = (bboxVerticalSide - rows * cellHeight) / 2;
|
20770 |
|
20771 |
|
20772 |
|
20773 | var pointMatrix = [];
|
20774 | var matrix = [];
|
20775 |
|
20776 | var closestToStart = [];
|
20777 | var closestToEnd = [];
|
20778 | var minDistStart = Infinity;
|
20779 | var minDistEnd = Infinity;
|
20780 | var currentY = north - deltaY;
|
20781 | var r = 0;
|
20782 | while (currentY >= south) {
|
20783 |
|
20784 | var matrixRow = [];
|
20785 | var pointMatrixRow = [];
|
20786 | var currentX = west + deltaX;
|
20787 | var c = 0;
|
20788 | while (currentX <= east) {
|
20789 | var pt = point([currentX, currentY]);
|
20790 | var isInsideObstacle = isInside$1(pt, obstacles);
|
20791 |
|
20792 | matrixRow.push(isInsideObstacle ? 0 : 1);
|
20793 |
|
20794 |
|
20795 | pointMatrixRow.push(currentX + '|' + currentY);
|
20796 |
|
20797 | var distStart = distance(pt, start);
|
20798 |
|
20799 | if (!isInsideObstacle && distStart < minDistStart) {
|
20800 | minDistStart = distStart;
|
20801 | closestToStart = {x: c, y: r};
|
20802 | }
|
20803 | var distEnd = distance(pt, end);
|
20804 |
|
20805 | if (!isInsideObstacle && distEnd < minDistEnd) {
|
20806 | minDistEnd = distEnd;
|
20807 | closestToEnd = {x: c, y: r};
|
20808 | }
|
20809 | currentX += cellWidth;
|
20810 | c++;
|
20811 | }
|
20812 | matrix.push(matrixRow);
|
20813 | pointMatrix.push(pointMatrixRow);
|
20814 | currentY -= cellHeight;
|
20815 | r++;
|
20816 | }
|
20817 |
|
20818 |
|
20819 |
|
20820 |
|
20821 | var graph = new Graph$1(matrix, {diagonal: true});
|
20822 | var startOnMatrix = graph.grid[closestToStart.y][closestToStart.x];
|
20823 | var endOnMatrix = graph.grid[closestToEnd.y][closestToEnd.x];
|
20824 | var result = astar.search(graph, startOnMatrix, endOnMatrix);
|
20825 |
|
20826 | var path = [startCoord];
|
20827 | result.forEach(function (coord) {
|
20828 | var coords = pointMatrix[coord.x][coord.y].split('|');
|
20829 | path.push([+coords[0], +coords[1]]);
|
20830 | });
|
20831 | path.push(endCoord);
|
20832 |
|
20833 |
|
20834 |
|
20835 |
|
20836 |
|
20837 |
|
20838 |
|
20839 |
|
20840 |
|
20841 |
|
20842 |
|
20843 |
|
20844 |
|
20845 |
|
20846 | return cleanCoords(lineString(path));
|
20847 | }
|
20848 |
|
20849 |
|
20850 |
|
20851 |
|
20852 |
|
20853 |
|
20854 |
|
20855 |
|
20856 |
|
20857 | function isInside$1(pt, polygons$$1) {
|
20858 | for (var i = 0; i < polygons$$1.features.length; i++) {
|
20859 | if (booleanPointInPolygon(pt, polygons$$1.features[i])) {
|
20860 | return true;
|
20861 | }
|
20862 | }
|
20863 | return false;
|
20864 | }
|
20865 |
|
20866 | var constant = function(x) {
|
20867 | return function() {
|
20868 | return x;
|
20869 | };
|
20870 | };
|
20871 |
|
20872 | function x(d) {
|
20873 | return d[0];
|
20874 | }
|
20875 |
|
20876 | function y(d) {
|
20877 | return d[1];
|
20878 | }
|
20879 |
|
20880 | function RedBlackTree() {
|
20881 | this._ = null;
|
20882 | }
|
20883 |
|
20884 | function RedBlackNode(node) {
|
20885 | node.U =
|
20886 | node.C =
|
20887 | node.L =
|
20888 | node.R =
|
20889 | node.P =
|
20890 | node.N = null;
|
20891 | }
|
20892 |
|
20893 | RedBlackTree.prototype = {
|
20894 | constructor: RedBlackTree,
|
20895 |
|
20896 | insert: function(after, node) {
|
20897 | var parent, grandpa, uncle;
|
20898 |
|
20899 | if (after) {
|
20900 | node.P = after;
|
20901 | node.N = after.N;
|
20902 | if (after.N) after.N.P = node;
|
20903 | after.N = node;
|
20904 | if (after.R) {
|
20905 | after = after.R;
|
20906 | while (after.L) after = after.L;
|
20907 | after.L = node;
|
20908 | } else {
|
20909 | after.R = node;
|
20910 | }
|
20911 | parent = after;
|
20912 | } else if (this._) {
|
20913 | after = RedBlackFirst(this._);
|
20914 | node.P = null;
|
20915 | node.N = after;
|
20916 | after.P = after.L = node;
|
20917 | parent = after;
|
20918 | } else {
|
20919 | node.P = node.N = null;
|
20920 | this._ = node;
|
20921 | parent = null;
|
20922 | }
|
20923 | node.L = node.R = null;
|
20924 | node.U = parent;
|
20925 | node.C = true;
|
20926 |
|
20927 | after = node;
|
20928 | while (parent && parent.C) {
|
20929 | grandpa = parent.U;
|
20930 | if (parent === grandpa.L) {
|
20931 | uncle = grandpa.R;
|
20932 | if (uncle && uncle.C) {
|
20933 | parent.C = uncle.C = false;
|
20934 | grandpa.C = true;
|
20935 | after = grandpa;
|
20936 | } else {
|
20937 | if (after === parent.R) {
|
20938 | RedBlackRotateLeft(this, parent);
|
20939 | after = parent;
|
20940 | parent = after.U;
|
20941 | }
|
20942 | parent.C = false;
|
20943 | grandpa.C = true;
|
20944 | RedBlackRotateRight(this, grandpa);
|
20945 | }
|
20946 | } else {
|
20947 | uncle = grandpa.L;
|
20948 | if (uncle && uncle.C) {
|
20949 | parent.C = uncle.C = false;
|
20950 | grandpa.C = true;
|
20951 | after = grandpa;
|
20952 | } else {
|
20953 | if (after === parent.L) {
|
20954 | RedBlackRotateRight(this, parent);
|
20955 | after = parent;
|
20956 | parent = after.U;
|
20957 | }
|
20958 | parent.C = false;
|
20959 | grandpa.C = true;
|
20960 | RedBlackRotateLeft(this, grandpa);
|
20961 | }
|
20962 | }
|
20963 | parent = after.U;
|
20964 | }
|
20965 | this._.C = false;
|
20966 | },
|
20967 |
|
20968 | remove: function(node) {
|
20969 | if (node.N) node.N.P = node.P;
|
20970 | if (node.P) node.P.N = node.N;
|
20971 | node.N = node.P = null;
|
20972 |
|
20973 | var parent = node.U,
|
20974 | sibling,
|
20975 | left = node.L,
|
20976 | right = node.R,
|
20977 | next,
|
20978 | red;
|
20979 |
|
20980 | if (!left) next = right;
|
20981 | else if (!right) next = left;
|
20982 | else next = RedBlackFirst(right);
|
20983 |
|
20984 | if (parent) {
|
20985 | if (parent.L === node) parent.L = next;
|
20986 | else parent.R = next;
|
20987 | } else {
|
20988 | this._ = next;
|
20989 | }
|
20990 |
|
20991 | if (left && right) {
|
20992 | red = next.C;
|
20993 | next.C = node.C;
|
20994 | next.L = left;
|
20995 | left.U = next;
|
20996 | if (next !== right) {
|
20997 | parent = next.U;
|
20998 | next.U = node.U;
|
20999 | node = next.R;
|
21000 | parent.L = node;
|
21001 | next.R = right;
|
21002 | right.U = next;
|
21003 | } else {
|
21004 | next.U = parent;
|
21005 | parent = next;
|
21006 | node = next.R;
|
21007 | }
|
21008 | } else {
|
21009 | red = node.C;
|
21010 | node = next;
|
21011 | }
|
21012 |
|
21013 | if (node) node.U = parent;
|
21014 | if (red) return;
|
21015 | if (node && node.C) { node.C = false; return; }
|
21016 |
|
21017 | do {
|
21018 | if (node === this._) break;
|
21019 | if (node === parent.L) {
|
21020 | sibling = parent.R;
|
21021 | if (sibling.C) {
|
21022 | sibling.C = false;
|
21023 | parent.C = true;
|
21024 | RedBlackRotateLeft(this, parent);
|
21025 | sibling = parent.R;
|
21026 | }
|
21027 | if ((sibling.L && sibling.L.C)
|
21028 | || (sibling.R && sibling.R.C)) {
|
21029 | if (!sibling.R || !sibling.R.C) {
|
21030 | sibling.L.C = false;
|
21031 | sibling.C = true;
|
21032 | RedBlackRotateRight(this, sibling);
|
21033 | sibling = parent.R;
|
21034 | }
|
21035 | sibling.C = parent.C;
|
21036 | parent.C = sibling.R.C = false;
|
21037 | RedBlackRotateLeft(this, parent);
|
21038 | node = this._;
|
21039 | break;
|
21040 | }
|
21041 | } else {
|
21042 | sibling = parent.L;
|
21043 | if (sibling.C) {
|
21044 | sibling.C = false;
|
21045 | parent.C = true;
|
21046 | RedBlackRotateRight(this, parent);
|
21047 | sibling = parent.L;
|
21048 | }
|
21049 | if ((sibling.L && sibling.L.C)
|
21050 | || (sibling.R && sibling.R.C)) {
|
21051 | if (!sibling.L || !sibling.L.C) {
|
21052 | sibling.R.C = false;
|
21053 | sibling.C = true;
|
21054 | RedBlackRotateLeft(this, sibling);
|
21055 | sibling = parent.L;
|
21056 | }
|
21057 | sibling.C = parent.C;
|
21058 | parent.C = sibling.L.C = false;
|
21059 | RedBlackRotateRight(this, parent);
|
21060 | node = this._;
|
21061 | break;
|
21062 | }
|
21063 | }
|
21064 | sibling.C = true;
|
21065 | node = parent;
|
21066 | parent = parent.U;
|
21067 | } while (!node.C);
|
21068 |
|
21069 | if (node) node.C = false;
|
21070 | }
|
21071 | };
|
21072 |
|
21073 | function RedBlackRotateLeft(tree, node) {
|
21074 | var p = node,
|
21075 | q = node.R,
|
21076 | parent = p.U;
|
21077 |
|
21078 | if (parent) {
|
21079 | if (parent.L === p) parent.L = q;
|
21080 | else parent.R = q;
|
21081 | } else {
|
21082 | tree._ = q;
|
21083 | }
|
21084 |
|
21085 | q.U = parent;
|
21086 | p.U = q;
|
21087 | p.R = q.L;
|
21088 | if (p.R) p.R.U = p;
|
21089 | q.L = p;
|
21090 | }
|
21091 |
|
21092 | function RedBlackRotateRight(tree, node) {
|
21093 | var p = node,
|
21094 | q = node.L,
|
21095 | parent = p.U;
|
21096 |
|
21097 | if (parent) {
|
21098 | if (parent.L === p) parent.L = q;
|
21099 | else parent.R = q;
|
21100 | } else {
|
21101 | tree._ = q;
|
21102 | }
|
21103 |
|
21104 | q.U = parent;
|
21105 | p.U = q;
|
21106 | p.L = q.R;
|
21107 | if (p.L) p.L.U = p;
|
21108 | q.R = p;
|
21109 | }
|
21110 |
|
21111 | function RedBlackFirst(node) {
|
21112 | while (node.L) node = node.L;
|
21113 | return node;
|
21114 | }
|
21115 |
|
21116 | function createEdge(left, right, v0, v1) {
|
21117 | var edge = [null, null],
|
21118 | index = edges.push(edge) - 1;
|
21119 | edge.left = left;
|
21120 | edge.right = right;
|
21121 | if (v0) setEdgeEnd(edge, left, right, v0);
|
21122 | if (v1) setEdgeEnd(edge, right, left, v1);
|
21123 | cells[left.index].halfedges.push(index);
|
21124 | cells[right.index].halfedges.push(index);
|
21125 | return edge;
|
21126 | }
|
21127 |
|
21128 | function createBorderEdge(left, v0, v1) {
|
21129 | var edge = [v0, v1];
|
21130 | edge.left = left;
|
21131 | return edge;
|
21132 | }
|
21133 |
|
21134 | function setEdgeEnd(edge, left, right, vertex) {
|
21135 | if (!edge[0] && !edge[1]) {
|
21136 | edge[0] = vertex;
|
21137 | edge.left = left;
|
21138 | edge.right = right;
|
21139 | } else if (edge.left === right) {
|
21140 | edge[1] = vertex;
|
21141 | } else {
|
21142 | edge[0] = vertex;
|
21143 | }
|
21144 | }
|
21145 |
|
21146 |
|
21147 | function clipEdge(edge, x0, y0, x1, y1) {
|
21148 | var a = edge[0],
|
21149 | b = edge[1],
|
21150 | ax = a[0],
|
21151 | ay = a[1],
|
21152 | bx = b[0],
|
21153 | by = b[1],
|
21154 | t0 = 0,
|
21155 | t1 = 1,
|
21156 | dx = bx - ax,
|
21157 | dy = by - ay,
|
21158 | r;
|
21159 |
|
21160 | r = x0 - ax;
|
21161 | if (!dx && r > 0) return;
|
21162 | r /= dx;
|
21163 | if (dx < 0) {
|
21164 | if (r < t0) return;
|
21165 | if (r < t1) t1 = r;
|
21166 | } else if (dx > 0) {
|
21167 | if (r > t1) return;
|
21168 | if (r > t0) t0 = r;
|
21169 | }
|
21170 |
|
21171 | r = x1 - ax;
|
21172 | if (!dx && r < 0) return;
|
21173 | r /= dx;
|
21174 | if (dx < 0) {
|
21175 | if (r > t1) return;
|
21176 | if (r > t0) t0 = r;
|
21177 | } else if (dx > 0) {
|
21178 | if (r < t0) return;
|
21179 | if (r < t1) t1 = r;
|
21180 | }
|
21181 |
|
21182 | r = y0 - ay;
|
21183 | if (!dy && r > 0) return;
|
21184 | r /= dy;
|
21185 | if (dy < 0) {
|
21186 | if (r < t0) return;
|
21187 | if (r < t1) t1 = r;
|
21188 | } else if (dy > 0) {
|
21189 | if (r > t1) return;
|
21190 | if (r > t0) t0 = r;
|
21191 | }
|
21192 |
|
21193 | r = y1 - ay;
|
21194 | if (!dy && r < 0) return;
|
21195 | r /= dy;
|
21196 | if (dy < 0) {
|
21197 | if (r > t1) return;
|
21198 | if (r > t0) t0 = r;
|
21199 | } else if (dy > 0) {
|
21200 | if (r < t0) return;
|
21201 | if (r < t1) t1 = r;
|
21202 | }
|
21203 |
|
21204 | if (!(t0 > 0) && !(t1 < 1)) return true;
|
21205 |
|
21206 | if (t0 > 0) edge[0] = [ax + t0 * dx, ay + t0 * dy];
|
21207 | if (t1 < 1) edge[1] = [ax + t1 * dx, ay + t1 * dy];
|
21208 | return true;
|
21209 | }
|
21210 |
|
21211 | function connectEdge(edge, x0, y0, x1, y1) {
|
21212 | var v1 = edge[1];
|
21213 | if (v1) return true;
|
21214 |
|
21215 | var v0 = edge[0],
|
21216 | left = edge.left,
|
21217 | right = edge.right,
|
21218 | lx = left[0],
|
21219 | ly = left[1],
|
21220 | rx = right[0],
|
21221 | ry = right[1],
|
21222 | fx = (lx + rx) / 2,
|
21223 | fy = (ly + ry) / 2,
|
21224 | fm,
|
21225 | fb;
|
21226 |
|
21227 | if (ry === ly) {
|
21228 | if (fx < x0 || fx >= x1) return;
|
21229 | if (lx > rx) {
|
21230 | if (!v0) v0 = [fx, y0];
|
21231 | else if (v0[1] >= y1) return;
|
21232 | v1 = [fx, y1];
|
21233 | } else {
|
21234 | if (!v0) v0 = [fx, y1];
|
21235 | else if (v0[1] < y0) return;
|
21236 | v1 = [fx, y0];
|
21237 | }
|
21238 | } else {
|
21239 | fm = (lx - rx) / (ry - ly);
|
21240 | fb = fy - fm * fx;
|
21241 | if (fm < -1 || fm > 1) {
|
21242 | if (lx > rx) {
|
21243 | if (!v0) v0 = [(y0 - fb) / fm, y0];
|
21244 | else if (v0[1] >= y1) return;
|
21245 | v1 = [(y1 - fb) / fm, y1];
|
21246 | } else {
|
21247 | if (!v0) v0 = [(y1 - fb) / fm, y1];
|
21248 | else if (v0[1] < y0) return;
|
21249 | v1 = [(y0 - fb) / fm, y0];
|
21250 | }
|
21251 | } else {
|
21252 | if (ly < ry) {
|
21253 | if (!v0) v0 = [x0, fm * x0 + fb];
|
21254 | else if (v0[0] >= x1) return;
|
21255 | v1 = [x1, fm * x1 + fb];
|
21256 | } else {
|
21257 | if (!v0) v0 = [x1, fm * x1 + fb];
|
21258 | else if (v0[0] < x0) return;
|
21259 | v1 = [x0, fm * x0 + fb];
|
21260 | }
|
21261 | }
|
21262 | }
|
21263 |
|
21264 | edge[0] = v0;
|
21265 | edge[1] = v1;
|
21266 | return true;
|
21267 | }
|
21268 |
|
21269 | function clipEdges(x0, y0, x1, y1) {
|
21270 | var i = edges.length,
|
21271 | edge;
|
21272 |
|
21273 | while (i--) {
|
21274 | if (!connectEdge(edge = edges[i], x0, y0, x1, y1)
|
21275 | || !clipEdge(edge, x0, y0, x1, y1)
|
21276 | || !(Math.abs(edge[0][0] - edge[1][0]) > epsilon
|
21277 | || Math.abs(edge[0][1] - edge[1][1]) > epsilon)) {
|
21278 | delete edges[i];
|
21279 | }
|
21280 | }
|
21281 | }
|
21282 |
|
21283 | function createCell(site) {
|
21284 | return cells[site.index] = {
|
21285 | site: site,
|
21286 | halfedges: []
|
21287 | };
|
21288 | }
|
21289 |
|
21290 | function cellHalfedgeAngle(cell, edge) {
|
21291 | var site = cell.site,
|
21292 | va = edge.left,
|
21293 | vb = edge.right;
|
21294 | if (site === vb) vb = va, va = site;
|
21295 | if (vb) return Math.atan2(vb[1] - va[1], vb[0] - va[0]);
|
21296 | if (site === va) va = edge[1], vb = edge[0];
|
21297 | else va = edge[0], vb = edge[1];
|
21298 | return Math.atan2(va[0] - vb[0], vb[1] - va[1]);
|
21299 | }
|
21300 |
|
21301 | function cellHalfedgeStart(cell, edge) {
|
21302 | return edge[+(edge.left !== cell.site)];
|
21303 | }
|
21304 |
|
21305 | function cellHalfedgeEnd(cell, edge) {
|
21306 | return edge[+(edge.left === cell.site)];
|
21307 | }
|
21308 |
|
21309 | function sortCellHalfedges() {
|
21310 | for (var i = 0, n = cells.length, cell, halfedges, j, m; i < n; ++i) {
|
21311 | if ((cell = cells[i]) && (m = (halfedges = cell.halfedges).length)) {
|
21312 | var index = new Array(m),
|
21313 | array = new Array(m);
|
21314 | for (j = 0; j < m; ++j) index[j] = j, array[j] = cellHalfedgeAngle(cell, edges[halfedges[j]]);
|
21315 | index.sort(function(i, j) { return array[j] - array[i]; });
|
21316 | for (j = 0; j < m; ++j) array[j] = halfedges[index[j]];
|
21317 | for (j = 0; j < m; ++j) halfedges[j] = array[j];
|
21318 | }
|
21319 | }
|
21320 | }
|
21321 |
|
21322 | function clipCells(x0, y0, x1, y1) {
|
21323 | var nCells = cells.length,
|
21324 | iCell,
|
21325 | cell,
|
21326 | site,
|
21327 | iHalfedge,
|
21328 | halfedges,
|
21329 | nHalfedges,
|
21330 | start,
|
21331 | startX,
|
21332 | startY,
|
21333 | end,
|
21334 | endX,
|
21335 | endY,
|
21336 | cover = true;
|
21337 |
|
21338 | for (iCell = 0; iCell < nCells; ++iCell) {
|
21339 | if (cell = cells[iCell]) {
|
21340 | site = cell.site;
|
21341 | halfedges = cell.halfedges;
|
21342 | iHalfedge = halfedges.length;
|
21343 |
|
21344 |
|
21345 | while (iHalfedge--) {
|
21346 | if (!edges[halfedges[iHalfedge]]) {
|
21347 | halfedges.splice(iHalfedge, 1);
|
21348 | }
|
21349 | }
|
21350 |
|
21351 |
|
21352 | iHalfedge = 0, nHalfedges = halfedges.length;
|
21353 | while (iHalfedge < nHalfedges) {
|
21354 | end = cellHalfedgeEnd(cell, edges[halfedges[iHalfedge]]), endX = end[0], endY = end[1];
|
21355 | start = cellHalfedgeStart(cell, edges[halfedges[++iHalfedge % nHalfedges]]), startX = start[0], startY = start[1];
|
21356 | if (Math.abs(endX - startX) > epsilon || Math.abs(endY - startY) > epsilon) {
|
21357 | halfedges.splice(iHalfedge, 0, edges.push(createBorderEdge(site, end,
|
21358 | Math.abs(endX - x0) < epsilon && y1 - endY > epsilon ? [x0, Math.abs(startX - x0) < epsilon ? startY : y1]
|
21359 | : Math.abs(endY - y1) < epsilon && x1 - endX > epsilon ? [Math.abs(startY - y1) < epsilon ? startX : x1, y1]
|
21360 | : Math.abs(endX - x1) < epsilon && endY - y0 > epsilon ? [x1, Math.abs(startX - x1) < epsilon ? startY : y0]
|
21361 | : Math.abs(endY - y0) < epsilon && endX - x0 > epsilon ? [Math.abs(startY - y0) < epsilon ? startX : x0, y0]
|
21362 | : null)) - 1);
|
21363 | ++nHalfedges;
|
21364 | }
|
21365 | }
|
21366 |
|
21367 | if (nHalfedges) cover = false;
|
21368 | }
|
21369 | }
|
21370 |
|
21371 |
|
21372 |
|
21373 | if (cover) {
|
21374 | var dx, dy, d2, dc = Infinity;
|
21375 |
|
21376 | for (iCell = 0, cover = null; iCell < nCells; ++iCell) {
|
21377 | if (cell = cells[iCell]) {
|
21378 | site = cell.site;
|
21379 | dx = site[0] - x0;
|
21380 | dy = site[1] - y0;
|
21381 | d2 = dx * dx + dy * dy;
|
21382 | if (d2 < dc) dc = d2, cover = cell;
|
21383 | }
|
21384 | }
|
21385 |
|
21386 | if (cover) {
|
21387 | var v00 = [x0, y0], v01 = [x0, y1], v11 = [x1, y1], v10 = [x1, y0];
|
21388 | cover.halfedges.push(
|
21389 | edges.push(createBorderEdge(site = cover.site, v00, v01)) - 1,
|
21390 | edges.push(createBorderEdge(site, v01, v11)) - 1,
|
21391 | edges.push(createBorderEdge(site, v11, v10)) - 1,
|
21392 | edges.push(createBorderEdge(site, v10, v00)) - 1
|
21393 | );
|
21394 | }
|
21395 | }
|
21396 |
|
21397 |
|
21398 | for (iCell = 0; iCell < nCells; ++iCell) {
|
21399 | if (cell = cells[iCell]) {
|
21400 | if (!cell.halfedges.length) {
|
21401 | delete cells[iCell];
|
21402 | }
|
21403 | }
|
21404 | }
|
21405 | }
|
21406 |
|
21407 | var circlePool = [];
|
21408 |
|
21409 | var firstCircle;
|
21410 |
|
21411 | function Circle() {
|
21412 | RedBlackNode(this);
|
21413 | this.x =
|
21414 | this.y =
|
21415 | this.arc =
|
21416 | this.site =
|
21417 | this.cy = null;
|
21418 | }
|
21419 |
|
21420 | function attachCircle(arc) {
|
21421 | var lArc = arc.P,
|
21422 | rArc = arc.N;
|
21423 |
|
21424 | if (!lArc || !rArc) return;
|
21425 |
|
21426 | var lSite = lArc.site,
|
21427 | cSite = arc.site,
|
21428 | rSite = rArc.site;
|
21429 |
|
21430 | if (lSite === rSite) return;
|
21431 |
|
21432 | var bx = cSite[0],
|
21433 | by = cSite[1],
|
21434 | ax = lSite[0] - bx,
|
21435 | ay = lSite[1] - by,
|
21436 | cx = rSite[0] - bx,
|
21437 | cy = rSite[1] - by;
|
21438 |
|
21439 | var d = 2 * (ax * cy - ay * cx);
|
21440 | if (d >= -epsilon2) return;
|
21441 |
|
21442 | var ha = ax * ax + ay * ay,
|
21443 | hc = cx * cx + cy * cy,
|
21444 | x = (cy * ha - ay * hc) / d,
|
21445 | y = (ax * hc - cx * ha) / d;
|
21446 |
|
21447 | var circle = circlePool.pop() || new Circle;
|
21448 | circle.arc = arc;
|
21449 | circle.site = cSite;
|
21450 | circle.x = x + bx;
|
21451 | circle.y = (circle.cy = y + by) + Math.sqrt(x * x + y * y);
|
21452 |
|
21453 | arc.circle = circle;
|
21454 |
|
21455 | var before = null,
|
21456 | node = circles._;
|
21457 |
|
21458 | while (node) {
|
21459 | if (circle.y < node.y || (circle.y === node.y && circle.x <= node.x)) {
|
21460 | if (node.L) node = node.L;
|
21461 | else { before = node.P; break; }
|
21462 | } else {
|
21463 | if (node.R) node = node.R;
|
21464 | else { before = node; break; }
|
21465 | }
|
21466 | }
|
21467 |
|
21468 | circles.insert(before, circle);
|
21469 | if (!before) firstCircle = circle;
|
21470 | }
|
21471 |
|
21472 | function detachCircle(arc) {
|
21473 | var circle = arc.circle;
|
21474 | if (circle) {
|
21475 | if (!circle.P) firstCircle = circle.N;
|
21476 | circles.remove(circle);
|
21477 | circlePool.push(circle);
|
21478 | RedBlackNode(circle);
|
21479 | arc.circle = null;
|
21480 | }
|
21481 | }
|
21482 |
|
21483 | var beachPool = [];
|
21484 |
|
21485 | function Beach() {
|
21486 | RedBlackNode(this);
|
21487 | this.edge =
|
21488 | this.site =
|
21489 | this.circle = null;
|
21490 | }
|
21491 |
|
21492 | function createBeach(site) {
|
21493 | var beach = beachPool.pop() || new Beach;
|
21494 | beach.site = site;
|
21495 | return beach;
|
21496 | }
|
21497 |
|
21498 | function detachBeach(beach) {
|
21499 | detachCircle(beach);
|
21500 | beaches.remove(beach);
|
21501 | beachPool.push(beach);
|
21502 | RedBlackNode(beach);
|
21503 | }
|
21504 |
|
21505 | function removeBeach(beach) {
|
21506 | var circle = beach.circle,
|
21507 | x = circle.x,
|
21508 | y = circle.cy,
|
21509 | vertex = [x, y],
|
21510 | previous = beach.P,
|
21511 | next = beach.N,
|
21512 | disappearing = [beach];
|
21513 |
|
21514 | detachBeach(beach);
|
21515 |
|
21516 | var lArc = previous;
|
21517 | while (lArc.circle
|
21518 | && Math.abs(x - lArc.circle.x) < epsilon
|
21519 | && Math.abs(y - lArc.circle.cy) < epsilon) {
|
21520 | previous = lArc.P;
|
21521 | disappearing.unshift(lArc);
|
21522 | detachBeach(lArc);
|
21523 | lArc = previous;
|
21524 | }
|
21525 |
|
21526 | disappearing.unshift(lArc);
|
21527 | detachCircle(lArc);
|
21528 |
|
21529 | var rArc = next;
|
21530 | while (rArc.circle
|
21531 | && Math.abs(x - rArc.circle.x) < epsilon
|
21532 | && Math.abs(y - rArc.circle.cy) < epsilon) {
|
21533 | next = rArc.N;
|
21534 | disappearing.push(rArc);
|
21535 | detachBeach(rArc);
|
21536 | rArc = next;
|
21537 | }
|
21538 |
|
21539 | disappearing.push(rArc);
|
21540 | detachCircle(rArc);
|
21541 |
|
21542 | var nArcs = disappearing.length,
|
21543 | iArc;
|
21544 | for (iArc = 1; iArc < nArcs; ++iArc) {
|
21545 | rArc = disappearing[iArc];
|
21546 | lArc = disappearing[iArc - 1];
|
21547 | setEdgeEnd(rArc.edge, lArc.site, rArc.site, vertex);
|
21548 | }
|
21549 |
|
21550 | lArc = disappearing[0];
|
21551 | rArc = disappearing[nArcs - 1];
|
21552 | rArc.edge = createEdge(lArc.site, rArc.site, null, vertex);
|
21553 |
|
21554 | attachCircle(lArc);
|
21555 | attachCircle(rArc);
|
21556 | }
|
21557 |
|
21558 | function addBeach(site) {
|
21559 | var x = site[0],
|
21560 | directrix = site[1],
|
21561 | lArc,
|
21562 | rArc,
|
21563 | dxl,
|
21564 | dxr,
|
21565 | node = beaches._;
|
21566 |
|
21567 | while (node) {
|
21568 | dxl = leftBreakPoint(node, directrix) - x;
|
21569 | if (dxl > epsilon) node = node.L; else {
|
21570 | dxr = x - rightBreakPoint(node, directrix);
|
21571 | if (dxr > epsilon) {
|
21572 | if (!node.R) {
|
21573 | lArc = node;
|
21574 | break;
|
21575 | }
|
21576 | node = node.R;
|
21577 | } else {
|
21578 | if (dxl > -epsilon) {
|
21579 | lArc = node.P;
|
21580 | rArc = node;
|
21581 | } else if (dxr > -epsilon) {
|
21582 | lArc = node;
|
21583 | rArc = node.N;
|
21584 | } else {
|
21585 | lArc = rArc = node;
|
21586 | }
|
21587 | break;
|
21588 | }
|
21589 | }
|
21590 | }
|
21591 |
|
21592 | createCell(site);
|
21593 | var newArc = createBeach(site);
|
21594 | beaches.insert(lArc, newArc);
|
21595 |
|
21596 | if (!lArc && !rArc) return;
|
21597 |
|
21598 | if (lArc === rArc) {
|
21599 | detachCircle(lArc);
|
21600 | rArc = createBeach(lArc.site);
|
21601 | beaches.insert(newArc, rArc);
|
21602 | newArc.edge = rArc.edge = createEdge(lArc.site, newArc.site);
|
21603 | attachCircle(lArc);
|
21604 | attachCircle(rArc);
|
21605 | return;
|
21606 | }
|
21607 |
|
21608 | if (!rArc) {
|
21609 | newArc.edge = createEdge(lArc.site, newArc.site);
|
21610 | return;
|
21611 | }
|
21612 |
|
21613 |
|
21614 | detachCircle(lArc);
|
21615 | detachCircle(rArc);
|
21616 |
|
21617 | var lSite = lArc.site,
|
21618 | ax = lSite[0],
|
21619 | ay = lSite[1],
|
21620 | bx = site[0] - ax,
|
21621 | by = site[1] - ay,
|
21622 | rSite = rArc.site,
|
21623 | cx = rSite[0] - ax,
|
21624 | cy = rSite[1] - ay,
|
21625 | d = 2 * (bx * cy - by * cx),
|
21626 | hb = bx * bx + by * by,
|
21627 | hc = cx * cx + cy * cy,
|
21628 | vertex = [(cy * hb - by * hc) / d + ax, (bx * hc - cx * hb) / d + ay];
|
21629 |
|
21630 | setEdgeEnd(rArc.edge, lSite, rSite, vertex);
|
21631 | newArc.edge = createEdge(lSite, site, null, vertex);
|
21632 | rArc.edge = createEdge(site, rSite, null, vertex);
|
21633 | attachCircle(lArc);
|
21634 | attachCircle(rArc);
|
21635 | }
|
21636 |
|
21637 | function leftBreakPoint(arc, directrix) {
|
21638 | var site = arc.site,
|
21639 | rfocx = site[0],
|
21640 | rfocy = site[1],
|
21641 | pby2 = rfocy - directrix;
|
21642 |
|
21643 | if (!pby2) return rfocx;
|
21644 |
|
21645 | var lArc = arc.P;
|
21646 | if (!lArc) return -Infinity;
|
21647 |
|
21648 | site = lArc.site;
|
21649 | var lfocx = site[0],
|
21650 | lfocy = site[1],
|
21651 | plby2 = lfocy - directrix;
|
21652 |
|
21653 | if (!plby2) return lfocx;
|
21654 |
|
21655 | var hl = lfocx - rfocx,
|
21656 | aby2 = 1 / pby2 - 1 / plby2,
|
21657 | b = hl / plby2;
|
21658 |
|
21659 | if (aby2) return (-b + Math.sqrt(b * b - 2 * aby2 * (hl * hl / (-2 * plby2) - lfocy + plby2 / 2 + rfocy - pby2 / 2))) / aby2 + rfocx;
|
21660 |
|
21661 | return (rfocx + lfocx) / 2;
|
21662 | }
|
21663 |
|
21664 | function rightBreakPoint(arc, directrix) {
|
21665 | var rArc = arc.N;
|
21666 | if (rArc) return leftBreakPoint(rArc, directrix);
|
21667 | var site = arc.site;
|
21668 | return site[1] === directrix ? site[0] : Infinity;
|
21669 | }
|
21670 |
|
21671 | var epsilon = 1e-6;
|
21672 | var epsilon2 = 1e-12;
|
21673 | var beaches;
|
21674 | var cells;
|
21675 | var circles;
|
21676 | var edges;
|
21677 |
|
21678 | function triangleArea(a, b, c) {
|
21679 | return (a[0] - c[0]) * (b[1] - a[1]) - (a[0] - b[0]) * (c[1] - a[1]);
|
21680 | }
|
21681 |
|
21682 | function lexicographic(a, b) {
|
21683 | return b[1] - a[1]
|
21684 | || b[0] - a[0];
|
21685 | }
|
21686 |
|
21687 | function Diagram(sites, extent) {
|
21688 | var site = sites.sort(lexicographic).pop(),
|
21689 | x,
|
21690 | y,
|
21691 | circle;
|
21692 |
|
21693 | edges = [];
|
21694 | cells = new Array(sites.length);
|
21695 | beaches = new RedBlackTree;
|
21696 | circles = new RedBlackTree;
|
21697 |
|
21698 | while (true) {
|
21699 | circle = firstCircle;
|
21700 | if (site && (!circle || site[1] < circle.y || (site[1] === circle.y && site[0] < circle.x))) {
|
21701 | if (site[0] !== x || site[1] !== y) {
|
21702 | addBeach(site);
|
21703 | x = site[0], y = site[1];
|
21704 | }
|
21705 | site = sites.pop();
|
21706 | } else if (circle) {
|
21707 | removeBeach(circle.arc);
|
21708 | } else {
|
21709 | break;
|
21710 | }
|
21711 | }
|
21712 |
|
21713 | sortCellHalfedges();
|
21714 |
|
21715 | if (extent) {
|
21716 | var x0 = +extent[0][0],
|
21717 | y0 = +extent[0][1],
|
21718 | x1 = +extent[1][0],
|
21719 | y1 = +extent[1][1];
|
21720 | clipEdges(x0, y0, x1, y1);
|
21721 | clipCells(x0, y0, x1, y1);
|
21722 | }
|
21723 |
|
21724 | this.edges = edges;
|
21725 | this.cells = cells;
|
21726 |
|
21727 | beaches =
|
21728 | circles =
|
21729 | edges =
|
21730 | cells = null;
|
21731 | }
|
21732 |
|
21733 | Diagram.prototype = {
|
21734 | constructor: Diagram,
|
21735 |
|
21736 | polygons: function() {
|
21737 | var edges = this.edges;
|
21738 |
|
21739 | return this.cells.map(function(cell) {
|
21740 | var polygon = cell.halfedges.map(function(i) { return cellHalfedgeStart(cell, edges[i]); });
|
21741 | polygon.data = cell.site.data;
|
21742 | return polygon;
|
21743 | });
|
21744 | },
|
21745 |
|
21746 | triangles: function() {
|
21747 | var triangles = [],
|
21748 | edges = this.edges;
|
21749 |
|
21750 | this.cells.forEach(function(cell, i) {
|
21751 | if (!(m = (halfedges = cell.halfedges).length)) return;
|
21752 | var site = cell.site,
|
21753 | halfedges,
|
21754 | j = -1,
|
21755 | m,
|
21756 | s0,
|
21757 | e1 = edges[halfedges[m - 1]],
|
21758 | s1 = e1.left === site ? e1.right : e1.left;
|
21759 |
|
21760 | while (++j < m) {
|
21761 | s0 = s1;
|
21762 | e1 = edges[halfedges[j]];
|
21763 | s1 = e1.left === site ? e1.right : e1.left;
|
21764 | if (s0 && s1 && i < s0.index && i < s1.index && triangleArea(site, s0, s1) < 0) {
|
21765 | triangles.push([site.data, s0.data, s1.data]);
|
21766 | }
|
21767 | }
|
21768 | });
|
21769 |
|
21770 | return triangles;
|
21771 | },
|
21772 |
|
21773 | links: function() {
|
21774 | return this.edges.filter(function(edge) {
|
21775 | return edge.right;
|
21776 | }).map(function(edge) {
|
21777 | return {
|
21778 | source: edge.left.data,
|
21779 | target: edge.right.data
|
21780 | };
|
21781 | });
|
21782 | },
|
21783 |
|
21784 | find: function(x, y, radius) {
|
21785 | var that = this, i0, i1 = that._found || 0, n = that.cells.length, cell;
|
21786 |
|
21787 |
|
21788 | while (!(cell = that.cells[i1])) if (++i1 >= n) return null;
|
21789 | var dx = x - cell.site[0], dy = y - cell.site[1], d2 = dx * dx + dy * dy;
|
21790 |
|
21791 |
|
21792 | do {
|
21793 | cell = that.cells[i0 = i1], i1 = null;
|
21794 | cell.halfedges.forEach(function(e) {
|
21795 | var edge = that.edges[e], v = edge.left;
|
21796 | if ((v === cell.site || !v) && !(v = edge.right)) return;
|
21797 | var vx = x - v[0], vy = y - v[1], v2 = vx * vx + vy * vy;
|
21798 | if (v2 < d2) d2 = v2, i1 = v.index;
|
21799 | });
|
21800 | } while (i1 !== null);
|
21801 |
|
21802 | that._found = i0;
|
21803 |
|
21804 | return radius == null || d2 <= radius * radius ? cell.site : null;
|
21805 | }
|
21806 | };
|
21807 |
|
21808 | var voronoi = function() {
|
21809 | var x$$1 = x,
|
21810 | y$$1 = y,
|
21811 | extent = null;
|
21812 |
|
21813 | function voronoi(data) {
|
21814 | return new Diagram(data.map(function(d, i) {
|
21815 | var s = [Math.round(x$$1(d, i, data) / epsilon) * epsilon, Math.round(y$$1(d, i, data) / epsilon) * epsilon];
|
21816 | s.index = i;
|
21817 | s.data = d;
|
21818 | return s;
|
21819 | }), extent);
|
21820 | }
|
21821 |
|
21822 | voronoi.polygons = function(data) {
|
21823 | return voronoi(data).polygons();
|
21824 | };
|
21825 |
|
21826 | voronoi.links = function(data) {
|
21827 | return voronoi(data).links();
|
21828 | };
|
21829 |
|
21830 | voronoi.triangles = function(data) {
|
21831 | return voronoi(data).triangles();
|
21832 | };
|
21833 |
|
21834 | voronoi.x = function(_) {
|
21835 | return arguments.length ? (x$$1 = typeof _ === "function" ? _ : constant(+_), voronoi) : x$$1;
|
21836 | };
|
21837 |
|
21838 | voronoi.y = function(_) {
|
21839 | return arguments.length ? (y$$1 = typeof _ === "function" ? _ : constant(+_), voronoi) : y$$1;
|
21840 | };
|
21841 |
|
21842 | voronoi.extent = function(_) {
|
21843 | return arguments.length ? (extent = _ == null ? null : [[+_[0][0], +_[0][1]], [+_[1][0], +_[1][1]]], voronoi) : extent && [[extent[0][0], extent[0][1]], [extent[1][0], extent[1][1]]];
|
21844 | };
|
21845 |
|
21846 | voronoi.size = function(_) {
|
21847 | return arguments.length ? (extent = _ == null ? null : [[0, 0], [+_[0], +_[1]]], voronoi) : extent && [extent[1][0] - extent[0][0], extent[1][1] - extent[0][1]];
|
21848 | };
|
21849 |
|
21850 | return voronoi;
|
21851 | };
|
21852 |
|
21853 |
|
21854 |
|
21855 |
|
21856 |
|
21857 |
|
21858 | function coordsToPolygon(coords) {
|
21859 | coords = coords.slice();
|
21860 | coords.push(coords[0]);
|
21861 | return polygon([coords]);
|
21862 | }
|
21863 |
|
21864 |
|
21865 |
|
21866 |
|
21867 |
|
21868 |
|
21869 |
|
21870 |
|
21871 |
|
21872 |
|
21873 |
|
21874 |
|
21875 |
|
21876 |
|
21877 |
|
21878 |
|
21879 |
|
21880 |
|
21881 |
|
21882 |
|
21883 |
|
21884 |
|
21885 | function voronoi$1(points$$1, options) {
|
21886 |
|
21887 | options = options || {};
|
21888 | if (!isObject(options)) throw new Error('options is invalid');
|
21889 | var bbox = options.bbox || [-180, -85, 180, 85];
|
21890 |
|
21891 |
|
21892 | if (!points$$1) throw new Error('points is required');
|
21893 | if (!Array.isArray(bbox)) throw new Error('bbox is invalid');
|
21894 | collectionOf(points$$1, 'Point', 'points');
|
21895 |
|
21896 |
|
21897 | return featureCollection(
|
21898 | voronoi()
|
21899 | .x(function (feature$$1) { return feature$$1.geometry.coordinates[0]; })
|
21900 | .y(function (feature$$1) { return feature$$1.geometry.coordinates[1]; })
|
21901 | .extent([[bbox[0], bbox[1]], [bbox[2], bbox[3]]])
|
21902 | .polygons(points$$1.features)
|
21903 | .map(coordsToPolygon)
|
21904 | );
|
21905 | }
|
21906 |
|
21907 |
|
21908 |
|
21909 |
|
21910 |
|
21911 |
|
21912 |
|
21913 |
|
21914 |
|
21915 |
|
21916 |
|
21917 |
|
21918 |
|
21919 |
|
21920 |
|
21921 |
|
21922 |
|
21923 |
|
21924 |
|
21925 |
|
21926 |
|
21927 |
|
21928 |
|
21929 | function ellipse(center, xSemiAxis, ySemiAxis, options) {
|
21930 |
|
21931 | options = options || {};
|
21932 | var steps = options.steps || 64;
|
21933 | var units = options.units || 'kilometers';
|
21934 | var angle = options.angle || 0;
|
21935 | var pivot = options.pivot || center;
|
21936 | var properties = options.properties || center.properties || {};
|
21937 |
|
21938 |
|
21939 | if (!center) throw new Error('center is required');
|
21940 | if (!xSemiAxis) throw new Error('xSemiAxis is required');
|
21941 | if (!ySemiAxis) throw new Error('ySemiAxis is required');
|
21942 | if (!isObject(options)) throw new Error('options must be an object');
|
21943 | if (!isNumber(steps)) throw new Error('steps must be a number');
|
21944 | if (!isNumber(angle)) throw new Error('angle must be a number');
|
21945 |
|
21946 | var centerCoords = getCoord(center);
|
21947 | if (units === 'degrees') {
|
21948 | var angleRad = degreesToRadians(angle);
|
21949 | } else {
|
21950 | xSemiAxis = rhumbDestination(center, xSemiAxis, 90, {units: units});
|
21951 | ySemiAxis = rhumbDestination(center, ySemiAxis, 0, {units: units});
|
21952 | xSemiAxis = getCoord(xSemiAxis)[0] - centerCoords[0];
|
21953 | ySemiAxis = getCoord(ySemiAxis)[1] - centerCoords[1];
|
21954 | }
|
21955 |
|
21956 | var coordinates = [];
|
21957 | for (var i = 0; i < steps; i += 1) {
|
21958 | var stepAngle = i * -360 / steps;
|
21959 | var x = ((xSemiAxis * ySemiAxis) / Math.sqrt(Math.pow(ySemiAxis, 2) + (Math.pow(xSemiAxis, 2) * Math.pow(getTanDeg(stepAngle), 2))));
|
21960 | var y = ((xSemiAxis * ySemiAxis) / Math.sqrt(Math.pow(xSemiAxis, 2) + (Math.pow(ySemiAxis, 2) / Math.pow(getTanDeg(stepAngle), 2))));
|
21961 |
|
21962 | if (stepAngle < -90 && stepAngle >= -270) x = -x;
|
21963 | if (stepAngle < -180 && stepAngle >= -360) y = -y;
|
21964 | if (units === 'degrees') {
|
21965 | var newx = x * Math.cos(angleRad) + y * Math.sin(angleRad);
|
21966 | var newy = y * Math.cos(angleRad) - x * Math.sin(angleRad);
|
21967 | x = newx;
|
21968 | y = newy;
|
21969 | }
|
21970 |
|
21971 | coordinates.push([x + centerCoords[0], y + centerCoords[1]]);
|
21972 | }
|
21973 | coordinates.push(coordinates[0]);
|
21974 | if (units === 'degrees') {
|
21975 | return polygon([coordinates], properties);
|
21976 | } else {
|
21977 | return transformRotate(polygon([coordinates], properties), angle, { pivot: pivot });
|
21978 | }
|
21979 | }
|
21980 |
|
21981 |
|
21982 |
|
21983 |
|
21984 |
|
21985 |
|
21986 |
|
21987 |
|
21988 | function getTanDeg(deg) {
|
21989 | var rad = deg * Math.PI / 180;
|
21990 | return Math.tan(rad);
|
21991 | }
|
21992 |
|
21993 |
|
21994 |
|
21995 |
|
21996 |
|
21997 |
|
21998 |
|
21999 |
|
22000 |
|
22001 |
|
22002 |
|
22003 |
|
22004 |
|
22005 |
|
22006 |
|
22007 |
|
22008 |
|
22009 |
|
22010 |
|
22011 |
|
22012 |
|
22013 |
|
22014 |
|
22015 |
|
22016 |
|
22017 | function centerMean(geojson, options) {
|
22018 |
|
22019 | options = options || {};
|
22020 | if (!isObject(options)) throw new Error('options is invalid');
|
22021 | var properties = options.properties;
|
22022 | var weightTerm = options.weight;
|
22023 |
|
22024 |
|
22025 | if (!geojson) throw new Error('geojson is required');
|
22026 |
|
22027 | var sumXs = 0;
|
22028 | var sumYs = 0;
|
22029 | var sumNs = 0;
|
22030 | geomEach(geojson, function (geom, featureIndex, properties) {
|
22031 | var weight = properties[weightTerm];
|
22032 | weight = (weight === undefined || weight === null) ? 1 : weight;
|
22033 | if (!isNumber(weight)) throw new Error('weight value must be a number for feature index ' + featureIndex);
|
22034 | weight = Number(weight);
|
22035 | if (weight > 0) {
|
22036 | coordEach(geom, function (coord) {
|
22037 | sumXs += coord[0] * weight;
|
22038 | sumYs += coord[1] * weight;
|
22039 | sumNs += weight;
|
22040 | });
|
22041 | }
|
22042 | });
|
22043 | return point([sumXs / sumNs, sumYs / sumNs], properties);
|
22044 | }
|
22045 |
|
22046 |
|
22047 |
|
22048 |
|
22049 |
|
22050 |
|
22051 |
|
22052 |
|
22053 |
|
22054 |
|
22055 |
|
22056 |
|
22057 |
|
22058 |
|
22059 |
|
22060 |
|
22061 |
|
22062 |
|
22063 |
|
22064 |
|
22065 |
|
22066 |
|
22067 |
|
22068 |
|
22069 |
|
22070 |
|
22071 |
|
22072 |
|
22073 |
|
22074 |
|
22075 |
|
22076 |
|
22077 |
|
22078 |
|
22079 |
|
22080 |
|
22081 |
|
22082 |
|
22083 |
|
22084 |
|
22085 |
|
22086 |
|
22087 |
|
22088 |
|
22089 |
|
22090 |
|
22091 |
|
22092 |
|
22093 |
|
22094 |
|
22095 |
|
22096 |
|
22097 |
|
22098 | function centerMedian(features, options) {
|
22099 |
|
22100 | options = options || {};
|
22101 | if (!isObject(options)) throw new Error('options is invalid');
|
22102 | var counter = options.counter || 10;
|
22103 | if (!isNumber(counter)) throw new Error('counter must be a number');
|
22104 | var weightTerm = options.weight;
|
22105 |
|
22106 |
|
22107 | var meanCenter = centerMean(features, {weight: options.weight});
|
22108 |
|
22109 |
|
22110 | var centroids = featureCollection([]);
|
22111 | featureEach(features, function (feature$$1) {
|
22112 | centroids.features.push(centroid(feature$$1, {weight: feature$$1.properties[weightTerm]}));
|
22113 | });
|
22114 |
|
22115 | centroids.properties = {
|
22116 | tolerance: options.tolerance,
|
22117 | medianCandidates: []
|
22118 | };
|
22119 | return findMedian(meanCenter.geometry.coordinates, [0, 0], centroids, counter);
|
22120 | }
|
22121 |
|
22122 |
|
22123 |
|
22124 |
|
22125 |
|
22126 |
|
22127 |
|
22128 |
|
22129 |
|
22130 |
|
22131 |
|
22132 | function findMedian(candidateMedian, previousCandidate, centroids, counter) {
|
22133 | var tolerance = centroids.properties.tolerance || 0.001;
|
22134 | var candidateXsum = 0;
|
22135 | var candidateYsum = 0;
|
22136 | var kSum = 0;
|
22137 | var centroidCount = 0;
|
22138 | featureEach(centroids, function (theCentroid) {
|
22139 | var weightValue = theCentroid.properties.weight;
|
22140 | var weight = (weightValue === undefined || weightValue === null) ? 1 : weightValue;
|
22141 | weight = Number(weight);
|
22142 | if (!isNumber(weight)) throw new Error('weight value must be a number');
|
22143 | if (weight > 0) {
|
22144 | centroidCount += 1;
|
22145 | var distanceFromCandidate = weight * distance(theCentroid, candidateMedian);
|
22146 | if (distanceFromCandidate === 0) distanceFromCandidate = 1;
|
22147 | var k = weight / distanceFromCandidate;
|
22148 | candidateXsum += theCentroid.geometry.coordinates[0] * k;
|
22149 | candidateYsum += theCentroid.geometry.coordinates[1] * k;
|
22150 | kSum += k;
|
22151 | }
|
22152 | });
|
22153 | if (centroidCount < 1) throw new Error('no features to measure');
|
22154 | var candidateX = candidateXsum / kSum;
|
22155 | var candidateY = candidateYsum / kSum;
|
22156 | if (centroidCount === 1 || counter === 0 || (Math.abs(candidateX - previousCandidate[0]) < tolerance && Math.abs(candidateY - previousCandidate[1]) < tolerance)) {
|
22157 | return point([candidateX, candidateY], {medianCandidates: centroids.properties.medianCandidates});
|
22158 | } else {
|
22159 | centroids.properties.medianCandidates.push([candidateX, candidateY]);
|
22160 | return findMedian([candidateX, candidateY], candidateMedian, centroids, counter - 1);
|
22161 | }
|
22162 | }
|
22163 |
|
22164 |
|
22165 |
|
22166 |
|
22167 |
|
22168 |
|
22169 |
|
22170 |
|
22171 |
|
22172 |
|
22173 |
|
22174 |
|
22175 |
|
22176 |
|
22177 |
|
22178 |
|
22179 |
|
22180 |
|
22181 |
|
22182 |
|
22183 |
|
22184 |
|
22185 |
|
22186 |
|
22187 |
|
22188 |
|
22189 |
|
22190 |
|
22191 |
|
22192 |
|
22193 |
|
22194 |
|
22195 |
|
22196 |
|
22197 |
|
22198 |
|
22199 |
|
22200 |
|
22201 |
|
22202 | function standardDeviationalEllipse(points$$1, options) {
|
22203 |
|
22204 | options = options || {};
|
22205 | if (!isObject(options)) throw new Error('options is invalid');
|
22206 | var steps = options.steps || 64;
|
22207 | var weightTerm = options.weight;
|
22208 | var properties = options.properties || {};
|
22209 |
|
22210 |
|
22211 | if (!isNumber(steps)) throw new Error('steps must be a number');
|
22212 | if (!isObject(properties)) throw new Error('properties must be a number');
|
22213 |
|
22214 |
|
22215 | var numberOfFeatures = coordAll(points$$1).length;
|
22216 | var meanCenter = centerMean(points$$1, {weight: weightTerm});
|
22217 |
|
22218 |
|
22219 |
|
22220 |
|
22221 |
|
22222 |
|
22223 |
|
22224 |
|
22225 | var xDeviationSquaredSum = 0;
|
22226 | var yDeviationSquaredSum = 0;
|
22227 | var xyDeviationSum = 0;
|
22228 |
|
22229 | featureEach(points$$1, function (point$$1) {
|
22230 | var weight = point$$1.properties[weightTerm] || 1;
|
22231 | var deviation = getDeviations(getCoords(point$$1), getCoords(meanCenter));
|
22232 | xDeviationSquaredSum += Math.pow(deviation.x, 2) * weight;
|
22233 | yDeviationSquaredSum += Math.pow(deviation.y, 2) * weight;
|
22234 | xyDeviationSum += deviation.x * deviation.y * weight;
|
22235 | });
|
22236 |
|
22237 | var bigA = xDeviationSquaredSum - yDeviationSquaredSum;
|
22238 | var bigB = Math.sqrt(Math.pow(bigA, 2) + 4 * Math.pow(xyDeviationSum, 2));
|
22239 | var bigC = 2 * xyDeviationSum;
|
22240 | var theta = Math.atan((bigA + bigB) / bigC);
|
22241 | var thetaDeg = theta * 180 / Math.PI;
|
22242 |
|
22243 |
|
22244 |
|
22245 |
|
22246 | var sigmaXsum = 0;
|
22247 | var sigmaYsum = 0;
|
22248 | var weightsum = 0;
|
22249 | featureEach(points$$1, function (point$$1) {
|
22250 | var weight = point$$1.properties[weightTerm] || 1;
|
22251 | var deviation = getDeviations(getCoords(point$$1), getCoords(meanCenter));
|
22252 | sigmaXsum += Math.pow((deviation.x * Math.cos(theta)) - (deviation.y * Math.sin(theta)), 2) * weight;
|
22253 | sigmaYsum += Math.pow((deviation.x * Math.sin(theta)) + (deviation.y * Math.cos(theta)), 2) * weight;
|
22254 | weightsum += weight;
|
22255 | });
|
22256 |
|
22257 | var sigmaX = Math.sqrt(2 * sigmaXsum / weightsum);
|
22258 | var sigmaY = Math.sqrt(2 * sigmaYsum / weightsum);
|
22259 |
|
22260 | var theEllipse = ellipse(meanCenter, sigmaX, sigmaY, {units: 'degrees', angle: thetaDeg, steps: steps, properties: properties});
|
22261 | var pointsWithinEllipse = pointsWithinPolygon(points$$1, featureCollection([theEllipse]));
|
22262 | var standardDeviationalEllipseProperties = {
|
22263 | meanCenterCoordinates: getCoords(meanCenter),
|
22264 | semiMajorAxis: sigmaX,
|
22265 | semiMinorAxis: sigmaY,
|
22266 | numberOfFeatures: numberOfFeatures,
|
22267 | angle: thetaDeg,
|
22268 | percentageWithinEllipse: 100 * coordAll(pointsWithinEllipse).length / numberOfFeatures
|
22269 | };
|
22270 | theEllipse.properties.standardDeviationalEllipse = standardDeviationalEllipseProperties;
|
22271 |
|
22272 | return theEllipse;
|
22273 | }
|
22274 |
|
22275 |
|
22276 |
|
22277 |
|
22278 |
|
22279 |
|
22280 |
|
22281 |
|
22282 |
|
22283 | function getDeviations(coordinates, center) {
|
22284 | return {
|
22285 | x: coordinates[0] - center[0],
|
22286 | y: coordinates[1] - center[1]
|
22287 | };
|
22288 | }
|
22289 |
|
22290 |
|
22291 |
|
22292 |
|
22293 |
|
22294 |
|
22295 |
|
22296 |
|
22297 |
|
22298 |
|
22299 |
|
22300 | function randomPosition(bbox) {
|
22301 | if (isObject(bbox)) bbox = bbox.bbox;
|
22302 | if (bbox && !Array.isArray(bbox)) throw new Error('bbox is invalid');
|
22303 | if (bbox) return coordInBBox(bbox);
|
22304 | else return [lon(), lat()];
|
22305 | }
|
22306 |
|
22307 |
|
22308 |
|
22309 |
|
22310 |
|
22311 |
|
22312 |
|
22313 |
|
22314 |
|
22315 |
|
22316 |
|
22317 |
|
22318 |
|
22319 | function randomPoint(count, options) {
|
22320 |
|
22321 | options = options || {};
|
22322 | if (!isObject(options)) throw new Error('options is invalid');
|
22323 | var bbox = options.bbox;
|
22324 | if (count === undefined || count === null) count = 1;
|
22325 |
|
22326 | var features = [];
|
22327 | for (var i = 0; i < count; i++) {
|
22328 | features.push(point(randomPosition(bbox)));
|
22329 | }
|
22330 | return featureCollection(features);
|
22331 | }
|
22332 |
|
22333 |
|
22334 |
|
22335 |
|
22336 |
|
22337 |
|
22338 |
|
22339 |
|
22340 |
|
22341 |
|
22342 |
|
22343 |
|
22344 |
|
22345 |
|
22346 |
|
22347 | function randomPolygon(count, options) {
|
22348 |
|
22349 | options = options || {};
|
22350 | if (!isObject(options)) throw new Error('options is invalid');
|
22351 | var bbox = options.bbox;
|
22352 | var num_vertices = options.num_vertices;
|
22353 | var max_radial_length = options.max_radial_length;
|
22354 | if (count === undefined || count === null) count = 1;
|
22355 |
|
22356 |
|
22357 | if (!isNumber(num_vertices)) num_vertices = 10;
|
22358 | if (!isNumber(max_radial_length)) max_radial_length = 10;
|
22359 |
|
22360 | var features = [];
|
22361 | for (var i = 0; i < count; i++) {
|
22362 | var vertices = [],
|
22363 | circle_offsets = Array.apply(null,
|
22364 | new Array(num_vertices + 1)).map(Math.random);
|
22365 |
|
22366 | circle_offsets.forEach(sumOffsets);
|
22367 | circle_offsets.forEach(scaleOffsets);
|
22368 | vertices[vertices.length - 1] = vertices[0];
|
22369 |
|
22370 |
|
22371 | vertices = vertices.map(vertexToCoordinate(randomPosition(bbox)));
|
22372 | features.push(polygon([vertices]));
|
22373 | }
|
22374 |
|
22375 | function sumOffsets(cur, index, arr) {
|
22376 | arr[index] = (index > 0) ? cur + arr[index - 1] : cur;
|
22377 | }
|
22378 |
|
22379 | function scaleOffsets(cur) {
|
22380 | cur = cur * 2 * Math.PI / circle_offsets[circle_offsets.length - 1];
|
22381 | var radial_scaler = Math.random();
|
22382 | vertices.push([
|
22383 | radial_scaler * max_radial_length * Math.sin(cur),
|
22384 | radial_scaler * max_radial_length * Math.cos(cur)
|
22385 | ]);
|
22386 | }
|
22387 |
|
22388 | return featureCollection(features);
|
22389 | }
|
22390 |
|
22391 |
|
22392 |
|
22393 |
|
22394 |
|
22395 |
|
22396 |
|
22397 |
|
22398 |
|
22399 |
|
22400 |
|
22401 |
|
22402 |
|
22403 |
|
22404 |
|
22405 |
|
22406 | function randomLineString(count, options) {
|
22407 |
|
22408 | options = options || {};
|
22409 | if (!isObject(options)) throw new Error('options is invalid');
|
22410 | var bbox = options.bbox;
|
22411 | var num_vertices = options.num_vertices;
|
22412 | var max_length = options.max_length;
|
22413 | var max_rotation = options.max_rotation;
|
22414 | if (count === undefined || count === null) count = 1;
|
22415 |
|
22416 |
|
22417 | if (!isNumber(num_vertices) || num_vertices < 2) num_vertices = 10;
|
22418 | if (!isNumber(max_length)) max_length = 0.0001;
|
22419 | if (!isNumber(max_rotation)) max_rotation = Math.PI / 8;
|
22420 |
|
22421 | var features = [];
|
22422 | for (var i = 0; i < count; i++) {
|
22423 | var startingPoint = randomPosition(bbox);
|
22424 | var vertices = [startingPoint];
|
22425 | for (var j = 0; j < num_vertices - 1; j++) {
|
22426 | var priorAngle = (j === 0) ?
|
22427 | Math.random() * 2 * Math.PI :
|
22428 | Math.tan(
|
22429 | (vertices[j][1] - vertices[j - 1][1]) /
|
22430 | (vertices[j][0] - vertices[j - 1][0])
|
22431 | );
|
22432 | var angle = priorAngle + (Math.random() - 0.5) * max_rotation * 2;
|
22433 | var distance = Math.random() * max_length;
|
22434 | vertices.push([
|
22435 | vertices[j][0] + distance * Math.cos(angle),
|
22436 | vertices[j][1] + distance * Math.sin(angle)
|
22437 | ]);
|
22438 | }
|
22439 | features.push(lineString(vertices));
|
22440 | }
|
22441 |
|
22442 | return featureCollection(features);
|
22443 | }
|
22444 |
|
22445 | function vertexToCoordinate(hub) {
|
22446 | return function (cur) { return [cur[0] + hub[0], cur[1] + hub[1]]; };
|
22447 | }
|
22448 |
|
22449 | function rnd() { return Math.random() - 0.5; }
|
22450 | function lon() { return rnd() * 360; }
|
22451 | function lat() { return rnd() * 180; }
|
22452 |
|
22453 | function coordInBBox(bbox) {
|
22454 | return [
|
22455 | (Math.random() * (bbox[2] - bbox[0])) + bbox[0],
|
22456 | (Math.random() * (bbox[3] - bbox[1])) + bbox[1]];
|
22457 | }
|
22458 |
|
22459 |
|
22460 |
|
22461 |
|
22462 | var main_es$4 = Object.freeze({
|
22463 | randomPosition: randomPosition,
|
22464 | randomPoint: randomPoint,
|
22465 | randomPolygon: randomPolygon,
|
22466 | randomLineString: randomLineString
|
22467 | });
|
22468 |
|
22469 |
|
22470 |
|
22471 |
|
22472 |
|
22473 |
|
22474 |
|
22475 |
|
22476 |
|
22477 |
|
22478 |
|
22479 |
|
22480 |
|
22481 |
|
22482 |
|
22483 |
|
22484 |
|
22485 |
|
22486 |
|
22487 |
|
22488 |
|
22489 |
|
22490 |
|
22491 |
|
22492 |
|
22493 |
|
22494 |
|
22495 |
|
22496 |
|
22497 |
|
22498 | function getCluster(geojson, filter) {
|
22499 |
|
22500 | if (!geojson) throw new Error('geojson is required');
|
22501 | if (geojson.type !== 'FeatureCollection') throw new Error('geojson must be a FeatureCollection');
|
22502 | if (filter === undefined || filter === null) throw new Error('filter is required');
|
22503 |
|
22504 |
|
22505 | var features = [];
|
22506 | featureEach(geojson, function (feature$$1) {
|
22507 | if (applyFilter(feature$$1.properties, filter)) features.push(feature$$1);
|
22508 | });
|
22509 | return featureCollection(features);
|
22510 | }
|
22511 |
|
22512 |
|
22513 |
|
22514 |
|
22515 |
|
22516 |
|
22517 |
|
22518 |
|
22519 |
|
22520 |
|
22521 |
|
22522 |
|
22523 |
|
22524 |
|
22525 |
|
22526 |
|
22527 |
|
22528 |
|
22529 |
|
22530 |
|
22531 |
|
22532 |
|
22533 |
|
22534 |
|
22535 |
|
22536 |
|
22537 |
|
22538 |
|
22539 |
|
22540 |
|
22541 |
|
22542 |
|
22543 |
|
22544 |
|
22545 |
|
22546 |
|
22547 |
|
22548 |
|
22549 |
|
22550 |
|
22551 |
|
22552 |
|
22553 |
|
22554 |
|
22555 |
|
22556 |
|
22557 |
|
22558 |
|
22559 |
|
22560 |
|
22561 | function clusterEach(geojson, property, callback) {
|
22562 |
|
22563 | if (!geojson) throw new Error('geojson is required');
|
22564 | if (geojson.type !== 'FeatureCollection') throw new Error('geojson must be a FeatureCollection');
|
22565 | if (property === undefined || property === null) throw new Error('property is required');
|
22566 |
|
22567 |
|
22568 | var bins = createBins(geojson, property);
|
22569 | var values = Object.keys(bins);
|
22570 | for (var index = 0; index < values.length; index++) {
|
22571 | var value = values[index];
|
22572 | var bin = bins[value];
|
22573 | var features = [];
|
22574 | for (var i = 0; i < bin.length; i++) {
|
22575 | features.push(geojson.features[bin[i]]);
|
22576 | }
|
22577 | callback(featureCollection(features), value, index);
|
22578 | }
|
22579 | }
|
22580 |
|
22581 |
|
22582 |
|
22583 |
|
22584 |
|
22585 |
|
22586 |
|
22587 |
|
22588 |
|
22589 |
|
22590 |
|
22591 |
|
22592 |
|
22593 |
|
22594 |
|
22595 |
|
22596 |
|
22597 |
|
22598 |
|
22599 |
|
22600 |
|
22601 |
|
22602 |
|
22603 |
|
22604 |
|
22605 |
|
22606 |
|
22607 |
|
22608 |
|
22609 |
|
22610 |
|
22611 |
|
22612 |
|
22613 |
|
22614 |
|
22615 |
|
22616 |
|
22617 |
|
22618 |
|
22619 |
|
22620 |
|
22621 |
|
22622 |
|
22623 |
|
22624 |
|
22625 |
|
22626 |
|
22627 |
|
22628 |
|
22629 |
|
22630 |
|
22631 |
|
22632 |
|
22633 |
|
22634 |
|
22635 |
|
22636 |
|
22637 |
|
22638 |
|
22639 |
|
22640 |
|
22641 |
|
22642 |
|
22643 |
|
22644 |
|
22645 | function clusterReduce(geojson, property, callback, initialValue) {
|
22646 | var previousValue = initialValue;
|
22647 | clusterEach(geojson, property, function (cluster, clusterValue, currentIndex) {
|
22648 | if (currentIndex === 0 && initialValue === undefined) previousValue = cluster;
|
22649 | else previousValue = callback(previousValue, cluster, clusterValue, currentIndex);
|
22650 | });
|
22651 | return previousValue;
|
22652 | }
|
22653 |
|
22654 |
|
22655 |
|
22656 |
|
22657 |
|
22658 |
|
22659 |
|
22660 |
|
22661 |
|
22662 |
|
22663 |
|
22664 |
|
22665 |
|
22666 |
|
22667 |
|
22668 |
|
22669 |
|
22670 |
|
22671 | function createBins(geojson, property) {
|
22672 | var bins = {};
|
22673 |
|
22674 | featureEach(geojson, function (feature$$1, i) {
|
22675 | var properties = feature$$1.properties || {};
|
22676 | if (properties.hasOwnProperty(property)) {
|
22677 | var value = properties[property];
|
22678 | if (bins.hasOwnProperty(value)) bins[value].push(i);
|
22679 | else bins[value] = [i];
|
22680 | }
|
22681 | });
|
22682 | return bins;
|
22683 | }
|
22684 |
|
22685 |
|
22686 |
|
22687 |
|
22688 |
|
22689 |
|
22690 |
|
22691 |
|
22692 |
|
22693 | function applyFilter(properties, filter) {
|
22694 | if (properties === undefined) return false;
|
22695 | var filterType = typeof filter;
|
22696 |
|
22697 |
|
22698 | if (filterType === 'number' || filterType === 'string') return properties.hasOwnProperty(filter);
|
22699 |
|
22700 | else if (Array.isArray(filter)) {
|
22701 | for (var i = 0; i < filter.length; i++) {
|
22702 | if (!applyFilter(properties, filter[i])) return false;
|
22703 | }
|
22704 | return true;
|
22705 |
|
22706 | } else {
|
22707 | return propertiesContainsFilter(properties, filter);
|
22708 | }
|
22709 | }
|
22710 |
|
22711 |
|
22712 |
|
22713 |
|
22714 |
|
22715 |
|
22716 |
|
22717 |
|
22718 |
|
22719 |
|
22720 |
|
22721 |
|
22722 |
|
22723 |
|
22724 | function propertiesContainsFilter(properties, filter) {
|
22725 | var keys = Object.keys(filter);
|
22726 | for (var i = 0; i < keys.length; i++) {
|
22727 | var key = keys[i];
|
22728 | if (properties[key] !== filter[key]) return false;
|
22729 | }
|
22730 | return true;
|
22731 | }
|
22732 |
|
22733 |
|
22734 |
|
22735 |
|
22736 |
|
22737 |
|
22738 |
|
22739 |
|
22740 |
|
22741 |
|
22742 |
|
22743 |
|
22744 | function filterProperties(properties, keys) {
|
22745 | if (!keys) return {};
|
22746 | if (!keys.length) return {};
|
22747 |
|
22748 | var newProperties = {};
|
22749 | for (var i = 0; i < keys.length; i++) {
|
22750 | var key = keys[i];
|
22751 | if (properties.hasOwnProperty(key)) newProperties[key] = properties[key];
|
22752 | }
|
22753 | return newProperties;
|
22754 | }
|
22755 |
|
22756 |
|
22757 |
|
22758 |
|
22759 | var main_es$5 = Object.freeze({
|
22760 | getCluster: getCluster,
|
22761 | clusterEach: clusterEach,
|
22762 | clusterReduce: clusterReduce,
|
22763 | createBins: createBins,
|
22764 | applyFilter: applyFilter,
|
22765 | propertiesContainsFilter: propertiesContainsFilter,
|
22766 | filterProperties: filterProperties
|
22767 | });
|
22768 |
|
22769 |
|
22770 |
|
22771 |
|
22772 |
|
22773 |
|
22774 | if (!('fill' in Array.prototype)) {
|
22775 | Object.defineProperty(Array.prototype, 'fill', {
|
22776 | configurable: true,
|
22777 | value: function fill (value) {
|
22778 | if (this === undefined || this === null) {
|
22779 | throw new TypeError(this + ' is not an object')
|
22780 | }
|
22781 |
|
22782 | var arrayLike = Object(this);
|
22783 |
|
22784 | var length = Math.max(Math.min(arrayLike.length, 9007199254740991), 0) || 0;
|
22785 |
|
22786 | var relativeStart = 1 in arguments ? parseInt(Number(arguments[1]), 10) || 0 : 0;
|
22787 |
|
22788 | relativeStart = relativeStart < 0 ? Math.max(length + relativeStart, 0) : Math.min(relativeStart, length);
|
22789 |
|
22790 | var relativeEnd = 2 in arguments && arguments[2] !== undefined ? parseInt(Number(arguments[2]), 10) || 0 : length;
|
22791 |
|
22792 | relativeEnd = relativeEnd < 0 ? Math.max(length + arguments[2], 0) : Math.min(relativeEnd, length);
|
22793 |
|
22794 | while (relativeStart < relativeEnd) {
|
22795 | arrayLike[relativeStart] = value;
|
22796 |
|
22797 | ++relativeStart;
|
22798 | }
|
22799 |
|
22800 | return arrayLike
|
22801 | },
|
22802 | writable: true
|
22803 | });
|
22804 | }
|
22805 |
|
22806 |
|
22807 |
|
22808 |
|
22809 | Number.isFinite = Number.isFinite || function (value) {
|
22810 | return typeof value === 'number' && isFinite(value)
|
22811 | };
|
22812 |
|
22813 | Number.isInteger = Number.isInteger || function (val) {
|
22814 | return typeof val === 'number' &&
|
22815 | isFinite(val) &&
|
22816 | Math.floor(val) === val
|
22817 | };
|
22818 |
|
22819 | Number.parseFloat = Number.parseFloat || parseFloat;
|
22820 |
|
22821 | Number.isNaN = Number.isNaN || function (value) {
|
22822 | return value !== value
|
22823 | };
|
22824 |
|
22825 |
|
22826 |
|
22827 |
|
22828 | Math.trunc = Math.trunc || function (x) {
|
22829 | return x < 0 ? Math.ceil(x) : Math.floor(x)
|
22830 | };
|
22831 |
|
22832 | var NumberUtil = function NumberUtil () {};
|
22833 |
|
22834 | NumberUtil.prototype.interfaces_ = function interfaces_ () {
|
22835 | return []
|
22836 | };
|
22837 | NumberUtil.prototype.getClass = function getClass () {
|
22838 | return NumberUtil
|
22839 | };
|
22840 | NumberUtil.prototype.equalsWithTolerance = function equalsWithTolerance (x1, x2, tolerance) {
|
22841 | return Math.abs(x1 - x2) <= tolerance
|
22842 | };
|
22843 |
|
22844 | var IllegalArgumentException = function IllegalArgumentException () {};
|
22845 |
|
22846 | var Double = function Double () {};
|
22847 |
|
22848 | var staticAccessors$1 = { MAX_VALUE: { configurable: true } };
|
22849 |
|
22850 | Double.isNaN = function isNaN (n) { return Number.isNaN(n) };
|
22851 | Double.doubleToLongBits = function doubleToLongBits (n) { return n };
|
22852 | Double.longBitsToDouble = function longBitsToDouble (n) { return n };
|
22853 | Double.isInfinite = function isInfinite (n) { return !Number.isFinite(n) };
|
22854 | staticAccessors$1.MAX_VALUE.get = function () { return Number.MAX_VALUE };
|
22855 |
|
22856 | Object.defineProperties( Double, staticAccessors$1 );
|
22857 |
|
22858 | var Comparable = function Comparable () {};
|
22859 |
|
22860 | var Clonable = function Clonable () {};
|
22861 |
|
22862 | var Comparator = function Comparator () {};
|
22863 |
|
22864 | function Serializable () {}
|
22865 |
|
22866 |
|
22867 |
|
22868 | var Coordinate = function Coordinate () {
|
22869 | this.x = null;
|
22870 | this.y = null;
|
22871 | this.z = null;
|
22872 | if (arguments.length === 0) {
|
22873 | this.x = 0.0;
|
22874 | this.y = 0.0;
|
22875 | this.z = Coordinate.NULL_ORDINATE;
|
22876 | } else if (arguments.length === 1) {
|
22877 | var c = arguments[0];
|
22878 | this.x = c.x;
|
22879 | this.y = c.y;
|
22880 | this.z = c.z;
|
22881 | } else if (arguments.length === 2) {
|
22882 | this.x = arguments[0];
|
22883 | this.y = arguments[1];
|
22884 | this.z = Coordinate.NULL_ORDINATE;
|
22885 | } else if (arguments.length === 3) {
|
22886 | this.x = arguments[0];
|
22887 | this.y = arguments[1];
|
22888 | this.z = arguments[2];
|
22889 | }
|
22890 | };
|
22891 |
|
22892 | var staticAccessors = { DimensionalComparator: { configurable: true },serialVersionUID: { configurable: true },NULL_ORDINATE: { configurable: true },X: { configurable: true },Y: { configurable: true },Z: { configurable: true } };
|
22893 | Coordinate.prototype.setOrdinate = function setOrdinate (ordinateIndex, value) {
|
22894 | switch (ordinateIndex) {
|
22895 | case Coordinate.X:
|
22896 | this.x = value;
|
22897 | break
|
22898 | case Coordinate.Y:
|
22899 | this.y = value;
|
22900 | break
|
22901 | case Coordinate.Z:
|
22902 | this.z = value;
|
22903 | break
|
22904 | default:
|
22905 | throw new IllegalArgumentException('Invalid ordinate index: ' + ordinateIndex)
|
22906 | }
|
22907 | };
|
22908 | Coordinate.prototype.equals2D = function equals2D () {
|
22909 | if (arguments.length === 1) {
|
22910 | var other = arguments[0];
|
22911 | if (this.x !== other.x) {
|
22912 | return false
|
22913 | }
|
22914 | if (this.y !== other.y) {
|
22915 | return false
|
22916 | }
|
22917 | return true
|
22918 | } else if (arguments.length === 2) {
|
22919 | var c = arguments[0];
|
22920 | var tolerance = arguments[1];
|
22921 | if (!NumberUtil.equalsWithTolerance(this.x, c.x, tolerance)) {
|
22922 | return false
|
22923 | }
|
22924 | if (!NumberUtil.equalsWithTolerance(this.y, c.y, tolerance)) {
|
22925 | return false
|
22926 | }
|
22927 | return true
|
22928 | }
|
22929 | };
|
22930 | Coordinate.prototype.getOrdinate = function getOrdinate (ordinateIndex) {
|
22931 | switch (ordinateIndex) {
|
22932 | case Coordinate.X:
|
22933 | return this.x
|
22934 | case Coordinate.Y:
|
22935 | return this.y
|
22936 | case Coordinate.Z:
|
22937 | return this.z
|
22938 | default:
|
22939 | }
|
22940 | throw new IllegalArgumentException('Invalid ordinate index: ' + ordinateIndex)
|
22941 | };
|
22942 | Coordinate.prototype.equals3D = function equals3D (other) {
|
22943 | return this.x === other.x &&
|
22944 | this.y === other.y &&
|
22945 | ((this.z === other.z || Double.isNaN(this.z)) &&
|
22946 | Double.isNaN(other.z))
|
22947 | };
|
22948 | Coordinate.prototype.equals = function equals (other) {
|
22949 | if (!(other instanceof Coordinate)) {
|
22950 | return false
|
22951 | }
|
22952 | return this.equals2D(other)
|
22953 | };
|
22954 | Coordinate.prototype.equalInZ = function equalInZ (c, tolerance) {
|
22955 | return NumberUtil.equalsWithTolerance(this.z, c.z, tolerance)
|
22956 | };
|
22957 | Coordinate.prototype.compareTo = function compareTo (o) {
|
22958 | var other = o;
|
22959 | if (this.x < other.x) { return -1 }
|
22960 | if (this.x > other.x) { return 1 }
|
22961 | if (this.y < other.y) { return -1 }
|
22962 | if (this.y > other.y) { return 1 }
|
22963 | return 0
|
22964 | };
|
22965 | Coordinate.prototype.clone = function clone () {
|
22966 |
|
22967 |
|
22968 |
|
22969 |
|
22970 |
|
22971 |
|
22972 |
|
22973 |
|
22974 |
|
22975 | };
|
22976 | Coordinate.prototype.copy = function copy () {
|
22977 | return new Coordinate(this)
|
22978 | };
|
22979 | Coordinate.prototype.toString = function toString () {
|
22980 | return '(' + this.x + ', ' + this.y + ', ' + this.z + ')'
|
22981 | };
|
22982 | Coordinate.prototype.distance3D = function distance3D (c) {
|
22983 | var dx = this.x - c.x;
|
22984 | var dy = this.y - c.y;
|
22985 | var dz = this.z - c.z;
|
22986 | return Math.sqrt(dx * dx + dy * dy + dz * dz)
|
22987 | };
|
22988 | Coordinate.prototype.distance = function distance (c) {
|
22989 | var dx = this.x - c.x;
|
22990 | var dy = this.y - c.y;
|
22991 | return Math.sqrt(dx * dx + dy * dy)
|
22992 | };
|
22993 | Coordinate.prototype.hashCode = function hashCode () {
|
22994 | var result = 17;
|
22995 | result = 37 * result + Coordinate.hashCode(this.x);
|
22996 | result = 37 * result + Coordinate.hashCode(this.y);
|
22997 | return result
|
22998 | };
|
22999 | Coordinate.prototype.setCoordinate = function setCoordinate (other) {
|
23000 | this.x = other.x;
|
23001 | this.y = other.y;
|
23002 | this.z = other.z;
|
23003 | };
|
23004 | Coordinate.prototype.interfaces_ = function interfaces_ () {
|
23005 | return [Comparable, Clonable, Serializable]
|
23006 | };
|
23007 | Coordinate.prototype.getClass = function getClass () {
|
23008 | return Coordinate
|
23009 | };
|
23010 | Coordinate.hashCode = function hashCode () {
|
23011 | if (arguments.length === 1) {
|
23012 | var x = arguments[0];
|
23013 | var f = Double.doubleToLongBits(x);
|
23014 | return Math.trunc((f ^ f) >>> 32)
|
23015 | }
|
23016 | };
|
23017 | staticAccessors.DimensionalComparator.get = function () { return DimensionalComparator };
|
23018 | staticAccessors.serialVersionUID.get = function () { return 6683108902428366910 };
|
23019 | staticAccessors.NULL_ORDINATE.get = function () { return Double.NaN };
|
23020 | staticAccessors.X.get = function () { return 0 };
|
23021 | staticAccessors.Y.get = function () { return 1 };
|
23022 | staticAccessors.Z.get = function () { return 2 };
|
23023 |
|
23024 | Object.defineProperties( Coordinate, staticAccessors );
|
23025 |
|
23026 | var DimensionalComparator = function DimensionalComparator (dimensionsToTest) {
|
23027 | this._dimensionsToTest = 2;
|
23028 | if (arguments.length === 0) {} else if (arguments.length === 1) {
|
23029 | var dimensionsToTest$1 = arguments[0];
|
23030 | if (dimensionsToTest$1 !== 2 && dimensionsToTest$1 !== 3) { throw new IllegalArgumentException('only 2 or 3 dimensions may be specified') }
|
23031 | this._dimensionsToTest = dimensionsToTest$1;
|
23032 | }
|
23033 | };
|
23034 | DimensionalComparator.prototype.compare = function compare (o1, o2) {
|
23035 | var c1 = o1;
|
23036 | var c2 = o2;
|
23037 | var compX = DimensionalComparator.compare(c1.x, c2.x);
|
23038 | if (compX !== 0) { return compX }
|
23039 | var compY = DimensionalComparator.compare(c1.y, c2.y);
|
23040 | if (compY !== 0) { return compY }
|
23041 | if (this._dimensionsToTest <= 2) { return 0 }
|
23042 | var compZ = DimensionalComparator.compare(c1.z, c2.z);
|
23043 | return compZ
|
23044 | };
|
23045 | DimensionalComparator.prototype.interfaces_ = function interfaces_ () {
|
23046 | return [Comparator]
|
23047 | };
|
23048 | DimensionalComparator.prototype.getClass = function getClass () {
|
23049 | return DimensionalComparator
|
23050 | };
|
23051 | DimensionalComparator.compare = function compare (a, b) {
|
23052 | if (a < b) { return -1 }
|
23053 | if (a > b) { return 1 }
|
23054 | if (Double.isNaN(a)) {
|
23055 | if (Double.isNaN(b)) { return 0 }
|
23056 | return -1
|
23057 | }
|
23058 | if (Double.isNaN(b)) { return 1 }
|
23059 | return 0
|
23060 | };
|
23061 |
|
23062 |
|
23063 |
|
23064 |
|
23065 | var CoordinateSequenceFactory = function CoordinateSequenceFactory () {};
|
23066 |
|
23067 | CoordinateSequenceFactory.prototype.create = function create () {
|
23068 |
|
23069 |
|
23070 |
|
23071 |
|
23072 |
|
23073 |
|
23074 |
|
23075 |
|
23076 |
|
23077 |
|
23078 | };
|
23079 | CoordinateSequenceFactory.prototype.interfaces_ = function interfaces_ () {
|
23080 | return []
|
23081 | };
|
23082 | CoordinateSequenceFactory.prototype.getClass = function getClass () {
|
23083 | return CoordinateSequenceFactory
|
23084 | };
|
23085 |
|
23086 | var Location = function Location () {};
|
23087 |
|
23088 | var staticAccessors$4 = { INTERIOR: { configurable: true },BOUNDARY: { configurable: true },EXTERIOR: { configurable: true },NONE: { configurable: true } };
|
23089 |
|
23090 | Location.prototype.interfaces_ = function interfaces_ () {
|
23091 | return []
|
23092 | };
|
23093 | Location.prototype.getClass = function getClass () {
|
23094 | return Location
|
23095 | };
|
23096 | Location.toLocationSymbol = function toLocationSymbol (locationValue) {
|
23097 | switch (locationValue) {
|
23098 | case Location.EXTERIOR:
|
23099 | return 'e'
|
23100 | case Location.BOUNDARY:
|
23101 | return 'b'
|
23102 | case Location.INTERIOR:
|
23103 | return 'i'
|
23104 | case Location.NONE:
|
23105 | return '-'
|
23106 | default:
|
23107 | }
|
23108 | throw new IllegalArgumentException('Unknown location value: ' + locationValue)
|
23109 | };
|
23110 | staticAccessors$4.INTERIOR.get = function () { return 0 };
|
23111 | staticAccessors$4.BOUNDARY.get = function () { return 1 };
|
23112 | staticAccessors$4.EXTERIOR.get = function () { return 2 };
|
23113 | staticAccessors$4.NONE.get = function () { return -1 };
|
23114 |
|
23115 | Object.defineProperties( Location, staticAccessors$4 );
|
23116 |
|
23117 | var hasInterface = function (o, i) {
|
23118 | return o.interfaces_ && o.interfaces_().indexOf(i) > -1
|
23119 | };
|
23120 |
|
23121 | var MathUtil = function MathUtil () {};
|
23122 |
|
23123 | var staticAccessors$5 = { LOG_10: { configurable: true } };
|
23124 |
|
23125 | MathUtil.prototype.interfaces_ = function interfaces_ () {
|
23126 | return []
|
23127 | };
|
23128 | MathUtil.prototype.getClass = function getClass () {
|
23129 | return MathUtil
|
23130 | };
|
23131 | MathUtil.log10 = function log10 (x) {
|
23132 | var ln = Math.log(x);
|
23133 | if (Double.isInfinite(ln)) { return ln }
|
23134 | if (Double.isNaN(ln)) { return ln }
|
23135 | return ln / MathUtil.LOG_10
|
23136 | };
|
23137 | MathUtil.min = function min (v1, v2, v3, v4) {
|
23138 | var min = v1;
|
23139 | if (v2 < min) { min = v2; }
|
23140 | if (v3 < min) { min = v3; }
|
23141 | if (v4 < min) { min = v4; }
|
23142 | return min
|
23143 | };
|
23144 | MathUtil.clamp = function clamp () {
|
23145 | if (typeof arguments[2] === 'number' && (typeof arguments[0] === 'number' && typeof arguments[1] === 'number')) {
|
23146 | var x = arguments[0];
|
23147 | var min = arguments[1];
|
23148 | var max = arguments[2];
|
23149 | if (x < min) { return min }
|
23150 | if (x > max) { return max }
|
23151 | return x
|
23152 | } else if (Number.isInteger(arguments[2]) && (Number.isInteger(arguments[0]) && Number.isInteger(arguments[1]))) {
|
23153 | var x$1 = arguments[0];
|
23154 | var min$1 = arguments[1];
|
23155 | var max$1 = arguments[2];
|
23156 | if (x$1 < min$1) { return min$1 }
|
23157 | if (x$1 > max$1) { return max$1 }
|
23158 | return x$1
|
23159 | }
|
23160 | };
|
23161 | MathUtil.wrap = function wrap (index, max) {
|
23162 | if (index < 0) {
|
23163 | return max - -index % max
|
23164 | }
|
23165 | return index % max
|
23166 | };
|
23167 | MathUtil.max = function max () {
|
23168 | if (arguments.length === 3) {
|
23169 | var v1 = arguments[0];
|
23170 | var v2 = arguments[1];
|
23171 | var v3 = arguments[2];
|
23172 | var max = v1;
|
23173 | if (v2 > max) { max = v2; }
|
23174 | if (v3 > max) { max = v3; }
|
23175 | return max
|
23176 | } else if (arguments.length === 4) {
|
23177 | var v1$1 = arguments[0];
|
23178 | var v2$1 = arguments[1];
|
23179 | var v3$1 = arguments[2];
|
23180 | var v4 = arguments[3];
|
23181 | var max$1 = v1$1;
|
23182 | if (v2$1 > max$1) { max$1 = v2$1; }
|
23183 | if (v3$1 > max$1) { max$1 = v3$1; }
|
23184 | if (v4 > max$1) { max$1 = v4; }
|
23185 | return max$1
|
23186 | }
|
23187 | };
|
23188 | MathUtil.average = function average (x1, x2) {
|
23189 | return (x1 + x2) / 2.0
|
23190 | };
|
23191 | staticAccessors$5.LOG_10.get = function () { return Math.log(10) };
|
23192 |
|
23193 | Object.defineProperties( MathUtil, staticAccessors$5 );
|
23194 |
|
23195 | var StringBuffer = function StringBuffer (str) {
|
23196 | this.str = str;
|
23197 | };
|
23198 | StringBuffer.prototype.append = function append (e) {
|
23199 | this.str += e;
|
23200 | };
|
23201 |
|
23202 | StringBuffer.prototype.setCharAt = function setCharAt (i, c) {
|
23203 | this.str = this.str.substr(0, i) + c + this.str.substr(i + 1);
|
23204 | };
|
23205 |
|
23206 | StringBuffer.prototype.toString = function toString (e) {
|
23207 | return this.str
|
23208 | };
|
23209 |
|
23210 | var Integer = function Integer (value) {
|
23211 | this.value = value;
|
23212 | };
|
23213 | Integer.prototype.intValue = function intValue () {
|
23214 | return this.value
|
23215 | };
|
23216 | Integer.prototype.compareTo = function compareTo (o) {
|
23217 | if (this.value < o) { return -1 }
|
23218 | if (this.value > o) { return 1 }
|
23219 | return 0
|
23220 | };
|
23221 | Integer.isNaN = function isNaN (n) { return Number.isNaN(n) };
|
23222 |
|
23223 | var Character = function Character () {};
|
23224 |
|
23225 | Character.isWhitespace = function isWhitespace (c) { return ((c <= 32 && c >= 0) || c === 127) };
|
23226 | Character.toUpperCase = function toUpperCase (c) { return c.toUpperCase() };
|
23227 |
|
23228 | var DD = function DD () {
|
23229 | this._hi = 0.0;
|
23230 | this._lo = 0.0;
|
23231 | if (arguments.length === 0) {
|
23232 | this.init(0.0);
|
23233 | } else if (arguments.length === 1) {
|
23234 | if (typeof arguments[0] === 'number') {
|
23235 | var x = arguments[0];
|
23236 | this.init(x);
|
23237 | } else if (arguments[0] instanceof DD) {
|
23238 | var dd = arguments[0];
|
23239 | this.init(dd);
|
23240 | } else if (typeof arguments[0] === 'string') {
|
23241 | var str = arguments[0];
|
23242 | DD.call(this, DD.parse(str));
|
23243 | }
|
23244 | } else if (arguments.length === 2) {
|
23245 | var hi = arguments[0];
|
23246 | var lo = arguments[1];
|
23247 | this.init(hi, lo);
|
23248 | }
|
23249 | };
|
23250 |
|
23251 | var staticAccessors$7 = { PI: { configurable: true },TWO_PI: { configurable: true },PI_2: { configurable: true },E: { configurable: true },NaN: { configurable: true },EPS: { configurable: true },SPLIT: { configurable: true },MAX_PRINT_DIGITS: { configurable: true },TEN: { configurable: true },ONE: { configurable: true },SCI_NOT_EXPONENT_CHAR: { configurable: true },SCI_NOT_ZERO: { configurable: true } };
|
23252 | DD.prototype.le = function le (y) {
|
23253 | return (this._hi < y._hi || this._hi === y._hi) && this._lo <= y._lo
|
23254 | };
|
23255 | DD.prototype.extractSignificantDigits = function extractSignificantDigits (insertDecimalPoint, magnitude) {
|
23256 | var y = this.abs();
|
23257 | var mag = DD.magnitude(y._hi);
|
23258 | var scale = DD.TEN.pow(mag);
|
23259 | y = y.divide(scale);
|
23260 | if (y.gt(DD.TEN)) {
|
23261 | y = y.divide(DD.TEN);
|
23262 | mag += 1;
|
23263 | } else if (y.lt(DD.ONE)) {
|
23264 | y = y.multiply(DD.TEN);
|
23265 | mag -= 1;
|
23266 | }
|
23267 | var decimalPointPos = mag + 1;
|
23268 | var buf = new StringBuffer();
|
23269 | var numDigits = DD.MAX_PRINT_DIGITS - 1;
|
23270 | for (var i = 0; i <= numDigits; i++) {
|
23271 | if (insertDecimalPoint && i === decimalPointPos) {
|
23272 | buf.append('.');
|
23273 | }
|
23274 | var digit = Math.trunc(y._hi);
|
23275 | if (digit < 0) {
|
23276 | break
|
23277 | }
|
23278 | var rebiasBy10 = false;
|
23279 | var digitChar = 0;
|
23280 | if (digit > 9) {
|
23281 | rebiasBy10 = true;
|
23282 | digitChar = '9';
|
23283 | } else {
|
23284 | digitChar = '0' + digit;
|
23285 | }
|
23286 | buf.append(digitChar);
|
23287 | y = y.subtract(DD.valueOf(digit)).multiply(DD.TEN);
|
23288 | if (rebiasBy10) { y.selfAdd(DD.TEN); }
|
23289 | var continueExtractingDigits = true;
|
23290 | var remMag = DD.magnitude(y._hi);
|
23291 | if (remMag < 0 && Math.abs(remMag) >= numDigits - i) { continueExtractingDigits = false; }
|
23292 | if (!continueExtractingDigits) { break }
|
23293 | }
|
23294 | magnitude[0] = mag;
|
23295 | return buf.toString()
|
23296 | };
|
23297 | DD.prototype.sqr = function sqr () {
|
23298 | return this.multiply(this)
|
23299 | };
|
23300 | DD.prototype.doubleValue = function doubleValue () {
|
23301 | return this._hi + this._lo
|
23302 | };
|
23303 | DD.prototype.subtract = function subtract () {
|
23304 | if (arguments[0] instanceof DD) {
|
23305 | var y = arguments[0];
|
23306 | return this.add(y.negate())
|
23307 | } else if (typeof arguments[0] === 'number') {
|
23308 | var y$1 = arguments[0];
|
23309 | return this.add(-y$1)
|
23310 | }
|
23311 | };
|
23312 | DD.prototype.equals = function equals () {
|
23313 | if (arguments.length === 1) {
|
23314 | var y = arguments[0];
|
23315 | return this._hi === y._hi && this._lo === y._lo
|
23316 | }
|
23317 | };
|
23318 | DD.prototype.isZero = function isZero () {
|
23319 | return this._hi === 0.0 && this._lo === 0.0
|
23320 | };
|
23321 | DD.prototype.selfSubtract = function selfSubtract () {
|
23322 | if (arguments[0] instanceof DD) {
|
23323 | var y = arguments[0];
|
23324 | if (this.isNaN()) { return this }
|
23325 | return this.selfAdd(-y._hi, -y._lo)
|
23326 | } else if (typeof arguments[0] === 'number') {
|
23327 | var y$1 = arguments[0];
|
23328 | if (this.isNaN()) { return this }
|
23329 | return this.selfAdd(-y$1, 0.0)
|
23330 | }
|
23331 | };
|
23332 | DD.prototype.getSpecialNumberString = function getSpecialNumberString () {
|
23333 | if (this.isZero()) { return '0.0' }
|
23334 | if (this.isNaN()) { return 'NaN ' }
|
23335 | return null
|
23336 | };
|
23337 | DD.prototype.min = function min (x) {
|
23338 | if (this.le(x)) {
|
23339 | return this
|
23340 | } else {
|
23341 | return x
|
23342 | }
|
23343 | };
|
23344 | DD.prototype.selfDivide = function selfDivide () {
|
23345 | if (arguments.length === 1) {
|
23346 | if (arguments[0] instanceof DD) {
|
23347 | var y = arguments[0];
|
23348 | return this.selfDivide(y._hi, y._lo)
|
23349 | } else if (typeof arguments[0] === 'number') {
|
23350 | var y$1 = arguments[0];
|
23351 | return this.selfDivide(y$1, 0.0)
|
23352 | }
|
23353 | } else if (arguments.length === 2) {
|
23354 | var yhi = arguments[0];
|
23355 | var ylo = arguments[1];
|
23356 | var hc = null;
|
23357 | var tc = null;
|
23358 | var hy = null;
|
23359 | var ty = null;
|
23360 | var C = null;
|
23361 | var c = null;
|
23362 | var U = null;
|
23363 | var u = null;
|
23364 | C = this._hi / yhi;
|
23365 | c = DD.SPLIT * C;
|
23366 | hc = c - C;
|
23367 | u = DD.SPLIT * yhi;
|
23368 | hc = c - hc;
|
23369 | tc = C - hc;
|
23370 | hy = u - yhi;
|
23371 | U = C * yhi;
|
23372 | hy = u - hy;
|
23373 | ty = yhi - hy;
|
23374 | u = hc * hy - U + hc * ty + tc * hy + tc * ty;
|
23375 | c = (this._hi - U - u + this._lo - C * ylo) / yhi;
|
23376 | u = C + c;
|
23377 | this._hi = u;
|
23378 | this._lo = C - u + c;
|
23379 | return this
|
23380 | }
|
23381 | };
|
23382 | DD.prototype.dump = function dump () {
|
23383 | return 'DD<' + this._hi + ', ' + this._lo + '>'
|
23384 | };
|
23385 | DD.prototype.divide = function divide () {
|
23386 | if (arguments[0] instanceof DD) {
|
23387 | var y = arguments[0];
|
23388 | var hc = null;
|
23389 | var tc = null;
|
23390 | var hy = null;
|
23391 | var ty = null;
|
23392 | var C = null;
|
23393 | var c = null;
|
23394 | var U = null;
|
23395 | var u = null;
|
23396 | C = this._hi / y._hi;
|
23397 | c = DD.SPLIT * C;
|
23398 | hc = c - C;
|
23399 | u = DD.SPLIT * y._hi;
|
23400 | hc = c - hc;
|
23401 | tc = C - hc;
|
23402 | hy = u - y._hi;
|
23403 | U = C * y._hi;
|
23404 | hy = u - hy;
|
23405 | ty = y._hi - hy;
|
23406 | u = hc * hy - U + hc * ty + tc * hy + tc * ty;
|
23407 | c = (this._hi - U - u + this._lo - C * y._lo) / y._hi;
|
23408 | u = C + c;
|
23409 | var zhi = u;
|
23410 | var zlo = C - u + c;
|
23411 | return new DD(zhi, zlo)
|
23412 | } else if (typeof arguments[0] === 'number') {
|
23413 | var y$1 = arguments[0];
|
23414 | if (Double.isNaN(y$1)) { return DD.createNaN() }
|
23415 | return DD.copy(this).selfDivide(y$1, 0.0)
|
23416 | }
|
23417 | };
|
23418 | DD.prototype.ge = function ge (y) {
|
23419 | return (this._hi > y._hi || this._hi === y._hi) && this._lo >= y._lo
|
23420 | };
|
23421 | DD.prototype.pow = function pow (exp) {
|
23422 | if (exp === 0.0) { return DD.valueOf(1.0) }
|
23423 | var r = new DD(this);
|
23424 | var s = DD.valueOf(1.0);
|
23425 | var n = Math.abs(exp);
|
23426 | if (n > 1) {
|
23427 | while (n > 0) {
|
23428 | if (n % 2 === 1) {
|
23429 | s.selfMultiply(r);
|
23430 | }
|
23431 | n /= 2;
|
23432 | if (n > 0) { r = r.sqr(); }
|
23433 | }
|
23434 | } else {
|
23435 | s = r;
|
23436 | }
|
23437 | if (exp < 0) { return s.reciprocal() }
|
23438 | return s
|
23439 | };
|
23440 | DD.prototype.ceil = function ceil () {
|
23441 | if (this.isNaN()) { return DD.NaN }
|
23442 | var fhi = Math.ceil(this._hi);
|
23443 | var flo = 0.0;
|
23444 | if (fhi === this._hi) {
|
23445 | flo = Math.ceil(this._lo);
|
23446 | }
|
23447 | return new DD(fhi, flo)
|
23448 | };
|
23449 | DD.prototype.compareTo = function compareTo (o) {
|
23450 | var other = o;
|
23451 | if (this._hi < other._hi) { return -1 }
|
23452 | if (this._hi > other._hi) { return 1 }
|
23453 | if (this._lo < other._lo) { return -1 }
|
23454 | if (this._lo > other._lo) { return 1 }
|
23455 | return 0
|
23456 | };
|
23457 | DD.prototype.rint = function rint () {
|
23458 | if (this.isNaN()) { return this }
|
23459 | var plus5 = this.add(0.5);
|
23460 | return plus5.floor()
|
23461 | };
|
23462 | DD.prototype.setValue = function setValue () {
|
23463 | if (arguments[0] instanceof DD) {
|
23464 | var value = arguments[0];
|
23465 | this.init(value);
|
23466 | return this
|
23467 | } else if (typeof arguments[0] === 'number') {
|
23468 | var value$1 = arguments[0];
|
23469 | this.init(value$1);
|
23470 | return this
|
23471 | }
|
23472 | };
|
23473 | DD.prototype.max = function max (x) {
|
23474 | if (this.ge(x)) {
|
23475 | return this
|
23476 | } else {
|
23477 | return x
|
23478 | }
|
23479 | };
|
23480 | DD.prototype.sqrt = function sqrt () {
|
23481 | if (this.isZero()) { return DD.valueOf(0.0) }
|
23482 | if (this.isNegative()) {
|
23483 | return DD.NaN
|
23484 | }
|
23485 | var x = 1.0 / Math.sqrt(this._hi);
|
23486 | var ax = this._hi * x;
|
23487 | var axdd = DD.valueOf(ax);
|
23488 | var diffSq = this.subtract(axdd.sqr());
|
23489 | var d2 = diffSq._hi * (x * 0.5);
|
23490 | return axdd.add(d2)
|
23491 | };
|
23492 | DD.prototype.selfAdd = function selfAdd () {
|
23493 | if (arguments.length === 1) {
|
23494 | if (arguments[0] instanceof DD) {
|
23495 | var y = arguments[0];
|
23496 | return this.selfAdd(y._hi, y._lo)
|
23497 | } else if (typeof arguments[0] === 'number') {
|
23498 | var y$1 = arguments[0];
|
23499 | var H = null;
|
23500 | var h = null;
|
23501 | var S = null;
|
23502 | var s = null;
|
23503 | var e = null;
|
23504 | var f = null;
|
23505 | S = this._hi + y$1;
|
23506 | e = S - this._hi;
|
23507 | s = S - e;
|
23508 | s = y$1 - e + (this._hi - s);
|
23509 | f = s + this._lo;
|
23510 | H = S + f;
|
23511 | h = f + (S - H);
|
23512 | this._hi = H + h;
|
23513 | this._lo = h + (H - this._hi);
|
23514 | return this
|
23515 | }
|
23516 | } else if (arguments.length === 2) {
|
23517 | var yhi = arguments[0];
|
23518 | var ylo = arguments[1];
|
23519 | var H$1 = null;
|
23520 | var h$1 = null;
|
23521 | var T = null;
|
23522 | var t = null;
|
23523 | var S$1 = null;
|
23524 | var s$1 = null;
|
23525 | var e$1 = null;
|
23526 | var f$1 = null;
|
23527 | S$1 = this._hi + yhi;
|
23528 | T = this._lo + ylo;
|
23529 | e$1 = S$1 - this._hi;
|
23530 | f$1 = T - this._lo;
|
23531 | s$1 = S$1 - e$1;
|
23532 | t = T - f$1;
|
23533 | s$1 = yhi - e$1 + (this._hi - s$1);
|
23534 | t = ylo - f$1 + (this._lo - t);
|
23535 | e$1 = s$1 + T;
|
23536 | H$1 = S$1 + e$1;
|
23537 | h$1 = e$1 + (S$1 - H$1);
|
23538 | e$1 = t + h$1;
|
23539 | var zhi = H$1 + e$1;
|
23540 | var zlo = e$1 + (H$1 - zhi);
|
23541 | this._hi = zhi;
|
23542 | this._lo = zlo;
|
23543 | return this
|
23544 | }
|
23545 | };
|
23546 | DD.prototype.selfMultiply = function selfMultiply () {
|
23547 | if (arguments.length === 1) {
|
23548 | if (arguments[0] instanceof DD) {
|
23549 | var y = arguments[0];
|
23550 | return this.selfMultiply(y._hi, y._lo)
|
23551 | } else if (typeof arguments[0] === 'number') {
|
23552 | var y$1 = arguments[0];
|
23553 | return this.selfMultiply(y$1, 0.0)
|
23554 | }
|
23555 | } else if (arguments.length === 2) {
|
23556 | var yhi = arguments[0];
|
23557 | var ylo = arguments[1];
|
23558 | var hx = null;
|
23559 | var tx = null;
|
23560 | var hy = null;
|
23561 | var ty = null;
|
23562 | var C = null;
|
23563 | var c = null;
|
23564 | C = DD.SPLIT * this._hi;
|
23565 | hx = C - this._hi;
|
23566 | c = DD.SPLIT * yhi;
|
23567 | hx = C - hx;
|
23568 | tx = this._hi - hx;
|
23569 | hy = c - yhi;
|
23570 | C = this._hi * yhi;
|
23571 | hy = c - hy;
|
23572 | ty = yhi - hy;
|
23573 | c = hx * hy - C + hx * ty + tx * hy + tx * ty + (this._hi * ylo + this._lo * yhi);
|
23574 | var zhi = C + c;
|
23575 | hx = C - zhi;
|
23576 | var zlo = c + hx;
|
23577 | this._hi = zhi;
|
23578 | this._lo = zlo;
|
23579 | return this
|
23580 | }
|
23581 | };
|
23582 | DD.prototype.selfSqr = function selfSqr () {
|
23583 | return this.selfMultiply(this)
|
23584 | };
|
23585 | DD.prototype.floor = function floor () {
|
23586 | if (this.isNaN()) { return DD.NaN }
|
23587 | var fhi = Math.floor(this._hi);
|
23588 | var flo = 0.0;
|
23589 | if (fhi === this._hi) {
|
23590 | flo = Math.floor(this._lo);
|
23591 | }
|
23592 | return new DD(fhi, flo)
|
23593 | };
|
23594 | DD.prototype.negate = function negate () {
|
23595 | if (this.isNaN()) { return this }
|
23596 | return new DD(-this._hi, -this._lo)
|
23597 | };
|
23598 | DD.prototype.clone = function clone () {
|
23599 |
|
23600 |
|
23601 |
|
23602 |
|
23603 |
|
23604 |
|
23605 |
|
23606 | };
|
23607 | DD.prototype.multiply = function multiply () {
|
23608 | if (arguments[0] instanceof DD) {
|
23609 | var y = arguments[0];
|
23610 | if (y.isNaN()) { return DD.createNaN() }
|
23611 | return DD.copy(this).selfMultiply(y)
|
23612 | } else if (typeof arguments[0] === 'number') {
|
23613 | var y$1 = arguments[0];
|
23614 | if (Double.isNaN(y$1)) { return DD.createNaN() }
|
23615 | return DD.copy(this).selfMultiply(y$1, 0.0)
|
23616 | }
|
23617 | };
|
23618 | DD.prototype.isNaN = function isNaN () {
|
23619 | return Double.isNaN(this._hi)
|
23620 | };
|
23621 | DD.prototype.intValue = function intValue () {
|
23622 | return Math.trunc(this._hi)
|
23623 | };
|
23624 | DD.prototype.toString = function toString () {
|
23625 | var mag = DD.magnitude(this._hi);
|
23626 | if (mag >= -3 && mag <= 20) { return this.toStandardNotation() }
|
23627 | return this.toSciNotation()
|
23628 | };
|
23629 | DD.prototype.toStandardNotation = function toStandardNotation () {
|
23630 | var specialStr = this.getSpecialNumberString();
|
23631 | if (specialStr !== null) { return specialStr }
|
23632 | var magnitude = new Array(1).fill(null);
|
23633 | var sigDigits = this.extractSignificantDigits(true, magnitude);
|
23634 | var decimalPointPos = magnitude[0] + 1;
|
23635 | var num = sigDigits;
|
23636 | if (sigDigits.charAt(0) === '.') {
|
23637 | num = '0' + sigDigits;
|
23638 | } else if (decimalPointPos < 0) {
|
23639 | num = '0.' + DD.stringOfChar('0', -decimalPointPos) + sigDigits;
|
23640 | } else if (sigDigits.indexOf('.') === -1) {
|
23641 | var numZeroes = decimalPointPos - sigDigits.length;
|
23642 | var zeroes = DD.stringOfChar('0', numZeroes);
|
23643 | num = sigDigits + zeroes + '.0';
|
23644 | }
|
23645 | if (this.isNegative()) { return '-' + num }
|
23646 | return num
|
23647 | };
|
23648 | DD.prototype.reciprocal = function reciprocal () {
|
23649 | var hc = null;
|
23650 | var tc = null;
|
23651 | var hy = null;
|
23652 | var ty = null;
|
23653 | var C = null;
|
23654 | var c = null;
|
23655 | var U = null;
|
23656 | var u = null;
|
23657 | C = 1.0 / this._hi;
|
23658 | c = DD.SPLIT * C;
|
23659 | hc = c - C;
|
23660 | u = DD.SPLIT * this._hi;
|
23661 | hc = c - hc;
|
23662 | tc = C - hc;
|
23663 | hy = u - this._hi;
|
23664 | U = C * this._hi;
|
23665 | hy = u - hy;
|
23666 | ty = this._hi - hy;
|
23667 | u = hc * hy - U + hc * ty + tc * hy + tc * ty;
|
23668 | c = (1.0 - U - u - C * this._lo) / this._hi;
|
23669 | var zhi = C + c;
|
23670 | var zlo = C - zhi + c;
|
23671 | return new DD(zhi, zlo)
|
23672 | };
|
23673 | DD.prototype.toSciNotation = function toSciNotation () {
|
23674 | if (this.isZero()) { return DD.SCI_NOT_ZERO }
|
23675 | var specialStr = this.getSpecialNumberString();
|
23676 | if (specialStr !== null) { return specialStr }
|
23677 | var magnitude = new Array(1).fill(null);
|
23678 | var digits = this.extractSignificantDigits(false, magnitude);
|
23679 | var expStr = DD.SCI_NOT_EXPONENT_CHAR + magnitude[0];
|
23680 | if (digits.charAt(0) === '0') {
|
23681 | throw new Error('Found leading zero: ' + digits)
|
23682 | }
|
23683 | var trailingDigits = '';
|
23684 | if (digits.length > 1) { trailingDigits = digits.substring(1); }
|
23685 | var digitsWithDecimal = digits.charAt(0) + '.' + trailingDigits;
|
23686 | if (this.isNegative()) { return '-' + digitsWithDecimal + expStr }
|
23687 | return digitsWithDecimal + expStr
|
23688 | };
|
23689 | DD.prototype.abs = function abs () {
|
23690 | if (this.isNaN()) { return DD.NaN }
|
23691 | if (this.isNegative()) { return this.negate() }
|
23692 | return new DD(this)
|
23693 | };
|
23694 | DD.prototype.isPositive = function isPositive () {
|
23695 | return (this._hi > 0.0 || this._hi === 0.0) && this._lo > 0.0
|
23696 | };
|
23697 | DD.prototype.lt = function lt (y) {
|
23698 | return (this._hi < y._hi || this._hi === y._hi) && this._lo < y._lo
|
23699 | };
|
23700 | DD.prototype.add = function add () {
|
23701 | if (arguments[0] instanceof DD) {
|
23702 | var y = arguments[0];
|
23703 | return DD.copy(this).selfAdd(y)
|
23704 | } else if (typeof arguments[0] === 'number') {
|
23705 | var y$1 = arguments[0];
|
23706 | return DD.copy(this).selfAdd(y$1)
|
23707 | }
|
23708 | };
|
23709 | DD.prototype.init = function init () {
|
23710 | if (arguments.length === 1) {
|
23711 | if (typeof arguments[0] === 'number') {
|
23712 | var x = arguments[0];
|
23713 | this._hi = x;
|
23714 | this._lo = 0.0;
|
23715 | } else if (arguments[0] instanceof DD) {
|
23716 | var dd = arguments[0];
|
23717 | this._hi = dd._hi;
|
23718 | this._lo = dd._lo;
|
23719 | }
|
23720 | } else if (arguments.length === 2) {
|
23721 | var hi = arguments[0];
|
23722 | var lo = arguments[1];
|
23723 | this._hi = hi;
|
23724 | this._lo = lo;
|
23725 | }
|
23726 | };
|
23727 | DD.prototype.gt = function gt (y) {
|
23728 | return (this._hi > y._hi || this._hi === y._hi) && this._lo > y._lo
|
23729 | };
|
23730 | DD.prototype.isNegative = function isNegative () {
|
23731 | return (this._hi < 0.0 || this._hi === 0.0) && this._lo < 0.0
|
23732 | };
|
23733 | DD.prototype.trunc = function trunc () {
|
23734 | if (this.isNaN()) { return DD.NaN }
|
23735 | if (this.isPositive()) { return this.floor(); } else { return this.ceil() }
|
23736 | };
|
23737 | DD.prototype.signum = function signum () {
|
23738 | if (this._hi > 0) { return 1 }
|
23739 | if (this._hi < 0) { return -1 }
|
23740 | if (this._lo > 0) { return 1 }
|
23741 | if (this._lo < 0) { return -1 }
|
23742 | return 0
|
23743 | };
|
23744 | DD.prototype.interfaces_ = function interfaces_ () {
|
23745 | return [Serializable, Comparable, Clonable]
|
23746 | };
|
23747 | DD.prototype.getClass = function getClass () {
|
23748 | return DD
|
23749 | };
|
23750 | DD.sqr = function sqr (x) {
|
23751 | return DD.valueOf(x).selfMultiply(x)
|
23752 | };
|
23753 | DD.valueOf = function valueOf () {
|
23754 | if (typeof arguments[0] === 'string') {
|
23755 | var str = arguments[0];
|
23756 | return DD.parse(str)
|
23757 | } else if (typeof arguments[0] === 'number') {
|
23758 | var x = arguments[0];
|
23759 | return new DD(x)
|
23760 | }
|
23761 | };
|
23762 | DD.sqrt = function sqrt (x) {
|
23763 | return DD.valueOf(x).sqrt()
|
23764 | };
|
23765 | DD.parse = function parse (str) {
|
23766 | var i = 0;
|
23767 | var strlen = str.length;
|
23768 | while (Character.isWhitespace(str.charAt(i))) { i++; }
|
23769 | var isNegative = false;
|
23770 | if (i < strlen) {
|
23771 | var signCh = str.charAt(i);
|
23772 | if (signCh === '-' || signCh === '+') {
|
23773 | i++;
|
23774 | if (signCh === '-') { isNegative = true; }
|
23775 | }
|
23776 | }
|
23777 | var val = new DD();
|
23778 | var numDigits = 0;
|
23779 | var numBeforeDec = 0;
|
23780 | var exp = 0;
|
23781 | while (true) {
|
23782 | if (i >= strlen) { break }
|
23783 | var ch = str.charAt(i);
|
23784 | i++;
|
23785 | if (Character.isDigit(ch)) {
|
23786 | var d = ch - '0';
|
23787 | val.selfMultiply(DD.TEN);
|
23788 | val.selfAdd(d);
|
23789 | numDigits++;
|
23790 | continue
|
23791 | }
|
23792 | if (ch === '.') {
|
23793 | numBeforeDec = numDigits;
|
23794 | continue
|
23795 | }
|
23796 | if (ch === 'e' || ch === 'E') {
|
23797 | var expStr = str.substring(i);
|
23798 | try {
|
23799 | exp = Integer.parseInt(expStr);
|
23800 | } catch (ex) {
|
23801 | if (ex instanceof Error) {
|
23802 | throw new Error('Invalid exponent ' + expStr + ' in string ' + str)
|
23803 | } else { throw ex }
|
23804 | } finally {}
|
23805 | break
|
23806 | }
|
23807 | throw new Error("Unexpected character '" + ch + "' at position " + i + ' in string ' + str)
|
23808 | }
|
23809 | var val2 = val;
|
23810 | var numDecPlaces = numDigits - numBeforeDec - exp;
|
23811 | if (numDecPlaces === 0) {
|
23812 | val2 = val;
|
23813 | } else if (numDecPlaces > 0) {
|
23814 | var scale = DD.TEN.pow(numDecPlaces);
|
23815 | val2 = val.divide(scale);
|
23816 | } else if (numDecPlaces < 0) {
|
23817 | var scale$1 = DD.TEN.pow(-numDecPlaces);
|
23818 | val2 = val.multiply(scale$1);
|
23819 | }
|
23820 | if (isNegative) {
|
23821 | return val2.negate()
|
23822 | }
|
23823 | return val2
|
23824 | };
|
23825 | DD.createNaN = function createNaN () {
|
23826 | return new DD(Double.NaN, Double.NaN)
|
23827 | };
|
23828 | DD.copy = function copy (dd) {
|
23829 | return new DD(dd)
|
23830 | };
|
23831 | DD.magnitude = function magnitude (x) {
|
23832 | var xAbs = Math.abs(x);
|
23833 | var xLog10 = Math.log(xAbs) / Math.log(10);
|
23834 | var xMag = Math.trunc(Math.floor(xLog10));
|
23835 | var xApprox = Math.pow(10, xMag);
|
23836 | if (xApprox * 10 <= xAbs) { xMag += 1; }
|
23837 | return xMag
|
23838 | };
|
23839 | DD.stringOfChar = function stringOfChar (ch, len) {
|
23840 | var buf = new StringBuffer();
|
23841 | for (var i = 0; i < len; i++) {
|
23842 | buf.append(ch);
|
23843 | }
|
23844 | return buf.toString()
|
23845 | };
|
23846 | staticAccessors$7.PI.get = function () { return new DD(3.141592653589793116e+00, 1.224646799147353207e-16) };
|
23847 | staticAccessors$7.TWO_PI.get = function () { return new DD(6.283185307179586232e+00, 2.449293598294706414e-16) };
|
23848 | staticAccessors$7.PI_2.get = function () { return new DD(1.570796326794896558e+00, 6.123233995736766036e-17) };
|
23849 | staticAccessors$7.E.get = function () { return new DD(2.718281828459045091e+00, 1.445646891729250158e-16) };
|
23850 | staticAccessors$7.NaN.get = function () { return new DD(Double.NaN, Double.NaN) };
|
23851 | staticAccessors$7.EPS.get = function () { return 1.23259516440783e-32 };
|
23852 | staticAccessors$7.SPLIT.get = function () { return 134217729.0 };
|
23853 | staticAccessors$7.MAX_PRINT_DIGITS.get = function () { return 32 };
|
23854 | staticAccessors$7.TEN.get = function () { return DD.valueOf(10.0) };
|
23855 | staticAccessors$7.ONE.get = function () { return DD.valueOf(1.0) };
|
23856 | staticAccessors$7.SCI_NOT_EXPONENT_CHAR.get = function () { return 'E' };
|
23857 | staticAccessors$7.SCI_NOT_ZERO.get = function () { return '0.0E0' };
|
23858 |
|
23859 | Object.defineProperties( DD, staticAccessors$7 );
|
23860 |
|
23861 | var CGAlgorithmsDD = function CGAlgorithmsDD () {};
|
23862 |
|
23863 | var staticAccessors$6 = { DP_SAFE_EPSILON: { configurable: true } };
|
23864 |
|
23865 | CGAlgorithmsDD.prototype.interfaces_ = function interfaces_ () {
|
23866 | return []
|
23867 | };
|
23868 | CGAlgorithmsDD.prototype.getClass = function getClass () {
|
23869 | return CGAlgorithmsDD
|
23870 | };
|
23871 | CGAlgorithmsDD.orientationIndex = function orientationIndex (p1, p2, q) {
|
23872 | var index = CGAlgorithmsDD.orientationIndexFilter(p1, p2, q);
|
23873 | if (index <= 1) { return index }
|
23874 | var dx1 = DD.valueOf(p2.x).selfAdd(-p1.x);
|
23875 | var dy1 = DD.valueOf(p2.y).selfAdd(-p1.y);
|
23876 | var dx2 = DD.valueOf(q.x).selfAdd(-p2.x);
|
23877 | var dy2 = DD.valueOf(q.y).selfAdd(-p2.y);
|
23878 | return dx1.selfMultiply(dy2).selfSubtract(dy1.selfMultiply(dx2)).signum()
|
23879 | };
|
23880 | CGAlgorithmsDD.signOfDet2x2 = function signOfDet2x2 (x1, y1, x2, y2) {
|
23881 | var det = x1.multiply(y2).selfSubtract(y1.multiply(x2));
|
23882 | return det.signum()
|
23883 | };
|
23884 | CGAlgorithmsDD.intersection = function intersection (p1, p2, q1, q2) {
|
23885 | var denom1 = DD.valueOf(q2.y).selfSubtract(q1.y).selfMultiply(DD.valueOf(p2.x).selfSubtract(p1.x));
|
23886 | var denom2 = DD.valueOf(q2.x).selfSubtract(q1.x).selfMultiply(DD.valueOf(p2.y).selfSubtract(p1.y));
|
23887 | var denom = denom1.subtract(denom2);
|
23888 | var numx1 = DD.valueOf(q2.x).selfSubtract(q1.x).selfMultiply(DD.valueOf(p1.y).selfSubtract(q1.y));
|
23889 | var numx2 = DD.valueOf(q2.y).selfSubtract(q1.y).selfMultiply(DD.valueOf(p1.x).selfSubtract(q1.x));
|
23890 | var numx = numx1.subtract(numx2);
|
23891 | var fracP = numx.selfDivide(denom).doubleValue();
|
23892 | var x = DD.valueOf(p1.x).selfAdd(DD.valueOf(p2.x).selfSubtract(p1.x).selfMultiply(fracP)).doubleValue();
|
23893 | var numy1 = DD.valueOf(p2.x).selfSubtract(p1.x).selfMultiply(DD.valueOf(p1.y).selfSubtract(q1.y));
|
23894 | var numy2 = DD.valueOf(p2.y).selfSubtract(p1.y).selfMultiply(DD.valueOf(p1.x).selfSubtract(q1.x));
|
23895 | var numy = numy1.subtract(numy2);
|
23896 | var fracQ = numy.selfDivide(denom).doubleValue();
|
23897 | var y = DD.valueOf(q1.y).selfAdd(DD.valueOf(q2.y).selfSubtract(q1.y).selfMultiply(fracQ)).doubleValue();
|
23898 | return new Coordinate(x, y)
|
23899 | };
|
23900 | CGAlgorithmsDD.orientationIndexFilter = function orientationIndexFilter (pa, pb, pc) {
|
23901 | var detsum = null;
|
23902 | var detleft = (pa.x - pc.x) * (pb.y - pc.y);
|
23903 | var detright = (pa.y - pc.y) * (pb.x - pc.x);
|
23904 | var det = detleft - detright;
|
23905 | if (detleft > 0.0) {
|
23906 | if (detright <= 0.0) {
|
23907 | return CGAlgorithmsDD.signum(det)
|
23908 | } else {
|
23909 | detsum = detleft + detright;
|
23910 | }
|
23911 | } else if (detleft < 0.0) {
|
23912 | if (detright >= 0.0) {
|
23913 | return CGAlgorithmsDD.signum(det)
|
23914 | } else {
|
23915 | detsum = -detleft - detright;
|
23916 | }
|
23917 | } else {
|
23918 | return CGAlgorithmsDD.signum(det)
|
23919 | }
|
23920 | var errbound = CGAlgorithmsDD.DP_SAFE_EPSILON * detsum;
|
23921 | if (det >= errbound || -det >= errbound) {
|
23922 | return CGAlgorithmsDD.signum(det)
|
23923 | }
|
23924 | return 2
|
23925 | };
|
23926 | CGAlgorithmsDD.signum = function signum (x) {
|
23927 | if (x > 0) { return 1 }
|
23928 | if (x < 0) { return -1 }
|
23929 | return 0
|
23930 | };
|
23931 | staticAccessors$6.DP_SAFE_EPSILON.get = function () { return 1e-15 };
|
23932 |
|
23933 | Object.defineProperties( CGAlgorithmsDD, staticAccessors$6 );
|
23934 |
|
23935 | var CoordinateSequence = function CoordinateSequence () {};
|
23936 |
|
23937 | var staticAccessors$8 = { X: { configurable: true },Y: { configurable: true },Z: { configurable: true },M: { configurable: true } };
|
23938 |
|
23939 | staticAccessors$8.X.get = function () { return 0 };
|
23940 | staticAccessors$8.Y.get = function () { return 1 };
|
23941 | staticAccessors$8.Z.get = function () { return 2 };
|
23942 | staticAccessors$8.M.get = function () { return 3 };
|
23943 | CoordinateSequence.prototype.setOrdinate = function setOrdinate (index, ordinateIndex, value) {};
|
23944 | CoordinateSequence.prototype.size = function size () {};
|
23945 | CoordinateSequence.prototype.getOrdinate = function getOrdinate (index, ordinateIndex) {};
|
23946 | CoordinateSequence.prototype.getCoordinate = function getCoordinate () {};
|
23947 | CoordinateSequence.prototype.getCoordinateCopy = function getCoordinateCopy (i) {};
|
23948 | CoordinateSequence.prototype.getDimension = function getDimension () {};
|
23949 | CoordinateSequence.prototype.getX = function getX (index) {};
|
23950 | CoordinateSequence.prototype.clone = function clone () {};
|
23951 | CoordinateSequence.prototype.expandEnvelope = function expandEnvelope (env) {};
|
23952 | CoordinateSequence.prototype.copy = function copy () {};
|
23953 | CoordinateSequence.prototype.getY = function getY (index) {};
|
23954 | CoordinateSequence.prototype.toCoordinateArray = function toCoordinateArray () {};
|
23955 | CoordinateSequence.prototype.interfaces_ = function interfaces_ () {
|
23956 | return [Clonable]
|
23957 | };
|
23958 | CoordinateSequence.prototype.getClass = function getClass () {
|
23959 | return CoordinateSequence
|
23960 | };
|
23961 |
|
23962 | Object.defineProperties( CoordinateSequence, staticAccessors$8 );
|
23963 |
|
23964 | var Exception = function Exception () {};
|
23965 |
|
23966 | var NotRepresentableException = (function (Exception$$1) {
|
23967 | function NotRepresentableException () {
|
23968 | Exception$$1.call(this, 'Projective point not representable on the Cartesian plane.');
|
23969 | }
|
23970 |
|
23971 | if ( Exception$$1 ) NotRepresentableException.__proto__ = Exception$$1;
|
23972 | NotRepresentableException.prototype = Object.create( Exception$$1 && Exception$$1.prototype );
|
23973 | NotRepresentableException.prototype.constructor = NotRepresentableException;
|
23974 | NotRepresentableException.prototype.interfaces_ = function interfaces_ () {
|
23975 | return []
|
23976 | };
|
23977 | NotRepresentableException.prototype.getClass = function getClass () {
|
23978 | return NotRepresentableException
|
23979 | };
|
23980 |
|
23981 | return NotRepresentableException;
|
23982 | }(Exception));
|
23983 |
|
23984 | var System = function System () {};
|
23985 |
|
23986 | System.arraycopy = function arraycopy (src, srcPos, dest, destPos, len) {
|
23987 | var c = 0;
|
23988 | for (var i = srcPos; i < srcPos + len; i++) {
|
23989 | dest[destPos + c] = src[i];
|
23990 | c++;
|
23991 | }
|
23992 | };
|
23993 |
|
23994 | System.getProperty = function getProperty (name) {
|
23995 | return {
|
23996 | 'line.separator': '\n'
|
23997 | }[name]
|
23998 | };
|
23999 |
|
24000 | var HCoordinate = function HCoordinate () {
|
24001 | this.x = null;
|
24002 | this.y = null;
|
24003 | this.w = null;
|
24004 | if (arguments.length === 0) {
|
24005 | this.x = 0.0;
|
24006 | this.y = 0.0;
|
24007 | this.w = 1.0;
|
24008 | } else if (arguments.length === 1) {
|
24009 | var p = arguments[0];
|
24010 | this.x = p.x;
|
24011 | this.y = p.y;
|
24012 | this.w = 1.0;
|
24013 | } else if (arguments.length === 2) {
|
24014 | if (typeof arguments[0] === 'number' && typeof arguments[1] === 'number') {
|
24015 | var _x = arguments[0];
|
24016 | var _y = arguments[1];
|
24017 | this.x = _x;
|
24018 | this.y = _y;
|
24019 | this.w = 1.0;
|
24020 | } else if (arguments[0] instanceof HCoordinate && arguments[1] instanceof HCoordinate) {
|
24021 | var p1 = arguments[0];
|
24022 | var p2 = arguments[1];
|
24023 | this.x = p1.y * p2.w - p2.y * p1.w;
|
24024 | this.y = p2.x * p1.w - p1.x * p2.w;
|
24025 | this.w = p1.x * p2.y - p2.x * p1.y;
|
24026 | } else if (arguments[0] instanceof Coordinate && arguments[1] instanceof Coordinate) {
|
24027 | var p1$1 = arguments[0];
|
24028 | var p2$1 = arguments[1];
|
24029 | this.x = p1$1.y - p2$1.y;
|
24030 | this.y = p2$1.x - p1$1.x;
|
24031 | this.w = p1$1.x * p2$1.y - p2$1.x * p1$1.y;
|
24032 | }
|
24033 | } else if (arguments.length === 3) {
|
24034 | var _x$1 = arguments[0];
|
24035 | var _y$1 = arguments[1];
|
24036 | var _w = arguments[2];
|
24037 | this.x = _x$1;
|
24038 | this.y = _y$1;
|
24039 | this.w = _w;
|
24040 | } else if (arguments.length === 4) {
|
24041 | var p1$2 = arguments[0];
|
24042 | var p2$2 = arguments[1];
|
24043 | var q1 = arguments[2];
|
24044 | var q2 = arguments[3];
|
24045 | var px = p1$2.y - p2$2.y;
|
24046 | var py = p2$2.x - p1$2.x;
|
24047 | var pw = p1$2.x * p2$2.y - p2$2.x * p1$2.y;
|
24048 | var qx = q1.y - q2.y;
|
24049 | var qy = q2.x - q1.x;
|
24050 | var qw = q1.x * q2.y - q2.x * q1.y;
|
24051 | this.x = py * qw - qy * pw;
|
24052 | this.y = qx * pw - px * qw;
|
24053 | this.w = px * qy - qx * py;
|
24054 | }
|
24055 | };
|
24056 | HCoordinate.prototype.getY = function getY () {
|
24057 | var a = this.y / this.w;
|
24058 | if (Double.isNaN(a) || Double.isInfinite(a)) {
|
24059 | throw new NotRepresentableException()
|
24060 | }
|
24061 | return a
|
24062 | };
|
24063 | HCoordinate.prototype.getX = function getX () {
|
24064 | var a = this.x / this.w;
|
24065 | if (Double.isNaN(a) || Double.isInfinite(a)) {
|
24066 | throw new NotRepresentableException()
|
24067 | }
|
24068 | return a
|
24069 | };
|
24070 | HCoordinate.prototype.getCoordinate = function getCoordinate () {
|
24071 | var p = new Coordinate();
|
24072 | p.x = this.getX();
|
24073 | p.y = this.getY();
|
24074 | return p
|
24075 | };
|
24076 | HCoordinate.prototype.interfaces_ = function interfaces_ () {
|
24077 | return []
|
24078 | };
|
24079 | HCoordinate.prototype.getClass = function getClass () {
|
24080 | return HCoordinate
|
24081 | };
|
24082 | HCoordinate.intersection = function intersection (p1, p2, q1, q2) {
|
24083 | var px = p1.y - p2.y;
|
24084 | var py = p2.x - p1.x;
|
24085 | var pw = p1.x * p2.y - p2.x * p1.y;
|
24086 | var qx = q1.y - q2.y;
|
24087 | var qy = q2.x - q1.x;
|
24088 | var qw = q1.x * q2.y - q2.x * q1.y;
|
24089 | var x = py * qw - qy * pw;
|
24090 | var y = qx * pw - px * qw;
|
24091 | var w = px * qy - qx * py;
|
24092 | var xInt = x / w;
|
24093 | var yInt = y / w;
|
24094 | if (Double.isNaN(xInt) || (Double.isInfinite(xInt) || Double.isNaN(yInt)) || Double.isInfinite(yInt)) {
|
24095 | throw new NotRepresentableException()
|
24096 | }
|
24097 | return new Coordinate(xInt, yInt)
|
24098 | };
|
24099 |
|
24100 | var Envelope = function Envelope () {
|
24101 | this._minx = null;
|
24102 | this._maxx = null;
|
24103 | this._miny = null;
|
24104 | this._maxy = null;
|
24105 | if (arguments.length === 0) {
|
24106 | this.init();
|
24107 | } else if (arguments.length === 1) {
|
24108 | if (arguments[0] instanceof Coordinate) {
|
24109 | var p = arguments[0];
|
24110 | this.init(p.x, p.x, p.y, p.y);
|
24111 | } else if (arguments[0] instanceof Envelope) {
|
24112 | var env = arguments[0];
|
24113 | this.init(env);
|
24114 | }
|
24115 | } else if (arguments.length === 2) {
|
24116 | var p1 = arguments[0];
|
24117 | var p2 = arguments[1];
|
24118 | this.init(p1.x, p2.x, p1.y, p2.y);
|
24119 | } else if (arguments.length === 4) {
|
24120 | var x1 = arguments[0];
|
24121 | var x2 = arguments[1];
|
24122 | var y1 = arguments[2];
|
24123 | var y2 = arguments[3];
|
24124 | this.init(x1, x2, y1, y2);
|
24125 | }
|
24126 | };
|
24127 |
|
24128 | var staticAccessors$9 = { serialVersionUID: { configurable: true } };
|
24129 | Envelope.prototype.getArea = function getArea () {
|
24130 | return this.getWidth() * this.getHeight()
|
24131 | };
|
24132 | Envelope.prototype.equals = function equals (other) {
|
24133 | if (!(other instanceof Envelope)) {
|
24134 | return false
|
24135 | }
|
24136 | var otherEnvelope = other;
|
24137 | if (this.isNull()) {
|
24138 | return otherEnvelope.isNull()
|
24139 | }
|
24140 | return this._maxx === otherEnvelope.getMaxX() && this._maxy === otherEnvelope.getMaxY() && this._minx === otherEnvelope.getMinX() && this._miny === otherEnvelope.getMinY()
|
24141 | };
|
24142 | Envelope.prototype.intersection = function intersection (env) {
|
24143 | if (this.isNull() || env.isNull() || !this.intersects(env)) { return new Envelope() }
|
24144 | var intMinX = this._minx > env._minx ? this._minx : env._minx;
|
24145 | var intMinY = this._miny > env._miny ? this._miny : env._miny;
|
24146 | var intMaxX = this._maxx < env._maxx ? this._maxx : env._maxx;
|
24147 | var intMaxY = this._maxy < env._maxy ? this._maxy : env._maxy;
|
24148 | return new Envelope(intMinX, intMaxX, intMinY, intMaxY)
|
24149 | };
|
24150 | Envelope.prototype.isNull = function isNull () {
|
24151 | return this._maxx < this._minx
|
24152 | };
|
24153 | Envelope.prototype.getMaxX = function getMaxX () {
|
24154 | return this._maxx
|
24155 | };
|
24156 | Envelope.prototype.covers = function covers () {
|
24157 | if (arguments.length === 1) {
|
24158 | if (arguments[0] instanceof Coordinate) {
|
24159 | var p = arguments[0];
|
24160 | return this.covers(p.x, p.y)
|
24161 | } else if (arguments[0] instanceof Envelope) {
|
24162 | var other = arguments[0];
|
24163 | if (this.isNull() || other.isNull()) {
|
24164 | return false
|
24165 | }
|
24166 | return other.getMinX() >= this._minx && other.getMaxX() <= this._maxx && other.getMinY() >= this._miny && other.getMaxY() <= this._maxy
|
24167 | }
|
24168 | } else if (arguments.length === 2) {
|
24169 | var x = arguments[0];
|
24170 | var y = arguments[1];
|
24171 | if (this.isNull()) { return false }
|
24172 | return x >= this._minx && x <= this._maxx && y >= this._miny && y <= this._maxy
|
24173 | }
|
24174 | };
|
24175 | Envelope.prototype.intersects = function intersects () {
|
24176 | if (arguments.length === 1) {
|
24177 | if (arguments[0] instanceof Envelope) {
|
24178 | var other = arguments[0];
|
24179 | if (this.isNull() || other.isNull()) {
|
24180 | return false
|
24181 | }
|
24182 | return !(other._minx > this._maxx || other._maxx < this._minx || other._miny > this._maxy || other._maxy < this._miny)
|
24183 | } else if (arguments[0] instanceof Coordinate) {
|
24184 | var p = arguments[0];
|
24185 | return this.intersects(p.x, p.y)
|
24186 | }
|
24187 | } else if (arguments.length === 2) {
|
24188 | var x = arguments[0];
|
24189 | var y = arguments[1];
|
24190 | if (this.isNull()) { return false }
|
24191 | return !(x > this._maxx || x < this._minx || y > this._maxy || y < this._miny)
|
24192 | }
|
24193 | };
|
24194 | Envelope.prototype.getMinY = function getMinY () {
|
24195 | return this._miny
|
24196 | };
|
24197 | Envelope.prototype.getMinX = function getMinX () {
|
24198 | return this._minx
|
24199 | };
|
24200 | Envelope.prototype.expandToInclude = function expandToInclude () {
|
24201 | if (arguments.length === 1) {
|
24202 | if (arguments[0] instanceof Coordinate) {
|
24203 | var p = arguments[0];
|
24204 | this.expandToInclude(p.x, p.y);
|
24205 | } else if (arguments[0] instanceof Envelope) {
|
24206 | var other = arguments[0];
|
24207 | if (other.isNull()) {
|
24208 | return null
|
24209 | }
|
24210 | if (this.isNull()) {
|
24211 | this._minx = other.getMinX();
|
24212 | this._maxx = other.getMaxX();
|
24213 | this._miny = other.getMinY();
|
24214 | this._maxy = other.getMaxY();
|
24215 | } else {
|
24216 | if (other._minx < this._minx) {
|
24217 | this._minx = other._minx;
|
24218 | }
|
24219 | if (other._maxx > this._maxx) {
|
24220 | this._maxx = other._maxx;
|
24221 | }
|
24222 | if (other._miny < this._miny) {
|
24223 | this._miny = other._miny;
|
24224 | }
|
24225 | if (other._maxy > this._maxy) {
|
24226 | this._maxy = other._maxy;
|
24227 | }
|
24228 | }
|
24229 | }
|
24230 | } else if (arguments.length === 2) {
|
24231 | var x = arguments[0];
|
24232 | var y = arguments[1];
|
24233 | if (this.isNull()) {
|
24234 | this._minx = x;
|
24235 | this._maxx = x;
|
24236 | this._miny = y;
|
24237 | this._maxy = y;
|
24238 | } else {
|
24239 | if (x < this._minx) {
|
24240 | this._minx = x;
|
24241 | }
|
24242 | if (x > this._maxx) {
|
24243 | this._maxx = x;
|
24244 | }
|
24245 | if (y < this._miny) {
|
24246 | this._miny = y;
|
24247 | }
|
24248 | if (y > this._maxy) {
|
24249 | this._maxy = y;
|
24250 | }
|
24251 | }
|
24252 | }
|
24253 | };
|
24254 | Envelope.prototype.minExtent = function minExtent () {
|
24255 | if (this.isNull()) { return 0.0 }
|
24256 | var w = this.getWidth();
|
24257 | var h = this.getHeight();
|
24258 | if (w < h) { return w }
|
24259 | return h
|
24260 | };
|
24261 | Envelope.prototype.getWidth = function getWidth () {
|
24262 | if (this.isNull()) {
|
24263 | return 0
|
24264 | }
|
24265 | return this._maxx - this._minx
|
24266 | };
|
24267 | Envelope.prototype.compareTo = function compareTo (o) {
|
24268 | var env = o;
|
24269 | if (this.isNull()) {
|
24270 | if (env.isNull()) { return 0 }
|
24271 | return -1
|
24272 | } else {
|
24273 | if (env.isNull()) { return 1 }
|
24274 | }
|
24275 | if (this._minx < env._minx) { return -1 }
|
24276 | if (this._minx > env._minx) { return 1 }
|
24277 | if (this._miny < env._miny) { return -1 }
|
24278 | if (this._miny > env._miny) { return 1 }
|
24279 | if (this._maxx < env._maxx) { return -1 }
|
24280 | if (this._maxx > env._maxx) { return 1 }
|
24281 | if (this._maxy < env._maxy) { return -1 }
|
24282 | if (this._maxy > env._maxy) { return 1 }
|
24283 | return 0
|
24284 | };
|
24285 | Envelope.prototype.translate = function translate (transX, transY) {
|
24286 | if (this.isNull()) {
|
24287 | return null
|
24288 | }
|
24289 | this.init(this.getMinX() + transX, this.getMaxX() + transX, this.getMinY() + transY, this.getMaxY() + transY);
|
24290 | };
|
24291 | Envelope.prototype.toString = function toString () {
|
24292 | return 'Env[' + this._minx + ' : ' + this._maxx + ', ' + this._miny + ' : ' + this._maxy + ']'
|
24293 | };
|
24294 | Envelope.prototype.setToNull = function setToNull () {
|
24295 | this._minx = 0;
|
24296 | this._maxx = -1;
|
24297 | this._miny = 0;
|
24298 | this._maxy = -1;
|
24299 | };
|
24300 | Envelope.prototype.getHeight = function getHeight () {
|
24301 | if (this.isNull()) {
|
24302 | return 0
|
24303 | }
|
24304 | return this._maxy - this._miny
|
24305 | };
|
24306 | Envelope.prototype.maxExtent = function maxExtent () {
|
24307 | if (this.isNull()) { return 0.0 }
|
24308 | var w = this.getWidth();
|
24309 | var h = this.getHeight();
|
24310 | if (w > h) { return w }
|
24311 | return h
|
24312 | };
|
24313 | Envelope.prototype.expandBy = function expandBy () {
|
24314 | if (arguments.length === 1) {
|
24315 | var distance = arguments[0];
|
24316 | this.expandBy(distance, distance);
|
24317 | } else if (arguments.length === 2) {
|
24318 | var deltaX = arguments[0];
|
24319 | var deltaY = arguments[1];
|
24320 | if (this.isNull()) { return null }
|
24321 | this._minx -= deltaX;
|
24322 | this._maxx += deltaX;
|
24323 | this._miny -= deltaY;
|
24324 | this._maxy += deltaY;
|
24325 | if (this._minx > this._maxx || this._miny > this._maxy) { this.setToNull(); }
|
24326 | }
|
24327 | };
|
24328 | Envelope.prototype.contains = function contains () {
|
24329 | if (arguments.length === 1) {
|
24330 | if (arguments[0] instanceof Envelope) {
|
24331 | var other = arguments[0];
|
24332 | return this.covers(other)
|
24333 | } else if (arguments[0] instanceof Coordinate) {
|
24334 | var p = arguments[0];
|
24335 | return this.covers(p)
|
24336 | }
|
24337 | } else if (arguments.length === 2) {
|
24338 | var x = arguments[0];
|
24339 | var y = arguments[1];
|
24340 | return this.covers(x, y)
|
24341 | }
|
24342 | };
|
24343 | Envelope.prototype.centre = function centre () {
|
24344 | if (this.isNull()) { return null }
|
24345 | return new Coordinate((this.getMinX() + this.getMaxX()) / 2.0, (this.getMinY() + this.getMaxY()) / 2.0)
|
24346 | };
|
24347 | Envelope.prototype.init = function init () {
|
24348 | if (arguments.length === 0) {
|
24349 | this.setToNull();
|
24350 | } else if (arguments.length === 1) {
|
24351 | if (arguments[0] instanceof Coordinate) {
|
24352 | var p = arguments[0];
|
24353 | this.init(p.x, p.x, p.y, p.y);
|
24354 | } else if (arguments[0] instanceof Envelope) {
|
24355 | var env = arguments[0];
|
24356 | this._minx = env._minx;
|
24357 | this._maxx = env._maxx;
|
24358 | this._miny = env._miny;
|
24359 | this._maxy = env._maxy;
|
24360 | }
|
24361 | } else if (arguments.length === 2) {
|
24362 | var p1 = arguments[0];
|
24363 | var p2 = arguments[1];
|
24364 | this.init(p1.x, p2.x, p1.y, p2.y);
|
24365 | } else if (arguments.length === 4) {
|
24366 | var x1 = arguments[0];
|
24367 | var x2 = arguments[1];
|
24368 | var y1 = arguments[2];
|
24369 | var y2 = arguments[3];
|
24370 | if (x1 < x2) {
|
24371 | this._minx = x1;
|
24372 | this._maxx = x2;
|
24373 | } else {
|
24374 | this._minx = x2;
|
24375 | this._maxx = x1;
|
24376 | }
|
24377 | if (y1 < y2) {
|
24378 | this._miny = y1;
|
24379 | this._maxy = y2;
|
24380 | } else {
|
24381 | this._miny = y2;
|
24382 | this._maxy = y1;
|
24383 | }
|
24384 | }
|
24385 | };
|
24386 | Envelope.prototype.getMaxY = function getMaxY () {
|
24387 | return this._maxy
|
24388 | };
|
24389 | Envelope.prototype.distance = function distance (env) {
|
24390 | if (this.intersects(env)) { return 0 }
|
24391 | var dx = 0.0;
|
24392 | if (this._maxx < env._minx) { dx = env._minx - this._maxx; } else if (this._minx > env._maxx) { dx = this._minx - env._maxx; }
|
24393 | var dy = 0.0;
|
24394 | if (this._maxy < env._miny) { dy = env._miny - this._maxy; } else if (this._miny > env._maxy) { dy = this._miny - env._maxy; }
|
24395 | if (dx === 0.0) { return dy }
|
24396 | if (dy === 0.0) { return dx }
|
24397 | return Math.sqrt(dx * dx + dy * dy)
|
24398 | };
|
24399 | Envelope.prototype.hashCode = function hashCode () {
|
24400 | var result = 17;
|
24401 | result = 37 * result + Coordinate.hashCode(this._minx);
|
24402 | result = 37 * result + Coordinate.hashCode(this._maxx);
|
24403 | result = 37 * result + Coordinate.hashCode(this._miny);
|
24404 | result = 37 * result + Coordinate.hashCode(this._maxy);
|
24405 | return result
|
24406 | };
|
24407 | Envelope.prototype.interfaces_ = function interfaces_ () {
|
24408 | return [Comparable, Serializable]
|
24409 | };
|
24410 | Envelope.prototype.getClass = function getClass () {
|
24411 | return Envelope
|
24412 | };
|
24413 | Envelope.intersects = function intersects () {
|
24414 | if (arguments.length === 3) {
|
24415 | var p1 = arguments[0];
|
24416 | var p2 = arguments[1];
|
24417 | var q = arguments[2];
|
24418 | if (q.x >= (p1.x < p2.x ? p1.x : p2.x) && q.x <= (p1.x > p2.x ? p1.x : p2.x) && (q.y >= (p1.y < p2.y ? p1.y : p2.y) && q.y <= (p1.y > p2.y ? p1.y : p2.y))) {
|
24419 | return true
|
24420 | }
|
24421 | return false
|
24422 | } else if (arguments.length === 4) {
|
24423 | var p1$1 = arguments[0];
|
24424 | var p2$1 = arguments[1];
|
24425 | var q1 = arguments[2];
|
24426 | var q2 = arguments[3];
|
24427 | var minq = Math.min(q1.x, q2.x);
|
24428 | var maxq = Math.max(q1.x, q2.x);
|
24429 | var minp = Math.min(p1$1.x, p2$1.x);
|
24430 | var maxp = Math.max(p1$1.x, p2$1.x);
|
24431 | if (minp > maxq) { return false }
|
24432 | if (maxp < minq) { return false }
|
24433 | minq = Math.min(q1.y, q2.y);
|
24434 | maxq = Math.max(q1.y, q2.y);
|
24435 | minp = Math.min(p1$1.y, p2$1.y);
|
24436 | maxp = Math.max(p1$1.y, p2$1.y);
|
24437 | if (minp > maxq) { return false }
|
24438 | if (maxp < minq) { return false }
|
24439 | return true
|
24440 | }
|
24441 | };
|
24442 | staticAccessors$9.serialVersionUID.get = function () { return 5873921885273102420 };
|
24443 |
|
24444 | Object.defineProperties( Envelope, staticAccessors$9 );
|
24445 |
|
24446 | var regExes = {
|
24447 | 'typeStr': /^\s*(\w+)\s*\(\s*(.*)\s*\)\s*$/,
|
24448 | 'emptyTypeStr': /^\s*(\w+)\s*EMPTY\s*$/,
|
24449 | 'spaces': /\s+/,
|
24450 | 'parenComma': /\)\s*,\s*\(/,
|
24451 | 'doubleParenComma': /\)\s*\)\s*,\s*\(\s*\(/,
|
24452 | 'trimParens': /^\s*\(?(.*?)\)?\s*$/
|
24453 | };
|
24454 |
|
24455 |
|
24456 |
|
24457 |
|
24458 |
|
24459 |
|
24460 |
|
24461 |
|
24462 |
|
24463 |
|
24464 |
|
24465 |
|
24466 |
|
24467 |
|
24468 | var WKTParser = function WKTParser (geometryFactory) {
|
24469 | this.geometryFactory = geometryFactory || new GeometryFactory();
|
24470 | };
|
24471 |
|
24472 |
|
24473 |
|
24474 |
|
24475 |
|
24476 |
|
24477 |
|
24478 |
|
24479 |
|
24480 | WKTParser.prototype.read = function read (wkt) {
|
24481 | var geometry, type, str;
|
24482 | wkt = wkt.replace(/[\n\r]/g, ' ');
|
24483 | var matches = regExes.typeStr.exec(wkt);
|
24484 | if (wkt.search('EMPTY') !== -1) {
|
24485 | matches = regExes.emptyTypeStr.exec(wkt);
|
24486 | matches[2] = undefined;
|
24487 | }
|
24488 | if (matches) {
|
24489 | type = matches[1].toLowerCase();
|
24490 | str = matches[2];
|
24491 | if (parse$1[type]) {
|
24492 | geometry = parse$1[type].apply(this, [str]);
|
24493 | }
|
24494 | }
|
24495 |
|
24496 | if (geometry === undefined) { throw new Error('Could not parse WKT ' + wkt) }
|
24497 |
|
24498 | return geometry
|
24499 | };
|
24500 |
|
24501 |
|
24502 |
|
24503 |
|
24504 |
|
24505 |
|
24506 |
|
24507 |
|
24508 | WKTParser.prototype.write = function write (geometry) {
|
24509 | return this.extractGeometry(geometry)
|
24510 | };
|
24511 |
|
24512 |
|
24513 |
|
24514 |
|
24515 |
|
24516 |
|
24517 |
|
24518 |
|
24519 | WKTParser.prototype.extractGeometry = function extractGeometry (geometry) {
|
24520 | var type = geometry.getGeometryType().toLowerCase();
|
24521 | if (!extract$1[type]) {
|
24522 | return null
|
24523 | }
|
24524 | var wktType = type.toUpperCase();
|
24525 | var data;
|
24526 | if (geometry.isEmpty()) {
|
24527 | data = wktType + ' EMPTY';
|
24528 | } else {
|
24529 | data = wktType + '(' + extract$1[type].apply(this, [geometry]) + ')';
|
24530 | }
|
24531 | return data
|
24532 | };
|
24533 |
|
24534 |
|
24535 |
|
24536 |
|
24537 |
|
24538 |
|
24539 | var extract$1 = {
|
24540 | coordinate: function coordinate (coordinate$1) {
|
24541 | return coordinate$1.x + ' ' + coordinate$1.y
|
24542 | },
|
24543 |
|
24544 | |
24545 |
|
24546 |
|
24547 |
|
24548 |
|
24549 |
|
24550 |
|
24551 | point: function point (point$1) {
|
24552 | return extract$1.coordinate.call(this, point$1._coordinates._coordinates[0])
|
24553 | },
|
24554 |
|
24555 | |
24556 |
|
24557 |
|
24558 |
|
24559 |
|
24560 |
|
24561 |
|
24562 |
|
24563 | multipoint: function multipoint (multipoint$1) {
|
24564 | var this$1 = this;
|
24565 |
|
24566 | var array = [];
|
24567 | for (var i = 0, len = multipoint$1._geometries.length; i < len; ++i) {
|
24568 | array.push('(' + extract$1.point.apply(this$1, [multipoint$1._geometries[i]]) + ')');
|
24569 | }
|
24570 | return array.join(',')
|
24571 | },
|
24572 |
|
24573 | |
24574 |
|
24575 |
|
24576 |
|
24577 |
|
24578 |
|
24579 | linestring: function linestring (linestring$1) {
|
24580 | var this$1 = this;
|
24581 |
|
24582 | var array = [];
|
24583 | for (var i = 0, len = linestring$1._points._coordinates.length; i < len; ++i) {
|
24584 | array.push(extract$1.coordinate.apply(this$1, [linestring$1._points._coordinates[i]]));
|
24585 | }
|
24586 | return array.join(',')
|
24587 | },
|
24588 |
|
24589 | linearring: function linearring (linearring$1) {
|
24590 | var this$1 = this;
|
24591 |
|
24592 | var array = [];
|
24593 | for (var i = 0, len = linearring$1._points._coordinates.length; i < len; ++i) {
|
24594 | array.push(extract$1.coordinate.apply(this$1, [linearring$1._points._coordinates[i]]));
|
24595 | }
|
24596 | return array.join(',')
|
24597 | },
|
24598 |
|
24599 | |
24600 |
|
24601 |
|
24602 |
|
24603 |
|
24604 |
|
24605 |
|
24606 | multilinestring: function multilinestring (multilinestring$1) {
|
24607 | var this$1 = this;
|
24608 |
|
24609 | var array = [];
|
24610 | for (var i = 0, len = multilinestring$1._geometries.length; i < len; ++i) {
|
24611 | array.push('(' +
|
24612 | extract$1.linestring.apply(this$1, [multilinestring$1._geometries[i]]) +
|
24613 | ')');
|
24614 | }
|
24615 | return array.join(',')
|
24616 | },
|
24617 |
|
24618 | |
24619 |
|
24620 |
|
24621 |
|
24622 |
|
24623 |
|
24624 | polygon: function polygon (polygon$1) {
|
24625 | var this$1 = this;
|
24626 |
|
24627 | var array = [];
|
24628 | array.push('(' + extract$1.linestring.apply(this, [polygon$1._shell]) + ')');
|
24629 | for (var i = 0, len = polygon$1._holes.length; i < len; ++i) {
|
24630 | array.push('(' + extract$1.linestring.apply(this$1, [polygon$1._holes[i]]) + ')');
|
24631 | }
|
24632 | return array.join(',')
|
24633 | },
|
24634 |
|
24635 | |
24636 |
|
24637 |
|
24638 |
|
24639 |
|
24640 |
|
24641 | multipolygon: function multipolygon (multipolygon$1) {
|
24642 | var this$1 = this;
|
24643 |
|
24644 | var array = [];
|
24645 | for (var i = 0, len = multipolygon$1._geometries.length; i < len; ++i) {
|
24646 | array.push('(' + extract$1.polygon.apply(this$1, [multipolygon$1._geometries[i]]) + ')');
|
24647 | }
|
24648 | return array.join(',')
|
24649 | },
|
24650 |
|
24651 | |
24652 |
|
24653 |
|
24654 |
|
24655 |
|
24656 |
|
24657 |
|
24658 | geometrycollection: function geometrycollection (collection) {
|
24659 | var this$1 = this;
|
24660 |
|
24661 | var array = [];
|
24662 | for (var i = 0, len = collection._geometries.length; i < len; ++i) {
|
24663 | array.push(this$1.extractGeometry(collection._geometries[i]));
|
24664 | }
|
24665 | return array.join(',')
|
24666 | }
|
24667 | };
|
24668 |
|
24669 |
|
24670 |
|
24671 |
|
24672 |
|
24673 |
|
24674 | var parse$1 = {
|
24675 | |
24676 |
|
24677 |
|
24678 |
|
24679 |
|
24680 |
|
24681 |
|
24682 | point: function point (str) {
|
24683 | if (str === undefined) {
|
24684 | return this.geometryFactory.createPoint()
|
24685 | }
|
24686 |
|
24687 | var coords = str.trim().split(regExes.spaces);
|
24688 | return this.geometryFactory.createPoint(new Coordinate(Number.parseFloat(coords[0]),
|
24689 | Number.parseFloat(coords[1])))
|
24690 | },
|
24691 |
|
24692 | |
24693 |
|
24694 |
|
24695 |
|
24696 |
|
24697 |
|
24698 |
|
24699 | multipoint: function multipoint (str) {
|
24700 | var this$1 = this;
|
24701 |
|
24702 | if (str === undefined) {
|
24703 | return this.geometryFactory.createMultiPoint()
|
24704 | }
|
24705 |
|
24706 | var point;
|
24707 | var points = str.trim().split(',');
|
24708 | var components = [];
|
24709 | for (var i = 0, len = points.length; i < len; ++i) {
|
24710 | point = points[i].replace(regExes.trimParens, '$1');
|
24711 | components.push(parse$1.point.apply(this$1, [point]));
|
24712 | }
|
24713 | return this.geometryFactory.createMultiPoint(components)
|
24714 | },
|
24715 |
|
24716 | |
24717 |
|
24718 |
|
24719 |
|
24720 |
|
24721 |
|
24722 |
|
24723 | linestring: function linestring (str) {
|
24724 | if (str === undefined) {
|
24725 | return this.geometryFactory.createLineString()
|
24726 | }
|
24727 |
|
24728 | var points = str.trim().split(',');
|
24729 | var components = [];
|
24730 | var coords;
|
24731 | for (var i = 0, len = points.length; i < len; ++i) {
|
24732 | coords = points[i].trim().split(regExes.spaces);
|
24733 | components.push(new Coordinate(Number.parseFloat(coords[0]), Number.parseFloat(coords[1])));
|
24734 | }
|
24735 | return this.geometryFactory.createLineString(components)
|
24736 | },
|
24737 |
|
24738 | |
24739 |
|
24740 |
|
24741 |
|
24742 |
|
24743 |
|
24744 |
|
24745 | linearring: function linearring (str) {
|
24746 | if (str === undefined) {
|
24747 | return this.geometryFactory.createLinearRing()
|
24748 | }
|
24749 |
|
24750 | var points = str.trim().split(',');
|
24751 | var components = [];
|
24752 | var coords;
|
24753 | for (var i = 0, len = points.length; i < len; ++i) {
|
24754 | coords = points[i].trim().split(regExes.spaces);
|
24755 | components.push(new Coordinate(Number.parseFloat(coords[0]), Number.parseFloat(coords[1])));
|
24756 | }
|
24757 | return this.geometryFactory.createLinearRing(components)
|
24758 | },
|
24759 |
|
24760 | |
24761 |
|
24762 |
|
24763 |
|
24764 |
|
24765 |
|
24766 |
|
24767 | multilinestring: function multilinestring (str) {
|
24768 | var this$1 = this;
|
24769 |
|
24770 | if (str === undefined) {
|
24771 | return this.geometryFactory.createMultiLineString()
|
24772 | }
|
24773 |
|
24774 | var line;
|
24775 | var lines = str.trim().split(regExes.parenComma);
|
24776 | var components = [];
|
24777 | for (var i = 0, len = lines.length; i < len; ++i) {
|
24778 | line = lines[i].replace(regExes.trimParens, '$1');
|
24779 | components.push(parse$1.linestring.apply(this$1, [line]));
|
24780 | }
|
24781 | return this.geometryFactory.createMultiLineString(components)
|
24782 | },
|
24783 |
|
24784 | |
24785 |
|
24786 |
|
24787 |
|
24788 |
|
24789 |
|
24790 |
|
24791 | polygon: function polygon (str) {
|
24792 | var this$1 = this;
|
24793 |
|
24794 | if (str === undefined) {
|
24795 | return this.geometryFactory.createPolygon()
|
24796 | }
|
24797 |
|
24798 | var ring, linestring, linearring;
|
24799 | var rings = str.trim().split(regExes.parenComma);
|
24800 | var shell;
|
24801 | var holes = [];
|
24802 | for (var i = 0, len = rings.length; i < len; ++i) {
|
24803 | ring = rings[i].replace(regExes.trimParens, '$1');
|
24804 | linestring = parse$1.linestring.apply(this$1, [ring]);
|
24805 | linearring = this$1.geometryFactory.createLinearRing(linestring._points);
|
24806 | if (i === 0) {
|
24807 | shell = linearring;
|
24808 | } else {
|
24809 | holes.push(linearring);
|
24810 | }
|
24811 | }
|
24812 | return this.geometryFactory.createPolygon(shell, holes)
|
24813 | },
|
24814 |
|
24815 | |
24816 |
|
24817 |
|
24818 |
|
24819 |
|
24820 |
|
24821 |
|
24822 | multipolygon: function multipolygon (str) {
|
24823 | var this$1 = this;
|
24824 |
|
24825 | if (str === undefined) {
|
24826 | return this.geometryFactory.createMultiPolygon()
|
24827 | }
|
24828 |
|
24829 | var polygon;
|
24830 | var polygons = str.trim().split(regExes.doubleParenComma);
|
24831 | var components = [];
|
24832 | for (var i = 0, len = polygons.length; i < len; ++i) {
|
24833 | polygon = polygons[i].replace(regExes.trimParens, '$1');
|
24834 | components.push(parse$1.polygon.apply(this$1, [polygon]));
|
24835 | }
|
24836 | return this.geometryFactory.createMultiPolygon(components)
|
24837 | },
|
24838 |
|
24839 | |
24840 |
|
24841 |
|
24842 |
|
24843 |
|
24844 |
|
24845 |
|
24846 | geometrycollection: function geometrycollection (str) {
|
24847 | var this$1 = this;
|
24848 |
|
24849 | if (str === undefined) {
|
24850 | return this.geometryFactory.createGeometryCollection()
|
24851 | }
|
24852 |
|
24853 |
|
24854 | str = str.replace(/,\s*([A-Za-z])/g, '|$1');
|
24855 | var wktArray = str.trim().split('|');
|
24856 | var components = [];
|
24857 | for (var i = 0, len = wktArray.length; i < len; ++i) {
|
24858 | components.push(this$1.read(wktArray[i]));
|
24859 | }
|
24860 | return this.geometryFactory.createGeometryCollection(components)
|
24861 | }
|
24862 | };
|
24863 |
|
24864 |
|
24865 |
|
24866 |
|
24867 |
|
24868 |
|
24869 |
|
24870 |
|
24871 |
|
24872 |
|
24873 |
|
24874 |
|
24875 |
|
24876 |
|
24877 |
|
24878 |
|
24879 |
|
24880 |
|
24881 |
|
24882 | var WKTWriter = function WKTWriter (geometryFactory) {
|
24883 | this.parser = new WKTParser(geometryFactory);
|
24884 | };
|
24885 |
|
24886 |
|
24887 |
|
24888 |
|
24889 |
|
24890 |
|
24891 |
|
24892 |
|
24893 |
|
24894 | WKTWriter.prototype.write = function write (geometry) {
|
24895 | return this.parser.write(geometry)
|
24896 | };
|
24897 |
|
24898 |
|
24899 |
|
24900 |
|
24901 |
|
24902 |
|
24903 |
|
24904 |
|
24905 |
|
24906 |
|
24907 | WKTWriter.toLineString = function toLineString (p0, p1) {
|
24908 | if (arguments.length !== 2) {
|
24909 | throw new Error('Not implemented')
|
24910 | }
|
24911 | return 'LINESTRING ( ' + p0.x + ' ' + p0.y + ', ' + p1.x + ' ' + p1.y + ' )'
|
24912 | };
|
24913 |
|
24914 | var RuntimeException = (function (Error) {
|
24915 | function RuntimeException (message) {
|
24916 | Error.call(this, message);
|
24917 | this.name = 'RuntimeException';
|
24918 | this.message = message;
|
24919 | this.stack = (new Error()).stack;
|
24920 | }
|
24921 |
|
24922 | if ( Error ) RuntimeException.__proto__ = Error;
|
24923 | RuntimeException.prototype = Object.create( Error && Error.prototype );
|
24924 | RuntimeException.prototype.constructor = RuntimeException;
|
24925 |
|
24926 | return RuntimeException;
|
24927 | }(Error));
|
24928 |
|
24929 | var AssertionFailedException = (function (RuntimeException$$1) {
|
24930 | function AssertionFailedException () {
|
24931 | RuntimeException$$1.call(this);
|
24932 | if (arguments.length === 0) {
|
24933 | RuntimeException$$1.call(this);
|
24934 | } else if (arguments.length === 1) {
|
24935 | var message = arguments[0];
|
24936 | RuntimeException$$1.call(this, message);
|
24937 | }
|
24938 | }
|
24939 |
|
24940 | if ( RuntimeException$$1 ) AssertionFailedException.__proto__ = RuntimeException$$1;
|
24941 | AssertionFailedException.prototype = Object.create( RuntimeException$$1 && RuntimeException$$1.prototype );
|
24942 | AssertionFailedException.prototype.constructor = AssertionFailedException;
|
24943 | AssertionFailedException.prototype.interfaces_ = function interfaces_ () {
|
24944 | return []
|
24945 | };
|
24946 | AssertionFailedException.prototype.getClass = function getClass () {
|
24947 | return AssertionFailedException
|
24948 | };
|
24949 |
|
24950 | return AssertionFailedException;
|
24951 | }(RuntimeException));
|
24952 |
|
24953 | var Assert = function Assert () {};
|
24954 |
|
24955 | Assert.prototype.interfaces_ = function interfaces_ () {
|
24956 | return []
|
24957 | };
|
24958 | Assert.prototype.getClass = function getClass () {
|
24959 | return Assert
|
24960 | };
|
24961 | Assert.shouldNeverReachHere = function shouldNeverReachHere () {
|
24962 | if (arguments.length === 0) {
|
24963 | Assert.shouldNeverReachHere(null);
|
24964 | } else if (arguments.length === 1) {
|
24965 | var message = arguments[0];
|
24966 | throw new AssertionFailedException('Should never reach here' + (message !== null ? ': ' + message : ''))
|
24967 | }
|
24968 | };
|
24969 | Assert.isTrue = function isTrue () {
|
24970 | var assertion;
|
24971 | var message;
|
24972 | if (arguments.length === 1) {
|
24973 | assertion = arguments[0];
|
24974 | Assert.isTrue(assertion, null);
|
24975 | } else if (arguments.length === 2) {
|
24976 | assertion = arguments[0];
|
24977 | message = arguments[1];
|
24978 | if (!assertion) {
|
24979 | if (message === null) {
|
24980 | throw new AssertionFailedException()
|
24981 | } else {
|
24982 | throw new AssertionFailedException(message)
|
24983 | }
|
24984 | }
|
24985 | }
|
24986 | };
|
24987 | Assert.equals = function equals () {
|
24988 | var expectedValue;
|
24989 | var actualValue;
|
24990 | var message;
|
24991 | if (arguments.length === 2) {
|
24992 | expectedValue = arguments[0];
|
24993 | actualValue = arguments[1];
|
24994 | Assert.equals(expectedValue, actualValue, null);
|
24995 | } else if (arguments.length === 3) {
|
24996 | expectedValue = arguments[0];
|
24997 | actualValue = arguments[1];
|
24998 | message = arguments[2];
|
24999 | if (!actualValue.equals(expectedValue)) {
|
25000 | throw new AssertionFailedException('Expected ' + expectedValue + ' but encountered ' + actualValue + (message !== null ? ': ' + message : ''))
|
25001 | }
|
25002 | }
|
25003 | };
|
25004 |
|
25005 | var LineIntersector = function LineIntersector () {
|
25006 | this._result = null;
|
25007 | this._inputLines = Array(2).fill().map(function () { return Array(2); });
|
25008 | this._intPt = new Array(2).fill(null);
|
25009 | this._intLineIndex = null;
|
25010 | this._isProper = null;
|
25011 | this._pa = null;
|
25012 | this._pb = null;
|
25013 | this._precisionModel = null;
|
25014 | this._intPt[0] = new Coordinate();
|
25015 | this._intPt[1] = new Coordinate();
|
25016 | this._pa = this._intPt[0];
|
25017 | this._pb = this._intPt[1];
|
25018 | this._result = 0;
|
25019 | };
|
25020 |
|
25021 | var staticAccessors$10 = { DONT_INTERSECT: { configurable: true },DO_INTERSECT: { configurable: true },COLLINEAR: { configurable: true },NO_INTERSECTION: { configurable: true },POINT_INTERSECTION: { configurable: true },COLLINEAR_INTERSECTION: { configurable: true } };
|
25022 | LineIntersector.prototype.getIndexAlongSegment = function getIndexAlongSegment (segmentIndex, intIndex) {
|
25023 | this.computeIntLineIndex();
|
25024 | return this._intLineIndex[segmentIndex][intIndex]
|
25025 | };
|
25026 | LineIntersector.prototype.getTopologySummary = function getTopologySummary () {
|
25027 | var catBuf = new StringBuffer();
|
25028 | if (this.isEndPoint()) { catBuf.append(' endpoint'); }
|
25029 | if (this._isProper) { catBuf.append(' proper'); }
|
25030 | if (this.isCollinear()) { catBuf.append(' collinear'); }
|
25031 | return catBuf.toString()
|
25032 | };
|
25033 | LineIntersector.prototype.computeIntersection = function computeIntersection (p1, p2, p3, p4) {
|
25034 | this._inputLines[0][0] = p1;
|
25035 | this._inputLines[0][1] = p2;
|
25036 | this._inputLines[1][0] = p3;
|
25037 | this._inputLines[1][1] = p4;
|
25038 | this._result = this.computeIntersect(p1, p2, p3, p4);
|
25039 | };
|
25040 | LineIntersector.prototype.getIntersectionNum = function getIntersectionNum () {
|
25041 | return this._result
|
25042 | };
|
25043 | LineIntersector.prototype.computeIntLineIndex = function computeIntLineIndex () {
|
25044 | if (arguments.length === 0) {
|
25045 | if (this._intLineIndex === null) {
|
25046 | this._intLineIndex = Array(2).fill().map(function () { return Array(2); });
|
25047 | this.computeIntLineIndex(0);
|
25048 | this.computeIntLineIndex(1);
|
25049 | }
|
25050 | } else if (arguments.length === 1) {
|
25051 | var segmentIndex = arguments[0];
|
25052 | var dist0 = this.getEdgeDistance(segmentIndex, 0);
|
25053 | var dist1 = this.getEdgeDistance(segmentIndex, 1);
|
25054 | if (dist0 > dist1) {
|
25055 | this._intLineIndex[segmentIndex][0] = 0;
|
25056 | this._intLineIndex[segmentIndex][1] = 1;
|
25057 | } else {
|
25058 | this._intLineIndex[segmentIndex][0] = 1;
|
25059 | this._intLineIndex[segmentIndex][1] = 0;
|
25060 | }
|
25061 | }
|
25062 | };
|
25063 | LineIntersector.prototype.isProper = function isProper () {
|
25064 | return this.hasIntersection() && this._isProper
|
25065 | };
|
25066 | LineIntersector.prototype.setPrecisionModel = function setPrecisionModel (precisionModel) {
|
25067 | this._precisionModel = precisionModel;
|
25068 | };
|
25069 | LineIntersector.prototype.isInteriorIntersection = function isInteriorIntersection () {
|
25070 | var this$1 = this;
|
25071 |
|
25072 | if (arguments.length === 0) {
|
25073 | if (this.isInteriorIntersection(0)) { return true }
|
25074 | if (this.isInteriorIntersection(1)) { return true }
|
25075 | return false
|
25076 | } else if (arguments.length === 1) {
|
25077 | var inputLineIndex = arguments[0];
|
25078 | for (var i = 0; i < this._result; i++) {
|
25079 | if (!(this$1._intPt[i].equals2D(this$1._inputLines[inputLineIndex][0]) || this$1._intPt[i].equals2D(this$1._inputLines[inputLineIndex][1]))) {
|
25080 | return true
|
25081 | }
|
25082 | }
|
25083 | return false
|
25084 | }
|
25085 | };
|
25086 | LineIntersector.prototype.getIntersection = function getIntersection (intIndex) {
|
25087 | return this._intPt[intIndex]
|
25088 | };
|
25089 | LineIntersector.prototype.isEndPoint = function isEndPoint () {
|
25090 | return this.hasIntersection() && !this._isProper
|
25091 | };
|
25092 | LineIntersector.prototype.hasIntersection = function hasIntersection () {
|
25093 | return this._result !== LineIntersector.NO_INTERSECTION
|
25094 | };
|
25095 | LineIntersector.prototype.getEdgeDistance = function getEdgeDistance (segmentIndex, intIndex) {
|
25096 | var dist = LineIntersector.computeEdgeDistance(this._intPt[intIndex], this._inputLines[segmentIndex][0], this._inputLines[segmentIndex][1]);
|
25097 | return dist
|
25098 | };
|
25099 | LineIntersector.prototype.isCollinear = function isCollinear () {
|
25100 | return this._result === LineIntersector.COLLINEAR_INTERSECTION
|
25101 | };
|
25102 | LineIntersector.prototype.toString = function toString () {
|
25103 | return WKTWriter.toLineString(this._inputLines[0][0], this._inputLines[0][1]) + ' - ' + WKTWriter.toLineString(this._inputLines[1][0], this._inputLines[1][1]) + this.getTopologySummary()
|
25104 | };
|
25105 | LineIntersector.prototype.getEndpoint = function getEndpoint (segmentIndex, ptIndex) {
|
25106 | return this._inputLines[segmentIndex][ptIndex]
|
25107 | };
|
25108 | LineIntersector.prototype.isIntersection = function isIntersection (pt) {
|
25109 | var this$1 = this;
|
25110 |
|
25111 | for (var i = 0; i < this._result; i++) {
|
25112 | if (this$1._intPt[i].equals2D(pt)) {
|
25113 | return true
|
25114 | }
|
25115 | }
|
25116 | return false
|
25117 | };
|
25118 | LineIntersector.prototype.getIntersectionAlongSegment = function getIntersectionAlongSegment (segmentIndex, intIndex) {
|
25119 | this.computeIntLineIndex();
|
25120 | return this._intPt[this._intLineIndex[segmentIndex][intIndex]]
|
25121 | };
|
25122 | LineIntersector.prototype.interfaces_ = function interfaces_ () {
|
25123 | return []
|
25124 | };
|
25125 | LineIntersector.prototype.getClass = function getClass () {
|
25126 | return LineIntersector
|
25127 | };
|
25128 | LineIntersector.computeEdgeDistance = function computeEdgeDistance (p, p0, p1) {
|
25129 | var dx = Math.abs(p1.x - p0.x);
|
25130 | var dy = Math.abs(p1.y - p0.y);
|
25131 | var dist = -1.0;
|
25132 | if (p.equals(p0)) {
|
25133 | dist = 0.0;
|
25134 | } else if (p.equals(p1)) {
|
25135 | if (dx > dy) { dist = dx; } else { dist = dy; }
|
25136 | } else {
|
25137 | var pdx = Math.abs(p.x - p0.x);
|
25138 | var pdy = Math.abs(p.y - p0.y);
|
25139 | if (dx > dy) { dist = pdx; } else { dist = pdy; }
|
25140 | if (dist === 0.0 && !p.equals(p0)) {
|
25141 | dist = Math.max(pdx, pdy);
|
25142 | }
|
25143 | }
|
25144 | Assert.isTrue(!(dist === 0.0 && !p.equals(p0)), 'Bad distance calculation');
|
25145 | return dist
|
25146 | };
|
25147 | LineIntersector.nonRobustComputeEdgeDistance = function nonRobustComputeEdgeDistance (p, p1, p2) {
|
25148 | var dx = p.x - p1.x;
|
25149 | var dy = p.y - p1.y;
|
25150 | var dist = Math.sqrt(dx * dx + dy * dy);
|
25151 | Assert.isTrue(!(dist === 0.0 && !p.equals(p1)), 'Invalid distance calculation');
|
25152 | return dist
|
25153 | };
|
25154 | staticAccessors$10.DONT_INTERSECT.get = function () { return 0 };
|
25155 | staticAccessors$10.DO_INTERSECT.get = function () { return 1 };
|
25156 | staticAccessors$10.COLLINEAR.get = function () { return 2 };
|
25157 | staticAccessors$10.NO_INTERSECTION.get = function () { return 0 };
|
25158 | staticAccessors$10.POINT_INTERSECTION.get = function () { return 1 };
|
25159 | staticAccessors$10.COLLINEAR_INTERSECTION.get = function () { return 2 };
|
25160 |
|
25161 | Object.defineProperties( LineIntersector, staticAccessors$10 );
|
25162 |
|
25163 | var RobustLineIntersector = (function (LineIntersector$$1) {
|
25164 | function RobustLineIntersector () {
|
25165 | LineIntersector$$1.apply(this, arguments);
|
25166 | }
|
25167 |
|
25168 | if ( LineIntersector$$1 ) RobustLineIntersector.__proto__ = LineIntersector$$1;
|
25169 | RobustLineIntersector.prototype = Object.create( LineIntersector$$1 && LineIntersector$$1.prototype );
|
25170 | RobustLineIntersector.prototype.constructor = RobustLineIntersector;
|
25171 |
|
25172 | RobustLineIntersector.prototype.isInSegmentEnvelopes = function isInSegmentEnvelopes (intPt) {
|
25173 | var env0 = new Envelope(this._inputLines[0][0], this._inputLines[0][1]);
|
25174 | var env1 = new Envelope(this._inputLines[1][0], this._inputLines[1][1]);
|
25175 | return env0.contains(intPt) && env1.contains(intPt)
|
25176 | };
|
25177 | RobustLineIntersector.prototype.computeIntersection = function computeIntersection () {
|
25178 | if (arguments.length === 3) {
|
25179 | var p = arguments[0];
|
25180 | var p1 = arguments[1];
|
25181 | var p2 = arguments[2];
|
25182 | this._isProper = false;
|
25183 | if (Envelope.intersects(p1, p2, p)) {
|
25184 | if (CGAlgorithms.orientationIndex(p1, p2, p) === 0 && CGAlgorithms.orientationIndex(p2, p1, p) === 0) {
|
25185 | this._isProper = true;
|
25186 | if (p.equals(p1) || p.equals(p2)) {
|
25187 | this._isProper = false;
|
25188 | }
|
25189 | this._result = LineIntersector$$1.POINT_INTERSECTION;
|
25190 | return null
|
25191 | }
|
25192 | }
|
25193 | this._result = LineIntersector$$1.NO_INTERSECTION;
|
25194 | } else { return LineIntersector$$1.prototype.computeIntersection.apply(this, arguments) }
|
25195 | };
|
25196 | RobustLineIntersector.prototype.normalizeToMinimum = function normalizeToMinimum (n1, n2, n3, n4, normPt) {
|
25197 | normPt.x = this.smallestInAbsValue(n1.x, n2.x, n3.x, n4.x);
|
25198 | normPt.y = this.smallestInAbsValue(n1.y, n2.y, n3.y, n4.y);
|
25199 | n1.x -= normPt.x;
|
25200 | n1.y -= normPt.y;
|
25201 | n2.x -= normPt.x;
|
25202 | n2.y -= normPt.y;
|
25203 | n3.x -= normPt.x;
|
25204 | n3.y -= normPt.y;
|
25205 | n4.x -= normPt.x;
|
25206 | n4.y -= normPt.y;
|
25207 | };
|
25208 | RobustLineIntersector.prototype.safeHCoordinateIntersection = function safeHCoordinateIntersection (p1, p2, q1, q2) {
|
25209 | var intPt = null;
|
25210 | try {
|
25211 | intPt = HCoordinate.intersection(p1, p2, q1, q2);
|
25212 | } catch (e) {
|
25213 | if (e instanceof NotRepresentableException) {
|
25214 | intPt = RobustLineIntersector.nearestEndpoint(p1, p2, q1, q2);
|
25215 | } else { throw e }
|
25216 | } finally {}
|
25217 | return intPt
|
25218 | };
|
25219 | RobustLineIntersector.prototype.intersection = function intersection (p1, p2, q1, q2) {
|
25220 | var intPt = this.intersectionWithNormalization(p1, p2, q1, q2);
|
25221 | if (!this.isInSegmentEnvelopes(intPt)) {
|
25222 | intPt = new Coordinate(RobustLineIntersector.nearestEndpoint(p1, p2, q1, q2));
|
25223 | }
|
25224 | if (this._precisionModel !== null) {
|
25225 | this._precisionModel.makePrecise(intPt);
|
25226 | }
|
25227 | return intPt
|
25228 | };
|
25229 | RobustLineIntersector.prototype.smallestInAbsValue = function smallestInAbsValue (x1, x2, x3, x4) {
|
25230 | var x = x1;
|
25231 | var xabs = Math.abs(x);
|
25232 | if (Math.abs(x2) < xabs) {
|
25233 | x = x2;
|
25234 | xabs = Math.abs(x2);
|
25235 | }
|
25236 | if (Math.abs(x3) < xabs) {
|
25237 | x = x3;
|
25238 | xabs = Math.abs(x3);
|
25239 | }
|
25240 | if (Math.abs(x4) < xabs) {
|
25241 | x = x4;
|
25242 | }
|
25243 | return x
|
25244 | };
|
25245 | RobustLineIntersector.prototype.checkDD = function checkDD (p1, p2, q1, q2, intPt) {
|
25246 | var intPtDD = CGAlgorithmsDD.intersection(p1, p2, q1, q2);
|
25247 | var isIn = this.isInSegmentEnvelopes(intPtDD);
|
25248 | System.out.println('DD in env = ' + isIn + ' --------------------- ' + intPtDD);
|
25249 | if (intPt.distance(intPtDD) > 0.0001) {
|
25250 | System.out.println('Distance = ' + intPt.distance(intPtDD));
|
25251 | }
|
25252 | };
|
25253 | RobustLineIntersector.prototype.intersectionWithNormalization = function intersectionWithNormalization (p1, p2, q1, q2) {
|
25254 | var n1 = new Coordinate(p1);
|
25255 | var n2 = new Coordinate(p2);
|
25256 | var n3 = new Coordinate(q1);
|
25257 | var n4 = new Coordinate(q2);
|
25258 | var normPt = new Coordinate();
|
25259 | this.normalizeToEnvCentre(n1, n2, n3, n4, normPt);
|
25260 | var intPt = this.safeHCoordinateIntersection(n1, n2, n3, n4);
|
25261 | intPt.x += normPt.x;
|
25262 | intPt.y += normPt.y;
|
25263 | return intPt
|
25264 | };
|
25265 | RobustLineIntersector.prototype.computeCollinearIntersection = function computeCollinearIntersection (p1, p2, q1, q2) {
|
25266 | var p1q1p2 = Envelope.intersects(p1, p2, q1);
|
25267 | var p1q2p2 = Envelope.intersects(p1, p2, q2);
|
25268 | var q1p1q2 = Envelope.intersects(q1, q2, p1);
|
25269 | var q1p2q2 = Envelope.intersects(q1, q2, p2);
|
25270 | if (p1q1p2 && p1q2p2) {
|
25271 | this._intPt[0] = q1;
|
25272 | this._intPt[1] = q2;
|
25273 | return LineIntersector$$1.COLLINEAR_INTERSECTION
|
25274 | }
|
25275 | if (q1p1q2 && q1p2q2) {
|
25276 | this._intPt[0] = p1;
|
25277 | this._intPt[1] = p2;
|
25278 | return LineIntersector$$1.COLLINEAR_INTERSECTION
|
25279 | }
|
25280 | if (p1q1p2 && q1p1q2) {
|
25281 | this._intPt[0] = q1;
|
25282 | this._intPt[1] = p1;
|
25283 | return q1.equals(p1) && !p1q2p2 && !q1p2q2 ? LineIntersector$$1.POINT_INTERSECTION : LineIntersector$$1.COLLINEAR_INTERSECTION
|
25284 | }
|
25285 | if (p1q1p2 && q1p2q2) {
|
25286 | this._intPt[0] = q1;
|
25287 | this._intPt[1] = p2;
|
25288 | return q1.equals(p2) && !p1q2p2 && !q1p1q2 ? LineIntersector$$1.POINT_INTERSECTION : LineIntersector$$1.COLLINEAR_INTERSECTION
|
25289 | }
|
25290 | if (p1q2p2 && q1p1q2) {
|
25291 | this._intPt[0] = q2;
|
25292 | this._intPt[1] = p1;
|
25293 | return q2.equals(p1) && !p1q1p2 && !q1p2q2 ? LineIntersector$$1.POINT_INTERSECTION : LineIntersector$$1.COLLINEAR_INTERSECTION
|
25294 | }
|
25295 | if (p1q2p2 && q1p2q2) {
|
25296 | this._intPt[0] = q2;
|
25297 | this._intPt[1] = p2;
|
25298 | return q2.equals(p2) && !p1q1p2 && !q1p1q2 ? LineIntersector$$1.POINT_INTERSECTION : LineIntersector$$1.COLLINEAR_INTERSECTION
|
25299 | }
|
25300 | return LineIntersector$$1.NO_INTERSECTION
|
25301 | };
|
25302 | RobustLineIntersector.prototype.normalizeToEnvCentre = function normalizeToEnvCentre (n00, n01, n10, n11, normPt) {
|
25303 | var minX0 = n00.x < n01.x ? n00.x : n01.x;
|
25304 | var minY0 = n00.y < n01.y ? n00.y : n01.y;
|
25305 | var maxX0 = n00.x > n01.x ? n00.x : n01.x;
|
25306 | var maxY0 = n00.y > n01.y ? n00.y : n01.y;
|
25307 | var minX1 = n10.x < n11.x ? n10.x : n11.x;
|
25308 | var minY1 = n10.y < n11.y ? n10.y : n11.y;
|
25309 | var maxX1 = n10.x > n11.x ? n10.x : n11.x;
|
25310 | var maxY1 = n10.y > n11.y ? n10.y : n11.y;
|
25311 | var intMinX = minX0 > minX1 ? minX0 : minX1;
|
25312 | var intMaxX = maxX0 < maxX1 ? maxX0 : maxX1;
|
25313 | var intMinY = minY0 > minY1 ? minY0 : minY1;
|
25314 | var intMaxY = maxY0 < maxY1 ? maxY0 : maxY1;
|
25315 | var intMidX = (intMinX + intMaxX) / 2.0;
|
25316 | var intMidY = (intMinY + intMaxY) / 2.0;
|
25317 | normPt.x = intMidX;
|
25318 | normPt.y = intMidY;
|
25319 | n00.x -= normPt.x;
|
25320 | n00.y -= normPt.y;
|
25321 | n01.x -= normPt.x;
|
25322 | n01.y -= normPt.y;
|
25323 | n10.x -= normPt.x;
|
25324 | n10.y -= normPt.y;
|
25325 | n11.x -= normPt.x;
|
25326 | n11.y -= normPt.y;
|
25327 | };
|
25328 | RobustLineIntersector.prototype.computeIntersect = function computeIntersect (p1, p2, q1, q2) {
|
25329 | this._isProper = false;
|
25330 | if (!Envelope.intersects(p1, p2, q1, q2)) { return LineIntersector$$1.NO_INTERSECTION }
|
25331 | var Pq1 = CGAlgorithms.orientationIndex(p1, p2, q1);
|
25332 | var Pq2 = CGAlgorithms.orientationIndex(p1, p2, q2);
|
25333 | if ((Pq1 > 0 && Pq2 > 0) || (Pq1 < 0 && Pq2 < 0)) {
|
25334 | return LineIntersector$$1.NO_INTERSECTION
|
25335 | }
|
25336 | var Qp1 = CGAlgorithms.orientationIndex(q1, q2, p1);
|
25337 | var Qp2 = CGAlgorithms.orientationIndex(q1, q2, p2);
|
25338 | if ((Qp1 > 0 && Qp2 > 0) || (Qp1 < 0 && Qp2 < 0)) {
|
25339 | return LineIntersector$$1.NO_INTERSECTION
|
25340 | }
|
25341 | var collinear = Pq1 === 0 && Pq2 === 0 && Qp1 === 0 && Qp2 === 0;
|
25342 | if (collinear) {
|
25343 | return this.computeCollinearIntersection(p1, p2, q1, q2)
|
25344 | }
|
25345 | if (Pq1 === 0 || Pq2 === 0 || Qp1 === 0 || Qp2 === 0) {
|
25346 | this._isProper = false;
|
25347 | if (p1.equals2D(q1) || p1.equals2D(q2)) {
|
25348 | this._intPt[0] = p1;
|
25349 | } else if (p2.equals2D(q1) || p2.equals2D(q2)) {
|
25350 | this._intPt[0] = p2;
|
25351 | } else if (Pq1 === 0) {
|
25352 | this._intPt[0] = new Coordinate(q1);
|
25353 | } else if (Pq2 === 0) {
|
25354 | this._intPt[0] = new Coordinate(q2);
|
25355 | } else if (Qp1 === 0) {
|
25356 | this._intPt[0] = new Coordinate(p1);
|
25357 | } else if (Qp2 === 0) {
|
25358 | this._intPt[0] = new Coordinate(p2);
|
25359 | }
|
25360 | } else {
|
25361 | this._isProper = true;
|
25362 | this._intPt[0] = this.intersection(p1, p2, q1, q2);
|
25363 | }
|
25364 | return LineIntersector$$1.POINT_INTERSECTION
|
25365 | };
|
25366 | RobustLineIntersector.prototype.interfaces_ = function interfaces_ () {
|
25367 | return []
|
25368 | };
|
25369 | RobustLineIntersector.prototype.getClass = function getClass () {
|
25370 | return RobustLineIntersector
|
25371 | };
|
25372 | RobustLineIntersector.nearestEndpoint = function nearestEndpoint (p1, p2, q1, q2) {
|
25373 | var nearestPt = p1;
|
25374 | var minDist = CGAlgorithms.distancePointLine(p1, q1, q2);
|
25375 | var dist = CGAlgorithms.distancePointLine(p2, q1, q2);
|
25376 | if (dist < minDist) {
|
25377 | minDist = dist;
|
25378 | nearestPt = p2;
|
25379 | }
|
25380 | dist = CGAlgorithms.distancePointLine(q1, p1, p2);
|
25381 | if (dist < minDist) {
|
25382 | minDist = dist;
|
25383 | nearestPt = q1;
|
25384 | }
|
25385 | dist = CGAlgorithms.distancePointLine(q2, p1, p2);
|
25386 | if (dist < minDist) {
|
25387 | minDist = dist;
|
25388 | nearestPt = q2;
|
25389 | }
|
25390 | return nearestPt
|
25391 | };
|
25392 |
|
25393 | return RobustLineIntersector;
|
25394 | }(LineIntersector));
|
25395 |
|
25396 | var RobustDeterminant = function RobustDeterminant () {};
|
25397 |
|
25398 | RobustDeterminant.prototype.interfaces_ = function interfaces_ () {
|
25399 | return []
|
25400 | };
|
25401 | RobustDeterminant.prototype.getClass = function getClass () {
|
25402 | return RobustDeterminant
|
25403 | };
|
25404 | RobustDeterminant.orientationIndex = function orientationIndex (p1, p2, q) {
|
25405 | var dx1 = p2.x - p1.x;
|
25406 | var dy1 = p2.y - p1.y;
|
25407 | var dx2 = q.x - p2.x;
|
25408 | var dy2 = q.y - p2.y;
|
25409 | return RobustDeterminant.signOfDet2x2(dx1, dy1, dx2, dy2)
|
25410 | };
|
25411 | RobustDeterminant.signOfDet2x2 = function signOfDet2x2 (x1, y1, x2, y2) {
|
25412 | var sign = null;
|
25413 | var swap = null;
|
25414 | var k = null;
|
25415 | sign = 1;
|
25416 | if (x1 === 0.0 || y2 === 0.0) {
|
25417 | if (y1 === 0.0 || x2 === 0.0) {
|
25418 | return 0
|
25419 | } else if (y1 > 0) {
|
25420 | if (x2 > 0) {
|
25421 | return -sign
|
25422 | } else {
|
25423 | return sign
|
25424 | }
|
25425 | } else {
|
25426 | if (x2 > 0) {
|
25427 | return sign
|
25428 | } else {
|
25429 | return -sign
|
25430 | }
|
25431 | }
|
25432 | }
|
25433 | if (y1 === 0.0 || x2 === 0.0) {
|
25434 | if (y2 > 0) {
|
25435 | if (x1 > 0) {
|
25436 | return sign
|
25437 | } else {
|
25438 | return -sign
|
25439 | }
|
25440 | } else {
|
25441 | if (x1 > 0) {
|
25442 | return -sign
|
25443 | } else {
|
25444 | return sign
|
25445 | }
|
25446 | }
|
25447 | }
|
25448 | if (y1 > 0.0) {
|
25449 | if (y2 > 0.0) {
|
25450 | if (y1 <= y2) {
|
25451 |
|
25452 | } else {
|
25453 | sign = -sign;
|
25454 | swap = x1;
|
25455 | x1 = x2;
|
25456 | x2 = swap;
|
25457 | swap = y1;
|
25458 | y1 = y2;
|
25459 | y2 = swap;
|
25460 | }
|
25461 | } else {
|
25462 | if (y1 <= -y2) {
|
25463 | sign = -sign;
|
25464 | x2 = -x2;
|
25465 | y2 = -y2;
|
25466 | } else {
|
25467 | swap = x1;
|
25468 | x1 = -x2;
|
25469 | x2 = swap;
|
25470 | swap = y1;
|
25471 | y1 = -y2;
|
25472 | y2 = swap;
|
25473 | }
|
25474 | }
|
25475 | } else {
|
25476 | if (y2 > 0.0) {
|
25477 | if (-y1 <= y2) {
|
25478 | sign = -sign;
|
25479 | x1 = -x1;
|
25480 | y1 = -y1;
|
25481 | } else {
|
25482 | swap = -x1;
|
25483 | x1 = x2;
|
25484 | x2 = swap;
|
25485 | swap = -y1;
|
25486 | y1 = y2;
|
25487 | y2 = swap;
|
25488 | }
|
25489 | } else {
|
25490 | if (y1 >= y2) {
|
25491 | x1 = -x1;
|
25492 | y1 = -y1;
|
25493 | x2 = -x2;
|
25494 | y2 = -y2;
|
25495 | } else {
|
25496 | sign = -sign;
|
25497 | swap = -x1;
|
25498 | x1 = -x2;
|
25499 | x2 = swap;
|
25500 | swap = -y1;
|
25501 | y1 = -y2;
|
25502 | y2 = swap;
|
25503 | }
|
25504 | }
|
25505 | }
|
25506 | if (x1 > 0.0) {
|
25507 | if (x2 > 0.0) {
|
25508 | if (x1 <= x2) {
|
25509 |
|
25510 | } else {
|
25511 | return sign
|
25512 | }
|
25513 | } else {
|
25514 | return sign
|
25515 | }
|
25516 | } else {
|
25517 | if (x2 > 0.0) {
|
25518 | return -sign
|
25519 | } else {
|
25520 | if (x1 >= x2) {
|
25521 | sign = -sign;
|
25522 | x1 = -x1;
|
25523 | x2 = -x2;
|
25524 | } else {
|
25525 | return -sign
|
25526 | }
|
25527 | }
|
25528 | }
|
25529 | while (true) {
|
25530 | k = Math.floor(x2 / x1);
|
25531 | x2 = x2 - k * x1;
|
25532 | y2 = y2 - k * y1;
|
25533 | if (y2 < 0.0) {
|
25534 | return -sign
|
25535 | }
|
25536 | if (y2 > y1) {
|
25537 | return sign
|
25538 | }
|
25539 | if (x1 > x2 + x2) {
|
25540 | if (y1 < y2 + y2) {
|
25541 | return sign
|
25542 | }
|
25543 | } else {
|
25544 | if (y1 > y2 + y2) {
|
25545 | return -sign
|
25546 | } else {
|
25547 | x2 = x1 - x2;
|
25548 | y2 = y1 - y2;
|
25549 | sign = -sign;
|
25550 | }
|
25551 | }
|
25552 | if (y2 === 0.0) {
|
25553 | if (x2 === 0.0) {
|
25554 | return 0
|
25555 | } else {
|
25556 | return -sign
|
25557 | }
|
25558 | }
|
25559 | if (x2 === 0.0) {
|
25560 | return sign
|
25561 | }
|
25562 | k = Math.floor(x1 / x2);
|
25563 | x1 = x1 - k * x2;
|
25564 | y1 = y1 - k * y2;
|
25565 | if (y1 < 0.0) {
|
25566 | return sign
|
25567 | }
|
25568 | if (y1 > y2) {
|
25569 | return -sign
|
25570 | }
|
25571 | if (x2 > x1 + x1) {
|
25572 | if (y2 < y1 + y1) {
|
25573 | return -sign
|
25574 | }
|
25575 | } else {
|
25576 | if (y2 > y1 + y1) {
|
25577 | return sign
|
25578 | } else {
|
25579 | x1 = x2 - x1;
|
25580 | y1 = y2 - y1;
|
25581 | sign = -sign;
|
25582 | }
|
25583 | }
|
25584 | if (y1 === 0.0) {
|
25585 | if (x1 === 0.0) {
|
25586 | return 0
|
25587 | } else {
|
25588 | return sign
|
25589 | }
|
25590 | }
|
25591 | if (x1 === 0.0) {
|
25592 | return -sign
|
25593 | }
|
25594 | }
|
25595 | };
|
25596 |
|
25597 | var RayCrossingCounter = function RayCrossingCounter () {
|
25598 | this._p = null;
|
25599 | this._crossingCount = 0;
|
25600 | this._isPointOnSegment = false;
|
25601 | var p = arguments[0];
|
25602 | this._p = p;
|
25603 | };
|
25604 | RayCrossingCounter.prototype.countSegment = function countSegment (p1, p2) {
|
25605 | if (p1.x < this._p.x && p2.x < this._p.x) { return null }
|
25606 | if (this._p.x === p2.x && this._p.y === p2.y) {
|
25607 | this._isPointOnSegment = true;
|
25608 | return null
|
25609 | }
|
25610 | if (p1.y === this._p.y && p2.y === this._p.y) {
|
25611 | var minx = p1.x;
|
25612 | var maxx = p2.x;
|
25613 | if (minx > maxx) {
|
25614 | minx = p2.x;
|
25615 | maxx = p1.x;
|
25616 | }
|
25617 | if (this._p.x >= minx && this._p.x <= maxx) {
|
25618 | this._isPointOnSegment = true;
|
25619 | }
|
25620 | return null
|
25621 | }
|
25622 | if ((p1.y > this._p.y && p2.y <= this._p.y) || (p2.y > this._p.y && p1.y <= this._p.y)) {
|
25623 | var x1 = p1.x - this._p.x;
|
25624 | var y1 = p1.y - this._p.y;
|
25625 | var x2 = p2.x - this._p.x;
|
25626 | var y2 = p2.y - this._p.y;
|
25627 | var xIntSign = RobustDeterminant.signOfDet2x2(x1, y1, x2, y2);
|
25628 | if (xIntSign === 0.0) {
|
25629 | this._isPointOnSegment = true;
|
25630 | return null
|
25631 | }
|
25632 | if (y2 < y1) { xIntSign = -xIntSign; }
|
25633 | if (xIntSign > 0.0) {
|
25634 | this._crossingCount++;
|
25635 | }
|
25636 | }
|
25637 | };
|
25638 | RayCrossingCounter.prototype.isPointInPolygon = function isPointInPolygon () {
|
25639 | return this.getLocation() !== Location.EXTERIOR
|
25640 | };
|
25641 | RayCrossingCounter.prototype.getLocation = function getLocation () {
|
25642 | if (this._isPointOnSegment) { return Location.BOUNDARY }
|
25643 | if (this._crossingCount % 2 === 1) {
|
25644 | return Location.INTERIOR
|
25645 | }
|
25646 | return Location.EXTERIOR
|
25647 | };
|
25648 | RayCrossingCounter.prototype.isOnSegment = function isOnSegment () {
|
25649 | return this._isPointOnSegment
|
25650 | };
|
25651 | RayCrossingCounter.prototype.interfaces_ = function interfaces_ () {
|
25652 | return []
|
25653 | };
|
25654 | RayCrossingCounter.prototype.getClass = function getClass () {
|
25655 | return RayCrossingCounter
|
25656 | };
|
25657 | RayCrossingCounter.locatePointInRing = function locatePointInRing () {
|
25658 | if (arguments[0] instanceof Coordinate && hasInterface(arguments[1], CoordinateSequence)) {
|
25659 | var p = arguments[0];
|
25660 | var ring = arguments[1];
|
25661 | var counter = new RayCrossingCounter(p);
|
25662 | var p1 = new Coordinate();
|
25663 | var p2 = new Coordinate();
|
25664 | for (var i = 1; i < ring.size(); i++) {
|
25665 | ring.getCoordinate(i, p1);
|
25666 | ring.getCoordinate(i - 1, p2);
|
25667 | counter.countSegment(p1, p2);
|
25668 | if (counter.isOnSegment()) { return counter.getLocation() }
|
25669 | }
|
25670 | return counter.getLocation()
|
25671 | } else if (arguments[0] instanceof Coordinate && arguments[1] instanceof Array) {
|
25672 | var p$1 = arguments[0];
|
25673 | var ring$1 = arguments[1];
|
25674 | var counter$1 = new RayCrossingCounter(p$1);
|
25675 | for (var i$1 = 1; i$1 < ring$1.length; i$1++) {
|
25676 | var p1$1 = ring$1[i$1];
|
25677 | var p2$1 = ring$1[i$1 - 1];
|
25678 | counter$1.countSegment(p1$1, p2$1);
|
25679 | if (counter$1.isOnSegment()) { return counter$1.getLocation() }
|
25680 | }
|
25681 | return counter$1.getLocation()
|
25682 | }
|
25683 | };
|
25684 |
|
25685 | var CGAlgorithms = function CGAlgorithms () {};
|
25686 |
|
25687 | var staticAccessors$3 = { CLOCKWISE: { configurable: true },RIGHT: { configurable: true },COUNTERCLOCKWISE: { configurable: true },LEFT: { configurable: true },COLLINEAR: { configurable: true },STRAIGHT: { configurable: true } };
|
25688 |
|
25689 | CGAlgorithms.prototype.interfaces_ = function interfaces_ () {
|
25690 | return []
|
25691 | };
|
25692 | CGAlgorithms.prototype.getClass = function getClass () {
|
25693 | return CGAlgorithms
|
25694 | };
|
25695 | CGAlgorithms.orientationIndex = function orientationIndex (p1, p2, q) {
|
25696 | return CGAlgorithmsDD.orientationIndex(p1, p2, q)
|
25697 | };
|
25698 | CGAlgorithms.signedArea = function signedArea () {
|
25699 | if (arguments[0] instanceof Array) {
|
25700 | var ring = arguments[0];
|
25701 | if (ring.length < 3) { return 0.0 }
|
25702 | var sum = 0.0;
|
25703 | var x0 = ring[0].x;
|
25704 | for (var i = 1; i < ring.length - 1; i++) {
|
25705 | var x = ring[i].x - x0;
|
25706 | var y1 = ring[i + 1].y;
|
25707 | var y2 = ring[i - 1].y;
|
25708 | sum += x * (y2 - y1);
|
25709 | }
|
25710 | return sum / 2.0
|
25711 | } else if (hasInterface(arguments[0], CoordinateSequence)) {
|
25712 | var ring$1 = arguments[0];
|
25713 | var n = ring$1.size();
|
25714 | if (n < 3) { return 0.0 }
|
25715 | var p0 = new Coordinate();
|
25716 | var p1 = new Coordinate();
|
25717 | var p2 = new Coordinate();
|
25718 | ring$1.getCoordinate(0, p1);
|
25719 | ring$1.getCoordinate(1, p2);
|
25720 | var x0$1 = p1.x;
|
25721 | p2.x -= x0$1;
|
25722 | var sum$1 = 0.0;
|
25723 | for (var i$1 = 1; i$1 < n - 1; i$1++) {
|
25724 | p0.y = p1.y;
|
25725 | p1.x = p2.x;
|
25726 | p1.y = p2.y;
|
25727 | ring$1.getCoordinate(i$1 + 1, p2);
|
25728 | p2.x -= x0$1;
|
25729 | sum$1 += p1.x * (p0.y - p2.y);
|
25730 | }
|
25731 | return sum$1 / 2.0
|
25732 | }
|
25733 | };
|
25734 | CGAlgorithms.distanceLineLine = function distanceLineLine (A, B, C, D) {
|
25735 | if (A.equals(B)) { return CGAlgorithms.distancePointLine(A, C, D) }
|
25736 | if (C.equals(D)) { return CGAlgorithms.distancePointLine(D, A, B) }
|
25737 | var noIntersection = false;
|
25738 | if (!Envelope.intersects(A, B, C, D)) {
|
25739 | noIntersection = true;
|
25740 | } else {
|
25741 | var denom = (B.x - A.x) * (D.y - C.y) - (B.y - A.y) * (D.x - C.x);
|
25742 | if (denom === 0) {
|
25743 | noIntersection = true;
|
25744 | } else {
|
25745 | var rNumb = (A.y - C.y) * (D.x - C.x) - (A.x - C.x) * (D.y - C.y);
|
25746 | var sNum = (A.y - C.y) * (B.x - A.x) - (A.x - C.x) * (B.y - A.y);
|
25747 | var s = sNum / denom;
|
25748 | var r = rNumb / denom;
|
25749 | if (r < 0 || r > 1 || s < 0 || s > 1) {
|
25750 | noIntersection = true;
|
25751 | }
|
25752 | }
|
25753 | }
|
25754 | if (noIntersection) {
|
25755 | return MathUtil.min(CGAlgorithms.distancePointLine(A, C, D), CGAlgorithms.distancePointLine(B, C, D), CGAlgorithms.distancePointLine(C, A, B), CGAlgorithms.distancePointLine(D, A, B))
|
25756 | }
|
25757 | return 0.0
|
25758 | };
|
25759 | CGAlgorithms.isPointInRing = function isPointInRing (p, ring) {
|
25760 | return CGAlgorithms.locatePointInRing(p, ring) !== Location.EXTERIOR
|
25761 | };
|
25762 | CGAlgorithms.computeLength = function computeLength (pts) {
|
25763 | var n = pts.size();
|
25764 | if (n <= 1) { return 0.0 }
|
25765 | var len = 0.0;
|
25766 | var p = new Coordinate();
|
25767 | pts.getCoordinate(0, p);
|
25768 | var x0 = p.x;
|
25769 | var y0 = p.y;
|
25770 | for (var i = 1; i < n; i++) {
|
25771 | pts.getCoordinate(i, p);
|
25772 | var x1 = p.x;
|
25773 | var y1 = p.y;
|
25774 | var dx = x1 - x0;
|
25775 | var dy = y1 - y0;
|
25776 | len += Math.sqrt(dx * dx + dy * dy);
|
25777 | x0 = x1;
|
25778 | y0 = y1;
|
25779 | }
|
25780 | return len
|
25781 | };
|
25782 | CGAlgorithms.isCCW = function isCCW (ring) {
|
25783 | var nPts = ring.length - 1;
|
25784 | if (nPts < 3) { throw new IllegalArgumentException('Ring has fewer than 4 points, so orientation cannot be determined') }
|
25785 | var hiPt = ring[0];
|
25786 | var hiIndex = 0;
|
25787 | for (var i = 1; i <= nPts; i++) {
|
25788 | var p = ring[i];
|
25789 | if (p.y > hiPt.y) {
|
25790 | hiPt = p;
|
25791 | hiIndex = i;
|
25792 | }
|
25793 | }
|
25794 | var iPrev = hiIndex;
|
25795 | do {
|
25796 | iPrev = iPrev - 1;
|
25797 | if (iPrev < 0) { iPrev = nPts; }
|
25798 | } while (ring[iPrev].equals2D(hiPt) && iPrev !== hiIndex)
|
25799 | var iNext = hiIndex;
|
25800 | do {
|
25801 | iNext = (iNext + 1) % nPts;
|
25802 | } while (ring[iNext].equals2D(hiPt) && iNext !== hiIndex)
|
25803 | var prev = ring[iPrev];
|
25804 | var next = ring[iNext];
|
25805 | if (prev.equals2D(hiPt) || next.equals2D(hiPt) || prev.equals2D(next)) { return false }
|
25806 | var disc = CGAlgorithms.computeOrientation(prev, hiPt, next);
|
25807 | var isCCW = false;
|
25808 | if (disc === 0) {
|
25809 | isCCW = prev.x > next.x;
|
25810 | } else {
|
25811 | isCCW = disc > 0;
|
25812 | }
|
25813 | return isCCW
|
25814 | };
|
25815 | CGAlgorithms.locatePointInRing = function locatePointInRing (p, ring) {
|
25816 | return RayCrossingCounter.locatePointInRing(p, ring)
|
25817 | };
|
25818 | CGAlgorithms.distancePointLinePerpendicular = function distancePointLinePerpendicular (p, A, B) {
|
25819 | var len2 = (B.x - A.x) * (B.x - A.x) + (B.y - A.y) * (B.y - A.y);
|
25820 | var s = ((A.y - p.y) * (B.x - A.x) - (A.x - p.x) * (B.y - A.y)) / len2;
|
25821 | return Math.abs(s) * Math.sqrt(len2)
|
25822 | };
|
25823 | CGAlgorithms.computeOrientation = function computeOrientation (p1, p2, q) {
|
25824 | return CGAlgorithms.orientationIndex(p1, p2, q)
|
25825 | };
|
25826 | CGAlgorithms.distancePointLine = function distancePointLine () {
|
25827 | if (arguments.length === 2) {
|
25828 | var p = arguments[0];
|
25829 | var line = arguments[1];
|
25830 | if (line.length === 0) { throw new IllegalArgumentException('Line array must contain at least one vertex') }
|
25831 | var minDistance = p.distance(line[0]);
|
25832 | for (var i = 0; i < line.length - 1; i++) {
|
25833 | var dist = CGAlgorithms.distancePointLine(p, line[i], line[i + 1]);
|
25834 | if (dist < minDistance) {
|
25835 | minDistance = dist;
|
25836 | }
|
25837 | }
|
25838 | return minDistance
|
25839 | } else if (arguments.length === 3) {
|
25840 | var p$1 = arguments[0];
|
25841 | var A = arguments[1];
|
25842 | var B = arguments[2];
|
25843 | if (A.x === B.x && A.y === B.y) { return p$1.distance(A) }
|
25844 | var len2 = (B.x - A.x) * (B.x - A.x) + (B.y - A.y) * (B.y - A.y);
|
25845 | var r = ((p$1.x - A.x) * (B.x - A.x) + (p$1.y - A.y) * (B.y - A.y)) / len2;
|
25846 | if (r <= 0.0) { return p$1.distance(A) }
|
25847 | if (r >= 1.0) { return p$1.distance(B) }
|
25848 | var s = ((A.y - p$1.y) * (B.x - A.x) - (A.x - p$1.x) * (B.y - A.y)) / len2;
|
25849 | return Math.abs(s) * Math.sqrt(len2)
|
25850 | }
|
25851 | };
|
25852 | CGAlgorithms.isOnLine = function isOnLine (p, pt) {
|
25853 | var lineIntersector = new RobustLineIntersector();
|
25854 | for (var i = 1; i < pt.length; i++) {
|
25855 | var p0 = pt[i - 1];
|
25856 | var p1 = pt[i];
|
25857 | lineIntersector.computeIntersection(p, p0, p1);
|
25858 | if (lineIntersector.hasIntersection()) {
|
25859 | return true
|
25860 | }
|
25861 | }
|
25862 | return false
|
25863 | };
|
25864 | staticAccessors$3.CLOCKWISE.get = function () { return -1 };
|
25865 | staticAccessors$3.RIGHT.get = function () { return CGAlgorithms.CLOCKWISE };
|
25866 | staticAccessors$3.COUNTERCLOCKWISE.get = function () { return 1 };
|
25867 | staticAccessors$3.LEFT.get = function () { return CGAlgorithms.COUNTERCLOCKWISE };
|
25868 | staticAccessors$3.COLLINEAR.get = function () { return 0 };
|
25869 | staticAccessors$3.STRAIGHT.get = function () { return CGAlgorithms.COLLINEAR };
|
25870 |
|
25871 | Object.defineProperties( CGAlgorithms, staticAccessors$3 );
|
25872 |
|
25873 | var GeometryComponentFilter = function GeometryComponentFilter () {};
|
25874 |
|
25875 | GeometryComponentFilter.prototype.filter = function filter (geom) {};
|
25876 | GeometryComponentFilter.prototype.interfaces_ = function interfaces_ () {
|
25877 | return []
|
25878 | };
|
25879 | GeometryComponentFilter.prototype.getClass = function getClass () {
|
25880 | return GeometryComponentFilter
|
25881 | };
|
25882 |
|
25883 | var Geometry = function Geometry () {
|
25884 | var factory = arguments[0];
|
25885 |
|
25886 | this._envelope = null;
|
25887 | this._factory = null;
|
25888 | this._SRID = null;
|
25889 | this._userData = null;
|
25890 | this._factory = factory;
|
25891 | this._SRID = factory.getSRID();
|
25892 | };
|
25893 |
|
25894 | var staticAccessors$11 = { serialVersionUID: { configurable: true },SORTINDEX_POINT: { configurable: true },SORTINDEX_MULTIPOINT: { configurable: true },SORTINDEX_LINESTRING: { configurable: true },SORTINDEX_LINEARRING: { configurable: true },SORTINDEX_MULTILINESTRING: { configurable: true },SORTINDEX_POLYGON: { configurable: true },SORTINDEX_MULTIPOLYGON: { configurable: true },SORTINDEX_GEOMETRYCOLLECTION: { configurable: true },geometryChangedFilter: { configurable: true } };
|
25895 | Geometry.prototype.isGeometryCollection = function isGeometryCollection () {
|
25896 | return this.getSortIndex() === Geometry.SORTINDEX_GEOMETRYCOLLECTION
|
25897 | };
|
25898 | Geometry.prototype.getFactory = function getFactory () {
|
25899 | return this._factory
|
25900 | };
|
25901 | Geometry.prototype.getGeometryN = function getGeometryN (n) {
|
25902 | return this
|
25903 | };
|
25904 | Geometry.prototype.getArea = function getArea () {
|
25905 | return 0.0
|
25906 | };
|
25907 | Geometry.prototype.isRectangle = function isRectangle () {
|
25908 | return false
|
25909 | };
|
25910 | Geometry.prototype.equals = function equals () {
|
25911 | if (arguments[0] instanceof Geometry) {
|
25912 | var g$1 = arguments[0];
|
25913 | if (g$1 === null) { return false }
|
25914 | return this.equalsTopo(g$1)
|
25915 | } else if (arguments[0] instanceof Object) {
|
25916 | var o = arguments[0];
|
25917 | if (!(o instanceof Geometry)) { return false }
|
25918 | var g = o;
|
25919 | return this.equalsExact(g)
|
25920 | }
|
25921 | };
|
25922 | Geometry.prototype.equalsExact = function equalsExact (other) {
|
25923 | return this === other || this.equalsExact(other, 0)
|
25924 | };
|
25925 | Geometry.prototype.geometryChanged = function geometryChanged () {
|
25926 | this.apply(Geometry.geometryChangedFilter);
|
25927 | };
|
25928 | Geometry.prototype.geometryChangedAction = function geometryChangedAction () {
|
25929 | this._envelope = null;
|
25930 | };
|
25931 | Geometry.prototype.equalsNorm = function equalsNorm (g) {
|
25932 | if (g === null) { return false }
|
25933 | return this.norm().equalsExact(g.norm())
|
25934 | };
|
25935 | Geometry.prototype.getLength = function getLength () {
|
25936 | return 0.0
|
25937 | };
|
25938 | Geometry.prototype.getNumGeometries = function getNumGeometries () {
|
25939 | return 1
|
25940 | };
|
25941 | Geometry.prototype.compareTo = function compareTo () {
|
25942 | if (arguments.length === 1) {
|
25943 | var o = arguments[0];
|
25944 | var other = o;
|
25945 | if (this.getSortIndex() !== other.getSortIndex()) {
|
25946 | return this.getSortIndex() - other.getSortIndex()
|
25947 | }
|
25948 | if (this.isEmpty() && other.isEmpty()) {
|
25949 | return 0
|
25950 | }
|
25951 | if (this.isEmpty()) {
|
25952 | return -1
|
25953 | }
|
25954 | if (other.isEmpty()) {
|
25955 | return 1
|
25956 | }
|
25957 | return this.compareToSameClass(o)
|
25958 | } else if (arguments.length === 2) {
|
25959 | var other$1 = arguments[0];
|
25960 | var comp = arguments[1];
|
25961 | if (this.getSortIndex() !== other$1.getSortIndex()) {
|
25962 | return this.getSortIndex() - other$1.getSortIndex()
|
25963 | }
|
25964 | if (this.isEmpty() && other$1.isEmpty()) {
|
25965 | return 0
|
25966 | }
|
25967 | if (this.isEmpty()) {
|
25968 | return -1
|
25969 | }
|
25970 | if (other$1.isEmpty()) {
|
25971 | return 1
|
25972 | }
|
25973 | return this.compareToSameClass(other$1, comp)
|
25974 | }
|
25975 | };
|
25976 | Geometry.prototype.getUserData = function getUserData () {
|
25977 | return this._userData
|
25978 | };
|
25979 | Geometry.prototype.getSRID = function getSRID () {
|
25980 | return this._SRID
|
25981 | };
|
25982 | Geometry.prototype.getEnvelope = function getEnvelope () {
|
25983 | return this.getFactory().toGeometry(this.getEnvelopeInternal())
|
25984 | };
|
25985 | Geometry.prototype.checkNotGeometryCollection = function checkNotGeometryCollection (g) {
|
25986 | if (g.getSortIndex() === Geometry.SORTINDEX_GEOMETRYCOLLECTION) {
|
25987 | throw new IllegalArgumentException('This method does not support GeometryCollection arguments')
|
25988 | }
|
25989 | };
|
25990 | Geometry.prototype.equal = function equal (a, b, tolerance) {
|
25991 | if (tolerance === 0) {
|
25992 | return a.equals(b)
|
25993 | }
|
25994 | return a.distance(b) <= tolerance
|
25995 | };
|
25996 | Geometry.prototype.norm = function norm () {
|
25997 | var copy = this.copy();
|
25998 | copy.normalize();
|
25999 | return copy
|
26000 | };
|
26001 | Geometry.prototype.getPrecisionModel = function getPrecisionModel () {
|
26002 | return this._factory.getPrecisionModel()
|
26003 | };
|
26004 | Geometry.prototype.getEnvelopeInternal = function getEnvelopeInternal () {
|
26005 | if (this._envelope === null) {
|
26006 | this._envelope = this.computeEnvelopeInternal();
|
26007 | }
|
26008 | return new Envelope(this._envelope)
|
26009 | };
|
26010 | Geometry.prototype.setSRID = function setSRID (SRID) {
|
26011 | this._SRID = SRID;
|
26012 | };
|
26013 | Geometry.prototype.setUserData = function setUserData (userData) {
|
26014 | this._userData = userData;
|
26015 | };
|
26016 | Geometry.prototype.compare = function compare (a, b) {
|
26017 | var i = a.iterator();
|
26018 | var j = b.iterator();
|
26019 | while (i.hasNext() && j.hasNext()) {
|
26020 | var aElement = i.next();
|
26021 | var bElement = j.next();
|
26022 | var comparison = aElement.compareTo(bElement);
|
26023 | if (comparison !== 0) {
|
26024 | return comparison
|
26025 | }
|
26026 | }
|
26027 | if (i.hasNext()) {
|
26028 | return 1
|
26029 | }
|
26030 | if (j.hasNext()) {
|
26031 | return -1
|
26032 | }
|
26033 | return 0
|
26034 | };
|
26035 | Geometry.prototype.hashCode = function hashCode () {
|
26036 | return this.getEnvelopeInternal().hashCode()
|
26037 | };
|
26038 | Geometry.prototype.isGeometryCollectionOrDerived = function isGeometryCollectionOrDerived () {
|
26039 | if (this.getSortIndex() === Geometry.SORTINDEX_GEOMETRYCOLLECTION || this.getSortIndex() === Geometry.SORTINDEX_MULTIPOINT || this.getSortIndex() === Geometry.SORTINDEX_MULTILINESTRING || this.getSortIndex() === Geometry.SORTINDEX_MULTIPOLYGON) {
|
26040 | return true
|
26041 | }
|
26042 | return false
|
26043 | };
|
26044 | Geometry.prototype.interfaces_ = function interfaces_ () {
|
26045 | return [Clonable, Comparable, Serializable]
|
26046 | };
|
26047 | Geometry.prototype.getClass = function getClass () {
|
26048 | return Geometry
|
26049 | };
|
26050 | Geometry.hasNonEmptyElements = function hasNonEmptyElements (geometries) {
|
26051 | for (var i = 0; i < geometries.length; i++) {
|
26052 | if (!geometries[i].isEmpty()) {
|
26053 | return true
|
26054 | }
|
26055 | }
|
26056 | return false
|
26057 | };
|
26058 | Geometry.hasNullElements = function hasNullElements (array) {
|
26059 | for (var i = 0; i < array.length; i++) {
|
26060 | if (array[i] === null) {
|
26061 | return true
|
26062 | }
|
26063 | }
|
26064 | return false
|
26065 | };
|
26066 | staticAccessors$11.serialVersionUID.get = function () { return 8763622679187376702 };
|
26067 | staticAccessors$11.SORTINDEX_POINT.get = function () { return 0 };
|
26068 | staticAccessors$11.SORTINDEX_MULTIPOINT.get = function () { return 1 };
|
26069 | staticAccessors$11.SORTINDEX_LINESTRING.get = function () { return 2 };
|
26070 | staticAccessors$11.SORTINDEX_LINEARRING.get = function () { return 3 };
|
26071 | staticAccessors$11.SORTINDEX_MULTILINESTRING.get = function () { return 4 };
|
26072 | staticAccessors$11.SORTINDEX_POLYGON.get = function () { return 5 };
|
26073 | staticAccessors$11.SORTINDEX_MULTIPOLYGON.get = function () { return 6 };
|
26074 | staticAccessors$11.SORTINDEX_GEOMETRYCOLLECTION.get = function () { return 7 };
|
26075 | staticAccessors$11.geometryChangedFilter.get = function () { return geometryChangedFilter };
|
26076 |
|
26077 | Object.defineProperties( Geometry, staticAccessors$11 );
|
26078 |
|
26079 | var geometryChangedFilter = function geometryChangedFilter () {};
|
26080 |
|
26081 | geometryChangedFilter.interfaces_ = function interfaces_ () {
|
26082 | return [GeometryComponentFilter]
|
26083 | };
|
26084 | geometryChangedFilter.filter = function filter (geom) {
|
26085 | geom.geometryChangedAction();
|
26086 | };
|
26087 |
|
26088 | var CoordinateFilter = function CoordinateFilter () {};
|
26089 |
|
26090 | CoordinateFilter.prototype.filter = function filter (coord) {};
|
26091 | CoordinateFilter.prototype.interfaces_ = function interfaces_ () {
|
26092 | return []
|
26093 | };
|
26094 | CoordinateFilter.prototype.getClass = function getClass () {
|
26095 | return CoordinateFilter
|
26096 | };
|
26097 |
|
26098 | var BoundaryNodeRule = function BoundaryNodeRule () {};
|
26099 |
|
26100 | var staticAccessors$12 = { Mod2BoundaryNodeRule: { configurable: true },EndPointBoundaryNodeRule: { configurable: true },MultiValentEndPointBoundaryNodeRule: { configurable: true },MonoValentEndPointBoundaryNodeRule: { configurable: true },MOD2_BOUNDARY_RULE: { configurable: true },ENDPOINT_BOUNDARY_RULE: { configurable: true },MULTIVALENT_ENDPOINT_BOUNDARY_RULE: { configurable: true },MONOVALENT_ENDPOINT_BOUNDARY_RULE: { configurable: true },OGC_SFS_BOUNDARY_RULE: { configurable: true } };
|
26101 |
|
26102 | BoundaryNodeRule.prototype.isInBoundary = function isInBoundary (boundaryCount) {};
|
26103 | BoundaryNodeRule.prototype.interfaces_ = function interfaces_ () {
|
26104 | return []
|
26105 | };
|
26106 | BoundaryNodeRule.prototype.getClass = function getClass () {
|
26107 | return BoundaryNodeRule
|
26108 | };
|
26109 | staticAccessors$12.Mod2BoundaryNodeRule.get = function () { return Mod2BoundaryNodeRule };
|
26110 | staticAccessors$12.EndPointBoundaryNodeRule.get = function () { return EndPointBoundaryNodeRule };
|
26111 | staticAccessors$12.MultiValentEndPointBoundaryNodeRule.get = function () { return MultiValentEndPointBoundaryNodeRule };
|
26112 | staticAccessors$12.MonoValentEndPointBoundaryNodeRule.get = function () { return MonoValentEndPointBoundaryNodeRule };
|
26113 | staticAccessors$12.MOD2_BOUNDARY_RULE.get = function () { return new Mod2BoundaryNodeRule() };
|
26114 | staticAccessors$12.ENDPOINT_BOUNDARY_RULE.get = function () { return new EndPointBoundaryNodeRule() };
|
26115 | staticAccessors$12.MULTIVALENT_ENDPOINT_BOUNDARY_RULE.get = function () { return new MultiValentEndPointBoundaryNodeRule() };
|
26116 | staticAccessors$12.MONOVALENT_ENDPOINT_BOUNDARY_RULE.get = function () { return new MonoValentEndPointBoundaryNodeRule() };
|
26117 | staticAccessors$12.OGC_SFS_BOUNDARY_RULE.get = function () { return BoundaryNodeRule.MOD2_BOUNDARY_RULE };
|
26118 |
|
26119 | Object.defineProperties( BoundaryNodeRule, staticAccessors$12 );
|
26120 |
|
26121 | var Mod2BoundaryNodeRule = function Mod2BoundaryNodeRule () {};
|
26122 |
|
26123 | Mod2BoundaryNodeRule.prototype.isInBoundary = function isInBoundary (boundaryCount) {
|
26124 | return boundaryCount % 2 === 1
|
26125 | };
|
26126 | Mod2BoundaryNodeRule.prototype.interfaces_ = function interfaces_ () {
|
26127 | return [BoundaryNodeRule]
|
26128 | };
|
26129 | Mod2BoundaryNodeRule.prototype.getClass = function getClass () {
|
26130 | return Mod2BoundaryNodeRule
|
26131 | };
|
26132 |
|
26133 | var EndPointBoundaryNodeRule = function EndPointBoundaryNodeRule () {};
|
26134 |
|
26135 | EndPointBoundaryNodeRule.prototype.isInBoundary = function isInBoundary (boundaryCount) {
|
26136 | return boundaryCount > 0
|
26137 | };
|
26138 | EndPointBoundaryNodeRule.prototype.interfaces_ = function interfaces_ () {
|
26139 | return [BoundaryNodeRule]
|
26140 | };
|
26141 | EndPointBoundaryNodeRule.prototype.getClass = function getClass () {
|
26142 | return EndPointBoundaryNodeRule
|
26143 | };
|
26144 |
|
26145 | var MultiValentEndPointBoundaryNodeRule = function MultiValentEndPointBoundaryNodeRule () {};
|
26146 |
|
26147 | MultiValentEndPointBoundaryNodeRule.prototype.isInBoundary = function isInBoundary (boundaryCount) {
|
26148 | return boundaryCount > 1
|
26149 | };
|
26150 | MultiValentEndPointBoundaryNodeRule.prototype.interfaces_ = function interfaces_ () {
|
26151 | return [BoundaryNodeRule]
|
26152 | };
|
26153 | MultiValentEndPointBoundaryNodeRule.prototype.getClass = function getClass () {
|
26154 | return MultiValentEndPointBoundaryNodeRule
|
26155 | };
|
26156 |
|
26157 | var MonoValentEndPointBoundaryNodeRule = function MonoValentEndPointBoundaryNodeRule () {};
|
26158 |
|
26159 | MonoValentEndPointBoundaryNodeRule.prototype.isInBoundary = function isInBoundary (boundaryCount) {
|
26160 | return boundaryCount === 1
|
26161 | };
|
26162 | MonoValentEndPointBoundaryNodeRule.prototype.interfaces_ = function interfaces_ () {
|
26163 | return [BoundaryNodeRule]
|
26164 | };
|
26165 | MonoValentEndPointBoundaryNodeRule.prototype.getClass = function getClass () {
|
26166 | return MonoValentEndPointBoundaryNodeRule
|
26167 | };
|
26168 |
|
26169 |
|
26170 |
|
26171 |
|
26172 |
|
26173 |
|
26174 |
|
26175 |
|
26176 |
|
26177 | var Collection = function Collection () {};
|
26178 |
|
26179 | Collection.prototype.add = function add () {};
|
26180 |
|
26181 |
|
26182 |
|
26183 |
|
26184 |
|
26185 |
|
26186 |
|
26187 |
|
26188 | Collection.prototype.addAll = function addAll () {};
|
26189 |
|
26190 |
|
26191 |
|
26192 |
|
26193 |
|
26194 | Collection.prototype.isEmpty = function isEmpty () {};
|
26195 |
|
26196 |
|
26197 |
|
26198 |
|
26199 |
|
26200 | Collection.prototype.iterator = function iterator () {};
|
26201 |
|
26202 |
|
26203 |
|
26204 |
|
26205 |
|
26206 | Collection.prototype.size = function size () {};
|
26207 |
|
26208 |
|
26209 |
|
26210 |
|
26211 |
|
26212 | Collection.prototype.toArray = function toArray () {};
|
26213 |
|
26214 |
|
26215 |
|
26216 |
|
26217 |
|
26218 |
|
26219 |
|
26220 | Collection.prototype.remove = function remove () {};
|
26221 |
|
26222 |
|
26223 |
|
26224 |
|
26225 |
|
26226 |
|
26227 |
|
26228 | var IndexOutOfBoundsException = (function (Error) {
|
26229 | function IndexOutOfBoundsException (message) {
|
26230 | Error.call(this);
|
26231 | this.message = message || '';
|
26232 | }
|
26233 |
|
26234 | if ( Error ) IndexOutOfBoundsException.__proto__ = Error;
|
26235 | IndexOutOfBoundsException.prototype = Object.create( Error && Error.prototype );
|
26236 | IndexOutOfBoundsException.prototype.constructor = IndexOutOfBoundsException;
|
26237 |
|
26238 | var staticAccessors = { name: { configurable: true } };
|
26239 |
|
26240 | |
26241 |
|
26242 |
|
26243 | staticAccessors.name.get = function () { return 'IndexOutOfBoundsException' };
|
26244 |
|
26245 | Object.defineProperties( IndexOutOfBoundsException, staticAccessors );
|
26246 |
|
26247 | return IndexOutOfBoundsException;
|
26248 | }(Error));
|
26249 |
|
26250 |
|
26251 |
|
26252 |
|
26253 |
|
26254 |
|
26255 | var Iterator = function Iterator () {};
|
26256 |
|
26257 | Iterator.prototype.hasNext = function hasNext () {};
|
26258 |
|
26259 |
|
26260 |
|
26261 |
|
26262 |
|
26263 | Iterator.prototype.next = function next () {};
|
26264 |
|
26265 |
|
26266 |
|
26267 |
|
26268 |
|
26269 | Iterator.prototype.remove = function remove () {};
|
26270 |
|
26271 |
|
26272 |
|
26273 |
|
26274 |
|
26275 |
|
26276 |
|
26277 |
|
26278 | var List = (function (Collection$$1) {
|
26279 | function List () {
|
26280 | Collection$$1.apply(this, arguments);
|
26281 | }
|
26282 |
|
26283 | if ( Collection$$1 ) List.__proto__ = Collection$$1;
|
26284 | List.prototype = Object.create( Collection$$1 && Collection$$1.prototype );
|
26285 | List.prototype.constructor = List;
|
26286 |
|
26287 | List.prototype.get = function get () { };
|
26288 |
|
26289 | |
26290 |
|
26291 |
|
26292 |
|
26293 |
|
26294 |
|
26295 |
|
26296 | List.prototype.set = function set () { };
|
26297 |
|
26298 | |
26299 |
|
26300 |
|
26301 |
|
26302 | List.prototype.isEmpty = function isEmpty () { };
|
26303 |
|
26304 | return List;
|
26305 | }(Collection));
|
26306 |
|
26307 |
|
26308 |
|
26309 |
|
26310 |
|
26311 |
|
26312 |
|
26313 | function NoSuchElementException (message) {
|
26314 | this.message = message || '';
|
26315 | }
|
26316 | NoSuchElementException.prototype = new Error();
|
26317 |
|
26318 |
|
26319 |
|
26320 |
|
26321 | NoSuchElementException.prototype.name = 'NoSuchElementException';
|
26322 |
|
26323 |
|
26324 |
|
26325 |
|
26326 |
|
26327 |
|
26328 |
|
26329 |
|
26330 |
|
26331 | var ArrayList = (function (List$$1) {
|
26332 | function ArrayList () {
|
26333 | List$$1.call(this);
|
26334 | this.array_ = [];
|
26335 |
|
26336 | if (arguments[0] instanceof Collection) {
|
26337 | this.addAll(arguments[0]);
|
26338 | }
|
26339 | }
|
26340 |
|
26341 | if ( List$$1 ) ArrayList.__proto__ = List$$1;
|
26342 | ArrayList.prototype = Object.create( List$$1 && List$$1.prototype );
|
26343 | ArrayList.prototype.constructor = ArrayList;
|
26344 |
|
26345 | ArrayList.prototype.ensureCapacity = function ensureCapacity () {};
|
26346 | ArrayList.prototype.interfaces_ = function interfaces_ () { return [List$$1, Collection] };
|
26347 |
|
26348 | |
26349 |
|
26350 |
|
26351 | ArrayList.prototype.add = function add (e) {
|
26352 | if (arguments.length === 1) {
|
26353 | this.array_.push(e);
|
26354 | } else {
|
26355 | this.array_.splice(arguments[0], arguments[1]);
|
26356 | }
|
26357 | return true
|
26358 | };
|
26359 |
|
26360 | ArrayList.prototype.clear = function clear () {
|
26361 | this.array_ = [];
|
26362 | };
|
26363 |
|
26364 | |
26365 |
|
26366 |
|
26367 | ArrayList.prototype.addAll = function addAll (c) {
|
26368 | var this$1 = this;
|
26369 |
|
26370 | for (var i = c.iterator(); i.hasNext();) {
|
26371 | this$1.add(i.next());
|
26372 | }
|
26373 | return true
|
26374 | };
|
26375 |
|
26376 | |
26377 |
|
26378 |
|
26379 | ArrayList.prototype.set = function set (index, element) {
|
26380 | var oldElement = this.array_[index];
|
26381 | this.array_[index] = element;
|
26382 | return oldElement
|
26383 | };
|
26384 |
|
26385 | |
26386 |
|
26387 |
|
26388 | ArrayList.prototype.iterator = function iterator () {
|
26389 | return new Iterator_(this)
|
26390 | };
|
26391 |
|
26392 | |
26393 |
|
26394 |
|
26395 | ArrayList.prototype.get = function get (index) {
|
26396 | if (index < 0 || index >= this.size()) {
|
26397 | throw new IndexOutOfBoundsException()
|
26398 | }
|
26399 |
|
26400 | return this.array_[index]
|
26401 | };
|
26402 |
|
26403 | |
26404 |
|
26405 |
|
26406 | ArrayList.prototype.isEmpty = function isEmpty () {
|
26407 | return this.array_.length === 0
|
26408 | };
|
26409 |
|
26410 | |
26411 |
|
26412 |
|
26413 | ArrayList.prototype.size = function size () {
|
26414 | return this.array_.length
|
26415 | };
|
26416 |
|
26417 | |
26418 |
|
26419 |
|
26420 | ArrayList.prototype.toArray = function toArray () {
|
26421 | var this$1 = this;
|
26422 |
|
26423 | var array = [];
|
26424 |
|
26425 | for (var i = 0, len = this.array_.length; i < len; i++) {
|
26426 | array.push(this$1.array_[i]);
|
26427 | }
|
26428 |
|
26429 | return array
|
26430 | };
|
26431 |
|
26432 | |
26433 |
|
26434 |
|
26435 | ArrayList.prototype.remove = function remove (o) {
|
26436 | var this$1 = this;
|
26437 |
|
26438 | var found = false;
|
26439 |
|
26440 | for (var i = 0, len = this.array_.length; i < len; i++) {
|
26441 | if (this$1.array_[i] === o) {
|
26442 | this$1.array_.splice(i, 1);
|
26443 | found = true;
|
26444 | break
|
26445 | }
|
26446 | }
|
26447 |
|
26448 | return found
|
26449 | };
|
26450 |
|
26451 | return ArrayList;
|
26452 | }(List));
|
26453 |
|
26454 |
|
26455 |
|
26456 |
|
26457 |
|
26458 |
|
26459 |
|
26460 | var Iterator_ = (function (Iterator$$1) {
|
26461 | function Iterator_ (arrayList) {
|
26462 | Iterator$$1.call(this);
|
26463 | |
26464 |
|
26465 |
|
26466 |
|
26467 | this.arrayList_ = arrayList;
|
26468 | |
26469 |
|
26470 |
|
26471 |
|
26472 | this.position_ = 0;
|
26473 | }
|
26474 |
|
26475 | if ( Iterator$$1 ) Iterator_.__proto__ = Iterator$$1;
|
26476 | Iterator_.prototype = Object.create( Iterator$$1 && Iterator$$1.prototype );
|
26477 | Iterator_.prototype.constructor = Iterator_;
|
26478 |
|
26479 | |
26480 |
|
26481 |
|
26482 | Iterator_.prototype.next = function next () {
|
26483 | if (this.position_ === this.arrayList_.size()) {
|
26484 | throw new NoSuchElementException()
|
26485 | }
|
26486 | return this.arrayList_.get(this.position_++)
|
26487 | };
|
26488 |
|
26489 | |
26490 |
|
26491 |
|
26492 | Iterator_.prototype.hasNext = function hasNext () {
|
26493 | if (this.position_ < this.arrayList_.size()) {
|
26494 | return true
|
26495 | } else {
|
26496 | return false
|
26497 | }
|
26498 | };
|
26499 |
|
26500 | |
26501 |
|
26502 |
|
26503 |
|
26504 | Iterator_.prototype.set = function set (element) {
|
26505 | return this.arrayList_.set(this.position_ - 1, element)
|
26506 | };
|
26507 |
|
26508 | |
26509 |
|
26510 |
|
26511 | Iterator_.prototype.remove = function remove () {
|
26512 | this.arrayList_.remove(this.arrayList_.get(this.position_));
|
26513 | };
|
26514 |
|
26515 | return Iterator_;
|
26516 | }(Iterator));
|
26517 |
|
26518 | var CoordinateList = (function (ArrayList$$1) {
|
26519 | function CoordinateList () {
|
26520 | ArrayList$$1.call(this);
|
26521 | if (arguments.length === 0) {
|
26522 | } else if (arguments.length === 1) {
|
26523 | var coord = arguments[0];
|
26524 | this.ensureCapacity(coord.length);
|
26525 | this.add(coord, true);
|
26526 | } else if (arguments.length === 2) {
|
26527 | var coord$1 = arguments[0];
|
26528 | var allowRepeated = arguments[1];
|
26529 | this.ensureCapacity(coord$1.length);
|
26530 | this.add(coord$1, allowRepeated);
|
26531 | }
|
26532 | }
|
26533 |
|
26534 | if ( ArrayList$$1 ) CoordinateList.__proto__ = ArrayList$$1;
|
26535 | CoordinateList.prototype = Object.create( ArrayList$$1 && ArrayList$$1.prototype );
|
26536 | CoordinateList.prototype.constructor = CoordinateList;
|
26537 |
|
26538 | var staticAccessors = { coordArrayType: { configurable: true } };
|
26539 | staticAccessors.coordArrayType.get = function () { return new Array(0).fill(null) };
|
26540 | CoordinateList.prototype.getCoordinate = function getCoordinate (i) {
|
26541 | return this.get(i)
|
26542 | };
|
26543 | CoordinateList.prototype.addAll = function addAll () {
|
26544 | var this$1 = this;
|
26545 |
|
26546 | if (arguments.length === 2) {
|
26547 | var coll = arguments[0];
|
26548 | var allowRepeated = arguments[1];
|
26549 | var isChanged = false;
|
26550 | for (var i = coll.iterator(); i.hasNext();) {
|
26551 | this$1.add(i.next(), allowRepeated);
|
26552 | isChanged = true;
|
26553 | }
|
26554 | return isChanged
|
26555 | } else { return ArrayList$$1.prototype.addAll.apply(this, arguments) }
|
26556 | };
|
26557 | CoordinateList.prototype.clone = function clone () {
|
26558 | var this$1 = this;
|
26559 |
|
26560 | var clone = ArrayList$$1.prototype.clone.call(this);
|
26561 | for (var i = 0; i < this.size(); i++) {
|
26562 | clone.add(i, this$1.get(i).copy());
|
26563 | }
|
26564 | return clone
|
26565 | };
|
26566 | CoordinateList.prototype.toCoordinateArray = function toCoordinateArray () {
|
26567 | return this.toArray(CoordinateList.coordArrayType)
|
26568 | };
|
26569 | CoordinateList.prototype.add = function add () {
|
26570 | var this$1 = this;
|
26571 |
|
26572 | if (arguments.length === 1) {
|
26573 | var coord = arguments[0];
|
26574 | ArrayList$$1.prototype.add.call(this, coord);
|
26575 | } else if (arguments.length === 2) {
|
26576 | if (arguments[0] instanceof Array && typeof arguments[1] === 'boolean') {
|
26577 | var coord$1 = arguments[0];
|
26578 | var allowRepeated = arguments[1];
|
26579 | this.add(coord$1, allowRepeated, true);
|
26580 | return true
|
26581 | } else if (arguments[0] instanceof Coordinate && typeof arguments[1] === 'boolean') {
|
26582 | var coord$2 = arguments[0];
|
26583 | var allowRepeated$1 = arguments[1];
|
26584 | if (!allowRepeated$1) {
|
26585 | if (this.size() >= 1) {
|
26586 | var last = this.get(this.size() - 1);
|
26587 | if (last.equals2D(coord$2)) { return null }
|
26588 | }
|
26589 | }
|
26590 | ArrayList$$1.prototype.add.call(this, coord$2);
|
26591 | } else if (arguments[0] instanceof Object && typeof arguments[1] === 'boolean') {
|
26592 | var obj = arguments[0];
|
26593 | var allowRepeated$2 = arguments[1];
|
26594 | this.add(obj, allowRepeated$2);
|
26595 | return true
|
26596 | }
|
26597 | } else if (arguments.length === 3) {
|
26598 | if (typeof arguments[2] === 'boolean' && (arguments[0] instanceof Array && typeof arguments[1] === 'boolean')) {
|
26599 | var coord$3 = arguments[0];
|
26600 | var allowRepeated$3 = arguments[1];
|
26601 | var direction = arguments[2];
|
26602 | if (direction) {
|
26603 | for (var i$1 = 0; i$1 < coord$3.length; i$1++) {
|
26604 | this$1.add(coord$3[i$1], allowRepeated$3);
|
26605 | }
|
26606 | } else {
|
26607 | for (var i$2 = coord$3.length - 1; i$2 >= 0; i$2--) {
|
26608 | this$1.add(coord$3[i$2], allowRepeated$3);
|
26609 | }
|
26610 | }
|
26611 | return true
|
26612 | } else if (typeof arguments[2] === 'boolean' && (Number.isInteger(arguments[0]) && arguments[1] instanceof Coordinate)) {
|
26613 | var i$3 = arguments[0];
|
26614 | var coord$4 = arguments[1];
|
26615 | var allowRepeated$4 = arguments[2];
|
26616 | if (!allowRepeated$4) {
|
26617 | var size = this.size();
|
26618 | if (size > 0) {
|
26619 | if (i$3 > 0) {
|
26620 | var prev = this.get(i$3 - 1);
|
26621 | if (prev.equals2D(coord$4)) { return null }
|
26622 | }
|
26623 | if (i$3 < size) {
|
26624 | var next = this.get(i$3);
|
26625 | if (next.equals2D(coord$4)) { return null }
|
26626 | }
|
26627 | }
|
26628 | }
|
26629 | ArrayList$$1.prototype.add.call(this, i$3, coord$4);
|
26630 | }
|
26631 | } else if (arguments.length === 4) {
|
26632 | var coord$5 = arguments[0];
|
26633 | var allowRepeated$5 = arguments[1];
|
26634 | var start = arguments[2];
|
26635 | var end = arguments[3];
|
26636 | var inc = 1;
|
26637 | if (start > end) { inc = -1; }
|
26638 | for (var i = start; i !== end; i += inc) {
|
26639 | this$1.add(coord$5[i], allowRepeated$5);
|
26640 | }
|
26641 | return true
|
26642 | }
|
26643 | };
|
26644 | CoordinateList.prototype.closeRing = function closeRing () {
|
26645 | if (this.size() > 0) { this.add(new Coordinate(this.get(0)), false); }
|
26646 | };
|
26647 | CoordinateList.prototype.interfaces_ = function interfaces_ () {
|
26648 | return []
|
26649 | };
|
26650 | CoordinateList.prototype.getClass = function getClass () {
|
26651 | return CoordinateList
|
26652 | };
|
26653 |
|
26654 | Object.defineProperties( CoordinateList, staticAccessors );
|
26655 |
|
26656 | return CoordinateList;
|
26657 | }(ArrayList));
|
26658 |
|
26659 | var CoordinateArrays = function CoordinateArrays () {};
|
26660 |
|
26661 | var staticAccessors$13 = { ForwardComparator: { configurable: true },BidirectionalComparator: { configurable: true },coordArrayType: { configurable: true } };
|
26662 |
|
26663 | staticAccessors$13.ForwardComparator.get = function () { return ForwardComparator };
|
26664 | staticAccessors$13.BidirectionalComparator.get = function () { return BidirectionalComparator };
|
26665 | staticAccessors$13.coordArrayType.get = function () { return new Array(0).fill(null) };
|
26666 |
|
26667 | CoordinateArrays.prototype.interfaces_ = function interfaces_ () {
|
26668 | return []
|
26669 | };
|
26670 | CoordinateArrays.prototype.getClass = function getClass () {
|
26671 | return CoordinateArrays
|
26672 | };
|
26673 | CoordinateArrays.isRing = function isRing (pts) {
|
26674 | if (pts.length < 4) { return false }
|
26675 | if (!pts[0].equals2D(pts[pts.length - 1])) { return false }
|
26676 | return true
|
26677 | };
|
26678 | CoordinateArrays.ptNotInList = function ptNotInList (testPts, pts) {
|
26679 | for (var i = 0; i < testPts.length; i++) {
|
26680 | var testPt = testPts[i];
|
26681 | if (CoordinateArrays.indexOf(testPt, pts) < 0) { return testPt }
|
26682 | }
|
26683 | return null
|
26684 | };
|
26685 | CoordinateArrays.scroll = function scroll (coordinates, firstCoordinate) {
|
26686 | var i = CoordinateArrays.indexOf(firstCoordinate, coordinates);
|
26687 | if (i < 0) { return null }
|
26688 | var newCoordinates = new Array(coordinates.length).fill(null);
|
26689 | System.arraycopy(coordinates, i, newCoordinates, 0, coordinates.length - i);
|
26690 | System.arraycopy(coordinates, 0, newCoordinates, coordinates.length - i, i);
|
26691 | System.arraycopy(newCoordinates, 0, coordinates, 0, coordinates.length);
|
26692 | };
|
26693 | CoordinateArrays.equals = function equals () {
|
26694 | if (arguments.length === 2) {
|
26695 | var coord1 = arguments[0];
|
26696 | var coord2 = arguments[1];
|
26697 | if (coord1 === coord2) { return true }
|
26698 | if (coord1 === null || coord2 === null) { return false }
|
26699 | if (coord1.length !== coord2.length) { return false }
|
26700 | for (var i = 0; i < coord1.length; i++) {
|
26701 | if (!coord1[i].equals(coord2[i])) { return false }
|
26702 | }
|
26703 | return true
|
26704 | } else if (arguments.length === 3) {
|
26705 | var coord1$1 = arguments[0];
|
26706 | var coord2$1 = arguments[1];
|
26707 | var coordinateComparator = arguments[2];
|
26708 | if (coord1$1 === coord2$1) { return true }
|
26709 | if (coord1$1 === null || coord2$1 === null) { return false }
|
26710 | if (coord1$1.length !== coord2$1.length) { return false }
|
26711 | for (var i$1 = 0; i$1 < coord1$1.length; i$1++) {
|
26712 | if (coordinateComparator.compare(coord1$1[i$1], coord2$1[i$1]) !== 0) { return false }
|
26713 | }
|
26714 | return true
|
26715 | }
|
26716 | };
|
26717 | CoordinateArrays.intersection = function intersection (coordinates, env) {
|
26718 | var coordList = new CoordinateList();
|
26719 | for (var i = 0; i < coordinates.length; i++) {
|
26720 | if (env.intersects(coordinates[i])) { coordList.add(coordinates[i], true); }
|
26721 | }
|
26722 | return coordList.toCoordinateArray()
|
26723 | };
|
26724 | CoordinateArrays.hasRepeatedPoints = function hasRepeatedPoints (coord) {
|
26725 | for (var i = 1; i < coord.length; i++) {
|
26726 | if (coord[i - 1].equals(coord[i])) {
|
26727 | return true
|
26728 | }
|
26729 | }
|
26730 | return false
|
26731 | };
|
26732 | CoordinateArrays.removeRepeatedPoints = function removeRepeatedPoints (coord) {
|
26733 | if (!CoordinateArrays.hasRepeatedPoints(coord)) { return coord }
|
26734 | var coordList = new CoordinateList(coord, false);
|
26735 | return coordList.toCoordinateArray()
|
26736 | };
|
26737 | CoordinateArrays.reverse = function reverse (coord) {
|
26738 | var last = coord.length - 1;
|
26739 | var mid = Math.trunc(last / 2);
|
26740 | for (var i = 0; i <= mid; i++) {
|
26741 | var tmp = coord[i];
|
26742 | coord[i] = coord[last - i];
|
26743 | coord[last - i] = tmp;
|
26744 | }
|
26745 | };
|
26746 | CoordinateArrays.removeNull = function removeNull (coord) {
|
26747 | var nonNull = 0;
|
26748 | for (var i = 0; i < coord.length; i++) {
|
26749 | if (coord[i] !== null) { nonNull++; }
|
26750 | }
|
26751 | var newCoord = new Array(nonNull).fill(null);
|
26752 | if (nonNull === 0) { return newCoord }
|
26753 | var j = 0;
|
26754 | for (var i$1 = 0; i$1 < coord.length; i$1++) {
|
26755 | if (coord[i$1] !== null) { newCoord[j++] = coord[i$1]; }
|
26756 | }
|
26757 | return newCoord
|
26758 | };
|
26759 | CoordinateArrays.copyDeep = function copyDeep () {
|
26760 | if (arguments.length === 1) {
|
26761 | var coordinates = arguments[0];
|
26762 | var copy = new Array(coordinates.length).fill(null);
|
26763 | for (var i = 0; i < coordinates.length; i++) {
|
26764 | copy[i] = new Coordinate(coordinates[i]);
|
26765 | }
|
26766 | return copy
|
26767 | } else if (arguments.length === 5) {
|
26768 | var src = arguments[0];
|
26769 | var srcStart = arguments[1];
|
26770 | var dest = arguments[2];
|
26771 | var destStart = arguments[3];
|
26772 | var length = arguments[4];
|
26773 | for (var i$1 = 0; i$1 < length; i$1++) {
|
26774 | dest[destStart + i$1] = new Coordinate(src[srcStart + i$1]);
|
26775 | }
|
26776 | }
|
26777 | };
|
26778 | CoordinateArrays.isEqualReversed = function isEqualReversed (pts1, pts2) {
|
26779 | for (var i = 0; i < pts1.length; i++) {
|
26780 | var p1 = pts1[i];
|
26781 | var p2 = pts2[pts1.length - i - 1];
|
26782 | if (p1.compareTo(p2) !== 0) { return false }
|
26783 | }
|
26784 | return true
|
26785 | };
|
26786 | CoordinateArrays.envelope = function envelope (coordinates) {
|
26787 | var env = new Envelope();
|
26788 | for (var i = 0; i < coordinates.length; i++) {
|
26789 | env.expandToInclude(coordinates[i]);
|
26790 | }
|
26791 | return env
|
26792 | };
|
26793 | CoordinateArrays.toCoordinateArray = function toCoordinateArray (coordList) {
|
26794 | return coordList.toArray(CoordinateArrays.coordArrayType)
|
26795 | };
|
26796 | CoordinateArrays.atLeastNCoordinatesOrNothing = function atLeastNCoordinatesOrNothing (n, c) {
|
26797 | return c.length >= n ? c : []
|
26798 | };
|
26799 | CoordinateArrays.indexOf = function indexOf (coordinate, coordinates) {
|
26800 | for (var i = 0; i < coordinates.length; i++) {
|
26801 | if (coordinate.equals(coordinates[i])) {
|
26802 | return i
|
26803 | }
|
26804 | }
|
26805 | return -1
|
26806 | };
|
26807 | CoordinateArrays.increasingDirection = function increasingDirection (pts) {
|
26808 | for (var i = 0; i < Math.trunc(pts.length / 2); i++) {
|
26809 | var j = pts.length - 1 - i;
|
26810 | var comp = pts[i].compareTo(pts[j]);
|
26811 | if (comp !== 0) { return comp }
|
26812 | }
|
26813 | return 1
|
26814 | };
|
26815 | CoordinateArrays.compare = function compare (pts1, pts2) {
|
26816 | var i = 0;
|
26817 | while (i < pts1.length && i < pts2.length) {
|
26818 | var compare = pts1[i].compareTo(pts2[i]);
|
26819 | if (compare !== 0) { return compare }
|
26820 | i++;
|
26821 | }
|
26822 | if (i < pts2.length) { return -1 }
|
26823 | if (i < pts1.length) { return 1 }
|
26824 | return 0
|
26825 | };
|
26826 | CoordinateArrays.minCoordinate = function minCoordinate (coordinates) {
|
26827 | var minCoord = null;
|
26828 | for (var i = 0; i < coordinates.length; i++) {
|
26829 | if (minCoord === null || minCoord.compareTo(coordinates[i]) > 0) {
|
26830 | minCoord = coordinates[i];
|
26831 | }
|
26832 | }
|
26833 | return minCoord
|
26834 | };
|
26835 | CoordinateArrays.extract = function extract (pts, start, end) {
|
26836 | start = MathUtil.clamp(start, 0, pts.length);
|
26837 | end = MathUtil.clamp(end, -1, pts.length);
|
26838 | var npts = end - start + 1;
|
26839 | if (end < 0) { npts = 0; }
|
26840 | if (start >= pts.length) { npts = 0; }
|
26841 | if (end < start) { npts = 0; }
|
26842 | var extractPts = new Array(npts).fill(null);
|
26843 | if (npts === 0) { return extractPts }
|
26844 | var iPts = 0;
|
26845 | for (var i = start; i <= end; i++) {
|
26846 | extractPts[iPts++] = pts[i];
|
26847 | }
|
26848 | return extractPts
|
26849 | };
|
26850 |
|
26851 | Object.defineProperties( CoordinateArrays, staticAccessors$13 );
|
26852 |
|
26853 | var ForwardComparator = function ForwardComparator () {};
|
26854 |
|
26855 | ForwardComparator.prototype.compare = function compare (o1, o2) {
|
26856 | var pts1 = o1;
|
26857 | var pts2 = o2;
|
26858 | return CoordinateArrays.compare(pts1, pts2)
|
26859 | };
|
26860 | ForwardComparator.prototype.interfaces_ = function interfaces_ () {
|
26861 | return [Comparator]
|
26862 | };
|
26863 | ForwardComparator.prototype.getClass = function getClass () {
|
26864 | return ForwardComparator
|
26865 | };
|
26866 |
|
26867 | var BidirectionalComparator = function BidirectionalComparator () {};
|
26868 |
|
26869 | BidirectionalComparator.prototype.compare = function compare (o1, o2) {
|
26870 | var pts1 = o1;
|
26871 | var pts2 = o2;
|
26872 | if (pts1.length < pts2.length) { return -1 }
|
26873 | if (pts1.length > pts2.length) { return 1 }
|
26874 | if (pts1.length === 0) { return 0 }
|
26875 | var forwardComp = CoordinateArrays.compare(pts1, pts2);
|
26876 | var isEqualRev = CoordinateArrays.isEqualReversed(pts1, pts2);
|
26877 | if (isEqualRev) { return 0 }
|
26878 | return forwardComp
|
26879 | };
|
26880 | BidirectionalComparator.prototype.OLDcompare = function OLDcompare (o1, o2) {
|
26881 | var pts1 = o1;
|
26882 | var pts2 = o2;
|
26883 | if (pts1.length < pts2.length) { return -1 }
|
26884 | if (pts1.length > pts2.length) { return 1 }
|
26885 | if (pts1.length === 0) { return 0 }
|
26886 | var dir1 = CoordinateArrays.increasingDirection(pts1);
|
26887 | var dir2 = CoordinateArrays.increasingDirection(pts2);
|
26888 | var i1 = dir1 > 0 ? 0 : pts1.length - 1;
|
26889 | var i2 = dir2 > 0 ? 0 : pts1.length - 1;
|
26890 | for (var i = 0; i < pts1.length; i++) {
|
26891 | var comparePt = pts1[i1].compareTo(pts2[i2]);
|
26892 | if (comparePt !== 0) { return comparePt }
|
26893 | i1 += dir1;
|
26894 | i2 += dir2;
|
26895 | }
|
26896 | return 0
|
26897 | };
|
26898 | BidirectionalComparator.prototype.interfaces_ = function interfaces_ () {
|
26899 | return [Comparator]
|
26900 | };
|
26901 | BidirectionalComparator.prototype.getClass = function getClass () {
|
26902 | return BidirectionalComparator
|
26903 | };
|
26904 |
|
26905 |
|
26906 |
|
26907 |
|
26908 |
|
26909 |
|
26910 |
|
26911 | var Map$1 = function Map () {};
|
26912 |
|
26913 | Map$1.prototype.get = function get () {};
|
26914 |
|
26915 |
|
26916 |
|
26917 |
|
26918 |
|
26919 |
|
26920 |
|
26921 | Map$1.prototype.put = function put () {};
|
26922 |
|
26923 |
|
26924 |
|
26925 |
|
26926 |
|
26927 | Map$1.prototype.size = function size () {};
|
26928 |
|
26929 |
|
26930 |
|
26931 |
|
26932 |
|
26933 | Map$1.prototype.values = function values () {};
|
26934 |
|
26935 |
|
26936 |
|
26937 |
|
26938 |
|
26939 |
|
26940 |
|
26941 |
|
26942 |
|
26943 |
|
26944 |
|
26945 |
|
26946 |
|
26947 |
|
26948 |
|
26949 |
|
26950 |
|
26951 | Map$1.prototype.entrySet = function entrySet () {};
|
26952 |
|
26953 |
|
26954 |
|
26955 |
|
26956 |
|
26957 |
|
26958 |
|
26959 |
|
26960 | var SortedMap = (function (Map) {
|
26961 | function SortedMap () {
|
26962 | Map.apply(this, arguments);
|
26963 | }if ( Map ) SortedMap.__proto__ = Map;
|
26964 | SortedMap.prototype = Object.create( Map && Map.prototype );
|
26965 | SortedMap.prototype.constructor = SortedMap;
|
26966 |
|
26967 |
|
26968 |
|
26969 | return SortedMap;
|
26970 | }(Map$1));
|
26971 |
|
26972 |
|
26973 |
|
26974 |
|
26975 |
|
26976 |
|
26977 |
|
26978 | function OperationNotSupported (message) {
|
26979 | this.message = message || '';
|
26980 | }
|
26981 | OperationNotSupported.prototype = new Error();
|
26982 |
|
26983 |
|
26984 |
|
26985 |
|
26986 | OperationNotSupported.prototype.name = 'OperationNotSupported';
|
26987 |
|
26988 |
|
26989 |
|
26990 |
|
26991 |
|
26992 |
|
26993 |
|
26994 |
|
26995 | function Set() {}
|
26996 | Set.prototype = new Collection();
|
26997 |
|
26998 |
|
26999 |
|
27000 |
|
27001 |
|
27002 |
|
27003 |
|
27004 |
|
27005 |
|
27006 | Set.prototype.contains = function() {};
|
27007 |
|
27008 |
|
27009 |
|
27010 |
|
27011 |
|
27012 |
|
27013 |
|
27014 |
|
27015 | var HashSet = (function (Set$$1) {
|
27016 | function HashSet () {
|
27017 | Set$$1.call(this);
|
27018 | this.array_ = [];
|
27019 |
|
27020 | if (arguments[0] instanceof Collection) {
|
27021 | this.addAll(arguments[0]);
|
27022 | }
|
27023 | }
|
27024 |
|
27025 | if ( Set$$1 ) HashSet.__proto__ = Set$$1;
|
27026 | HashSet.prototype = Object.create( Set$$1 && Set$$1.prototype );
|
27027 | HashSet.prototype.constructor = HashSet;
|
27028 |
|
27029 | |
27030 |
|
27031 |
|
27032 | HashSet.prototype.contains = function contains (o) {
|
27033 | var this$1 = this;
|
27034 |
|
27035 | for (var i = 0, len = this.array_.length; i < len; i++) {
|
27036 | var e = this$1.array_[i];
|
27037 | if (e === o) {
|
27038 | return true
|
27039 | }
|
27040 | }
|
27041 | return false
|
27042 | };
|
27043 |
|
27044 | |
27045 |
|
27046 |
|
27047 | HashSet.prototype.add = function add (o) {
|
27048 | if (this.contains(o)) {
|
27049 | return false
|
27050 | }
|
27051 |
|
27052 | this.array_.push(o);
|
27053 |
|
27054 | return true
|
27055 | };
|
27056 |
|
27057 | |
27058 |
|
27059 |
|
27060 | HashSet.prototype.addAll = function addAll (c) {
|
27061 | var this$1 = this;
|
27062 |
|
27063 | for (var i = c.iterator(); i.hasNext();) {
|
27064 | this$1.add(i.next());
|
27065 | }
|
27066 | return true
|
27067 | };
|
27068 |
|
27069 | |
27070 |
|
27071 |
|
27072 | HashSet.prototype.remove = function remove (o) {
|
27073 |
|
27074 | throw new Error()
|
27075 | };
|
27076 |
|
27077 | |
27078 |
|
27079 |
|
27080 | HashSet.prototype.size = function size () {
|
27081 | return this.array_.length
|
27082 | };
|
27083 |
|
27084 | |
27085 |
|
27086 |
|
27087 | HashSet.prototype.isEmpty = function isEmpty () {
|
27088 | return this.array_.length === 0
|
27089 | };
|
27090 |
|
27091 | |
27092 |
|
27093 |
|
27094 | HashSet.prototype.toArray = function toArray () {
|
27095 | var this$1 = this;
|
27096 |
|
27097 | var array = [];
|
27098 |
|
27099 | for (var i = 0, len = this.array_.length; i < len; i++) {
|
27100 | array.push(this$1.array_[i]);
|
27101 | }
|
27102 |
|
27103 | return array
|
27104 | };
|
27105 |
|
27106 | |
27107 |
|
27108 |
|
27109 | HashSet.prototype.iterator = function iterator () {
|
27110 | return new Iterator_$1(this)
|
27111 | };
|
27112 |
|
27113 | return HashSet;
|
27114 | }(Set));
|
27115 |
|
27116 |
|
27117 |
|
27118 |
|
27119 |
|
27120 |
|
27121 |
|
27122 | var Iterator_$1 = (function (Iterator$$1) {
|
27123 | function Iterator_ (hashSet) {
|
27124 | Iterator$$1.call(this);
|
27125 | |
27126 |
|
27127 |
|
27128 |
|
27129 | this.hashSet_ = hashSet;
|
27130 | |
27131 |
|
27132 |
|
27133 |
|
27134 | this.position_ = 0;
|
27135 | }
|
27136 |
|
27137 | if ( Iterator$$1 ) Iterator_.__proto__ = Iterator$$1;
|
27138 | Iterator_.prototype = Object.create( Iterator$$1 && Iterator$$1.prototype );
|
27139 | Iterator_.prototype.constructor = Iterator_;
|
27140 |
|
27141 | |
27142 |
|
27143 |
|
27144 | Iterator_.prototype.next = function next () {
|
27145 | if (this.position_ === this.hashSet_.size()) {
|
27146 | throw new NoSuchElementException()
|
27147 | }
|
27148 | return this.hashSet_.array_[this.position_++]
|
27149 | };
|
27150 |
|
27151 | |
27152 |
|
27153 |
|
27154 | Iterator_.prototype.hasNext = function hasNext () {
|
27155 | if (this.position_ < this.hashSet_.size()) {
|
27156 | return true
|
27157 | } else {
|
27158 | return false
|
27159 | }
|
27160 | };
|
27161 |
|
27162 | |
27163 |
|
27164 |
|
27165 | Iterator_.prototype.remove = function remove () {
|
27166 | throw new OperationNotSupported()
|
27167 | };
|
27168 |
|
27169 | return Iterator_;
|
27170 | }(Iterator));
|
27171 |
|
27172 | var BLACK = 0;
|
27173 | var RED = 1;
|
27174 | function colorOf (p) { return (p === null ? BLACK : p.color) }
|
27175 | function parentOf (p) { return (p === null ? null : p.parent) }
|
27176 | function setColor (p, c) { if (p !== null) { p.color = c; } }
|
27177 | function leftOf (p) { return (p === null ? null : p.left) }
|
27178 | function rightOf (p) { return (p === null ? null : p.right) }
|
27179 |
|
27180 |
|
27181 |
|
27182 |
|
27183 |
|
27184 |
|
27185 |
|
27186 |
|
27187 | function TreeMap () {
|
27188 | |
27189 |
|
27190 |
|
27191 |
|
27192 | this.root_ = null;
|
27193 | |
27194 |
|
27195 |
|
27196 |
|
27197 | this.size_ = 0;
|
27198 | }
|
27199 | TreeMap.prototype = new SortedMap();
|
27200 |
|
27201 |
|
27202 |
|
27203 |
|
27204 | TreeMap.prototype.get = function (key) {
|
27205 | var p = this.root_;
|
27206 | while (p !== null) {
|
27207 | var cmp = key['compareTo'](p.key);
|
27208 | if (cmp < 0) { p = p.left; }
|
27209 | else if (cmp > 0) { p = p.right; }
|
27210 | else { return p.value }
|
27211 | }
|
27212 | return null
|
27213 | };
|
27214 |
|
27215 |
|
27216 |
|
27217 |
|
27218 | TreeMap.prototype.put = function (key, value) {
|
27219 | if (this.root_ === null) {
|
27220 | this.root_ = {
|
27221 | key: key,
|
27222 | value: value,
|
27223 | left: null,
|
27224 | right: null,
|
27225 | parent: null,
|
27226 | color: BLACK,
|
27227 | getValue: function getValue () { return this.value },
|
27228 | getKey: function getKey () { return this.key }
|
27229 | };
|
27230 | this.size_ = 1;
|
27231 | return null
|
27232 | }
|
27233 | var t = this.root_;
|
27234 | var parent;
|
27235 | var cmp;
|
27236 | do {
|
27237 | parent = t;
|
27238 | cmp = key['compareTo'](t.key);
|
27239 | if (cmp < 0) {
|
27240 | t = t.left;
|
27241 | } else if (cmp > 0) {
|
27242 | t = t.right;
|
27243 | } else {
|
27244 | var oldValue = t.value;
|
27245 | t.value = value;
|
27246 | return oldValue
|
27247 | }
|
27248 | } while (t !== null)
|
27249 | var e = {
|
27250 | key: key,
|
27251 | left: null,
|
27252 | right: null,
|
27253 | value: value,
|
27254 | parent: parent,
|
27255 | color: BLACK,
|
27256 | getValue: function getValue () { return this.value },
|
27257 | getKey: function getKey () { return this.key }
|
27258 | };
|
27259 | if (cmp < 0) {
|
27260 | parent.left = e;
|
27261 | } else {
|
27262 | parent.right = e;
|
27263 | }
|
27264 | this.fixAfterInsertion(e);
|
27265 | this.size_++;
|
27266 | return null
|
27267 | };
|
27268 |
|
27269 |
|
27270 |
|
27271 |
|
27272 | TreeMap.prototype.fixAfterInsertion = function (x) {
|
27273 | var this$1 = this;
|
27274 |
|
27275 | x.color = RED;
|
27276 | while (x != null && x !== this.root_ && x.parent.color === RED) {
|
27277 | if (parentOf(x) === leftOf(parentOf(parentOf(x)))) {
|
27278 | var y = rightOf(parentOf(parentOf(x)));
|
27279 | if (colorOf(y) === RED) {
|
27280 | setColor(parentOf(x), BLACK);
|
27281 | setColor(y, BLACK);
|
27282 | setColor(parentOf(parentOf(x)), RED);
|
27283 | x = parentOf(parentOf(x));
|
27284 | } else {
|
27285 | if (x === rightOf(parentOf(x))) {
|
27286 | x = parentOf(x);
|
27287 | this$1.rotateLeft(x);
|
27288 | }
|
27289 | setColor(parentOf(x), BLACK);
|
27290 | setColor(parentOf(parentOf(x)), RED);
|
27291 | this$1.rotateRight(parentOf(parentOf(x)));
|
27292 | }
|
27293 | } else {
|
27294 | var y$1 = leftOf(parentOf(parentOf(x)));
|
27295 | if (colorOf(y$1) === RED) {
|
27296 | setColor(parentOf(x), BLACK);
|
27297 | setColor(y$1, BLACK);
|
27298 | setColor(parentOf(parentOf(x)), RED);
|
27299 | x = parentOf(parentOf(x));
|
27300 | } else {
|
27301 | if (x === leftOf(parentOf(x))) {
|
27302 | x = parentOf(x);
|
27303 | this$1.rotateRight(x);
|
27304 | }
|
27305 | setColor(parentOf(x), BLACK);
|
27306 | setColor(parentOf(parentOf(x)), RED);
|
27307 | this$1.rotateLeft(parentOf(parentOf(x)));
|
27308 | }
|
27309 | }
|
27310 | }
|
27311 | this.root_.color = BLACK;
|
27312 | };
|
27313 |
|
27314 |
|
27315 |
|
27316 |
|
27317 | TreeMap.prototype.values = function () {
|
27318 | var arrayList = new ArrayList();
|
27319 | var p = this.getFirstEntry();
|
27320 | if (p !== null) {
|
27321 | arrayList.add(p.value);
|
27322 | while ((p = TreeMap.successor(p)) !== null) {
|
27323 | arrayList.add(p.value);
|
27324 | }
|
27325 | }
|
27326 | return arrayList
|
27327 | };
|
27328 |
|
27329 |
|
27330 |
|
27331 |
|
27332 | TreeMap.prototype.entrySet = function () {
|
27333 | var hashSet = new HashSet();
|
27334 | var p = this.getFirstEntry();
|
27335 | if (p !== null) {
|
27336 | hashSet.add(p);
|
27337 | while ((p = TreeMap.successor(p)) !== null) {
|
27338 | hashSet.add(p);
|
27339 | }
|
27340 | }
|
27341 | return hashSet
|
27342 | };
|
27343 |
|
27344 |
|
27345 |
|
27346 |
|
27347 | TreeMap.prototype.rotateLeft = function (p) {
|
27348 | if (p != null) {
|
27349 | var r = p.right;
|
27350 | p.right = r.left;
|
27351 | if (r.left != null) { r.left.parent = p; }
|
27352 | r.parent = p.parent;
|
27353 | if (p.parent === null) { this.root_ = r; } else if (p.parent.left === p) { p.parent.left = r; } else { p.parent.right = r; }
|
27354 | r.left = p;
|
27355 | p.parent = r;
|
27356 | }
|
27357 | };
|
27358 |
|
27359 |
|
27360 |
|
27361 |
|
27362 | TreeMap.prototype.rotateRight = function (p) {
|
27363 | if (p != null) {
|
27364 | var l = p.left;
|
27365 | p.left = l.right;
|
27366 | if (l.right != null) { l.right.parent = p; }
|
27367 | l.parent = p.parent;
|
27368 | if (p.parent === null) { this.root_ = l; } else if (p.parent.right === p) { p.parent.right = l; } else { p.parent.left = l; }
|
27369 | l.right = p;
|
27370 | p.parent = l;
|
27371 | }
|
27372 | };
|
27373 |
|
27374 |
|
27375 |
|
27376 |
|
27377 | TreeMap.prototype.getFirstEntry = function () {
|
27378 | var p = this.root_;
|
27379 | if (p != null) {
|
27380 | while (p.left != null) {
|
27381 | p = p.left;
|
27382 | }
|
27383 | }
|
27384 | return p
|
27385 | };
|
27386 |
|
27387 |
|
27388 |
|
27389 |
|
27390 |
|
27391 |
|
27392 | TreeMap.successor = function (t) {
|
27393 | if (t === null) { return null } else if (t.right !== null) {
|
27394 | var p = t.right;
|
27395 | while (p.left !== null) {
|
27396 | p = p.left;
|
27397 | }
|
27398 | return p
|
27399 | } else {
|
27400 | var p$1 = t.parent;
|
27401 | var ch = t;
|
27402 | while (p$1 !== null && ch === p$1.right) {
|
27403 | ch = p$1;
|
27404 | p$1 = p$1.parent;
|
27405 | }
|
27406 | return p$1
|
27407 | }
|
27408 | };
|
27409 |
|
27410 |
|
27411 |
|
27412 |
|
27413 | TreeMap.prototype.size = function () {
|
27414 | return this.size_
|
27415 | };
|
27416 |
|
27417 | var Lineal = function Lineal () {};
|
27418 |
|
27419 | Lineal.prototype.interfaces_ = function interfaces_ () {
|
27420 | return []
|
27421 | };
|
27422 | Lineal.prototype.getClass = function getClass () {
|
27423 | return Lineal
|
27424 | };
|
27425 |
|
27426 |
|
27427 |
|
27428 |
|
27429 |
|
27430 |
|
27431 |
|
27432 |
|
27433 | function SortedSet () {}
|
27434 | SortedSet.prototype = new Set();
|
27435 |
|
27436 |
|
27437 |
|
27438 |
|
27439 |
|
27440 |
|
27441 |
|
27442 |
|
27443 |
|
27444 | function TreeSet () {
|
27445 | |
27446 |
|
27447 |
|
27448 |
|
27449 | this.array_ = [];
|
27450 |
|
27451 | if (arguments[0] instanceof Collection) {
|
27452 | this.addAll(arguments[0]);
|
27453 | }
|
27454 | }
|
27455 | TreeSet.prototype = new SortedSet();
|
27456 |
|
27457 |
|
27458 |
|
27459 |
|
27460 | TreeSet.prototype.contains = function (o) {
|
27461 | var this$1 = this;
|
27462 |
|
27463 | for (var i = 0, len = this.array_.length; i < len; i++) {
|
27464 | var e = this$1.array_[i];
|
27465 | if (e['compareTo'](o) === 0) {
|
27466 | return true
|
27467 | }
|
27468 | }
|
27469 | return false
|
27470 | };
|
27471 |
|
27472 |
|
27473 |
|
27474 |
|
27475 | TreeSet.prototype.add = function (o) {
|
27476 | var this$1 = this;
|
27477 |
|
27478 | if (this.contains(o)) {
|
27479 | return false
|
27480 | }
|
27481 |
|
27482 | for (var i = 0, len = this.array_.length; i < len; i++) {
|
27483 | var e = this$1.array_[i];
|
27484 | if (e['compareTo'](o) === 1) {
|
27485 | this$1.array_.splice(i, 0, o);
|
27486 | return true
|
27487 | }
|
27488 | }
|
27489 |
|
27490 | this.array_.push(o);
|
27491 |
|
27492 | return true
|
27493 | };
|
27494 |
|
27495 |
|
27496 |
|
27497 |
|
27498 | TreeSet.prototype.addAll = function (c) {
|
27499 | var this$1 = this;
|
27500 |
|
27501 | for (var i = c.iterator(); i.hasNext();) {
|
27502 | this$1.add(i.next());
|
27503 | }
|
27504 | return true
|
27505 | };
|
27506 |
|
27507 |
|
27508 |
|
27509 |
|
27510 | TreeSet.prototype.remove = function (e) {
|
27511 | throw new OperationNotSupported()
|
27512 | };
|
27513 |
|
27514 |
|
27515 |
|
27516 |
|
27517 | TreeSet.prototype.size = function () {
|
27518 | return this.array_.length
|
27519 | };
|
27520 |
|
27521 |
|
27522 |
|
27523 |
|
27524 | TreeSet.prototype.isEmpty = function () {
|
27525 | return this.array_.length === 0
|
27526 | };
|
27527 |
|
27528 |
|
27529 |
|
27530 |
|
27531 | TreeSet.prototype.toArray = function () {
|
27532 | var this$1 = this;
|
27533 |
|
27534 | var array = [];
|
27535 |
|
27536 | for (var i = 0, len = this.array_.length; i < len; i++) {
|
27537 | array.push(this$1.array_[i]);
|
27538 | }
|
27539 |
|
27540 | return array
|
27541 | };
|
27542 |
|
27543 |
|
27544 |
|
27545 |
|
27546 | TreeSet.prototype.iterator = function () {
|
27547 | return new Iterator_$2(this)
|
27548 | };
|
27549 |
|
27550 |
|
27551 |
|
27552 |
|
27553 |
|
27554 |
|
27555 |
|
27556 | var Iterator_$2 = function (treeSet) {
|
27557 | |
27558 |
|
27559 |
|
27560 |
|
27561 | this.treeSet_ = treeSet;
|
27562 | |
27563 |
|
27564 |
|
27565 |
|
27566 | this.position_ = 0;
|
27567 | };
|
27568 |
|
27569 |
|
27570 |
|
27571 |
|
27572 | Iterator_$2.prototype.next = function () {
|
27573 | if (this.position_ === this.treeSet_.size()) {
|
27574 | throw new NoSuchElementException()
|
27575 | }
|
27576 | return this.treeSet_.array_[this.position_++]
|
27577 | };
|
27578 |
|
27579 |
|
27580 |
|
27581 |
|
27582 | Iterator_$2.prototype.hasNext = function () {
|
27583 | if (this.position_ < this.treeSet_.size()) {
|
27584 | return true
|
27585 | } else {
|
27586 | return false
|
27587 | }
|
27588 | };
|
27589 |
|
27590 |
|
27591 |
|
27592 |
|
27593 | Iterator_$2.prototype.remove = function () {
|
27594 | throw new OperationNotSupported()
|
27595 | };
|
27596 |
|
27597 |
|
27598 |
|
27599 |
|
27600 |
|
27601 |
|
27602 |
|
27603 | var Arrays = function Arrays () {};
|
27604 |
|
27605 | Arrays.sort = function sort () {
|
27606 | var a = arguments[0];
|
27607 | var i;
|
27608 | var t;
|
27609 | var comparator;
|
27610 | var compare;
|
27611 | if (arguments.length === 1) {
|
27612 | compare = function (a, b) {
|
27613 | return a.compareTo(b)
|
27614 | };
|
27615 | a.sort(compare);
|
27616 | } else if (arguments.length === 2) {
|
27617 | comparator = arguments[1];
|
27618 | compare = function (a, b) {
|
27619 | return comparator['compare'](a, b)
|
27620 | };
|
27621 | a.sort(compare);
|
27622 | } else if (arguments.length === 3) {
|
27623 | t = a.slice(arguments[1], arguments[2]);
|
27624 | t.sort();
|
27625 | var r = a.slice(0, arguments[1]).concat(t, a.slice(arguments[2], a.length));
|
27626 | a.splice(0, a.length);
|
27627 | for (i = 0; i < r.length; i++) {
|
27628 | a.push(r[i]);
|
27629 | }
|
27630 | } else if (arguments.length === 4) {
|
27631 | t = a.slice(arguments[1], arguments[2]);
|
27632 | comparator = arguments[3];
|
27633 | compare = function (a, b) {
|
27634 | return comparator['compare'](a, b)
|
27635 | };
|
27636 | t.sort(compare);
|
27637 | r = a.slice(0, arguments[1]).concat(t, a.slice(arguments[2], a.length));
|
27638 | a.splice(0, a.length);
|
27639 | for (i = 0; i < r.length; i++) {
|
27640 | a.push(r[i]);
|
27641 | }
|
27642 | }
|
27643 | };
|
27644 |
|
27645 |
|
27646 |
|
27647 |
|
27648 | Arrays.asList = function asList (array) {
|
27649 | var arrayList = new ArrayList();
|
27650 | for (var i = 0, len = array.length; i < len; i++) {
|
27651 | arrayList.add(array[i]);
|
27652 | }
|
27653 | return arrayList
|
27654 | };
|
27655 |
|
27656 | var Dimension = function Dimension () {};
|
27657 |
|
27658 | var staticAccessors$14 = { P: { configurable: true },L: { configurable: true },A: { configurable: true },FALSE: { configurable: true },TRUE: { configurable: true },DONTCARE: { configurable: true },SYM_FALSE: { configurable: true },SYM_TRUE: { configurable: true },SYM_DONTCARE: { configurable: true },SYM_P: { configurable: true },SYM_L: { configurable: true },SYM_A: { configurable: true } };
|
27659 |
|
27660 | staticAccessors$14.P.get = function () { return 0 };
|
27661 | staticAccessors$14.L.get = function () { return 1 };
|
27662 | staticAccessors$14.A.get = function () { return 2 };
|
27663 | staticAccessors$14.FALSE.get = function () { return -1 };
|
27664 | staticAccessors$14.TRUE.get = function () { return -2 };
|
27665 | staticAccessors$14.DONTCARE.get = function () { return -3 };
|
27666 | staticAccessors$14.SYM_FALSE.get = function () { return 'F' };
|
27667 | staticAccessors$14.SYM_TRUE.get = function () { return 'T' };
|
27668 | staticAccessors$14.SYM_DONTCARE.get = function () { return '*' };
|
27669 | staticAccessors$14.SYM_P.get = function () { return '0' };
|
27670 | staticAccessors$14.SYM_L.get = function () { return '1' };
|
27671 | staticAccessors$14.SYM_A.get = function () { return '2' };
|
27672 |
|
27673 | Dimension.prototype.interfaces_ = function interfaces_ () {
|
27674 | return []
|
27675 | };
|
27676 | Dimension.prototype.getClass = function getClass () {
|
27677 | return Dimension
|
27678 | };
|
27679 | Dimension.toDimensionSymbol = function toDimensionSymbol (dimensionValue) {
|
27680 | switch (dimensionValue) {
|
27681 | case Dimension.FALSE:
|
27682 | return Dimension.SYM_FALSE
|
27683 | case Dimension.TRUE:
|
27684 | return Dimension.SYM_TRUE
|
27685 | case Dimension.DONTCARE:
|
27686 | return Dimension.SYM_DONTCARE
|
27687 | case Dimension.P:
|
27688 | return Dimension.SYM_P
|
27689 | case Dimension.L:
|
27690 | return Dimension.SYM_L
|
27691 | case Dimension.A:
|
27692 | return Dimension.SYM_A
|
27693 | default:
|
27694 | }
|
27695 | throw new IllegalArgumentException('Unknown dimension value: ' + dimensionValue)
|
27696 | };
|
27697 | Dimension.toDimensionValue = function toDimensionValue (dimensionSymbol) {
|
27698 | switch (Character.toUpperCase(dimensionSymbol)) {
|
27699 | case Dimension.SYM_FALSE:
|
27700 | return Dimension.FALSE
|
27701 | case Dimension.SYM_TRUE:
|
27702 | return Dimension.TRUE
|
27703 | case Dimension.SYM_DONTCARE:
|
27704 | return Dimension.DONTCARE
|
27705 | case Dimension.SYM_P:
|
27706 | return Dimension.P
|
27707 | case Dimension.SYM_L:
|
27708 | return Dimension.L
|
27709 | case Dimension.SYM_A:
|
27710 | return Dimension.A
|
27711 | default:
|
27712 | }
|
27713 | throw new IllegalArgumentException('Unknown dimension symbol: ' + dimensionSymbol)
|
27714 | };
|
27715 |
|
27716 | Object.defineProperties( Dimension, staticAccessors$14 );
|
27717 |
|
27718 | var GeometryFilter = function GeometryFilter () {};
|
27719 |
|
27720 | GeometryFilter.prototype.filter = function filter (geom) {};
|
27721 | GeometryFilter.prototype.interfaces_ = function interfaces_ () {
|
27722 | return []
|
27723 | };
|
27724 | GeometryFilter.prototype.getClass = function getClass () {
|
27725 | return GeometryFilter
|
27726 | };
|
27727 |
|
27728 | var CoordinateSequenceFilter = function CoordinateSequenceFilter () {};
|
27729 |
|
27730 | CoordinateSequenceFilter.prototype.filter = function filter (seq, i) {};
|
27731 | CoordinateSequenceFilter.prototype.isDone = function isDone () {};
|
27732 | CoordinateSequenceFilter.prototype.isGeometryChanged = function isGeometryChanged () {};
|
27733 | CoordinateSequenceFilter.prototype.interfaces_ = function interfaces_ () {
|
27734 | return []
|
27735 | };
|
27736 | CoordinateSequenceFilter.prototype.getClass = function getClass () {
|
27737 | return CoordinateSequenceFilter
|
27738 | };
|
27739 |
|
27740 | var GeometryCollection = (function (Geometry$$1) {
|
27741 | function GeometryCollection (geometries, factory) {
|
27742 | Geometry$$1.call(this, factory);
|
27743 | this._geometries = geometries || [];
|
27744 |
|
27745 | if (Geometry$$1.hasNullElements(this._geometries)) {
|
27746 | throw new IllegalArgumentException('geometries must not contain null elements')
|
27747 | }
|
27748 | }
|
27749 |
|
27750 | if ( Geometry$$1 ) GeometryCollection.__proto__ = Geometry$$1;
|
27751 | GeometryCollection.prototype = Object.create( Geometry$$1 && Geometry$$1.prototype );
|
27752 | GeometryCollection.prototype.constructor = GeometryCollection;
|
27753 |
|
27754 | var staticAccessors = { serialVersionUID: { configurable: true } };
|
27755 | GeometryCollection.prototype.computeEnvelopeInternal = function computeEnvelopeInternal () {
|
27756 | var this$1 = this;
|
27757 |
|
27758 | var envelope = new Envelope();
|
27759 | for (var i = 0; i < this._geometries.length; i++) {
|
27760 | envelope.expandToInclude(this$1._geometries[i].getEnvelopeInternal());
|
27761 | }
|
27762 | return envelope
|
27763 | };
|
27764 | GeometryCollection.prototype.getGeometryN = function getGeometryN (n) {
|
27765 | return this._geometries[n]
|
27766 | };
|
27767 | GeometryCollection.prototype.getSortIndex = function getSortIndex () {
|
27768 | return Geometry$$1.SORTINDEX_GEOMETRYCOLLECTION
|
27769 | };
|
27770 | GeometryCollection.prototype.getCoordinates = function getCoordinates () {
|
27771 | var this$1 = this;
|
27772 |
|
27773 | var coordinates = new Array(this.getNumPoints()).fill(null);
|
27774 | var k = -1;
|
27775 | for (var i = 0; i < this._geometries.length; i++) {
|
27776 | var childCoordinates = this$1._geometries[i].getCoordinates();
|
27777 | for (var j = 0; j < childCoordinates.length; j++) {
|
27778 | k++;
|
27779 | coordinates[k] = childCoordinates[j];
|
27780 | }
|
27781 | }
|
27782 | return coordinates
|
27783 | };
|
27784 | GeometryCollection.prototype.getArea = function getArea () {
|
27785 | var this$1 = this;
|
27786 |
|
27787 | var area = 0.0;
|
27788 | for (var i = 0; i < this._geometries.length; i++) {
|
27789 | area += this$1._geometries[i].getArea();
|
27790 | }
|
27791 | return area
|
27792 | };
|
27793 | GeometryCollection.prototype.equalsExact = function equalsExact () {
|
27794 | var this$1 = this;
|
27795 |
|
27796 | if (arguments.length === 2) {
|
27797 | var other = arguments[0];
|
27798 | var tolerance = arguments[1];
|
27799 | if (!this.isEquivalentClass(other)) {
|
27800 | return false
|
27801 | }
|
27802 | var otherCollection = other;
|
27803 | if (this._geometries.length !== otherCollection._geometries.length) {
|
27804 | return false
|
27805 | }
|
27806 | for (var i = 0; i < this._geometries.length; i++) {
|
27807 | if (!this$1._geometries[i].equalsExact(otherCollection._geometries[i], tolerance)) {
|
27808 | return false
|
27809 | }
|
27810 | }
|
27811 | return true
|
27812 | } else { return Geometry$$1.prototype.equalsExact.apply(this, arguments) }
|
27813 | };
|
27814 | GeometryCollection.prototype.normalize = function normalize () {
|
27815 | var this$1 = this;
|
27816 |
|
27817 | for (var i = 0; i < this._geometries.length; i++) {
|
27818 | this$1._geometries[i].normalize();
|
27819 | }
|
27820 | Arrays.sort(this._geometries);
|
27821 | };
|
27822 | GeometryCollection.prototype.getCoordinate = function getCoordinate () {
|
27823 | if (this.isEmpty()) { return null }
|
27824 | return this._geometries[0].getCoordinate()
|
27825 | };
|
27826 | GeometryCollection.prototype.getBoundaryDimension = function getBoundaryDimension () {
|
27827 | var this$1 = this;
|
27828 |
|
27829 | var dimension = Dimension.FALSE;
|
27830 | for (var i = 0; i < this._geometries.length; i++) {
|
27831 | dimension = Math.max(dimension, this$1._geometries[i].getBoundaryDimension());
|
27832 | }
|
27833 | return dimension
|
27834 | };
|
27835 | GeometryCollection.prototype.getDimension = function getDimension () {
|
27836 | var this$1 = this;
|
27837 |
|
27838 | var dimension = Dimension.FALSE;
|
27839 | for (var i = 0; i < this._geometries.length; i++) {
|
27840 | dimension = Math.max(dimension, this$1._geometries[i].getDimension());
|
27841 | }
|
27842 | return dimension
|
27843 | };
|
27844 | GeometryCollection.prototype.getLength = function getLength () {
|
27845 | var this$1 = this;
|
27846 |
|
27847 | var sum = 0.0;
|
27848 | for (var i = 0; i < this._geometries.length; i++) {
|
27849 | sum += this$1._geometries[i].getLength();
|
27850 | }
|
27851 | return sum
|
27852 | };
|
27853 | GeometryCollection.prototype.getNumPoints = function getNumPoints () {
|
27854 | var this$1 = this;
|
27855 |
|
27856 | var numPoints = 0;
|
27857 | for (var i = 0; i < this._geometries.length; i++) {
|
27858 | numPoints += this$1._geometries[i].getNumPoints();
|
27859 | }
|
27860 | return numPoints
|
27861 | };
|
27862 | GeometryCollection.prototype.getNumGeometries = function getNumGeometries () {
|
27863 | return this._geometries.length
|
27864 | };
|
27865 | GeometryCollection.prototype.reverse = function reverse () {
|
27866 | var this$1 = this;
|
27867 |
|
27868 | var n = this._geometries.length;
|
27869 | var revGeoms = new Array(n).fill(null);
|
27870 | for (var i = 0; i < this._geometries.length; i++) {
|
27871 | revGeoms[i] = this$1._geometries[i].reverse();
|
27872 | }
|
27873 | return this.getFactory().createGeometryCollection(revGeoms)
|
27874 | };
|
27875 | GeometryCollection.prototype.compareToSameClass = function compareToSameClass () {
|
27876 | var this$1 = this;
|
27877 |
|
27878 | if (arguments.length === 1) {
|
27879 | var o = arguments[0];
|
27880 | var theseElements = new TreeSet(Arrays.asList(this._geometries));
|
27881 | var otherElements = new TreeSet(Arrays.asList(o._geometries));
|
27882 | return this.compare(theseElements, otherElements)
|
27883 | } else if (arguments.length === 2) {
|
27884 | var o$1 = arguments[0];
|
27885 | var comp = arguments[1];
|
27886 | var gc = o$1;
|
27887 | var n1 = this.getNumGeometries();
|
27888 | var n2 = gc.getNumGeometries();
|
27889 | var i = 0;
|
27890 | while (i < n1 && i < n2) {
|
27891 | var thisGeom = this$1.getGeometryN(i);
|
27892 | var otherGeom = gc.getGeometryN(i);
|
27893 | var holeComp = thisGeom.compareToSameClass(otherGeom, comp);
|
27894 | if (holeComp !== 0) { return holeComp }
|
27895 | i++;
|
27896 | }
|
27897 | if (i < n1) { return 1 }
|
27898 | if (i < n2) { return -1 }
|
27899 | return 0
|
27900 | }
|
27901 | };
|
27902 | GeometryCollection.prototype.apply = function apply () {
|
27903 | var this$1 = this;
|
27904 |
|
27905 | if (hasInterface(arguments[0], CoordinateFilter)) {
|
27906 | var filter = arguments[0];
|
27907 | for (var i = 0; i < this._geometries.length; i++) {
|
27908 | this$1._geometries[i].apply(filter);
|
27909 | }
|
27910 | } else if (hasInterface(arguments[0], CoordinateSequenceFilter)) {
|
27911 | var filter$1 = arguments[0];
|
27912 | if (this._geometries.length === 0) { return null }
|
27913 | for (var i$1 = 0; i$1 < this._geometries.length; i$1++) {
|
27914 | this$1._geometries[i$1].apply(filter$1);
|
27915 | if (filter$1.isDone()) {
|
27916 | break
|
27917 | }
|
27918 | }
|
27919 | if (filter$1.isGeometryChanged()) { this.geometryChanged(); }
|
27920 | } else if (hasInterface(arguments[0], GeometryFilter)) {
|
27921 | var filter$2 = arguments[0];
|
27922 | filter$2.filter(this);
|
27923 | for (var i$2 = 0; i$2 < this._geometries.length; i$2++) {
|
27924 | this$1._geometries[i$2].apply(filter$2);
|
27925 | }
|
27926 | } else if (hasInterface(arguments[0], GeometryComponentFilter)) {
|
27927 | var filter$3 = arguments[0];
|
27928 | filter$3.filter(this);
|
27929 | for (var i$3 = 0; i$3 < this._geometries.length; i$3++) {
|
27930 | this$1._geometries[i$3].apply(filter$3);
|
27931 | }
|
27932 | }
|
27933 | };
|
27934 | GeometryCollection.prototype.getBoundary = function getBoundary () {
|
27935 | this.checkNotGeometryCollection(this);
|
27936 | Assert.shouldNeverReachHere();
|
27937 | return null
|
27938 | };
|
27939 | GeometryCollection.prototype.clone = function clone () {
|
27940 | var this$1 = this;
|
27941 |
|
27942 | var gc = Geometry$$1.prototype.clone.call(this);
|
27943 | gc._geometries = new Array(this._geometries.length).fill(null);
|
27944 | for (var i = 0; i < this._geometries.length; i++) {
|
27945 | gc._geometries[i] = this$1._geometries[i].clone();
|
27946 | }
|
27947 | return gc
|
27948 | };
|
27949 | GeometryCollection.prototype.getGeometryType = function getGeometryType () {
|
27950 | return 'GeometryCollection'
|
27951 | };
|
27952 | GeometryCollection.prototype.copy = function copy () {
|
27953 | var this$1 = this;
|
27954 |
|
27955 | var geometries = new Array(this._geometries.length).fill(null);
|
27956 | for (var i = 0; i < geometries.length; i++) {
|
27957 | geometries[i] = this$1._geometries[i].copy();
|
27958 | }
|
27959 | return new GeometryCollection(geometries, this._factory)
|
27960 | };
|
27961 | GeometryCollection.prototype.isEmpty = function isEmpty () {
|
27962 | var this$1 = this;
|
27963 |
|
27964 | for (var i = 0; i < this._geometries.length; i++) {
|
27965 | if (!this$1._geometries[i].isEmpty()) {
|
27966 | return false
|
27967 | }
|
27968 | }
|
27969 | return true
|
27970 | };
|
27971 | GeometryCollection.prototype.interfaces_ = function interfaces_ () {
|
27972 | return []
|
27973 | };
|
27974 | GeometryCollection.prototype.getClass = function getClass () {
|
27975 | return GeometryCollection
|
27976 | };
|
27977 | staticAccessors.serialVersionUID.get = function () { return -5694727726395021467 };
|
27978 |
|
27979 | Object.defineProperties( GeometryCollection, staticAccessors );
|
27980 |
|
27981 | return GeometryCollection;
|
27982 | }(Geometry));
|
27983 |
|
27984 | var MultiLineString = (function (GeometryCollection$$1) {
|
27985 | function MultiLineString () {
|
27986 | GeometryCollection$$1.apply(this, arguments);
|
27987 | }
|
27988 |
|
27989 | if ( GeometryCollection$$1 ) MultiLineString.__proto__ = GeometryCollection$$1;
|
27990 | MultiLineString.prototype = Object.create( GeometryCollection$$1 && GeometryCollection$$1.prototype );
|
27991 | MultiLineString.prototype.constructor = MultiLineString;
|
27992 |
|
27993 | var staticAccessors = { serialVersionUID: { configurable: true } };
|
27994 |
|
27995 | MultiLineString.prototype.getSortIndex = function getSortIndex () {
|
27996 | return Geometry.SORTINDEX_MULTILINESTRING
|
27997 | };
|
27998 | MultiLineString.prototype.equalsExact = function equalsExact () {
|
27999 | if (arguments.length === 2) {
|
28000 | var other = arguments[0];
|
28001 | var tolerance = arguments[1];
|
28002 | if (!this.isEquivalentClass(other)) {
|
28003 | return false
|
28004 | }
|
28005 | return GeometryCollection$$1.prototype.equalsExact.call(this, other, tolerance)
|
28006 | } else { return GeometryCollection$$1.prototype.equalsExact.apply(this, arguments) }
|
28007 | };
|
28008 | MultiLineString.prototype.getBoundaryDimension = function getBoundaryDimension () {
|
28009 | if (this.isClosed()) {
|
28010 | return Dimension.FALSE
|
28011 | }
|
28012 | return 0
|
28013 | };
|
28014 | MultiLineString.prototype.isClosed = function isClosed () {
|
28015 | var this$1 = this;
|
28016 |
|
28017 | if (this.isEmpty()) {
|
28018 | return false
|
28019 | }
|
28020 | for (var i = 0; i < this._geometries.length; i++) {
|
28021 | if (!this$1._geometries[i].isClosed()) {
|
28022 | return false
|
28023 | }
|
28024 | }
|
28025 | return true
|
28026 | };
|
28027 | MultiLineString.prototype.getDimension = function getDimension () {
|
28028 | return 1
|
28029 | };
|
28030 | MultiLineString.prototype.reverse = function reverse () {
|
28031 | var this$1 = this;
|
28032 |
|
28033 | var nLines = this._geometries.length;
|
28034 | var revLines = new Array(nLines).fill(null);
|
28035 | for (var i = 0; i < this._geometries.length; i++) {
|
28036 | revLines[nLines - 1 - i] = this$1._geometries[i].reverse();
|
28037 | }
|
28038 | return this.getFactory().createMultiLineString(revLines)
|
28039 | };
|
28040 | MultiLineString.prototype.getBoundary = function getBoundary () {
|
28041 | return new BoundaryOp(this).getBoundary()
|
28042 | };
|
28043 | MultiLineString.prototype.getGeometryType = function getGeometryType () {
|
28044 | return 'MultiLineString'
|
28045 | };
|
28046 | MultiLineString.prototype.copy = function copy () {
|
28047 | var this$1 = this;
|
28048 |
|
28049 | var lineStrings = new Array(this._geometries.length).fill(null);
|
28050 | for (var i = 0; i < lineStrings.length; i++) {
|
28051 | lineStrings[i] = this$1._geometries[i].copy();
|
28052 | }
|
28053 | return new MultiLineString(lineStrings, this._factory)
|
28054 | };
|
28055 | MultiLineString.prototype.interfaces_ = function interfaces_ () {
|
28056 | return [Lineal]
|
28057 | };
|
28058 | MultiLineString.prototype.getClass = function getClass () {
|
28059 | return MultiLineString
|
28060 | };
|
28061 | staticAccessors.serialVersionUID.get = function () { return 8166665132445433741 };
|
28062 |
|
28063 | Object.defineProperties( MultiLineString, staticAccessors );
|
28064 |
|
28065 | return MultiLineString;
|
28066 | }(GeometryCollection));
|
28067 |
|
28068 | var BoundaryOp = function BoundaryOp () {
|
28069 | this._geom = null;
|
28070 | this._geomFact = null;
|
28071 | this._bnRule = null;
|
28072 | this._endpointMap = null;
|
28073 | if (arguments.length === 1) {
|
28074 | var geom = arguments[0];
|
28075 | var bnRule = BoundaryNodeRule.MOD2_BOUNDARY_RULE;
|
28076 | this._geom = geom;
|
28077 | this._geomFact = geom.getFactory();
|
28078 | this._bnRule = bnRule;
|
28079 | } else if (arguments.length === 2) {
|
28080 | var geom$1 = arguments[0];
|
28081 | var bnRule$1 = arguments[1];
|
28082 | this._geom = geom$1;
|
28083 | this._geomFact = geom$1.getFactory();
|
28084 | this._bnRule = bnRule$1;
|
28085 | }
|
28086 | };
|
28087 | BoundaryOp.prototype.boundaryMultiLineString = function boundaryMultiLineString (mLine) {
|
28088 | if (this._geom.isEmpty()) {
|
28089 | return this.getEmptyMultiPoint()
|
28090 | }
|
28091 | var bdyPts = this.computeBoundaryCoordinates(mLine);
|
28092 | if (bdyPts.length === 1) {
|
28093 | return this._geomFact.createPoint(bdyPts[0])
|
28094 | }
|
28095 | return this._geomFact.createMultiPointFromCoords(bdyPts)
|
28096 | };
|
28097 | BoundaryOp.prototype.getBoundary = function getBoundary () {
|
28098 | if (this._geom instanceof LineString$1) { return this.boundaryLineString(this._geom) }
|
28099 | if (this._geom instanceof MultiLineString) { return this.boundaryMultiLineString(this._geom) }
|
28100 | return this._geom.getBoundary()
|
28101 | };
|
28102 | BoundaryOp.prototype.boundaryLineString = function boundaryLineString (line) {
|
28103 | if (this._geom.isEmpty()) {
|
28104 | return this.getEmptyMultiPoint()
|
28105 | }
|
28106 | if (line.isClosed()) {
|
28107 | var closedEndpointOnBoundary = this._bnRule.isInBoundary(2);
|
28108 | if (closedEndpointOnBoundary) {
|
28109 | return line.getStartPoint()
|
28110 | } else {
|
28111 | return this._geomFact.createMultiPoint()
|
28112 | }
|
28113 | }
|
28114 | return this._geomFact.createMultiPoint([line.getStartPoint(), line.getEndPoint()])
|
28115 | };
|
28116 | BoundaryOp.prototype.getEmptyMultiPoint = function getEmptyMultiPoint () {
|
28117 | return this._geomFact.createMultiPoint()
|
28118 | };
|
28119 | BoundaryOp.prototype.computeBoundaryCoordinates = function computeBoundaryCoordinates (mLine) {
|
28120 | var this$1 = this;
|
28121 |
|
28122 | var bdyPts = new ArrayList();
|
28123 | this._endpointMap = new TreeMap();
|
28124 | for (var i = 0; i < mLine.getNumGeometries(); i++) {
|
28125 | var line = mLine.getGeometryN(i);
|
28126 | if (line.getNumPoints() === 0) { continue }
|
28127 | this$1.addEndpoint(line.getCoordinateN(0));
|
28128 | this$1.addEndpoint(line.getCoordinateN(line.getNumPoints() - 1));
|
28129 | }
|
28130 | for (var it = this._endpointMap.entrySet().iterator(); it.hasNext();) {
|
28131 | var entry = it.next();
|
28132 | var counter = entry.getValue();
|
28133 | var valence = counter.count;
|
28134 | if (this$1._bnRule.isInBoundary(valence)) {
|
28135 | bdyPts.add(entry.getKey());
|
28136 | }
|
28137 | }
|
28138 | return CoordinateArrays.toCoordinateArray(bdyPts)
|
28139 | };
|
28140 | BoundaryOp.prototype.addEndpoint = function addEndpoint (pt) {
|
28141 | var counter = this._endpointMap.get(pt);
|
28142 | if (counter === null) {
|
28143 | counter = new Counter();
|
28144 | this._endpointMap.put(pt, counter);
|
28145 | }
|
28146 | counter.count++;
|
28147 | };
|
28148 | BoundaryOp.prototype.interfaces_ = function interfaces_ () {
|
28149 | return []
|
28150 | };
|
28151 | BoundaryOp.prototype.getClass = function getClass () {
|
28152 | return BoundaryOp
|
28153 | };
|
28154 | BoundaryOp.getBoundary = function getBoundary () {
|
28155 | if (arguments.length === 1) {
|
28156 | var g = arguments[0];
|
28157 | var bop = new BoundaryOp(g);
|
28158 | return bop.getBoundary()
|
28159 | } else if (arguments.length === 2) {
|
28160 | var g$1 = arguments[0];
|
28161 | var bnRule = arguments[1];
|
28162 | var bop$1 = new BoundaryOp(g$1, bnRule);
|
28163 | return bop$1.getBoundary()
|
28164 | }
|
28165 | };
|
28166 |
|
28167 | var Counter = function Counter () {
|
28168 | this.count = null;
|
28169 | };
|
28170 | Counter.prototype.interfaces_ = function interfaces_ () {
|
28171 | return []
|
28172 | };
|
28173 | Counter.prototype.getClass = function getClass () {
|
28174 | return Counter
|
28175 | };
|
28176 |
|
28177 |
|
28178 |
|
28179 | function PrintStream () {}
|
28180 |
|
28181 | function StringReader () {}
|
28182 |
|
28183 | var DecimalFormat = function DecimalFormat () {};
|
28184 |
|
28185 | function ByteArrayOutputStream () {}
|
28186 |
|
28187 | function IOException () {}
|
28188 |
|
28189 | function LineNumberReader () {}
|
28190 |
|
28191 | var StringUtil = function StringUtil () {};
|
28192 |
|
28193 | var staticAccessors$15 = { NEWLINE: { configurable: true },SIMPLE_ORDINATE_FORMAT: { configurable: true } };
|
28194 |
|
28195 | StringUtil.prototype.interfaces_ = function interfaces_ () {
|
28196 | return []
|
28197 | };
|
28198 | StringUtil.prototype.getClass = function getClass () {
|
28199 | return StringUtil
|
28200 | };
|
28201 | StringUtil.chars = function chars (c, n) {
|
28202 | var ch = new Array(n).fill(null);
|
28203 | for (var i = 0; i < n; i++) {
|
28204 | ch[i] = c;
|
28205 | }
|
28206 | return String(ch)
|
28207 | };
|
28208 | StringUtil.getStackTrace = function getStackTrace () {
|
28209 | if (arguments.length === 1) {
|
28210 | var t = arguments[0];
|
28211 | var os = new ByteArrayOutputStream();
|
28212 | var ps = new PrintStream(os);
|
28213 | t.printStackTrace(ps);
|
28214 | return os.toString()
|
28215 | } else if (arguments.length === 2) {
|
28216 | var t$1 = arguments[0];
|
28217 | var depth = arguments[1];
|
28218 | var stackTrace = '';
|
28219 | var stringReader = new StringReader(StringUtil.getStackTrace(t$1));
|
28220 | var lineNumberReader = new LineNumberReader(stringReader);
|
28221 | for (var i = 0; i < depth; i++) {
|
28222 | try {
|
28223 | stackTrace += lineNumberReader.readLine() + StringUtil.NEWLINE;
|
28224 | } catch (e) {
|
28225 | if (e instanceof IOException) {
|
28226 | Assert.shouldNeverReachHere();
|
28227 | } else { throw e }
|
28228 | } finally {}
|
28229 | }
|
28230 | return stackTrace
|
28231 | }
|
28232 | };
|
28233 | StringUtil.split = function split (s, separator) {
|
28234 | var separatorlen = separator.length;
|
28235 | var tokenList = new ArrayList();
|
28236 | var tmpString = '' + s;
|
28237 | var pos = tmpString.indexOf(separator);
|
28238 | while (pos >= 0) {
|
28239 | var token = tmpString.substring(0, pos);
|
28240 | tokenList.add(token);
|
28241 | tmpString = tmpString.substring(pos + separatorlen);
|
28242 | pos = tmpString.indexOf(separator);
|
28243 | }
|
28244 | if (tmpString.length > 0) { tokenList.add(tmpString); }
|
28245 | var res = new Array(tokenList.size()).fill(null);
|
28246 | for (var i = 0; i < res.length; i++) {
|
28247 | res[i] = tokenList.get(i);
|
28248 | }
|
28249 | return res
|
28250 | };
|
28251 | StringUtil.toString = function toString () {
|
28252 | if (arguments.length === 1) {
|
28253 | var d = arguments[0];
|
28254 | return StringUtil.SIMPLE_ORDINATE_FORMAT.format(d)
|
28255 | }
|
28256 | };
|
28257 | StringUtil.spaces = function spaces (n) {
|
28258 | return StringUtil.chars(' ', n)
|
28259 | };
|
28260 | staticAccessors$15.NEWLINE.get = function () { return System.getProperty('line.separator') };
|
28261 | staticAccessors$15.SIMPLE_ORDINATE_FORMAT.get = function () { return new DecimalFormat('0.#') };
|
28262 |
|
28263 | Object.defineProperties( StringUtil, staticAccessors$15 );
|
28264 |
|
28265 | var CoordinateSequences = function CoordinateSequences () {};
|
28266 |
|
28267 | CoordinateSequences.prototype.interfaces_ = function interfaces_ () {
|
28268 | return []
|
28269 | };
|
28270 | CoordinateSequences.prototype.getClass = function getClass () {
|
28271 | return CoordinateSequences
|
28272 | };
|
28273 | CoordinateSequences.copyCoord = function copyCoord (src, srcPos, dest, destPos) {
|
28274 | var minDim = Math.min(src.getDimension(), dest.getDimension());
|
28275 | for (var dim = 0; dim < minDim; dim++) {
|
28276 | dest.setOrdinate(destPos, dim, src.getOrdinate(srcPos, dim));
|
28277 | }
|
28278 | };
|
28279 | CoordinateSequences.isRing = function isRing (seq) {
|
28280 | var n = seq.size();
|
28281 | if (n === 0) { return true }
|
28282 | if (n <= 3) { return false }
|
28283 | return seq.getOrdinate(0, CoordinateSequence.X) === seq.getOrdinate(n - 1, CoordinateSequence.X) && seq.getOrdinate(0, CoordinateSequence.Y) === seq.getOrdinate(n - 1, CoordinateSequence.Y)
|
28284 | };
|
28285 | CoordinateSequences.isEqual = function isEqual (cs1, cs2) {
|
28286 | var cs1Size = cs1.size();
|
28287 | var cs2Size = cs2.size();
|
28288 | if (cs1Size !== cs2Size) { return false }
|
28289 | var dim = Math.min(cs1.getDimension(), cs2.getDimension());
|
28290 | for (var i = 0; i < cs1Size; i++) {
|
28291 | for (var d = 0; d < dim; d++) {
|
28292 | var v1 = cs1.getOrdinate(i, d);
|
28293 | var v2 = cs2.getOrdinate(i, d);
|
28294 | if (cs1.getOrdinate(i, d) === cs2.getOrdinate(i, d)) { continue }
|
28295 | if (Double.isNaN(v1) && Double.isNaN(v2)) { continue }
|
28296 | return false
|
28297 | }
|
28298 | }
|
28299 | return true
|
28300 | };
|
28301 | CoordinateSequences.extend = function extend (fact, seq, size) {
|
28302 | var newseq = fact.create(size, seq.getDimension());
|
28303 | var n = seq.size();
|
28304 | CoordinateSequences.copy(seq, 0, newseq, 0, n);
|
28305 | if (n > 0) {
|
28306 | for (var i = n; i < size; i++) { CoordinateSequences.copy(seq, n - 1, newseq, i, 1); }
|
28307 | }
|
28308 | return newseq
|
28309 | };
|
28310 | CoordinateSequences.reverse = function reverse (seq) {
|
28311 | var last = seq.size() - 1;
|
28312 | var mid = Math.trunc(last / 2);
|
28313 | for (var i = 0; i <= mid; i++) {
|
28314 | CoordinateSequences.swap(seq, i, last - i);
|
28315 | }
|
28316 | };
|
28317 | CoordinateSequences.swap = function swap (seq, i, j) {
|
28318 | if (i === j) { return null }
|
28319 | for (var dim = 0; dim < seq.getDimension(); dim++) {
|
28320 | var tmp = seq.getOrdinate(i, dim);
|
28321 | seq.setOrdinate(i, dim, seq.getOrdinate(j, dim));
|
28322 | seq.setOrdinate(j, dim, tmp);
|
28323 | }
|
28324 | };
|
28325 | CoordinateSequences.copy = function copy (src, srcPos, dest, destPos, length) {
|
28326 | for (var i = 0; i < length; i++) {
|
28327 | CoordinateSequences.copyCoord(src, srcPos + i, dest, destPos + i);
|
28328 | }
|
28329 | };
|
28330 | CoordinateSequences.toString = function toString () {
|
28331 | if (arguments.length === 1) {
|
28332 | var cs = arguments[0];
|
28333 | var size = cs.size();
|
28334 | if (size === 0) { return '()' }
|
28335 | var dim = cs.getDimension();
|
28336 | var buf = new StringBuffer();
|
28337 | buf.append('(');
|
28338 | for (var i = 0; i < size; i++) {
|
28339 | if (i > 0) { buf.append(' '); }
|
28340 | for (var d = 0; d < dim; d++) {
|
28341 | if (d > 0) { buf.append(','); }
|
28342 | buf.append(StringUtil.toString(cs.getOrdinate(i, d)));
|
28343 | }
|
28344 | }
|
28345 | buf.append(')');
|
28346 | return buf.toString()
|
28347 | }
|
28348 | };
|
28349 | CoordinateSequences.ensureValidRing = function ensureValidRing (fact, seq) {
|
28350 | var n = seq.size();
|
28351 | if (n === 0) { return seq }
|
28352 | if (n <= 3) { return CoordinateSequences.createClosedRing(fact, seq, 4) }
|
28353 | var isClosed = seq.getOrdinate(0, CoordinateSequence.X) === seq.getOrdinate(n - 1, CoordinateSequence.X) && seq.getOrdinate(0, CoordinateSequence.Y) === seq.getOrdinate(n - 1, CoordinateSequence.Y);
|
28354 | if (isClosed) { return seq }
|
28355 | return CoordinateSequences.createClosedRing(fact, seq, n + 1)
|
28356 | };
|
28357 | CoordinateSequences.createClosedRing = function createClosedRing (fact, seq, size) {
|
28358 | var newseq = fact.create(size, seq.getDimension());
|
28359 | var n = seq.size();
|
28360 | CoordinateSequences.copy(seq, 0, newseq, 0, n);
|
28361 | for (var i = n; i < size; i++) { CoordinateSequences.copy(seq, 0, newseq, i, 1); }
|
28362 | return newseq
|
28363 | };
|
28364 |
|
28365 | var LineString$1 = (function (Geometry$$1) {
|
28366 | function LineString (points, factory) {
|
28367 | Geometry$$1.call(this, factory);
|
28368 | this._points = null;
|
28369 | this.init(points);
|
28370 | }
|
28371 |
|
28372 | if ( Geometry$$1 ) LineString.__proto__ = Geometry$$1;
|
28373 | LineString.prototype = Object.create( Geometry$$1 && Geometry$$1.prototype );
|
28374 | LineString.prototype.constructor = LineString;
|
28375 |
|
28376 | var staticAccessors = { serialVersionUID: { configurable: true } };
|
28377 | LineString.prototype.computeEnvelopeInternal = function computeEnvelopeInternal () {
|
28378 | if (this.isEmpty()) {
|
28379 | return new Envelope()
|
28380 | }
|
28381 | return this._points.expandEnvelope(new Envelope())
|
28382 | };
|
28383 | LineString.prototype.isRing = function isRing () {
|
28384 | return this.isClosed() && this.isSimple()
|
28385 | };
|
28386 | LineString.prototype.getSortIndex = function getSortIndex () {
|
28387 | return Geometry$$1.SORTINDEX_LINESTRING
|
28388 | };
|
28389 | LineString.prototype.getCoordinates = function getCoordinates () {
|
28390 | return this._points.toCoordinateArray()
|
28391 | };
|
28392 | LineString.prototype.equalsExact = function equalsExact () {
|
28393 | var this$1 = this;
|
28394 |
|
28395 | if (arguments.length === 2) {
|
28396 | var other = arguments[0];
|
28397 | var tolerance = arguments[1];
|
28398 | if (!this.isEquivalentClass(other)) {
|
28399 | return false
|
28400 | }
|
28401 | var otherLineString = other;
|
28402 | if (this._points.size() !== otherLineString._points.size()) {
|
28403 | return false
|
28404 | }
|
28405 | for (var i = 0; i < this._points.size(); i++) {
|
28406 | if (!this$1.equal(this$1._points.getCoordinate(i), otherLineString._points.getCoordinate(i), tolerance)) {
|
28407 | return false
|
28408 | }
|
28409 | }
|
28410 | return true
|
28411 | } else { return Geometry$$1.prototype.equalsExact.apply(this, arguments) }
|
28412 | };
|
28413 | LineString.prototype.normalize = function normalize () {
|
28414 | var this$1 = this;
|
28415 |
|
28416 | for (var i = 0; i < Math.trunc(this._points.size() / 2); i++) {
|
28417 | var j = this$1._points.size() - 1 - i;
|
28418 | if (!this$1._points.getCoordinate(i).equals(this$1._points.getCoordinate(j))) {
|
28419 | if (this$1._points.getCoordinate(i).compareTo(this$1._points.getCoordinate(j)) > 0) {
|
28420 | CoordinateSequences.reverse(this$1._points);
|
28421 | }
|
28422 | return null
|
28423 | }
|
28424 | }
|
28425 | };
|
28426 | LineString.prototype.getCoordinate = function getCoordinate () {
|
28427 | if (this.isEmpty()) { return null }
|
28428 | return this._points.getCoordinate(0)
|
28429 | };
|
28430 | LineString.prototype.getBoundaryDimension = function getBoundaryDimension () {
|
28431 | if (this.isClosed()) {
|
28432 | return Dimension.FALSE
|
28433 | }
|
28434 | return 0
|
28435 | };
|
28436 | LineString.prototype.isClosed = function isClosed () {
|
28437 | if (this.isEmpty()) {
|
28438 | return false
|
28439 | }
|
28440 | return this.getCoordinateN(0).equals2D(this.getCoordinateN(this.getNumPoints() - 1))
|
28441 | };
|
28442 | LineString.prototype.getEndPoint = function getEndPoint () {
|
28443 | if (this.isEmpty()) {
|
28444 | return null
|
28445 | }
|
28446 | return this.getPointN(this.getNumPoints() - 1)
|
28447 | };
|
28448 | LineString.prototype.getDimension = function getDimension () {
|
28449 | return 1
|
28450 | };
|
28451 | LineString.prototype.getLength = function getLength () {
|
28452 | return CGAlgorithms.computeLength(this._points)
|
28453 | };
|
28454 | LineString.prototype.getNumPoints = function getNumPoints () {
|
28455 | return this._points.size()
|
28456 | };
|
28457 | LineString.prototype.reverse = function reverse () {
|
28458 | var seq = this._points.copy();
|
28459 | CoordinateSequences.reverse(seq);
|
28460 | var revLine = this.getFactory().createLineString(seq);
|
28461 | return revLine
|
28462 | };
|
28463 | LineString.prototype.compareToSameClass = function compareToSameClass () {
|
28464 | var this$1 = this;
|
28465 |
|
28466 | if (arguments.length === 1) {
|
28467 | var o = arguments[0];
|
28468 | var line = o;
|
28469 | var i = 0;
|
28470 | var j = 0;
|
28471 | while (i < this._points.size() && j < line._points.size()) {
|
28472 | var comparison = this$1._points.getCoordinate(i).compareTo(line._points.getCoordinate(j));
|
28473 | if (comparison !== 0) {
|
28474 | return comparison
|
28475 | }
|
28476 | i++;
|
28477 | j++;
|
28478 | }
|
28479 | if (i < this._points.size()) {
|
28480 | return 1
|
28481 | }
|
28482 | if (j < line._points.size()) {
|
28483 | return -1
|
28484 | }
|
28485 | return 0
|
28486 | } else if (arguments.length === 2) {
|
28487 | var o$1 = arguments[0];
|
28488 | var comp = arguments[1];
|
28489 | var line$1 = o$1;
|
28490 | return comp.compare(this._points, line$1._points)
|
28491 | }
|
28492 | };
|
28493 | LineString.prototype.apply = function apply () {
|
28494 | var this$1 = this;
|
28495 |
|
28496 | if (hasInterface(arguments[0], CoordinateFilter)) {
|
28497 | var filter = arguments[0];
|
28498 | for (var i = 0; i < this._points.size(); i++) {
|
28499 | filter.filter(this$1._points.getCoordinate(i));
|
28500 | }
|
28501 | } else if (hasInterface(arguments[0], CoordinateSequenceFilter)) {
|
28502 | var filter$1 = arguments[0];
|
28503 | if (this._points.size() === 0) { return null }
|
28504 | for (var i$1 = 0; i$1 < this._points.size(); i$1++) {
|
28505 | filter$1.filter(this$1._points, i$1);
|
28506 | if (filter$1.isDone()) { break }
|
28507 | }
|
28508 | if (filter$1.isGeometryChanged()) { this.geometryChanged(); }
|
28509 | } else if (hasInterface(arguments[0], GeometryFilter)) {
|
28510 | var filter$2 = arguments[0];
|
28511 | filter$2.filter(this);
|
28512 | } else if (hasInterface(arguments[0], GeometryComponentFilter)) {
|
28513 | var filter$3 = arguments[0];
|
28514 | filter$3.filter(this);
|
28515 | }
|
28516 | };
|
28517 | LineString.prototype.getBoundary = function getBoundary () {
|
28518 | return new BoundaryOp(this).getBoundary()
|
28519 | };
|
28520 | LineString.prototype.isEquivalentClass = function isEquivalentClass (other) {
|
28521 | return other instanceof LineString
|
28522 | };
|
28523 | LineString.prototype.clone = function clone () {
|
28524 | var ls = Geometry$$1.prototype.clone.call(this);
|
28525 | ls._points = this._points.clone();
|
28526 | return ls
|
28527 | };
|
28528 | LineString.prototype.getCoordinateN = function getCoordinateN (n) {
|
28529 | return this._points.getCoordinate(n)
|
28530 | };
|
28531 | LineString.prototype.getGeometryType = function getGeometryType () {
|
28532 | return 'LineString'
|
28533 | };
|
28534 | LineString.prototype.copy = function copy () {
|
28535 | return new LineString(this._points.copy(), this._factory)
|
28536 | };
|
28537 | LineString.prototype.getCoordinateSequence = function getCoordinateSequence () {
|
28538 | return this._points
|
28539 | };
|
28540 | LineString.prototype.isEmpty = function isEmpty () {
|
28541 | return this._points.size() === 0
|
28542 | };
|
28543 | LineString.prototype.init = function init (points) {
|
28544 | if (points === null) {
|
28545 | points = this.getFactory().getCoordinateSequenceFactory().create([]);
|
28546 | }
|
28547 | if (points.size() === 1) {
|
28548 | throw new IllegalArgumentException('Invalid number of points in LineString (found ' + points.size() + ' - must be 0 or >= 2)')
|
28549 | }
|
28550 | this._points = points;
|
28551 | };
|
28552 | LineString.prototype.isCoordinate = function isCoordinate (pt) {
|
28553 | var this$1 = this;
|
28554 |
|
28555 | for (var i = 0; i < this._points.size(); i++) {
|
28556 | if (this$1._points.getCoordinate(i).equals(pt)) {
|
28557 | return true
|
28558 | }
|
28559 | }
|
28560 | return false
|
28561 | };
|
28562 | LineString.prototype.getStartPoint = function getStartPoint () {
|
28563 | if (this.isEmpty()) {
|
28564 | return null
|
28565 | }
|
28566 | return this.getPointN(0)
|
28567 | };
|
28568 | LineString.prototype.getPointN = function getPointN (n) {
|
28569 | return this.getFactory().createPoint(this._points.getCoordinate(n))
|
28570 | };
|
28571 | LineString.prototype.interfaces_ = function interfaces_ () {
|
28572 | return [Lineal]
|
28573 | };
|
28574 | LineString.prototype.getClass = function getClass () {
|
28575 | return LineString
|
28576 | };
|
28577 | staticAccessors.serialVersionUID.get = function () { return 3110669828065365560 };
|
28578 |
|
28579 | Object.defineProperties( LineString, staticAccessors );
|
28580 |
|
28581 | return LineString;
|
28582 | }(Geometry));
|
28583 |
|
28584 | var Puntal = function Puntal () {};
|
28585 |
|
28586 | Puntal.prototype.interfaces_ = function interfaces_ () {
|
28587 | return []
|
28588 | };
|
28589 | Puntal.prototype.getClass = function getClass () {
|
28590 | return Puntal
|
28591 | };
|
28592 |
|
28593 | var Point = (function (Geometry$$1) {
|
28594 | function Point (coordinates, factory) {
|
28595 | Geometry$$1.call(this, factory);
|
28596 | this._coordinates = coordinates || null;
|
28597 | this.init(this._coordinates);
|
28598 | }
|
28599 |
|
28600 | if ( Geometry$$1 ) Point.__proto__ = Geometry$$1;
|
28601 | Point.prototype = Object.create( Geometry$$1 && Geometry$$1.prototype );
|
28602 | Point.prototype.constructor = Point;
|
28603 |
|
28604 | var staticAccessors = { serialVersionUID: { configurable: true } };
|
28605 | Point.prototype.computeEnvelopeInternal = function computeEnvelopeInternal () {
|
28606 | if (this.isEmpty()) {
|
28607 | return new Envelope()
|
28608 | }
|
28609 | var env = new Envelope();
|
28610 | env.expandToInclude(this._coordinates.getX(0), this._coordinates.getY(0));
|
28611 | return env
|
28612 | };
|
28613 | Point.prototype.getSortIndex = function getSortIndex () {
|
28614 | return Geometry$$1.SORTINDEX_POINT
|
28615 | };
|
28616 | Point.prototype.getCoordinates = function getCoordinates () {
|
28617 | return this.isEmpty() ? [] : [this.getCoordinate()]
|
28618 | };
|
28619 | Point.prototype.equalsExact = function equalsExact () {
|
28620 | if (arguments.length === 2) {
|
28621 | var other = arguments[0];
|
28622 | var tolerance = arguments[1];
|
28623 | if (!this.isEquivalentClass(other)) {
|
28624 | return false
|
28625 | }
|
28626 | if (this.isEmpty() && other.isEmpty()) {
|
28627 | return true
|
28628 | }
|
28629 | if (this.isEmpty() !== other.isEmpty()) {
|
28630 | return false
|
28631 | }
|
28632 | return this.equal(other.getCoordinate(), this.getCoordinate(), tolerance)
|
28633 | } else { return Geometry$$1.prototype.equalsExact.apply(this, arguments) }
|
28634 | };
|
28635 | Point.prototype.normalize = function normalize () {};
|
28636 | Point.prototype.getCoordinate = function getCoordinate () {
|
28637 | return this._coordinates.size() !== 0 ? this._coordinates.getCoordinate(0) : null
|
28638 | };
|
28639 | Point.prototype.getBoundaryDimension = function getBoundaryDimension () {
|
28640 | return Dimension.FALSE
|
28641 | };
|
28642 | Point.prototype.getDimension = function getDimension () {
|
28643 | return 0
|
28644 | };
|
28645 | Point.prototype.getNumPoints = function getNumPoints () {
|
28646 | return this.isEmpty() ? 0 : 1
|
28647 | };
|
28648 | Point.prototype.reverse = function reverse () {
|
28649 | return this.copy()
|
28650 | };
|
28651 | Point.prototype.getX = function getX () {
|
28652 | if (this.getCoordinate() === null) {
|
28653 | throw new Error('getX called on empty Point')
|
28654 | }
|
28655 | return this.getCoordinate().x
|
28656 | };
|
28657 | Point.prototype.compareToSameClass = function compareToSameClass () {
|
28658 | if (arguments.length === 1) {
|
28659 | var other = arguments[0];
|
28660 | var point$1 = other;
|
28661 | return this.getCoordinate().compareTo(point$1.getCoordinate())
|
28662 | } else if (arguments.length === 2) {
|
28663 | var other$1 = arguments[0];
|
28664 | var comp = arguments[1];
|
28665 | var point = other$1;
|
28666 | return comp.compare(this._coordinates, point._coordinates)
|
28667 | }
|
28668 | };
|
28669 | Point.prototype.apply = function apply () {
|
28670 | if (hasInterface(arguments[0], CoordinateFilter)) {
|
28671 | var filter = arguments[0];
|
28672 | if (this.isEmpty()) {
|
28673 | return null
|
28674 | }
|
28675 | filter.filter(this.getCoordinate());
|
28676 | } else if (hasInterface(arguments[0], CoordinateSequenceFilter)) {
|
28677 | var filter$1 = arguments[0];
|
28678 | if (this.isEmpty()) { return null }
|
28679 | filter$1.filter(this._coordinates, 0);
|
28680 | if (filter$1.isGeometryChanged()) { this.geometryChanged(); }
|
28681 | } else if (hasInterface(arguments[0], GeometryFilter)) {
|
28682 | var filter$2 = arguments[0];
|
28683 | filter$2.filter(this);
|
28684 | } else if (hasInterface(arguments[0], GeometryComponentFilter)) {
|
28685 | var filter$3 = arguments[0];
|
28686 | filter$3.filter(this);
|
28687 | }
|
28688 | };
|
28689 | Point.prototype.getBoundary = function getBoundary () {
|
28690 | return this.getFactory().createGeometryCollection(null)
|
28691 | };
|
28692 | Point.prototype.clone = function clone () {
|
28693 | var p = Geometry$$1.prototype.clone.call(this);
|
28694 | p._coordinates = this._coordinates.clone();
|
28695 | return p
|
28696 | };
|
28697 | Point.prototype.getGeometryType = function getGeometryType () {
|
28698 | return 'Point'
|
28699 | };
|
28700 | Point.prototype.copy = function copy () {
|
28701 | return new Point(this._coordinates.copy(), this._factory)
|
28702 | };
|
28703 | Point.prototype.getCoordinateSequence = function getCoordinateSequence () {
|
28704 | return this._coordinates
|
28705 | };
|
28706 | Point.prototype.getY = function getY () {
|
28707 | if (this.getCoordinate() === null) {
|
28708 | throw new Error('getY called on empty Point')
|
28709 | }
|
28710 | return this.getCoordinate().y
|
28711 | };
|
28712 | Point.prototype.isEmpty = function isEmpty () {
|
28713 | return this._coordinates.size() === 0
|
28714 | };
|
28715 | Point.prototype.init = function init (coordinates) {
|
28716 | if (coordinates === null) {
|
28717 | coordinates = this.getFactory().getCoordinateSequenceFactory().create([]);
|
28718 | }
|
28719 | Assert.isTrue(coordinates.size() <= 1);
|
28720 | this._coordinates = coordinates;
|
28721 | };
|
28722 | Point.prototype.isSimple = function isSimple () {
|
28723 | return true
|
28724 | };
|
28725 | Point.prototype.interfaces_ = function interfaces_ () {
|
28726 | return [Puntal]
|
28727 | };
|
28728 | Point.prototype.getClass = function getClass () {
|
28729 | return Point
|
28730 | };
|
28731 | staticAccessors.serialVersionUID.get = function () { return 4902022702746614570 };
|
28732 |
|
28733 | Object.defineProperties( Point, staticAccessors );
|
28734 |
|
28735 | return Point;
|
28736 | }(Geometry));
|
28737 |
|
28738 | var Polygonal = function Polygonal () {};
|
28739 |
|
28740 | Polygonal.prototype.interfaces_ = function interfaces_ () {
|
28741 | return []
|
28742 | };
|
28743 | Polygonal.prototype.getClass = function getClass () {
|
28744 | return Polygonal
|
28745 | };
|
28746 |
|
28747 | var Polygon = (function (Geometry$$1) {
|
28748 | function Polygon (shell, holes, factory) {
|
28749 | Geometry$$1.call(this, factory);
|
28750 | this._shell = null;
|
28751 | this._holes = null;
|
28752 | if (shell === null) {
|
28753 | shell = this.getFactory().createLinearRing();
|
28754 | }
|
28755 | if (holes === null) {
|
28756 | holes = [];
|
28757 | }
|
28758 | if (Geometry$$1.hasNullElements(holes)) {
|
28759 | throw new IllegalArgumentException('holes must not contain null elements')
|
28760 | }
|
28761 | if (shell.isEmpty() && Geometry$$1.hasNonEmptyElements(holes)) {
|
28762 | throw new IllegalArgumentException('shell is empty but holes are not')
|
28763 | }
|
28764 | this._shell = shell;
|
28765 | this._holes = holes;
|
28766 | }
|
28767 |
|
28768 | if ( Geometry$$1 ) Polygon.__proto__ = Geometry$$1;
|
28769 | Polygon.prototype = Object.create( Geometry$$1 && Geometry$$1.prototype );
|
28770 | Polygon.prototype.constructor = Polygon;
|
28771 |
|
28772 | var staticAccessors = { serialVersionUID: { configurable: true } };
|
28773 | Polygon.prototype.computeEnvelopeInternal = function computeEnvelopeInternal () {
|
28774 | return this._shell.getEnvelopeInternal()
|
28775 | };
|
28776 | Polygon.prototype.getSortIndex = function getSortIndex () {
|
28777 | return Geometry$$1.SORTINDEX_POLYGON
|
28778 | };
|
28779 | Polygon.prototype.getCoordinates = function getCoordinates () {
|
28780 | var this$1 = this;
|
28781 |
|
28782 | if (this.isEmpty()) {
|
28783 | return []
|
28784 | }
|
28785 | var coordinates = new Array(this.getNumPoints()).fill(null);
|
28786 | var k = -1;
|
28787 | var shellCoordinates = this._shell.getCoordinates();
|
28788 | for (var x = 0; x < shellCoordinates.length; x++) {
|
28789 | k++;
|
28790 | coordinates[k] = shellCoordinates[x];
|
28791 | }
|
28792 | for (var i = 0; i < this._holes.length; i++) {
|
28793 | var childCoordinates = this$1._holes[i].getCoordinates();
|
28794 | for (var j = 0; j < childCoordinates.length; j++) {
|
28795 | k++;
|
28796 | coordinates[k] = childCoordinates[j];
|
28797 | }
|
28798 | }
|
28799 | return coordinates
|
28800 | };
|
28801 | Polygon.prototype.getArea = function getArea () {
|
28802 | var this$1 = this;
|
28803 |
|
28804 | var area = 0.0;
|
28805 | area += Math.abs(CGAlgorithms.signedArea(this._shell.getCoordinateSequence()));
|
28806 | for (var i = 0; i < this._holes.length; i++) {
|
28807 | area -= Math.abs(CGAlgorithms.signedArea(this$1._holes[i].getCoordinateSequence()));
|
28808 | }
|
28809 | return area
|
28810 | };
|
28811 | Polygon.prototype.isRectangle = function isRectangle () {
|
28812 | if (this.getNumInteriorRing() !== 0) { return false }
|
28813 | if (this._shell === null) { return false }
|
28814 | if (this._shell.getNumPoints() !== 5) { return false }
|
28815 | var seq = this._shell.getCoordinateSequence();
|
28816 | var env = this.getEnvelopeInternal();
|
28817 | for (var i = 0; i < 5; i++) {
|
28818 | var x = seq.getX(i);
|
28819 | if (!(x === env.getMinX() || x === env.getMaxX())) { return false }
|
28820 | var y = seq.getY(i);
|
28821 | if (!(y === env.getMinY() || y === env.getMaxY())) { return false }
|
28822 | }
|
28823 | var prevX = seq.getX(0);
|
28824 | var prevY = seq.getY(0);
|
28825 | for (var i$1 = 1; i$1 <= 4; i$1++) {
|
28826 | var x$1 = seq.getX(i$1);
|
28827 | var y$1 = seq.getY(i$1);
|
28828 | var xChanged = x$1 !== prevX;
|
28829 | var yChanged = y$1 !== prevY;
|
28830 | if (xChanged === yChanged) { return false }
|
28831 | prevX = x$1;
|
28832 | prevY = y$1;
|
28833 | }
|
28834 | return true
|
28835 | };
|
28836 | Polygon.prototype.equalsExact = function equalsExact () {
|
28837 | var this$1 = this;
|
28838 |
|
28839 | if (arguments.length === 2) {
|
28840 | var other = arguments[0];
|
28841 | var tolerance = arguments[1];
|
28842 | if (!this.isEquivalentClass(other)) {
|
28843 | return false
|
28844 | }
|
28845 | var otherPolygon = other;
|
28846 | var thisShell = this._shell;
|
28847 | var otherPolygonShell = otherPolygon._shell;
|
28848 | if (!thisShell.equalsExact(otherPolygonShell, tolerance)) {
|
28849 | return false
|
28850 | }
|
28851 | if (this._holes.length !== otherPolygon._holes.length) {
|
28852 | return false
|
28853 | }
|
28854 | for (var i = 0; i < this._holes.length; i++) {
|
28855 | if (!this$1._holes[i].equalsExact(otherPolygon._holes[i], tolerance)) {
|
28856 | return false
|
28857 | }
|
28858 | }
|
28859 | return true
|
28860 | } else { return Geometry$$1.prototype.equalsExact.apply(this, arguments) }
|
28861 | };
|
28862 | Polygon.prototype.normalize = function normalize () {
|
28863 | var this$1 = this;
|
28864 |
|
28865 | if (arguments.length === 0) {
|
28866 | this.normalize(this._shell, true);
|
28867 | for (var i = 0; i < this._holes.length; i++) {
|
28868 | this$1.normalize(this$1._holes[i], false);
|
28869 | }
|
28870 | Arrays.sort(this._holes);
|
28871 | } else if (arguments.length === 2) {
|
28872 | var ring = arguments[0];
|
28873 | var clockwise = arguments[1];
|
28874 | if (ring.isEmpty()) {
|
28875 | return null
|
28876 | }
|
28877 | var uniqueCoordinates = new Array(ring.getCoordinates().length - 1).fill(null);
|
28878 | System.arraycopy(ring.getCoordinates(), 0, uniqueCoordinates, 0, uniqueCoordinates.length);
|
28879 | var minCoordinate = CoordinateArrays.minCoordinate(ring.getCoordinates());
|
28880 | CoordinateArrays.scroll(uniqueCoordinates, minCoordinate);
|
28881 | System.arraycopy(uniqueCoordinates, 0, ring.getCoordinates(), 0, uniqueCoordinates.length);
|
28882 | ring.getCoordinates()[uniqueCoordinates.length] = uniqueCoordinates[0];
|
28883 | if (CGAlgorithms.isCCW(ring.getCoordinates()) === clockwise) {
|
28884 | CoordinateArrays.reverse(ring.getCoordinates());
|
28885 | }
|
28886 | }
|
28887 | };
|
28888 | Polygon.prototype.getCoordinate = function getCoordinate () {
|
28889 | return this._shell.getCoordinate()
|
28890 | };
|
28891 | Polygon.prototype.getNumInteriorRing = function getNumInteriorRing () {
|
28892 | return this._holes.length
|
28893 | };
|
28894 | Polygon.prototype.getBoundaryDimension = function getBoundaryDimension () {
|
28895 | return 1
|
28896 | };
|
28897 | Polygon.prototype.getDimension = function getDimension () {
|
28898 | return 2
|
28899 | };
|
28900 | Polygon.prototype.getLength = function getLength () {
|
28901 | var this$1 = this;
|
28902 |
|
28903 | var len = 0.0;
|
28904 | len += this._shell.getLength();
|
28905 | for (var i = 0; i < this._holes.length; i++) {
|
28906 | len += this$1._holes[i].getLength();
|
28907 | }
|
28908 | return len
|
28909 | };
|
28910 | Polygon.prototype.getNumPoints = function getNumPoints () {
|
28911 | var this$1 = this;
|
28912 |
|
28913 | var numPoints = this._shell.getNumPoints();
|
28914 | for (var i = 0; i < this._holes.length; i++) {
|
28915 | numPoints += this$1._holes[i].getNumPoints();
|
28916 | }
|
28917 | return numPoints
|
28918 | };
|
28919 | Polygon.prototype.reverse = function reverse () {
|
28920 | var this$1 = this;
|
28921 |
|
28922 | var poly = this.copy();
|
28923 | poly._shell = this._shell.copy().reverse();
|
28924 | poly._holes = new Array(this._holes.length).fill(null);
|
28925 | for (var i = 0; i < this._holes.length; i++) {
|
28926 | poly._holes[i] = this$1._holes[i].copy().reverse();
|
28927 | }
|
28928 | return poly
|
28929 | };
|
28930 | Polygon.prototype.convexHull = function convexHull () {
|
28931 | return this.getExteriorRing().convexHull()
|
28932 | };
|
28933 | Polygon.prototype.compareToSameClass = function compareToSameClass () {
|
28934 | var this$1 = this;
|
28935 |
|
28936 | if (arguments.length === 1) {
|
28937 | var o = arguments[0];
|
28938 | var thisShell = this._shell;
|
28939 | var otherShell = o._shell;
|
28940 | return thisShell.compareToSameClass(otherShell)
|
28941 | } else if (arguments.length === 2) {
|
28942 | var o$1 = arguments[0];
|
28943 | var comp = arguments[1];
|
28944 | var poly = o$1;
|
28945 | var thisShell$1 = this._shell;
|
28946 | var otherShell$1 = poly._shell;
|
28947 | var shellComp = thisShell$1.compareToSameClass(otherShell$1, comp);
|
28948 | if (shellComp !== 0) { return shellComp }
|
28949 | var nHole1 = this.getNumInteriorRing();
|
28950 | var nHole2 = poly.getNumInteriorRing();
|
28951 | var i = 0;
|
28952 | while (i < nHole1 && i < nHole2) {
|
28953 | var thisHole = this$1.getInteriorRingN(i);
|
28954 | var otherHole = poly.getInteriorRingN(i);
|
28955 | var holeComp = thisHole.compareToSameClass(otherHole, comp);
|
28956 | if (holeComp !== 0) { return holeComp }
|
28957 | i++;
|
28958 | }
|
28959 | if (i < nHole1) { return 1 }
|
28960 | if (i < nHole2) { return -1 }
|
28961 | return 0
|
28962 | }
|
28963 | };
|
28964 | Polygon.prototype.apply = function apply (filter) {
|
28965 | var this$1 = this;
|
28966 |
|
28967 | if (hasInterface(filter, CoordinateFilter)) {
|
28968 | this._shell.apply(filter);
|
28969 | for (var i$1 = 0; i$1 < this._holes.length; i$1++) {
|
28970 | this$1._holes[i$1].apply(filter);
|
28971 | }
|
28972 | } else if (hasInterface(filter, CoordinateSequenceFilter)) {
|
28973 | this._shell.apply(filter);
|
28974 | if (!filter.isDone()) {
|
28975 | for (var i$2 = 0; i$2 < this._holes.length; i$2++) {
|
28976 | this$1._holes[i$2].apply(filter);
|
28977 | if (filter.isDone()) { break }
|
28978 | }
|
28979 | }
|
28980 | if (filter.isGeometryChanged()) { this.geometryChanged(); }
|
28981 | } else if (hasInterface(filter, GeometryFilter)) {
|
28982 | filter.filter(this);
|
28983 | } else if (hasInterface(filter, GeometryComponentFilter)) {
|
28984 | filter.filter(this);
|
28985 | this._shell.apply(filter);
|
28986 | for (var i = 0; i < this._holes.length; i++) {
|
28987 | this$1._holes[i].apply(filter);
|
28988 | }
|
28989 | }
|
28990 | };
|
28991 | Polygon.prototype.getBoundary = function getBoundary () {
|
28992 | var this$1 = this;
|
28993 |
|
28994 | if (this.isEmpty()) {
|
28995 | return this.getFactory().createMultiLineString()
|
28996 | }
|
28997 | var rings = new Array(this._holes.length + 1).fill(null);
|
28998 | rings[0] = this._shell;
|
28999 | for (var i = 0; i < this._holes.length; i++) {
|
29000 | rings[i + 1] = this$1._holes[i];
|
29001 | }
|
29002 | if (rings.length <= 1) { return this.getFactory().createLinearRing(rings[0].getCoordinateSequence()) }
|
29003 | return this.getFactory().createMultiLineString(rings)
|
29004 | };
|
29005 | Polygon.prototype.clone = function clone () {
|
29006 | var this$1 = this;
|
29007 |
|
29008 | var poly = Geometry$$1.prototype.clone.call(this);
|
29009 | poly._shell = this._shell.clone();
|
29010 | poly._holes = new Array(this._holes.length).fill(null);
|
29011 | for (var i = 0; i < this._holes.length; i++) {
|
29012 | poly._holes[i] = this$1._holes[i].clone();
|
29013 | }
|
29014 | return poly
|
29015 | };
|
29016 | Polygon.prototype.getGeometryType = function getGeometryType () {
|
29017 | return 'Polygon'
|
29018 | };
|
29019 | Polygon.prototype.copy = function copy () {
|
29020 | var this$1 = this;
|
29021 |
|
29022 | var shell = this._shell.copy();
|
29023 | var holes = new Array(this._holes.length).fill(null);
|
29024 | for (var i = 0; i < holes.length; i++) {
|
29025 | holes[i] = this$1._holes[i].copy();
|
29026 | }
|
29027 | return new Polygon(shell, holes, this._factory)
|
29028 | };
|
29029 | Polygon.prototype.getExteriorRing = function getExteriorRing () {
|
29030 | return this._shell
|
29031 | };
|
29032 | Polygon.prototype.isEmpty = function isEmpty () {
|
29033 | return this._shell.isEmpty()
|
29034 | };
|
29035 | Polygon.prototype.getInteriorRingN = function getInteriorRingN (n) {
|
29036 | return this._holes[n]
|
29037 | };
|
29038 | Polygon.prototype.interfaces_ = function interfaces_ () {
|
29039 | return [Polygonal]
|
29040 | };
|
29041 | Polygon.prototype.getClass = function getClass () {
|
29042 | return Polygon
|
29043 | };
|
29044 | staticAccessors.serialVersionUID.get = function () { return -3494792200821764533 };
|
29045 |
|
29046 | Object.defineProperties( Polygon, staticAccessors );
|
29047 |
|
29048 | return Polygon;
|
29049 | }(Geometry));
|
29050 |
|
29051 | var MultiPoint = (function (GeometryCollection$$1) {
|
29052 | function MultiPoint () {
|
29053 | GeometryCollection$$1.apply(this, arguments);
|
29054 | }
|
29055 |
|
29056 | if ( GeometryCollection$$1 ) MultiPoint.__proto__ = GeometryCollection$$1;
|
29057 | MultiPoint.prototype = Object.create( GeometryCollection$$1 && GeometryCollection$$1.prototype );
|
29058 | MultiPoint.prototype.constructor = MultiPoint;
|
29059 |
|
29060 | var staticAccessors = { serialVersionUID: { configurable: true } };
|
29061 |
|
29062 | MultiPoint.prototype.getSortIndex = function getSortIndex () {
|
29063 | return Geometry.SORTINDEX_MULTIPOINT
|
29064 | };
|
29065 | MultiPoint.prototype.isValid = function isValid () {
|
29066 | return true
|
29067 | };
|
29068 | MultiPoint.prototype.equalsExact = function equalsExact () {
|
29069 | if (arguments.length === 2) {
|
29070 | var other = arguments[0];
|
29071 | var tolerance = arguments[1];
|
29072 | if (!this.isEquivalentClass(other)) {
|
29073 | return false
|
29074 | }
|
29075 | return GeometryCollection$$1.prototype.equalsExact.call(this, other, tolerance)
|
29076 | } else { return GeometryCollection$$1.prototype.equalsExact.apply(this, arguments) }
|
29077 | };
|
29078 | MultiPoint.prototype.getCoordinate = function getCoordinate () {
|
29079 | if (arguments.length === 1) {
|
29080 | var n = arguments[0];
|
29081 | return this._geometries[n].getCoordinate()
|
29082 | } else { return GeometryCollection$$1.prototype.getCoordinate.apply(this, arguments) }
|
29083 | };
|
29084 | MultiPoint.prototype.getBoundaryDimension = function getBoundaryDimension () {
|
29085 | return Dimension.FALSE
|
29086 | };
|
29087 | MultiPoint.prototype.getDimension = function getDimension () {
|
29088 | return 0
|
29089 | };
|
29090 | MultiPoint.prototype.getBoundary = function getBoundary () {
|
29091 | return this.getFactory().createGeometryCollection(null)
|
29092 | };
|
29093 | MultiPoint.prototype.getGeometryType = function getGeometryType () {
|
29094 | return 'MultiPoint'
|
29095 | };
|
29096 | MultiPoint.prototype.copy = function copy () {
|
29097 | var this$1 = this;
|
29098 |
|
29099 | var points = new Array(this._geometries.length).fill(null);
|
29100 | for (var i = 0; i < points.length; i++) {
|
29101 | points[i] = this$1._geometries[i].copy();
|
29102 | }
|
29103 | return new MultiPoint(points, this._factory)
|
29104 | };
|
29105 | MultiPoint.prototype.interfaces_ = function interfaces_ () {
|
29106 | return [Puntal]
|
29107 | };
|
29108 | MultiPoint.prototype.getClass = function getClass () {
|
29109 | return MultiPoint
|
29110 | };
|
29111 | staticAccessors.serialVersionUID.get = function () { return -8048474874175355449 };
|
29112 |
|
29113 | Object.defineProperties( MultiPoint, staticAccessors );
|
29114 |
|
29115 | return MultiPoint;
|
29116 | }(GeometryCollection));
|
29117 |
|
29118 | var LinearRing = (function (LineString$$1) {
|
29119 | function LinearRing (points, factory) {
|
29120 | if (points instanceof Coordinate && factory instanceof GeometryFactory) {
|
29121 | points = factory.getCoordinateSequenceFactory().create(points);
|
29122 | }
|
29123 | LineString$$1.call(this, points, factory);
|
29124 | this.validateConstruction();
|
29125 | }
|
29126 |
|
29127 | if ( LineString$$1 ) LinearRing.__proto__ = LineString$$1;
|
29128 | LinearRing.prototype = Object.create( LineString$$1 && LineString$$1.prototype );
|
29129 | LinearRing.prototype.constructor = LinearRing;
|
29130 |
|
29131 | var staticAccessors = { MINIMUM_VALID_SIZE: { configurable: true },serialVersionUID: { configurable: true } };
|
29132 | LinearRing.prototype.getSortIndex = function getSortIndex () {
|
29133 | return Geometry.SORTINDEX_LINEARRING
|
29134 | };
|
29135 | LinearRing.prototype.getBoundaryDimension = function getBoundaryDimension () {
|
29136 | return Dimension.FALSE
|
29137 | };
|
29138 | LinearRing.prototype.isClosed = function isClosed () {
|
29139 | if (this.isEmpty()) {
|
29140 | return true
|
29141 | }
|
29142 | return LineString$$1.prototype.isClosed.call(this)
|
29143 | };
|
29144 | LinearRing.prototype.reverse = function reverse () {
|
29145 | var seq = this._points.copy();
|
29146 | CoordinateSequences.reverse(seq);
|
29147 | var rev = this.getFactory().createLinearRing(seq);
|
29148 | return rev
|
29149 | };
|
29150 | LinearRing.prototype.validateConstruction = function validateConstruction () {
|
29151 | if (!this.isEmpty() && !LineString$$1.prototype.isClosed.call(this)) {
|
29152 | throw new IllegalArgumentException('Points of LinearRing do not form a closed linestring')
|
29153 | }
|
29154 | if (this.getCoordinateSequence().size() >= 1 && this.getCoordinateSequence().size() < LinearRing.MINIMUM_VALID_SIZE) {
|
29155 | throw new IllegalArgumentException('Invalid number of points in LinearRing (found ' + this.getCoordinateSequence().size() + ' - must be 0 or >= 4)')
|
29156 | }
|
29157 | };
|
29158 | LinearRing.prototype.getGeometryType = function getGeometryType () {
|
29159 | return 'LinearRing'
|
29160 | };
|
29161 | LinearRing.prototype.copy = function copy () {
|
29162 | return new LinearRing(this._points.copy(), this._factory)
|
29163 | };
|
29164 | LinearRing.prototype.interfaces_ = function interfaces_ () {
|
29165 | return []
|
29166 | };
|
29167 | LinearRing.prototype.getClass = function getClass () {
|
29168 | return LinearRing
|
29169 | };
|
29170 | staticAccessors.MINIMUM_VALID_SIZE.get = function () { return 4 };
|
29171 | staticAccessors.serialVersionUID.get = function () { return -4261142084085851829 };
|
29172 |
|
29173 | Object.defineProperties( LinearRing, staticAccessors );
|
29174 |
|
29175 | return LinearRing;
|
29176 | }(LineString$1));
|
29177 |
|
29178 | var MultiPolygon = (function (GeometryCollection$$1) {
|
29179 | function MultiPolygon () {
|
29180 | GeometryCollection$$1.apply(this, arguments);
|
29181 | }
|
29182 |
|
29183 | if ( GeometryCollection$$1 ) MultiPolygon.__proto__ = GeometryCollection$$1;
|
29184 | MultiPolygon.prototype = Object.create( GeometryCollection$$1 && GeometryCollection$$1.prototype );
|
29185 | MultiPolygon.prototype.constructor = MultiPolygon;
|
29186 |
|
29187 | var staticAccessors = { serialVersionUID: { configurable: true } };
|
29188 |
|
29189 | MultiPolygon.prototype.getSortIndex = function getSortIndex () {
|
29190 | return Geometry.SORTINDEX_MULTIPOLYGON
|
29191 | };
|
29192 | MultiPolygon.prototype.equalsExact = function equalsExact () {
|
29193 | if (arguments.length === 2) {
|
29194 | var other = arguments[0];
|
29195 | var tolerance = arguments[1];
|
29196 | if (!this.isEquivalentClass(other)) {
|
29197 | return false
|
29198 | }
|
29199 | return GeometryCollection$$1.prototype.equalsExact.call(this, other, tolerance)
|
29200 | } else { return GeometryCollection$$1.prototype.equalsExact.apply(this, arguments) }
|
29201 | };
|
29202 | MultiPolygon.prototype.getBoundaryDimension = function getBoundaryDimension () {
|
29203 | return 1
|
29204 | };
|
29205 | MultiPolygon.prototype.getDimension = function getDimension () {
|
29206 | return 2
|
29207 | };
|
29208 | MultiPolygon.prototype.reverse = function reverse () {
|
29209 | var this$1 = this;
|
29210 |
|
29211 | var n = this._geometries.length;
|
29212 | var revGeoms = new Array(n).fill(null);
|
29213 | for (var i = 0; i < this._geometries.length; i++) {
|
29214 | revGeoms[i] = this$1._geometries[i].reverse();
|
29215 | }
|
29216 | return this.getFactory().createMultiPolygon(revGeoms)
|
29217 | };
|
29218 | MultiPolygon.prototype.getBoundary = function getBoundary () {
|
29219 | var this$1 = this;
|
29220 |
|
29221 | if (this.isEmpty()) {
|
29222 | return this.getFactory().createMultiLineString()
|
29223 | }
|
29224 | var allRings = new ArrayList();
|
29225 | for (var i = 0; i < this._geometries.length; i++) {
|
29226 | var polygon = this$1._geometries[i];
|
29227 | var rings = polygon.getBoundary();
|
29228 | for (var j = 0; j < rings.getNumGeometries(); j++) {
|
29229 | allRings.add(rings.getGeometryN(j));
|
29230 | }
|
29231 | }
|
29232 | var allRingsArray = new Array(allRings.size()).fill(null);
|
29233 | return this.getFactory().createMultiLineString(allRings.toArray(allRingsArray))
|
29234 | };
|
29235 | MultiPolygon.prototype.getGeometryType = function getGeometryType () {
|
29236 | return 'MultiPolygon'
|
29237 | };
|
29238 | MultiPolygon.prototype.copy = function copy () {
|
29239 | var this$1 = this;
|
29240 |
|
29241 | var polygons = new Array(this._geometries.length).fill(null);
|
29242 | for (var i = 0; i < polygons.length; i++) {
|
29243 | polygons[i] = this$1._geometries[i].copy();
|
29244 | }
|
29245 | return new MultiPolygon(polygons, this._factory)
|
29246 | };
|
29247 | MultiPolygon.prototype.interfaces_ = function interfaces_ () {
|
29248 | return [Polygonal]
|
29249 | };
|
29250 | MultiPolygon.prototype.getClass = function getClass () {
|
29251 | return MultiPolygon
|
29252 | };
|
29253 | staticAccessors.serialVersionUID.get = function () { return -551033529766975875 };
|
29254 |
|
29255 | Object.defineProperties( MultiPolygon, staticAccessors );
|
29256 |
|
29257 | return MultiPolygon;
|
29258 | }(GeometryCollection));
|
29259 |
|
29260 | var GeometryEditor = function GeometryEditor (factory) {
|
29261 | this._factory = factory || null;
|
29262 | this._isUserDataCopied = false;
|
29263 | };
|
29264 |
|
29265 | var staticAccessors$16 = { NoOpGeometryOperation: { configurable: true },CoordinateOperation: { configurable: true },CoordinateSequenceOperation: { configurable: true } };
|
29266 | GeometryEditor.prototype.setCopyUserData = function setCopyUserData (isUserDataCopied) {
|
29267 | this._isUserDataCopied = isUserDataCopied;
|
29268 | };
|
29269 | GeometryEditor.prototype.edit = function edit (geometry, operation) {
|
29270 | if (geometry === null) { return null }
|
29271 | var result = this.editInternal(geometry, operation);
|
29272 | if (this._isUserDataCopied) {
|
29273 | result.setUserData(geometry.getUserData());
|
29274 | }
|
29275 | return result
|
29276 | };
|
29277 | GeometryEditor.prototype.editInternal = function editInternal (geometry, operation) {
|
29278 | if (this._factory === null) { this._factory = geometry.getFactory(); }
|
29279 | if (geometry instanceof GeometryCollection) {
|
29280 | return this.editGeometryCollection(geometry, operation)
|
29281 | }
|
29282 | if (geometry instanceof Polygon) {
|
29283 | return this.editPolygon(geometry, operation)
|
29284 | }
|
29285 | if (geometry instanceof Point) {
|
29286 | return operation.edit(geometry, this._factory)
|
29287 | }
|
29288 | if (geometry instanceof LineString$1) {
|
29289 | return operation.edit(geometry, this._factory)
|
29290 | }
|
29291 | Assert.shouldNeverReachHere('Unsupported Geometry class: ' + geometry.getClass().getName());
|
29292 | return null
|
29293 | };
|
29294 | GeometryEditor.prototype.editGeometryCollection = function editGeometryCollection (collection, operation) {
|
29295 | var this$1 = this;
|
29296 |
|
29297 | var collectionForType = operation.edit(collection, this._factory);
|
29298 | var geometries = new ArrayList();
|
29299 | for (var i = 0; i < collectionForType.getNumGeometries(); i++) {
|
29300 | var geometry = this$1.edit(collectionForType.getGeometryN(i), operation);
|
29301 | if (geometry === null || geometry.isEmpty()) {
|
29302 | continue
|
29303 | }
|
29304 | geometries.add(geometry);
|
29305 | }
|
29306 | if (collectionForType.getClass() === MultiPoint) {
|
29307 | return this._factory.createMultiPoint(geometries.toArray([]))
|
29308 | }
|
29309 | if (collectionForType.getClass() === MultiLineString) {
|
29310 | return this._factory.createMultiLineString(geometries.toArray([]))
|
29311 | }
|
29312 | if (collectionForType.getClass() === MultiPolygon) {
|
29313 | return this._factory.createMultiPolygon(geometries.toArray([]))
|
29314 | }
|
29315 | return this._factory.createGeometryCollection(geometries.toArray([]))
|
29316 | };
|
29317 | GeometryEditor.prototype.editPolygon = function editPolygon (polygon, operation) {
|
29318 | var this$1 = this;
|
29319 |
|
29320 | var newPolygon = operation.edit(polygon, this._factory);
|
29321 | if (newPolygon === null) { newPolygon = this._factory.createPolygon(null); }
|
29322 | if (newPolygon.isEmpty()) {
|
29323 | return newPolygon
|
29324 | }
|
29325 | var shell = this.edit(newPolygon.getExteriorRing(), operation);
|
29326 | if (shell === null || shell.isEmpty()) {
|
29327 | return this._factory.createPolygon()
|
29328 | }
|
29329 | var holes = new ArrayList();
|
29330 | for (var i = 0; i < newPolygon.getNumInteriorRing(); i++) {
|
29331 | var hole = this$1.edit(newPolygon.getInteriorRingN(i), operation);
|
29332 | if (hole === null || hole.isEmpty()) {
|
29333 | continue
|
29334 | }
|
29335 | holes.add(hole);
|
29336 | }
|
29337 | return this._factory.createPolygon(shell, holes.toArray([]))
|
29338 | };
|
29339 | GeometryEditor.prototype.interfaces_ = function interfaces_ () {
|
29340 | return []
|
29341 | };
|
29342 | GeometryEditor.prototype.getClass = function getClass () {
|
29343 | return GeometryEditor
|
29344 | };
|
29345 | GeometryEditor.GeometryEditorOperation = function GeometryEditorOperation () {};
|
29346 | staticAccessors$16.NoOpGeometryOperation.get = function () { return NoOpGeometryOperation };
|
29347 | staticAccessors$16.CoordinateOperation.get = function () { return CoordinateOperation };
|
29348 | staticAccessors$16.CoordinateSequenceOperation.get = function () { return CoordinateSequenceOperation };
|
29349 |
|
29350 | Object.defineProperties( GeometryEditor, staticAccessors$16 );
|
29351 |
|
29352 | var NoOpGeometryOperation = function NoOpGeometryOperation () {};
|
29353 |
|
29354 | NoOpGeometryOperation.prototype.edit = function edit (geometry, factory) {
|
29355 | return geometry
|
29356 | };
|
29357 | NoOpGeometryOperation.prototype.interfaces_ = function interfaces_ () {
|
29358 | return [GeometryEditor.GeometryEditorOperation]
|
29359 | };
|
29360 | NoOpGeometryOperation.prototype.getClass = function getClass () {
|
29361 | return NoOpGeometryOperation
|
29362 | };
|
29363 |
|
29364 | var CoordinateOperation = function CoordinateOperation () {};
|
29365 |
|
29366 | CoordinateOperation.prototype.edit = function edit (geometry, factory) {
|
29367 | var coords = this.editCoordinates(geometry.getCoordinates(), geometry);
|
29368 | if (coords === null) { return geometry }
|
29369 | if (geometry instanceof LinearRing) {
|
29370 | return factory.createLinearRing(coords)
|
29371 | }
|
29372 | if (geometry instanceof LineString$1) {
|
29373 | return factory.createLineString(coords)
|
29374 | }
|
29375 | if (geometry instanceof Point) {
|
29376 | if (coords.length > 0) {
|
29377 | return factory.createPoint(coords[0])
|
29378 | } else {
|
29379 | return factory.createPoint()
|
29380 | }
|
29381 | }
|
29382 | return geometry
|
29383 | };
|
29384 | CoordinateOperation.prototype.interfaces_ = function interfaces_ () {
|
29385 | return [GeometryEditor.GeometryEditorOperation]
|
29386 | };
|
29387 | CoordinateOperation.prototype.getClass = function getClass () {
|
29388 | return CoordinateOperation
|
29389 | };
|
29390 |
|
29391 | var CoordinateSequenceOperation = function CoordinateSequenceOperation () {};
|
29392 |
|
29393 | CoordinateSequenceOperation.prototype.edit = function edit (geometry, factory) {
|
29394 | if (geometry instanceof LinearRing) {
|
29395 | return factory.createLinearRing(this.edit(geometry.getCoordinateSequence(), geometry))
|
29396 | }
|
29397 | if (geometry instanceof LineString$1) {
|
29398 | return factory.createLineString(this.edit(geometry.getCoordinateSequence(), geometry))
|
29399 | }
|
29400 | if (geometry instanceof Point) {
|
29401 | return factory.createPoint(this.edit(geometry.getCoordinateSequence(), geometry))
|
29402 | }
|
29403 | return geometry
|
29404 | };
|
29405 | CoordinateSequenceOperation.prototype.interfaces_ = function interfaces_ () {
|
29406 | return [GeometryEditor.GeometryEditorOperation]
|
29407 | };
|
29408 | CoordinateSequenceOperation.prototype.getClass = function getClass () {
|
29409 | return CoordinateSequenceOperation
|
29410 | };
|
29411 |
|
29412 | var CoordinateArraySequence = function CoordinateArraySequence () {
|
29413 | var this$1 = this;
|
29414 |
|
29415 | this._dimension = 3;
|
29416 | this._coordinates = null;
|
29417 | if (arguments.length === 1) {
|
29418 | if (arguments[0] instanceof Array) {
|
29419 | this._coordinates = arguments[0];
|
29420 | this._dimension = 3;
|
29421 | } else if (Number.isInteger(arguments[0])) {
|
29422 | var size = arguments[0];
|
29423 | this._coordinates = new Array(size).fill(null);
|
29424 | for (var i = 0; i < size; i++) {
|
29425 | this$1._coordinates[i] = new Coordinate();
|
29426 | }
|
29427 | } else if (hasInterface(arguments[0], CoordinateSequence)) {
|
29428 | var coordSeq = arguments[0];
|
29429 | if (coordSeq === null) {
|
29430 | this._coordinates = new Array(0).fill(null);
|
29431 | return null
|
29432 | }
|
29433 | this._dimension = coordSeq.getDimension();
|
29434 | this._coordinates = new Array(coordSeq.size()).fill(null);
|
29435 | for (var i$1 = 0; i$1 < this._coordinates.length; i$1++) {
|
29436 | this$1._coordinates[i$1] = coordSeq.getCoordinateCopy(i$1);
|
29437 | }
|
29438 | }
|
29439 | } else if (arguments.length === 2) {
|
29440 | if (arguments[0] instanceof Array && Number.isInteger(arguments[1])) {
|
29441 | var coordinates = arguments[0];
|
29442 | var dimension = arguments[1];
|
29443 | this._coordinates = coordinates;
|
29444 | this._dimension = dimension;
|
29445 | if (coordinates === null) { this._coordinates = new Array(0).fill(null); }
|
29446 | } else if (Number.isInteger(arguments[0]) && Number.isInteger(arguments[1])) {
|
29447 | var size$1 = arguments[0];
|
29448 | var dimension$1 = arguments[1];
|
29449 | this._coordinates = new Array(size$1).fill(null);
|
29450 | this._dimension = dimension$1;
|
29451 | for (var i$2 = 0; i$2 < size$1; i$2++) {
|
29452 | this$1._coordinates[i$2] = new Coordinate();
|
29453 | }
|
29454 | }
|
29455 | }
|
29456 | };
|
29457 |
|
29458 | var staticAccessors$18 = { serialVersionUID: { configurable: true } };
|
29459 | CoordinateArraySequence.prototype.setOrdinate = function setOrdinate (index, ordinateIndex, value) {
|
29460 | switch (ordinateIndex) {
|
29461 | case CoordinateSequence.X:
|
29462 | this._coordinates[index].x = value;
|
29463 | break
|
29464 | case CoordinateSequence.Y:
|
29465 | this._coordinates[index].y = value;
|
29466 | break
|
29467 | case CoordinateSequence.Z:
|
29468 | this._coordinates[index].z = value;
|
29469 | break
|
29470 | default:
|
29471 | throw new IllegalArgumentException('invalid ordinateIndex')
|
29472 | }
|
29473 | };
|
29474 | CoordinateArraySequence.prototype.size = function size () {
|
29475 | return this._coordinates.length
|
29476 | };
|
29477 | CoordinateArraySequence.prototype.getOrdinate = function getOrdinate (index, ordinateIndex) {
|
29478 | switch (ordinateIndex) {
|
29479 | case CoordinateSequence.X:
|
29480 | return this._coordinates[index].x
|
29481 | case CoordinateSequence.Y:
|
29482 | return this._coordinates[index].y
|
29483 | case CoordinateSequence.Z:
|
29484 | return this._coordinates[index].z
|
29485 | default:
|
29486 | }
|
29487 | return Double.NaN
|
29488 | };
|
29489 | CoordinateArraySequence.prototype.getCoordinate = function getCoordinate () {
|
29490 | if (arguments.length === 1) {
|
29491 | var i = arguments[0];
|
29492 | return this._coordinates[i]
|
29493 | } else if (arguments.length === 2) {
|
29494 | var index = arguments[0];
|
29495 | var coord = arguments[1];
|
29496 | coord.x = this._coordinates[index].x;
|
29497 | coord.y = this._coordinates[index].y;
|
29498 | coord.z = this._coordinates[index].z;
|
29499 | }
|
29500 | };
|
29501 | CoordinateArraySequence.prototype.getCoordinateCopy = function getCoordinateCopy (i) {
|
29502 | return new Coordinate(this._coordinates[i])
|
29503 | };
|
29504 | CoordinateArraySequence.prototype.getDimension = function getDimension () {
|
29505 | return this._dimension
|
29506 | };
|
29507 | CoordinateArraySequence.prototype.getX = function getX (index) {
|
29508 | return this._coordinates[index].x
|
29509 | };
|
29510 | CoordinateArraySequence.prototype.clone = function clone () {
|
29511 | var this$1 = this;
|
29512 |
|
29513 | var cloneCoordinates = new Array(this.size()).fill(null);
|
29514 | for (var i = 0; i < this._coordinates.length; i++) {
|
29515 | cloneCoordinates[i] = this$1._coordinates[i].clone();
|
29516 | }
|
29517 | return new CoordinateArraySequence(cloneCoordinates, this._dimension)
|
29518 | };
|
29519 | CoordinateArraySequence.prototype.expandEnvelope = function expandEnvelope (env) {
|
29520 | var this$1 = this;
|
29521 |
|
29522 | for (var i = 0; i < this._coordinates.length; i++) {
|
29523 | env.expandToInclude(this$1._coordinates[i]);
|
29524 | }
|
29525 | return env
|
29526 | };
|
29527 | CoordinateArraySequence.prototype.copy = function copy () {
|
29528 | var this$1 = this;
|
29529 |
|
29530 | var cloneCoordinates = new Array(this.size()).fill(null);
|
29531 | for (var i = 0; i < this._coordinates.length; i++) {
|
29532 | cloneCoordinates[i] = this$1._coordinates[i].copy();
|
29533 | }
|
29534 | return new CoordinateArraySequence(cloneCoordinates, this._dimension)
|
29535 | };
|
29536 | CoordinateArraySequence.prototype.toString = function toString () {
|
29537 | var this$1 = this;
|
29538 |
|
29539 | if (this._coordinates.length > 0) {
|
29540 | var strBuf = new StringBuffer(17 * this._coordinates.length);
|
29541 | strBuf.append('(');
|
29542 | strBuf.append(this._coordinates[0]);
|
29543 | for (var i = 1; i < this._coordinates.length; i++) {
|
29544 | strBuf.append(', ');
|
29545 | strBuf.append(this$1._coordinates[i]);
|
29546 | }
|
29547 | strBuf.append(')');
|
29548 | return strBuf.toString()
|
29549 | } else {
|
29550 | return '()'
|
29551 | }
|
29552 | };
|
29553 | CoordinateArraySequence.prototype.getY = function getY (index) {
|
29554 | return this._coordinates[index].y
|
29555 | };
|
29556 | CoordinateArraySequence.prototype.toCoordinateArray = function toCoordinateArray () {
|
29557 | return this._coordinates
|
29558 | };
|
29559 | CoordinateArraySequence.prototype.interfaces_ = function interfaces_ () {
|
29560 | return [CoordinateSequence, Serializable]
|
29561 | };
|
29562 | CoordinateArraySequence.prototype.getClass = function getClass () {
|
29563 | return CoordinateArraySequence
|
29564 | };
|
29565 | staticAccessors$18.serialVersionUID.get = function () { return -915438501601840650 };
|
29566 |
|
29567 | Object.defineProperties( CoordinateArraySequence, staticAccessors$18 );
|
29568 |
|
29569 | var CoordinateArraySequenceFactory = function CoordinateArraySequenceFactory () {};
|
29570 |
|
29571 | var staticAccessors$17 = { serialVersionUID: { configurable: true },instanceObject: { configurable: true } };
|
29572 |
|
29573 | CoordinateArraySequenceFactory.prototype.readResolve = function readResolve () {
|
29574 | return CoordinateArraySequenceFactory.instance()
|
29575 | };
|
29576 | CoordinateArraySequenceFactory.prototype.create = function create () {
|
29577 | if (arguments.length === 1) {
|
29578 | if (arguments[0] instanceof Array) {
|
29579 | var coordinates = arguments[0];
|
29580 | return new CoordinateArraySequence(coordinates)
|
29581 | } else if (hasInterface(arguments[0], CoordinateSequence)) {
|
29582 | var coordSeq = arguments[0];
|
29583 | return new CoordinateArraySequence(coordSeq)
|
29584 | }
|
29585 | } else if (arguments.length === 2) {
|
29586 | var size = arguments[0];
|
29587 | var dimension = arguments[1];
|
29588 | if (dimension > 3) { dimension = 3; }
|
29589 | if (dimension < 2) { return new CoordinateArraySequence(size) }
|
29590 | return new CoordinateArraySequence(size, dimension)
|
29591 | }
|
29592 | };
|
29593 | CoordinateArraySequenceFactory.prototype.interfaces_ = function interfaces_ () {
|
29594 | return [CoordinateSequenceFactory, Serializable]
|
29595 | };
|
29596 | CoordinateArraySequenceFactory.prototype.getClass = function getClass () {
|
29597 | return CoordinateArraySequenceFactory
|
29598 | };
|
29599 | CoordinateArraySequenceFactory.instance = function instance () {
|
29600 | return CoordinateArraySequenceFactory.instanceObject
|
29601 | };
|
29602 |
|
29603 | staticAccessors$17.serialVersionUID.get = function () { return -4099577099607551657 };
|
29604 | staticAccessors$17.instanceObject.get = function () { return new CoordinateArraySequenceFactory() };
|
29605 |
|
29606 | Object.defineProperties( CoordinateArraySequenceFactory, staticAccessors$17 );
|
29607 |
|
29608 |
|
29609 |
|
29610 |
|
29611 |
|
29612 |
|
29613 |
|
29614 |
|
29615 | var HashMap = (function (MapInterface) {
|
29616 | function HashMap () {
|
29617 | MapInterface.call(this);
|
29618 | this.map_ = new Map();
|
29619 | }
|
29620 |
|
29621 | if ( MapInterface ) HashMap.__proto__ = MapInterface;
|
29622 | HashMap.prototype = Object.create( MapInterface && MapInterface.prototype );
|
29623 | HashMap.prototype.constructor = HashMap;
|
29624 | |
29625 |
|
29626 |
|
29627 | HashMap.prototype.get = function get (key) {
|
29628 | return this.map_.get(key) || null
|
29629 | };
|
29630 |
|
29631 | |
29632 |
|
29633 |
|
29634 | HashMap.prototype.put = function put (key, value) {
|
29635 | this.map_.set(key, value);
|
29636 | return value
|
29637 | };
|
29638 |
|
29639 | |
29640 |
|
29641 |
|
29642 | HashMap.prototype.values = function values () {
|
29643 | var arrayList = new ArrayList();
|
29644 | var it = this.map_.values();
|
29645 | var o = it.next();
|
29646 | while (!o.done) {
|
29647 | arrayList.add(o.value);
|
29648 | o = it.next();
|
29649 | }
|
29650 | return arrayList
|
29651 | };
|
29652 |
|
29653 | |
29654 |
|
29655 |
|
29656 | HashMap.prototype.entrySet = function entrySet () {
|
29657 | var hashSet = new HashSet();
|
29658 | this.map_.entries().forEach(function (entry) { return hashSet.add(entry); });
|
29659 | return hashSet
|
29660 | };
|
29661 |
|
29662 | |
29663 |
|
29664 |
|
29665 | HashMap.prototype.size = function size () {
|
29666 | return this.map_.size()
|
29667 | };
|
29668 |
|
29669 | return HashMap;
|
29670 | }(Map$1));
|
29671 |
|
29672 | var PrecisionModel = function PrecisionModel () {
|
29673 | this._modelType = null;
|
29674 | this._scale = null;
|
29675 | if (arguments.length === 0) {
|
29676 | this._modelType = PrecisionModel.FLOATING;
|
29677 | } else if (arguments.length === 1) {
|
29678 | if (arguments[0] instanceof Type) {
|
29679 | var modelType = arguments[0];
|
29680 | this._modelType = modelType;
|
29681 | if (modelType === PrecisionModel.FIXED) {
|
29682 | this.setScale(1.0);
|
29683 | }
|
29684 | } else if (typeof arguments[0] === 'number') {
|
29685 | var scale = arguments[0];
|
29686 | this._modelType = PrecisionModel.FIXED;
|
29687 | this.setScale(scale);
|
29688 | } else if (arguments[0] instanceof PrecisionModel) {
|
29689 | var pm = arguments[0];
|
29690 | this._modelType = pm._modelType;
|
29691 | this._scale = pm._scale;
|
29692 | }
|
29693 | }
|
29694 | };
|
29695 |
|
29696 | var staticAccessors$19 = { serialVersionUID: { configurable: true },maximumPreciseValue: { configurable: true } };
|
29697 | PrecisionModel.prototype.equals = function equals (other) {
|
29698 | if (!(other instanceof PrecisionModel)) {
|
29699 | return false
|
29700 | }
|
29701 | var otherPrecisionModel = other;
|
29702 | return this._modelType === otherPrecisionModel._modelType && this._scale === otherPrecisionModel._scale
|
29703 | };
|
29704 | PrecisionModel.prototype.compareTo = function compareTo (o) {
|
29705 | var other = o;
|
29706 | var sigDigits = this.getMaximumSignificantDigits();
|
29707 | var otherSigDigits = other.getMaximumSignificantDigits();
|
29708 | return new Integer(sigDigits).compareTo(new Integer(otherSigDigits))
|
29709 | };
|
29710 | PrecisionModel.prototype.getScale = function getScale () {
|
29711 | return this._scale
|
29712 | };
|
29713 | PrecisionModel.prototype.isFloating = function isFloating () {
|
29714 | return this._modelType === PrecisionModel.FLOATING || this._modelType === PrecisionModel.FLOATING_SINGLE
|
29715 | };
|
29716 | PrecisionModel.prototype.getType = function getType () {
|
29717 | return this._modelType
|
29718 | };
|
29719 | PrecisionModel.prototype.toString = function toString () {
|
29720 | var description = 'UNKNOWN';
|
29721 | if (this._modelType === PrecisionModel.FLOATING) {
|
29722 | description = 'Floating';
|
29723 | } else if (this._modelType === PrecisionModel.FLOATING_SINGLE) {
|
29724 | description = 'Floating-Single';
|
29725 | } else if (this._modelType === PrecisionModel.FIXED) {
|
29726 | description = 'Fixed (Scale=' + this.getScale() + ')';
|
29727 | }
|
29728 | return description
|
29729 | };
|
29730 | PrecisionModel.prototype.makePrecise = function makePrecise () {
|
29731 | if (typeof arguments[0] === 'number') {
|
29732 | var val = arguments[0];
|
29733 | if (Double.isNaN(val)) { return val }
|
29734 | if (this._modelType === PrecisionModel.FLOATING_SINGLE) {
|
29735 | var floatSingleVal = val;
|
29736 | return floatSingleVal
|
29737 | }
|
29738 | if (this._modelType === PrecisionModel.FIXED) {
|
29739 | return Math.round(val * this._scale) / this._scale
|
29740 | }
|
29741 | return val
|
29742 | } else if (arguments[0] instanceof Coordinate) {
|
29743 | var coord = arguments[0];
|
29744 | if (this._modelType === PrecisionModel.FLOATING) { return null }
|
29745 | coord.x = this.makePrecise(coord.x);
|
29746 | coord.y = this.makePrecise(coord.y);
|
29747 | }
|
29748 | };
|
29749 | PrecisionModel.prototype.getMaximumSignificantDigits = function getMaximumSignificantDigits () {
|
29750 | var maxSigDigits = 16;
|
29751 | if (this._modelType === PrecisionModel.FLOATING) {
|
29752 | maxSigDigits = 16;
|
29753 | } else if (this._modelType === PrecisionModel.FLOATING_SINGLE) {
|
29754 | maxSigDigits = 6;
|
29755 | } else if (this._modelType === PrecisionModel.FIXED) {
|
29756 | maxSigDigits = 1 + Math.trunc(Math.ceil(Math.log(this.getScale()) / Math.log(10)));
|
29757 | }
|
29758 | return maxSigDigits
|
29759 | };
|
29760 | PrecisionModel.prototype.setScale = function setScale (scale) {
|
29761 | this._scale = Math.abs(scale);
|
29762 | };
|
29763 | PrecisionModel.prototype.interfaces_ = function interfaces_ () {
|
29764 | return [Serializable, Comparable]
|
29765 | };
|
29766 | PrecisionModel.prototype.getClass = function getClass () {
|
29767 | return PrecisionModel
|
29768 | };
|
29769 | PrecisionModel.mostPrecise = function mostPrecise (pm1, pm2) {
|
29770 | if (pm1.compareTo(pm2) >= 0) { return pm1 }
|
29771 | return pm2
|
29772 | };
|
29773 | staticAccessors$19.serialVersionUID.get = function () { return 7777263578777803835 };
|
29774 | staticAccessors$19.maximumPreciseValue.get = function () { return 9007199254740992.0 };
|
29775 |
|
29776 | Object.defineProperties( PrecisionModel, staticAccessors$19 );
|
29777 |
|
29778 | var Type = function Type (name) {
|
29779 | this._name = name || null;
|
29780 | Type.nameToTypeMap.put(name, this);
|
29781 | };
|
29782 |
|
29783 | var staticAccessors$1$1 = { serialVersionUID: { configurable: true },nameToTypeMap: { configurable: true } };
|
29784 | Type.prototype.readResolve = function readResolve () {
|
29785 | return Type.nameToTypeMap.get(this._name)
|
29786 | };
|
29787 | Type.prototype.toString = function toString () {
|
29788 | return this._name
|
29789 | };
|
29790 | Type.prototype.interfaces_ = function interfaces_ () {
|
29791 | return [Serializable]
|
29792 | };
|
29793 | Type.prototype.getClass = function getClass () {
|
29794 | return Type
|
29795 | };
|
29796 | staticAccessors$1$1.serialVersionUID.get = function () { return -5528602631731589822 };
|
29797 | staticAccessors$1$1.nameToTypeMap.get = function () { return new HashMap() };
|
29798 |
|
29799 | Object.defineProperties( Type, staticAccessors$1$1 );
|
29800 |
|
29801 | PrecisionModel.Type = Type;
|
29802 | PrecisionModel.FIXED = new Type('FIXED');
|
29803 | PrecisionModel.FLOATING = new Type('FLOATING');
|
29804 | PrecisionModel.FLOATING_SINGLE = new Type('FLOATING SINGLE');
|
29805 |
|
29806 | var GeometryFactory = function GeometryFactory () {
|
29807 | this._precisionModel = new PrecisionModel();
|
29808 | this._SRID = 0;
|
29809 | this._coordinateSequenceFactory = GeometryFactory.getDefaultCoordinateSequenceFactory();
|
29810 |
|
29811 | if (arguments.length === 0) {
|
29812 | } else if (arguments.length === 1) {
|
29813 | if (hasInterface(arguments[0], CoordinateSequenceFactory)) {
|
29814 | this._coordinateSequenceFactory = arguments[0];
|
29815 | } else if (arguments[0] instanceof PrecisionModel) {
|
29816 | this._precisionModel = arguments[0];
|
29817 | }
|
29818 | } else if (arguments.length === 2) {
|
29819 | this._precisionModel = arguments[0];
|
29820 | this._SRID = arguments[1];
|
29821 | } else if (arguments.length === 3) {
|
29822 | this._precisionModel = arguments[0];
|
29823 | this._SRID = arguments[1];
|
29824 | this._coordinateSequenceFactory = arguments[2];
|
29825 | }
|
29826 | };
|
29827 |
|
29828 | var staticAccessors$2 = { serialVersionUID: { configurable: true } };
|
29829 | GeometryFactory.prototype.toGeometry = function toGeometry (envelope) {
|
29830 | if (envelope.isNull()) {
|
29831 | return this.createPoint(null)
|
29832 | }
|
29833 | if (envelope.getMinX() === envelope.getMaxX() && envelope.getMinY() === envelope.getMaxY()) {
|
29834 | return this.createPoint(new Coordinate(envelope.getMinX(), envelope.getMinY()))
|
29835 | }
|
29836 | if (envelope.getMinX() === envelope.getMaxX() || envelope.getMinY() === envelope.getMaxY()) {
|
29837 | return this.createLineString([new Coordinate(envelope.getMinX(), envelope.getMinY()), new Coordinate(envelope.getMaxX(), envelope.getMaxY())])
|
29838 | }
|
29839 | return this.createPolygon(this.createLinearRing([new Coordinate(envelope.getMinX(), envelope.getMinY()), new Coordinate(envelope.getMinX(), envelope.getMaxY()), new Coordinate(envelope.getMaxX(), envelope.getMaxY()), new Coordinate(envelope.getMaxX(), envelope.getMinY()), new Coordinate(envelope.getMinX(), envelope.getMinY())]), null)
|
29840 | };
|
29841 | GeometryFactory.prototype.createLineString = function createLineString (coordinates) {
|
29842 | if (!coordinates) { return new LineString$1(this.getCoordinateSequenceFactory().create([]), this) }
|
29843 | else if (coordinates instanceof Array) { return new LineString$1(this.getCoordinateSequenceFactory().create(coordinates), this) }
|
29844 | else if (hasInterface(coordinates, CoordinateSequence)) { return new LineString$1(coordinates, this) }
|
29845 | };
|
29846 | GeometryFactory.prototype.createMultiLineString = function createMultiLineString () {
|
29847 | if (arguments.length === 0) {
|
29848 | return new MultiLineString(null, this)
|
29849 | } else if (arguments.length === 1) {
|
29850 | var lineStrings = arguments[0];
|
29851 | return new MultiLineString(lineStrings, this)
|
29852 | }
|
29853 | };
|
29854 | GeometryFactory.prototype.buildGeometry = function buildGeometry (geomList) {
|
29855 | var geomClass = null;
|
29856 | var isHeterogeneous = false;
|
29857 | var hasGeometryCollection = false;
|
29858 | for (var i = geomList.iterator(); i.hasNext();) {
|
29859 | var geom = i.next();
|
29860 | var partClass = geom.getClass();
|
29861 | if (geomClass === null) {
|
29862 | geomClass = partClass;
|
29863 | }
|
29864 | if (partClass !== geomClass) {
|
29865 | isHeterogeneous = true;
|
29866 | }
|
29867 | if (geom.isGeometryCollectionOrDerived()) { hasGeometryCollection = true; }
|
29868 | }
|
29869 | if (geomClass === null) {
|
29870 | return this.createGeometryCollection()
|
29871 | }
|
29872 | if (isHeterogeneous || hasGeometryCollection) {
|
29873 | return this.createGeometryCollection(GeometryFactory.toGeometryArray(geomList))
|
29874 | }
|
29875 | var geom0 = geomList.iterator().next();
|
29876 | var isCollection = geomList.size() > 1;
|
29877 | if (isCollection) {
|
29878 | if (geom0 instanceof Polygon) {
|
29879 | return this.createMultiPolygon(GeometryFactory.toPolygonArray(geomList))
|
29880 | } else if (geom0 instanceof LineString$1) {
|
29881 | return this.createMultiLineString(GeometryFactory.toLineStringArray(geomList))
|
29882 | } else if (geom0 instanceof Point) {
|
29883 | return this.createMultiPoint(GeometryFactory.toPointArray(geomList))
|
29884 | }
|
29885 | Assert.shouldNeverReachHere('Unhandled class: ' + geom0.getClass().getName());
|
29886 | }
|
29887 | return geom0
|
29888 | };
|
29889 | GeometryFactory.prototype.createMultiPointFromCoords = function createMultiPointFromCoords (coordinates) {
|
29890 | return this.createMultiPoint(coordinates !== null ? this.getCoordinateSequenceFactory().create(coordinates) : null)
|
29891 | };
|
29892 | GeometryFactory.prototype.createPoint = function createPoint () {
|
29893 | if (arguments.length === 0) {
|
29894 | return this.createPoint(this.getCoordinateSequenceFactory().create([]))
|
29895 | } else if (arguments.length === 1) {
|
29896 | if (arguments[0] instanceof Coordinate) {
|
29897 | var coordinate = arguments[0];
|
29898 | return this.createPoint(coordinate !== null ? this.getCoordinateSequenceFactory().create([coordinate]) : null)
|
29899 | } else if (hasInterface(arguments[0], CoordinateSequence)) {
|
29900 | var coordinates = arguments[0];
|
29901 | return new Point(coordinates, this)
|
29902 | }
|
29903 | }
|
29904 | };
|
29905 | GeometryFactory.prototype.getCoordinateSequenceFactory = function getCoordinateSequenceFactory () {
|
29906 | return this._coordinateSequenceFactory
|
29907 | };
|
29908 | GeometryFactory.prototype.createPolygon = function createPolygon () {
|
29909 | if (arguments.length === 0) {
|
29910 | return new Polygon(null, null, this)
|
29911 | } else if (arguments.length === 1) {
|
29912 | if (hasInterface(arguments[0], CoordinateSequence)) {
|
29913 | var coordinates = arguments[0];
|
29914 | return this.createPolygon(this.createLinearRing(coordinates))
|
29915 | } else if (arguments[0] instanceof Array) {
|
29916 | var coordinates$1 = arguments[0];
|
29917 | return this.createPolygon(this.createLinearRing(coordinates$1))
|
29918 | } else if (arguments[0] instanceof LinearRing) {
|
29919 | var shell = arguments[0];
|
29920 | return this.createPolygon(shell, null)
|
29921 | }
|
29922 | } else if (arguments.length === 2) {
|
29923 | var shell$1 = arguments[0];
|
29924 | var holes = arguments[1];
|
29925 | return new Polygon(shell$1, holes, this)
|
29926 | }
|
29927 | };
|
29928 | GeometryFactory.prototype.getSRID = function getSRID () {
|
29929 | return this._SRID
|
29930 | };
|
29931 | GeometryFactory.prototype.createGeometryCollection = function createGeometryCollection () {
|
29932 | if (arguments.length === 0) {
|
29933 | return new GeometryCollection(null, this)
|
29934 | } else if (arguments.length === 1) {
|
29935 | var geometries = arguments[0];
|
29936 | return new GeometryCollection(geometries, this)
|
29937 | }
|
29938 | };
|
29939 | GeometryFactory.prototype.createGeometry = function createGeometry (g) {
|
29940 | var editor = new GeometryEditor(this);
|
29941 | return editor.edit(g, {
|
29942 | edit: function () {
|
29943 | if (arguments.length === 2) {
|
29944 | var coordSeq = arguments[0];
|
29945 |
|
29946 | return this._coordinateSequenceFactory.create(coordSeq)
|
29947 | }
|
29948 | }
|
29949 | })
|
29950 | };
|
29951 | GeometryFactory.prototype.getPrecisionModel = function getPrecisionModel () {
|
29952 | return this._precisionModel
|
29953 | };
|
29954 | GeometryFactory.prototype.createLinearRing = function createLinearRing () {
|
29955 | if (arguments.length === 0) {
|
29956 | return this.createLinearRing(this.getCoordinateSequenceFactory().create([]))
|
29957 | } else if (arguments.length === 1) {
|
29958 | if (arguments[0] instanceof Array) {
|
29959 | var coordinates = arguments[0];
|
29960 | return this.createLinearRing(coordinates !== null ? this.getCoordinateSequenceFactory().create(coordinates) : null)
|
29961 | } else if (hasInterface(arguments[0], CoordinateSequence)) {
|
29962 | var coordinates$1 = arguments[0];
|
29963 | return new LinearRing(coordinates$1, this)
|
29964 | }
|
29965 | }
|
29966 | };
|
29967 | GeometryFactory.prototype.createMultiPolygon = function createMultiPolygon () {
|
29968 | if (arguments.length === 0) {
|
29969 | return new MultiPolygon(null, this)
|
29970 | } else if (arguments.length === 1) {
|
29971 | var polygons = arguments[0];
|
29972 | return new MultiPolygon(polygons, this)
|
29973 | }
|
29974 | };
|
29975 | GeometryFactory.prototype.createMultiPoint = function createMultiPoint () {
|
29976 | var this$1 = this;
|
29977 |
|
29978 | if (arguments.length === 0) {
|
29979 | return new MultiPoint(null, this)
|
29980 | } else if (arguments.length === 1) {
|
29981 | if (arguments[0] instanceof Array) {
|
29982 | var point = arguments[0];
|
29983 | return new MultiPoint(point, this)
|
29984 | } else if (arguments[0] instanceof Array) {
|
29985 | var coordinates = arguments[0];
|
29986 | return this.createMultiPoint(coordinates !== null ? this.getCoordinateSequenceFactory().create(coordinates) : null)
|
29987 | } else if (hasInterface(arguments[0], CoordinateSequence)) {
|
29988 | var coordinates$1 = arguments[0];
|
29989 | if (coordinates$1 === null) {
|
29990 | return this.createMultiPoint(new Array(0).fill(null))
|
29991 | }
|
29992 | var points = new Array(coordinates$1.size()).fill(null);
|
29993 | for (var i = 0; i < coordinates$1.size(); i++) {
|
29994 | var ptSeq = this$1.getCoordinateSequenceFactory().create(1, coordinates$1.getDimension());
|
29995 | CoordinateSequences.copy(coordinates$1, i, ptSeq, 0, 1);
|
29996 | points[i] = this$1.createPoint(ptSeq);
|
29997 | }
|
29998 | return this.createMultiPoint(points)
|
29999 | }
|
30000 | }
|
30001 | };
|
30002 | GeometryFactory.prototype.interfaces_ = function interfaces_ () {
|
30003 | return [Serializable]
|
30004 | };
|
30005 | GeometryFactory.prototype.getClass = function getClass () {
|
30006 | return GeometryFactory
|
30007 | };
|
30008 | GeometryFactory.toMultiPolygonArray = function toMultiPolygonArray (multiPolygons) {
|
30009 | var multiPolygonArray = new Array(multiPolygons.size()).fill(null);
|
30010 | return multiPolygons.toArray(multiPolygonArray)
|
30011 | };
|
30012 | GeometryFactory.toGeometryArray = function toGeometryArray (geometries) {
|
30013 | if (geometries === null) { return null }
|
30014 | var geometryArray = new Array(geometries.size()).fill(null);
|
30015 | return geometries.toArray(geometryArray)
|
30016 | };
|
30017 | GeometryFactory.getDefaultCoordinateSequenceFactory = function getDefaultCoordinateSequenceFactory () {
|
30018 | return CoordinateArraySequenceFactory.instance()
|
30019 | };
|
30020 | GeometryFactory.toMultiLineStringArray = function toMultiLineStringArray (multiLineStrings) {
|
30021 | var multiLineStringArray = new Array(multiLineStrings.size()).fill(null);
|
30022 | return multiLineStrings.toArray(multiLineStringArray)
|
30023 | };
|
30024 | GeometryFactory.toLineStringArray = function toLineStringArray (lineStrings) {
|
30025 | var lineStringArray = new Array(lineStrings.size()).fill(null);
|
30026 | return lineStrings.toArray(lineStringArray)
|
30027 | };
|
30028 | GeometryFactory.toMultiPointArray = function toMultiPointArray (multiPoints) {
|
30029 | var multiPointArray = new Array(multiPoints.size()).fill(null);
|
30030 | return multiPoints.toArray(multiPointArray)
|
30031 | };
|
30032 | GeometryFactory.toLinearRingArray = function toLinearRingArray (linearRings) {
|
30033 | var linearRingArray = new Array(linearRings.size()).fill(null);
|
30034 | return linearRings.toArray(linearRingArray)
|
30035 | };
|
30036 | GeometryFactory.toPointArray = function toPointArray (points) {
|
30037 | var pointArray = new Array(points.size()).fill(null);
|
30038 | return points.toArray(pointArray)
|
30039 | };
|
30040 | GeometryFactory.toPolygonArray = function toPolygonArray (polygons) {
|
30041 | var polygonArray = new Array(polygons.size()).fill(null);
|
30042 | return polygons.toArray(polygonArray)
|
30043 | };
|
30044 | GeometryFactory.createPointFromInternalCoord = function createPointFromInternalCoord (coord, exemplar) {
|
30045 | exemplar.getPrecisionModel().makePrecise(coord);
|
30046 | return exemplar.getFactory().createPoint(coord)
|
30047 | };
|
30048 | staticAccessors$2.serialVersionUID.get = function () { return -6820524753094095635 };
|
30049 |
|
30050 | Object.defineProperties( GeometryFactory, staticAccessors$2 );
|
30051 |
|
30052 | var geometryTypes = ['Point', 'MultiPoint', 'LineString', 'MultiLineString', 'Polygon', 'MultiPolygon'];
|
30053 |
|
30054 |
|
30055 |
|
30056 |
|
30057 |
|
30058 |
|
30059 |
|
30060 |
|
30061 |
|
30062 |
|
30063 |
|
30064 |
|
30065 |
|
30066 |
|
30067 | var GeoJSONParser = function GeoJSONParser (geometryFactory) {
|
30068 | this.geometryFactory = geometryFactory || new GeometryFactory();
|
30069 | };
|
30070 |
|
30071 |
|
30072 |
|
30073 |
|
30074 |
|
30075 |
|
30076 |
|
30077 |
|
30078 | GeoJSONParser.prototype.read = function read (json) {
|
30079 | var obj;
|
30080 | if (typeof json === 'string') {
|
30081 | obj = JSON.parse(json);
|
30082 | } else {
|
30083 | obj = json;
|
30084 | }
|
30085 |
|
30086 | var type = obj.type;
|
30087 |
|
30088 | if (!parse[type]) {
|
30089 | throw new Error('Unknown GeoJSON type: ' + obj.type)
|
30090 | }
|
30091 |
|
30092 | if (geometryTypes.indexOf(type) !== -1) {
|
30093 | return parse[type].apply(this, [obj.coordinates])
|
30094 | } else if (type === 'GeometryCollection') {
|
30095 | return parse[type].apply(this, [obj.geometries])
|
30096 | }
|
30097 |
|
30098 |
|
30099 | return parse[type].apply(this, [obj])
|
30100 | };
|
30101 |
|
30102 |
|
30103 |
|
30104 |
|
30105 |
|
30106 |
|
30107 |
|
30108 |
|
30109 |
|
30110 | GeoJSONParser.prototype.write = function write (geometry) {
|
30111 | var type = geometry.getGeometryType();
|
30112 |
|
30113 | if (!extract$1$1[type]) {
|
30114 | throw new Error('Geometry is not supported')
|
30115 | }
|
30116 |
|
30117 | return extract$1$1[type].apply(this, [geometry])
|
30118 | };
|
30119 |
|
30120 | var parse = {
|
30121 | |
30122 |
|
30123 |
|
30124 |
|
30125 |
|
30126 |
|
30127 |
|
30128 |
|
30129 | Feature: function (obj) {
|
30130 | var feature = {};
|
30131 |
|
30132 |
|
30133 | for (var key in obj) {
|
30134 | feature[key] = obj[key];
|
30135 | }
|
30136 |
|
30137 |
|
30138 | if (obj.geometry) {
|
30139 | var type = obj.geometry.type;
|
30140 | if (!parse[type]) {
|
30141 | throw new Error('Unknown GeoJSON type: ' + obj.type)
|
30142 | }
|
30143 | feature.geometry = this.read(obj.geometry);
|
30144 | }
|
30145 |
|
30146 |
|
30147 | if (obj.bbox) {
|
30148 | feature.bbox = parse.bbox.apply(this, [obj.bbox]);
|
30149 | }
|
30150 |
|
30151 | return feature
|
30152 | },
|
30153 |
|
30154 | |
30155 |
|
30156 |
|
30157 |
|
30158 |
|
30159 |
|
30160 |
|
30161 |
|
30162 | FeatureCollection: function (obj) {
|
30163 | var this$1 = this;
|
30164 |
|
30165 | var featureCollection = {};
|
30166 |
|
30167 | if (obj.features) {
|
30168 | featureCollection.features = [];
|
30169 |
|
30170 | for (var i = 0; i < obj.features.length; ++i) {
|
30171 | featureCollection.features.push(this$1.read(obj.features[i]));
|
30172 | }
|
30173 | }
|
30174 |
|
30175 | if (obj.bbox) {
|
30176 | featureCollection.bbox = this.parse.bbox.apply(this, [obj.bbox]);
|
30177 | }
|
30178 |
|
30179 | return featureCollection
|
30180 | },
|
30181 |
|
30182 | |
30183 |
|
30184 |
|
30185 |
|
30186 |
|
30187 |
|
30188 |
|
30189 |
|
30190 | coordinates: function (array) {
|
30191 | var coordinates = [];
|
30192 | for (var i = 0; i < array.length; ++i) {
|
30193 | var sub = array[i];
|
30194 | coordinates.push(new Coordinate(sub[0], sub[1]));
|
30195 | }
|
30196 | return coordinates
|
30197 | },
|
30198 |
|
30199 | |
30200 |
|
30201 |
|
30202 |
|
30203 |
|
30204 |
|
30205 |
|
30206 |
|
30207 | bbox: function (array) {
|
30208 | return this.geometryFactory.createLinearRing([
|
30209 | new Coordinate(array[0], array[1]),
|
30210 | new Coordinate(array[2], array[1]),
|
30211 | new Coordinate(array[2], array[3]),
|
30212 | new Coordinate(array[0], array[3]),
|
30213 | new Coordinate(array[0], array[1])
|
30214 | ])
|
30215 | },
|
30216 |
|
30217 | |
30218 |
|
30219 |
|
30220 |
|
30221 |
|
30222 |
|
30223 |
|
30224 |
|
30225 | Point: function (array) {
|
30226 | var coordinate = new Coordinate(array[0], array[1]);
|
30227 | return this.geometryFactory.createPoint(coordinate)
|
30228 | },
|
30229 |
|
30230 | |
30231 |
|
30232 |
|
30233 |
|
30234 |
|
30235 |
|
30236 |
|
30237 |
|
30238 | MultiPoint: function (array) {
|
30239 | var this$1 = this;
|
30240 |
|
30241 | var points = [];
|
30242 | for (var i = 0; i < array.length; ++i) {
|
30243 | points.push(parse.Point.apply(this$1, [array[i]]));
|
30244 | }
|
30245 | return this.geometryFactory.createMultiPoint(points)
|
30246 | },
|
30247 |
|
30248 | |
30249 |
|
30250 |
|
30251 |
|
30252 |
|
30253 |
|
30254 |
|
30255 |
|
30256 | LineString: function (array) {
|
30257 | var coordinates = parse.coordinates.apply(this, [array]);
|
30258 | return this.geometryFactory.createLineString(coordinates)
|
30259 | },
|
30260 |
|
30261 | |
30262 |
|
30263 |
|
30264 |
|
30265 |
|
30266 |
|
30267 |
|
30268 |
|
30269 | MultiLineString: function (array) {
|
30270 | var this$1 = this;
|
30271 |
|
30272 | var lineStrings = [];
|
30273 | for (var i = 0; i < array.length; ++i) {
|
30274 | lineStrings.push(parse.LineString.apply(this$1, [array[i]]));
|
30275 | }
|
30276 | return this.geometryFactory.createMultiLineString(lineStrings)
|
30277 | },
|
30278 |
|
30279 | |
30280 |
|
30281 |
|
30282 |
|
30283 |
|
30284 |
|
30285 |
|
30286 |
|
30287 | Polygon: function (array) {
|
30288 | var this$1 = this;
|
30289 |
|
30290 | var shellCoordinates = parse.coordinates.apply(this, [array[0]]);
|
30291 | var shell = this.geometryFactory.createLinearRing(shellCoordinates);
|
30292 | var holes = [];
|
30293 | for (var i = 1; i < array.length; ++i) {
|
30294 | var hole = array[i];
|
30295 | var coordinates = parse.coordinates.apply(this$1, [hole]);
|
30296 | var linearRing = this$1.geometryFactory.createLinearRing(coordinates);
|
30297 | holes.push(linearRing);
|
30298 | }
|
30299 | return this.geometryFactory.createPolygon(shell, holes)
|
30300 | },
|
30301 |
|
30302 | |
30303 |
|
30304 |
|
30305 |
|
30306 |
|
30307 |
|
30308 |
|
30309 |
|
30310 | MultiPolygon: function (array) {
|
30311 | var this$1 = this;
|
30312 |
|
30313 | var polygons = [];
|
30314 | for (var i = 0; i < array.length; ++i) {
|
30315 | var polygon = array[i];
|
30316 | polygons.push(parse.Polygon.apply(this$1, [polygon]));
|
30317 | }
|
30318 | return this.geometryFactory.createMultiPolygon(polygons)
|
30319 | },
|
30320 |
|
30321 | |
30322 |
|
30323 |
|
30324 |
|
30325 |
|
30326 |
|
30327 |
|
30328 |
|
30329 | GeometryCollection: function (array) {
|
30330 | var this$1 = this;
|
30331 |
|
30332 | var geometries = [];
|
30333 | for (var i = 0; i < array.length; ++i) {
|
30334 | var geometry = array[i];
|
30335 | geometries.push(this$1.read(geometry));
|
30336 | }
|
30337 | return this.geometryFactory.createGeometryCollection(geometries)
|
30338 | }
|
30339 | };
|
30340 |
|
30341 | var extract$1$1 = {
|
30342 | |
30343 |
|
30344 |
|
30345 |
|
30346 |
|
30347 |
|
30348 |
|
30349 |
|
30350 | coordinate: function (coordinate) {
|
30351 | return [coordinate.x, coordinate.y]
|
30352 | },
|
30353 |
|
30354 | |
30355 |
|
30356 |
|
30357 |
|
30358 |
|
30359 |
|
30360 |
|
30361 |
|
30362 | Point: function (point) {
|
30363 | var array = extract$1$1.coordinate.apply(this, [point.getCoordinate()]);
|
30364 | return {
|
30365 | type: 'Point',
|
30366 | coordinates: array
|
30367 | }
|
30368 | },
|
30369 |
|
30370 | |
30371 |
|
30372 |
|
30373 |
|
30374 |
|
30375 |
|
30376 |
|
30377 |
|
30378 | MultiPoint: function (multipoint) {
|
30379 | var this$1 = this;
|
30380 |
|
30381 | var array = [];
|
30382 | for (var i = 0; i < multipoint._geometries.length; ++i) {
|
30383 | var point = multipoint._geometries[i];
|
30384 | var geoJson = extract$1$1.Point.apply(this$1, [point]);
|
30385 | array.push(geoJson.coordinates);
|
30386 | }
|
30387 | return {
|
30388 | type: 'MultiPoint',
|
30389 | coordinates: array
|
30390 | }
|
30391 | },
|
30392 |
|
30393 | |
30394 |
|
30395 |
|
30396 |
|
30397 |
|
30398 |
|
30399 |
|
30400 |
|
30401 | LineString: function (linestring) {
|
30402 | var this$1 = this;
|
30403 |
|
30404 | var array = [];
|
30405 | var coordinates = linestring.getCoordinates();
|
30406 | for (var i = 0; i < coordinates.length; ++i) {
|
30407 | var coordinate = coordinates[i];
|
30408 | array.push(extract$1$1.coordinate.apply(this$1, [coordinate]));
|
30409 | }
|
30410 | return {
|
30411 | type: 'LineString',
|
30412 | coordinates: array
|
30413 | }
|
30414 | },
|
30415 |
|
30416 | |
30417 |
|
30418 |
|
30419 |
|
30420 |
|
30421 |
|
30422 |
|
30423 |
|
30424 | MultiLineString: function (multilinestring) {
|
30425 | var this$1 = this;
|
30426 |
|
30427 | var array = [];
|
30428 | for (var i = 0; i < multilinestring._geometries.length; ++i) {
|
30429 | var linestring = multilinestring._geometries[i];
|
30430 | var geoJson = extract$1$1.LineString.apply(this$1, [linestring]);
|
30431 | array.push(geoJson.coordinates);
|
30432 | }
|
30433 | return {
|
30434 | type: 'MultiLineString',
|
30435 | coordinates: array
|
30436 | }
|
30437 | },
|
30438 |
|
30439 | |
30440 |
|
30441 |
|
30442 |
|
30443 |
|
30444 |
|
30445 |
|
30446 |
|
30447 | Polygon: function (polygon) {
|
30448 | var this$1 = this;
|
30449 |
|
30450 | var array = [];
|
30451 | var shellGeoJson = extract$1$1.LineString.apply(this, [polygon._shell]);
|
30452 | array.push(shellGeoJson.coordinates);
|
30453 | for (var i = 0; i < polygon._holes.length; ++i) {
|
30454 | var hole = polygon._holes[i];
|
30455 | var holeGeoJson = extract$1$1.LineString.apply(this$1, [hole]);
|
30456 | array.push(holeGeoJson.coordinates);
|
30457 | }
|
30458 | return {
|
30459 | type: 'Polygon',
|
30460 | coordinates: array
|
30461 | }
|
30462 | },
|
30463 |
|
30464 | |
30465 |
|
30466 |
|
30467 |
|
30468 |
|
30469 |
|
30470 |
|
30471 |
|
30472 | MultiPolygon: function (multipolygon) {
|
30473 | var this$1 = this;
|
30474 |
|
30475 | var array = [];
|
30476 | for (var i = 0; i < multipolygon._geometries.length; ++i) {
|
30477 | var polygon = multipolygon._geometries[i];
|
30478 | var geoJson = extract$1$1.Polygon.apply(this$1, [polygon]);
|
30479 | array.push(geoJson.coordinates);
|
30480 | }
|
30481 | return {
|
30482 | type: 'MultiPolygon',
|
30483 | coordinates: array
|
30484 | }
|
30485 | },
|
30486 |
|
30487 | |
30488 |
|
30489 |
|
30490 |
|
30491 |
|
30492 |
|
30493 |
|
30494 |
|
30495 | GeometryCollection: function (collection) {
|
30496 | var this$1 = this;
|
30497 |
|
30498 | var array = [];
|
30499 | for (var i = 0; i < collection._geometries.length; ++i) {
|
30500 | var geometry = collection._geometries[i];
|
30501 | var type = geometry.getGeometryType();
|
30502 | array.push(extract$1$1[type].apply(this$1, [geometry]));
|
30503 | }
|
30504 | return {
|
30505 | type: 'GeometryCollection',
|
30506 | geometries: array
|
30507 | }
|
30508 | }
|
30509 | };
|
30510 |
|
30511 |
|
30512 |
|
30513 |
|
30514 |
|
30515 |
|
30516 |
|
30517 |
|
30518 |
|
30519 |
|
30520 |
|
30521 |
|
30522 |
|
30523 |
|
30524 | var GeoJSONReader = function GeoJSONReader (geometryFactory) {
|
30525 | this.geometryFactory = geometryFactory || new GeometryFactory();
|
30526 | this.precisionModel = this.geometryFactory.getPrecisionModel();
|
30527 | this.parser = new GeoJSONParser(this.geometryFactory);
|
30528 | };
|
30529 |
|
30530 |
|
30531 |
|
30532 |
|
30533 |
|
30534 |
|
30535 |
|
30536 |
|
30537 |
|
30538 | GeoJSONReader.prototype.read = function read (geoJson) {
|
30539 | var geometry = this.parser.read(geoJson);
|
30540 |
|
30541 | if (this.precisionModel.getType() === PrecisionModel.FIXED) {
|
30542 | this.reducePrecision(geometry);
|
30543 | }
|
30544 |
|
30545 | return geometry
|
30546 | };
|
30547 |
|
30548 |
|
30549 | GeoJSONReader.prototype.reducePrecision = function reducePrecision (geometry) {
|
30550 | var this$1 = this;
|
30551 |
|
30552 | var i, len;
|
30553 |
|
30554 | if (geometry.coordinate) {
|
30555 | this.precisionModel.makePrecise(geometry.coordinate);
|
30556 | } else if (geometry.points) {
|
30557 | for (i = 0, len = geometry.points.length; i < len; i++) {
|
30558 | this$1.precisionModel.makePrecise(geometry.points[i]);
|
30559 | }
|
30560 | } else if (geometry.geometries) {
|
30561 | for (i = 0, len = geometry.geometries.length; i < len; i++) {
|
30562 | this$1.reducePrecision(geometry.geometries[i]);
|
30563 | }
|
30564 | }
|
30565 | };
|
30566 |
|
30567 |
|
30568 |
|
30569 |
|
30570 |
|
30571 |
|
30572 |
|
30573 |
|
30574 |
|
30575 |
|
30576 |
|
30577 |
|
30578 |
|
30579 |
|
30580 |
|
30581 |
|
30582 |
|
30583 |
|
30584 |
|
30585 | var GeoJSONWriter = function GeoJSONWriter () {
|
30586 | this.parser = new GeoJSONParser(this.geometryFactory);
|
30587 | };
|
30588 |
|
30589 |
|
30590 |
|
30591 |
|
30592 |
|
30593 |
|
30594 |
|
30595 |
|
30596 | GeoJSONWriter.prototype.write = function write (geometry) {
|
30597 | return this.parser.write(geometry)
|
30598 | };
|
30599 |
|
30600 |
|
30601 |
|
30602 |
|
30603 |
|
30604 | var Position = function Position () {};
|
30605 |
|
30606 | var staticAccessors$20 = { ON: { configurable: true },LEFT: { configurable: true },RIGHT: { configurable: true } };
|
30607 |
|
30608 | Position.prototype.interfaces_ = function interfaces_ () {
|
30609 | return []
|
30610 | };
|
30611 | Position.prototype.getClass = function getClass () {
|
30612 | return Position
|
30613 | };
|
30614 | Position.opposite = function opposite (position) {
|
30615 | if (position === Position.LEFT) { return Position.RIGHT }
|
30616 | if (position === Position.RIGHT) { return Position.LEFT }
|
30617 | return position
|
30618 | };
|
30619 | staticAccessors$20.ON.get = function () { return 0 };
|
30620 | staticAccessors$20.LEFT.get = function () { return 1 };
|
30621 | staticAccessors$20.RIGHT.get = function () { return 2 };
|
30622 |
|
30623 | Object.defineProperties( Position, staticAccessors$20 );
|
30624 |
|
30625 |
|
30626 |
|
30627 |
|
30628 |
|
30629 |
|
30630 |
|
30631 | function EmptyStackException (message) {
|
30632 | this.message = message || '';
|
30633 | }
|
30634 | EmptyStackException.prototype = new Error();
|
30635 |
|
30636 |
|
30637 |
|
30638 |
|
30639 | EmptyStackException.prototype.name = 'EmptyStackException';
|
30640 |
|
30641 |
|
30642 |
|
30643 |
|
30644 |
|
30645 |
|
30646 |
|
30647 |
|
30648 | function Stack () {
|
30649 | |
30650 |
|
30651 |
|
30652 |
|
30653 | this.array_ = [];
|
30654 | }
|
30655 | Stack.prototype = new List();
|
30656 |
|
30657 |
|
30658 |
|
30659 |
|
30660 | Stack.prototype.add = function (e) {
|
30661 | this.array_.push(e);
|
30662 | return true
|
30663 | };
|
30664 |
|
30665 |
|
30666 |
|
30667 |
|
30668 | Stack.prototype.get = function (index) {
|
30669 | if (index < 0 || index >= this.size()) {
|
30670 | throw new Error()
|
30671 | }
|
30672 |
|
30673 | return this.array_[index]
|
30674 | };
|
30675 |
|
30676 |
|
30677 |
|
30678 |
|
30679 |
|
30680 |
|
30681 | Stack.prototype.push = function (e) {
|
30682 | this.array_.push(e);
|
30683 | return e
|
30684 | };
|
30685 |
|
30686 |
|
30687 |
|
30688 |
|
30689 |
|
30690 |
|
30691 | Stack.prototype.pop = function (e) {
|
30692 | if (this.array_.length === 0) {
|
30693 | throw new EmptyStackException()
|
30694 | }
|
30695 |
|
30696 | return this.array_.pop()
|
30697 | };
|
30698 |
|
30699 |
|
30700 |
|
30701 |
|
30702 |
|
30703 |
|
30704 | Stack.prototype.peek = function () {
|
30705 | if (this.array_.length === 0) {
|
30706 | throw new EmptyStackException()
|
30707 | }
|
30708 |
|
30709 | return this.array_[this.array_.length - 1]
|
30710 | };
|
30711 |
|
30712 |
|
30713 |
|
30714 |
|
30715 |
|
30716 |
|
30717 | Stack.prototype.empty = function () {
|
30718 | if (this.array_.length === 0) {
|
30719 | return true
|
30720 | } else {
|
30721 | return false
|
30722 | }
|
30723 | };
|
30724 |
|
30725 |
|
30726 |
|
30727 |
|
30728 | Stack.prototype.isEmpty = function () {
|
30729 | return this.empty()
|
30730 | };
|
30731 |
|
30732 |
|
30733 |
|
30734 |
|
30735 |
|
30736 |
|
30737 |
|
30738 |
|
30739 |
|
30740 |
|
30741 |
|
30742 |
|
30743 |
|
30744 |
|
30745 |
|
30746 | Stack.prototype.search = function (o) {
|
30747 | return this.array_.indexOf(o)
|
30748 | };
|
30749 |
|
30750 |
|
30751 |
|
30752 |
|
30753 |
|
30754 | Stack.prototype.size = function () {
|
30755 | return this.array_.length
|
30756 | };
|
30757 |
|
30758 |
|
30759 |
|
30760 |
|
30761 | Stack.prototype.toArray = function () {
|
30762 | var this$1 = this;
|
30763 |
|
30764 | var array = [];
|
30765 |
|
30766 | for (var i = 0, len = this.array_.length; i < len; i++) {
|
30767 | array.push(this$1.array_[i]);
|
30768 | }
|
30769 |
|
30770 | return array
|
30771 | };
|
30772 |
|
30773 | var RightmostEdgeFinder = function RightmostEdgeFinder () {
|
30774 | this._minIndex = -1;
|
30775 | this._minCoord = null;
|
30776 | this._minDe = null;
|
30777 | this._orientedDe = null;
|
30778 | };
|
30779 | RightmostEdgeFinder.prototype.getCoordinate = function getCoordinate () {
|
30780 | return this._minCoord
|
30781 | };
|
30782 | RightmostEdgeFinder.prototype.getRightmostSide = function getRightmostSide (de, index) {
|
30783 | var side = this.getRightmostSideOfSegment(de, index);
|
30784 | if (side < 0) { side = this.getRightmostSideOfSegment(de, index - 1); }
|
30785 | if (side < 0) {
|
30786 | this._minCoord = null;
|
30787 | this.checkForRightmostCoordinate(de);
|
30788 | }
|
30789 | return side
|
30790 | };
|
30791 | RightmostEdgeFinder.prototype.findRightmostEdgeAtVertex = function findRightmostEdgeAtVertex () {
|
30792 | var pts = this._minDe.getEdge().getCoordinates();
|
30793 | Assert.isTrue(this._minIndex > 0 && this._minIndex < pts.length, 'rightmost point expected to be interior vertex of edge');
|
30794 | var pPrev = pts[this._minIndex - 1];
|
30795 | var pNext = pts[this._minIndex + 1];
|
30796 | var orientation = CGAlgorithms.computeOrientation(this._minCoord, pNext, pPrev);
|
30797 | var usePrev = false;
|
30798 | if (pPrev.y < this._minCoord.y && pNext.y < this._minCoord.y && orientation === CGAlgorithms.COUNTERCLOCKWISE) {
|
30799 | usePrev = true;
|
30800 | } else if (pPrev.y > this._minCoord.y && pNext.y > this._minCoord.y && orientation === CGAlgorithms.CLOCKWISE) {
|
30801 | usePrev = true;
|
30802 | }
|
30803 | if (usePrev) {
|
30804 | this._minIndex = this._minIndex - 1;
|
30805 | }
|
30806 | };
|
30807 | RightmostEdgeFinder.prototype.getRightmostSideOfSegment = function getRightmostSideOfSegment (de, i) {
|
30808 | var e = de.getEdge();
|
30809 | var coord = e.getCoordinates();
|
30810 | if (i < 0 || i + 1 >= coord.length) { return -1 }
|
30811 | if (coord[i].y === coord[i + 1].y) { return -1 }
|
30812 | var pos = Position.LEFT;
|
30813 | if (coord[i].y < coord[i + 1].y) { pos = Position.RIGHT; }
|
30814 | return pos
|
30815 | };
|
30816 | RightmostEdgeFinder.prototype.getEdge = function getEdge () {
|
30817 | return this._orientedDe
|
30818 | };
|
30819 | RightmostEdgeFinder.prototype.checkForRightmostCoordinate = function checkForRightmostCoordinate (de) {
|
30820 | var this$1 = this;
|
30821 |
|
30822 | var coord = de.getEdge().getCoordinates();
|
30823 | for (var i = 0; i < coord.length - 1; i++) {
|
30824 | if (this$1._minCoord === null || coord[i].x > this$1._minCoord.x) {
|
30825 | this$1._minDe = de;
|
30826 | this$1._minIndex = i;
|
30827 | this$1._minCoord = coord[i];
|
30828 | }
|
30829 | }
|
30830 | };
|
30831 | RightmostEdgeFinder.prototype.findRightmostEdgeAtNode = function findRightmostEdgeAtNode () {
|
30832 | var node = this._minDe.getNode();
|
30833 | var star = node.getEdges();
|
30834 | this._minDe = star.getRightmostEdge();
|
30835 | if (!this._minDe.isForward()) {
|
30836 | this._minDe = this._minDe.getSym();
|
30837 | this._minIndex = this._minDe.getEdge().getCoordinates().length - 1;
|
30838 | }
|
30839 | };
|
30840 | RightmostEdgeFinder.prototype.findEdge = function findEdge (dirEdgeList) {
|
30841 | var this$1 = this;
|
30842 |
|
30843 | for (var i = dirEdgeList.iterator(); i.hasNext();) {
|
30844 | var de = i.next();
|
30845 | if (!de.isForward()) { continue }
|
30846 | this$1.checkForRightmostCoordinate(de);
|
30847 | }
|
30848 | Assert.isTrue(this._minIndex !== 0 || this._minCoord.equals(this._minDe.getCoordinate()), 'inconsistency in rightmost processing');
|
30849 | if (this._minIndex === 0) {
|
30850 | this.findRightmostEdgeAtNode();
|
30851 | } else {
|
30852 | this.findRightmostEdgeAtVertex();
|
30853 | }
|
30854 | this._orientedDe = this._minDe;
|
30855 | var rightmostSide = this.getRightmostSide(this._minDe, this._minIndex);
|
30856 | if (rightmostSide === Position.LEFT) {
|
30857 | this._orientedDe = this._minDe.getSym();
|
30858 | }
|
30859 | };
|
30860 | RightmostEdgeFinder.prototype.interfaces_ = function interfaces_ () {
|
30861 | return []
|
30862 | };
|
30863 | RightmostEdgeFinder.prototype.getClass = function getClass () {
|
30864 | return RightmostEdgeFinder
|
30865 | };
|
30866 |
|
30867 | var TopologyException = (function (RuntimeException$$1) {
|
30868 | function TopologyException (msg, pt) {
|
30869 | RuntimeException$$1.call(this, TopologyException.msgWithCoord(msg, pt));
|
30870 | this.pt = pt ? new Coordinate(pt) : null;
|
30871 | this.name = 'TopologyException';
|
30872 | }
|
30873 |
|
30874 | if ( RuntimeException$$1 ) TopologyException.__proto__ = RuntimeException$$1;
|
30875 | TopologyException.prototype = Object.create( RuntimeException$$1 && RuntimeException$$1.prototype );
|
30876 | TopologyException.prototype.constructor = TopologyException;
|
30877 | TopologyException.prototype.getCoordinate = function getCoordinate () {
|
30878 | return this.pt
|
30879 | };
|
30880 | TopologyException.prototype.interfaces_ = function interfaces_ () {
|
30881 | return []
|
30882 | };
|
30883 | TopologyException.prototype.getClass = function getClass () {
|
30884 | return TopologyException
|
30885 | };
|
30886 | TopologyException.msgWithCoord = function msgWithCoord (msg, pt) {
|
30887 | if (!pt) { return msg + ' [ ' + pt + ' ]' }
|
30888 | return msg
|
30889 | };
|
30890 |
|
30891 | return TopologyException;
|
30892 | }(RuntimeException));
|
30893 |
|
30894 | var LinkedList = function LinkedList () {
|
30895 | this.array_ = [];
|
30896 | };
|
30897 | LinkedList.prototype.addLast = function addLast (e) {
|
30898 | this.array_.push(e);
|
30899 | };
|
30900 | LinkedList.prototype.removeFirst = function removeFirst () {
|
30901 | return this.array_.shift()
|
30902 | };
|
30903 | LinkedList.prototype.isEmpty = function isEmpty () {
|
30904 | return this.array_.length === 0
|
30905 | };
|
30906 |
|
30907 | var BufferSubgraph = function BufferSubgraph () {
|
30908 | this._finder = null;
|
30909 | this._dirEdgeList = new ArrayList();
|
30910 | this._nodes = new ArrayList();
|
30911 | this._rightMostCoord = null;
|
30912 | this._env = null;
|
30913 | this._finder = new RightmostEdgeFinder();
|
30914 | };
|
30915 | BufferSubgraph.prototype.clearVisitedEdges = function clearVisitedEdges () {
|
30916 | for (var it = this._dirEdgeList.iterator(); it.hasNext();) {
|
30917 | var de = it.next();
|
30918 | de.setVisited(false);
|
30919 | }
|
30920 | };
|
30921 | BufferSubgraph.prototype.getRightmostCoordinate = function getRightmostCoordinate () {
|
30922 | return this._rightMostCoord
|
30923 | };
|
30924 | BufferSubgraph.prototype.computeNodeDepth = function computeNodeDepth (n) {
|
30925 | var this$1 = this;
|
30926 |
|
30927 | var startEdge = null;
|
30928 | for (var i = n.getEdges().iterator(); i.hasNext();) {
|
30929 | var de = i.next();
|
30930 | if (de.isVisited() || de.getSym().isVisited()) {
|
30931 | startEdge = de;
|
30932 | break
|
30933 | }
|
30934 | }
|
30935 | if (startEdge === null) { throw new TopologyException('unable to find edge to compute depths at ' + n.getCoordinate()) }
|
30936 | n.getEdges().computeDepths(startEdge);
|
30937 | for (var i$1 = n.getEdges().iterator(); i$1.hasNext();) {
|
30938 | var de$1 = i$1.next();
|
30939 | de$1.setVisited(true);
|
30940 | this$1.copySymDepths(de$1);
|
30941 | }
|
30942 | };
|
30943 | BufferSubgraph.prototype.computeDepth = function computeDepth (outsideDepth) {
|
30944 | this.clearVisitedEdges();
|
30945 | var de = this._finder.getEdge();
|
30946 |
|
30947 |
|
30948 | de.setEdgeDepths(Position.RIGHT, outsideDepth);
|
30949 | this.copySymDepths(de);
|
30950 | this.computeDepths(de);
|
30951 | };
|
30952 | BufferSubgraph.prototype.create = function create (node) {
|
30953 | this.addReachable(node);
|
30954 | this._finder.findEdge(this._dirEdgeList);
|
30955 | this._rightMostCoord = this._finder.getCoordinate();
|
30956 | };
|
30957 | BufferSubgraph.prototype.findResultEdges = function findResultEdges () {
|
30958 | for (var it = this._dirEdgeList.iterator(); it.hasNext();) {
|
30959 | var de = it.next();
|
30960 | if (de.getDepth(Position.RIGHT) >= 1 && de.getDepth(Position.LEFT) <= 0 && !de.isInteriorAreaEdge()) {
|
30961 | de.setInResult(true);
|
30962 | }
|
30963 | }
|
30964 | };
|
30965 | BufferSubgraph.prototype.computeDepths = function computeDepths (startEdge) {
|
30966 | var this$1 = this;
|
30967 |
|
30968 | var nodesVisited = new HashSet();
|
30969 | var nodeQueue = new LinkedList();
|
30970 | var startNode = startEdge.getNode();
|
30971 | nodeQueue.addLast(startNode);
|
30972 | nodesVisited.add(startNode);
|
30973 | startEdge.setVisited(true);
|
30974 | while (!nodeQueue.isEmpty()) {
|
30975 | var n = nodeQueue.removeFirst();
|
30976 | nodesVisited.add(n);
|
30977 | this$1.computeNodeDepth(n);
|
30978 | for (var i = n.getEdges().iterator(); i.hasNext();) {
|
30979 | var de = i.next();
|
30980 | var sym = de.getSym();
|
30981 | if (sym.isVisited()) { continue }
|
30982 | var adjNode = sym.getNode();
|
30983 | if (!nodesVisited.contains(adjNode)) {
|
30984 | nodeQueue.addLast(adjNode);
|
30985 | nodesVisited.add(adjNode);
|
30986 | }
|
30987 | }
|
30988 | }
|
30989 | };
|
30990 | BufferSubgraph.prototype.compareTo = function compareTo (o) {
|
30991 | var graph = o;
|
30992 | if (this._rightMostCoord.x < graph._rightMostCoord.x) {
|
30993 | return -1
|
30994 | }
|
30995 | if (this._rightMostCoord.x > graph._rightMostCoord.x) {
|
30996 | return 1
|
30997 | }
|
30998 | return 0
|
30999 | };
|
31000 | BufferSubgraph.prototype.getEnvelope = function getEnvelope () {
|
31001 | if (this._env === null) {
|
31002 | var edgeEnv = new Envelope();
|
31003 | for (var it = this._dirEdgeList.iterator(); it.hasNext();) {
|
31004 | var dirEdge = it.next();
|
31005 | var pts = dirEdge.getEdge().getCoordinates();
|
31006 | for (var i = 0; i < pts.length - 1; i++) {
|
31007 | edgeEnv.expandToInclude(pts[i]);
|
31008 | }
|
31009 | }
|
31010 | this._env = edgeEnv;
|
31011 | }
|
31012 | return this._env
|
31013 | };
|
31014 | BufferSubgraph.prototype.addReachable = function addReachable (startNode) {
|
31015 | var this$1 = this;
|
31016 |
|
31017 | var nodeStack = new Stack();
|
31018 | nodeStack.add(startNode);
|
31019 | while (!nodeStack.empty()) {
|
31020 | var node = nodeStack.pop();
|
31021 | this$1.add(node, nodeStack);
|
31022 | }
|
31023 | };
|
31024 | BufferSubgraph.prototype.copySymDepths = function copySymDepths (de) {
|
31025 | var sym = de.getSym();
|
31026 | sym.setDepth(Position.LEFT, de.getDepth(Position.RIGHT));
|
31027 | sym.setDepth(Position.RIGHT, de.getDepth(Position.LEFT));
|
31028 | };
|
31029 | BufferSubgraph.prototype.add = function add (node, nodeStack) {
|
31030 | var this$1 = this;
|
31031 |
|
31032 | node.setVisited(true);
|
31033 | this._nodes.add(node);
|
31034 | for (var i = node.getEdges().iterator(); i.hasNext();) {
|
31035 | var de = i.next();
|
31036 | this$1._dirEdgeList.add(de);
|
31037 | var sym = de.getSym();
|
31038 | var symNode = sym.getNode();
|
31039 | if (!symNode.isVisited()) { nodeStack.push(symNode); }
|
31040 | }
|
31041 | };
|
31042 | BufferSubgraph.prototype.getNodes = function getNodes () {
|
31043 | return this._nodes
|
31044 | };
|
31045 | BufferSubgraph.prototype.getDirectedEdges = function getDirectedEdges () {
|
31046 | return this._dirEdgeList
|
31047 | };
|
31048 | BufferSubgraph.prototype.interfaces_ = function interfaces_ () {
|
31049 | return [Comparable]
|
31050 | };
|
31051 | BufferSubgraph.prototype.getClass = function getClass () {
|
31052 | return BufferSubgraph
|
31053 | };
|
31054 |
|
31055 | var TopologyLocation = function TopologyLocation () {
|
31056 | var this$1 = this;
|
31057 |
|
31058 | this.location = null;
|
31059 | if (arguments.length === 1) {
|
31060 | if (arguments[0] instanceof Array) {
|
31061 | var location = arguments[0];
|
31062 | this.init(location.length);
|
31063 | } else if (Number.isInteger(arguments[0])) {
|
31064 | var on = arguments[0];
|
31065 | this.init(1);
|
31066 | this.location[Position.ON] = on;
|
31067 | } else if (arguments[0] instanceof TopologyLocation) {
|
31068 | var gl = arguments[0];
|
31069 | this.init(gl.location.length);
|
31070 | if (gl !== null) {
|
31071 | for (var i = 0; i < this.location.length; i++) {
|
31072 | this$1.location[i] = gl.location[i];
|
31073 | }
|
31074 | }
|
31075 | }
|
31076 | } else if (arguments.length === 3) {
|
31077 | var on$1 = arguments[0];
|
31078 | var left = arguments[1];
|
31079 | var right = arguments[2];
|
31080 | this.init(3);
|
31081 | this.location[Position.ON] = on$1;
|
31082 | this.location[Position.LEFT] = left;
|
31083 | this.location[Position.RIGHT] = right;
|
31084 | }
|
31085 | };
|
31086 | TopologyLocation.prototype.setAllLocations = function setAllLocations (locValue) {
|
31087 | var this$1 = this;
|
31088 |
|
31089 | for (var i = 0; i < this.location.length; i++) {
|
31090 | this$1.location[i] = locValue;
|
31091 | }
|
31092 | };
|
31093 | TopologyLocation.prototype.isNull = function isNull () {
|
31094 | var this$1 = this;
|
31095 |
|
31096 | for (var i = 0; i < this.location.length; i++) {
|
31097 | if (this$1.location[i] !== Location.NONE) { return false }
|
31098 | }
|
31099 | return true
|
31100 | };
|
31101 | TopologyLocation.prototype.setAllLocationsIfNull = function setAllLocationsIfNull (locValue) {
|
31102 | var this$1 = this;
|
31103 |
|
31104 | for (var i = 0; i < this.location.length; i++) {
|
31105 | if (this$1.location[i] === Location.NONE) { this$1.location[i] = locValue; }
|
31106 | }
|
31107 | };
|
31108 | TopologyLocation.prototype.isLine = function isLine () {
|
31109 | return this.location.length === 1
|
31110 | };
|
31111 | TopologyLocation.prototype.merge = function merge (gl) {
|
31112 | var this$1 = this;
|
31113 |
|
31114 | if (gl.location.length > this.location.length) {
|
31115 | var newLoc = new Array(3).fill(null);
|
31116 | newLoc[Position.ON] = this.location[Position.ON];
|
31117 | newLoc[Position.LEFT] = Location.NONE;
|
31118 | newLoc[Position.RIGHT] = Location.NONE;
|
31119 | this.location = newLoc;
|
31120 | }
|
31121 | for (var i = 0; i < this.location.length; i++) {
|
31122 | if (this$1.location[i] === Location.NONE && i < gl.location.length) { this$1.location[i] = gl.location[i]; }
|
31123 | }
|
31124 | };
|
31125 | TopologyLocation.prototype.getLocations = function getLocations () {
|
31126 | return this.location
|
31127 | };
|
31128 | TopologyLocation.prototype.flip = function flip () {
|
31129 | if (this.location.length <= 1) { return null }
|
31130 | var temp = this.location[Position.LEFT];
|
31131 | this.location[Position.LEFT] = this.location[Position.RIGHT];
|
31132 | this.location[Position.RIGHT] = temp;
|
31133 | };
|
31134 | TopologyLocation.prototype.toString = function toString () {
|
31135 | var buf = new StringBuffer();
|
31136 | if (this.location.length > 1) { buf.append(Location.toLocationSymbol(this.location[Position.LEFT])); }
|
31137 | buf.append(Location.toLocationSymbol(this.location[Position.ON]));
|
31138 | if (this.location.length > 1) { buf.append(Location.toLocationSymbol(this.location[Position.RIGHT])); }
|
31139 | return buf.toString()
|
31140 | };
|
31141 | TopologyLocation.prototype.setLocations = function setLocations (on, left, right) {
|
31142 | this.location[Position.ON] = on;
|
31143 | this.location[Position.LEFT] = left;
|
31144 | this.location[Position.RIGHT] = right;
|
31145 | };
|
31146 | TopologyLocation.prototype.get = function get (posIndex) {
|
31147 | if (posIndex < this.location.length) { return this.location[posIndex] }
|
31148 | return Location.NONE
|
31149 | };
|
31150 | TopologyLocation.prototype.isArea = function isArea () {
|
31151 | return this.location.length > 1
|
31152 | };
|
31153 | TopologyLocation.prototype.isAnyNull = function isAnyNull () {
|
31154 | var this$1 = this;
|
31155 |
|
31156 | for (var i = 0; i < this.location.length; i++) {
|
31157 | if (this$1.location[i] === Location.NONE) { return true }
|
31158 | }
|
31159 | return false
|
31160 | };
|
31161 | TopologyLocation.prototype.setLocation = function setLocation () {
|
31162 | if (arguments.length === 1) {
|
31163 | var locValue = arguments[0];
|
31164 | this.setLocation(Position.ON, locValue);
|
31165 | } else if (arguments.length === 2) {
|
31166 | var locIndex = arguments[0];
|
31167 | var locValue$1 = arguments[1];
|
31168 | this.location[locIndex] = locValue$1;
|
31169 | }
|
31170 | };
|
31171 | TopologyLocation.prototype.init = function init (size) {
|
31172 | this.location = new Array(size).fill(null);
|
31173 | this.setAllLocations(Location.NONE);
|
31174 | };
|
31175 | TopologyLocation.prototype.isEqualOnSide = function isEqualOnSide (le, locIndex) {
|
31176 | return this.location[locIndex] === le.location[locIndex]
|
31177 | };
|
31178 | TopologyLocation.prototype.allPositionsEqual = function allPositionsEqual (loc) {
|
31179 | var this$1 = this;
|
31180 |
|
31181 | for (var i = 0; i < this.location.length; i++) {
|
31182 | if (this$1.location[i] !== loc) { return false }
|
31183 | }
|
31184 | return true
|
31185 | };
|
31186 | TopologyLocation.prototype.interfaces_ = function interfaces_ () {
|
31187 | return []
|
31188 | };
|
31189 | TopologyLocation.prototype.getClass = function getClass () {
|
31190 | return TopologyLocation
|
31191 | };
|
31192 |
|
31193 | var Label = function Label () {
|
31194 | this.elt = new Array(2).fill(null);
|
31195 | if (arguments.length === 1) {
|
31196 | if (Number.isInteger(arguments[0])) {
|
31197 | var onLoc = arguments[0];
|
31198 | this.elt[0] = new TopologyLocation(onLoc);
|
31199 | this.elt[1] = new TopologyLocation(onLoc);
|
31200 | } else if (arguments[0] instanceof Label) {
|
31201 | var lbl = arguments[0];
|
31202 | this.elt[0] = new TopologyLocation(lbl.elt[0]);
|
31203 | this.elt[1] = new TopologyLocation(lbl.elt[1]);
|
31204 | }
|
31205 | } else if (arguments.length === 2) {
|
31206 | var geomIndex = arguments[0];
|
31207 | var onLoc$1 = arguments[1];
|
31208 | this.elt[0] = new TopologyLocation(Location.NONE);
|
31209 | this.elt[1] = new TopologyLocation(Location.NONE);
|
31210 | this.elt[geomIndex].setLocation(onLoc$1);
|
31211 | } else if (arguments.length === 3) {
|
31212 | var onLoc$2 = arguments[0];
|
31213 | var leftLoc = arguments[1];
|
31214 | var rightLoc = arguments[2];
|
31215 | this.elt[0] = new TopologyLocation(onLoc$2, leftLoc, rightLoc);
|
31216 | this.elt[1] = new TopologyLocation(onLoc$2, leftLoc, rightLoc);
|
31217 | } else if (arguments.length === 4) {
|
31218 | var geomIndex$1 = arguments[0];
|
31219 | var onLoc$3 = arguments[1];
|
31220 | var leftLoc$1 = arguments[2];
|
31221 | var rightLoc$1 = arguments[3];
|
31222 | this.elt[0] = new TopologyLocation(Location.NONE, Location.NONE, Location.NONE);
|
31223 | this.elt[1] = new TopologyLocation(Location.NONE, Location.NONE, Location.NONE);
|
31224 | this.elt[geomIndex$1].setLocations(onLoc$3, leftLoc$1, rightLoc$1);
|
31225 | }
|
31226 | };
|
31227 | Label.prototype.getGeometryCount = function getGeometryCount () {
|
31228 | var count = 0;
|
31229 | if (!this.elt[0].isNull()) { count++; }
|
31230 | if (!this.elt[1].isNull()) { count++; }
|
31231 | return count
|
31232 | };
|
31233 | Label.prototype.setAllLocations = function setAllLocations (geomIndex, location) {
|
31234 | this.elt[geomIndex].setAllLocations(location);
|
31235 | };
|
31236 | Label.prototype.isNull = function isNull (geomIndex) {
|
31237 | return this.elt[geomIndex].isNull()
|
31238 | };
|
31239 | Label.prototype.setAllLocationsIfNull = function setAllLocationsIfNull () {
|
31240 | if (arguments.length === 1) {
|
31241 | var location = arguments[0];
|
31242 | this.setAllLocationsIfNull(0, location);
|
31243 | this.setAllLocationsIfNull(1, location);
|
31244 | } else if (arguments.length === 2) {
|
31245 | var geomIndex = arguments[0];
|
31246 | var location$1 = arguments[1];
|
31247 | this.elt[geomIndex].setAllLocationsIfNull(location$1);
|
31248 | }
|
31249 | };
|
31250 | Label.prototype.isLine = function isLine (geomIndex) {
|
31251 | return this.elt[geomIndex].isLine()
|
31252 | };
|
31253 | Label.prototype.merge = function merge (lbl) {
|
31254 | var this$1 = this;
|
31255 |
|
31256 | for (var i = 0; i < 2; i++) {
|
31257 | if (this$1.elt[i] === null && lbl.elt[i] !== null) {
|
31258 | this$1.elt[i] = new TopologyLocation(lbl.elt[i]);
|
31259 | } else {
|
31260 | this$1.elt[i].merge(lbl.elt[i]);
|
31261 | }
|
31262 | }
|
31263 | };
|
31264 | Label.prototype.flip = function flip () {
|
31265 | this.elt[0].flip();
|
31266 | this.elt[1].flip();
|
31267 | };
|
31268 | Label.prototype.getLocation = function getLocation () {
|
31269 | if (arguments.length === 1) {
|
31270 | var geomIndex = arguments[0];
|
31271 | return this.elt[geomIndex].get(Position.ON)
|
31272 | } else if (arguments.length === 2) {
|
31273 | var geomIndex$1 = arguments[0];
|
31274 | var posIndex = arguments[1];
|
31275 | return this.elt[geomIndex$1].get(posIndex)
|
31276 | }
|
31277 | };
|
31278 | Label.prototype.toString = function toString () {
|
31279 | var buf = new StringBuffer();
|
31280 | if (this.elt[0] !== null) {
|
31281 | buf.append('A:');
|
31282 | buf.append(this.elt[0].toString());
|
31283 | }
|
31284 | if (this.elt[1] !== null) {
|
31285 | buf.append(' B:');
|
31286 | buf.append(this.elt[1].toString());
|
31287 | }
|
31288 | return buf.toString()
|
31289 | };
|
31290 | Label.prototype.isArea = function isArea () {
|
31291 | if (arguments.length === 0) {
|
31292 | return this.elt[0].isArea() || this.elt[1].isArea()
|
31293 | } else if (arguments.length === 1) {
|
31294 | var geomIndex = arguments[0];
|
31295 | return this.elt[geomIndex].isArea()
|
31296 | }
|
31297 | };
|
31298 | Label.prototype.isAnyNull = function isAnyNull (geomIndex) {
|
31299 | return this.elt[geomIndex].isAnyNull()
|
31300 | };
|
31301 | Label.prototype.setLocation = function setLocation () {
|
31302 | if (arguments.length === 2) {
|
31303 | var geomIndex = arguments[0];
|
31304 | var location = arguments[1];
|
31305 | this.elt[geomIndex].setLocation(Position.ON, location);
|
31306 | } else if (arguments.length === 3) {
|
31307 | var geomIndex$1 = arguments[0];
|
31308 | var posIndex = arguments[1];
|
31309 | var location$1 = arguments[2];
|
31310 | this.elt[geomIndex$1].setLocation(posIndex, location$1);
|
31311 | }
|
31312 | };
|
31313 | Label.prototype.isEqualOnSide = function isEqualOnSide (lbl, side) {
|
31314 | return this.elt[0].isEqualOnSide(lbl.elt[0], side) && this.elt[1].isEqualOnSide(lbl.elt[1], side)
|
31315 | };
|
31316 | Label.prototype.allPositionsEqual = function allPositionsEqual (geomIndex, loc) {
|
31317 | return this.elt[geomIndex].allPositionsEqual(loc)
|
31318 | };
|
31319 | Label.prototype.toLine = function toLine (geomIndex) {
|
31320 | if (this.elt[geomIndex].isArea()) { this.elt[geomIndex] = new TopologyLocation(this.elt[geomIndex].location[0]); }
|
31321 | };
|
31322 | Label.prototype.interfaces_ = function interfaces_ () {
|
31323 | return []
|
31324 | };
|
31325 | Label.prototype.getClass = function getClass () {
|
31326 | return Label
|
31327 | };
|
31328 | Label.toLineLabel = function toLineLabel (label) {
|
31329 | var lineLabel = new Label(Location.NONE);
|
31330 | for (var i = 0; i < 2; i++) {
|
31331 | lineLabel.setLocation(i, label.getLocation(i));
|
31332 | }
|
31333 | return lineLabel
|
31334 | };
|
31335 |
|
31336 | var EdgeRing$1 = function EdgeRing () {
|
31337 | this._startDe = null;
|
31338 | this._maxNodeDegree = -1;
|
31339 | this._edges = new ArrayList();
|
31340 | this._pts = new ArrayList();
|
31341 | this._label = new Label(Location.NONE);
|
31342 | this._ring = null;
|
31343 | this._isHole = null;
|
31344 | this._shell = null;
|
31345 | this._holes = new ArrayList();
|
31346 | this._geometryFactory = null;
|
31347 | var start = arguments[0];
|
31348 | var geometryFactory = arguments[1];
|
31349 | this._geometryFactory = geometryFactory;
|
31350 | this.computePoints(start);
|
31351 | this.computeRing();
|
31352 | };
|
31353 | EdgeRing$1.prototype.computeRing = function computeRing () {
|
31354 | var this$1 = this;
|
31355 |
|
31356 | if (this._ring !== null) { return null }
|
31357 | var coord = new Array(this._pts.size()).fill(null);
|
31358 | for (var i = 0; i < this._pts.size(); i++) {
|
31359 | coord[i] = this$1._pts.get(i);
|
31360 | }
|
31361 | this._ring = this._geometryFactory.createLinearRing(coord);
|
31362 | this._isHole = CGAlgorithms.isCCW(this._ring.getCoordinates());
|
31363 | };
|
31364 | EdgeRing$1.prototype.isIsolated = function isIsolated () {
|
31365 | return this._label.getGeometryCount() === 1
|
31366 | };
|
31367 | EdgeRing$1.prototype.computePoints = function computePoints (start) {
|
31368 | var this$1 = this;
|
31369 |
|
31370 | this._startDe = start;
|
31371 | var de = start;
|
31372 | var isFirstEdge = true;
|
31373 | do {
|
31374 | if (de === null) { throw new TopologyException('Found null DirectedEdge') }
|
31375 | if (de.getEdgeRing() === this$1) { throw new TopologyException('Directed Edge visited twice during ring-building at ' + de.getCoordinate()) }
|
31376 | this$1._edges.add(de);
|
31377 | var label = de.getLabel();
|
31378 | Assert.isTrue(label.isArea());
|
31379 | this$1.mergeLabel(label);
|
31380 | this$1.addPoints(de.getEdge(), de.isForward(), isFirstEdge);
|
31381 | isFirstEdge = false;
|
31382 | this$1.setEdgeRing(de, this$1);
|
31383 | de = this$1.getNext(de);
|
31384 | } while (de !== this._startDe)
|
31385 | };
|
31386 | EdgeRing$1.prototype.getLinearRing = function getLinearRing () {
|
31387 | return this._ring
|
31388 | };
|
31389 | EdgeRing$1.prototype.getCoordinate = function getCoordinate (i) {
|
31390 | return this._pts.get(i)
|
31391 | };
|
31392 | EdgeRing$1.prototype.computeMaxNodeDegree = function computeMaxNodeDegree () {
|
31393 | var this$1 = this;
|
31394 |
|
31395 | this._maxNodeDegree = 0;
|
31396 | var de = this._startDe;
|
31397 | do {
|
31398 | var node = de.getNode();
|
31399 | var degree = node.getEdges().getOutgoingDegree(this$1);
|
31400 | if (degree > this$1._maxNodeDegree) { this$1._maxNodeDegree = degree; }
|
31401 | de = this$1.getNext(de);
|
31402 | } while (de !== this._startDe)
|
31403 | this._maxNodeDegree *= 2;
|
31404 | };
|
31405 | EdgeRing$1.prototype.addPoints = function addPoints (edge, isForward, isFirstEdge) {
|
31406 | var this$1 = this;
|
31407 |
|
31408 | var edgePts = edge.getCoordinates();
|
31409 | if (isForward) {
|
31410 | var startIndex = 1;
|
31411 | if (isFirstEdge) { startIndex = 0; }
|
31412 | for (var i = startIndex; i < edgePts.length; i++) {
|
31413 | this$1._pts.add(edgePts[i]);
|
31414 | }
|
31415 | } else {
|
31416 | var startIndex$1 = edgePts.length - 2;
|
31417 | if (isFirstEdge) { startIndex$1 = edgePts.length - 1; }
|
31418 | for (var i$1 = startIndex$1; i$1 >= 0; i$1--) {
|
31419 | this$1._pts.add(edgePts[i$1]);
|
31420 | }
|
31421 | }
|
31422 | };
|
31423 | EdgeRing$1.prototype.isHole = function isHole () {
|
31424 | return this._isHole
|
31425 | };
|
31426 | EdgeRing$1.prototype.setInResult = function setInResult () {
|
31427 | var de = this._startDe;
|
31428 | do {
|
31429 | de.getEdge().setInResult(true);
|
31430 | de = de.getNext();
|
31431 | } while (de !== this._startDe)
|
31432 | };
|
31433 | EdgeRing$1.prototype.containsPoint = function containsPoint (p) {
|
31434 | var shell = this.getLinearRing();
|
31435 | var env = shell.getEnvelopeInternal();
|
31436 | if (!env.contains(p)) { return false }
|
31437 | if (!CGAlgorithms.isPointInRing(p, shell.getCoordinates())) { return false }
|
31438 | for (var i = this._holes.iterator(); i.hasNext();) {
|
31439 | var hole = i.next();
|
31440 | if (hole.containsPoint(p)) { return false }
|
31441 | }
|
31442 | return true
|
31443 | };
|
31444 | EdgeRing$1.prototype.addHole = function addHole (ring) {
|
31445 | this._holes.add(ring);
|
31446 | };
|
31447 | EdgeRing$1.prototype.isShell = function isShell () {
|
31448 | return this._shell === null
|
31449 | };
|
31450 | EdgeRing$1.prototype.getLabel = function getLabel () {
|
31451 | return this._label
|
31452 | };
|
31453 | EdgeRing$1.prototype.getEdges = function getEdges () {
|
31454 | return this._edges
|
31455 | };
|
31456 | EdgeRing$1.prototype.getMaxNodeDegree = function getMaxNodeDegree () {
|
31457 | if (this._maxNodeDegree < 0) { this.computeMaxNodeDegree(); }
|
31458 | return this._maxNodeDegree
|
31459 | };
|
31460 | EdgeRing$1.prototype.getShell = function getShell () {
|
31461 | return this._shell
|
31462 | };
|
31463 | EdgeRing$1.prototype.mergeLabel = function mergeLabel () {
|
31464 | if (arguments.length === 1) {
|
31465 | var deLabel = arguments[0];
|
31466 | this.mergeLabel(deLabel, 0);
|
31467 | this.mergeLabel(deLabel, 1);
|
31468 | } else if (arguments.length === 2) {
|
31469 | var deLabel$1 = arguments[0];
|
31470 | var geomIndex = arguments[1];
|
31471 | var loc = deLabel$1.getLocation(geomIndex, Position.RIGHT);
|
31472 | if (loc === Location.NONE) { return null }
|
31473 | if (this._label.getLocation(geomIndex) === Location.NONE) {
|
31474 | this._label.setLocation(geomIndex, loc);
|
31475 | return null
|
31476 | }
|
31477 | }
|
31478 | };
|
31479 | EdgeRing$1.prototype.setShell = function setShell (shell) {
|
31480 | this._shell = shell;
|
31481 | if (shell !== null) { shell.addHole(this); }
|
31482 | };
|
31483 | EdgeRing$1.prototype.toPolygon = function toPolygon (geometryFactory) {
|
31484 | var this$1 = this;
|
31485 |
|
31486 | var holeLR = new Array(this._holes.size()).fill(null);
|
31487 | for (var i = 0; i < this._holes.size(); i++) {
|
31488 | holeLR[i] = this$1._holes.get(i).getLinearRing();
|
31489 | }
|
31490 | var poly = geometryFactory.createPolygon(this.getLinearRing(), holeLR);
|
31491 | return poly
|
31492 | };
|
31493 | EdgeRing$1.prototype.interfaces_ = function interfaces_ () {
|
31494 | return []
|
31495 | };
|
31496 | EdgeRing$1.prototype.getClass = function getClass () {
|
31497 | return EdgeRing$1
|
31498 | };
|
31499 |
|
31500 | var MinimalEdgeRing = (function (EdgeRing$$1) {
|
31501 | function MinimalEdgeRing () {
|
31502 | var start = arguments[0];
|
31503 | var geometryFactory = arguments[1];
|
31504 | EdgeRing$$1.call(this, start, geometryFactory);
|
31505 | }
|
31506 |
|
31507 | if ( EdgeRing$$1 ) MinimalEdgeRing.__proto__ = EdgeRing$$1;
|
31508 | MinimalEdgeRing.prototype = Object.create( EdgeRing$$1 && EdgeRing$$1.prototype );
|
31509 | MinimalEdgeRing.prototype.constructor = MinimalEdgeRing;
|
31510 | MinimalEdgeRing.prototype.setEdgeRing = function setEdgeRing (de, er) {
|
31511 | de.setMinEdgeRing(er);
|
31512 | };
|
31513 | MinimalEdgeRing.prototype.getNext = function getNext (de) {
|
31514 | return de.getNextMin()
|
31515 | };
|
31516 | MinimalEdgeRing.prototype.interfaces_ = function interfaces_ () {
|
31517 | return []
|
31518 | };
|
31519 | MinimalEdgeRing.prototype.getClass = function getClass () {
|
31520 | return MinimalEdgeRing
|
31521 | };
|
31522 |
|
31523 | return MinimalEdgeRing;
|
31524 | }(EdgeRing$1));
|
31525 |
|
31526 | var MaximalEdgeRing = (function (EdgeRing$$1) {
|
31527 | function MaximalEdgeRing () {
|
31528 | var start = arguments[0];
|
31529 | var geometryFactory = arguments[1];
|
31530 | EdgeRing$$1.call(this, start, geometryFactory);
|
31531 | }
|
31532 |
|
31533 | if ( EdgeRing$$1 ) MaximalEdgeRing.__proto__ = EdgeRing$$1;
|
31534 | MaximalEdgeRing.prototype = Object.create( EdgeRing$$1 && EdgeRing$$1.prototype );
|
31535 | MaximalEdgeRing.prototype.constructor = MaximalEdgeRing;
|
31536 | MaximalEdgeRing.prototype.buildMinimalRings = function buildMinimalRings () {
|
31537 | var this$1 = this;
|
31538 |
|
31539 | var minEdgeRings = new ArrayList();
|
31540 | var de = this._startDe;
|
31541 | do {
|
31542 | if (de.getMinEdgeRing() === null) {
|
31543 | var minEr = new MinimalEdgeRing(de, this$1._geometryFactory);
|
31544 | minEdgeRings.add(minEr);
|
31545 | }
|
31546 | de = de.getNext();
|
31547 | } while (de !== this._startDe)
|
31548 | return minEdgeRings
|
31549 | };
|
31550 | MaximalEdgeRing.prototype.setEdgeRing = function setEdgeRing (de, er) {
|
31551 | de.setEdgeRing(er);
|
31552 | };
|
31553 | MaximalEdgeRing.prototype.linkDirectedEdgesForMinimalEdgeRings = function linkDirectedEdgesForMinimalEdgeRings () {
|
31554 | var this$1 = this;
|
31555 |
|
31556 | var de = this._startDe;
|
31557 | do {
|
31558 | var node = de.getNode();
|
31559 | node.getEdges().linkMinimalDirectedEdges(this$1);
|
31560 | de = de.getNext();
|
31561 | } while (de !== this._startDe)
|
31562 | };
|
31563 | MaximalEdgeRing.prototype.getNext = function getNext (de) {
|
31564 | return de.getNext()
|
31565 | };
|
31566 | MaximalEdgeRing.prototype.interfaces_ = function interfaces_ () {
|
31567 | return []
|
31568 | };
|
31569 | MaximalEdgeRing.prototype.getClass = function getClass () {
|
31570 | return MaximalEdgeRing
|
31571 | };
|
31572 |
|
31573 | return MaximalEdgeRing;
|
31574 | }(EdgeRing$1));
|
31575 |
|
31576 | var GraphComponent = function GraphComponent () {
|
31577 | this._label = null;
|
31578 | this._isInResult = false;
|
31579 | this._isCovered = false;
|
31580 | this._isCoveredSet = false;
|
31581 | this._isVisited = false;
|
31582 | if (arguments.length === 0) {} else if (arguments.length === 1) {
|
31583 | var label = arguments[0];
|
31584 | this._label = label;
|
31585 | }
|
31586 | };
|
31587 | GraphComponent.prototype.setVisited = function setVisited (isVisited) {
|
31588 | this._isVisited = isVisited;
|
31589 | };
|
31590 | GraphComponent.prototype.setInResult = function setInResult (isInResult) {
|
31591 | this._isInResult = isInResult;
|
31592 | };
|
31593 | GraphComponent.prototype.isCovered = function isCovered () {
|
31594 | return this._isCovered
|
31595 | };
|
31596 | GraphComponent.prototype.isCoveredSet = function isCoveredSet () {
|
31597 | return this._isCoveredSet
|
31598 | };
|
31599 | GraphComponent.prototype.setLabel = function setLabel (label) {
|
31600 | this._label = label;
|
31601 | };
|
31602 | GraphComponent.prototype.getLabel = function getLabel () {
|
31603 | return this._label
|
31604 | };
|
31605 | GraphComponent.prototype.setCovered = function setCovered (isCovered) {
|
31606 | this._isCovered = isCovered;
|
31607 | this._isCoveredSet = true;
|
31608 | };
|
31609 | GraphComponent.prototype.updateIM = function updateIM (im) {
|
31610 | Assert.isTrue(this._label.getGeometryCount() >= 2, 'found partial label');
|
31611 | this.computeIM(im);
|
31612 | };
|
31613 | GraphComponent.prototype.isInResult = function isInResult () {
|
31614 | return this._isInResult
|
31615 | };
|
31616 | GraphComponent.prototype.isVisited = function isVisited () {
|
31617 | return this._isVisited
|
31618 | };
|
31619 | GraphComponent.prototype.interfaces_ = function interfaces_ () {
|
31620 | return []
|
31621 | };
|
31622 | GraphComponent.prototype.getClass = function getClass () {
|
31623 | return GraphComponent
|
31624 | };
|
31625 |
|
31626 | var Node$2 = (function (GraphComponent$$1) {
|
31627 | function Node () {
|
31628 | GraphComponent$$1.call(this);
|
31629 | this._coord = null;
|
31630 | this._edges = null;
|
31631 | var coord = arguments[0];
|
31632 | var edges = arguments[1];
|
31633 | this._coord = coord;
|
31634 | this._edges = edges;
|
31635 | this._label = new Label(0, Location.NONE);
|
31636 | }
|
31637 |
|
31638 | if ( GraphComponent$$1 ) Node.__proto__ = GraphComponent$$1;
|
31639 | Node.prototype = Object.create( GraphComponent$$1 && GraphComponent$$1.prototype );
|
31640 | Node.prototype.constructor = Node;
|
31641 | Node.prototype.isIncidentEdgeInResult = function isIncidentEdgeInResult () {
|
31642 | for (var it = this.getEdges().getEdges().iterator(); it.hasNext();) {
|
31643 | var de = it.next();
|
31644 | if (de.getEdge().isInResult()) { return true }
|
31645 | }
|
31646 | return false
|
31647 | };
|
31648 | Node.prototype.isIsolated = function isIsolated () {
|
31649 | return this._label.getGeometryCount() === 1
|
31650 | };
|
31651 | Node.prototype.getCoordinate = function getCoordinate () {
|
31652 | return this._coord
|
31653 | };
|
31654 | Node.prototype.print = function print (out) {
|
31655 | out.println('node ' + this._coord + ' lbl: ' + this._label);
|
31656 | };
|
31657 | Node.prototype.computeIM = function computeIM (im) {};
|
31658 | Node.prototype.computeMergedLocation = function computeMergedLocation (label2, eltIndex) {
|
31659 | var loc = Location.NONE;
|
31660 | loc = this._label.getLocation(eltIndex);
|
31661 | if (!label2.isNull(eltIndex)) {
|
31662 | var nLoc = label2.getLocation(eltIndex);
|
31663 | if (loc !== Location.BOUNDARY) { loc = nLoc; }
|
31664 | }
|
31665 | return loc
|
31666 | };
|
31667 | Node.prototype.setLabel = function setLabel () {
|
31668 | if (arguments.length === 2) {
|
31669 | var argIndex = arguments[0];
|
31670 | var onLocation = arguments[1];
|
31671 | if (this._label === null) {
|
31672 | this._label = new Label(argIndex, onLocation);
|
31673 | } else { this._label.setLocation(argIndex, onLocation); }
|
31674 | } else { return GraphComponent$$1.prototype.setLabel.apply(this, arguments) }
|
31675 | };
|
31676 | Node.prototype.getEdges = function getEdges () {
|
31677 | return this._edges
|
31678 | };
|
31679 | Node.prototype.mergeLabel = function mergeLabel () {
|
31680 | var this$1 = this;
|
31681 |
|
31682 | if (arguments[0] instanceof Node) {
|
31683 | var n = arguments[0];
|
31684 | this.mergeLabel(n._label);
|
31685 | } else if (arguments[0] instanceof Label) {
|
31686 | var label2 = arguments[0];
|
31687 | for (var i = 0; i < 2; i++) {
|
31688 | var loc = this$1.computeMergedLocation(label2, i);
|
31689 | var thisLoc = this$1._label.getLocation(i);
|
31690 | if (thisLoc === Location.NONE) { this$1._label.setLocation(i, loc); }
|
31691 | }
|
31692 | }
|
31693 | };
|
31694 | Node.prototype.add = function add (e) {
|
31695 | this._edges.insert(e);
|
31696 | e.setNode(this);
|
31697 | };
|
31698 | Node.prototype.setLabelBoundary = function setLabelBoundary (argIndex) {
|
31699 | if (this._label === null) { return null }
|
31700 | var loc = Location.NONE;
|
31701 | if (this._label !== null) { loc = this._label.getLocation(argIndex); }
|
31702 | var newLoc = null;
|
31703 | switch (loc) {
|
31704 | case Location.BOUNDARY:
|
31705 | newLoc = Location.INTERIOR;
|
31706 | break
|
31707 | case Location.INTERIOR:
|
31708 | newLoc = Location.BOUNDARY;
|
31709 | break
|
31710 | default:
|
31711 | newLoc = Location.BOUNDARY;
|
31712 | break
|
31713 | }
|
31714 | this._label.setLocation(argIndex, newLoc);
|
31715 | };
|
31716 | Node.prototype.interfaces_ = function interfaces_ () {
|
31717 | return []
|
31718 | };
|
31719 | Node.prototype.getClass = function getClass () {
|
31720 | return Node
|
31721 | };
|
31722 |
|
31723 | return Node;
|
31724 | }(GraphComponent));
|
31725 |
|
31726 | var NodeMap = function NodeMap () {
|
31727 | this.nodeMap = new TreeMap();
|
31728 | this.nodeFact = null;
|
31729 | var nodeFact = arguments[0];
|
31730 | this.nodeFact = nodeFact;
|
31731 | };
|
31732 | NodeMap.prototype.find = function find (coord) {
|
31733 | return this.nodeMap.get(coord)
|
31734 | };
|
31735 | NodeMap.prototype.addNode = function addNode () {
|
31736 | if (arguments[0] instanceof Coordinate) {
|
31737 | var coord = arguments[0];
|
31738 | var node = this.nodeMap.get(coord);
|
31739 | if (node === null) {
|
31740 | node = this.nodeFact.createNode(coord);
|
31741 | this.nodeMap.put(coord, node);
|
31742 | }
|
31743 | return node
|
31744 | } else if (arguments[0] instanceof Node$2) {
|
31745 | var n = arguments[0];
|
31746 | var node$1 = this.nodeMap.get(n.getCoordinate());
|
31747 | if (node$1 === null) {
|
31748 | this.nodeMap.put(n.getCoordinate(), n);
|
31749 | return n
|
31750 | }
|
31751 | node$1.mergeLabel(n);
|
31752 | return node$1
|
31753 | }
|
31754 | };
|
31755 | NodeMap.prototype.print = function print (out) {
|
31756 | for (var it = this.iterator(); it.hasNext();) {
|
31757 | var n = it.next();
|
31758 | n.print(out);
|
31759 | }
|
31760 | };
|
31761 | NodeMap.prototype.iterator = function iterator () {
|
31762 | return this.nodeMap.values().iterator()
|
31763 | };
|
31764 | NodeMap.prototype.values = function values () {
|
31765 | return this.nodeMap.values()
|
31766 | };
|
31767 | NodeMap.prototype.getBoundaryNodes = function getBoundaryNodes (geomIndex) {
|
31768 | var bdyNodes = new ArrayList();
|
31769 | for (var i = this.iterator(); i.hasNext();) {
|
31770 | var node = i.next();
|
31771 | if (node.getLabel().getLocation(geomIndex) === Location.BOUNDARY) { bdyNodes.add(node); }
|
31772 | }
|
31773 | return bdyNodes
|
31774 | };
|
31775 | NodeMap.prototype.add = function add (e) {
|
31776 | var p = e.getCoordinate();
|
31777 | var n = this.addNode(p);
|
31778 | n.add(e);
|
31779 | };
|
31780 | NodeMap.prototype.interfaces_ = function interfaces_ () {
|
31781 | return []
|
31782 | };
|
31783 | NodeMap.prototype.getClass = function getClass () {
|
31784 | return NodeMap
|
31785 | };
|
31786 |
|
31787 | var Quadrant = function Quadrant () {};
|
31788 |
|
31789 | var staticAccessors$21 = { NE: { configurable: true },NW: { configurable: true },SW: { configurable: true },SE: { configurable: true } };
|
31790 |
|
31791 | Quadrant.prototype.interfaces_ = function interfaces_ () {
|
31792 | return []
|
31793 | };
|
31794 | Quadrant.prototype.getClass = function getClass () {
|
31795 | return Quadrant
|
31796 | };
|
31797 | Quadrant.isNorthern = function isNorthern (quad) {
|
31798 | return quad === Quadrant.NE || quad === Quadrant.NW
|
31799 | };
|
31800 | Quadrant.isOpposite = function isOpposite (quad1, quad2) {
|
31801 | if (quad1 === quad2) { return false }
|
31802 | var diff = (quad1 - quad2 + 4) % 4;
|
31803 | if (diff === 2) { return true }
|
31804 | return false
|
31805 | };
|
31806 | Quadrant.commonHalfPlane = function commonHalfPlane (quad1, quad2) {
|
31807 | if (quad1 === quad2) { return quad1 }
|
31808 | var diff = (quad1 - quad2 + 4) % 4;
|
31809 | if (diff === 2) { return -1 }
|
31810 | var min = quad1 < quad2 ? quad1 : quad2;
|
31811 | var max = quad1 > quad2 ? quad1 : quad2;
|
31812 | if (min === 0 && max === 3) { return 3 }
|
31813 | return min
|
31814 | };
|
31815 | Quadrant.isInHalfPlane = function isInHalfPlane (quad, halfPlane) {
|
31816 | if (halfPlane === Quadrant.SE) {
|
31817 | return quad === Quadrant.SE || quad === Quadrant.SW
|
31818 | }
|
31819 | return quad === halfPlane || quad === halfPlane + 1
|
31820 | };
|
31821 | Quadrant.quadrant = function quadrant () {
|
31822 | if (typeof arguments[0] === 'number' && typeof arguments[1] === 'number') {
|
31823 | var dx = arguments[0];
|
31824 | var dy = arguments[1];
|
31825 | if (dx === 0.0 && dy === 0.0) { throw new IllegalArgumentException('Cannot compute the quadrant for point ( ' + dx + ', ' + dy + ' )') }
|
31826 | if (dx >= 0.0) {
|
31827 | if (dy >= 0.0) { return Quadrant.NE; } else { return Quadrant.SE }
|
31828 | } else {
|
31829 | if (dy >= 0.0) { return Quadrant.NW; } else { return Quadrant.SW }
|
31830 | }
|
31831 | } else if (arguments[0] instanceof Coordinate && arguments[1] instanceof Coordinate) {
|
31832 | var p0 = arguments[0];
|
31833 | var p1 = arguments[1];
|
31834 | if (p1.x === p0.x && p1.y === p0.y) { throw new IllegalArgumentException('Cannot compute the quadrant for two identical points ' + p0) }
|
31835 | if (p1.x >= p0.x) {
|
31836 | if (p1.y >= p0.y) { return Quadrant.NE; } else { return Quadrant.SE }
|
31837 | } else {
|
31838 | if (p1.y >= p0.y) { return Quadrant.NW; } else { return Quadrant.SW }
|
31839 | }
|
31840 | }
|
31841 | };
|
31842 | staticAccessors$21.NE.get = function () { return 0 };
|
31843 | staticAccessors$21.NW.get = function () { return 1 };
|
31844 | staticAccessors$21.SW.get = function () { return 2 };
|
31845 | staticAccessors$21.SE.get = function () { return 3 };
|
31846 |
|
31847 | Object.defineProperties( Quadrant, staticAccessors$21 );
|
31848 |
|
31849 | var EdgeEnd = function EdgeEnd () {
|
31850 | this._edge = null;
|
31851 | this._label = null;
|
31852 | this._node = null;
|
31853 | this._p0 = null;
|
31854 | this._p1 = null;
|
31855 | this._dx = null;
|
31856 | this._dy = null;
|
31857 | this._quadrant = null;
|
31858 | if (arguments.length === 1) {
|
31859 | var edge = arguments[0];
|
31860 | this._edge = edge;
|
31861 | } else if (arguments.length === 3) {
|
31862 | var edge$1 = arguments[0];
|
31863 | var p0 = arguments[1];
|
31864 | var p1 = arguments[2];
|
31865 | var label = null;
|
31866 | this._edge = edge$1;
|
31867 | this.init(p0, p1);
|
31868 | this._label = label;
|
31869 | } else if (arguments.length === 4) {
|
31870 | var edge$2 = arguments[0];
|
31871 | var p0$1 = arguments[1];
|
31872 | var p1$1 = arguments[2];
|
31873 | var label$1 = arguments[3];
|
31874 | this._edge = edge$2;
|
31875 | this.init(p0$1, p1$1);
|
31876 | this._label = label$1;
|
31877 | }
|
31878 | };
|
31879 | EdgeEnd.prototype.compareDirection = function compareDirection (e) {
|
31880 | if (this._dx === e._dx && this._dy === e._dy) { return 0 }
|
31881 | if (this._quadrant > e._quadrant) { return 1 }
|
31882 | if (this._quadrant < e._quadrant) { return -1 }
|
31883 | return CGAlgorithms.computeOrientation(e._p0, e._p1, this._p1)
|
31884 | };
|
31885 | EdgeEnd.prototype.getDy = function getDy () {
|
31886 | return this._dy
|
31887 | };
|
31888 | EdgeEnd.prototype.getCoordinate = function getCoordinate () {
|
31889 | return this._p0
|
31890 | };
|
31891 | EdgeEnd.prototype.setNode = function setNode (node) {
|
31892 | this._node = node;
|
31893 | };
|
31894 | EdgeEnd.prototype.print = function print (out) {
|
31895 | var angle = Math.atan2(this._dy, this._dx);
|
31896 | var className = this.getClass().getName();
|
31897 | var lastDotPos = className.lastIndexOf('.');
|
31898 | var name = className.substring(lastDotPos + 1);
|
31899 | out.print(' ' + name + ': ' + this._p0 + ' - ' + this._p1 + ' ' + this._quadrant + ':' + angle + ' ' + this._label);
|
31900 | };
|
31901 | EdgeEnd.prototype.compareTo = function compareTo (obj) {
|
31902 | var e = obj;
|
31903 | return this.compareDirection(e)
|
31904 | };
|
31905 | EdgeEnd.prototype.getDirectedCoordinate = function getDirectedCoordinate () {
|
31906 | return this._p1
|
31907 | };
|
31908 | EdgeEnd.prototype.getDx = function getDx () {
|
31909 | return this._dx
|
31910 | };
|
31911 | EdgeEnd.prototype.getLabel = function getLabel () {
|
31912 | return this._label
|
31913 | };
|
31914 | EdgeEnd.prototype.getEdge = function getEdge () {
|
31915 | return this._edge
|
31916 | };
|
31917 | EdgeEnd.prototype.getQuadrant = function getQuadrant () {
|
31918 | return this._quadrant
|
31919 | };
|
31920 | EdgeEnd.prototype.getNode = function getNode () {
|
31921 | return this._node
|
31922 | };
|
31923 | EdgeEnd.prototype.toString = function toString () {
|
31924 | var angle = Math.atan2(this._dy, this._dx);
|
31925 | var className = this.getClass().getName();
|
31926 | var lastDotPos = className.lastIndexOf('.');
|
31927 | var name = className.substring(lastDotPos + 1);
|
31928 | return ' ' + name + ': ' + this._p0 + ' - ' + this._p1 + ' ' + this._quadrant + ':' + angle + ' ' + this._label
|
31929 | };
|
31930 | EdgeEnd.prototype.computeLabel = function computeLabel (boundaryNodeRule) {};
|
31931 | EdgeEnd.prototype.init = function init (p0, p1) {
|
31932 | this._p0 = p0;
|
31933 | this._p1 = p1;
|
31934 | this._dx = p1.x - p0.x;
|
31935 | this._dy = p1.y - p0.y;
|
31936 | this._quadrant = Quadrant.quadrant(this._dx, this._dy);
|
31937 | Assert.isTrue(!(this._dx === 0 && this._dy === 0), 'EdgeEnd with identical endpoints found');
|
31938 | };
|
31939 | EdgeEnd.prototype.interfaces_ = function interfaces_ () {
|
31940 | return [Comparable]
|
31941 | };
|
31942 | EdgeEnd.prototype.getClass = function getClass () {
|
31943 | return EdgeEnd
|
31944 | };
|
31945 |
|
31946 | var DirectedEdge = (function (EdgeEnd$$1) {
|
31947 | function DirectedEdge () {
|
31948 | var edge = arguments[0];
|
31949 | var isForward = arguments[1];
|
31950 | EdgeEnd$$1.call(this, edge);
|
31951 | this._isForward = null;
|
31952 | this._isInResult = false;
|
31953 | this._isVisited = false;
|
31954 | this._sym = null;
|
31955 | this._next = null;
|
31956 | this._nextMin = null;
|
31957 | this._edgeRing = null;
|
31958 | this._minEdgeRing = null;
|
31959 | this._depth = [0, -999, -999];
|
31960 | this._isForward = isForward;
|
31961 | if (isForward) {
|
31962 | this.init(edge.getCoordinate(0), edge.getCoordinate(1));
|
31963 | } else {
|
31964 | var n = edge.getNumPoints() - 1;
|
31965 | this.init(edge.getCoordinate(n), edge.getCoordinate(n - 1));
|
31966 | }
|
31967 | this.computeDirectedLabel();
|
31968 | }
|
31969 |
|
31970 | if ( EdgeEnd$$1 ) DirectedEdge.__proto__ = EdgeEnd$$1;
|
31971 | DirectedEdge.prototype = Object.create( EdgeEnd$$1 && EdgeEnd$$1.prototype );
|
31972 | DirectedEdge.prototype.constructor = DirectedEdge;
|
31973 | DirectedEdge.prototype.getNextMin = function getNextMin () {
|
31974 | return this._nextMin
|
31975 | };
|
31976 | DirectedEdge.prototype.getDepth = function getDepth (position) {
|
31977 | return this._depth[position]
|
31978 | };
|
31979 | DirectedEdge.prototype.setVisited = function setVisited (isVisited) {
|
31980 | this._isVisited = isVisited;
|
31981 | };
|
31982 | DirectedEdge.prototype.computeDirectedLabel = function computeDirectedLabel () {
|
31983 | this._label = new Label(this._edge.getLabel());
|
31984 | if (!this._isForward) { this._label.flip(); }
|
31985 | };
|
31986 | DirectedEdge.prototype.getNext = function getNext () {
|
31987 | return this._next
|
31988 | };
|
31989 | DirectedEdge.prototype.setDepth = function setDepth (position, depthVal) {
|
31990 | if (this._depth[position] !== -999) {
|
31991 | if (this._depth[position] !== depthVal) { throw new TopologyException('assigned depths do not match', this.getCoordinate()) }
|
31992 | }
|
31993 | this._depth[position] = depthVal;
|
31994 | };
|
31995 | DirectedEdge.prototype.isInteriorAreaEdge = function isInteriorAreaEdge () {
|
31996 | var this$1 = this;
|
31997 |
|
31998 | var isInteriorAreaEdge = true;
|
31999 | for (var i = 0; i < 2; i++) {
|
32000 | if (!(this$1._label.isArea(i) && this$1._label.getLocation(i, Position.LEFT) === Location.INTERIOR && this$1._label.getLocation(i, Position.RIGHT) === Location.INTERIOR)) {
|
32001 | isInteriorAreaEdge = false;
|
32002 | }
|
32003 | }
|
32004 | return isInteriorAreaEdge
|
32005 | };
|
32006 | DirectedEdge.prototype.setNextMin = function setNextMin (nextMin) {
|
32007 | this._nextMin = nextMin;
|
32008 | };
|
32009 | DirectedEdge.prototype.print = function print (out) {
|
32010 | EdgeEnd$$1.prototype.print.call(this, out);
|
32011 | out.print(' ' + this._depth[Position.LEFT] + '/' + this._depth[Position.RIGHT]);
|
32012 | out.print(' (' + this.getDepthDelta() + ')');
|
32013 | if (this._isInResult) { out.print(' inResult'); }
|
32014 | };
|
32015 | DirectedEdge.prototype.setMinEdgeRing = function setMinEdgeRing (minEdgeRing) {
|
32016 | this._minEdgeRing = minEdgeRing;
|
32017 | };
|
32018 | DirectedEdge.prototype.isLineEdge = function isLineEdge () {
|
32019 | var isLine = this._label.isLine(0) || this._label.isLine(1);
|
32020 | var isExteriorIfArea0 = !this._label.isArea(0) || this._label.allPositionsEqual(0, Location.EXTERIOR);
|
32021 | var isExteriorIfArea1 = !this._label.isArea(1) || this._label.allPositionsEqual(1, Location.EXTERIOR);
|
32022 | return isLine && isExteriorIfArea0 && isExteriorIfArea1
|
32023 | };
|
32024 | DirectedEdge.prototype.setEdgeRing = function setEdgeRing (edgeRing) {
|
32025 | this._edgeRing = edgeRing;
|
32026 | };
|
32027 | DirectedEdge.prototype.getMinEdgeRing = function getMinEdgeRing () {
|
32028 | return this._minEdgeRing
|
32029 | };
|
32030 | DirectedEdge.prototype.getDepthDelta = function getDepthDelta () {
|
32031 | var depthDelta = this._edge.getDepthDelta();
|
32032 | if (!this._isForward) { depthDelta = -depthDelta; }
|
32033 | return depthDelta
|
32034 | };
|
32035 | DirectedEdge.prototype.setInResult = function setInResult (isInResult) {
|
32036 | this._isInResult = isInResult;
|
32037 | };
|
32038 | DirectedEdge.prototype.getSym = function getSym () {
|
32039 | return this._sym
|
32040 | };
|
32041 | DirectedEdge.prototype.isForward = function isForward () {
|
32042 | return this._isForward
|
32043 | };
|
32044 | DirectedEdge.prototype.getEdge = function getEdge () {
|
32045 | return this._edge
|
32046 | };
|
32047 | DirectedEdge.prototype.printEdge = function printEdge (out) {
|
32048 | this.print(out);
|
32049 | out.print(' ');
|
32050 | if (this._isForward) { this._edge.print(out); } else { this._edge.printReverse(out); }
|
32051 | };
|
32052 | DirectedEdge.prototype.setSym = function setSym (de) {
|
32053 | this._sym = de;
|
32054 | };
|
32055 | DirectedEdge.prototype.setVisitedEdge = function setVisitedEdge (isVisited) {
|
32056 | this.setVisited(isVisited);
|
32057 | this._sym.setVisited(isVisited);
|
32058 | };
|
32059 | DirectedEdge.prototype.setEdgeDepths = function setEdgeDepths (position, depth) {
|
32060 | var depthDelta = this.getEdge().getDepthDelta();
|
32061 | if (!this._isForward) { depthDelta = -depthDelta; }
|
32062 | var directionFactor = 1;
|
32063 | if (position === Position.LEFT) { directionFactor = -1; }
|
32064 | var oppositePos = Position.opposite(position);
|
32065 | var delta = depthDelta * directionFactor;
|
32066 | var oppositeDepth = depth + delta;
|
32067 | this.setDepth(position, depth);
|
32068 | this.setDepth(oppositePos, oppositeDepth);
|
32069 | };
|
32070 | DirectedEdge.prototype.getEdgeRing = function getEdgeRing () {
|
32071 | return this._edgeRing
|
32072 | };
|
32073 | DirectedEdge.prototype.isInResult = function isInResult () {
|
32074 | return this._isInResult
|
32075 | };
|
32076 | DirectedEdge.prototype.setNext = function setNext (next) {
|
32077 | this._next = next;
|
32078 | };
|
32079 | DirectedEdge.prototype.isVisited = function isVisited () {
|
32080 | return this._isVisited
|
32081 | };
|
32082 | DirectedEdge.prototype.interfaces_ = function interfaces_ () {
|
32083 | return []
|
32084 | };
|
32085 | DirectedEdge.prototype.getClass = function getClass () {
|
32086 | return DirectedEdge
|
32087 | };
|
32088 | DirectedEdge.depthFactor = function depthFactor (currLocation, nextLocation) {
|
32089 | if (currLocation === Location.EXTERIOR && nextLocation === Location.INTERIOR) { return 1; } else if (currLocation === Location.INTERIOR && nextLocation === Location.EXTERIOR) { return -1 }
|
32090 | return 0
|
32091 | };
|
32092 |
|
32093 | return DirectedEdge;
|
32094 | }(EdgeEnd));
|
32095 |
|
32096 | var NodeFactory = function NodeFactory () {};
|
32097 |
|
32098 | NodeFactory.prototype.createNode = function createNode (coord) {
|
32099 | return new Node$2(coord, null)
|
32100 | };
|
32101 | NodeFactory.prototype.interfaces_ = function interfaces_ () {
|
32102 | return []
|
32103 | };
|
32104 | NodeFactory.prototype.getClass = function getClass () {
|
32105 | return NodeFactory
|
32106 | };
|
32107 |
|
32108 | var PlanarGraph = function PlanarGraph () {
|
32109 | this._edges = new ArrayList();
|
32110 | this._nodes = null;
|
32111 | this._edgeEndList = new ArrayList();
|
32112 | if (arguments.length === 0) {
|
32113 | this._nodes = new NodeMap(new NodeFactory());
|
32114 | } else if (arguments.length === 1) {
|
32115 | var nodeFact = arguments[0];
|
32116 | this._nodes = new NodeMap(nodeFact);
|
32117 | }
|
32118 | };
|
32119 | PlanarGraph.prototype.printEdges = function printEdges (out) {
|
32120 | var this$1 = this;
|
32121 |
|
32122 | out.println('Edges:');
|
32123 | for (var i = 0; i < this._edges.size(); i++) {
|
32124 | out.println('edge ' + i + ':');
|
32125 | var e = this$1._edges.get(i);
|
32126 | e.print(out);
|
32127 | e.eiList.print(out);
|
32128 | }
|
32129 | };
|
32130 | PlanarGraph.prototype.find = function find (coord) {
|
32131 | return this._nodes.find(coord)
|
32132 | };
|
32133 | PlanarGraph.prototype.addNode = function addNode () {
|
32134 | if (arguments[0] instanceof Node$2) {
|
32135 | var node = arguments[0];
|
32136 | return this._nodes.addNode(node)
|
32137 | } else if (arguments[0] instanceof Coordinate) {
|
32138 | var coord = arguments[0];
|
32139 | return this._nodes.addNode(coord)
|
32140 | }
|
32141 | };
|
32142 | PlanarGraph.prototype.getNodeIterator = function getNodeIterator () {
|
32143 | return this._nodes.iterator()
|
32144 | };
|
32145 | PlanarGraph.prototype.linkResultDirectedEdges = function linkResultDirectedEdges () {
|
32146 | for (var nodeit = this._nodes.iterator(); nodeit.hasNext();) {
|
32147 | var node = nodeit.next();
|
32148 | node.getEdges().linkResultDirectedEdges();
|
32149 | }
|
32150 | };
|
32151 | PlanarGraph.prototype.debugPrintln = function debugPrintln (o) {
|
32152 | System.out.println(o);
|
32153 | };
|
32154 | PlanarGraph.prototype.isBoundaryNode = function isBoundaryNode (geomIndex, coord) {
|
32155 | var node = this._nodes.find(coord);
|
32156 | if (node === null) { return false }
|
32157 | var label = node.getLabel();
|
32158 | if (label !== null && label.getLocation(geomIndex) === Location.BOUNDARY) { return true }
|
32159 | return false
|
32160 | };
|
32161 | PlanarGraph.prototype.linkAllDirectedEdges = function linkAllDirectedEdges () {
|
32162 | for (var nodeit = this._nodes.iterator(); nodeit.hasNext();) {
|
32163 | var node = nodeit.next();
|
32164 | node.getEdges().linkAllDirectedEdges();
|
32165 | }
|
32166 | };
|
32167 | PlanarGraph.prototype.matchInSameDirection = function matchInSameDirection (p0, p1, ep0, ep1) {
|
32168 | if (!p0.equals(ep0)) { return false }
|
32169 | if (CGAlgorithms.computeOrientation(p0, p1, ep1) === CGAlgorithms.COLLINEAR && Quadrant.quadrant(p0, p1) === Quadrant.quadrant(ep0, ep1)) { return true }
|
32170 | return false
|
32171 | };
|
32172 | PlanarGraph.prototype.getEdgeEnds = function getEdgeEnds () {
|
32173 | return this._edgeEndList
|
32174 | };
|
32175 | PlanarGraph.prototype.debugPrint = function debugPrint (o) {
|
32176 | System.out.print(o);
|
32177 | };
|
32178 | PlanarGraph.prototype.getEdgeIterator = function getEdgeIterator () {
|
32179 | return this._edges.iterator()
|
32180 | };
|
32181 | PlanarGraph.prototype.findEdgeInSameDirection = function findEdgeInSameDirection (p0, p1) {
|
32182 | var this$1 = this;
|
32183 |
|
32184 | for (var i = 0; i < this._edges.size(); i++) {
|
32185 | var e = this$1._edges.get(i);
|
32186 | var eCoord = e.getCoordinates();
|
32187 | if (this$1.matchInSameDirection(p0, p1, eCoord[0], eCoord[1])) { return e }
|
32188 | if (this$1.matchInSameDirection(p0, p1, eCoord[eCoord.length - 1], eCoord[eCoord.length - 2])) { return e }
|
32189 | }
|
32190 | return null
|
32191 | };
|
32192 | PlanarGraph.prototype.insertEdge = function insertEdge (e) {
|
32193 | this._edges.add(e);
|
32194 | };
|
32195 | PlanarGraph.prototype.findEdgeEnd = function findEdgeEnd (e) {
|
32196 | for (var i = this.getEdgeEnds().iterator(); i.hasNext();) {
|
32197 | var ee = i.next();
|
32198 | if (ee.getEdge() === e) { return ee }
|
32199 | }
|
32200 | return null
|
32201 | };
|
32202 | PlanarGraph.prototype.addEdges = function addEdges (edgesToAdd) {
|
32203 | var this$1 = this;
|
32204 |
|
32205 | for (var it = edgesToAdd.iterator(); it.hasNext();) {
|
32206 | var e = it.next();
|
32207 | this$1._edges.add(e);
|
32208 | var de1 = new DirectedEdge(e, true);
|
32209 | var de2 = new DirectedEdge(e, false);
|
32210 | de1.setSym(de2);
|
32211 | de2.setSym(de1);
|
32212 | this$1.add(de1);
|
32213 | this$1.add(de2);
|
32214 | }
|
32215 | };
|
32216 | PlanarGraph.prototype.add = function add (e) {
|
32217 | this._nodes.add(e);
|
32218 | this._edgeEndList.add(e);
|
32219 | };
|
32220 | PlanarGraph.prototype.getNodes = function getNodes () {
|
32221 | return this._nodes.values()
|
32222 | };
|
32223 | PlanarGraph.prototype.findEdge = function findEdge (p0, p1) {
|
32224 | var this$1 = this;
|
32225 |
|
32226 | for (var i = 0; i < this._edges.size(); i++) {
|
32227 | var e = this$1._edges.get(i);
|
32228 | var eCoord = e.getCoordinates();
|
32229 | if (p0.equals(eCoord[0]) && p1.equals(eCoord[1])) { return e }
|
32230 | }
|
32231 | return null
|
32232 | };
|
32233 | PlanarGraph.prototype.interfaces_ = function interfaces_ () {
|
32234 | return []
|
32235 | };
|
32236 | PlanarGraph.prototype.getClass = function getClass () {
|
32237 | return PlanarGraph
|
32238 | };
|
32239 | PlanarGraph.linkResultDirectedEdges = function linkResultDirectedEdges (nodes) {
|
32240 | for (var nodeit = nodes.iterator(); nodeit.hasNext();) {
|
32241 | var node = nodeit.next();
|
32242 | node.getEdges().linkResultDirectedEdges();
|
32243 | }
|
32244 | };
|
32245 |
|
32246 | var PolygonBuilder = function PolygonBuilder () {
|
32247 | this._geometryFactory = null;
|
32248 | this._shellList = new ArrayList();
|
32249 | var geometryFactory = arguments[0];
|
32250 | this._geometryFactory = geometryFactory;
|
32251 | };
|
32252 | PolygonBuilder.prototype.sortShellsAndHoles = function sortShellsAndHoles (edgeRings, shellList, freeHoleList) {
|
32253 | for (var it = edgeRings.iterator(); it.hasNext();) {
|
32254 | var er = it.next();
|
32255 | if (er.isHole()) {
|
32256 | freeHoleList.add(er);
|
32257 | } else {
|
32258 | shellList.add(er);
|
32259 | }
|
32260 | }
|
32261 | };
|
32262 | PolygonBuilder.prototype.computePolygons = function computePolygons (shellList) {
|
32263 | var this$1 = this;
|
32264 |
|
32265 | var resultPolyList = new ArrayList();
|
32266 | for (var it = shellList.iterator(); it.hasNext();) {
|
32267 | var er = it.next();
|
32268 | var poly = er.toPolygon(this$1._geometryFactory);
|
32269 | resultPolyList.add(poly);
|
32270 | }
|
32271 | return resultPolyList
|
32272 | };
|
32273 | PolygonBuilder.prototype.placeFreeHoles = function placeFreeHoles (shellList, freeHoleList) {
|
32274 | var this$1 = this;
|
32275 |
|
32276 | for (var it = freeHoleList.iterator(); it.hasNext();) {
|
32277 | var hole = it.next();
|
32278 | if (hole.getShell() === null) {
|
32279 | var shell = this$1.findEdgeRingContaining(hole, shellList);
|
32280 | if (shell === null) { throw new TopologyException('unable to assign hole to a shell', hole.getCoordinate(0)) }
|
32281 | hole.setShell(shell);
|
32282 | }
|
32283 | }
|
32284 | };
|
32285 | PolygonBuilder.prototype.buildMinimalEdgeRings = function buildMinimalEdgeRings (maxEdgeRings, shellList, freeHoleList) {
|
32286 | var this$1 = this;
|
32287 |
|
32288 | var edgeRings = new ArrayList();
|
32289 | for (var it = maxEdgeRings.iterator(); it.hasNext();) {
|
32290 | var er = it.next();
|
32291 | if (er.getMaxNodeDegree() > 2) {
|
32292 | er.linkDirectedEdgesForMinimalEdgeRings();
|
32293 | var minEdgeRings = er.buildMinimalRings();
|
32294 | var shell = this$1.findShell(minEdgeRings);
|
32295 | if (shell !== null) {
|
32296 | this$1.placePolygonHoles(shell, minEdgeRings);
|
32297 | shellList.add(shell);
|
32298 | } else {
|
32299 | freeHoleList.addAll(minEdgeRings);
|
32300 | }
|
32301 | } else {
|
32302 | edgeRings.add(er);
|
32303 | }
|
32304 | }
|
32305 | return edgeRings
|
32306 | };
|
32307 | PolygonBuilder.prototype.containsPoint = function containsPoint (p) {
|
32308 | for (var it = this._shellList.iterator(); it.hasNext();) {
|
32309 | var er = it.next();
|
32310 | if (er.containsPoint(p)) { return true }
|
32311 | }
|
32312 | return false
|
32313 | };
|
32314 | PolygonBuilder.prototype.buildMaximalEdgeRings = function buildMaximalEdgeRings (dirEdges) {
|
32315 | var this$1 = this;
|
32316 |
|
32317 | var maxEdgeRings = new ArrayList();
|
32318 | for (var it = dirEdges.iterator(); it.hasNext();) {
|
32319 | var de = it.next();
|
32320 | if (de.isInResult() && de.getLabel().isArea()) {
|
32321 | if (de.getEdgeRing() === null) {
|
32322 | var er = new MaximalEdgeRing(de, this$1._geometryFactory);
|
32323 | maxEdgeRings.add(er);
|
32324 | er.setInResult();
|
32325 | }
|
32326 | }
|
32327 | }
|
32328 | return maxEdgeRings
|
32329 | };
|
32330 | PolygonBuilder.prototype.placePolygonHoles = function placePolygonHoles (shell, minEdgeRings) {
|
32331 | for (var it = minEdgeRings.iterator(); it.hasNext();) {
|
32332 | var er = it.next();
|
32333 | if (er.isHole()) {
|
32334 | er.setShell(shell);
|
32335 | }
|
32336 | }
|
32337 | };
|
32338 | PolygonBuilder.prototype.getPolygons = function getPolygons () {
|
32339 | var resultPolyList = this.computePolygons(this._shellList);
|
32340 | return resultPolyList
|
32341 | };
|
32342 | PolygonBuilder.prototype.findEdgeRingContaining = function findEdgeRingContaining (testEr, shellList) {
|
32343 | var testRing = testEr.getLinearRing();
|
32344 | var testEnv = testRing.getEnvelopeInternal();
|
32345 | var testPt = testRing.getCoordinateN(0);
|
32346 | var minShell = null;
|
32347 | var minEnv = null;
|
32348 | for (var it = shellList.iterator(); it.hasNext();) {
|
32349 | var tryShell = it.next();
|
32350 | var tryRing = tryShell.getLinearRing();
|
32351 | var tryEnv = tryRing.getEnvelopeInternal();
|
32352 | if (minShell !== null) { minEnv = minShell.getLinearRing().getEnvelopeInternal(); }
|
32353 | var isContained = false;
|
32354 | if (tryEnv.contains(testEnv) && CGAlgorithms.isPointInRing(testPt, tryRing.getCoordinates())) { isContained = true; }
|
32355 | if (isContained) {
|
32356 | if (minShell === null || minEnv.contains(tryEnv)) {
|
32357 | minShell = tryShell;
|
32358 | }
|
32359 | }
|
32360 | }
|
32361 | return minShell
|
32362 | };
|
32363 | PolygonBuilder.prototype.findShell = function findShell (minEdgeRings) {
|
32364 | var shellCount = 0;
|
32365 | var shell = null;
|
32366 | for (var it = minEdgeRings.iterator(); it.hasNext();) {
|
32367 | var er = it.next();
|
32368 | if (!er.isHole()) {
|
32369 | shell = er;
|
32370 | shellCount++;
|
32371 | }
|
32372 | }
|
32373 | Assert.isTrue(shellCount <= 1, 'found two shells in MinimalEdgeRing list');
|
32374 | return shell
|
32375 | };
|
32376 | PolygonBuilder.prototype.add = function add () {
|
32377 | if (arguments.length === 1) {
|
32378 | var graph = arguments[0];
|
32379 | this.add(graph.getEdgeEnds(), graph.getNodes());
|
32380 | } else if (arguments.length === 2) {
|
32381 | var dirEdges = arguments[0];
|
32382 | var nodes = arguments[1];
|
32383 | PlanarGraph.linkResultDirectedEdges(nodes);
|
32384 | var maxEdgeRings = this.buildMaximalEdgeRings(dirEdges);
|
32385 | var freeHoleList = new ArrayList();
|
32386 | var edgeRings = this.buildMinimalEdgeRings(maxEdgeRings, this._shellList, freeHoleList);
|
32387 | this.sortShellsAndHoles(edgeRings, this._shellList, freeHoleList);
|
32388 | this.placeFreeHoles(this._shellList, freeHoleList);
|
32389 | }
|
32390 | };
|
32391 | PolygonBuilder.prototype.interfaces_ = function interfaces_ () {
|
32392 | return []
|
32393 | };
|
32394 | PolygonBuilder.prototype.getClass = function getClass () {
|
32395 | return PolygonBuilder
|
32396 | };
|
32397 |
|
32398 | var Boundable = function Boundable () {};
|
32399 |
|
32400 | Boundable.prototype.getBounds = function getBounds () {};
|
32401 | Boundable.prototype.interfaces_ = function interfaces_ () {
|
32402 | return []
|
32403 | };
|
32404 | Boundable.prototype.getClass = function getClass () {
|
32405 | return Boundable
|
32406 | };
|
32407 |
|
32408 | var ItemBoundable = function ItemBoundable () {
|
32409 | this._bounds = null;
|
32410 | this._item = null;
|
32411 | var bounds = arguments[0];
|
32412 | var item = arguments[1];
|
32413 | this._bounds = bounds;
|
32414 | this._item = item;
|
32415 | };
|
32416 | ItemBoundable.prototype.getItem = function getItem () {
|
32417 | return this._item
|
32418 | };
|
32419 | ItemBoundable.prototype.getBounds = function getBounds () {
|
32420 | return this._bounds
|
32421 | };
|
32422 | ItemBoundable.prototype.interfaces_ = function interfaces_ () {
|
32423 | return [Boundable, Serializable]
|
32424 | };
|
32425 | ItemBoundable.prototype.getClass = function getClass () {
|
32426 | return ItemBoundable
|
32427 | };
|
32428 |
|
32429 | var PriorityQueue = function PriorityQueue () {
|
32430 | this._size = null;
|
32431 | this._items = null;
|
32432 | this._size = 0;
|
32433 | this._items = new ArrayList();
|
32434 | this._items.add(null);
|
32435 | };
|
32436 | PriorityQueue.prototype.poll = function poll () {
|
32437 | if (this.isEmpty()) { return null }
|
32438 | var minItem = this._items.get(1);
|
32439 | this._items.set(1, this._items.get(this._size));
|
32440 | this._size -= 1;
|
32441 | this.reorder(1);
|
32442 | return minItem
|
32443 | };
|
32444 | PriorityQueue.prototype.size = function size () {
|
32445 | return this._size
|
32446 | };
|
32447 | PriorityQueue.prototype.reorder = function reorder (hole) {
|
32448 | var this$1 = this;
|
32449 |
|
32450 | var child = null;
|
32451 | var tmp = this._items.get(hole);
|
32452 | for (; hole * 2 <= this._size; hole = child) {
|
32453 | child = hole * 2;
|
32454 | if (child !== this$1._size && this$1._items.get(child + 1).compareTo(this$1._items.get(child)) < 0) { child++; }
|
32455 | if (this$1._items.get(child).compareTo(tmp) < 0) { this$1._items.set(hole, this$1._items.get(child)); } else { break }
|
32456 | }
|
32457 | this._items.set(hole, tmp);
|
32458 | };
|
32459 | PriorityQueue.prototype.clear = function clear () {
|
32460 | this._size = 0;
|
32461 | this._items.clear();
|
32462 | };
|
32463 | PriorityQueue.prototype.isEmpty = function isEmpty () {
|
32464 | return this._size === 0
|
32465 | };
|
32466 | PriorityQueue.prototype.add = function add (x) {
|
32467 | var this$1 = this;
|
32468 |
|
32469 | this._items.add(null);
|
32470 | this._size += 1;
|
32471 | var hole = this._size;
|
32472 | this._items.set(0, x);
|
32473 | for (; x.compareTo(this._items.get(Math.trunc(hole / 2))) < 0; hole /= 2) {
|
32474 | this$1._items.set(hole, this$1._items.get(Math.trunc(hole / 2)));
|
32475 | }
|
32476 | this._items.set(hole, x);
|
32477 | };
|
32478 | PriorityQueue.prototype.interfaces_ = function interfaces_ () {
|
32479 | return []
|
32480 | };
|
32481 | PriorityQueue.prototype.getClass = function getClass () {
|
32482 | return PriorityQueue
|
32483 | };
|
32484 |
|
32485 | var ItemVisitor = function ItemVisitor () {};
|
32486 |
|
32487 | ItemVisitor.prototype.visitItem = function visitItem (item) {};
|
32488 | ItemVisitor.prototype.interfaces_ = function interfaces_ () {
|
32489 | return []
|
32490 | };
|
32491 | ItemVisitor.prototype.getClass = function getClass () {
|
32492 | return ItemVisitor
|
32493 | };
|
32494 |
|
32495 | var SpatialIndex = function SpatialIndex () {};
|
32496 |
|
32497 | SpatialIndex.prototype.insert = function insert (itemEnv, item) {};
|
32498 | SpatialIndex.prototype.remove = function remove (itemEnv, item) {};
|
32499 | SpatialIndex.prototype.query = function query () {
|
32500 |
|
32501 |
|
32502 |
|
32503 |
|
32504 |
|
32505 |
|
32506 | };
|
32507 | SpatialIndex.prototype.interfaces_ = function interfaces_ () {
|
32508 | return []
|
32509 | };
|
32510 | SpatialIndex.prototype.getClass = function getClass () {
|
32511 | return SpatialIndex
|
32512 | };
|
32513 |
|
32514 | var AbstractNode = function AbstractNode () {
|
32515 | this._childBoundables = new ArrayList();
|
32516 | this._bounds = null;
|
32517 | this._level = null;
|
32518 | if (arguments.length === 0) {} else if (arguments.length === 1) {
|
32519 | var level = arguments[0];
|
32520 | this._level = level;
|
32521 | }
|
32522 | };
|
32523 |
|
32524 | var staticAccessors$22 = { serialVersionUID: { configurable: true } };
|
32525 | AbstractNode.prototype.getLevel = function getLevel () {
|
32526 | return this._level
|
32527 | };
|
32528 | AbstractNode.prototype.size = function size () {
|
32529 | return this._childBoundables.size()
|
32530 | };
|
32531 | AbstractNode.prototype.getChildBoundables = function getChildBoundables () {
|
32532 | return this._childBoundables
|
32533 | };
|
32534 | AbstractNode.prototype.addChildBoundable = function addChildBoundable (childBoundable) {
|
32535 | Assert.isTrue(this._bounds === null);
|
32536 | this._childBoundables.add(childBoundable);
|
32537 | };
|
32538 | AbstractNode.prototype.isEmpty = function isEmpty () {
|
32539 | return this._childBoundables.isEmpty()
|
32540 | };
|
32541 | AbstractNode.prototype.getBounds = function getBounds () {
|
32542 | if (this._bounds === null) {
|
32543 | this._bounds = this.computeBounds();
|
32544 | }
|
32545 | return this._bounds
|
32546 | };
|
32547 | AbstractNode.prototype.interfaces_ = function interfaces_ () {
|
32548 | return [Boundable, Serializable]
|
32549 | };
|
32550 | AbstractNode.prototype.getClass = function getClass () {
|
32551 | return AbstractNode
|
32552 | };
|
32553 | staticAccessors$22.serialVersionUID.get = function () { return 6493722185909573708 };
|
32554 |
|
32555 | Object.defineProperties( AbstractNode, staticAccessors$22 );
|
32556 |
|
32557 | var Collections = function Collections () {};
|
32558 |
|
32559 | Collections.reverseOrder = function reverseOrder () {
|
32560 | return {
|
32561 | compare: function compare (a, b) {
|
32562 | return b.compareTo(a)
|
32563 | }
|
32564 | }
|
32565 | };
|
32566 | Collections.min = function min (l) {
|
32567 | Collections.sort(l);
|
32568 | return l.get(0)
|
32569 | };
|
32570 | Collections.sort = function sort (l, c) {
|
32571 | var a = l.toArray();
|
32572 | if (c) {
|
32573 | Arrays.sort(a, c);
|
32574 | } else {
|
32575 | Arrays.sort(a);
|
32576 | }
|
32577 | var i = l.iterator();
|
32578 | for (var pos = 0, alen = a.length; pos < alen; pos++) {
|
32579 | i.next();
|
32580 | i.set(a[pos]);
|
32581 | }
|
32582 | };
|
32583 | Collections.singletonList = function singletonList (o) {
|
32584 | var arrayList = new ArrayList();
|
32585 | arrayList.add(o);
|
32586 | return arrayList
|
32587 | };
|
32588 |
|
32589 | var BoundablePair = function BoundablePair () {
|
32590 | this._boundable1 = null;
|
32591 | this._boundable2 = null;
|
32592 | this._distance = null;
|
32593 | this._itemDistance = null;
|
32594 | var boundable1 = arguments[0];
|
32595 | var boundable2 = arguments[1];
|
32596 | var itemDistance = arguments[2];
|
32597 | this._boundable1 = boundable1;
|
32598 | this._boundable2 = boundable2;
|
32599 | this._itemDistance = itemDistance;
|
32600 | this._distance = this.distance();
|
32601 | };
|
32602 | BoundablePair.prototype.expandToQueue = function expandToQueue (priQ, minDistance) {
|
32603 | var isComp1 = BoundablePair.isComposite(this._boundable1);
|
32604 | var isComp2 = BoundablePair.isComposite(this._boundable2);
|
32605 | if (isComp1 && isComp2) {
|
32606 | if (BoundablePair.area(this._boundable1) > BoundablePair.area(this._boundable2)) {
|
32607 | this.expand(this._boundable1, this._boundable2, priQ, minDistance);
|
32608 | return null
|
32609 | } else {
|
32610 | this.expand(this._boundable2, this._boundable1, priQ, minDistance);
|
32611 | return null
|
32612 | }
|
32613 | } else if (isComp1) {
|
32614 | this.expand(this._boundable1, this._boundable2, priQ, minDistance);
|
32615 | return null
|
32616 | } else if (isComp2) {
|
32617 | this.expand(this._boundable2, this._boundable1, priQ, minDistance);
|
32618 | return null
|
32619 | }
|
32620 | throw new IllegalArgumentException('neither boundable is composite')
|
32621 | };
|
32622 | BoundablePair.prototype.isLeaves = function isLeaves () {
|
32623 | return !(BoundablePair.isComposite(this._boundable1) || BoundablePair.isComposite(this._boundable2))
|
32624 | };
|
32625 | BoundablePair.prototype.compareTo = function compareTo (o) {
|
32626 | var nd = o;
|
32627 | if (this._distance < nd._distance) { return -1 }
|
32628 | if (this._distance > nd._distance) { return 1 }
|
32629 | return 0
|
32630 | };
|
32631 | BoundablePair.prototype.expand = function expand (bndComposite, bndOther, priQ, minDistance) {
|
32632 | var this$1 = this;
|
32633 |
|
32634 | var children = bndComposite.getChildBoundables();
|
32635 | for (var i = children.iterator(); i.hasNext();) {
|
32636 | var child = i.next();
|
32637 | var bp = new BoundablePair(child, bndOther, this$1._itemDistance);
|
32638 | if (bp.getDistance() < minDistance) {
|
32639 | priQ.add(bp);
|
32640 | }
|
32641 | }
|
32642 | };
|
32643 | BoundablePair.prototype.getBoundable = function getBoundable (i) {
|
32644 | if (i === 0) { return this._boundable1 }
|
32645 | return this._boundable2
|
32646 | };
|
32647 | BoundablePair.prototype.getDistance = function getDistance () {
|
32648 | return this._distance
|
32649 | };
|
32650 | BoundablePair.prototype.distance = function distance () {
|
32651 | if (this.isLeaves()) {
|
32652 | return this._itemDistance.distance(this._boundable1, this._boundable2)
|
32653 | }
|
32654 | return this._boundable1.getBounds().distance(this._boundable2.getBounds())
|
32655 | };
|
32656 | BoundablePair.prototype.interfaces_ = function interfaces_ () {
|
32657 | return [Comparable]
|
32658 | };
|
32659 | BoundablePair.prototype.getClass = function getClass () {
|
32660 | return BoundablePair
|
32661 | };
|
32662 | BoundablePair.area = function area (b) {
|
32663 | return b.getBounds().getArea()
|
32664 | };
|
32665 | BoundablePair.isComposite = function isComposite (item) {
|
32666 | return item instanceof AbstractNode
|
32667 | };
|
32668 |
|
32669 | var AbstractSTRtree = function AbstractSTRtree () {
|
32670 | this._root = null;
|
32671 | this._built = false;
|
32672 | this._itemBoundables = new ArrayList();
|
32673 | this._nodeCapacity = null;
|
32674 | if (arguments.length === 0) {
|
32675 | var nodeCapacity = AbstractSTRtree.DEFAULT_NODE_CAPACITY;
|
32676 | this._nodeCapacity = nodeCapacity;
|
32677 | } else if (arguments.length === 1) {
|
32678 | var nodeCapacity$1 = arguments[0];
|
32679 | Assert.isTrue(nodeCapacity$1 > 1, 'Node capacity must be greater than 1');
|
32680 | this._nodeCapacity = nodeCapacity$1;
|
32681 | }
|
32682 | };
|
32683 |
|
32684 | var staticAccessors$23 = { IntersectsOp: { configurable: true },serialVersionUID: { configurable: true },DEFAULT_NODE_CAPACITY: { configurable: true } };
|
32685 | AbstractSTRtree.prototype.getNodeCapacity = function getNodeCapacity () {
|
32686 | return this._nodeCapacity
|
32687 | };
|
32688 | AbstractSTRtree.prototype.lastNode = function lastNode (nodes) {
|
32689 | return nodes.get(nodes.size() - 1)
|
32690 | };
|
32691 | AbstractSTRtree.prototype.size = function size () {
|
32692 | var this$1 = this;
|
32693 |
|
32694 | if (arguments.length === 0) {
|
32695 | if (this.isEmpty()) {
|
32696 | return 0
|
32697 | }
|
32698 | this.build();
|
32699 | return this.size(this._root)
|
32700 | } else if (arguments.length === 1) {
|
32701 | var node = arguments[0];
|
32702 | var size = 0;
|
32703 | for (var i = node.getChildBoundables().iterator(); i.hasNext();) {
|
32704 | var childBoundable = i.next();
|
32705 | if (childBoundable instanceof AbstractNode) {
|
32706 | size += this$1.size(childBoundable);
|
32707 | } else if (childBoundable instanceof ItemBoundable) {
|
32708 | size += 1;
|
32709 | }
|
32710 | }
|
32711 | return size
|
32712 | }
|
32713 | };
|
32714 | AbstractSTRtree.prototype.removeItem = function removeItem (node, item) {
|
32715 | var childToRemove = null;
|
32716 | for (var i = node.getChildBoundables().iterator(); i.hasNext();) {
|
32717 | var childBoundable = i.next();
|
32718 | if (childBoundable instanceof ItemBoundable) {
|
32719 | if (childBoundable.getItem() === item) { childToRemove = childBoundable; }
|
32720 | }
|
32721 | }
|
32722 | if (childToRemove !== null) {
|
32723 | node.getChildBoundables().remove(childToRemove);
|
32724 | return true
|
32725 | }
|
32726 | return false
|
32727 | };
|
32728 | AbstractSTRtree.prototype.itemsTree = function itemsTree () {
|
32729 | var this$1 = this;
|
32730 |
|
32731 | if (arguments.length === 0) {
|
32732 | this.build();
|
32733 | var valuesTree = this.itemsTree(this._root);
|
32734 | if (valuesTree === null) { return new ArrayList() }
|
32735 | return valuesTree
|
32736 | } else if (arguments.length === 1) {
|
32737 | var node = arguments[0];
|
32738 | var valuesTreeForNode = new ArrayList();
|
32739 | for (var i = node.getChildBoundables().iterator(); i.hasNext();) {
|
32740 | var childBoundable = i.next();
|
32741 | if (childBoundable instanceof AbstractNode) {
|
32742 | var valuesTreeForChild = this$1.itemsTree(childBoundable);
|
32743 | if (valuesTreeForChild !== null) { valuesTreeForNode.add(valuesTreeForChild); }
|
32744 | } else if (childBoundable instanceof ItemBoundable) {
|
32745 | valuesTreeForNode.add(childBoundable.getItem());
|
32746 | } else {
|
32747 | Assert.shouldNeverReachHere();
|
32748 | }
|
32749 | }
|
32750 | if (valuesTreeForNode.size() <= 0) { return null }
|
32751 | return valuesTreeForNode
|
32752 | }
|
32753 | };
|
32754 | AbstractSTRtree.prototype.insert = function insert (bounds, item) {
|
32755 | Assert.isTrue(!this._built, 'Cannot insert items into an STR packed R-tree after it has been built.');
|
32756 | this._itemBoundables.add(new ItemBoundable(bounds, item));
|
32757 | };
|
32758 | AbstractSTRtree.prototype.boundablesAtLevel = function boundablesAtLevel () {
|
32759 | var this$1 = this;
|
32760 |
|
32761 | if (arguments.length === 1) {
|
32762 | var level = arguments[0];
|
32763 | var boundables = new ArrayList();
|
32764 | this.boundablesAtLevel(level, this._root, boundables);
|
32765 | return boundables
|
32766 | } else if (arguments.length === 3) {
|
32767 | var level$1 = arguments[0];
|
32768 | var top = arguments[1];
|
32769 | var boundables$1 = arguments[2];
|
32770 | Assert.isTrue(level$1 > -2);
|
32771 | if (top.getLevel() === level$1) {
|
32772 | boundables$1.add(top);
|
32773 | return null
|
32774 | }
|
32775 | for (var i = top.getChildBoundables().iterator(); i.hasNext();) {
|
32776 | var boundable = i.next();
|
32777 | if (boundable instanceof AbstractNode) {
|
32778 | this$1.boundablesAtLevel(level$1, boundable, boundables$1);
|
32779 | } else {
|
32780 | Assert.isTrue(boundable instanceof ItemBoundable);
|
32781 | if (level$1 === -1) {
|
32782 | boundables$1.add(boundable);
|
32783 | }
|
32784 | }
|
32785 | }
|
32786 | return null
|
32787 | }
|
32788 | };
|
32789 | AbstractSTRtree.prototype.query = function query () {
|
32790 | var this$1 = this;
|
32791 |
|
32792 | if (arguments.length === 1) {
|
32793 | var searchBounds = arguments[0];
|
32794 | this.build();
|
32795 | var matches = new ArrayList();
|
32796 | if (this.isEmpty()) {
|
32797 | return matches
|
32798 | }
|
32799 | if (this.getIntersectsOp().intersects(this._root.getBounds(), searchBounds)) {
|
32800 | this.query(searchBounds, this._root, matches);
|
32801 | }
|
32802 | return matches
|
32803 | } else if (arguments.length === 2) {
|
32804 | var searchBounds$1 = arguments[0];
|
32805 | var visitor = arguments[1];
|
32806 | this.build();
|
32807 | if (this.isEmpty()) {
|
32808 | return null
|
32809 | }
|
32810 | if (this.getIntersectsOp().intersects(this._root.getBounds(), searchBounds$1)) {
|
32811 | this.query(searchBounds$1, this._root, visitor);
|
32812 | }
|
32813 | } else if (arguments.length === 3) {
|
32814 | if (hasInterface(arguments[2], ItemVisitor) && (arguments[0] instanceof Object && arguments[1] instanceof AbstractNode)) {
|
32815 | var searchBounds$2 = arguments[0];
|
32816 | var node = arguments[1];
|
32817 | var visitor$1 = arguments[2];
|
32818 | var childBoundables = node.getChildBoundables();
|
32819 | for (var i = 0; i < childBoundables.size(); i++) {
|
32820 | var childBoundable = childBoundables.get(i);
|
32821 | if (!this$1.getIntersectsOp().intersects(childBoundable.getBounds(), searchBounds$2)) {
|
32822 | continue
|
32823 | }
|
32824 | if (childBoundable instanceof AbstractNode) {
|
32825 | this$1.query(searchBounds$2, childBoundable, visitor$1);
|
32826 | } else if (childBoundable instanceof ItemBoundable) {
|
32827 | visitor$1.visitItem(childBoundable.getItem());
|
32828 | } else {
|
32829 | Assert.shouldNeverReachHere();
|
32830 | }
|
32831 | }
|
32832 | } else if (hasInterface(arguments[2], List) && (arguments[0] instanceof Object && arguments[1] instanceof AbstractNode)) {
|
32833 | var searchBounds$3 = arguments[0];
|
32834 | var node$1 = arguments[1];
|
32835 | var matches$1 = arguments[2];
|
32836 | var childBoundables$1 = node$1.getChildBoundables();
|
32837 | for (var i$1 = 0; i$1 < childBoundables$1.size(); i$1++) {
|
32838 | var childBoundable$1 = childBoundables$1.get(i$1);
|
32839 | if (!this$1.getIntersectsOp().intersects(childBoundable$1.getBounds(), searchBounds$3)) {
|
32840 | continue
|
32841 | }
|
32842 | if (childBoundable$1 instanceof AbstractNode) {
|
32843 | this$1.query(searchBounds$3, childBoundable$1, matches$1);
|
32844 | } else if (childBoundable$1 instanceof ItemBoundable) {
|
32845 | matches$1.add(childBoundable$1.getItem());
|
32846 | } else {
|
32847 | Assert.shouldNeverReachHere();
|
32848 | }
|
32849 | }
|
32850 | }
|
32851 | }
|
32852 | };
|
32853 | AbstractSTRtree.prototype.build = function build () {
|
32854 | if (this._built) { return null }
|
32855 | this._root = this._itemBoundables.isEmpty() ? this.createNode(0) : this.createHigherLevels(this._itemBoundables, -1);
|
32856 | this._itemBoundables = null;
|
32857 | this._built = true;
|
32858 | };
|
32859 | AbstractSTRtree.prototype.getRoot = function getRoot () {
|
32860 | this.build();
|
32861 | return this._root
|
32862 | };
|
32863 | AbstractSTRtree.prototype.remove = function remove () {
|
32864 | var this$1 = this;
|
32865 |
|
32866 | if (arguments.length === 2) {
|
32867 | var searchBounds = arguments[0];
|
32868 | var item = arguments[1];
|
32869 | this.build();
|
32870 | if (this.getIntersectsOp().intersects(this._root.getBounds(), searchBounds)) {
|
32871 | return this.remove(searchBounds, this._root, item)
|
32872 | }
|
32873 | return false
|
32874 | } else if (arguments.length === 3) {
|
32875 | var searchBounds$1 = arguments[0];
|
32876 | var node = arguments[1];
|
32877 | var item$1 = arguments[2];
|
32878 | var found = this.removeItem(node, item$1);
|
32879 | if (found) { return true }
|
32880 | var childToPrune = null;
|
32881 | for (var i = node.getChildBoundables().iterator(); i.hasNext();) {
|
32882 | var childBoundable = i.next();
|
32883 | if (!this$1.getIntersectsOp().intersects(childBoundable.getBounds(), searchBounds$1)) {
|
32884 | continue
|
32885 | }
|
32886 | if (childBoundable instanceof AbstractNode) {
|
32887 | found = this$1.remove(searchBounds$1, childBoundable, item$1);
|
32888 | if (found) {
|
32889 | childToPrune = childBoundable;
|
32890 | break
|
32891 | }
|
32892 | }
|
32893 | }
|
32894 | if (childToPrune !== null) {
|
32895 | if (childToPrune.getChildBoundables().isEmpty()) {
|
32896 | node.getChildBoundables().remove(childToPrune);
|
32897 | }
|
32898 | }
|
32899 | return found
|
32900 | }
|
32901 | };
|
32902 | AbstractSTRtree.prototype.createHigherLevels = function createHigherLevels (boundablesOfALevel, level) {
|
32903 | Assert.isTrue(!boundablesOfALevel.isEmpty());
|
32904 | var parentBoundables = this.createParentBoundables(boundablesOfALevel, level + 1);
|
32905 | if (parentBoundables.size() === 1) {
|
32906 | return parentBoundables.get(0)
|
32907 | }
|
32908 | return this.createHigherLevels(parentBoundables, level + 1)
|
32909 | };
|
32910 | AbstractSTRtree.prototype.depth = function depth () {
|
32911 | var this$1 = this;
|
32912 |
|
32913 | if (arguments.length === 0) {
|
32914 | if (this.isEmpty()) {
|
32915 | return 0
|
32916 | }
|
32917 | this.build();
|
32918 | return this.depth(this._root)
|
32919 | } else if (arguments.length === 1) {
|
32920 | var node = arguments[0];
|
32921 | var maxChildDepth = 0;
|
32922 | for (var i = node.getChildBoundables().iterator(); i.hasNext();) {
|
32923 | var childBoundable = i.next();
|
32924 | if (childBoundable instanceof AbstractNode) {
|
32925 | var childDepth = this$1.depth(childBoundable);
|
32926 | if (childDepth > maxChildDepth) { maxChildDepth = childDepth; }
|
32927 | }
|
32928 | }
|
32929 | return maxChildDepth + 1
|
32930 | }
|
32931 | };
|
32932 | AbstractSTRtree.prototype.createParentBoundables = function createParentBoundables (childBoundables, newLevel) {
|
32933 | var this$1 = this;
|
32934 |
|
32935 | Assert.isTrue(!childBoundables.isEmpty());
|
32936 | var parentBoundables = new ArrayList();
|
32937 | parentBoundables.add(this.createNode(newLevel));
|
32938 | var sortedChildBoundables = new ArrayList(childBoundables);
|
32939 | Collections.sort(sortedChildBoundables, this.getComparator());
|
32940 | for (var i = sortedChildBoundables.iterator(); i.hasNext();) {
|
32941 | var childBoundable = i.next();
|
32942 | if (this$1.lastNode(parentBoundables).getChildBoundables().size() === this$1.getNodeCapacity()) {
|
32943 | parentBoundables.add(this$1.createNode(newLevel));
|
32944 | }
|
32945 | this$1.lastNode(parentBoundables).addChildBoundable(childBoundable);
|
32946 | }
|
32947 | return parentBoundables
|
32948 | };
|
32949 | AbstractSTRtree.prototype.isEmpty = function isEmpty () {
|
32950 | if (!this._built) { return this._itemBoundables.isEmpty() }
|
32951 | return this._root.isEmpty()
|
32952 | };
|
32953 | AbstractSTRtree.prototype.interfaces_ = function interfaces_ () {
|
32954 | return [Serializable]
|
32955 | };
|
32956 | AbstractSTRtree.prototype.getClass = function getClass () {
|
32957 | return AbstractSTRtree
|
32958 | };
|
32959 | AbstractSTRtree.compareDoubles = function compareDoubles (a, b) {
|
32960 | return a > b ? 1 : a < b ? -1 : 0
|
32961 | };
|
32962 | staticAccessors$23.IntersectsOp.get = function () { return IntersectsOp };
|
32963 | staticAccessors$23.serialVersionUID.get = function () { return -3886435814360241337 };
|
32964 | staticAccessors$23.DEFAULT_NODE_CAPACITY.get = function () { return 10 };
|
32965 |
|
32966 | Object.defineProperties( AbstractSTRtree, staticAccessors$23 );
|
32967 |
|
32968 | var IntersectsOp = function IntersectsOp () {};
|
32969 |
|
32970 | var ItemDistance = function ItemDistance () {};
|
32971 |
|
32972 | ItemDistance.prototype.distance = function distance (item1, item2) {};
|
32973 | ItemDistance.prototype.interfaces_ = function interfaces_ () {
|
32974 | return []
|
32975 | };
|
32976 | ItemDistance.prototype.getClass = function getClass () {
|
32977 | return ItemDistance
|
32978 | };
|
32979 |
|
32980 | var STRtree = (function (AbstractSTRtree$$1) {
|
32981 | function STRtree (nodeCapacity) {
|
32982 | nodeCapacity = nodeCapacity || STRtree.DEFAULT_NODE_CAPACITY;
|
32983 | AbstractSTRtree$$1.call(this, nodeCapacity);
|
32984 | }
|
32985 |
|
32986 | if ( AbstractSTRtree$$1 ) STRtree.__proto__ = AbstractSTRtree$$1;
|
32987 | STRtree.prototype = Object.create( AbstractSTRtree$$1 && AbstractSTRtree$$1.prototype );
|
32988 | STRtree.prototype.constructor = STRtree;
|
32989 |
|
32990 | var staticAccessors = { STRtreeNode: { configurable: true },serialVersionUID: { configurable: true },xComparator: { configurable: true },yComparator: { configurable: true },intersectsOp: { configurable: true },DEFAULT_NODE_CAPACITY: { configurable: true } };
|
32991 | STRtree.prototype.createParentBoundablesFromVerticalSlices = function createParentBoundablesFromVerticalSlices (verticalSlices, newLevel) {
|
32992 | var this$1 = this;
|
32993 |
|
32994 | Assert.isTrue(verticalSlices.length > 0);
|
32995 | var parentBoundables = new ArrayList();
|
32996 | for (var i = 0; i < verticalSlices.length; i++) {
|
32997 | parentBoundables.addAll(this$1.createParentBoundablesFromVerticalSlice(verticalSlices[i], newLevel));
|
32998 | }
|
32999 | return parentBoundables
|
33000 | };
|
33001 | STRtree.prototype.createNode = function createNode (level) {
|
33002 | return new STRtreeNode(level)
|
33003 | };
|
33004 | STRtree.prototype.size = function size () {
|
33005 | if (arguments.length === 0) {
|
33006 | return AbstractSTRtree$$1.prototype.size.call(this)
|
33007 | } else { return AbstractSTRtree$$1.prototype.size.apply(this, arguments) }
|
33008 | };
|
33009 | STRtree.prototype.insert = function insert () {
|
33010 | if (arguments.length === 2) {
|
33011 | var itemEnv = arguments[0];
|
33012 | var item = arguments[1];
|
33013 | if (itemEnv.isNull()) {
|
33014 | return null
|
33015 | }
|
33016 | AbstractSTRtree$$1.prototype.insert.call(this, itemEnv, item);
|
33017 | } else { return AbstractSTRtree$$1.prototype.insert.apply(this, arguments) }
|
33018 | };
|
33019 | STRtree.prototype.getIntersectsOp = function getIntersectsOp () {
|
33020 | return STRtree.intersectsOp
|
33021 | };
|
33022 | STRtree.prototype.verticalSlices = function verticalSlices (childBoundables, sliceCount) {
|
33023 | var sliceCapacity = Math.trunc(Math.ceil(childBoundables.size() / sliceCount));
|
33024 | var slices = new Array(sliceCount).fill(null);
|
33025 | var i = childBoundables.iterator();
|
33026 | for (var j = 0; j < sliceCount; j++) {
|
33027 | slices[j] = new ArrayList();
|
33028 | var boundablesAddedToSlice = 0;
|
33029 | while (i.hasNext() && boundablesAddedToSlice < sliceCapacity) {
|
33030 | var childBoundable = i.next();
|
33031 | slices[j].add(childBoundable);
|
33032 | boundablesAddedToSlice++;
|
33033 | }
|
33034 | }
|
33035 | return slices
|
33036 | };
|
33037 | STRtree.prototype.query = function query () {
|
33038 | if (arguments.length === 1) {
|
33039 | var searchEnv = arguments[0];
|
33040 | return AbstractSTRtree$$1.prototype.query.call(this, searchEnv)
|
33041 | } else if (arguments.length === 2) {
|
33042 | var searchEnv$1 = arguments[0];
|
33043 | var visitor = arguments[1];
|
33044 | AbstractSTRtree$$1.prototype.query.call(this, searchEnv$1, visitor);
|
33045 | } else if (arguments.length === 3) {
|
33046 | if (hasInterface(arguments[2], ItemVisitor) && (arguments[0] instanceof Object && arguments[1] instanceof AbstractNode)) {
|
33047 | var searchBounds = arguments[0];
|
33048 | var node = arguments[1];
|
33049 | var visitor$1 = arguments[2];
|
33050 | AbstractSTRtree$$1.prototype.query.call(this, searchBounds, node, visitor$1);
|
33051 | } else if (hasInterface(arguments[2], List) && (arguments[0] instanceof Object && arguments[1] instanceof AbstractNode)) {
|
33052 | var searchBounds$1 = arguments[0];
|
33053 | var node$1 = arguments[1];
|
33054 | var matches = arguments[2];
|
33055 | AbstractSTRtree$$1.prototype.query.call(this, searchBounds$1, node$1, matches);
|
33056 | }
|
33057 | }
|
33058 | };
|
33059 | STRtree.prototype.getComparator = function getComparator () {
|
33060 | return STRtree.yComparator
|
33061 | };
|
33062 | STRtree.prototype.createParentBoundablesFromVerticalSlice = function createParentBoundablesFromVerticalSlice (childBoundables, newLevel) {
|
33063 | return AbstractSTRtree$$1.prototype.createParentBoundables.call(this, childBoundables, newLevel)
|
33064 | };
|
33065 | STRtree.prototype.remove = function remove () {
|
33066 | if (arguments.length === 2) {
|
33067 | var itemEnv = arguments[0];
|
33068 | var item = arguments[1];
|
33069 | return AbstractSTRtree$$1.prototype.remove.call(this, itemEnv, item)
|
33070 | } else { return AbstractSTRtree$$1.prototype.remove.apply(this, arguments) }
|
33071 | };
|
33072 | STRtree.prototype.depth = function depth () {
|
33073 | if (arguments.length === 0) {
|
33074 | return AbstractSTRtree$$1.prototype.depth.call(this)
|
33075 | } else { return AbstractSTRtree$$1.prototype.depth.apply(this, arguments) }
|
33076 | };
|
33077 | STRtree.prototype.createParentBoundables = function createParentBoundables (childBoundables, newLevel) {
|
33078 | Assert.isTrue(!childBoundables.isEmpty());
|
33079 | var minLeafCount = Math.trunc(Math.ceil(childBoundables.size() / this.getNodeCapacity()));
|
33080 | var sortedChildBoundables = new ArrayList(childBoundables);
|
33081 | Collections.sort(sortedChildBoundables, STRtree.xComparator);
|
33082 | var verticalSlices = this.verticalSlices(sortedChildBoundables, Math.trunc(Math.ceil(Math.sqrt(minLeafCount))));
|
33083 | return this.createParentBoundablesFromVerticalSlices(verticalSlices, newLevel)
|
33084 | };
|
33085 | STRtree.prototype.nearestNeighbour = function nearestNeighbour () {
|
33086 | if (arguments.length === 1) {
|
33087 | if (hasInterface(arguments[0], ItemDistance)) {
|
33088 | var itemDist = arguments[0];
|
33089 | var bp = new BoundablePair(this.getRoot(), this.getRoot(), itemDist);
|
33090 | return this.nearestNeighbour(bp)
|
33091 | } else if (arguments[0] instanceof BoundablePair) {
|
33092 | var initBndPair = arguments[0];
|
33093 | return this.nearestNeighbour(initBndPair, Double.POSITIVE_INFINITY)
|
33094 | }
|
33095 | } else if (arguments.length === 2) {
|
33096 | if (arguments[0] instanceof STRtree && hasInterface(arguments[1], ItemDistance)) {
|
33097 | var tree = arguments[0];
|
33098 | var itemDist$1 = arguments[1];
|
33099 | var bp$1 = new BoundablePair(this.getRoot(), tree.getRoot(), itemDist$1);
|
33100 | return this.nearestNeighbour(bp$1)
|
33101 | } else if (arguments[0] instanceof BoundablePair && typeof arguments[1] === 'number') {
|
33102 | var initBndPair$1 = arguments[0];
|
33103 | var maxDistance = arguments[1];
|
33104 | var distanceLowerBound = maxDistance;
|
33105 | var minPair = null;
|
33106 | var priQ = new PriorityQueue();
|
33107 | priQ.add(initBndPair$1);
|
33108 | while (!priQ.isEmpty() && distanceLowerBound > 0.0) {
|
33109 | var bndPair = priQ.poll();
|
33110 | var currentDistance = bndPair.getDistance();
|
33111 | if (currentDistance >= distanceLowerBound) { break }
|
33112 | if (bndPair.isLeaves()) {
|
33113 | distanceLowerBound = currentDistance;
|
33114 | minPair = bndPair;
|
33115 | } else {
|
33116 | bndPair.expandToQueue(priQ, distanceLowerBound);
|
33117 | }
|
33118 | }
|
33119 | return [minPair.getBoundable(0).getItem(), minPair.getBoundable(1).getItem()]
|
33120 | }
|
33121 | } else if (arguments.length === 3) {
|
33122 | var env = arguments[0];
|
33123 | var item = arguments[1];
|
33124 | var itemDist$2 = arguments[2];
|
33125 | var bnd = new ItemBoundable(env, item);
|
33126 | var bp$2 = new BoundablePair(this.getRoot(), bnd, itemDist$2);
|
33127 | return this.nearestNeighbour(bp$2)[0]
|
33128 | }
|
33129 | };
|
33130 | STRtree.prototype.interfaces_ = function interfaces_ () {
|
33131 | return [SpatialIndex, Serializable]
|
33132 | };
|
33133 | STRtree.prototype.getClass = function getClass () {
|
33134 | return STRtree
|
33135 | };
|
33136 | STRtree.centreX = function centreX (e) {
|
33137 | return STRtree.avg(e.getMinX(), e.getMaxX())
|
33138 | };
|
33139 | STRtree.avg = function avg (a, b) {
|
33140 | return (a + b) / 2
|
33141 | };
|
33142 | STRtree.centreY = function centreY (e) {
|
33143 | return STRtree.avg(e.getMinY(), e.getMaxY())
|
33144 | };
|
33145 | staticAccessors.STRtreeNode.get = function () { return STRtreeNode };
|
33146 | staticAccessors.serialVersionUID.get = function () { return 259274702368956900 };
|
33147 | staticAccessors.xComparator.get = function () {
|
33148 | return {
|
33149 | interfaces_: function () {
|
33150 | return [Comparator]
|
33151 | },
|
33152 | compare: function (o1, o2) {
|
33153 | return AbstractSTRtree$$1.compareDoubles(STRtree.centreX(o1.getBounds()), STRtree.centreX(o2.getBounds()))
|
33154 | }
|
33155 | }
|
33156 | };
|
33157 | staticAccessors.yComparator.get = function () {
|
33158 | return {
|
33159 | interfaces_: function () {
|
33160 | return [Comparator]
|
33161 | },
|
33162 | compare: function (o1, o2) {
|
33163 | return AbstractSTRtree$$1.compareDoubles(STRtree.centreY(o1.getBounds()), STRtree.centreY(o2.getBounds()))
|
33164 | }
|
33165 | }
|
33166 | };
|
33167 | staticAccessors.intersectsOp.get = function () {
|
33168 | return {
|
33169 | interfaces_: function () {
|
33170 | return [AbstractSTRtree$$1.IntersectsOp]
|
33171 | },
|
33172 | intersects: function (aBounds, bBounds) {
|
33173 | return aBounds.intersects(bBounds)
|
33174 | }
|
33175 | }
|
33176 | };
|
33177 | staticAccessors.DEFAULT_NODE_CAPACITY.get = function () { return 10 };
|
33178 |
|
33179 | Object.defineProperties( STRtree, staticAccessors );
|
33180 |
|
33181 | return STRtree;
|
33182 | }(AbstractSTRtree));
|
33183 |
|
33184 | var STRtreeNode = (function (AbstractNode$$1) {
|
33185 | function STRtreeNode () {
|
33186 | var level = arguments[0];
|
33187 | AbstractNode$$1.call(this, level);
|
33188 | }
|
33189 |
|
33190 | if ( AbstractNode$$1 ) STRtreeNode.__proto__ = AbstractNode$$1;
|
33191 | STRtreeNode.prototype = Object.create( AbstractNode$$1 && AbstractNode$$1.prototype );
|
33192 | STRtreeNode.prototype.constructor = STRtreeNode;
|
33193 | STRtreeNode.prototype.computeBounds = function computeBounds () {
|
33194 | var bounds = null;
|
33195 | for (var i = this.getChildBoundables().iterator(); i.hasNext();) {
|
33196 | var childBoundable = i.next();
|
33197 | if (bounds === null) {
|
33198 | bounds = new Envelope(childBoundable.getBounds());
|
33199 | } else {
|
33200 | bounds.expandToInclude(childBoundable.getBounds());
|
33201 | }
|
33202 | }
|
33203 | return bounds
|
33204 | };
|
33205 | STRtreeNode.prototype.interfaces_ = function interfaces_ () {
|
33206 | return []
|
33207 | };
|
33208 | STRtreeNode.prototype.getClass = function getClass () {
|
33209 | return STRtreeNode
|
33210 | };
|
33211 |
|
33212 | return STRtreeNode;
|
33213 | }(AbstractNode));
|
33214 |
|
33215 | var SegmentPointComparator = function SegmentPointComparator () {};
|
33216 |
|
33217 | SegmentPointComparator.prototype.interfaces_ = function interfaces_ () {
|
33218 | return []
|
33219 | };
|
33220 | SegmentPointComparator.prototype.getClass = function getClass () {
|
33221 | return SegmentPointComparator
|
33222 | };
|
33223 | SegmentPointComparator.relativeSign = function relativeSign (x0, x1) {
|
33224 | if (x0 < x1) { return -1 }
|
33225 | if (x0 > x1) { return 1 }
|
33226 | return 0
|
33227 | };
|
33228 | SegmentPointComparator.compare = function compare (octant, p0, p1) {
|
33229 | if (p0.equals2D(p1)) { return 0 }
|
33230 | var xSign = SegmentPointComparator.relativeSign(p0.x, p1.x);
|
33231 | var ySign = SegmentPointComparator.relativeSign(p0.y, p1.y);
|
33232 | switch (octant) {
|
33233 | case 0:
|
33234 | return SegmentPointComparator.compareValue(xSign, ySign)
|
33235 | case 1:
|
33236 | return SegmentPointComparator.compareValue(ySign, xSign)
|
33237 | case 2:
|
33238 | return SegmentPointComparator.compareValue(ySign, -xSign)
|
33239 | case 3:
|
33240 | return SegmentPointComparator.compareValue(-xSign, ySign)
|
33241 | case 4:
|
33242 | return SegmentPointComparator.compareValue(-xSign, -ySign)
|
33243 | case 5:
|
33244 | return SegmentPointComparator.compareValue(-ySign, -xSign)
|
33245 | case 6:
|
33246 | return SegmentPointComparator.compareValue(-ySign, xSign)
|
33247 | case 7:
|
33248 | return SegmentPointComparator.compareValue(xSign, -ySign)
|
33249 | default:
|
33250 | }
|
33251 | Assert.shouldNeverReachHere('invalid octant value');
|
33252 | return 0
|
33253 | };
|
33254 | SegmentPointComparator.compareValue = function compareValue (compareSign0, compareSign1) {
|
33255 | if (compareSign0 < 0) { return -1 }
|
33256 | if (compareSign0 > 0) { return 1 }
|
33257 | if (compareSign1 < 0) { return -1 }
|
33258 | if (compareSign1 > 0) { return 1 }
|
33259 | return 0
|
33260 | };
|
33261 |
|
33262 | var SegmentNode = function SegmentNode () {
|
33263 | this._segString = null;
|
33264 | this.coord = null;
|
33265 | this.segmentIndex = null;
|
33266 | this._segmentOctant = null;
|
33267 | this._isInterior = null;
|
33268 | var segString = arguments[0];
|
33269 | var coord = arguments[1];
|
33270 | var segmentIndex = arguments[2];
|
33271 | var segmentOctant = arguments[3];
|
33272 | this._segString = segString;
|
33273 | this.coord = new Coordinate(coord);
|
33274 | this.segmentIndex = segmentIndex;
|
33275 | this._segmentOctant = segmentOctant;
|
33276 | this._isInterior = !coord.equals2D(segString.getCoordinate(segmentIndex));
|
33277 | };
|
33278 | SegmentNode.prototype.getCoordinate = function getCoordinate () {
|
33279 | return this.coord
|
33280 | };
|
33281 | SegmentNode.prototype.print = function print (out) {
|
33282 | out.print(this.coord);
|
33283 | out.print(' seg # = ' + this.segmentIndex);
|
33284 | };
|
33285 | SegmentNode.prototype.compareTo = function compareTo (obj) {
|
33286 | var other = obj;
|
33287 | if (this.segmentIndex < other.segmentIndex) { return -1 }
|
33288 | if (this.segmentIndex > other.segmentIndex) { return 1 }
|
33289 | if (this.coord.equals2D(other.coord)) { return 0 }
|
33290 | return SegmentPointComparator.compare(this._segmentOctant, this.coord, other.coord)
|
33291 | };
|
33292 | SegmentNode.prototype.isEndPoint = function isEndPoint (maxSegmentIndex) {
|
33293 | if (this.segmentIndex === 0 && !this._isInterior) { return true }
|
33294 | if (this.segmentIndex === maxSegmentIndex) { return true }
|
33295 | return false
|
33296 | };
|
33297 | SegmentNode.prototype.isInterior = function isInterior () {
|
33298 | return this._isInterior
|
33299 | };
|
33300 | SegmentNode.prototype.interfaces_ = function interfaces_ () {
|
33301 | return [Comparable]
|
33302 | };
|
33303 | SegmentNode.prototype.getClass = function getClass () {
|
33304 | return SegmentNode
|
33305 | };
|
33306 |
|
33307 |
|
33308 | var SegmentNodeList = function SegmentNodeList () {
|
33309 | this._nodeMap = new TreeMap();
|
33310 | this._edge = null;
|
33311 | var edge = arguments[0];
|
33312 | this._edge = edge;
|
33313 | };
|
33314 | SegmentNodeList.prototype.getSplitCoordinates = function getSplitCoordinates () {
|
33315 | var this$1 = this;
|
33316 |
|
33317 | var coordList = new CoordinateList();
|
33318 | this.addEndpoints();
|
33319 | var it = this.iterator();
|
33320 | var eiPrev = it.next();
|
33321 | while (it.hasNext()) {
|
33322 | var ei = it.next();
|
33323 | this$1.addEdgeCoordinates(eiPrev, ei, coordList);
|
33324 | eiPrev = ei;
|
33325 | }
|
33326 | return coordList.toCoordinateArray()
|
33327 | };
|
33328 | SegmentNodeList.prototype.addCollapsedNodes = function addCollapsedNodes () {
|
33329 | var this$1 = this;
|
33330 |
|
33331 | var collapsedVertexIndexes = new ArrayList();
|
33332 | this.findCollapsesFromInsertedNodes(collapsedVertexIndexes);
|
33333 | this.findCollapsesFromExistingVertices(collapsedVertexIndexes);
|
33334 | for (var it = collapsedVertexIndexes.iterator(); it.hasNext();) {
|
33335 | var vertexIndex = it.next().intValue();
|
33336 | this$1.add(this$1._edge.getCoordinate(vertexIndex), vertexIndex);
|
33337 | }
|
33338 | };
|
33339 | SegmentNodeList.prototype.print = function print (out) {
|
33340 | out.println('Intersections:');
|
33341 | for (var it = this.iterator(); it.hasNext();) {
|
33342 | var ei = it.next();
|
33343 | ei.print(out);
|
33344 | }
|
33345 | };
|
33346 | SegmentNodeList.prototype.findCollapsesFromExistingVertices = function findCollapsesFromExistingVertices (collapsedVertexIndexes) {
|
33347 | var this$1 = this;
|
33348 |
|
33349 | for (var i = 0; i < this._edge.size() - 2; i++) {
|
33350 | var p0 = this$1._edge.getCoordinate(i);
|
33351 |
|
33352 | var p2 = this$1._edge.getCoordinate(i + 2);
|
33353 | if (p0.equals2D(p2)) {
|
33354 | collapsedVertexIndexes.add(new Integer(i + 1));
|
33355 | }
|
33356 | }
|
33357 | };
|
33358 | SegmentNodeList.prototype.addEdgeCoordinates = function addEdgeCoordinates (ei0, ei1, coordList) {
|
33359 | var this$1 = this;
|
33360 |
|
33361 |
|
33362 | var lastSegStartPt = this._edge.getCoordinate(ei1.segmentIndex);
|
33363 | var useIntPt1 = ei1.isInterior() || !ei1.coord.equals2D(lastSegStartPt);
|
33364 |
|
33365 |
|
33366 |
|
33367 |
|
33368 | coordList.add(new Coordinate(ei0.coord), false);
|
33369 | for (var i = ei0.segmentIndex + 1; i <= ei1.segmentIndex; i++) {
|
33370 | coordList.add(this$1._edge.getCoordinate(i));
|
33371 | }
|
33372 | if (useIntPt1) {
|
33373 | coordList.add(new Coordinate(ei1.coord));
|
33374 | }
|
33375 | };
|
33376 | SegmentNodeList.prototype.iterator = function iterator () {
|
33377 | return this._nodeMap.values().iterator()
|
33378 | };
|
33379 | SegmentNodeList.prototype.addSplitEdges = function addSplitEdges (edgeList) {
|
33380 | var this$1 = this;
|
33381 |
|
33382 | this.addEndpoints();
|
33383 | this.addCollapsedNodes();
|
33384 | var it = this.iterator();
|
33385 | var eiPrev = it.next();
|
33386 | while (it.hasNext()) {
|
33387 | var ei = it.next();
|
33388 | var newEdge = this$1.createSplitEdge(eiPrev, ei);
|
33389 | edgeList.add(newEdge);
|
33390 | eiPrev = ei;
|
33391 | }
|
33392 | };
|
33393 | SegmentNodeList.prototype.findCollapseIndex = function findCollapseIndex (ei0, ei1, collapsedVertexIndex) {
|
33394 | if (!ei0.coord.equals2D(ei1.coord)) { return false }
|
33395 | var numVerticesBetween = ei1.segmentIndex - ei0.segmentIndex;
|
33396 | if (!ei1.isInterior()) {
|
33397 | numVerticesBetween--;
|
33398 | }
|
33399 | if (numVerticesBetween === 1) {
|
33400 | collapsedVertexIndex[0] = ei0.segmentIndex + 1;
|
33401 | return true
|
33402 | }
|
33403 | return false
|
33404 | };
|
33405 | SegmentNodeList.prototype.findCollapsesFromInsertedNodes = function findCollapsesFromInsertedNodes (collapsedVertexIndexes) {
|
33406 | var this$1 = this;
|
33407 |
|
33408 | var collapsedVertexIndex = new Array(1).fill(null);
|
33409 | var it = this.iterator();
|
33410 | var eiPrev = it.next();
|
33411 | while (it.hasNext()) {
|
33412 | var ei = it.next();
|
33413 | var isCollapsed = this$1.findCollapseIndex(eiPrev, ei, collapsedVertexIndex);
|
33414 | if (isCollapsed) { collapsedVertexIndexes.add(new Integer(collapsedVertexIndex[0])); }
|
33415 | eiPrev = ei;
|
33416 | }
|
33417 | };
|
33418 | SegmentNodeList.prototype.getEdge = function getEdge () {
|
33419 | return this._edge
|
33420 | };
|
33421 | SegmentNodeList.prototype.addEndpoints = function addEndpoints () {
|
33422 | var maxSegIndex = this._edge.size() - 1;
|
33423 | this.add(this._edge.getCoordinate(0), 0);
|
33424 | this.add(this._edge.getCoordinate(maxSegIndex), maxSegIndex);
|
33425 | };
|
33426 | SegmentNodeList.prototype.createSplitEdge = function createSplitEdge (ei0, ei1) {
|
33427 | var this$1 = this;
|
33428 |
|
33429 | var npts = ei1.segmentIndex - ei0.segmentIndex + 2;
|
33430 | var lastSegStartPt = this._edge.getCoordinate(ei1.segmentIndex);
|
33431 | var useIntPt1 = ei1.isInterior() || !ei1.coord.equals2D(lastSegStartPt);
|
33432 | if (!useIntPt1) {
|
33433 | npts--;
|
33434 | }
|
33435 | var pts = new Array(npts).fill(null);
|
33436 | var ipt = 0;
|
33437 | pts[ipt++] = new Coordinate(ei0.coord);
|
33438 | for (var i = ei0.segmentIndex + 1; i <= ei1.segmentIndex; i++) {
|
33439 | pts[ipt++] = this$1._edge.getCoordinate(i);
|
33440 | }
|
33441 | if (useIntPt1) { pts[ipt] = new Coordinate(ei1.coord); }
|
33442 | return new NodedSegmentString(pts, this._edge.getData())
|
33443 | };
|
33444 | SegmentNodeList.prototype.add = function add (intPt, segmentIndex) {
|
33445 | var eiNew = new SegmentNode(this._edge, intPt, segmentIndex, this._edge.getSegmentOctant(segmentIndex));
|
33446 | var ei = this._nodeMap.get(eiNew);
|
33447 | if (ei !== null) {
|
33448 | Assert.isTrue(ei.coord.equals2D(intPt), 'Found equal nodes with different coordinates');
|
33449 | return ei
|
33450 | }
|
33451 | this._nodeMap.put(eiNew, eiNew);
|
33452 | return eiNew
|
33453 | };
|
33454 | SegmentNodeList.prototype.checkSplitEdgesCorrectness = function checkSplitEdgesCorrectness (splitEdges) {
|
33455 | var edgePts = this._edge.getCoordinates();
|
33456 | var split0 = splitEdges.get(0);
|
33457 | var pt0 = split0.getCoordinate(0);
|
33458 | if (!pt0.equals2D(edgePts[0])) { throw new RuntimeException('bad split edge start point at ' + pt0) }
|
33459 | var splitn = splitEdges.get(splitEdges.size() - 1);
|
33460 | var splitnPts = splitn.getCoordinates();
|
33461 | var ptn = splitnPts[splitnPts.length - 1];
|
33462 | if (!ptn.equals2D(edgePts[edgePts.length - 1])) { throw new RuntimeException('bad split edge end point at ' + ptn) }
|
33463 | };
|
33464 | SegmentNodeList.prototype.interfaces_ = function interfaces_ () {
|
33465 | return []
|
33466 | };
|
33467 | SegmentNodeList.prototype.getClass = function getClass () {
|
33468 | return SegmentNodeList
|
33469 | };
|
33470 |
|
33471 |
|
33472 |
|
33473 |
|
33474 |
|
33475 |
|
33476 |
|
33477 |
|
33478 |
|
33479 |
|
33480 |
|
33481 |
|
33482 |
|
33483 |
|
33484 |
|
33485 |
|
33486 |
|
33487 |
|
33488 |
|
33489 |
|
33490 |
|
33491 |
|
33492 |
|
33493 |
|
33494 |
|
33495 |
|
33496 |
|
33497 |
|
33498 |
|
33499 |
|
33500 |
|
33501 |
|
33502 |
|
33503 |
|
33504 |
|
33505 |
|
33506 |
|
33507 |
|
33508 |
|
33509 |
|
33510 |
|
33511 |
|
33512 |
|
33513 |
|
33514 |
|
33515 |
|
33516 |
|
33517 |
|
33518 |
|
33519 |
|
33520 |
|
33521 |
|
33522 | var Octant = function Octant () {};
|
33523 |
|
33524 | Octant.prototype.interfaces_ = function interfaces_ () {
|
33525 | return []
|
33526 | };
|
33527 | Octant.prototype.getClass = function getClass () {
|
33528 | return Octant
|
33529 | };
|
33530 | Octant.octant = function octant () {
|
33531 | if (typeof arguments[0] === 'number' && typeof arguments[1] === 'number') {
|
33532 | var dx = arguments[0];
|
33533 | var dy = arguments[1];
|
33534 | if (dx === 0.0 && dy === 0.0) { throw new IllegalArgumentException('Cannot compute the octant for point ( ' + dx + ', ' + dy + ' )') }
|
33535 | var adx = Math.abs(dx);
|
33536 | var ady = Math.abs(dy);
|
33537 | if (dx >= 0) {
|
33538 | if (dy >= 0) {
|
33539 | if (adx >= ady) { return 0; } else { return 1 }
|
33540 | } else {
|
33541 | if (adx >= ady) { return 7; } else { return 6 }
|
33542 | }
|
33543 | } else {
|
33544 | if (dy >= 0) {
|
33545 | if (adx >= ady) { return 3; } else { return 2 }
|
33546 | } else {
|
33547 | if (adx >= ady) { return 4; } else { return 5 }
|
33548 | }
|
33549 | }
|
33550 | } else if (arguments[0] instanceof Coordinate && arguments[1] instanceof Coordinate) {
|
33551 | var p0 = arguments[0];
|
33552 | var p1 = arguments[1];
|
33553 | var dx$1 = p1.x - p0.x;
|
33554 | var dy$1 = p1.y - p0.y;
|
33555 | if (dx$1 === 0.0 && dy$1 === 0.0) { throw new IllegalArgumentException('Cannot compute the octant for two identical points ' + p0) }
|
33556 | return Octant.octant(dx$1, dy$1)
|
33557 | }
|
33558 | };
|
33559 |
|
33560 | var SegmentString = function SegmentString () {};
|
33561 |
|
33562 | SegmentString.prototype.getCoordinates = function getCoordinates () {};
|
33563 | SegmentString.prototype.size = function size () {};
|
33564 | SegmentString.prototype.getCoordinate = function getCoordinate (i) {};
|
33565 | SegmentString.prototype.isClosed = function isClosed () {};
|
33566 | SegmentString.prototype.setData = function setData (data) {};
|
33567 | SegmentString.prototype.getData = function getData () {};
|
33568 | SegmentString.prototype.interfaces_ = function interfaces_ () {
|
33569 | return []
|
33570 | };
|
33571 | SegmentString.prototype.getClass = function getClass () {
|
33572 | return SegmentString
|
33573 | };
|
33574 |
|
33575 | var NodableSegmentString = function NodableSegmentString () {};
|
33576 |
|
33577 | NodableSegmentString.prototype.addIntersection = function addIntersection (intPt, segmentIndex) {};
|
33578 | NodableSegmentString.prototype.interfaces_ = function interfaces_ () {
|
33579 | return [SegmentString]
|
33580 | };
|
33581 | NodableSegmentString.prototype.getClass = function getClass () {
|
33582 | return NodableSegmentString
|
33583 | };
|
33584 |
|
33585 | var NodedSegmentString = function NodedSegmentString () {
|
33586 | this._nodeList = new SegmentNodeList(this);
|
33587 | this._pts = null;
|
33588 | this._data = null;
|
33589 | var pts = arguments[0];
|
33590 | var data = arguments[1];
|
33591 | this._pts = pts;
|
33592 | this._data = data;
|
33593 | };
|
33594 | NodedSegmentString.prototype.getCoordinates = function getCoordinates () {
|
33595 | return this._pts
|
33596 | };
|
33597 | NodedSegmentString.prototype.size = function size () {
|
33598 | return this._pts.length
|
33599 | };
|
33600 | NodedSegmentString.prototype.getCoordinate = function getCoordinate (i) {
|
33601 | return this._pts[i]
|
33602 | };
|
33603 | NodedSegmentString.prototype.isClosed = function isClosed () {
|
33604 | return this._pts[0].equals(this._pts[this._pts.length - 1])
|
33605 | };
|
33606 | NodedSegmentString.prototype.getSegmentOctant = function getSegmentOctant (index) {
|
33607 | if (index === this._pts.length - 1) { return -1 }
|
33608 | return this.safeOctant(this.getCoordinate(index), this.getCoordinate(index + 1))
|
33609 | };
|
33610 | NodedSegmentString.prototype.setData = function setData (data) {
|
33611 | this._data = data;
|
33612 | };
|
33613 | NodedSegmentString.prototype.safeOctant = function safeOctant (p0, p1) {
|
33614 | if (p0.equals2D(p1)) { return 0 }
|
33615 | return Octant.octant(p0, p1)
|
33616 | };
|
33617 | NodedSegmentString.prototype.getData = function getData () {
|
33618 | return this._data
|
33619 | };
|
33620 | NodedSegmentString.prototype.addIntersection = function addIntersection () {
|
33621 | if (arguments.length === 2) {
|
33622 | var intPt$1 = arguments[0];
|
33623 | var segmentIndex = arguments[1];
|
33624 | this.addIntersectionNode(intPt$1, segmentIndex);
|
33625 | } else if (arguments.length === 4) {
|
33626 | var li = arguments[0];
|
33627 | var segmentIndex$1 = arguments[1];
|
33628 |
|
33629 | var intIndex = arguments[3];
|
33630 | var intPt = new Coordinate(li.getIntersection(intIndex));
|
33631 | this.addIntersection(intPt, segmentIndex$1);
|
33632 | }
|
33633 | };
|
33634 | NodedSegmentString.prototype.toString = function toString () {
|
33635 | return WKTWriter.toLineString(new CoordinateArraySequence(this._pts))
|
33636 | };
|
33637 | NodedSegmentString.prototype.getNodeList = function getNodeList () {
|
33638 | return this._nodeList
|
33639 | };
|
33640 | NodedSegmentString.prototype.addIntersectionNode = function addIntersectionNode (intPt, segmentIndex) {
|
33641 | var normalizedSegmentIndex = segmentIndex;
|
33642 | var nextSegIndex = normalizedSegmentIndex + 1;
|
33643 | if (nextSegIndex < this._pts.length) {
|
33644 | var nextPt = this._pts[nextSegIndex];
|
33645 | if (intPt.equals2D(nextPt)) {
|
33646 | normalizedSegmentIndex = nextSegIndex;
|
33647 | }
|
33648 | }
|
33649 | var ei = this._nodeList.add(intPt, normalizedSegmentIndex);
|
33650 | return ei
|
33651 | };
|
33652 | NodedSegmentString.prototype.addIntersections = function addIntersections (li, segmentIndex, geomIndex) {
|
33653 | var this$1 = this;
|
33654 |
|
33655 | for (var i = 0; i < li.getIntersectionNum(); i++) {
|
33656 | this$1.addIntersection(li, segmentIndex, geomIndex, i);
|
33657 | }
|
33658 | };
|
33659 | NodedSegmentString.prototype.interfaces_ = function interfaces_ () {
|
33660 | return [NodableSegmentString]
|
33661 | };
|
33662 | NodedSegmentString.prototype.getClass = function getClass () {
|
33663 | return NodedSegmentString
|
33664 | };
|
33665 | NodedSegmentString.getNodedSubstrings = function getNodedSubstrings () {
|
33666 | if (arguments.length === 1) {
|
33667 | var segStrings = arguments[0];
|
33668 | var resultEdgelist = new ArrayList();
|
33669 | NodedSegmentString.getNodedSubstrings(segStrings, resultEdgelist);
|
33670 | return resultEdgelist
|
33671 | } else if (arguments.length === 2) {
|
33672 | var segStrings$1 = arguments[0];
|
33673 | var resultEdgelist$1 = arguments[1];
|
33674 | for (var i = segStrings$1.iterator(); i.hasNext();) {
|
33675 | var ss = i.next();
|
33676 | ss.getNodeList().addSplitEdges(resultEdgelist$1);
|
33677 | }
|
33678 | }
|
33679 | };
|
33680 |
|
33681 | var LineSegment = function LineSegment () {
|
33682 | this.p0 = null;
|
33683 | this.p1 = null;
|
33684 | if (arguments.length === 0) {
|
33685 | this.p0 = new Coordinate();
|
33686 | this.p1 = new Coordinate();
|
33687 | } else if (arguments.length === 1) {
|
33688 | var ls = arguments[0];
|
33689 | this.p0 = new Coordinate(ls.p0);
|
33690 | this.p1 = new Coordinate(ls.p1);
|
33691 | } else if (arguments.length === 2) {
|
33692 | this.p0 = arguments[0];
|
33693 | this.p1 = arguments[1];
|
33694 | } else if (arguments.length === 4) {
|
33695 | var x0 = arguments[0];
|
33696 | var y0 = arguments[1];
|
33697 | var x1 = arguments[2];
|
33698 | var y1 = arguments[3];
|
33699 | this.p0 = new Coordinate(x0, y0);
|
33700 | this.p1 = new Coordinate(x1, y1);
|
33701 | }
|
33702 | };
|
33703 |
|
33704 | var staticAccessors$24 = { serialVersionUID: { configurable: true } };
|
33705 | LineSegment.prototype.minX = function minX () {
|
33706 | return Math.min(this.p0.x, this.p1.x)
|
33707 | };
|
33708 | LineSegment.prototype.orientationIndex = function orientationIndex () {
|
33709 | if (arguments[0] instanceof LineSegment) {
|
33710 | var seg = arguments[0];
|
33711 | var orient0 = CGAlgorithms.orientationIndex(this.p0, this.p1, seg.p0);
|
33712 | var orient1 = CGAlgorithms.orientationIndex(this.p0, this.p1, seg.p1);
|
33713 | if (orient0 >= 0 && orient1 >= 0) { return Math.max(orient0, orient1) }
|
33714 | if (orient0 <= 0 && orient1 <= 0) { return Math.max(orient0, orient1) }
|
33715 | return 0
|
33716 | } else if (arguments[0] instanceof Coordinate) {
|
33717 | var p = arguments[0];
|
33718 | return CGAlgorithms.orientationIndex(this.p0, this.p1, p)
|
33719 | }
|
33720 | };
|
33721 | LineSegment.prototype.toGeometry = function toGeometry (geomFactory) {
|
33722 | return geomFactory.createLineString([this.p0, this.p1])
|
33723 | };
|
33724 | LineSegment.prototype.isVertical = function isVertical () {
|
33725 | return this.p0.x === this.p1.x
|
33726 | };
|
33727 | LineSegment.prototype.equals = function equals (o) {
|
33728 | if (!(o instanceof LineSegment)) {
|
33729 | return false
|
33730 | }
|
33731 | var other = o;
|
33732 | return this.p0.equals(other.p0) && this.p1.equals(other.p1)
|
33733 | };
|
33734 | LineSegment.prototype.intersection = function intersection (line) {
|
33735 | var li = new RobustLineIntersector();
|
33736 | li.computeIntersection(this.p0, this.p1, line.p0, line.p1);
|
33737 | if (li.hasIntersection()) { return li.getIntersection(0) }
|
33738 | return null
|
33739 | };
|
33740 | LineSegment.prototype.project = function project () {
|
33741 | if (arguments[0] instanceof Coordinate) {
|
33742 | var p = arguments[0];
|
33743 | if (p.equals(this.p0) || p.equals(this.p1)) { return new Coordinate(p) }
|
33744 | var r = this.projectionFactor(p);
|
33745 | var coord = new Coordinate();
|
33746 | coord.x = this.p0.x + r * (this.p1.x - this.p0.x);
|
33747 | coord.y = this.p0.y + r * (this.p1.y - this.p0.y);
|
33748 | return coord
|
33749 | } else if (arguments[0] instanceof LineSegment) {
|
33750 | var seg = arguments[0];
|
33751 | var pf0 = this.projectionFactor(seg.p0);
|
33752 | var pf1 = this.projectionFactor(seg.p1);
|
33753 | if (pf0 >= 1.0 && pf1 >= 1.0) { return null }
|
33754 | if (pf0 <= 0.0 && pf1 <= 0.0) { return null }
|
33755 | var newp0 = this.project(seg.p0);
|
33756 | if (pf0 < 0.0) { newp0 = this.p0; }
|
33757 | if (pf0 > 1.0) { newp0 = this.p1; }
|
33758 | var newp1 = this.project(seg.p1);
|
33759 | if (pf1 < 0.0) { newp1 = this.p0; }
|
33760 | if (pf1 > 1.0) { newp1 = this.p1; }
|
33761 | return new LineSegment(newp0, newp1)
|
33762 | }
|
33763 | };
|
33764 | LineSegment.prototype.normalize = function normalize () {
|
33765 | if (this.p1.compareTo(this.p0) < 0) { this.reverse(); }
|
33766 | };
|
33767 | LineSegment.prototype.angle = function angle () {
|
33768 | return Math.atan2(this.p1.y - this.p0.y, this.p1.x - this.p0.x)
|
33769 | };
|
33770 | LineSegment.prototype.getCoordinate = function getCoordinate (i) {
|
33771 | if (i === 0) { return this.p0 }
|
33772 | return this.p1
|
33773 | };
|
33774 | LineSegment.prototype.distancePerpendicular = function distancePerpendicular (p) {
|
33775 | return CGAlgorithms.distancePointLinePerpendicular(p, this.p0, this.p1)
|
33776 | };
|
33777 | LineSegment.prototype.minY = function minY () {
|
33778 | return Math.min(this.p0.y, this.p1.y)
|
33779 | };
|
33780 | LineSegment.prototype.midPoint = function midPoint () {
|
33781 | return LineSegment.midPoint(this.p0, this.p1)
|
33782 | };
|
33783 | LineSegment.prototype.projectionFactor = function projectionFactor (p) {
|
33784 | if (p.equals(this.p0)) { return 0.0 }
|
33785 | if (p.equals(this.p1)) { return 1.0 }
|
33786 | var dx = this.p1.x - this.p0.x;
|
33787 | var dy = this.p1.y - this.p0.y;
|
33788 | var len = dx * dx + dy * dy;
|
33789 | if (len <= 0.0) { return Double.NaN }
|
33790 | var r = ((p.x - this.p0.x) * dx + (p.y - this.p0.y) * dy) / len;
|
33791 | return r
|
33792 | };
|
33793 | LineSegment.prototype.closestPoints = function closestPoints (line) {
|
33794 | var intPt = this.intersection(line);
|
33795 | if (intPt !== null) {
|
33796 | return [intPt, intPt]
|
33797 | }
|
33798 | var closestPt = new Array(2).fill(null);
|
33799 | var minDistance = Double.MAX_VALUE;
|
33800 | var dist = null;
|
33801 | var close00 = this.closestPoint(line.p0);
|
33802 | minDistance = close00.distance(line.p0);
|
33803 | closestPt[0] = close00;
|
33804 | closestPt[1] = line.p0;
|
33805 | var close01 = this.closestPoint(line.p1);
|
33806 | dist = close01.distance(line.p1);
|
33807 | if (dist < minDistance) {
|
33808 | minDistance = dist;
|
33809 | closestPt[0] = close01;
|
33810 | closestPt[1] = line.p1;
|
33811 | }
|
33812 | var close10 = line.closestPoint(this.p0);
|
33813 | dist = close10.distance(this.p0);
|
33814 | if (dist < minDistance) {
|
33815 | minDistance = dist;
|
33816 | closestPt[0] = this.p0;
|
33817 | closestPt[1] = close10;
|
33818 | }
|
33819 | var close11 = line.closestPoint(this.p1);
|
33820 | dist = close11.distance(this.p1);
|
33821 | if (dist < minDistance) {
|
33822 | minDistance = dist;
|
33823 | closestPt[0] = this.p1;
|
33824 | closestPt[1] = close11;
|
33825 | }
|
33826 | return closestPt
|
33827 | };
|
33828 | LineSegment.prototype.closestPoint = function closestPoint (p) {
|
33829 | var factor = this.projectionFactor(p);
|
33830 | if (factor > 0 && factor < 1) {
|
33831 | return this.project(p)
|
33832 | }
|
33833 | var dist0 = this.p0.distance(p);
|
33834 | var dist1 = this.p1.distance(p);
|
33835 | if (dist0 < dist1) { return this.p0 }
|
33836 | return this.p1
|
33837 | };
|
33838 | LineSegment.prototype.maxX = function maxX () {
|
33839 | return Math.max(this.p0.x, this.p1.x)
|
33840 | };
|
33841 | LineSegment.prototype.getLength = function getLength () {
|
33842 | return this.p0.distance(this.p1)
|
33843 | };
|
33844 | LineSegment.prototype.compareTo = function compareTo (o) {
|
33845 | var other = o;
|
33846 | var comp0 = this.p0.compareTo(other.p0);
|
33847 | if (comp0 !== 0) { return comp0 }
|
33848 | return this.p1.compareTo(other.p1)
|
33849 | };
|
33850 | LineSegment.prototype.reverse = function reverse () {
|
33851 | var temp = this.p0;
|
33852 | this.p0 = this.p1;
|
33853 | this.p1 = temp;
|
33854 | };
|
33855 | LineSegment.prototype.equalsTopo = function equalsTopo (other) {
|
33856 | return this.p0.equals(other.p0) &&
|
33857 | (this.p1.equals(other.p1) || this.p0.equals(other.p1)) &&
|
33858 | this.p1.equals(other.p0)
|
33859 | };
|
33860 | LineSegment.prototype.lineIntersection = function lineIntersection (line) {
|
33861 | try {
|
33862 | var intPt = HCoordinate.intersection(this.p0, this.p1, line.p0, line.p1);
|
33863 | return intPt
|
33864 | } catch (ex) {
|
33865 | if (ex instanceof NotRepresentableException) {} else { throw ex }
|
33866 | } finally {}
|
33867 | return null
|
33868 | };
|
33869 | LineSegment.prototype.maxY = function maxY () {
|
33870 | return Math.max(this.p0.y, this.p1.y)
|
33871 | };
|
33872 | LineSegment.prototype.pointAlongOffset = function pointAlongOffset (segmentLengthFraction, offsetDistance) {
|
33873 | var segx = this.p0.x + segmentLengthFraction * (this.p1.x - this.p0.x);
|
33874 | var segy = this.p0.y + segmentLengthFraction * (this.p1.y - this.p0.y);
|
33875 | var dx = this.p1.x - this.p0.x;
|
33876 | var dy = this.p1.y - this.p0.y;
|
33877 | var len = Math.sqrt(dx * dx + dy * dy);
|
33878 | var ux = 0.0;
|
33879 | var uy = 0.0;
|
33880 | if (offsetDistance !== 0.0) {
|
33881 | if (len <= 0.0) { throw new Error('Cannot compute offset from zero-length line segment') }
|
33882 | ux = offsetDistance * dx / len;
|
33883 | uy = offsetDistance * dy / len;
|
33884 | }
|
33885 | var offsetx = segx - uy;
|
33886 | var offsety = segy + ux;
|
33887 | var coord = new Coordinate(offsetx, offsety);
|
33888 | return coord
|
33889 | };
|
33890 | LineSegment.prototype.setCoordinates = function setCoordinates () {
|
33891 | if (arguments.length === 1) {
|
33892 | var ls = arguments[0];
|
33893 | this.setCoordinates(ls.p0, ls.p1);
|
33894 | } else if (arguments.length === 2) {
|
33895 | var p0 = arguments[0];
|
33896 | var p1 = arguments[1];
|
33897 | this.p0.x = p0.x;
|
33898 | this.p0.y = p0.y;
|
33899 | this.p1.x = p1.x;
|
33900 | this.p1.y = p1.y;
|
33901 | }
|
33902 | };
|
33903 | LineSegment.prototype.segmentFraction = function segmentFraction (inputPt) {
|
33904 | var segFrac = this.projectionFactor(inputPt);
|
33905 | if (segFrac < 0.0) { segFrac = 0.0; } else if (segFrac > 1.0 || Double.isNaN(segFrac)) { segFrac = 1.0; }
|
33906 | return segFrac
|
33907 | };
|
33908 | LineSegment.prototype.toString = function toString () {
|
33909 | return 'LINESTRING( ' + this.p0.x + ' ' + this.p0.y + ', ' + this.p1.x + ' ' + this.p1.y + ')'
|
33910 | };
|
33911 | LineSegment.prototype.isHorizontal = function isHorizontal () {
|
33912 | return this.p0.y === this.p1.y
|
33913 | };
|
33914 | LineSegment.prototype.distance = function distance () {
|
33915 | if (arguments[0] instanceof LineSegment) {
|
33916 | var ls = arguments[0];
|
33917 | return CGAlgorithms.distanceLineLine(this.p0, this.p1, ls.p0, ls.p1)
|
33918 | } else if (arguments[0] instanceof Coordinate) {
|
33919 | var p = arguments[0];
|
33920 | return CGAlgorithms.distancePointLine(p, this.p0, this.p1)
|
33921 | }
|
33922 | };
|
33923 | LineSegment.prototype.pointAlong = function pointAlong (segmentLengthFraction) {
|
33924 | var coord = new Coordinate();
|
33925 | coord.x = this.p0.x + segmentLengthFraction * (this.p1.x - this.p0.x);
|
33926 | coord.y = this.p0.y + segmentLengthFraction * (this.p1.y - this.p0.y);
|
33927 | return coord
|
33928 | };
|
33929 | LineSegment.prototype.hashCode = function hashCode () {
|
33930 | var bits0 = Double.doubleToLongBits(this.p0.x);
|
33931 | bits0 ^= Double.doubleToLongBits(this.p0.y) * 31;
|
33932 | var hash0 = Math.trunc(bits0) ^ Math.trunc(bits0 >> 32);
|
33933 | var bits1 = Double.doubleToLongBits(this.p1.x);
|
33934 | bits1 ^= Double.doubleToLongBits(this.p1.y) * 31;
|
33935 | var hash1 = Math.trunc(bits1) ^ Math.trunc(bits1 >> 32);
|
33936 | return hash0 ^ hash1
|
33937 | };
|
33938 | LineSegment.prototype.interfaces_ = function interfaces_ () {
|
33939 | return [Comparable, Serializable]
|
33940 | };
|
33941 | LineSegment.prototype.getClass = function getClass () {
|
33942 | return LineSegment
|
33943 | };
|
33944 | LineSegment.midPoint = function midPoint (p0, p1) {
|
33945 | return new Coordinate((p0.x + p1.x) / 2, (p0.y + p1.y) / 2)
|
33946 | };
|
33947 | staticAccessors$24.serialVersionUID.get = function () { return 3252005833466256227 };
|
33948 |
|
33949 | Object.defineProperties( LineSegment, staticAccessors$24 );
|
33950 |
|
33951 | var MonotoneChainOverlapAction = function MonotoneChainOverlapAction () {
|
33952 | this.tempEnv1 = new Envelope();
|
33953 | this.tempEnv2 = new Envelope();
|
33954 | this._overlapSeg1 = new LineSegment();
|
33955 | this._overlapSeg2 = new LineSegment();
|
33956 | };
|
33957 | MonotoneChainOverlapAction.prototype.overlap = function overlap () {
|
33958 | if (arguments.length === 2) {
|
33959 |
|
33960 |
|
33961 | } else if (arguments.length === 4) {
|
33962 | var mc1 = arguments[0];
|
33963 | var start1 = arguments[1];
|
33964 | var mc2 = arguments[2];
|
33965 | var start2 = arguments[3];
|
33966 | mc1.getLineSegment(start1, this._overlapSeg1);
|
33967 | mc2.getLineSegment(start2, this._overlapSeg2);
|
33968 | this.overlap(this._overlapSeg1, this._overlapSeg2);
|
33969 | }
|
33970 | };
|
33971 | MonotoneChainOverlapAction.prototype.interfaces_ = function interfaces_ () {
|
33972 | return []
|
33973 | };
|
33974 | MonotoneChainOverlapAction.prototype.getClass = function getClass () {
|
33975 | return MonotoneChainOverlapAction
|
33976 | };
|
33977 |
|
33978 | var MonotoneChain = function MonotoneChain () {
|
33979 | this._pts = null;
|
33980 | this._start = null;
|
33981 | this._end = null;
|
33982 | this._env = null;
|
33983 | this._context = null;
|
33984 | this._id = null;
|
33985 | var pts = arguments[0];
|
33986 | var start = arguments[1];
|
33987 | var end = arguments[2];
|
33988 | var context = arguments[3];
|
33989 | this._pts = pts;
|
33990 | this._start = start;
|
33991 | this._end = end;
|
33992 | this._context = context;
|
33993 | };
|
33994 | MonotoneChain.prototype.getLineSegment = function getLineSegment (index, ls) {
|
33995 | ls.p0 = this._pts[index];
|
33996 | ls.p1 = this._pts[index + 1];
|
33997 | };
|
33998 | MonotoneChain.prototype.computeSelect = function computeSelect (searchEnv, start0, end0, mcs) {
|
33999 | var p0 = this._pts[start0];
|
34000 | var p1 = this._pts[end0];
|
34001 | mcs.tempEnv1.init(p0, p1);
|
34002 | if (end0 - start0 === 1) {
|
34003 | mcs.select(this, start0);
|
34004 | return null
|
34005 | }
|
34006 | if (!searchEnv.intersects(mcs.tempEnv1)) { return null }
|
34007 | var mid = Math.trunc((start0 + end0) / 2);
|
34008 | if (start0 < mid) {
|
34009 | this.computeSelect(searchEnv, start0, mid, mcs);
|
34010 | }
|
34011 | if (mid < end0) {
|
34012 | this.computeSelect(searchEnv, mid, end0, mcs);
|
34013 | }
|
34014 | };
|
34015 | MonotoneChain.prototype.getCoordinates = function getCoordinates () {
|
34016 | var this$1 = this;
|
34017 |
|
34018 | var coord = new Array(this._end - this._start + 1).fill(null);
|
34019 | var index = 0;
|
34020 | for (var i = this._start; i <= this._end; i++) {
|
34021 | coord[index++] = this$1._pts[i];
|
34022 | }
|
34023 | return coord
|
34024 | };
|
34025 | MonotoneChain.prototype.computeOverlaps = function computeOverlaps (mc, mco) {
|
34026 | this.computeOverlapsInternal(this._start, this._end, mc, mc._start, mc._end, mco);
|
34027 | };
|
34028 | MonotoneChain.prototype.setId = function setId (id) {
|
34029 | this._id = id;
|
34030 | };
|
34031 | MonotoneChain.prototype.select = function select (searchEnv, mcs) {
|
34032 | this.computeSelect(searchEnv, this._start, this._end, mcs);
|
34033 | };
|
34034 | MonotoneChain.prototype.getEnvelope = function getEnvelope () {
|
34035 | if (this._env === null) {
|
34036 | var p0 = this._pts[this._start];
|
34037 | var p1 = this._pts[this._end];
|
34038 | this._env = new Envelope(p0, p1);
|
34039 | }
|
34040 | return this._env
|
34041 | };
|
34042 | MonotoneChain.prototype.getEndIndex = function getEndIndex () {
|
34043 | return this._end
|
34044 | };
|
34045 | MonotoneChain.prototype.getStartIndex = function getStartIndex () {
|
34046 | return this._start
|
34047 | };
|
34048 | MonotoneChain.prototype.getContext = function getContext () {
|
34049 | return this._context
|
34050 | };
|
34051 | MonotoneChain.prototype.getId = function getId () {
|
34052 | return this._id
|
34053 | };
|
34054 | MonotoneChain.prototype.computeOverlapsInternal = function computeOverlapsInternal (start0, end0, mc, start1, end1, mco) {
|
34055 | var p00 = this._pts[start0];
|
34056 | var p01 = this._pts[end0];
|
34057 | var p10 = mc._pts[start1];
|
34058 | var p11 = mc._pts[end1];
|
34059 | if (end0 - start0 === 1 && end1 - start1 === 1) {
|
34060 | mco.overlap(this, start0, mc, start1);
|
34061 | return null
|
34062 | }
|
34063 | mco.tempEnv1.init(p00, p01);
|
34064 | mco.tempEnv2.init(p10, p11);
|
34065 | if (!mco.tempEnv1.intersects(mco.tempEnv2)) { return null }
|
34066 | var mid0 = Math.trunc((start0 + end0) / 2);
|
34067 | var mid1 = Math.trunc((start1 + end1) / 2);
|
34068 | if (start0 < mid0) {
|
34069 | if (start1 < mid1) { this.computeOverlapsInternal(start0, mid0, mc, start1, mid1, mco); }
|
34070 | if (mid1 < end1) { this.computeOverlapsInternal(start0, mid0, mc, mid1, end1, mco); }
|
34071 | }
|
34072 | if (mid0 < end0) {
|
34073 | if (start1 < mid1) { this.computeOverlapsInternal(mid0, end0, mc, start1, mid1, mco); }
|
34074 | if (mid1 < end1) { this.computeOverlapsInternal(mid0, end0, mc, mid1, end1, mco); }
|
34075 | }
|
34076 | };
|
34077 | MonotoneChain.prototype.interfaces_ = function interfaces_ () {
|
34078 | return []
|
34079 | };
|
34080 | MonotoneChain.prototype.getClass = function getClass () {
|
34081 | return MonotoneChain
|
34082 | };
|
34083 |
|
34084 | var MonotoneChainBuilder = function MonotoneChainBuilder () {};
|
34085 |
|
34086 | MonotoneChainBuilder.prototype.interfaces_ = function interfaces_ () {
|
34087 | return []
|
34088 | };
|
34089 | MonotoneChainBuilder.prototype.getClass = function getClass () {
|
34090 | return MonotoneChainBuilder
|
34091 | };
|
34092 | MonotoneChainBuilder.getChainStartIndices = function getChainStartIndices (pts) {
|
34093 | var start = 0;
|
34094 | var startIndexList = new ArrayList();
|
34095 | startIndexList.add(new Integer(start));
|
34096 | do {
|
34097 | var last = MonotoneChainBuilder.findChainEnd(pts, start);
|
34098 | startIndexList.add(new Integer(last));
|
34099 | start = last;
|
34100 | } while (start < pts.length - 1)
|
34101 | var startIndex = MonotoneChainBuilder.toIntArray(startIndexList);
|
34102 | return startIndex
|
34103 | };
|
34104 | MonotoneChainBuilder.findChainEnd = function findChainEnd (pts, start) {
|
34105 | var safeStart = start;
|
34106 | while (safeStart < pts.length - 1 && pts[safeStart].equals2D(pts[safeStart + 1])) {
|
34107 | safeStart++;
|
34108 | }
|
34109 | if (safeStart >= pts.length - 1) {
|
34110 | return pts.length - 1
|
34111 | }
|
34112 | var chainQuad = Quadrant.quadrant(pts[safeStart], pts[safeStart + 1]);
|
34113 | var last = start + 1;
|
34114 | while (last < pts.length) {
|
34115 | if (!pts[last - 1].equals2D(pts[last])) {
|
34116 | var quad = Quadrant.quadrant(pts[last - 1], pts[last]);
|
34117 | if (quad !== chainQuad) { break }
|
34118 | }
|
34119 | last++;
|
34120 | }
|
34121 | return last - 1
|
34122 | };
|
34123 | MonotoneChainBuilder.getChains = function getChains () {
|
34124 | if (arguments.length === 1) {
|
34125 | var pts = arguments[0];
|
34126 | return MonotoneChainBuilder.getChains(pts, null)
|
34127 | } else if (arguments.length === 2) {
|
34128 | var pts$1 = arguments[0];
|
34129 | var context = arguments[1];
|
34130 | var mcList = new ArrayList();
|
34131 | var startIndex = MonotoneChainBuilder.getChainStartIndices(pts$1);
|
34132 | for (var i = 0; i < startIndex.length - 1; i++) {
|
34133 | var mc = new MonotoneChain(pts$1, startIndex[i], startIndex[i + 1], context);
|
34134 | mcList.add(mc);
|
34135 | }
|
34136 | return mcList
|
34137 | }
|
34138 | };
|
34139 | MonotoneChainBuilder.toIntArray = function toIntArray (list) {
|
34140 | var array = new Array(list.size()).fill(null);
|
34141 | for (var i = 0; i < array.length; i++) {
|
34142 | array[i] = list.get(i).intValue();
|
34143 | }
|
34144 | return array
|
34145 | };
|
34146 |
|
34147 | var Noder = function Noder () {};
|
34148 |
|
34149 | Noder.prototype.computeNodes = function computeNodes (segStrings) {};
|
34150 | Noder.prototype.getNodedSubstrings = function getNodedSubstrings () {};
|
34151 | Noder.prototype.interfaces_ = function interfaces_ () {
|
34152 | return []
|
34153 | };
|
34154 | Noder.prototype.getClass = function getClass () {
|
34155 | return Noder
|
34156 | };
|
34157 |
|
34158 | var SinglePassNoder = function SinglePassNoder () {
|
34159 | this._segInt = null;
|
34160 | if (arguments.length === 0) {} else if (arguments.length === 1) {
|
34161 | var segInt = arguments[0];
|
34162 | this.setSegmentIntersector(segInt);
|
34163 | }
|
34164 | };
|
34165 | SinglePassNoder.prototype.setSegmentIntersector = function setSegmentIntersector (segInt) {
|
34166 | this._segInt = segInt;
|
34167 | };
|
34168 | SinglePassNoder.prototype.interfaces_ = function interfaces_ () {
|
34169 | return [Noder]
|
34170 | };
|
34171 | SinglePassNoder.prototype.getClass = function getClass () {
|
34172 | return SinglePassNoder
|
34173 | };
|
34174 |
|
34175 | var MCIndexNoder = (function (SinglePassNoder$$1) {
|
34176 | function MCIndexNoder (si) {
|
34177 | if (si) { SinglePassNoder$$1.call(this, si); }
|
34178 | else { SinglePassNoder$$1.call(this); }
|
34179 | this._monoChains = new ArrayList();
|
34180 | this._index = new STRtree();
|
34181 | this._idCounter = 0;
|
34182 | this._nodedSegStrings = null;
|
34183 | this._nOverlaps = 0;
|
34184 | }
|
34185 |
|
34186 | if ( SinglePassNoder$$1 ) MCIndexNoder.__proto__ = SinglePassNoder$$1;
|
34187 | MCIndexNoder.prototype = Object.create( SinglePassNoder$$1 && SinglePassNoder$$1.prototype );
|
34188 | MCIndexNoder.prototype.constructor = MCIndexNoder;
|
34189 |
|
34190 | var staticAccessors = { SegmentOverlapAction: { configurable: true } };
|
34191 | MCIndexNoder.prototype.getMonotoneChains = function getMonotoneChains () {
|
34192 | return this._monoChains
|
34193 | };
|
34194 | MCIndexNoder.prototype.getNodedSubstrings = function getNodedSubstrings () {
|
34195 | return NodedSegmentString.getNodedSubstrings(this._nodedSegStrings)
|
34196 | };
|
34197 | MCIndexNoder.prototype.getIndex = function getIndex () {
|
34198 | return this._index
|
34199 | };
|
34200 | MCIndexNoder.prototype.add = function add (segStr) {
|
34201 | var this$1 = this;
|
34202 |
|
34203 | var segChains = MonotoneChainBuilder.getChains(segStr.getCoordinates(), segStr);
|
34204 | for (var i = segChains.iterator(); i.hasNext();) {
|
34205 | var mc = i.next();
|
34206 | mc.setId(this$1._idCounter++);
|
34207 | this$1._index.insert(mc.getEnvelope(), mc);
|
34208 | this$1._monoChains.add(mc);
|
34209 | }
|
34210 | };
|
34211 | MCIndexNoder.prototype.computeNodes = function computeNodes (inputSegStrings) {
|
34212 | var this$1 = this;
|
34213 |
|
34214 | this._nodedSegStrings = inputSegStrings;
|
34215 | for (var i = inputSegStrings.iterator(); i.hasNext();) {
|
34216 | this$1.add(i.next());
|
34217 | }
|
34218 | this.intersectChains();
|
34219 | };
|
34220 | MCIndexNoder.prototype.intersectChains = function intersectChains () {
|
34221 | var this$1 = this;
|
34222 |
|
34223 | var overlapAction = new SegmentOverlapAction(this._segInt);
|
34224 | for (var i = this._monoChains.iterator(); i.hasNext();) {
|
34225 | var queryChain = i.next();
|
34226 | var overlapChains = this$1._index.query(queryChain.getEnvelope());
|
34227 | for (var j = overlapChains.iterator(); j.hasNext();) {
|
34228 | var testChain = j.next();
|
34229 | if (testChain.getId() > queryChain.getId()) {
|
34230 | queryChain.computeOverlaps(testChain, overlapAction);
|
34231 | this$1._nOverlaps++;
|
34232 | }
|
34233 | if (this$1._segInt.isDone()) { return null }
|
34234 | }
|
34235 | }
|
34236 | };
|
34237 | MCIndexNoder.prototype.interfaces_ = function interfaces_ () {
|
34238 | return []
|
34239 | };
|
34240 | MCIndexNoder.prototype.getClass = function getClass () {
|
34241 | return MCIndexNoder
|
34242 | };
|
34243 | staticAccessors.SegmentOverlapAction.get = function () { return SegmentOverlapAction };
|
34244 |
|
34245 | Object.defineProperties( MCIndexNoder, staticAccessors );
|
34246 |
|
34247 | return MCIndexNoder;
|
34248 | }(SinglePassNoder));
|
34249 |
|
34250 | var SegmentOverlapAction = (function (MonotoneChainOverlapAction$$1) {
|
34251 | function SegmentOverlapAction () {
|
34252 | MonotoneChainOverlapAction$$1.call(this);
|
34253 | this._si = null;
|
34254 | var si = arguments[0];
|
34255 | this._si = si;
|
34256 | }
|
34257 |
|
34258 | if ( MonotoneChainOverlapAction$$1 ) SegmentOverlapAction.__proto__ = MonotoneChainOverlapAction$$1;
|
34259 | SegmentOverlapAction.prototype = Object.create( MonotoneChainOverlapAction$$1 && MonotoneChainOverlapAction$$1.prototype );
|
34260 | SegmentOverlapAction.prototype.constructor = SegmentOverlapAction;
|
34261 | SegmentOverlapAction.prototype.overlap = function overlap () {
|
34262 | if (arguments.length === 4) {
|
34263 | var mc1 = arguments[0];
|
34264 | var start1 = arguments[1];
|
34265 | var mc2 = arguments[2];
|
34266 | var start2 = arguments[3];
|
34267 | var ss1 = mc1.getContext();
|
34268 | var ss2 = mc2.getContext();
|
34269 | this._si.processIntersections(ss1, start1, ss2, start2);
|
34270 | } else { return MonotoneChainOverlapAction$$1.prototype.overlap.apply(this, arguments) }
|
34271 | };
|
34272 | SegmentOverlapAction.prototype.interfaces_ = function interfaces_ () {
|
34273 | return []
|
34274 | };
|
34275 | SegmentOverlapAction.prototype.getClass = function getClass () {
|
34276 | return SegmentOverlapAction
|
34277 | };
|
34278 |
|
34279 | return SegmentOverlapAction;
|
34280 | }(MonotoneChainOverlapAction));
|
34281 |
|
34282 | var BufferParameters = function BufferParameters () {
|
34283 | this._quadrantSegments = BufferParameters.DEFAULT_QUADRANT_SEGMENTS;
|
34284 | this._endCapStyle = BufferParameters.CAP_ROUND;
|
34285 | this._joinStyle = BufferParameters.JOIN_ROUND;
|
34286 | this._mitreLimit = BufferParameters.DEFAULT_MITRE_LIMIT;
|
34287 | this._isSingleSided = false;
|
34288 | this._simplifyFactor = BufferParameters.DEFAULT_SIMPLIFY_FACTOR;
|
34289 |
|
34290 | if (arguments.length === 0) {} else if (arguments.length === 1) {
|
34291 | var quadrantSegments = arguments[0];
|
34292 | this.setQuadrantSegments(quadrantSegments);
|
34293 | } else if (arguments.length === 2) {
|
34294 | var quadrantSegments$1 = arguments[0];
|
34295 | var endCapStyle = arguments[1];
|
34296 | this.setQuadrantSegments(quadrantSegments$1);
|
34297 | this.setEndCapStyle(endCapStyle);
|
34298 | } else if (arguments.length === 4) {
|
34299 | var quadrantSegments$2 = arguments[0];
|
34300 | var endCapStyle$1 = arguments[1];
|
34301 | var joinStyle = arguments[2];
|
34302 | var mitreLimit = arguments[3];
|
34303 | this.setQuadrantSegments(quadrantSegments$2);
|
34304 | this.setEndCapStyle(endCapStyle$1);
|
34305 | this.setJoinStyle(joinStyle);
|
34306 | this.setMitreLimit(mitreLimit);
|
34307 | }
|
34308 | };
|
34309 |
|
34310 | var staticAccessors$25 = { CAP_ROUND: { configurable: true },CAP_FLAT: { configurable: true },CAP_SQUARE: { configurable: true },JOIN_ROUND: { configurable: true },JOIN_MITRE: { configurable: true },JOIN_BEVEL: { configurable: true },DEFAULT_QUADRANT_SEGMENTS: { configurable: true },DEFAULT_MITRE_LIMIT: { configurable: true },DEFAULT_SIMPLIFY_FACTOR: { configurable: true } };
|
34311 | BufferParameters.prototype.getEndCapStyle = function getEndCapStyle () {
|
34312 | return this._endCapStyle
|
34313 | };
|
34314 | BufferParameters.prototype.isSingleSided = function isSingleSided () {
|
34315 | return this._isSingleSided
|
34316 | };
|
34317 | BufferParameters.prototype.setQuadrantSegments = function setQuadrantSegments (quadSegs) {
|
34318 | this._quadrantSegments = quadSegs;
|
34319 | if (this._quadrantSegments === 0) { this._joinStyle = BufferParameters.JOIN_BEVEL; }
|
34320 | if (this._quadrantSegments < 0) {
|
34321 | this._joinStyle = BufferParameters.JOIN_MITRE;
|
34322 | this._mitreLimit = Math.abs(this._quadrantSegments);
|
34323 | }
|
34324 | if (quadSegs <= 0) {
|
34325 | this._quadrantSegments = 1;
|
34326 | }
|
34327 | if (this._joinStyle !== BufferParameters.JOIN_ROUND) {
|
34328 | this._quadrantSegments = BufferParameters.DEFAULT_QUADRANT_SEGMENTS;
|
34329 | }
|
34330 | };
|
34331 | BufferParameters.prototype.getJoinStyle = function getJoinStyle () {
|
34332 | return this._joinStyle
|
34333 | };
|
34334 | BufferParameters.prototype.setJoinStyle = function setJoinStyle (joinStyle) {
|
34335 | this._joinStyle = joinStyle;
|
34336 | };
|
34337 | BufferParameters.prototype.setSimplifyFactor = function setSimplifyFactor (simplifyFactor) {
|
34338 | this._simplifyFactor = simplifyFactor < 0 ? 0 : simplifyFactor;
|
34339 | };
|
34340 | BufferParameters.prototype.getSimplifyFactor = function getSimplifyFactor () {
|
34341 | return this._simplifyFactor
|
34342 | };
|
34343 | BufferParameters.prototype.getQuadrantSegments = function getQuadrantSegments () {
|
34344 | return this._quadrantSegments
|
34345 | };
|
34346 | BufferParameters.prototype.setEndCapStyle = function setEndCapStyle (endCapStyle) {
|
34347 | this._endCapStyle = endCapStyle;
|
34348 | };
|
34349 | BufferParameters.prototype.getMitreLimit = function getMitreLimit () {
|
34350 | return this._mitreLimit
|
34351 | };
|
34352 | BufferParameters.prototype.setMitreLimit = function setMitreLimit (mitreLimit) {
|
34353 | this._mitreLimit = mitreLimit;
|
34354 | };
|
34355 | BufferParameters.prototype.setSingleSided = function setSingleSided (isSingleSided) {
|
34356 | this._isSingleSided = isSingleSided;
|
34357 | };
|
34358 | BufferParameters.prototype.interfaces_ = function interfaces_ () {
|
34359 | return []
|
34360 | };
|
34361 | BufferParameters.prototype.getClass = function getClass () {
|
34362 | return BufferParameters
|
34363 | };
|
34364 | BufferParameters.bufferDistanceError = function bufferDistanceError (quadSegs) {
|
34365 | var alpha = Math.PI / 2.0 / quadSegs;
|
34366 | return 1 - Math.cos(alpha / 2.0)
|
34367 | };
|
34368 | staticAccessors$25.CAP_ROUND.get = function () { return 1 };
|
34369 | staticAccessors$25.CAP_FLAT.get = function () { return 2 };
|
34370 | staticAccessors$25.CAP_SQUARE.get = function () { return 3 };
|
34371 | staticAccessors$25.JOIN_ROUND.get = function () { return 1 };
|
34372 | staticAccessors$25.JOIN_MITRE.get = function () { return 2 };
|
34373 | staticAccessors$25.JOIN_BEVEL.get = function () { return 3 };
|
34374 | staticAccessors$25.DEFAULT_QUADRANT_SEGMENTS.get = function () { return 8 };
|
34375 | staticAccessors$25.DEFAULT_MITRE_LIMIT.get = function () { return 5.0 };
|
34376 | staticAccessors$25.DEFAULT_SIMPLIFY_FACTOR.get = function () { return 0.01 };
|
34377 |
|
34378 | Object.defineProperties( BufferParameters, staticAccessors$25 );
|
34379 |
|
34380 | var BufferInputLineSimplifier = function BufferInputLineSimplifier (inputLine) {
|
34381 | this._distanceTol = null;
|
34382 | this._isDeleted = null;
|
34383 | this._angleOrientation = CGAlgorithms.COUNTERCLOCKWISE;
|
34384 | this._inputLine = inputLine || null;
|
34385 | };
|
34386 |
|
34387 | var staticAccessors$26 = { INIT: { configurable: true },DELETE: { configurable: true },KEEP: { configurable: true },NUM_PTS_TO_CHECK: { configurable: true } };
|
34388 | BufferInputLineSimplifier.prototype.isDeletable = function isDeletable (i0, i1, i2, distanceTol) {
|
34389 | var p0 = this._inputLine[i0];
|
34390 | var p1 = this._inputLine[i1];
|
34391 | var p2 = this._inputLine[i2];
|
34392 | if (!this.isConcave(p0, p1, p2)) { return false }
|
34393 | if (!this.isShallow(p0, p1, p2, distanceTol)) { return false }
|
34394 | return this.isShallowSampled(p0, p1, i0, i2, distanceTol)
|
34395 | };
|
34396 | BufferInputLineSimplifier.prototype.deleteShallowConcavities = function deleteShallowConcavities () {
|
34397 | var this$1 = this;
|
34398 |
|
34399 | var index = 1;
|
34400 |
|
34401 | var midIndex = this.findNextNonDeletedIndex(index);
|
34402 | var lastIndex = this.findNextNonDeletedIndex(midIndex);
|
34403 | var isChanged = false;
|
34404 | while (lastIndex < this._inputLine.length) {
|
34405 | var isMiddleVertexDeleted = false;
|
34406 | if (this$1.isDeletable(index, midIndex, lastIndex, this$1._distanceTol)) {
|
34407 | this$1._isDeleted[midIndex] = BufferInputLineSimplifier.DELETE;
|
34408 | isMiddleVertexDeleted = true;
|
34409 | isChanged = true;
|
34410 | }
|
34411 | if (isMiddleVertexDeleted) { index = lastIndex; } else { index = midIndex; }
|
34412 | midIndex = this$1.findNextNonDeletedIndex(index);
|
34413 | lastIndex = this$1.findNextNonDeletedIndex(midIndex);
|
34414 | }
|
34415 | return isChanged
|
34416 | };
|
34417 | BufferInputLineSimplifier.prototype.isShallowConcavity = function isShallowConcavity (p0, p1, p2, distanceTol) {
|
34418 | var orientation = CGAlgorithms.computeOrientation(p0, p1, p2);
|
34419 | var isAngleToSimplify = orientation === this._angleOrientation;
|
34420 | if (!isAngleToSimplify) { return false }
|
34421 | var dist = CGAlgorithms.distancePointLine(p1, p0, p2);
|
34422 | return dist < distanceTol
|
34423 | };
|
34424 | BufferInputLineSimplifier.prototype.isShallowSampled = function isShallowSampled (p0, p2, i0, i2, distanceTol) {
|
34425 | var this$1 = this;
|
34426 |
|
34427 | var inc = Math.trunc((i2 - i0) / BufferInputLineSimplifier.NUM_PTS_TO_CHECK);
|
34428 | if (inc <= 0) { inc = 1; }
|
34429 | for (var i = i0; i < i2; i += inc) {
|
34430 | if (!this$1.isShallow(p0, p2, this$1._inputLine[i], distanceTol)) { return false }
|
34431 | }
|
34432 | return true
|
34433 | };
|
34434 | BufferInputLineSimplifier.prototype.isConcave = function isConcave (p0, p1, p2) {
|
34435 | var orientation = CGAlgorithms.computeOrientation(p0, p1, p2);
|
34436 | var isConcave = orientation === this._angleOrientation;
|
34437 | return isConcave
|
34438 | };
|
34439 | BufferInputLineSimplifier.prototype.simplify = function simplify (distanceTol) {
|
34440 | var this$1 = this;
|
34441 |
|
34442 | this._distanceTol = Math.abs(distanceTol);
|
34443 | if (distanceTol < 0) { this._angleOrientation = CGAlgorithms.CLOCKWISE; }
|
34444 | this._isDeleted = new Array(this._inputLine.length).fill(null);
|
34445 | var isChanged = false;
|
34446 | do {
|
34447 | isChanged = this$1.deleteShallowConcavities();
|
34448 | } while (isChanged)
|
34449 | return this.collapseLine()
|
34450 | };
|
34451 | BufferInputLineSimplifier.prototype.findNextNonDeletedIndex = function findNextNonDeletedIndex (index) {
|
34452 | var next = index + 1;
|
34453 | while (next < this._inputLine.length && this._isDeleted[next] === BufferInputLineSimplifier.DELETE) { next++; }
|
34454 | return next
|
34455 | };
|
34456 | BufferInputLineSimplifier.prototype.isShallow = function isShallow (p0, p1, p2, distanceTol) {
|
34457 | var dist = CGAlgorithms.distancePointLine(p1, p0, p2);
|
34458 | return dist < distanceTol
|
34459 | };
|
34460 | BufferInputLineSimplifier.prototype.collapseLine = function collapseLine () {
|
34461 | var this$1 = this;
|
34462 |
|
34463 | var coordList = new CoordinateList();
|
34464 | for (var i = 0; i < this._inputLine.length; i++) {
|
34465 | if (this$1._isDeleted[i] !== BufferInputLineSimplifier.DELETE) { coordList.add(this$1._inputLine[i]); }
|
34466 | }
|
34467 | return coordList.toCoordinateArray()
|
34468 | };
|
34469 | BufferInputLineSimplifier.prototype.interfaces_ = function interfaces_ () {
|
34470 | return []
|
34471 | };
|
34472 | BufferInputLineSimplifier.prototype.getClass = function getClass () {
|
34473 | return BufferInputLineSimplifier
|
34474 | };
|
34475 | BufferInputLineSimplifier.simplify = function simplify (inputLine, distanceTol) {
|
34476 | var simp = new BufferInputLineSimplifier(inputLine);
|
34477 | return simp.simplify(distanceTol)
|
34478 | };
|
34479 | staticAccessors$26.INIT.get = function () { return 0 };
|
34480 | staticAccessors$26.DELETE.get = function () { return 1 };
|
34481 | staticAccessors$26.KEEP.get = function () { return 1 };
|
34482 | staticAccessors$26.NUM_PTS_TO_CHECK.get = function () { return 10 };
|
34483 |
|
34484 | Object.defineProperties( BufferInputLineSimplifier, staticAccessors$26 );
|
34485 |
|
34486 | var OffsetSegmentString = function OffsetSegmentString () {
|
34487 | this._ptList = null;
|
34488 | this._precisionModel = null;
|
34489 | this._minimimVertexDistance = 0.0;
|
34490 | this._ptList = new ArrayList();
|
34491 | };
|
34492 |
|
34493 | var staticAccessors$28 = { COORDINATE_ARRAY_TYPE: { configurable: true } };
|
34494 | OffsetSegmentString.prototype.getCoordinates = function getCoordinates () {
|
34495 | var coord = this._ptList.toArray(OffsetSegmentString.COORDINATE_ARRAY_TYPE);
|
34496 | return coord
|
34497 | };
|
34498 | OffsetSegmentString.prototype.setPrecisionModel = function setPrecisionModel (precisionModel) {
|
34499 | this._precisionModel = precisionModel;
|
34500 | };
|
34501 | OffsetSegmentString.prototype.addPt = function addPt (pt) {
|
34502 | var bufPt = new Coordinate(pt);
|
34503 | this._precisionModel.makePrecise(bufPt);
|
34504 | if (this.isRedundant(bufPt)) { return null }
|
34505 | this._ptList.add(bufPt);
|
34506 | };
|
34507 | OffsetSegmentString.prototype.revere = function revere () {};
|
34508 | OffsetSegmentString.prototype.addPts = function addPts (pt, isForward) {
|
34509 | var this$1 = this;
|
34510 |
|
34511 | if (isForward) {
|
34512 | for (var i = 0; i < pt.length; i++) {
|
34513 | this$1.addPt(pt[i]);
|
34514 | }
|
34515 | } else {
|
34516 | for (var i$1 = pt.length - 1; i$1 >= 0; i$1--) {
|
34517 | this$1.addPt(pt[i$1]);
|
34518 | }
|
34519 | }
|
34520 | };
|
34521 | OffsetSegmentString.prototype.isRedundant = function isRedundant (pt) {
|
34522 | if (this._ptList.size() < 1) { return false }
|
34523 | var lastPt = this._ptList.get(this._ptList.size() - 1);
|
34524 | var ptDist = pt.distance(lastPt);
|
34525 | if (ptDist < this._minimimVertexDistance) { return true }
|
34526 | return false
|
34527 | };
|
34528 | OffsetSegmentString.prototype.toString = function toString () {
|
34529 | var fact = new GeometryFactory();
|
34530 | var line = fact.createLineString(this.getCoordinates());
|
34531 | return line.toString()
|
34532 | };
|
34533 | OffsetSegmentString.prototype.closeRing = function closeRing () {
|
34534 | if (this._ptList.size() < 1) { return null }
|
34535 | var startPt = new Coordinate(this._ptList.get(0));
|
34536 | var lastPt = this._ptList.get(this._ptList.size() - 1);
|
34537 |
|
34538 |
|
34539 | if (startPt.equals(lastPt)) { return null }
|
34540 | this._ptList.add(startPt);
|
34541 | };
|
34542 | OffsetSegmentString.prototype.setMinimumVertexDistance = function setMinimumVertexDistance (minimimVertexDistance) {
|
34543 | this._minimimVertexDistance = minimimVertexDistance;
|
34544 | };
|
34545 | OffsetSegmentString.prototype.interfaces_ = function interfaces_ () {
|
34546 | return []
|
34547 | };
|
34548 | OffsetSegmentString.prototype.getClass = function getClass () {
|
34549 | return OffsetSegmentString
|
34550 | };
|
34551 | staticAccessors$28.COORDINATE_ARRAY_TYPE.get = function () { return new Array(0).fill(null) };
|
34552 |
|
34553 | Object.defineProperties( OffsetSegmentString, staticAccessors$28 );
|
34554 |
|
34555 | var Angle = function Angle () {};
|
34556 |
|
34557 | var staticAccessors$29 = { PI_TIMES_2: { configurable: true },PI_OVER_2: { configurable: true },PI_OVER_4: { configurable: true },COUNTERCLOCKWISE: { configurable: true },CLOCKWISE: { configurable: true },NONE: { configurable: true } };
|
34558 |
|
34559 | Angle.prototype.interfaces_ = function interfaces_ () {
|
34560 | return []
|
34561 | };
|
34562 | Angle.prototype.getClass = function getClass () {
|
34563 | return Angle
|
34564 | };
|
34565 | Angle.toDegrees = function toDegrees (radians) {
|
34566 | return radians * 180 / Math.PI
|
34567 | };
|
34568 | Angle.normalize = function normalize (angle) {
|
34569 | while (angle > Math.PI) { angle -= Angle.PI_TIMES_2; }
|
34570 | while (angle <= -Math.PI) { angle += Angle.PI_TIMES_2; }
|
34571 | return angle
|
34572 | };
|
34573 | Angle.angle = function angle () {
|
34574 | if (arguments.length === 1) {
|
34575 | var p = arguments[0];
|
34576 | return Math.atan2(p.y, p.x)
|
34577 | } else if (arguments.length === 2) {
|
34578 | var p0 = arguments[0];
|
34579 | var p1 = arguments[1];
|
34580 | var dx = p1.x - p0.x;
|
34581 | var dy = p1.y - p0.y;
|
34582 | return Math.atan2(dy, dx)
|
34583 | }
|
34584 | };
|
34585 | Angle.isAcute = function isAcute (p0, p1, p2) {
|
34586 | var dx0 = p0.x - p1.x;
|
34587 | var dy0 = p0.y - p1.y;
|
34588 | var dx1 = p2.x - p1.x;
|
34589 | var dy1 = p2.y - p1.y;
|
34590 | var dotprod = dx0 * dx1 + dy0 * dy1;
|
34591 | return dotprod > 0
|
34592 | };
|
34593 | Angle.isObtuse = function isObtuse (p0, p1, p2) {
|
34594 | var dx0 = p0.x - p1.x;
|
34595 | var dy0 = p0.y - p1.y;
|
34596 | var dx1 = p2.x - p1.x;
|
34597 | var dy1 = p2.y - p1.y;
|
34598 | var dotprod = dx0 * dx1 + dy0 * dy1;
|
34599 | return dotprod < 0
|
34600 | };
|
34601 | Angle.interiorAngle = function interiorAngle (p0, p1, p2) {
|
34602 | var anglePrev = Angle.angle(p1, p0);
|
34603 | var angleNext = Angle.angle(p1, p2);
|
34604 | return Math.abs(angleNext - anglePrev)
|
34605 | };
|
34606 | Angle.normalizePositive = function normalizePositive (angle) {
|
34607 | if (angle < 0.0) {
|
34608 | while (angle < 0.0) { angle += Angle.PI_TIMES_2; }
|
34609 | if (angle >= Angle.PI_TIMES_2) { angle = 0.0; }
|
34610 | } else {
|
34611 | while (angle >= Angle.PI_TIMES_2) { angle -= Angle.PI_TIMES_2; }
|
34612 | if (angle < 0.0) { angle = 0.0; }
|
34613 | }
|
34614 | return angle
|
34615 | };
|
34616 | Angle.angleBetween = function angleBetween (tip1, tail, tip2) {
|
34617 | var a1 = Angle.angle(tail, tip1);
|
34618 | var a2 = Angle.angle(tail, tip2);
|
34619 | return Angle.diff(a1, a2)
|
34620 | };
|
34621 | Angle.diff = function diff (ang1, ang2) {
|
34622 | var delAngle = null;
|
34623 | if (ang1 < ang2) {
|
34624 | delAngle = ang2 - ang1;
|
34625 | } else {
|
34626 | delAngle = ang1 - ang2;
|
34627 | }
|
34628 | if (delAngle > Math.PI) {
|
34629 | delAngle = 2 * Math.PI - delAngle;
|
34630 | }
|
34631 | return delAngle
|
34632 | };
|
34633 | Angle.toRadians = function toRadians (angleDegrees) {
|
34634 | return angleDegrees * Math.PI / 180.0
|
34635 | };
|
34636 | Angle.getTurn = function getTurn (ang1, ang2) {
|
34637 | var crossproduct = Math.sin(ang2 - ang1);
|
34638 | if (crossproduct > 0) {
|
34639 | return Angle.COUNTERCLOCKWISE
|
34640 | }
|
34641 | if (crossproduct < 0) {
|
34642 | return Angle.CLOCKWISE
|
34643 | }
|
34644 | return Angle.NONE
|
34645 | };
|
34646 | Angle.angleBetweenOriented = function angleBetweenOriented (tip1, tail, tip2) {
|
34647 | var a1 = Angle.angle(tail, tip1);
|
34648 | var a2 = Angle.angle(tail, tip2);
|
34649 | var angDel = a2 - a1;
|
34650 | if (angDel <= -Math.PI) { return angDel + Angle.PI_TIMES_2 }
|
34651 | if (angDel > Math.PI) { return angDel - Angle.PI_TIMES_2 }
|
34652 | return angDel
|
34653 | };
|
34654 | staticAccessors$29.PI_TIMES_2.get = function () { return 2.0 * Math.PI };
|
34655 | staticAccessors$29.PI_OVER_2.get = function () { return Math.PI / 2.0 };
|
34656 | staticAccessors$29.PI_OVER_4.get = function () { return Math.PI / 4.0 };
|
34657 | staticAccessors$29.COUNTERCLOCKWISE.get = function () { return CGAlgorithms.COUNTERCLOCKWISE };
|
34658 | staticAccessors$29.CLOCKWISE.get = function () { return CGAlgorithms.CLOCKWISE };
|
34659 | staticAccessors$29.NONE.get = function () { return CGAlgorithms.COLLINEAR };
|
34660 |
|
34661 | Object.defineProperties( Angle, staticAccessors$29 );
|
34662 |
|
34663 | var OffsetSegmentGenerator = function OffsetSegmentGenerator () {
|
34664 | this._maxCurveSegmentError = 0.0;
|
34665 | this._filletAngleQuantum = null;
|
34666 | this._closingSegLengthFactor = 1;
|
34667 | this._segList = null;
|
34668 | this._distance = 0.0;
|
34669 | this._precisionModel = null;
|
34670 | this._bufParams = null;
|
34671 | this._li = null;
|
34672 | this._s0 = null;
|
34673 | this._s1 = null;
|
34674 | this._s2 = null;
|
34675 | this._seg0 = new LineSegment();
|
34676 | this._seg1 = new LineSegment();
|
34677 | this._offset0 = new LineSegment();
|
34678 | this._offset1 = new LineSegment();
|
34679 | this._side = 0;
|
34680 | this._hasNarrowConcaveAngle = false;
|
34681 | var precisionModel = arguments[0];
|
34682 | var bufParams = arguments[1];
|
34683 | var distance = arguments[2];
|
34684 | this._precisionModel = precisionModel;
|
34685 | this._bufParams = bufParams;
|
34686 | this._li = new RobustLineIntersector();
|
34687 | this._filletAngleQuantum = Math.PI / 2.0 / bufParams.getQuadrantSegments();
|
34688 | if (bufParams.getQuadrantSegments() >= 8 && bufParams.getJoinStyle() === BufferParameters.JOIN_ROUND) { this._closingSegLengthFactor = OffsetSegmentGenerator.MAX_CLOSING_SEG_LEN_FACTOR; }
|
34689 | this.init(distance);
|
34690 | };
|
34691 |
|
34692 | var staticAccessors$27 = { OFFSET_SEGMENT_SEPARATION_FACTOR: { configurable: true },INSIDE_TURN_VERTEX_SNAP_DISTANCE_FACTOR: { configurable: true },CURVE_VERTEX_SNAP_DISTANCE_FACTOR: { configurable: true },MAX_CLOSING_SEG_LEN_FACTOR: { configurable: true } };
|
34693 | OffsetSegmentGenerator.prototype.addNextSegment = function addNextSegment (p, addStartPoint) {
|
34694 | this._s0 = this._s1;
|
34695 | this._s1 = this._s2;
|
34696 | this._s2 = p;
|
34697 | this._seg0.setCoordinates(this._s0, this._s1);
|
34698 | this.computeOffsetSegment(this._seg0, this._side, this._distance, this._offset0);
|
34699 | this._seg1.setCoordinates(this._s1, this._s2);
|
34700 | this.computeOffsetSegment(this._seg1, this._side, this._distance, this._offset1);
|
34701 | if (this._s1.equals(this._s2)) { return null }
|
34702 | var orientation = CGAlgorithms.computeOrientation(this._s0, this._s1, this._s2);
|
34703 | var outsideTurn = (orientation === CGAlgorithms.CLOCKWISE && this._side === Position.LEFT) || (orientation === CGAlgorithms.COUNTERCLOCKWISE && this._side === Position.RIGHT);
|
34704 | if (orientation === 0) {
|
34705 | this.addCollinear(addStartPoint);
|
34706 | } else if (outsideTurn) {
|
34707 | this.addOutsideTurn(orientation, addStartPoint);
|
34708 | } else {
|
34709 | this.addInsideTurn(orientation, addStartPoint);
|
34710 | }
|
34711 | };
|
34712 | OffsetSegmentGenerator.prototype.addLineEndCap = function addLineEndCap (p0, p1) {
|
34713 | var seg = new LineSegment(p0, p1);
|
34714 | var offsetL = new LineSegment();
|
34715 | this.computeOffsetSegment(seg, Position.LEFT, this._distance, offsetL);
|
34716 | var offsetR = new LineSegment();
|
34717 | this.computeOffsetSegment(seg, Position.RIGHT, this._distance, offsetR);
|
34718 | var dx = p1.x - p0.x;
|
34719 | var dy = p1.y - p0.y;
|
34720 | var angle = Math.atan2(dy, dx);
|
34721 | switch (this._bufParams.getEndCapStyle()) {
|
34722 | case BufferParameters.CAP_ROUND:
|
34723 | this._segList.addPt(offsetL.p1);
|
34724 | this.addFilletArc(p1, angle + Math.PI / 2, angle - Math.PI / 2, CGAlgorithms.CLOCKWISE, this._distance);
|
34725 | this._segList.addPt(offsetR.p1);
|
34726 | break
|
34727 | case BufferParameters.CAP_FLAT:
|
34728 | this._segList.addPt(offsetL.p1);
|
34729 | this._segList.addPt(offsetR.p1);
|
34730 | break
|
34731 | case BufferParameters.CAP_SQUARE:
|
34732 | var squareCapSideOffset = new Coordinate();
|
34733 | squareCapSideOffset.x = Math.abs(this._distance) * Math.cos(angle);
|
34734 | squareCapSideOffset.y = Math.abs(this._distance) * Math.sin(angle);
|
34735 | var squareCapLOffset = new Coordinate(offsetL.p1.x + squareCapSideOffset.x, offsetL.p1.y + squareCapSideOffset.y);
|
34736 | var squareCapROffset = new Coordinate(offsetR.p1.x + squareCapSideOffset.x, offsetR.p1.y + squareCapSideOffset.y);
|
34737 | this._segList.addPt(squareCapLOffset);
|
34738 | this._segList.addPt(squareCapROffset);
|
34739 | break
|
34740 | default:
|
34741 | }
|
34742 | };
|
34743 | OffsetSegmentGenerator.prototype.getCoordinates = function getCoordinates () {
|
34744 | var pts = this._segList.getCoordinates();
|
34745 | return pts
|
34746 | };
|
34747 | OffsetSegmentGenerator.prototype.addMitreJoin = function addMitreJoin (p, offset0, offset1, distance) {
|
34748 | var isMitreWithinLimit = true;
|
34749 | var intPt = null;
|
34750 | try {
|
34751 | intPt = HCoordinate.intersection(offset0.p0, offset0.p1, offset1.p0, offset1.p1);
|
34752 | var mitreRatio = distance <= 0.0 ? 1.0 : intPt.distance(p) / Math.abs(distance);
|
34753 | if (mitreRatio > this._bufParams.getMitreLimit()) { isMitreWithinLimit = false; }
|
34754 | } catch (ex) {
|
34755 | if (ex instanceof NotRepresentableException) {
|
34756 | intPt = new Coordinate(0, 0);
|
34757 | isMitreWithinLimit = false;
|
34758 | } else { throw ex }
|
34759 | } finally {}
|
34760 | if (isMitreWithinLimit) {
|
34761 | this._segList.addPt(intPt);
|
34762 | } else {
|
34763 | this.addLimitedMitreJoin(offset0, offset1, distance, this._bufParams.getMitreLimit());
|
34764 | }
|
34765 | };
|
34766 | OffsetSegmentGenerator.prototype.addFilletCorner = function addFilletCorner (p, p0, p1, direction, radius) {
|
34767 | var dx0 = p0.x - p.x;
|
34768 | var dy0 = p0.y - p.y;
|
34769 | var startAngle = Math.atan2(dy0, dx0);
|
34770 | var dx1 = p1.x - p.x;
|
34771 | var dy1 = p1.y - p.y;
|
34772 | var endAngle = Math.atan2(dy1, dx1);
|
34773 | if (direction === CGAlgorithms.CLOCKWISE) {
|
34774 | if (startAngle <= endAngle) { startAngle += 2.0 * Math.PI; }
|
34775 | } else {
|
34776 | if (startAngle >= endAngle) { startAngle -= 2.0 * Math.PI; }
|
34777 | }
|
34778 | this._segList.addPt(p0);
|
34779 | this.addFilletArc(p, startAngle, endAngle, direction, radius);
|
34780 | this._segList.addPt(p1);
|
34781 | };
|
34782 | OffsetSegmentGenerator.prototype.addOutsideTurn = function addOutsideTurn (orientation, addStartPoint) {
|
34783 | if (this._offset0.p1.distance(this._offset1.p0) < this._distance * OffsetSegmentGenerator.OFFSET_SEGMENT_SEPARATION_FACTOR) {
|
34784 | this._segList.addPt(this._offset0.p1);
|
34785 | return null
|
34786 | }
|
34787 | if (this._bufParams.getJoinStyle() === BufferParameters.JOIN_MITRE) {
|
34788 | this.addMitreJoin(this._s1, this._offset0, this._offset1, this._distance);
|
34789 | } else if (this._bufParams.getJoinStyle() === BufferParameters.JOIN_BEVEL) {
|
34790 | this.addBevelJoin(this._offset0, this._offset1);
|
34791 | } else {
|
34792 | if (addStartPoint) { this._segList.addPt(this._offset0.p1); }
|
34793 | this.addFilletCorner(this._s1, this._offset0.p1, this._offset1.p0, orientation, this._distance);
|
34794 | this._segList.addPt(this._offset1.p0);
|
34795 | }
|
34796 | };
|
34797 | OffsetSegmentGenerator.prototype.createSquare = function createSquare (p) {
|
34798 | this._segList.addPt(new Coordinate(p.x + this._distance, p.y + this._distance));
|
34799 | this._segList.addPt(new Coordinate(p.x + this._distance, p.y - this._distance));
|
34800 | this._segList.addPt(new Coordinate(p.x - this._distance, p.y - this._distance));
|
34801 | this._segList.addPt(new Coordinate(p.x - this._distance, p.y + this._distance));
|
34802 | this._segList.closeRing();
|
34803 | };
|
34804 | OffsetSegmentGenerator.prototype.addSegments = function addSegments (pt, isForward) {
|
34805 | this._segList.addPts(pt, isForward);
|
34806 | };
|
34807 | OffsetSegmentGenerator.prototype.addFirstSegment = function addFirstSegment () {
|
34808 | this._segList.addPt(this._offset1.p0);
|
34809 | };
|
34810 | OffsetSegmentGenerator.prototype.addLastSegment = function addLastSegment () {
|
34811 | this._segList.addPt(this._offset1.p1);
|
34812 | };
|
34813 | OffsetSegmentGenerator.prototype.initSideSegments = function initSideSegments (s1, s2, side) {
|
34814 | this._s1 = s1;
|
34815 | this._s2 = s2;
|
34816 | this._side = side;
|
34817 | this._seg1.setCoordinates(s1, s2);
|
34818 | this.computeOffsetSegment(this._seg1, side, this._distance, this._offset1);
|
34819 | };
|
34820 | OffsetSegmentGenerator.prototype.addLimitedMitreJoin = function addLimitedMitreJoin (offset0, offset1, distance, mitreLimit) {
|
34821 | var basePt = this._seg0.p1;
|
34822 | var ang0 = Angle.angle(basePt, this._seg0.p0);
|
34823 |
|
34824 | var angDiff = Angle.angleBetweenOriented(this._seg0.p0, basePt, this._seg1.p1);
|
34825 | var angDiffHalf = angDiff / 2;
|
34826 | var midAng = Angle.normalize(ang0 + angDiffHalf);
|
34827 | var mitreMidAng = Angle.normalize(midAng + Math.PI);
|
34828 | var mitreDist = mitreLimit * distance;
|
34829 | var bevelDelta = mitreDist * Math.abs(Math.sin(angDiffHalf));
|
34830 | var bevelHalfLen = distance - bevelDelta;
|
34831 | var bevelMidX = basePt.x + mitreDist * Math.cos(mitreMidAng);
|
34832 | var bevelMidY = basePt.y + mitreDist * Math.sin(mitreMidAng);
|
34833 | var bevelMidPt = new Coordinate(bevelMidX, bevelMidY);
|
34834 | var mitreMidLine = new LineSegment(basePt, bevelMidPt);
|
34835 | var bevelEndLeft = mitreMidLine.pointAlongOffset(1.0, bevelHalfLen);
|
34836 | var bevelEndRight = mitreMidLine.pointAlongOffset(1.0, -bevelHalfLen);
|
34837 | if (this._side === Position.LEFT) {
|
34838 | this._segList.addPt(bevelEndLeft);
|
34839 | this._segList.addPt(bevelEndRight);
|
34840 | } else {
|
34841 | this._segList.addPt(bevelEndRight);
|
34842 | this._segList.addPt(bevelEndLeft);
|
34843 | }
|
34844 | };
|
34845 | OffsetSegmentGenerator.prototype.computeOffsetSegment = function computeOffsetSegment (seg, side, distance, offset) {
|
34846 | var sideSign = side === Position.LEFT ? 1 : -1;
|
34847 | var dx = seg.p1.x - seg.p0.x;
|
34848 | var dy = seg.p1.y - seg.p0.y;
|
34849 | var len = Math.sqrt(dx * dx + dy * dy);
|
34850 | var ux = sideSign * distance * dx / len;
|
34851 | var uy = sideSign * distance * dy / len;
|
34852 | offset.p0.x = seg.p0.x - uy;
|
34853 | offset.p0.y = seg.p0.y + ux;
|
34854 | offset.p1.x = seg.p1.x - uy;
|
34855 | offset.p1.y = seg.p1.y + ux;
|
34856 | };
|
34857 | OffsetSegmentGenerator.prototype.addFilletArc = function addFilletArc (p, startAngle, endAngle, direction, radius) {
|
34858 | var this$1 = this;
|
34859 |
|
34860 | var directionFactor = direction === CGAlgorithms.CLOCKWISE ? -1 : 1;
|
34861 | var totalAngle = Math.abs(startAngle - endAngle);
|
34862 | var nSegs = Math.trunc(totalAngle / this._filletAngleQuantum + 0.5);
|
34863 | if (nSegs < 1) { return null }
|
34864 | var initAngle = 0.0;
|
34865 | var currAngleInc = totalAngle / nSegs;
|
34866 | var currAngle = initAngle;
|
34867 | var pt = new Coordinate();
|
34868 | while (currAngle < totalAngle) {
|
34869 | var angle = startAngle + directionFactor * currAngle;
|
34870 | pt.x = p.x + radius * Math.cos(angle);
|
34871 | pt.y = p.y + radius * Math.sin(angle);
|
34872 | this$1._segList.addPt(pt);
|
34873 | currAngle += currAngleInc;
|
34874 | }
|
34875 | };
|
34876 | OffsetSegmentGenerator.prototype.addInsideTurn = function addInsideTurn (orientation, addStartPoint) {
|
34877 | this._li.computeIntersection(this._offset0.p0, this._offset0.p1, this._offset1.p0, this._offset1.p1);
|
34878 | if (this._li.hasIntersection()) {
|
34879 | this._segList.addPt(this._li.getIntersection(0));
|
34880 | } else {
|
34881 | this._hasNarrowConcaveAngle = true;
|
34882 | if (this._offset0.p1.distance(this._offset1.p0) < this._distance * OffsetSegmentGenerator.INSIDE_TURN_VERTEX_SNAP_DISTANCE_FACTOR) {
|
34883 | this._segList.addPt(this._offset0.p1);
|
34884 | } else {
|
34885 | this._segList.addPt(this._offset0.p1);
|
34886 | if (this._closingSegLengthFactor > 0) {
|
34887 | var mid0 = new Coordinate((this._closingSegLengthFactor * this._offset0.p1.x + this._s1.x) / (this._closingSegLengthFactor + 1), (this._closingSegLengthFactor * this._offset0.p1.y + this._s1.y) / (this._closingSegLengthFactor + 1));
|
34888 | this._segList.addPt(mid0);
|
34889 | var mid1 = new Coordinate((this._closingSegLengthFactor * this._offset1.p0.x + this._s1.x) / (this._closingSegLengthFactor + 1), (this._closingSegLengthFactor * this._offset1.p0.y + this._s1.y) / (this._closingSegLengthFactor + 1));
|
34890 | this._segList.addPt(mid1);
|
34891 | } else {
|
34892 | this._segList.addPt(this._s1);
|
34893 | }
|
34894 | this._segList.addPt(this._offset1.p0);
|
34895 | }
|
34896 | }
|
34897 | };
|
34898 | OffsetSegmentGenerator.prototype.createCircle = function createCircle (p) {
|
34899 | var pt = new Coordinate(p.x + this._distance, p.y);
|
34900 | this._segList.addPt(pt);
|
34901 | this.addFilletArc(p, 0.0, 2.0 * Math.PI, -1, this._distance);
|
34902 | this._segList.closeRing();
|
34903 | };
|
34904 | OffsetSegmentGenerator.prototype.addBevelJoin = function addBevelJoin (offset0, offset1) {
|
34905 | this._segList.addPt(offset0.p1);
|
34906 | this._segList.addPt(offset1.p0);
|
34907 | };
|
34908 | OffsetSegmentGenerator.prototype.init = function init (distance) {
|
34909 | this._distance = distance;
|
34910 | this._maxCurveSegmentError = distance * (1 - Math.cos(this._filletAngleQuantum / 2.0));
|
34911 | this._segList = new OffsetSegmentString();
|
34912 | this._segList.setPrecisionModel(this._precisionModel);
|
34913 | this._segList.setMinimumVertexDistance(distance * OffsetSegmentGenerator.CURVE_VERTEX_SNAP_DISTANCE_FACTOR);
|
34914 | };
|
34915 | OffsetSegmentGenerator.prototype.addCollinear = function addCollinear (addStartPoint) {
|
34916 | this._li.computeIntersection(this._s0, this._s1, this._s1, this._s2);
|
34917 | var numInt = this._li.getIntersectionNum();
|
34918 | if (numInt >= 2) {
|
34919 | if (this._bufParams.getJoinStyle() === BufferParameters.JOIN_BEVEL || this._bufParams.getJoinStyle() === BufferParameters.JOIN_MITRE) {
|
34920 | if (addStartPoint) { this._segList.addPt(this._offset0.p1); }
|
34921 | this._segList.addPt(this._offset1.p0);
|
34922 | } else {
|
34923 | this.addFilletCorner(this._s1, this._offset0.p1, this._offset1.p0, CGAlgorithms.CLOCKWISE, this._distance);
|
34924 | }
|
34925 | }
|
34926 | };
|
34927 | OffsetSegmentGenerator.prototype.closeRing = function closeRing () {
|
34928 | this._segList.closeRing();
|
34929 | };
|
34930 | OffsetSegmentGenerator.prototype.hasNarrowConcaveAngle = function hasNarrowConcaveAngle () {
|
34931 | return this._hasNarrowConcaveAngle
|
34932 | };
|
34933 | OffsetSegmentGenerator.prototype.interfaces_ = function interfaces_ () {
|
34934 | return []
|
34935 | };
|
34936 | OffsetSegmentGenerator.prototype.getClass = function getClass () {
|
34937 | return OffsetSegmentGenerator
|
34938 | };
|
34939 | staticAccessors$27.OFFSET_SEGMENT_SEPARATION_FACTOR.get = function () { return 1.0E-3 };
|
34940 | staticAccessors$27.INSIDE_TURN_VERTEX_SNAP_DISTANCE_FACTOR.get = function () { return 1.0E-3 };
|
34941 | staticAccessors$27.CURVE_VERTEX_SNAP_DISTANCE_FACTOR.get = function () { return 1.0E-6 };
|
34942 | staticAccessors$27.MAX_CLOSING_SEG_LEN_FACTOR.get = function () { return 80 };
|
34943 |
|
34944 | Object.defineProperties( OffsetSegmentGenerator, staticAccessors$27 );
|
34945 |
|
34946 | var OffsetCurveBuilder = function OffsetCurveBuilder () {
|
34947 | this._distance = 0.0;
|
34948 | this._precisionModel = null;
|
34949 | this._bufParams = null;
|
34950 | var precisionModel = arguments[0];
|
34951 | var bufParams = arguments[1];
|
34952 | this._precisionModel = precisionModel;
|
34953 | this._bufParams = bufParams;
|
34954 | };
|
34955 | OffsetCurveBuilder.prototype.getOffsetCurve = function getOffsetCurve (inputPts, distance) {
|
34956 | this._distance = distance;
|
34957 | if (distance === 0.0) { return null }
|
34958 | var isRightSide = distance < 0.0;
|
34959 | var posDistance = Math.abs(distance);
|
34960 | var segGen = this.getSegGen(posDistance);
|
34961 | if (inputPts.length <= 1) {
|
34962 | this.computePointCurve(inputPts[0], segGen);
|
34963 | } else {
|
34964 | this.computeOffsetCurve(inputPts, isRightSide, segGen);
|
34965 | }
|
34966 | var curvePts = segGen.getCoordinates();
|
34967 | if (isRightSide) { CoordinateArrays.reverse(curvePts); }
|
34968 | return curvePts
|
34969 | };
|
34970 | OffsetCurveBuilder.prototype.computeSingleSidedBufferCurve = function computeSingleSidedBufferCurve (inputPts, isRightSide, segGen) {
|
34971 | var distTol = this.simplifyTolerance(this._distance);
|
34972 | if (isRightSide) {
|
34973 | segGen.addSegments(inputPts, true);
|
34974 | var simp2 = BufferInputLineSimplifier.simplify(inputPts, -distTol);
|
34975 | var n2 = simp2.length - 1;
|
34976 | segGen.initSideSegments(simp2[n2], simp2[n2 - 1], Position.LEFT);
|
34977 | segGen.addFirstSegment();
|
34978 | for (var i = n2 - 2; i >= 0; i--) {
|
34979 | segGen.addNextSegment(simp2[i], true);
|
34980 | }
|
34981 | } else {
|
34982 | segGen.addSegments(inputPts, false);
|
34983 | var simp1 = BufferInputLineSimplifier.simplify(inputPts, distTol);
|
34984 | var n1 = simp1.length - 1;
|
34985 | segGen.initSideSegments(simp1[0], simp1[1], Position.LEFT);
|
34986 | segGen.addFirstSegment();
|
34987 | for (var i$1 = 2; i$1 <= n1; i$1++) {
|
34988 | segGen.addNextSegment(simp1[i$1], true);
|
34989 | }
|
34990 | }
|
34991 | segGen.addLastSegment();
|
34992 | segGen.closeRing();
|
34993 | };
|
34994 | OffsetCurveBuilder.prototype.computeRingBufferCurve = function computeRingBufferCurve (inputPts, side, segGen) {
|
34995 | var distTol = this.simplifyTolerance(this._distance);
|
34996 | if (side === Position.RIGHT) { distTol = -distTol; }
|
34997 | var simp = BufferInputLineSimplifier.simplify(inputPts, distTol);
|
34998 | var n = simp.length - 1;
|
34999 | segGen.initSideSegments(simp[n - 1], simp[0], side);
|
35000 | for (var i = 1; i <= n; i++) {
|
35001 | var addStartPoint = i !== 1;
|
35002 | segGen.addNextSegment(simp[i], addStartPoint);
|
35003 | }
|
35004 | segGen.closeRing();
|
35005 | };
|
35006 | OffsetCurveBuilder.prototype.computeLineBufferCurve = function computeLineBufferCurve (inputPts, segGen) {
|
35007 | var distTol = this.simplifyTolerance(this._distance);
|
35008 | var simp1 = BufferInputLineSimplifier.simplify(inputPts, distTol);
|
35009 | var n1 = simp1.length - 1;
|
35010 | segGen.initSideSegments(simp1[0], simp1[1], Position.LEFT);
|
35011 | for (var i = 2; i <= n1; i++) {
|
35012 | segGen.addNextSegment(simp1[i], true);
|
35013 | }
|
35014 | segGen.addLastSegment();
|
35015 | segGen.addLineEndCap(simp1[n1 - 1], simp1[n1]);
|
35016 | var simp2 = BufferInputLineSimplifier.simplify(inputPts, -distTol);
|
35017 | var n2 = simp2.length - 1;
|
35018 | segGen.initSideSegments(simp2[n2], simp2[n2 - 1], Position.LEFT);
|
35019 | for (var i$1 = n2 - 2; i$1 >= 0; i$1--) {
|
35020 | segGen.addNextSegment(simp2[i$1], true);
|
35021 | }
|
35022 | segGen.addLastSegment();
|
35023 | segGen.addLineEndCap(simp2[1], simp2[0]);
|
35024 | segGen.closeRing();
|
35025 | };
|
35026 | OffsetCurveBuilder.prototype.computePointCurve = function computePointCurve (pt, segGen) {
|
35027 | switch (this._bufParams.getEndCapStyle()) {
|
35028 | case BufferParameters.CAP_ROUND:
|
35029 | segGen.createCircle(pt);
|
35030 | break
|
35031 | case BufferParameters.CAP_SQUARE:
|
35032 | segGen.createSquare(pt);
|
35033 | break
|
35034 | default:
|
35035 | }
|
35036 | };
|
35037 | OffsetCurveBuilder.prototype.getLineCurve = function getLineCurve (inputPts, distance) {
|
35038 | this._distance = distance;
|
35039 | if (distance < 0.0 && !this._bufParams.isSingleSided()) { return null }
|
35040 | if (distance === 0.0) { return null }
|
35041 | var posDistance = Math.abs(distance);
|
35042 | var segGen = this.getSegGen(posDistance);
|
35043 | if (inputPts.length <= 1) {
|
35044 | this.computePointCurve(inputPts[0], segGen);
|
35045 | } else {
|
35046 | if (this._bufParams.isSingleSided()) {
|
35047 | var isRightSide = distance < 0.0;
|
35048 | this.computeSingleSidedBufferCurve(inputPts, isRightSide, segGen);
|
35049 | } else { this.computeLineBufferCurve(inputPts, segGen); }
|
35050 | }
|
35051 | var lineCoord = segGen.getCoordinates();
|
35052 | return lineCoord
|
35053 | };
|
35054 | OffsetCurveBuilder.prototype.getBufferParameters = function getBufferParameters () {
|
35055 | return this._bufParams
|
35056 | };
|
35057 | OffsetCurveBuilder.prototype.simplifyTolerance = function simplifyTolerance (bufDistance) {
|
35058 | return bufDistance * this._bufParams.getSimplifyFactor()
|
35059 | };
|
35060 | OffsetCurveBuilder.prototype.getRingCurve = function getRingCurve (inputPts, side, distance) {
|
35061 | this._distance = distance;
|
35062 | if (inputPts.length <= 2) { return this.getLineCurve(inputPts, distance) }
|
35063 | if (distance === 0.0) {
|
35064 | return OffsetCurveBuilder.copyCoordinates(inputPts)
|
35065 | }
|
35066 | var segGen = this.getSegGen(distance);
|
35067 | this.computeRingBufferCurve(inputPts, side, segGen);
|
35068 | return segGen.getCoordinates()
|
35069 | };
|
35070 | OffsetCurveBuilder.prototype.computeOffsetCurve = function computeOffsetCurve (inputPts, isRightSide, segGen) {
|
35071 | var distTol = this.simplifyTolerance(this._distance);
|
35072 | if (isRightSide) {
|
35073 | var simp2 = BufferInputLineSimplifier.simplify(inputPts, -distTol);
|
35074 | var n2 = simp2.length - 1;
|
35075 | segGen.initSideSegments(simp2[n2], simp2[n2 - 1], Position.LEFT);
|
35076 | segGen.addFirstSegment();
|
35077 | for (var i = n2 - 2; i >= 0; i--) {
|
35078 | segGen.addNextSegment(simp2[i], true);
|
35079 | }
|
35080 | } else {
|
35081 | var simp1 = BufferInputLineSimplifier.simplify(inputPts, distTol);
|
35082 | var n1 = simp1.length - 1;
|
35083 | segGen.initSideSegments(simp1[0], simp1[1], Position.LEFT);
|
35084 | segGen.addFirstSegment();
|
35085 | for (var i$1 = 2; i$1 <= n1; i$1++) {
|
35086 | segGen.addNextSegment(simp1[i$1], true);
|
35087 | }
|
35088 | }
|
35089 | segGen.addLastSegment();
|
35090 | };
|
35091 | OffsetCurveBuilder.prototype.getSegGen = function getSegGen (distance) {
|
35092 | return new OffsetSegmentGenerator(this._precisionModel, this._bufParams, distance)
|
35093 | };
|
35094 | OffsetCurveBuilder.prototype.interfaces_ = function interfaces_ () {
|
35095 | return []
|
35096 | };
|
35097 | OffsetCurveBuilder.prototype.getClass = function getClass () {
|
35098 | return OffsetCurveBuilder
|
35099 | };
|
35100 | OffsetCurveBuilder.copyCoordinates = function copyCoordinates (pts) {
|
35101 | var copy = new Array(pts.length).fill(null);
|
35102 | for (var i = 0; i < copy.length; i++) {
|
35103 | copy[i] = new Coordinate(pts[i]);
|
35104 | }
|
35105 | return copy
|
35106 | };
|
35107 |
|
35108 | var SubgraphDepthLocater = function SubgraphDepthLocater () {
|
35109 | this._subgraphs = null;
|
35110 | this._seg = new LineSegment();
|
35111 | this._cga = new CGAlgorithms();
|
35112 | var subgraphs = arguments[0];
|
35113 | this._subgraphs = subgraphs;
|
35114 | };
|
35115 |
|
35116 | var staticAccessors$30 = { DepthSegment: { configurable: true } };
|
35117 | SubgraphDepthLocater.prototype.findStabbedSegments = function findStabbedSegments () {
|
35118 | var this$1 = this;
|
35119 |
|
35120 | if (arguments.length === 1) {
|
35121 | var stabbingRayLeftPt = arguments[0];
|
35122 | var stabbedSegments = new ArrayList();
|
35123 | for (var i = this._subgraphs.iterator(); i.hasNext();) {
|
35124 | var bsg = i.next();
|
35125 | var env = bsg.getEnvelope();
|
35126 | if (stabbingRayLeftPt.y < env.getMinY() || stabbingRayLeftPt.y > env.getMaxY()) { continue }
|
35127 | this$1.findStabbedSegments(stabbingRayLeftPt, bsg.getDirectedEdges(), stabbedSegments);
|
35128 | }
|
35129 | return stabbedSegments
|
35130 | } else if (arguments.length === 3) {
|
35131 | if (hasInterface(arguments[2], List) && (arguments[0] instanceof Coordinate && arguments[1] instanceof DirectedEdge)) {
|
35132 | var stabbingRayLeftPt$1 = arguments[0];
|
35133 | var dirEdge = arguments[1];
|
35134 | var stabbedSegments$1 = arguments[2];
|
35135 | var pts = dirEdge.getEdge().getCoordinates();
|
35136 | for (var i$1 = 0; i$1 < pts.length - 1; i$1++) {
|
35137 | this$1._seg.p0 = pts[i$1];
|
35138 | this$1._seg.p1 = pts[i$1 + 1];
|
35139 | if (this$1._seg.p0.y > this$1._seg.p1.y) { this$1._seg.reverse(); }
|
35140 | var maxx = Math.max(this$1._seg.p0.x, this$1._seg.p1.x);
|
35141 | if (maxx < stabbingRayLeftPt$1.x) { continue }
|
35142 | if (this$1._seg.isHorizontal()) { continue }
|
35143 | if (stabbingRayLeftPt$1.y < this$1._seg.p0.y || stabbingRayLeftPt$1.y > this$1._seg.p1.y) { continue }
|
35144 | if (CGAlgorithms.computeOrientation(this$1._seg.p0, this$1._seg.p1, stabbingRayLeftPt$1) === CGAlgorithms.RIGHT) { continue }
|
35145 | var depth = dirEdge.getDepth(Position.LEFT);
|
35146 | if (!this$1._seg.p0.equals(pts[i$1])) { depth = dirEdge.getDepth(Position.RIGHT); }
|
35147 | var ds = new DepthSegment(this$1._seg, depth);
|
35148 | stabbedSegments$1.add(ds);
|
35149 | }
|
35150 | } else if (hasInterface(arguments[2], List) && (arguments[0] instanceof Coordinate && hasInterface(arguments[1], List))) {
|
35151 | var stabbingRayLeftPt$2 = arguments[0];
|
35152 | var dirEdges = arguments[1];
|
35153 | var stabbedSegments$2 = arguments[2];
|
35154 | for (var i$2 = dirEdges.iterator(); i$2.hasNext();) {
|
35155 | var de = i$2.next();
|
35156 | if (!de.isForward()) { continue }
|
35157 | this$1.findStabbedSegments(stabbingRayLeftPt$2, de, stabbedSegments$2);
|
35158 | }
|
35159 | }
|
35160 | }
|
35161 | };
|
35162 | SubgraphDepthLocater.prototype.getDepth = function getDepth (p) {
|
35163 | var stabbedSegments = this.findStabbedSegments(p);
|
35164 | if (stabbedSegments.size() === 0) { return 0 }
|
35165 | var ds = Collections.min(stabbedSegments);
|
35166 | return ds._leftDepth
|
35167 | };
|
35168 | SubgraphDepthLocater.prototype.interfaces_ = function interfaces_ () {
|
35169 | return []
|
35170 | };
|
35171 | SubgraphDepthLocater.prototype.getClass = function getClass () {
|
35172 | return SubgraphDepthLocater
|
35173 | };
|
35174 | staticAccessors$30.DepthSegment.get = function () { return DepthSegment };
|
35175 |
|
35176 | Object.defineProperties( SubgraphDepthLocater, staticAccessors$30 );
|
35177 |
|
35178 | var DepthSegment = function DepthSegment () {
|
35179 | this._upwardSeg = null;
|
35180 | this._leftDepth = null;
|
35181 | var seg = arguments[0];
|
35182 | var depth = arguments[1];
|
35183 | this._upwardSeg = new LineSegment(seg);
|
35184 | this._leftDepth = depth;
|
35185 | };
|
35186 | DepthSegment.prototype.compareTo = function compareTo (obj) {
|
35187 | var other = obj;
|
35188 | if (this._upwardSeg.minX() >= other._upwardSeg.maxX()) { return 1 }
|
35189 | if (this._upwardSeg.maxX() <= other._upwardSeg.minX()) { return -1 }
|
35190 | var orientIndex = this._upwardSeg.orientationIndex(other._upwardSeg);
|
35191 | if (orientIndex !== 0) { return orientIndex }
|
35192 | orientIndex = -1 * other._upwardSeg.orientationIndex(this._upwardSeg);
|
35193 | if (orientIndex !== 0) { return orientIndex }
|
35194 | return this._upwardSeg.compareTo(other._upwardSeg)
|
35195 | };
|
35196 | DepthSegment.prototype.compareX = function compareX (seg0, seg1) {
|
35197 | var compare0 = seg0.p0.compareTo(seg1.p0);
|
35198 | if (compare0 !== 0) { return compare0 }
|
35199 | return seg0.p1.compareTo(seg1.p1)
|
35200 | };
|
35201 | DepthSegment.prototype.toString = function toString () {
|
35202 | return this._upwardSeg.toString()
|
35203 | };
|
35204 | DepthSegment.prototype.interfaces_ = function interfaces_ () {
|
35205 | return [Comparable]
|
35206 | };
|
35207 | DepthSegment.prototype.getClass = function getClass () {
|
35208 | return DepthSegment
|
35209 | };
|
35210 |
|
35211 | var Triangle$1 = function Triangle (p0, p1, p2) {
|
35212 | this.p0 = p0 || null;
|
35213 | this.p1 = p1 || null;
|
35214 | this.p2 = p2 || null;
|
35215 | };
|
35216 | Triangle$1.prototype.area = function area () {
|
35217 | return Triangle$1.area(this.p0, this.p1, this.p2)
|
35218 | };
|
35219 | Triangle$1.prototype.signedArea = function signedArea () {
|
35220 | return Triangle$1.signedArea(this.p0, this.p1, this.p2)
|
35221 | };
|
35222 | Triangle$1.prototype.interpolateZ = function interpolateZ (p) {
|
35223 | if (p === null) { throw new IllegalArgumentException('Supplied point is null.') }
|
35224 | return Triangle$1.interpolateZ(p, this.p0, this.p1, this.p2)
|
35225 | };
|
35226 | Triangle$1.prototype.longestSideLength = function longestSideLength () {
|
35227 | return Triangle$1.longestSideLength(this.p0, this.p1, this.p2)
|
35228 | };
|
35229 | Triangle$1.prototype.isAcute = function isAcute () {
|
35230 | return Triangle$1.isAcute(this.p0, this.p1, this.p2)
|
35231 | };
|
35232 | Triangle$1.prototype.circumcentre = function circumcentre () {
|
35233 | return Triangle$1.circumcentre(this.p0, this.p1, this.p2)
|
35234 | };
|
35235 | Triangle$1.prototype.area3D = function area3D () {
|
35236 | return Triangle$1.area3D(this.p0, this.p1, this.p2)
|
35237 | };
|
35238 | Triangle$1.prototype.centroid = function centroid () {
|
35239 | return Triangle$1.centroid(this.p0, this.p1, this.p2)
|
35240 | };
|
35241 | Triangle$1.prototype.inCentre = function inCentre () {
|
35242 | return Triangle$1.inCentre(this.p0, this.p1, this.p2)
|
35243 | };
|
35244 | Triangle$1.prototype.interfaces_ = function interfaces_ () {
|
35245 | return []
|
35246 | };
|
35247 | Triangle$1.prototype.getClass = function getClass () {
|
35248 | return Triangle$1
|
35249 | };
|
35250 | Triangle$1.area = function area (a, b, c) {
|
35251 | return Math.abs(((c.x - a.x) * (b.y - a.y) - (b.x - a.x) * (c.y - a.y)) / 2)
|
35252 | };
|
35253 | Triangle$1.signedArea = function signedArea (a, b, c) {
|
35254 | return ((c.x - a.x) * (b.y - a.y) - (b.x - a.x) * (c.y - a.y)) / 2
|
35255 | };
|
35256 | Triangle$1.det = function det (m00, m01, m10, m11) {
|
35257 | return m00 * m11 - m01 * m10
|
35258 | };
|
35259 | Triangle$1.interpolateZ = function interpolateZ (p, v0, v1, v2) {
|
35260 | var x0 = v0.x;
|
35261 | var y0 = v0.y;
|
35262 | var a = v1.x - x0;
|
35263 | var b = v2.x - x0;
|
35264 | var c = v1.y - y0;
|
35265 | var d = v2.y - y0;
|
35266 | var det = a * d - b * c;
|
35267 | var dx = p.x - x0;
|
35268 | var dy = p.y - y0;
|
35269 | var t = (d * dx - b * dy) / det;
|
35270 | var u = (-c * dx + a * dy) / det;
|
35271 | var z = v0.z + t * (v1.z - v0.z) + u * (v2.z - v0.z);
|
35272 | return z
|
35273 | };
|
35274 | Triangle$1.longestSideLength = function longestSideLength (a, b, c) {
|
35275 | var lenAB = a.distance(b);
|
35276 | var lenBC = b.distance(c);
|
35277 | var lenCA = c.distance(a);
|
35278 | var maxLen = lenAB;
|
35279 | if (lenBC > maxLen) { maxLen = lenBC; }
|
35280 | if (lenCA > maxLen) { maxLen = lenCA; }
|
35281 | return maxLen
|
35282 | };
|
35283 | Triangle$1.isAcute = function isAcute (a, b, c) {
|
35284 | if (!Angle.isAcute(a, b, c)) { return false }
|
35285 | if (!Angle.isAcute(b, c, a)) { return false }
|
35286 | if (!Angle.isAcute(c, a, b)) { return false }
|
35287 | return true
|
35288 | };
|
35289 | Triangle$1.circumcentre = function circumcentre (a, b, c) {
|
35290 | var cx = c.x;
|
35291 | var cy = c.y;
|
35292 | var ax = a.x - cx;
|
35293 | var ay = a.y - cy;
|
35294 | var bx = b.x - cx;
|
35295 | var by = b.y - cy;
|
35296 | var denom = 2 * Triangle$1.det(ax, ay, bx, by);
|
35297 | var numx = Triangle$1.det(ay, ax * ax + ay * ay, by, bx * bx + by * by);
|
35298 | var numy = Triangle$1.det(ax, ax * ax + ay * ay, bx, bx * bx + by * by);
|
35299 | var ccx = cx - numx / denom;
|
35300 | var ccy = cy + numy / denom;
|
35301 | return new Coordinate(ccx, ccy)
|
35302 | };
|
35303 | Triangle$1.perpendicularBisector = function perpendicularBisector (a, b) {
|
35304 | var dx = b.x - a.x;
|
35305 | var dy = b.y - a.y;
|
35306 | var l1 = new HCoordinate(a.x + dx / 2.0, a.y + dy / 2.0, 1.0);
|
35307 | var l2 = new HCoordinate(a.x - dy + dx / 2.0, a.y + dx + dy / 2.0, 1.0);
|
35308 | return new HCoordinate(l1, l2)
|
35309 | };
|
35310 | Triangle$1.angleBisector = function angleBisector (a, b, c) {
|
35311 | var len0 = b.distance(a);
|
35312 | var len2 = b.distance(c);
|
35313 | var frac = len0 / (len0 + len2);
|
35314 | var dx = c.x - a.x;
|
35315 | var dy = c.y - a.y;
|
35316 | var splitPt = new Coordinate(a.x + frac * dx, a.y + frac * dy);
|
35317 | return splitPt
|
35318 | };
|
35319 | Triangle$1.area3D = function area3D (a, b, c) {
|
35320 | var ux = b.x - a.x;
|
35321 | var uy = b.y - a.y;
|
35322 | var uz = b.z - a.z;
|
35323 | var vx = c.x - a.x;
|
35324 | var vy = c.y - a.y;
|
35325 | var vz = c.z - a.z;
|
35326 | var crossx = uy * vz - uz * vy;
|
35327 | var crossy = uz * vx - ux * vz;
|
35328 | var crossz = ux * vy - uy * vx;
|
35329 | var absSq = crossx * crossx + crossy * crossy + crossz * crossz;
|
35330 | var area3D = Math.sqrt(absSq) / 2;
|
35331 | return area3D
|
35332 | };
|
35333 | Triangle$1.centroid = function centroid (a, b, c) {
|
35334 | var x = (a.x + b.x + c.x) / 3;
|
35335 | var y = (a.y + b.y + c.y) / 3;
|
35336 | return new Coordinate(x, y)
|
35337 | };
|
35338 | Triangle$1.inCentre = function inCentre (a, b, c) {
|
35339 | var len0 = b.distance(c);
|
35340 | var len1 = a.distance(c);
|
35341 | var len2 = a.distance(b);
|
35342 | var circum = len0 + len1 + len2;
|
35343 | var inCentreX = (len0 * a.x + len1 * b.x + len2 * c.x) / circum;
|
35344 | var inCentreY = (len0 * a.y + len1 * b.y + len2 * c.y) / circum;
|
35345 | return new Coordinate(inCentreX, inCentreY)
|
35346 | };
|
35347 |
|
35348 | var OffsetCurveSetBuilder = function OffsetCurveSetBuilder () {
|
35349 | this._inputGeom = null;
|
35350 | this._distance = null;
|
35351 | this._curveBuilder = null;
|
35352 | this._curveList = new ArrayList();
|
35353 | var inputGeom = arguments[0];
|
35354 | var distance = arguments[1];
|
35355 | var curveBuilder = arguments[2];
|
35356 | this._inputGeom = inputGeom;
|
35357 | this._distance = distance;
|
35358 | this._curveBuilder = curveBuilder;
|
35359 | };
|
35360 | OffsetCurveSetBuilder.prototype.addPoint = function addPoint (p) {
|
35361 | if (this._distance <= 0.0) { return null }
|
35362 | var coord = p.getCoordinates();
|
35363 | var curve = this._curveBuilder.getLineCurve(coord, this._distance);
|
35364 | this.addCurve(curve, Location.EXTERIOR, Location.INTERIOR);
|
35365 | };
|
35366 | OffsetCurveSetBuilder.prototype.addPolygon = function addPolygon (p) {
|
35367 | var this$1 = this;
|
35368 |
|
35369 | var offsetDistance = this._distance;
|
35370 | var offsetSide = Position.LEFT;
|
35371 | if (this._distance < 0.0) {
|
35372 | offsetDistance = -this._distance;
|
35373 | offsetSide = Position.RIGHT;
|
35374 | }
|
35375 | var shell = p.getExteriorRing();
|
35376 | var shellCoord = CoordinateArrays.removeRepeatedPoints(shell.getCoordinates());
|
35377 | if (this._distance < 0.0 && this.isErodedCompletely(shell, this._distance)) { return null }
|
35378 | if (this._distance <= 0.0 && shellCoord.length < 3) { return null }
|
35379 | this.addPolygonRing(shellCoord, offsetDistance, offsetSide, Location.EXTERIOR, Location.INTERIOR);
|
35380 | for (var i = 0; i < p.getNumInteriorRing(); i++) {
|
35381 | var hole = p.getInteriorRingN(i);
|
35382 | var holeCoord = CoordinateArrays.removeRepeatedPoints(hole.getCoordinates());
|
35383 | if (this$1._distance > 0.0 && this$1.isErodedCompletely(hole, -this$1._distance)) { continue }
|
35384 | this$1.addPolygonRing(holeCoord, offsetDistance, Position.opposite(offsetSide), Location.INTERIOR, Location.EXTERIOR);
|
35385 | }
|
35386 | };
|
35387 | OffsetCurveSetBuilder.prototype.isTriangleErodedCompletely = function isTriangleErodedCompletely (triangleCoord, bufferDistance) {
|
35388 | var tri = new Triangle$1(triangleCoord[0], triangleCoord[1], triangleCoord[2]);
|
35389 | var inCentre = tri.inCentre();
|
35390 | var distToCentre = CGAlgorithms.distancePointLine(inCentre, tri.p0, tri.p1);
|
35391 | return distToCentre < Math.abs(bufferDistance)
|
35392 | };
|
35393 | OffsetCurveSetBuilder.prototype.addLineString = function addLineString (line) {
|
35394 | if (this._distance <= 0.0 && !this._curveBuilder.getBufferParameters().isSingleSided()) { return null }
|
35395 | var coord = CoordinateArrays.removeRepeatedPoints(line.getCoordinates());
|
35396 | var curve = this._curveBuilder.getLineCurve(coord, this._distance);
|
35397 | this.addCurve(curve, Location.EXTERIOR, Location.INTERIOR);
|
35398 | };
|
35399 | OffsetCurveSetBuilder.prototype.addCurve = function addCurve (coord, leftLoc, rightLoc) {
|
35400 | if (coord === null || coord.length < 2) { return null }
|
35401 | var e = new NodedSegmentString(coord, new Label(0, Location.BOUNDARY, leftLoc, rightLoc));
|
35402 | this._curveList.add(e);
|
35403 | };
|
35404 | OffsetCurveSetBuilder.prototype.getCurves = function getCurves () {
|
35405 | this.add(this._inputGeom);
|
35406 | return this._curveList
|
35407 | };
|
35408 | OffsetCurveSetBuilder.prototype.addPolygonRing = function addPolygonRing (coord, offsetDistance, side, cwLeftLoc, cwRightLoc) {
|
35409 | if (offsetDistance === 0.0 && coord.length < LinearRing.MINIMUM_VALID_SIZE) { return null }
|
35410 | var leftLoc = cwLeftLoc;
|
35411 | var rightLoc = cwRightLoc;
|
35412 | if (coord.length >= LinearRing.MINIMUM_VALID_SIZE && CGAlgorithms.isCCW(coord)) {
|
35413 | leftLoc = cwRightLoc;
|
35414 | rightLoc = cwLeftLoc;
|
35415 | side = Position.opposite(side);
|
35416 | }
|
35417 | var curve = this._curveBuilder.getRingCurve(coord, side, offsetDistance);
|
35418 | this.addCurve(curve, leftLoc, rightLoc);
|
35419 | };
|
35420 | OffsetCurveSetBuilder.prototype.add = function add (g) {
|
35421 | if (g.isEmpty()) { return null }
|
35422 | if (g instanceof Polygon) { this.addPolygon(g); }
|
35423 | else if (g instanceof LineString$1) { this.addLineString(g); }
|
35424 | else if (g instanceof Point) { this.addPoint(g); }
|
35425 | else if (g instanceof MultiPoint) { this.addCollection(g); }
|
35426 | else if (g instanceof MultiLineString) { this.addCollection(g); }
|
35427 | else if (g instanceof MultiPolygon) { this.addCollection(g); }
|
35428 | else if (g instanceof GeometryCollection) { this.addCollection(g); }
|
35429 |
|
35430 | };
|
35431 | OffsetCurveSetBuilder.prototype.isErodedCompletely = function isErodedCompletely (ring, bufferDistance) {
|
35432 | var ringCoord = ring.getCoordinates();
|
35433 |
|
35434 | if (ringCoord.length < 4) { return bufferDistance < 0 }
|
35435 | if (ringCoord.length === 4) { return this.isTriangleErodedCompletely(ringCoord, bufferDistance) }
|
35436 | var env = ring.getEnvelopeInternal();
|
35437 | var envMinDimension = Math.min(env.getHeight(), env.getWidth());
|
35438 | if (bufferDistance < 0.0 && 2 * Math.abs(bufferDistance) > envMinDimension) { return true }
|
35439 | return false
|
35440 | };
|
35441 | OffsetCurveSetBuilder.prototype.addCollection = function addCollection (gc) {
|
35442 | var this$1 = this;
|
35443 |
|
35444 | for (var i = 0; i < gc.getNumGeometries(); i++) {
|
35445 | var g = gc.getGeometryN(i);
|
35446 | this$1.add(g);
|
35447 | }
|
35448 | };
|
35449 | OffsetCurveSetBuilder.prototype.interfaces_ = function interfaces_ () {
|
35450 | return []
|
35451 | };
|
35452 | OffsetCurveSetBuilder.prototype.getClass = function getClass () {
|
35453 | return OffsetCurveSetBuilder
|
35454 | };
|
35455 |
|
35456 | var PointOnGeometryLocator = function PointOnGeometryLocator () {};
|
35457 |
|
35458 | PointOnGeometryLocator.prototype.locate = function locate (p) {};
|
35459 | PointOnGeometryLocator.prototype.interfaces_ = function interfaces_ () {
|
35460 | return []
|
35461 | };
|
35462 | PointOnGeometryLocator.prototype.getClass = function getClass () {
|
35463 | return PointOnGeometryLocator
|
35464 | };
|
35465 |
|
35466 | var GeometryCollectionIterator = function GeometryCollectionIterator () {
|
35467 | this._parent = null;
|
35468 | this._atStart = null;
|
35469 | this._max = null;
|
35470 | this._index = null;
|
35471 | this._subcollectionIterator = null;
|
35472 | var parent = arguments[0];
|
35473 | this._parent = parent;
|
35474 | this._atStart = true;
|
35475 | this._index = 0;
|
35476 | this._max = parent.getNumGeometries();
|
35477 | };
|
35478 | GeometryCollectionIterator.prototype.next = function next () {
|
35479 | if (this._atStart) {
|
35480 | this._atStart = false;
|
35481 | if (GeometryCollectionIterator.isAtomic(this._parent)) { this._index++; }
|
35482 | return this._parent
|
35483 | }
|
35484 | if (this._subcollectionIterator !== null) {
|
35485 | if (this._subcollectionIterator.hasNext()) {
|
35486 | return this._subcollectionIterator.next()
|
35487 | } else {
|
35488 | this._subcollectionIterator = null;
|
35489 | }
|
35490 | }
|
35491 | if (this._index >= this._max) {
|
35492 | throw new NoSuchElementException()
|
35493 | }
|
35494 | var obj = this._parent.getGeometryN(this._index++);
|
35495 | if (obj instanceof GeometryCollection) {
|
35496 | this._subcollectionIterator = new GeometryCollectionIterator(obj);
|
35497 | return this._subcollectionIterator.next()
|
35498 | }
|
35499 | return obj
|
35500 | };
|
35501 | GeometryCollectionIterator.prototype.remove = function remove () {
|
35502 | throw new Error(this.getClass().getName())
|
35503 | };
|
35504 | GeometryCollectionIterator.prototype.hasNext = function hasNext () {
|
35505 | if (this._atStart) {
|
35506 | return true
|
35507 | }
|
35508 | if (this._subcollectionIterator !== null) {
|
35509 | if (this._subcollectionIterator.hasNext()) {
|
35510 | return true
|
35511 | }
|
35512 | this._subcollectionIterator = null;
|
35513 | }
|
35514 | if (this._index >= this._max) {
|
35515 | return false
|
35516 | }
|
35517 | return true
|
35518 | };
|
35519 | GeometryCollectionIterator.prototype.interfaces_ = function interfaces_ () {
|
35520 | return [Iterator]
|
35521 | };
|
35522 | GeometryCollectionIterator.prototype.getClass = function getClass () {
|
35523 | return GeometryCollectionIterator
|
35524 | };
|
35525 | GeometryCollectionIterator.isAtomic = function isAtomic (geom) {
|
35526 | return !(geom instanceof GeometryCollection)
|
35527 | };
|
35528 |
|
35529 | var SimplePointInAreaLocator = function SimplePointInAreaLocator () {
|
35530 | this._geom = null;
|
35531 | var geom = arguments[0];
|
35532 | this._geom = geom;
|
35533 | };
|
35534 | SimplePointInAreaLocator.prototype.locate = function locate (p) {
|
35535 | return SimplePointInAreaLocator.locate(p, this._geom)
|
35536 | };
|
35537 | SimplePointInAreaLocator.prototype.interfaces_ = function interfaces_ () {
|
35538 | return [PointOnGeometryLocator]
|
35539 | };
|
35540 | SimplePointInAreaLocator.prototype.getClass = function getClass () {
|
35541 | return SimplePointInAreaLocator
|
35542 | };
|
35543 | SimplePointInAreaLocator.isPointInRing = function isPointInRing (p, ring) {
|
35544 | if (!ring.getEnvelopeInternal().intersects(p)) { return false }
|
35545 | return CGAlgorithms.isPointInRing(p, ring.getCoordinates())
|
35546 | };
|
35547 | SimplePointInAreaLocator.containsPointInPolygon = function containsPointInPolygon (p, poly) {
|
35548 | if (poly.isEmpty()) { return false }
|
35549 | var shell = poly.getExteriorRing();
|
35550 | if (!SimplePointInAreaLocator.isPointInRing(p, shell)) { return false }
|
35551 | for (var i = 0; i < poly.getNumInteriorRing(); i++) {
|
35552 | var hole = poly.getInteriorRingN(i);
|
35553 | if (SimplePointInAreaLocator.isPointInRing(p, hole)) { return false }
|
35554 | }
|
35555 | return true
|
35556 | };
|
35557 | SimplePointInAreaLocator.containsPoint = function containsPoint (p, geom) {
|
35558 | if (geom instanceof Polygon) {
|
35559 | return SimplePointInAreaLocator.containsPointInPolygon(p, geom)
|
35560 | } else if (geom instanceof GeometryCollection) {
|
35561 | var geomi = new GeometryCollectionIterator(geom);
|
35562 | while (geomi.hasNext()) {
|
35563 | var g2 = geomi.next();
|
35564 | if (g2 !== geom) { if (SimplePointInAreaLocator.containsPoint(p, g2)) { return true } }
|
35565 | }
|
35566 | }
|
35567 | return false
|
35568 | };
|
35569 | SimplePointInAreaLocator.locate = function locate (p, geom) {
|
35570 | if (geom.isEmpty()) { return Location.EXTERIOR }
|
35571 | if (SimplePointInAreaLocator.containsPoint(p, geom)) { return Location.INTERIOR }
|
35572 | return Location.EXTERIOR
|
35573 | };
|
35574 |
|
35575 | var EdgeEndStar = function EdgeEndStar () {
|
35576 | this._edgeMap = new TreeMap();
|
35577 | this._edgeList = null;
|
35578 | this._ptInAreaLocation = [Location.NONE, Location.NONE];
|
35579 | };
|
35580 | EdgeEndStar.prototype.getNextCW = function getNextCW (ee) {
|
35581 | this.getEdges();
|
35582 | var i = this._edgeList.indexOf(ee);
|
35583 | var iNextCW = i - 1;
|
35584 | if (i === 0) { iNextCW = this._edgeList.size() - 1; }
|
35585 | return this._edgeList.get(iNextCW)
|
35586 | };
|
35587 | EdgeEndStar.prototype.propagateSideLabels = function propagateSideLabels (geomIndex) {
|
35588 | var startLoc = Location.NONE;
|
35589 | for (var it = this.iterator(); it.hasNext();) {
|
35590 | var e = it.next();
|
35591 | var label = e.getLabel();
|
35592 | if (label.isArea(geomIndex) && label.getLocation(geomIndex, Position.LEFT) !== Location.NONE) { startLoc = label.getLocation(geomIndex, Position.LEFT); }
|
35593 | }
|
35594 | if (startLoc === Location.NONE) { return null }
|
35595 | var currLoc = startLoc;
|
35596 | for (var it$1 = this.iterator(); it$1.hasNext();) {
|
35597 | var e$1 = it$1.next();
|
35598 | var label$1 = e$1.getLabel();
|
35599 | if (label$1.getLocation(geomIndex, Position.ON) === Location.NONE) { label$1.setLocation(geomIndex, Position.ON, currLoc); }
|
35600 | if (label$1.isArea(geomIndex)) {
|
35601 | var leftLoc = label$1.getLocation(geomIndex, Position.LEFT);
|
35602 | var rightLoc = label$1.getLocation(geomIndex, Position.RIGHT);
|
35603 | if (rightLoc !== Location.NONE) {
|
35604 | if (rightLoc !== currLoc) { throw new TopologyException('side location conflict', e$1.getCoordinate()) }
|
35605 | if (leftLoc === Location.NONE) {
|
35606 | Assert.shouldNeverReachHere('found single null side (at ' + e$1.getCoordinate() + ')');
|
35607 | }
|
35608 | currLoc = leftLoc;
|
35609 | } else {
|
35610 | Assert.isTrue(label$1.getLocation(geomIndex, Position.LEFT) === Location.NONE, 'found single null side');
|
35611 | label$1.setLocation(geomIndex, Position.RIGHT, currLoc);
|
35612 | label$1.setLocation(geomIndex, Position.LEFT, currLoc);
|
35613 | }
|
35614 | }
|
35615 | }
|
35616 | };
|
35617 | EdgeEndStar.prototype.getCoordinate = function getCoordinate () {
|
35618 | var it = this.iterator();
|
35619 | if (!it.hasNext()) { return null }
|
35620 | var e = it.next();
|
35621 | return e.getCoordinate()
|
35622 | };
|
35623 | EdgeEndStar.prototype.print = function print (out) {
|
35624 | System.out.println('EdgeEndStar: ' + this.getCoordinate());
|
35625 | for (var it = this.iterator(); it.hasNext();) {
|
35626 | var e = it.next();
|
35627 | e.print(out);
|
35628 | }
|
35629 | };
|
35630 | EdgeEndStar.prototype.isAreaLabelsConsistent = function isAreaLabelsConsistent (geomGraph) {
|
35631 | this.computeEdgeEndLabels(geomGraph.getBoundaryNodeRule());
|
35632 | return this.checkAreaLabelsConsistent(0)
|
35633 | };
|
35634 | EdgeEndStar.prototype.checkAreaLabelsConsistent = function checkAreaLabelsConsistent (geomIndex) {
|
35635 | var edges = this.getEdges();
|
35636 | if (edges.size() <= 0) { return true }
|
35637 | var lastEdgeIndex = edges.size() - 1;
|
35638 | var startLabel = edges.get(lastEdgeIndex).getLabel();
|
35639 | var startLoc = startLabel.getLocation(geomIndex, Position.LEFT);
|
35640 | Assert.isTrue(startLoc !== Location.NONE, 'Found unlabelled area edge');
|
35641 | var currLoc = startLoc;
|
35642 | for (var it = this.iterator(); it.hasNext();) {
|
35643 | var e = it.next();
|
35644 | var label = e.getLabel();
|
35645 | Assert.isTrue(label.isArea(geomIndex), 'Found non-area edge');
|
35646 | var leftLoc = label.getLocation(geomIndex, Position.LEFT);
|
35647 | var rightLoc = label.getLocation(geomIndex, Position.RIGHT);
|
35648 | if (leftLoc === rightLoc) {
|
35649 | return false
|
35650 | }
|
35651 | if (rightLoc !== currLoc) {
|
35652 | return false
|
35653 | }
|
35654 | currLoc = leftLoc;
|
35655 | }
|
35656 | return true
|
35657 | };
|
35658 | EdgeEndStar.prototype.findIndex = function findIndex (eSearch) {
|
35659 | var this$1 = this;
|
35660 |
|
35661 | this.iterator();
|
35662 | for (var i = 0; i < this._edgeList.size(); i++) {
|
35663 | var e = this$1._edgeList.get(i);
|
35664 | if (e === eSearch) { return i }
|
35665 | }
|
35666 | return -1
|
35667 | };
|
35668 | EdgeEndStar.prototype.iterator = function iterator () {
|
35669 | return this.getEdges().iterator()
|
35670 | };
|
35671 | EdgeEndStar.prototype.getEdges = function getEdges () {
|
35672 | if (this._edgeList === null) {
|
35673 | this._edgeList = new ArrayList(this._edgeMap.values());
|
35674 | }
|
35675 | return this._edgeList
|
35676 | };
|
35677 | EdgeEndStar.prototype.getLocation = function getLocation (geomIndex, p, geom) {
|
35678 | if (this._ptInAreaLocation[geomIndex] === Location.NONE) {
|
35679 | this._ptInAreaLocation[geomIndex] = SimplePointInAreaLocator.locate(p, geom[geomIndex].getGeometry());
|
35680 | }
|
35681 | return this._ptInAreaLocation[geomIndex]
|
35682 | };
|
35683 | EdgeEndStar.prototype.toString = function toString () {
|
35684 | var buf = new StringBuffer();
|
35685 | buf.append('EdgeEndStar: ' + this.getCoordinate());
|
35686 | buf.append('\n');
|
35687 | for (var it = this.iterator(); it.hasNext();) {
|
35688 | var e = it.next();
|
35689 | buf.append(e);
|
35690 | buf.append('\n');
|
35691 | }
|
35692 | return buf.toString()
|
35693 | };
|
35694 | EdgeEndStar.prototype.computeEdgeEndLabels = function computeEdgeEndLabels (boundaryNodeRule) {
|
35695 | for (var it = this.iterator(); it.hasNext();) {
|
35696 | var ee = it.next();
|
35697 | ee.computeLabel(boundaryNodeRule);
|
35698 | }
|
35699 | };
|
35700 | EdgeEndStar.prototype.computeLabelling = function computeLabelling (geomGraph) {
|
35701 | var this$1 = this;
|
35702 |
|
35703 | this.computeEdgeEndLabels(geomGraph[0].getBoundaryNodeRule());
|
35704 | this.propagateSideLabels(0);
|
35705 | this.propagateSideLabels(1);
|
35706 | var hasDimensionalCollapseEdge = [false, false];
|
35707 | for (var it = this.iterator(); it.hasNext();) {
|
35708 | var e = it.next();
|
35709 | var label = e.getLabel();
|
35710 | for (var geomi = 0; geomi < 2; geomi++) {
|
35711 | if (label.isLine(geomi) && label.getLocation(geomi) === Location.BOUNDARY) { hasDimensionalCollapseEdge[geomi] = true; }
|
35712 | }
|
35713 | }
|
35714 | for (var it$1 = this.iterator(); it$1.hasNext();) {
|
35715 | var e$1 = it$1.next();
|
35716 | var label$1 = e$1.getLabel();
|
35717 | for (var geomi$1 = 0; geomi$1 < 2; geomi$1++) {
|
35718 | if (label$1.isAnyNull(geomi$1)) {
|
35719 | var loc = Location.NONE;
|
35720 | if (hasDimensionalCollapseEdge[geomi$1]) {
|
35721 | loc = Location.EXTERIOR;
|
35722 | } else {
|
35723 | var p = e$1.getCoordinate();
|
35724 | loc = this$1.getLocation(geomi$1, p, geomGraph);
|
35725 | }
|
35726 | label$1.setAllLocationsIfNull(geomi$1, loc);
|
35727 | }
|
35728 | }
|
35729 | }
|
35730 | };
|
35731 | EdgeEndStar.prototype.getDegree = function getDegree () {
|
35732 | return this._edgeMap.size()
|
35733 | };
|
35734 | EdgeEndStar.prototype.insertEdgeEnd = function insertEdgeEnd (e, obj) {
|
35735 | this._edgeMap.put(e, obj);
|
35736 | this._edgeList = null;
|
35737 | };
|
35738 | EdgeEndStar.prototype.interfaces_ = function interfaces_ () {
|
35739 | return []
|
35740 | };
|
35741 | EdgeEndStar.prototype.getClass = function getClass () {
|
35742 | return EdgeEndStar
|
35743 | };
|
35744 |
|
35745 | var DirectedEdgeStar = (function (EdgeEndStar$$1) {
|
35746 | function DirectedEdgeStar () {
|
35747 | EdgeEndStar$$1.call(this);
|
35748 | this._resultAreaEdgeList = null;
|
35749 | this._label = null;
|
35750 | this._SCANNING_FOR_INCOMING = 1;
|
35751 | this._LINKING_TO_OUTGOING = 2;
|
35752 | }
|
35753 |
|
35754 | if ( EdgeEndStar$$1 ) DirectedEdgeStar.__proto__ = EdgeEndStar$$1;
|
35755 | DirectedEdgeStar.prototype = Object.create( EdgeEndStar$$1 && EdgeEndStar$$1.prototype );
|
35756 | DirectedEdgeStar.prototype.constructor = DirectedEdgeStar;
|
35757 | DirectedEdgeStar.prototype.linkResultDirectedEdges = function linkResultDirectedEdges () {
|
35758 | var this$1 = this;
|
35759 |
|
35760 | this.getResultAreaEdges();
|
35761 | var firstOut = null;
|
35762 | var incoming = null;
|
35763 | var state = this._SCANNING_FOR_INCOMING;
|
35764 | for (var i = 0; i < this._resultAreaEdgeList.size(); i++) {
|
35765 | var nextOut = this$1._resultAreaEdgeList.get(i);
|
35766 | var nextIn = nextOut.getSym();
|
35767 | if (!nextOut.getLabel().isArea()) { continue }
|
35768 | if (firstOut === null && nextOut.isInResult()) { firstOut = nextOut; }
|
35769 | switch (state) {
|
35770 | case this$1._SCANNING_FOR_INCOMING:
|
35771 | if (!nextIn.isInResult()) { continue }
|
35772 | incoming = nextIn;
|
35773 | state = this$1._LINKING_TO_OUTGOING;
|
35774 | break
|
35775 | case this$1._LINKING_TO_OUTGOING:
|
35776 | if (!nextOut.isInResult()) { continue }
|
35777 | incoming.setNext(nextOut);
|
35778 | state = this$1._SCANNING_FOR_INCOMING;
|
35779 | break
|
35780 | default:
|
35781 | }
|
35782 | }
|
35783 | if (state === this._LINKING_TO_OUTGOING) {
|
35784 | if (firstOut === null) { throw new TopologyException('no outgoing dirEdge found', this.getCoordinate()) }
|
35785 | Assert.isTrue(firstOut.isInResult(), 'unable to link last incoming dirEdge');
|
35786 | incoming.setNext(firstOut);
|
35787 | }
|
35788 | };
|
35789 | DirectedEdgeStar.prototype.insert = function insert (ee) {
|
35790 | var de = ee;
|
35791 | this.insertEdgeEnd(de, de);
|
35792 | };
|
35793 | DirectedEdgeStar.prototype.getRightmostEdge = function getRightmostEdge () {
|
35794 | var edges = this.getEdges();
|
35795 | var size = edges.size();
|
35796 | if (size < 1) { return null }
|
35797 | var de0 = edges.get(0);
|
35798 | if (size === 1) { return de0 }
|
35799 | var deLast = edges.get(size - 1);
|
35800 | var quad0 = de0.getQuadrant();
|
35801 | var quad1 = deLast.getQuadrant();
|
35802 | if (Quadrant.isNorthern(quad0) && Quadrant.isNorthern(quad1)) { return de0; } else if (!Quadrant.isNorthern(quad0) && !Quadrant.isNorthern(quad1)) { return deLast; } else {
|
35803 |
|
35804 | if (de0.getDy() !== 0) { return de0; } else if (deLast.getDy() !== 0) { return deLast }
|
35805 | }
|
35806 | Assert.shouldNeverReachHere('found two horizontal edges incident on node');
|
35807 | return null
|
35808 | };
|
35809 | DirectedEdgeStar.prototype.print = function print (out) {
|
35810 | System.out.println('DirectedEdgeStar: ' + this.getCoordinate());
|
35811 | for (var it = this.iterator(); it.hasNext();) {
|
35812 | var de = it.next();
|
35813 | out.print('out ');
|
35814 | de.print(out);
|
35815 | out.println();
|
35816 | out.print('in ');
|
35817 | de.getSym().print(out);
|
35818 | out.println();
|
35819 | }
|
35820 | };
|
35821 | DirectedEdgeStar.prototype.getResultAreaEdges = function getResultAreaEdges () {
|
35822 | var this$1 = this;
|
35823 |
|
35824 | if (this._resultAreaEdgeList !== null) { return this._resultAreaEdgeList }
|
35825 | this._resultAreaEdgeList = new ArrayList();
|
35826 | for (var it = this.iterator(); it.hasNext();) {
|
35827 | var de = it.next();
|
35828 | if (de.isInResult() || de.getSym().isInResult()) { this$1._resultAreaEdgeList.add(de); }
|
35829 | }
|
35830 | return this._resultAreaEdgeList
|
35831 | };
|
35832 | DirectedEdgeStar.prototype.updateLabelling = function updateLabelling (nodeLabel) {
|
35833 | for (var it = this.iterator(); it.hasNext();) {
|
35834 | var de = it.next();
|
35835 | var label = de.getLabel();
|
35836 | label.setAllLocationsIfNull(0, nodeLabel.getLocation(0));
|
35837 | label.setAllLocationsIfNull(1, nodeLabel.getLocation(1));
|
35838 | }
|
35839 | };
|
35840 | DirectedEdgeStar.prototype.linkAllDirectedEdges = function linkAllDirectedEdges () {
|
35841 | var this$1 = this;
|
35842 |
|
35843 | this.getEdges();
|
35844 | var prevOut = null;
|
35845 | var firstIn = null;
|
35846 | for (var i = this._edgeList.size() - 1; i >= 0; i--) {
|
35847 | var nextOut = this$1._edgeList.get(i);
|
35848 | var nextIn = nextOut.getSym();
|
35849 | if (firstIn === null) { firstIn = nextIn; }
|
35850 | if (prevOut !== null) { nextIn.setNext(prevOut); }
|
35851 | prevOut = nextOut;
|
35852 | }
|
35853 | firstIn.setNext(prevOut);
|
35854 | };
|
35855 | DirectedEdgeStar.prototype.computeDepths = function computeDepths () {
|
35856 | var this$1 = this;
|
35857 |
|
35858 | if (arguments.length === 1) {
|
35859 | var de = arguments[0];
|
35860 | var edgeIndex = this.findIndex(de);
|
35861 |
|
35862 | var startDepth = de.getDepth(Position.LEFT);
|
35863 | var targetLastDepth = de.getDepth(Position.RIGHT);
|
35864 | var nextDepth = this.computeDepths(edgeIndex + 1, this._edgeList.size(), startDepth);
|
35865 | var lastDepth = this.computeDepths(0, edgeIndex, nextDepth);
|
35866 | if (lastDepth !== targetLastDepth) { throw new TopologyException('depth mismatch at ' + de.getCoordinate()) }
|
35867 | } else if (arguments.length === 3) {
|
35868 | var startIndex = arguments[0];
|
35869 | var endIndex = arguments[1];
|
35870 | var startDepth$1 = arguments[2];
|
35871 | var currDepth = startDepth$1;
|
35872 | for (var i = startIndex; i < endIndex; i++) {
|
35873 | var nextDe = this$1._edgeList.get(i);
|
35874 |
|
35875 | nextDe.setEdgeDepths(Position.RIGHT, currDepth);
|
35876 | currDepth = nextDe.getDepth(Position.LEFT);
|
35877 | }
|
35878 | return currDepth
|
35879 | }
|
35880 | };
|
35881 | DirectedEdgeStar.prototype.mergeSymLabels = function mergeSymLabels () {
|
35882 | for (var it = this.iterator(); it.hasNext();) {
|
35883 | var de = it.next();
|
35884 | var label = de.getLabel();
|
35885 | label.merge(de.getSym().getLabel());
|
35886 | }
|
35887 | };
|
35888 | DirectedEdgeStar.prototype.linkMinimalDirectedEdges = function linkMinimalDirectedEdges (er) {
|
35889 | var this$1 = this;
|
35890 |
|
35891 | var firstOut = null;
|
35892 | var incoming = null;
|
35893 | var state = this._SCANNING_FOR_INCOMING;
|
35894 | for (var i = this._resultAreaEdgeList.size() - 1; i >= 0; i--) {
|
35895 | var nextOut = this$1._resultAreaEdgeList.get(i);
|
35896 | var nextIn = nextOut.getSym();
|
35897 | if (firstOut === null && nextOut.getEdgeRing() === er) { firstOut = nextOut; }
|
35898 | switch (state) {
|
35899 | case this$1._SCANNING_FOR_INCOMING:
|
35900 | if (nextIn.getEdgeRing() !== er) { continue }
|
35901 | incoming = nextIn;
|
35902 | state = this$1._LINKING_TO_OUTGOING;
|
35903 | break
|
35904 | case this$1._LINKING_TO_OUTGOING:
|
35905 | if (nextOut.getEdgeRing() !== er) { continue }
|
35906 | incoming.setNextMin(nextOut);
|
35907 | state = this$1._SCANNING_FOR_INCOMING;
|
35908 | break
|
35909 | default:
|
35910 | }
|
35911 | }
|
35912 | if (state === this._LINKING_TO_OUTGOING) {
|
35913 | Assert.isTrue(firstOut !== null, 'found null for first outgoing dirEdge');
|
35914 | Assert.isTrue(firstOut.getEdgeRing() === er, 'unable to link last incoming dirEdge');
|
35915 | incoming.setNextMin(firstOut);
|
35916 | }
|
35917 | };
|
35918 | DirectedEdgeStar.prototype.getOutgoingDegree = function getOutgoingDegree () {
|
35919 | if (arguments.length === 0) {
|
35920 | var degree = 0;
|
35921 | for (var it = this.iterator(); it.hasNext();) {
|
35922 | var de = it.next();
|
35923 | if (de.isInResult()) { degree++; }
|
35924 | }
|
35925 | return degree
|
35926 | } else if (arguments.length === 1) {
|
35927 | var er = arguments[0];
|
35928 | var degree$1 = 0;
|
35929 | for (var it$1 = this.iterator(); it$1.hasNext();) {
|
35930 | var de$1 = it$1.next();
|
35931 | if (de$1.getEdgeRing() === er) { degree$1++; }
|
35932 | }
|
35933 | return degree$1
|
35934 | }
|
35935 | };
|
35936 | DirectedEdgeStar.prototype.getLabel = function getLabel () {
|
35937 | return this._label
|
35938 | };
|
35939 | DirectedEdgeStar.prototype.findCoveredLineEdges = function findCoveredLineEdges () {
|
35940 | var startLoc = Location.NONE;
|
35941 | for (var it = this.iterator(); it.hasNext();) {
|
35942 | var nextOut = it.next();
|
35943 | var nextIn = nextOut.getSym();
|
35944 | if (!nextOut.isLineEdge()) {
|
35945 | if (nextOut.isInResult()) {
|
35946 | startLoc = Location.INTERIOR;
|
35947 | break
|
35948 | }
|
35949 | if (nextIn.isInResult()) {
|
35950 | startLoc = Location.EXTERIOR;
|
35951 | break
|
35952 | }
|
35953 | }
|
35954 | }
|
35955 | if (startLoc === Location.NONE) { return null }
|
35956 | var currLoc = startLoc;
|
35957 | for (var it$1 = this.iterator(); it$1.hasNext();) {
|
35958 | var nextOut$1 = it$1.next();
|
35959 | var nextIn$1 = nextOut$1.getSym();
|
35960 | if (nextOut$1.isLineEdge()) {
|
35961 | nextOut$1.getEdge().setCovered(currLoc === Location.INTERIOR);
|
35962 | } else {
|
35963 | if (nextOut$1.isInResult()) { currLoc = Location.EXTERIOR; }
|
35964 | if (nextIn$1.isInResult()) { currLoc = Location.INTERIOR; }
|
35965 | }
|
35966 | }
|
35967 | };
|
35968 | DirectedEdgeStar.prototype.computeLabelling = function computeLabelling (geom) {
|
35969 | var this$1 = this;
|
35970 |
|
35971 | EdgeEndStar$$1.prototype.computeLabelling.call(this, geom);
|
35972 | this._label = new Label(Location.NONE);
|
35973 | for (var it = this.iterator(); it.hasNext();) {
|
35974 | var ee = it.next();
|
35975 | var e = ee.getEdge();
|
35976 | var eLabel = e.getLabel();
|
35977 | for (var i = 0; i < 2; i++) {
|
35978 | var eLoc = eLabel.getLocation(i);
|
35979 | if (eLoc === Location.INTERIOR || eLoc === Location.BOUNDARY) { this$1._label.setLocation(i, Location.INTERIOR); }
|
35980 | }
|
35981 | }
|
35982 | };
|
35983 | DirectedEdgeStar.prototype.interfaces_ = function interfaces_ () {
|
35984 | return []
|
35985 | };
|
35986 | DirectedEdgeStar.prototype.getClass = function getClass () {
|
35987 | return DirectedEdgeStar
|
35988 | };
|
35989 |
|
35990 | return DirectedEdgeStar;
|
35991 | }(EdgeEndStar));
|
35992 |
|
35993 | var OverlayNodeFactory = (function (NodeFactory$$1) {
|
35994 | function OverlayNodeFactory () {
|
35995 | NodeFactory$$1.apply(this, arguments);
|
35996 | }
|
35997 |
|
35998 | if ( NodeFactory$$1 ) OverlayNodeFactory.__proto__ = NodeFactory$$1;
|
35999 | OverlayNodeFactory.prototype = Object.create( NodeFactory$$1 && NodeFactory$$1.prototype );
|
36000 | OverlayNodeFactory.prototype.constructor = OverlayNodeFactory;
|
36001 |
|
36002 | OverlayNodeFactory.prototype.createNode = function createNode (coord) {
|
36003 | return new Node$2(coord, new DirectedEdgeStar())
|
36004 | };
|
36005 | OverlayNodeFactory.prototype.interfaces_ = function interfaces_ () {
|
36006 | return []
|
36007 | };
|
36008 | OverlayNodeFactory.prototype.getClass = function getClass () {
|
36009 | return OverlayNodeFactory
|
36010 | };
|
36011 |
|
36012 | return OverlayNodeFactory;
|
36013 | }(NodeFactory));
|
36014 |
|
36015 | var OrientedCoordinateArray = function OrientedCoordinateArray () {
|
36016 | this._pts = null;
|
36017 | this._orientation = null;
|
36018 | var pts = arguments[0];
|
36019 | this._pts = pts;
|
36020 | this._orientation = OrientedCoordinateArray.orientation(pts);
|
36021 | };
|
36022 | OrientedCoordinateArray.prototype.compareTo = function compareTo (o1) {
|
36023 | var oca = o1;
|
36024 | var comp = OrientedCoordinateArray.compareOriented(this._pts, this._orientation, oca._pts, oca._orientation);
|
36025 | return comp
|
36026 | };
|
36027 | OrientedCoordinateArray.prototype.interfaces_ = function interfaces_ () {
|
36028 | return [Comparable]
|
36029 | };
|
36030 | OrientedCoordinateArray.prototype.getClass = function getClass () {
|
36031 | return OrientedCoordinateArray
|
36032 | };
|
36033 | OrientedCoordinateArray.orientation = function orientation (pts) {
|
36034 | return CoordinateArrays.increasingDirection(pts) === 1
|
36035 | };
|
36036 | OrientedCoordinateArray.compareOriented = function compareOriented (pts1, orientation1, pts2, orientation2) {
|
36037 | var dir1 = orientation1 ? 1 : -1;
|
36038 | var dir2 = orientation2 ? 1 : -1;
|
36039 | var limit1 = orientation1 ? pts1.length : -1;
|
36040 | var limit2 = orientation2 ? pts2.length : -1;
|
36041 | var i1 = orientation1 ? 0 : pts1.length - 1;
|
36042 | var i2 = orientation2 ? 0 : pts2.length - 1;
|
36043 |
|
36044 | while (true) {
|
36045 | var compPt = pts1[i1].compareTo(pts2[i2]);
|
36046 | if (compPt !== 0) { return compPt }
|
36047 | i1 += dir1;
|
36048 | i2 += dir2;
|
36049 | var done1 = i1 === limit1;
|
36050 | var done2 = i2 === limit2;
|
36051 | if (done1 && !done2) { return -1 }
|
36052 | if (!done1 && done2) { return 1 }
|
36053 | if (done1 && done2) { return 0 }
|
36054 | }
|
36055 | };
|
36056 |
|
36057 | var EdgeList = function EdgeList () {
|
36058 | this._edges = new ArrayList();
|
36059 | this._ocaMap = new TreeMap();
|
36060 | };
|
36061 | EdgeList.prototype.print = function print (out) {
|
36062 | var this$1 = this;
|
36063 |
|
36064 | out.print('MULTILINESTRING ( ');
|
36065 | for (var j = 0; j < this._edges.size(); j++) {
|
36066 | var e = this$1._edges.get(j);
|
36067 | if (j > 0) { out.print(','); }
|
36068 | out.print('(');
|
36069 | var pts = e.getCoordinates();
|
36070 | for (var i = 0; i < pts.length; i++) {
|
36071 | if (i > 0) { out.print(','); }
|
36072 | out.print(pts[i].x + ' ' + pts[i].y);
|
36073 | }
|
36074 | out.println(')');
|
36075 | }
|
36076 | out.print(') ');
|
36077 | };
|
36078 | EdgeList.prototype.addAll = function addAll (edgeColl) {
|
36079 | var this$1 = this;
|
36080 |
|
36081 | for (var i = edgeColl.iterator(); i.hasNext();) {
|
36082 | this$1.add(i.next());
|
36083 | }
|
36084 | };
|
36085 | EdgeList.prototype.findEdgeIndex = function findEdgeIndex (e) {
|
36086 | var this$1 = this;
|
36087 |
|
36088 | for (var i = 0; i < this._edges.size(); i++) {
|
36089 | if (this$1._edges.get(i).equals(e)) { return i }
|
36090 | }
|
36091 | return -1
|
36092 | };
|
36093 | EdgeList.prototype.iterator = function iterator () {
|
36094 | return this._edges.iterator()
|
36095 | };
|
36096 | EdgeList.prototype.getEdges = function getEdges () {
|
36097 | return this._edges
|
36098 | };
|
36099 | EdgeList.prototype.get = function get (i) {
|
36100 | return this._edges.get(i)
|
36101 | };
|
36102 | EdgeList.prototype.findEqualEdge = function findEqualEdge (e) {
|
36103 | var oca = new OrientedCoordinateArray(e.getCoordinates());
|
36104 | var matchEdge = this._ocaMap.get(oca);
|
36105 | return matchEdge
|
36106 | };
|
36107 | EdgeList.prototype.add = function add (e) {
|
36108 | this._edges.add(e);
|
36109 | var oca = new OrientedCoordinateArray(e.getCoordinates());
|
36110 | this._ocaMap.put(oca, e);
|
36111 | };
|
36112 | EdgeList.prototype.interfaces_ = function interfaces_ () {
|
36113 | return []
|
36114 | };
|
36115 | EdgeList.prototype.getClass = function getClass () {
|
36116 | return EdgeList
|
36117 | };
|
36118 |
|
36119 | var SegmentIntersector = function SegmentIntersector () {};
|
36120 |
|
36121 | SegmentIntersector.prototype.processIntersections = function processIntersections (e0, segIndex0, e1, segIndex1) {};
|
36122 | SegmentIntersector.prototype.isDone = function isDone () {};
|
36123 | SegmentIntersector.prototype.interfaces_ = function interfaces_ () {
|
36124 | return []
|
36125 | };
|
36126 | SegmentIntersector.prototype.getClass = function getClass () {
|
36127 | return SegmentIntersector
|
36128 | };
|
36129 |
|
36130 | var IntersectionAdder = function IntersectionAdder () {
|
36131 | this._hasIntersection = false;
|
36132 | this._hasProper = false;
|
36133 | this._hasProperInterior = false;
|
36134 | this._hasInterior = false;
|
36135 | this._properIntersectionPoint = null;
|
36136 | this._li = null;
|
36137 | this._isSelfIntersection = null;
|
36138 | this.numIntersections = 0;
|
36139 | this.numInteriorIntersections = 0;
|
36140 | this.numProperIntersections = 0;
|
36141 | this.numTests = 0;
|
36142 | var li = arguments[0];
|
36143 | this._li = li;
|
36144 | };
|
36145 | IntersectionAdder.prototype.isTrivialIntersection = function isTrivialIntersection (e0, segIndex0, e1, segIndex1) {
|
36146 | if (e0 === e1) {
|
36147 | if (this._li.getIntersectionNum() === 1) {
|
36148 | if (IntersectionAdder.isAdjacentSegments(segIndex0, segIndex1)) { return true }
|
36149 | if (e0.isClosed()) {
|
36150 | var maxSegIndex = e0.size() - 1;
|
36151 | if ((segIndex0 === 0 && segIndex1 === maxSegIndex) ||
|
36152 | (segIndex1 === 0 && segIndex0 === maxSegIndex)) {
|
36153 | return true
|
36154 | }
|
36155 | }
|
36156 | }
|
36157 | }
|
36158 | return false
|
36159 | };
|
36160 | IntersectionAdder.prototype.getProperIntersectionPoint = function getProperIntersectionPoint () {
|
36161 | return this._properIntersectionPoint
|
36162 | };
|
36163 | IntersectionAdder.prototype.hasProperInteriorIntersection = function hasProperInteriorIntersection () {
|
36164 | return this._hasProperInterior
|
36165 | };
|
36166 | IntersectionAdder.prototype.getLineIntersector = function getLineIntersector () {
|
36167 | return this._li
|
36168 | };
|
36169 | IntersectionAdder.prototype.hasProperIntersection = function hasProperIntersection () {
|
36170 | return this._hasProper
|
36171 | };
|
36172 | IntersectionAdder.prototype.processIntersections = function processIntersections (e0, segIndex0, e1, segIndex1) {
|
36173 | if (e0 === e1 && segIndex0 === segIndex1) { return null }
|
36174 | this.numTests++;
|
36175 | var p00 = e0.getCoordinates()[segIndex0];
|
36176 | var p01 = e0.getCoordinates()[segIndex0 + 1];
|
36177 | var p10 = e1.getCoordinates()[segIndex1];
|
36178 | var p11 = e1.getCoordinates()[segIndex1 + 1];
|
36179 | this._li.computeIntersection(p00, p01, p10, p11);
|
36180 | if (this._li.hasIntersection()) {
|
36181 | this.numIntersections++;
|
36182 | if (this._li.isInteriorIntersection()) {
|
36183 | this.numInteriorIntersections++;
|
36184 | this._hasInterior = true;
|
36185 | }
|
36186 | if (!this.isTrivialIntersection(e0, segIndex0, e1, segIndex1)) {
|
36187 | this._hasIntersection = true;
|
36188 | e0.addIntersections(this._li, segIndex0, 0);
|
36189 | e1.addIntersections(this._li, segIndex1, 1);
|
36190 | if (this._li.isProper()) {
|
36191 | this.numProperIntersections++;
|
36192 | this._hasProper = true;
|
36193 | this._hasProperInterior = true;
|
36194 | }
|
36195 | }
|
36196 | }
|
36197 | };
|
36198 | IntersectionAdder.prototype.hasIntersection = function hasIntersection () {
|
36199 | return this._hasIntersection
|
36200 | };
|
36201 | IntersectionAdder.prototype.isDone = function isDone () {
|
36202 | return false
|
36203 | };
|
36204 | IntersectionAdder.prototype.hasInteriorIntersection = function hasInteriorIntersection () {
|
36205 | return this._hasInterior
|
36206 | };
|
36207 | IntersectionAdder.prototype.interfaces_ = function interfaces_ () {
|
36208 | return [SegmentIntersector]
|
36209 | };
|
36210 | IntersectionAdder.prototype.getClass = function getClass () {
|
36211 | return IntersectionAdder
|
36212 | };
|
36213 | IntersectionAdder.isAdjacentSegments = function isAdjacentSegments (i1, i2) {
|
36214 | return Math.abs(i1 - i2) === 1
|
36215 | };
|
36216 |
|
36217 | var EdgeIntersection = function EdgeIntersection () {
|
36218 | this.coord = null;
|
36219 | this.segmentIndex = null;
|
36220 | this.dist = null;
|
36221 | var coord = arguments[0];
|
36222 | var segmentIndex = arguments[1];
|
36223 | var dist = arguments[2];
|
36224 | this.coord = new Coordinate(coord);
|
36225 | this.segmentIndex = segmentIndex;
|
36226 | this.dist = dist;
|
36227 | };
|
36228 | EdgeIntersection.prototype.getSegmentIndex = function getSegmentIndex () {
|
36229 | return this.segmentIndex
|
36230 | };
|
36231 | EdgeIntersection.prototype.getCoordinate = function getCoordinate () {
|
36232 | return this.coord
|
36233 | };
|
36234 | EdgeIntersection.prototype.print = function print (out) {
|
36235 | out.print(this.coord);
|
36236 | out.print(' seg # = ' + this.segmentIndex);
|
36237 | out.println(' dist = ' + this.dist);
|
36238 | };
|
36239 | EdgeIntersection.prototype.compareTo = function compareTo (obj) {
|
36240 | var other = obj;
|
36241 | return this.compare(other.segmentIndex, other.dist)
|
36242 | };
|
36243 | EdgeIntersection.prototype.isEndPoint = function isEndPoint (maxSegmentIndex) {
|
36244 | if (this.segmentIndex === 0 && this.dist === 0.0) { return true }
|
36245 | if (this.segmentIndex === maxSegmentIndex) { return true }
|
36246 | return false
|
36247 | };
|
36248 | EdgeIntersection.prototype.toString = function toString () {
|
36249 | return this.coord + ' seg # = ' + this.segmentIndex + ' dist = ' + this.dist
|
36250 | };
|
36251 | EdgeIntersection.prototype.getDistance = function getDistance () {
|
36252 | return this.dist
|
36253 | };
|
36254 | EdgeIntersection.prototype.compare = function compare (segmentIndex, dist) {
|
36255 | if (this.segmentIndex < segmentIndex) { return -1 }
|
36256 | if (this.segmentIndex > segmentIndex) { return 1 }
|
36257 | if (this.dist < dist) { return -1 }
|
36258 | if (this.dist > dist) { return 1 }
|
36259 | return 0
|
36260 | };
|
36261 | EdgeIntersection.prototype.interfaces_ = function interfaces_ () {
|
36262 | return [Comparable]
|
36263 | };
|
36264 | EdgeIntersection.prototype.getClass = function getClass () {
|
36265 | return EdgeIntersection
|
36266 | };
|
36267 |
|
36268 | var EdgeIntersectionList = function EdgeIntersectionList () {
|
36269 | this._nodeMap = new TreeMap();
|
36270 | this.edge = null;
|
36271 | var edge = arguments[0];
|
36272 | this.edge = edge;
|
36273 | };
|
36274 | EdgeIntersectionList.prototype.print = function print (out) {
|
36275 | out.println('Intersections:');
|
36276 | for (var it = this.iterator(); it.hasNext();) {
|
36277 | var ei = it.next();
|
36278 | ei.print(out);
|
36279 | }
|
36280 | };
|
36281 | EdgeIntersectionList.prototype.iterator = function iterator () {
|
36282 | return this._nodeMap.values().iterator()
|
36283 | };
|
36284 | EdgeIntersectionList.prototype.addSplitEdges = function addSplitEdges (edgeList) {
|
36285 | var this$1 = this;
|
36286 |
|
36287 | this.addEndpoints();
|
36288 | var it = this.iterator();
|
36289 | var eiPrev = it.next();
|
36290 | while (it.hasNext()) {
|
36291 | var ei = it.next();
|
36292 | var newEdge = this$1.createSplitEdge(eiPrev, ei);
|
36293 | edgeList.add(newEdge);
|
36294 | eiPrev = ei;
|
36295 | }
|
36296 | };
|
36297 | EdgeIntersectionList.prototype.addEndpoints = function addEndpoints () {
|
36298 | var maxSegIndex = this.edge.pts.length - 1;
|
36299 | this.add(this.edge.pts[0], 0, 0.0);
|
36300 | this.add(this.edge.pts[maxSegIndex], maxSegIndex, 0.0);
|
36301 | };
|
36302 | EdgeIntersectionList.prototype.createSplitEdge = function createSplitEdge (ei0, ei1) {
|
36303 | var this$1 = this;
|
36304 |
|
36305 | var npts = ei1.segmentIndex - ei0.segmentIndex + 2;
|
36306 | var lastSegStartPt = this.edge.pts[ei1.segmentIndex];
|
36307 | var useIntPt1 = ei1.dist > 0.0 || !ei1.coord.equals2D(lastSegStartPt);
|
36308 | if (!useIntPt1) {
|
36309 | npts--;
|
36310 | }
|
36311 | var pts = new Array(npts).fill(null);
|
36312 | var ipt = 0;
|
36313 | pts[ipt++] = new Coordinate(ei0.coord);
|
36314 | for (var i = ei0.segmentIndex + 1; i <= ei1.segmentIndex; i++) {
|
36315 | pts[ipt++] = this$1.edge.pts[i];
|
36316 | }
|
36317 | if (useIntPt1) { pts[ipt] = ei1.coord; }
|
36318 | return new Edge$1(pts, new Label(this.edge._label))
|
36319 | };
|
36320 | EdgeIntersectionList.prototype.add = function add (intPt, segmentIndex, dist) {
|
36321 | var eiNew = new EdgeIntersection(intPt, segmentIndex, dist);
|
36322 | var ei = this._nodeMap.get(eiNew);
|
36323 | if (ei !== null) {
|
36324 | return ei
|
36325 | }
|
36326 | this._nodeMap.put(eiNew, eiNew);
|
36327 | return eiNew
|
36328 | };
|
36329 | EdgeIntersectionList.prototype.isIntersection = function isIntersection (pt) {
|
36330 | for (var it = this.iterator(); it.hasNext();) {
|
36331 | var ei = it.next();
|
36332 | if (ei.coord.equals(pt)) { return true }
|
36333 | }
|
36334 | return false
|
36335 | };
|
36336 | EdgeIntersectionList.prototype.interfaces_ = function interfaces_ () {
|
36337 | return []
|
36338 | };
|
36339 | EdgeIntersectionList.prototype.getClass = function getClass () {
|
36340 | return EdgeIntersectionList
|
36341 | };
|
36342 |
|
36343 | var MonotoneChainIndexer = function MonotoneChainIndexer () {};
|
36344 |
|
36345 | MonotoneChainIndexer.prototype.getChainStartIndices = function getChainStartIndices (pts) {
|
36346 | var this$1 = this;
|
36347 |
|
36348 | var start = 0;
|
36349 | var startIndexList = new ArrayList();
|
36350 | startIndexList.add(new Integer(start));
|
36351 | do {
|
36352 | var last = this$1.findChainEnd(pts, start);
|
36353 | startIndexList.add(new Integer(last));
|
36354 | start = last;
|
36355 | } while (start < pts.length - 1)
|
36356 | var startIndex = MonotoneChainIndexer.toIntArray(startIndexList);
|
36357 | return startIndex
|
36358 | };
|
36359 | MonotoneChainIndexer.prototype.findChainEnd = function findChainEnd (pts, start) {
|
36360 | var chainQuad = Quadrant.quadrant(pts[start], pts[start + 1]);
|
36361 | var last = start + 1;
|
36362 | while (last < pts.length) {
|
36363 | var quad = Quadrant.quadrant(pts[last - 1], pts[last]);
|
36364 | if (quad !== chainQuad) { break }
|
36365 | last++;
|
36366 | }
|
36367 | return last - 1
|
36368 | };
|
36369 | MonotoneChainIndexer.prototype.interfaces_ = function interfaces_ () {
|
36370 | return []
|
36371 | };
|
36372 | MonotoneChainIndexer.prototype.getClass = function getClass () {
|
36373 | return MonotoneChainIndexer
|
36374 | };
|
36375 | MonotoneChainIndexer.toIntArray = function toIntArray (list) {
|
36376 | var array = new Array(list.size()).fill(null);
|
36377 | for (var i = 0; i < array.length; i++) {
|
36378 | array[i] = list.get(i).intValue();
|
36379 | }
|
36380 | return array
|
36381 | };
|
36382 |
|
36383 | var MonotoneChainEdge = function MonotoneChainEdge () {
|
36384 | this.e = null;
|
36385 | this.pts = null;
|
36386 | this.startIndex = null;
|
36387 | this.env1 = new Envelope();
|
36388 | this.env2 = new Envelope();
|
36389 | var e = arguments[0];
|
36390 | this.e = e;
|
36391 | this.pts = e.getCoordinates();
|
36392 | var mcb = new MonotoneChainIndexer();
|
36393 | this.startIndex = mcb.getChainStartIndices(this.pts);
|
36394 | };
|
36395 | MonotoneChainEdge.prototype.getCoordinates = function getCoordinates () {
|
36396 | return this.pts
|
36397 | };
|
36398 | MonotoneChainEdge.prototype.getMaxX = function getMaxX (chainIndex) {
|
36399 | var x1 = this.pts[this.startIndex[chainIndex]].x;
|
36400 | var x2 = this.pts[this.startIndex[chainIndex + 1]].x;
|
36401 | return x1 > x2 ? x1 : x2
|
36402 | };
|
36403 | MonotoneChainEdge.prototype.getMinX = function getMinX (chainIndex) {
|
36404 | var x1 = this.pts[this.startIndex[chainIndex]].x;
|
36405 | var x2 = this.pts[this.startIndex[chainIndex + 1]].x;
|
36406 | return x1 < x2 ? x1 : x2
|
36407 | };
|
36408 | MonotoneChainEdge.prototype.computeIntersectsForChain = function computeIntersectsForChain () {
|
36409 | if (arguments.length === 4) {
|
36410 | var chainIndex0 = arguments[0];
|
36411 | var mce = arguments[1];
|
36412 | var chainIndex1 = arguments[2];
|
36413 | var si = arguments[3];
|
36414 | this.computeIntersectsForChain(this.startIndex[chainIndex0], this.startIndex[chainIndex0 + 1], mce, mce.startIndex[chainIndex1], mce.startIndex[chainIndex1 + 1], si);
|
36415 | } else if (arguments.length === 6) {
|
36416 | var start0 = arguments[0];
|
36417 | var end0 = arguments[1];
|
36418 | var mce$1 = arguments[2];
|
36419 | var start1 = arguments[3];
|
36420 | var end1 = arguments[4];
|
36421 | var ei = arguments[5];
|
36422 | var p00 = this.pts[start0];
|
36423 | var p01 = this.pts[end0];
|
36424 | var p10 = mce$1.pts[start1];
|
36425 | var p11 = mce$1.pts[end1];
|
36426 | if (end0 - start0 === 1 && end1 - start1 === 1) {
|
36427 | ei.addIntersections(this.e, start0, mce$1.e, start1);
|
36428 | return null
|
36429 | }
|
36430 | this.env1.init(p00, p01);
|
36431 | this.env2.init(p10, p11);
|
36432 | if (!this.env1.intersects(this.env2)) { return null }
|
36433 | var mid0 = Math.trunc((start0 + end0) / 2);
|
36434 | var mid1 = Math.trunc((start1 + end1) / 2);
|
36435 | if (start0 < mid0) {
|
36436 | if (start1 < mid1) { this.computeIntersectsForChain(start0, mid0, mce$1, start1, mid1, ei); }
|
36437 | if (mid1 < end1) { this.computeIntersectsForChain(start0, mid0, mce$1, mid1, end1, ei); }
|
36438 | }
|
36439 | if (mid0 < end0) {
|
36440 | if (start1 < mid1) { this.computeIntersectsForChain(mid0, end0, mce$1, start1, mid1, ei); }
|
36441 | if (mid1 < end1) { this.computeIntersectsForChain(mid0, end0, mce$1, mid1, end1, ei); }
|
36442 | }
|
36443 | }
|
36444 | };
|
36445 | MonotoneChainEdge.prototype.getStartIndexes = function getStartIndexes () {
|
36446 | return this.startIndex
|
36447 | };
|
36448 | MonotoneChainEdge.prototype.computeIntersects = function computeIntersects (mce, si) {
|
36449 | var this$1 = this;
|
36450 |
|
36451 | for (var i = 0; i < this.startIndex.length - 1; i++) {
|
36452 | for (var j = 0; j < mce.startIndex.length - 1; j++) {
|
36453 | this$1.computeIntersectsForChain(i, mce, j, si);
|
36454 | }
|
36455 | }
|
36456 | };
|
36457 | MonotoneChainEdge.prototype.interfaces_ = function interfaces_ () {
|
36458 | return []
|
36459 | };
|
36460 | MonotoneChainEdge.prototype.getClass = function getClass () {
|
36461 | return MonotoneChainEdge
|
36462 | };
|
36463 |
|
36464 | var Depth = function Depth () {
|
36465 | var this$1 = this;
|
36466 |
|
36467 | this._depth = Array(2).fill().map(function () { return Array(3); });
|
36468 | for (var i = 0; i < 2; i++) {
|
36469 | for (var j = 0; j < 3; j++) {
|
36470 | this$1._depth[i][j] = Depth.NULL_VALUE;
|
36471 | }
|
36472 | }
|
36473 | };
|
36474 |
|
36475 | var staticAccessors$31 = { NULL_VALUE: { configurable: true } };
|
36476 | Depth.prototype.getDepth = function getDepth (geomIndex, posIndex) {
|
36477 | return this._depth[geomIndex][posIndex]
|
36478 | };
|
36479 | Depth.prototype.setDepth = function setDepth (geomIndex, posIndex, depthValue) {
|
36480 | this._depth[geomIndex][posIndex] = depthValue;
|
36481 | };
|
36482 | Depth.prototype.isNull = function isNull () {
|
36483 | var this$1 = this;
|
36484 |
|
36485 | if (arguments.length === 0) {
|
36486 | for (var i = 0; i < 2; i++) {
|
36487 | for (var j = 0; j < 3; j++) {
|
36488 | if (this$1._depth[i][j] !== Depth.NULL_VALUE) { return false }
|
36489 | }
|
36490 | }
|
36491 | return true
|
36492 | } else if (arguments.length === 1) {
|
36493 | var geomIndex = arguments[0];
|
36494 | return this._depth[geomIndex][1] === Depth.NULL_VALUE
|
36495 | } else if (arguments.length === 2) {
|
36496 | var geomIndex$1 = arguments[0];
|
36497 | var posIndex = arguments[1];
|
36498 | return this._depth[geomIndex$1][posIndex] === Depth.NULL_VALUE
|
36499 | }
|
36500 | };
|
36501 | Depth.prototype.normalize = function normalize () {
|
36502 | var this$1 = this;
|
36503 |
|
36504 | for (var i = 0; i < 2; i++) {
|
36505 | if (!this$1.isNull(i)) {
|
36506 | var minDepth = this$1._depth[i][1];
|
36507 | if (this$1._depth[i][2] < minDepth) { minDepth = this$1._depth[i][2]; }
|
36508 | if (minDepth < 0) { minDepth = 0; }
|
36509 | for (var j = 1; j < 3; j++) {
|
36510 | var newValue = 0;
|
36511 | if (this$1._depth[i][j] > minDepth) { newValue = 1; }
|
36512 | this$1._depth[i][j] = newValue;
|
36513 | }
|
36514 | }
|
36515 | }
|
36516 | };
|
36517 | Depth.prototype.getDelta = function getDelta (geomIndex) {
|
36518 | return this._depth[geomIndex][Position.RIGHT] - this._depth[geomIndex][Position.LEFT]
|
36519 | };
|
36520 | Depth.prototype.getLocation = function getLocation (geomIndex, posIndex) {
|
36521 | if (this._depth[geomIndex][posIndex] <= 0) { return Location.EXTERIOR }
|
36522 | return Location.INTERIOR
|
36523 | };
|
36524 | Depth.prototype.toString = function toString () {
|
36525 | return 'A: ' + this._depth[0][1] + ',' + this._depth[0][2] + ' B: ' + this._depth[1][1] + ',' + this._depth[1][2]
|
36526 | };
|
36527 | Depth.prototype.add = function add () {
|
36528 | var this$1 = this;
|
36529 |
|
36530 | if (arguments.length === 1) {
|
36531 | var lbl = arguments[0];
|
36532 | for (var i = 0; i < 2; i++) {
|
36533 | for (var j = 1; j < 3; j++) {
|
36534 | var loc = lbl.getLocation(i, j);
|
36535 | if (loc === Location.EXTERIOR || loc === Location.INTERIOR) {
|
36536 | if (this$1.isNull(i, j)) {
|
36537 | this$1._depth[i][j] = Depth.depthAtLocation(loc);
|
36538 | } else { this$1._depth[i][j] += Depth.depthAtLocation(loc); }
|
36539 | }
|
36540 | }
|
36541 | }
|
36542 | } else if (arguments.length === 3) {
|
36543 | var geomIndex = arguments[0];
|
36544 | var posIndex = arguments[1];
|
36545 | var location = arguments[2];
|
36546 | if (location === Location.INTERIOR) { this._depth[geomIndex][posIndex]++; }
|
36547 | }
|
36548 | };
|
36549 | Depth.prototype.interfaces_ = function interfaces_ () {
|
36550 | return []
|
36551 | };
|
36552 | Depth.prototype.getClass = function getClass () {
|
36553 | return Depth
|
36554 | };
|
36555 | Depth.depthAtLocation = function depthAtLocation (location) {
|
36556 | if (location === Location.EXTERIOR) { return 0 }
|
36557 | if (location === Location.INTERIOR) { return 1 }
|
36558 | return Depth.NULL_VALUE
|
36559 | };
|
36560 | staticAccessors$31.NULL_VALUE.get = function () { return -1 };
|
36561 |
|
36562 | Object.defineProperties( Depth, staticAccessors$31 );
|
36563 |
|
36564 | var Edge$1 = (function (GraphComponent$$1) {
|
36565 | function Edge () {
|
36566 | GraphComponent$$1.call(this);
|
36567 | this.pts = null;
|
36568 | this._env = null;
|
36569 | this.eiList = new EdgeIntersectionList(this);
|
36570 | this._name = null;
|
36571 | this._mce = null;
|
36572 | this._isIsolated = true;
|
36573 | this._depth = new Depth();
|
36574 | this._depthDelta = 0;
|
36575 | if (arguments.length === 1) {
|
36576 | var pts = arguments[0];
|
36577 | Edge.call(this, pts, null);
|
36578 | } else if (arguments.length === 2) {
|
36579 | var pts$1 = arguments[0];
|
36580 | var label = arguments[1];
|
36581 | this.pts = pts$1;
|
36582 | this._label = label;
|
36583 | }
|
36584 | }
|
36585 |
|
36586 | if ( GraphComponent$$1 ) Edge.__proto__ = GraphComponent$$1;
|
36587 | Edge.prototype = Object.create( GraphComponent$$1 && GraphComponent$$1.prototype );
|
36588 | Edge.prototype.constructor = Edge;
|
36589 | Edge.prototype.getDepth = function getDepth () {
|
36590 | return this._depth
|
36591 | };
|
36592 | Edge.prototype.getCollapsedEdge = function getCollapsedEdge () {
|
36593 | var newPts = new Array(2).fill(null);
|
36594 | newPts[0] = this.pts[0];
|
36595 | newPts[1] = this.pts[1];
|
36596 | var newe = new Edge(newPts, Label.toLineLabel(this._label));
|
36597 | return newe
|
36598 | };
|
36599 | Edge.prototype.isIsolated = function isIsolated () {
|
36600 | return this._isIsolated
|
36601 | };
|
36602 | Edge.prototype.getCoordinates = function getCoordinates () {
|
36603 | return this.pts
|
36604 | };
|
36605 | Edge.prototype.setIsolated = function setIsolated (isIsolated) {
|
36606 | this._isIsolated = isIsolated;
|
36607 | };
|
36608 | Edge.prototype.setName = function setName (name) {
|
36609 | this._name = name;
|
36610 | };
|
36611 | Edge.prototype.equals = function equals (o) {
|
36612 | var this$1 = this;
|
36613 |
|
36614 | if (!(o instanceof Edge)) { return false }
|
36615 | var e = o;
|
36616 | if (this.pts.length !== e.pts.length) { return false }
|
36617 | var isEqualForward = true;
|
36618 | var isEqualReverse = true;
|
36619 | var iRev = this.pts.length;
|
36620 | for (var i = 0; i < this.pts.length; i++) {
|
36621 | if (!this$1.pts[i].equals2D(e.pts[i])) {
|
36622 | isEqualForward = false;
|
36623 | }
|
36624 | if (!this$1.pts[i].equals2D(e.pts[--iRev])) {
|
36625 | isEqualReverse = false;
|
36626 | }
|
36627 | if (!isEqualForward && !isEqualReverse) { return false }
|
36628 | }
|
36629 | return true
|
36630 | };
|
36631 | Edge.prototype.getCoordinate = function getCoordinate () {
|
36632 | if (arguments.length === 0) {
|
36633 | if (this.pts.length > 0) { return this.pts[0] }
|
36634 | return null
|
36635 | } else if (arguments.length === 1) {
|
36636 | var i = arguments[0];
|
36637 | return this.pts[i]
|
36638 | }
|
36639 | };
|
36640 | Edge.prototype.print = function print (out) {
|
36641 | var this$1 = this;
|
36642 |
|
36643 | out.print('edge ' + this._name + ': ');
|
36644 | out.print('LINESTRING (');
|
36645 | for (var i = 0; i < this.pts.length; i++) {
|
36646 | if (i > 0) { out.print(','); }
|
36647 | out.print(this$1.pts[i].x + ' ' + this$1.pts[i].y);
|
36648 | }
|
36649 | out.print(') ' + this._label + ' ' + this._depthDelta);
|
36650 | };
|
36651 | Edge.prototype.computeIM = function computeIM (im) {
|
36652 | Edge.updateIM(this._label, im);
|
36653 | };
|
36654 | Edge.prototype.isCollapsed = function isCollapsed () {
|
36655 | if (!this._label.isArea()) { return false }
|
36656 | if (this.pts.length !== 3) { return false }
|
36657 | if (this.pts[0].equals(this.pts[2])) { return true }
|
36658 | return false
|
36659 | };
|
36660 | Edge.prototype.isClosed = function isClosed () {
|
36661 | return this.pts[0].equals(this.pts[this.pts.length - 1])
|
36662 | };
|
36663 | Edge.prototype.getMaximumSegmentIndex = function getMaximumSegmentIndex () {
|
36664 | return this.pts.length - 1
|
36665 | };
|
36666 | Edge.prototype.getDepthDelta = function getDepthDelta () {
|
36667 | return this._depthDelta
|
36668 | };
|
36669 | Edge.prototype.getNumPoints = function getNumPoints () {
|
36670 | return this.pts.length
|
36671 | };
|
36672 | Edge.prototype.printReverse = function printReverse (out) {
|
36673 | var this$1 = this;
|
36674 |
|
36675 | out.print('edge ' + this._name + ': ');
|
36676 | for (var i = this.pts.length - 1; i >= 0; i--) {
|
36677 | out.print(this$1.pts[i] + ' ');
|
36678 | }
|
36679 | out.println('');
|
36680 | };
|
36681 | Edge.prototype.getMonotoneChainEdge = function getMonotoneChainEdge () {
|
36682 | if (this._mce === null) { this._mce = new MonotoneChainEdge(this); }
|
36683 | return this._mce
|
36684 | };
|
36685 | Edge.prototype.getEnvelope = function getEnvelope () {
|
36686 | var this$1 = this;
|
36687 |
|
36688 | if (this._env === null) {
|
36689 | this._env = new Envelope();
|
36690 | for (var i = 0; i < this.pts.length; i++) {
|
36691 | this$1._env.expandToInclude(this$1.pts[i]);
|
36692 | }
|
36693 | }
|
36694 | return this._env
|
36695 | };
|
36696 | Edge.prototype.addIntersection = function addIntersection (li, segmentIndex, geomIndex, intIndex) {
|
36697 | var intPt = new Coordinate(li.getIntersection(intIndex));
|
36698 | var normalizedSegmentIndex = segmentIndex;
|
36699 | var dist = li.getEdgeDistance(geomIndex, intIndex);
|
36700 | var nextSegIndex = normalizedSegmentIndex + 1;
|
36701 | if (nextSegIndex < this.pts.length) {
|
36702 | var nextPt = this.pts[nextSegIndex];
|
36703 | if (intPt.equals2D(nextPt)) {
|
36704 | normalizedSegmentIndex = nextSegIndex;
|
36705 | dist = 0.0;
|
36706 | }
|
36707 | }
|
36708 | this.eiList.add(intPt, normalizedSegmentIndex, dist);
|
36709 | };
|
36710 | Edge.prototype.toString = function toString () {
|
36711 | var this$1 = this;
|
36712 |
|
36713 | var buf = new StringBuffer();
|
36714 | buf.append('edge ' + this._name + ': ');
|
36715 | buf.append('LINESTRING (');
|
36716 | for (var i = 0; i < this.pts.length; i++) {
|
36717 | if (i > 0) { buf.append(','); }
|
36718 | buf.append(this$1.pts[i].x + ' ' + this$1.pts[i].y);
|
36719 | }
|
36720 | buf.append(') ' + this._label + ' ' + this._depthDelta);
|
36721 | return buf.toString()
|
36722 | };
|
36723 | Edge.prototype.isPointwiseEqual = function isPointwiseEqual (e) {
|
36724 | var this$1 = this;
|
36725 |
|
36726 | if (this.pts.length !== e.pts.length) { return false }
|
36727 | for (var i = 0; i < this.pts.length; i++) {
|
36728 | if (!this$1.pts[i].equals2D(e.pts[i])) {
|
36729 | return false
|
36730 | }
|
36731 | }
|
36732 | return true
|
36733 | };
|
36734 | Edge.prototype.setDepthDelta = function setDepthDelta (depthDelta) {
|
36735 | this._depthDelta = depthDelta;
|
36736 | };
|
36737 | Edge.prototype.getEdgeIntersectionList = function getEdgeIntersectionList () {
|
36738 | return this.eiList
|
36739 | };
|
36740 | Edge.prototype.addIntersections = function addIntersections (li, segmentIndex, geomIndex) {
|
36741 | var this$1 = this;
|
36742 |
|
36743 | for (var i = 0; i < li.getIntersectionNum(); i++) {
|
36744 | this$1.addIntersection(li, segmentIndex, geomIndex, i);
|
36745 | }
|
36746 | };
|
36747 | Edge.prototype.interfaces_ = function interfaces_ () {
|
36748 | return []
|
36749 | };
|
36750 | Edge.prototype.getClass = function getClass () {
|
36751 | return Edge
|
36752 | };
|
36753 | Edge.updateIM = function updateIM () {
|
36754 | if (arguments.length === 2) {
|
36755 | var label = arguments[0];
|
36756 | var im = arguments[1];
|
36757 | im.setAtLeastIfValid(label.getLocation(0, Position.ON), label.getLocation(1, Position.ON), 1);
|
36758 | if (label.isArea()) {
|
36759 | im.setAtLeastIfValid(label.getLocation(0, Position.LEFT), label.getLocation(1, Position.LEFT), 2);
|
36760 | im.setAtLeastIfValid(label.getLocation(0, Position.RIGHT), label.getLocation(1, Position.RIGHT), 2);
|
36761 | }
|
36762 | } else { return GraphComponent$$1.prototype.updateIM.apply(this, arguments) }
|
36763 | };
|
36764 |
|
36765 | return Edge;
|
36766 | }(GraphComponent));
|
36767 |
|
36768 | var BufferBuilder = function BufferBuilder (bufParams) {
|
36769 | this._workingPrecisionModel = null;
|
36770 | this._workingNoder = null;
|
36771 | this._geomFact = null;
|
36772 | this._graph = null;
|
36773 | this._edgeList = new EdgeList();
|
36774 | this._bufParams = bufParams || null;
|
36775 | };
|
36776 | BufferBuilder.prototype.setWorkingPrecisionModel = function setWorkingPrecisionModel (pm) {
|
36777 | this._workingPrecisionModel = pm;
|
36778 | };
|
36779 | BufferBuilder.prototype.insertUniqueEdge = function insertUniqueEdge (e) {
|
36780 | var existingEdge = this._edgeList.findEqualEdge(e);
|
36781 | if (existingEdge !== null) {
|
36782 | var existingLabel = existingEdge.getLabel();
|
36783 | var labelToMerge = e.getLabel();
|
36784 | if (!existingEdge.isPointwiseEqual(e)) {
|
36785 | labelToMerge = new Label(e.getLabel());
|
36786 | labelToMerge.flip();
|
36787 | }
|
36788 | existingLabel.merge(labelToMerge);
|
36789 | var mergeDelta = BufferBuilder.depthDelta(labelToMerge);
|
36790 | var existingDelta = existingEdge.getDepthDelta();
|
36791 | var newDelta = existingDelta + mergeDelta;
|
36792 | existingEdge.setDepthDelta(newDelta);
|
36793 | } else {
|
36794 | this._edgeList.add(e);
|
36795 | e.setDepthDelta(BufferBuilder.depthDelta(e.getLabel()));
|
36796 | }
|
36797 | };
|
36798 | BufferBuilder.prototype.buildSubgraphs = function buildSubgraphs (subgraphList, polyBuilder) {
|
36799 | var processedGraphs = new ArrayList();
|
36800 | for (var i = subgraphList.iterator(); i.hasNext();) {
|
36801 | var subgraph = i.next();
|
36802 | var p = subgraph.getRightmostCoordinate();
|
36803 | var locater = new SubgraphDepthLocater(processedGraphs);
|
36804 | var outsideDepth = locater.getDepth(p);
|
36805 | subgraph.computeDepth(outsideDepth);
|
36806 | subgraph.findResultEdges();
|
36807 | processedGraphs.add(subgraph);
|
36808 | polyBuilder.add(subgraph.getDirectedEdges(), subgraph.getNodes());
|
36809 | }
|
36810 | };
|
36811 | BufferBuilder.prototype.createSubgraphs = function createSubgraphs (graph) {
|
36812 | var subgraphList = new ArrayList();
|
36813 | for (var i = graph.getNodes().iterator(); i.hasNext();) {
|
36814 | var node = i.next();
|
36815 | if (!node.isVisited()) {
|
36816 | var subgraph = new BufferSubgraph();
|
36817 | subgraph.create(node);
|
36818 | subgraphList.add(subgraph);
|
36819 | }
|
36820 | }
|
36821 | Collections.sort(subgraphList, Collections.reverseOrder());
|
36822 | return subgraphList
|
36823 | };
|
36824 | BufferBuilder.prototype.createEmptyResultGeometry = function createEmptyResultGeometry () {
|
36825 | var emptyGeom = this._geomFact.createPolygon();
|
36826 | return emptyGeom
|
36827 | };
|
36828 | BufferBuilder.prototype.getNoder = function getNoder (precisionModel) {
|
36829 | if (this._workingNoder !== null) { return this._workingNoder }
|
36830 | var noder = new MCIndexNoder();
|
36831 | var li = new RobustLineIntersector();
|
36832 | li.setPrecisionModel(precisionModel);
|
36833 | noder.setSegmentIntersector(new IntersectionAdder(li));
|
36834 | return noder
|
36835 | };
|
36836 | BufferBuilder.prototype.buffer = function buffer (g, distance) {
|
36837 | var precisionModel = this._workingPrecisionModel;
|
36838 | if (precisionModel === null) { precisionModel = g.getPrecisionModel(); }
|
36839 | this._geomFact = g.getFactory();
|
36840 | var curveBuilder = new OffsetCurveBuilder(precisionModel, this._bufParams);
|
36841 | var curveSetBuilder = new OffsetCurveSetBuilder(g, distance, curveBuilder);
|
36842 | var bufferSegStrList = curveSetBuilder.getCurves();
|
36843 | if (bufferSegStrList.size() <= 0) {
|
36844 | return this.createEmptyResultGeometry()
|
36845 | }
|
36846 | this.computeNodedEdges(bufferSegStrList, precisionModel);
|
36847 | this._graph = new PlanarGraph(new OverlayNodeFactory());
|
36848 | this._graph.addEdges(this._edgeList.getEdges());
|
36849 | var subgraphList = this.createSubgraphs(this._graph);
|
36850 | var polyBuilder = new PolygonBuilder(this._geomFact);
|
36851 | this.buildSubgraphs(subgraphList, polyBuilder);
|
36852 | var resultPolyList = polyBuilder.getPolygons();
|
36853 | if (resultPolyList.size() <= 0) {
|
36854 | return this.createEmptyResultGeometry()
|
36855 | }
|
36856 | var resultGeom = this._geomFact.buildGeometry(resultPolyList);
|
36857 | return resultGeom
|
36858 | };
|
36859 | BufferBuilder.prototype.computeNodedEdges = function computeNodedEdges (bufferSegStrList, precisionModel) {
|
36860 | var this$1 = this;
|
36861 |
|
36862 | var noder = this.getNoder(precisionModel);
|
36863 | noder.computeNodes(bufferSegStrList);
|
36864 | var nodedSegStrings = noder.getNodedSubstrings();
|
36865 | for (var i = nodedSegStrings.iterator(); i.hasNext();) {
|
36866 | var segStr = i.next();
|
36867 | var pts = segStr.getCoordinates();
|
36868 | if (pts.length === 2 && pts[0].equals2D(pts[1])) { continue }
|
36869 | var oldLabel = segStr.getData();
|
36870 | var edge = new Edge$1(segStr.getCoordinates(), new Label(oldLabel));
|
36871 | this$1.insertUniqueEdge(edge);
|
36872 | }
|
36873 | };
|
36874 | BufferBuilder.prototype.setNoder = function setNoder (noder) {
|
36875 | this._workingNoder = noder;
|
36876 | };
|
36877 | BufferBuilder.prototype.interfaces_ = function interfaces_ () {
|
36878 | return []
|
36879 | };
|
36880 | BufferBuilder.prototype.getClass = function getClass () {
|
36881 | return BufferBuilder
|
36882 | };
|
36883 | BufferBuilder.depthDelta = function depthDelta (label) {
|
36884 | var lLoc = label.getLocation(0, Position.LEFT);
|
36885 | var rLoc = label.getLocation(0, Position.RIGHT);
|
36886 | if (lLoc === Location.INTERIOR && rLoc === Location.EXTERIOR) { return 1; } else if (lLoc === Location.EXTERIOR && rLoc === Location.INTERIOR) { return -1 }
|
36887 | return 0
|
36888 | };
|
36889 | BufferBuilder.convertSegStrings = function convertSegStrings (it) {
|
36890 | var fact = new GeometryFactory();
|
36891 | var lines = new ArrayList();
|
36892 | while (it.hasNext()) {
|
36893 | var ss = it.next();
|
36894 | var line = fact.createLineString(ss.getCoordinates());
|
36895 | lines.add(line);
|
36896 | }
|
36897 | return fact.buildGeometry(lines)
|
36898 | };
|
36899 |
|
36900 | var ScaledNoder = function ScaledNoder () {
|
36901 | this._noder = null;
|
36902 | this._scaleFactor = null;
|
36903 | this._offsetX = null;
|
36904 | this._offsetY = null;
|
36905 | this._isScaled = false;
|
36906 | if (arguments.length === 2) {
|
36907 | var noder = arguments[0];
|
36908 | var scaleFactor = arguments[1];
|
36909 | this._noder = noder;
|
36910 | this._scaleFactor = scaleFactor;
|
36911 | this._offsetX = 0.0;
|
36912 | this._offsetY = 0.0;
|
36913 | this._isScaled = !this.isIntegerPrecision();
|
36914 | } else if (arguments.length === 4) {
|
36915 | var noder$1 = arguments[0];
|
36916 | var scaleFactor$1 = arguments[1];
|
36917 | var offsetX = arguments[2];
|
36918 | var offsetY = arguments[3];
|
36919 | this._noder = noder$1;
|
36920 | this._scaleFactor = scaleFactor$1;
|
36921 | this._offsetX = offsetX;
|
36922 | this._offsetY = offsetY;
|
36923 | this._isScaled = !this.isIntegerPrecision();
|
36924 | }
|
36925 | };
|
36926 | ScaledNoder.prototype.rescale = function rescale () {
|
36927 | var this$1 = this;
|
36928 |
|
36929 | if (hasInterface(arguments[0], Collection)) {
|
36930 | var segStrings = arguments[0];
|
36931 | for (var i = segStrings.iterator(); i.hasNext();) {
|
36932 | var ss = i.next();
|
36933 | this$1.rescale(ss.getCoordinates());
|
36934 | }
|
36935 | } else if (arguments[0] instanceof Array) {
|
36936 | var pts = arguments[0];
|
36937 |
|
36938 |
|
36939 |
|
36940 |
|
36941 |
|
36942 |
|
36943 | for (var i$1 = 0; i$1 < pts.length; i$1++) {
|
36944 | pts[i$1].x = pts[i$1].x / this$1._scaleFactor + this$1._offsetX;
|
36945 | pts[i$1].y = pts[i$1].y / this$1._scaleFactor + this$1._offsetY;
|
36946 | }
|
36947 | if (pts.length === 2 && pts[0].equals2D(pts[1])) {
|
36948 | System.out.println(pts);
|
36949 | }
|
36950 | }
|
36951 | };
|
36952 | ScaledNoder.prototype.scale = function scale () {
|
36953 | var this$1 = this;
|
36954 |
|
36955 | if (hasInterface(arguments[0], Collection)) {
|
36956 | var segStrings = arguments[0];
|
36957 | var nodedSegmentStrings = new ArrayList();
|
36958 | for (var i = segStrings.iterator(); i.hasNext();) {
|
36959 | var ss = i.next();
|
36960 | nodedSegmentStrings.add(new NodedSegmentString(this$1.scale(ss.getCoordinates()), ss.getData()));
|
36961 | }
|
36962 | return nodedSegmentStrings
|
36963 | } else if (arguments[0] instanceof Array) {
|
36964 | var pts = arguments[0];
|
36965 | var roundPts = new Array(pts.length).fill(null);
|
36966 | for (var i$1 = 0; i$1 < pts.length; i$1++) {
|
36967 | roundPts[i$1] = new Coordinate(Math.round((pts[i$1].x - this$1._offsetX) * this$1._scaleFactor), Math.round((pts[i$1].y - this$1._offsetY) * this$1._scaleFactor), pts[i$1].z);
|
36968 | }
|
36969 | var roundPtsNoDup = CoordinateArrays.removeRepeatedPoints(roundPts);
|
36970 | return roundPtsNoDup
|
36971 | }
|
36972 | };
|
36973 | ScaledNoder.prototype.isIntegerPrecision = function isIntegerPrecision () {
|
36974 | return this._scaleFactor === 1.0
|
36975 | };
|
36976 | ScaledNoder.prototype.getNodedSubstrings = function getNodedSubstrings () {
|
36977 | var splitSS = this._noder.getNodedSubstrings();
|
36978 | if (this._isScaled) { this.rescale(splitSS); }
|
36979 | return splitSS
|
36980 | };
|
36981 | ScaledNoder.prototype.computeNodes = function computeNodes (inputSegStrings) {
|
36982 | var intSegStrings = inputSegStrings;
|
36983 | if (this._isScaled) { intSegStrings = this.scale(inputSegStrings); }
|
36984 | this._noder.computeNodes(intSegStrings);
|
36985 | };
|
36986 | ScaledNoder.prototype.interfaces_ = function interfaces_ () {
|
36987 | return [Noder]
|
36988 | };
|
36989 | ScaledNoder.prototype.getClass = function getClass () {
|
36990 | return ScaledNoder
|
36991 | };
|
36992 |
|
36993 | var NodingValidator = function NodingValidator () {
|
36994 | this._li = new RobustLineIntersector();
|
36995 | this._segStrings = null;
|
36996 | var segStrings = arguments[0];
|
36997 | this._segStrings = segStrings;
|
36998 | };
|
36999 |
|
37000 | var staticAccessors$33 = { fact: { configurable: true } };
|
37001 | NodingValidator.prototype.checkEndPtVertexIntersections = function checkEndPtVertexIntersections () {
|
37002 | var this$1 = this;
|
37003 |
|
37004 | if (arguments.length === 0) {
|
37005 | for (var i = this._segStrings.iterator(); i.hasNext();) {
|
37006 | var ss = i.next();
|
37007 | var pts = ss.getCoordinates();
|
37008 | this$1.checkEndPtVertexIntersections(pts[0], this$1._segStrings);
|
37009 | this$1.checkEndPtVertexIntersections(pts[pts.length - 1], this$1._segStrings);
|
37010 | }
|
37011 | } else if (arguments.length === 2) {
|
37012 | var testPt = arguments[0];
|
37013 | var segStrings = arguments[1];
|
37014 | for (var i$1 = segStrings.iterator(); i$1.hasNext();) {
|
37015 | var ss$1 = i$1.next();
|
37016 | var pts$1 = ss$1.getCoordinates();
|
37017 | for (var j = 1; j < pts$1.length - 1; j++) {
|
37018 | if (pts$1[j].equals(testPt)) { throw new RuntimeException('found endpt/interior pt intersection at index ' + j + ' :pt ' + testPt) }
|
37019 | }
|
37020 | }
|
37021 | }
|
37022 | };
|
37023 | NodingValidator.prototype.checkInteriorIntersections = function checkInteriorIntersections () {
|
37024 | var this$1 = this;
|
37025 |
|
37026 | if (arguments.length === 0) {
|
37027 | for (var i = this._segStrings.iterator(); i.hasNext();) {
|
37028 | var ss0 = i.next();
|
37029 | for (var j = this._segStrings.iterator(); j.hasNext();) {
|
37030 | var ss1 = j.next();
|
37031 | this$1.checkInteriorIntersections(ss0, ss1);
|
37032 | }
|
37033 | }
|
37034 | } else if (arguments.length === 2) {
|
37035 | var ss0$1 = arguments[0];
|
37036 | var ss1$1 = arguments[1];
|
37037 | var pts0 = ss0$1.getCoordinates();
|
37038 | var pts1 = ss1$1.getCoordinates();
|
37039 | for (var i0 = 0; i0 < pts0.length - 1; i0++) {
|
37040 | for (var i1 = 0; i1 < pts1.length - 1; i1++) {
|
37041 | this$1.checkInteriorIntersections(ss0$1, i0, ss1$1, i1);
|
37042 | }
|
37043 | }
|
37044 | } else if (arguments.length === 4) {
|
37045 | var e0 = arguments[0];
|
37046 | var segIndex0 = arguments[1];
|
37047 | var e1 = arguments[2];
|
37048 | var segIndex1 = arguments[3];
|
37049 | if (e0 === e1 && segIndex0 === segIndex1) { return null }
|
37050 | var p00 = e0.getCoordinates()[segIndex0];
|
37051 | var p01 = e0.getCoordinates()[segIndex0 + 1];
|
37052 | var p10 = e1.getCoordinates()[segIndex1];
|
37053 | var p11 = e1.getCoordinates()[segIndex1 + 1];
|
37054 | this._li.computeIntersection(p00, p01, p10, p11);
|
37055 | if (this._li.hasIntersection()) {
|
37056 | if (this._li.isProper() || this.hasInteriorIntersection(this._li, p00, p01) || this.hasInteriorIntersection(this._li, p10, p11)) {
|
37057 | throw new RuntimeException('found non-noded intersection at ' + p00 + '-' + p01 + ' and ' + p10 + '-' + p11)
|
37058 | }
|
37059 | }
|
37060 | }
|
37061 | };
|
37062 | NodingValidator.prototype.checkValid = function checkValid () {
|
37063 | this.checkEndPtVertexIntersections();
|
37064 | this.checkInteriorIntersections();
|
37065 | this.checkCollapses();
|
37066 | };
|
37067 | NodingValidator.prototype.checkCollapses = function checkCollapses () {
|
37068 | var this$1 = this;
|
37069 |
|
37070 | if (arguments.length === 0) {
|
37071 | for (var i = this._segStrings.iterator(); i.hasNext();) {
|
37072 | var ss = i.next();
|
37073 | this$1.checkCollapses(ss);
|
37074 | }
|
37075 | } else if (arguments.length === 1) {
|
37076 | var ss$1 = arguments[0];
|
37077 | var pts = ss$1.getCoordinates();
|
37078 | for (var i$1 = 0; i$1 < pts.length - 2; i$1++) {
|
37079 | this$1.checkCollapse(pts[i$1], pts[i$1 + 1], pts[i$1 + 2]);
|
37080 | }
|
37081 | }
|
37082 | };
|
37083 | NodingValidator.prototype.hasInteriorIntersection = function hasInteriorIntersection (li, p0, p1) {
|
37084 | for (var i = 0; i < li.getIntersectionNum(); i++) {
|
37085 | var intPt = li.getIntersection(i);
|
37086 | if (!(intPt.equals(p0) || intPt.equals(p1))) { return true }
|
37087 | }
|
37088 | return false
|
37089 | };
|
37090 | NodingValidator.prototype.checkCollapse = function checkCollapse (p0, p1, p2) {
|
37091 | if (p0.equals(p2)) { throw new RuntimeException('found non-noded collapse at ' + NodingValidator.fact.createLineString([p0, p1, p2])) }
|
37092 | };
|
37093 | NodingValidator.prototype.interfaces_ = function interfaces_ () {
|
37094 | return []
|
37095 | };
|
37096 | NodingValidator.prototype.getClass = function getClass () {
|
37097 | return NodingValidator
|
37098 | };
|
37099 | staticAccessors$33.fact.get = function () { return new GeometryFactory() };
|
37100 |
|
37101 | Object.defineProperties( NodingValidator, staticAccessors$33 );
|
37102 |
|
37103 | var HotPixel = function HotPixel () {
|
37104 | this._li = null;
|
37105 | this._pt = null;
|
37106 | this._originalPt = null;
|
37107 | this._ptScaled = null;
|
37108 | this._p0Scaled = null;
|
37109 | this._p1Scaled = null;
|
37110 | this._scaleFactor = null;
|
37111 | this._minx = null;
|
37112 | this._maxx = null;
|
37113 | this._miny = null;
|
37114 | this._maxy = null;
|
37115 | this._corner = new Array(4).fill(null);
|
37116 | this._safeEnv = null;
|
37117 | var pt = arguments[0];
|
37118 | var scaleFactor = arguments[1];
|
37119 | var li = arguments[2];
|
37120 | this._originalPt = pt;
|
37121 | this._pt = pt;
|
37122 | this._scaleFactor = scaleFactor;
|
37123 | this._li = li;
|
37124 | if (scaleFactor <= 0) { throw new IllegalArgumentException('Scale factor must be non-zero') }
|
37125 | if (scaleFactor !== 1.0) {
|
37126 | this._pt = new Coordinate(this.scale(pt.x), this.scale(pt.y));
|
37127 | this._p0Scaled = new Coordinate();
|
37128 | this._p1Scaled = new Coordinate();
|
37129 | }
|
37130 | this.initCorners(this._pt);
|
37131 | };
|
37132 |
|
37133 | var staticAccessors$34 = { SAFE_ENV_EXPANSION_FACTOR: { configurable: true } };
|
37134 | HotPixel.prototype.intersectsScaled = function intersectsScaled (p0, p1) {
|
37135 | var segMinx = Math.min(p0.x, p1.x);
|
37136 | var segMaxx = Math.max(p0.x, p1.x);
|
37137 | var segMiny = Math.min(p0.y, p1.y);
|
37138 | var segMaxy = Math.max(p0.y, p1.y);
|
37139 | var isOutsidePixelEnv = this._maxx < segMinx || this._minx > segMaxx || this._maxy < segMiny || this._miny > segMaxy;
|
37140 | if (isOutsidePixelEnv) { return false }
|
37141 | var intersects = this.intersectsToleranceSquare(p0, p1);
|
37142 | Assert.isTrue(!(isOutsidePixelEnv && intersects), 'Found bad envelope test');
|
37143 | return intersects
|
37144 | };
|
37145 | HotPixel.prototype.initCorners = function initCorners (pt) {
|
37146 | var tolerance = 0.5;
|
37147 | this._minx = pt.x - tolerance;
|
37148 | this._maxx = pt.x + tolerance;
|
37149 | this._miny = pt.y - tolerance;
|
37150 | this._maxy = pt.y + tolerance;
|
37151 | this._corner[0] = new Coordinate(this._maxx, this._maxy);
|
37152 | this._corner[1] = new Coordinate(this._minx, this._maxy);
|
37153 | this._corner[2] = new Coordinate(this._minx, this._miny);
|
37154 | this._corner[3] = new Coordinate(this._maxx, this._miny);
|
37155 | };
|
37156 | HotPixel.prototype.intersects = function intersects (p0, p1) {
|
37157 | if (this._scaleFactor === 1.0) { return this.intersectsScaled(p0, p1) }
|
37158 | this.copyScaled(p0, this._p0Scaled);
|
37159 | this.copyScaled(p1, this._p1Scaled);
|
37160 | return this.intersectsScaled(this._p0Scaled, this._p1Scaled)
|
37161 | };
|
37162 | HotPixel.prototype.scale = function scale (val) {
|
37163 | return Math.round(val * this._scaleFactor)
|
37164 | };
|
37165 | HotPixel.prototype.getCoordinate = function getCoordinate () {
|
37166 | return this._originalPt
|
37167 | };
|
37168 | HotPixel.prototype.copyScaled = function copyScaled (p, pScaled) {
|
37169 | pScaled.x = this.scale(p.x);
|
37170 | pScaled.y = this.scale(p.y);
|
37171 | };
|
37172 | HotPixel.prototype.getSafeEnvelope = function getSafeEnvelope () {
|
37173 | if (this._safeEnv === null) {
|
37174 | var safeTolerance = HotPixel.SAFE_ENV_EXPANSION_FACTOR / this._scaleFactor;
|
37175 | this._safeEnv = new Envelope(this._originalPt.x - safeTolerance, this._originalPt.x + safeTolerance, this._originalPt.y - safeTolerance, this._originalPt.y + safeTolerance);
|
37176 | }
|
37177 | return this._safeEnv
|
37178 | };
|
37179 | HotPixel.prototype.intersectsPixelClosure = function intersectsPixelClosure (p0, p1) {
|
37180 | this._li.computeIntersection(p0, p1, this._corner[0], this._corner[1]);
|
37181 | if (this._li.hasIntersection()) { return true }
|
37182 | this._li.computeIntersection(p0, p1, this._corner[1], this._corner[2]);
|
37183 | if (this._li.hasIntersection()) { return true }
|
37184 | this._li.computeIntersection(p0, p1, this._corner[2], this._corner[3]);
|
37185 | if (this._li.hasIntersection()) { return true }
|
37186 | this._li.computeIntersection(p0, p1, this._corner[3], this._corner[0]);
|
37187 | if (this._li.hasIntersection()) { return true }
|
37188 | return false
|
37189 | };
|
37190 | HotPixel.prototype.intersectsToleranceSquare = function intersectsToleranceSquare (p0, p1) {
|
37191 | var intersectsLeft = false;
|
37192 | var intersectsBottom = false;
|
37193 | this._li.computeIntersection(p0, p1, this._corner[0], this._corner[1]);
|
37194 | if (this._li.isProper()) { return true }
|
37195 | this._li.computeIntersection(p0, p1, this._corner[1], this._corner[2]);
|
37196 | if (this._li.isProper()) { return true }
|
37197 | if (this._li.hasIntersection()) { intersectsLeft = true; }
|
37198 | this._li.computeIntersection(p0, p1, this._corner[2], this._corner[3]);
|
37199 | if (this._li.isProper()) { return true }
|
37200 | if (this._li.hasIntersection()) { intersectsBottom = true; }
|
37201 | this._li.computeIntersection(p0, p1, this._corner[3], this._corner[0]);
|
37202 | if (this._li.isProper()) { return true }
|
37203 | if (intersectsLeft && intersectsBottom) { return true }
|
37204 | if (p0.equals(this._pt)) { return true }
|
37205 | if (p1.equals(this._pt)) { return true }
|
37206 | return false
|
37207 | };
|
37208 | HotPixel.prototype.addSnappedNode = function addSnappedNode (segStr, segIndex) {
|
37209 | var p0 = segStr.getCoordinate(segIndex);
|
37210 | var p1 = segStr.getCoordinate(segIndex + 1);
|
37211 | if (this.intersects(p0, p1)) {
|
37212 | segStr.addIntersection(this.getCoordinate(), segIndex);
|
37213 | return true
|
37214 | }
|
37215 | return false
|
37216 | };
|
37217 | HotPixel.prototype.interfaces_ = function interfaces_ () {
|
37218 | return []
|
37219 | };
|
37220 | HotPixel.prototype.getClass = function getClass () {
|
37221 | return HotPixel
|
37222 | };
|
37223 | staticAccessors$34.SAFE_ENV_EXPANSION_FACTOR.get = function () { return 0.75 };
|
37224 |
|
37225 | Object.defineProperties( HotPixel, staticAccessors$34 );
|
37226 |
|
37227 | var MonotoneChainSelectAction = function MonotoneChainSelectAction () {
|
37228 | this.tempEnv1 = new Envelope();
|
37229 | this.selectedSegment = new LineSegment();
|
37230 | };
|
37231 | MonotoneChainSelectAction.prototype.select = function select () {
|
37232 | if (arguments.length === 1) {
|
37233 |
|
37234 | } else if (arguments.length === 2) {
|
37235 | var mc = arguments[0];
|
37236 | var startIndex = arguments[1];
|
37237 | mc.getLineSegment(startIndex, this.selectedSegment);
|
37238 | this.select(this.selectedSegment);
|
37239 | }
|
37240 | };
|
37241 | MonotoneChainSelectAction.prototype.interfaces_ = function interfaces_ () {
|
37242 | return []
|
37243 | };
|
37244 | MonotoneChainSelectAction.prototype.getClass = function getClass () {
|
37245 | return MonotoneChainSelectAction
|
37246 | };
|
37247 |
|
37248 | var MCIndexPointSnapper = function MCIndexPointSnapper () {
|
37249 | this._index = null;
|
37250 | var index = arguments[0];
|
37251 | this._index = index;
|
37252 | };
|
37253 |
|
37254 | var staticAccessors$35 = { HotPixelSnapAction: { configurable: true } };
|
37255 | MCIndexPointSnapper.prototype.snap = function snap () {
|
37256 | if (arguments.length === 1) {
|
37257 | var hotPixel = arguments[0];
|
37258 | return this.snap(hotPixel, null, -1)
|
37259 | } else if (arguments.length === 3) {
|
37260 | var hotPixel$1 = arguments[0];
|
37261 | var parentEdge = arguments[1];
|
37262 | var hotPixelVertexIndex = arguments[2];
|
37263 | var pixelEnv = hotPixel$1.getSafeEnvelope();
|
37264 | var hotPixelSnapAction = new HotPixelSnapAction(hotPixel$1, parentEdge, hotPixelVertexIndex);
|
37265 | this._index.query(pixelEnv, {
|
37266 | interfaces_: function () {
|
37267 | return [ItemVisitor]
|
37268 | },
|
37269 | visitItem: function (item) {
|
37270 | var testChain = item;
|
37271 | testChain.select(pixelEnv, hotPixelSnapAction);
|
37272 | }
|
37273 | });
|
37274 | return hotPixelSnapAction.isNodeAdded()
|
37275 | }
|
37276 | };
|
37277 | MCIndexPointSnapper.prototype.interfaces_ = function interfaces_ () {
|
37278 | return []
|
37279 | };
|
37280 | MCIndexPointSnapper.prototype.getClass = function getClass () {
|
37281 | return MCIndexPointSnapper
|
37282 | };
|
37283 | staticAccessors$35.HotPixelSnapAction.get = function () { return HotPixelSnapAction };
|
37284 |
|
37285 | Object.defineProperties( MCIndexPointSnapper, staticAccessors$35 );
|
37286 |
|
37287 | var HotPixelSnapAction = (function (MonotoneChainSelectAction$$1) {
|
37288 | function HotPixelSnapAction () {
|
37289 | MonotoneChainSelectAction$$1.call(this);
|
37290 | this._hotPixel = null;
|
37291 | this._parentEdge = null;
|
37292 | this._hotPixelVertexIndex = null;
|
37293 | this._isNodeAdded = false;
|
37294 | var hotPixel = arguments[0];
|
37295 | var parentEdge = arguments[1];
|
37296 | var hotPixelVertexIndex = arguments[2];
|
37297 | this._hotPixel = hotPixel;
|
37298 | this._parentEdge = parentEdge;
|
37299 | this._hotPixelVertexIndex = hotPixelVertexIndex;
|
37300 | }
|
37301 |
|
37302 | if ( MonotoneChainSelectAction$$1 ) HotPixelSnapAction.__proto__ = MonotoneChainSelectAction$$1;
|
37303 | HotPixelSnapAction.prototype = Object.create( MonotoneChainSelectAction$$1 && MonotoneChainSelectAction$$1.prototype );
|
37304 | HotPixelSnapAction.prototype.constructor = HotPixelSnapAction;
|
37305 | HotPixelSnapAction.prototype.isNodeAdded = function isNodeAdded () {
|
37306 | return this._isNodeAdded
|
37307 | };
|
37308 | HotPixelSnapAction.prototype.select = function select () {
|
37309 | if (arguments.length === 2) {
|
37310 | var mc = arguments[0];
|
37311 | var startIndex = arguments[1];
|
37312 | var ss = mc.getContext();
|
37313 | if (this._parentEdge !== null) {
|
37314 | if (ss === this._parentEdge && startIndex === this._hotPixelVertexIndex) { return null }
|
37315 | }
|
37316 | this._isNodeAdded = this._hotPixel.addSnappedNode(ss, startIndex);
|
37317 | } else { return MonotoneChainSelectAction$$1.prototype.select.apply(this, arguments) }
|
37318 | };
|
37319 | HotPixelSnapAction.prototype.interfaces_ = function interfaces_ () {
|
37320 | return []
|
37321 | };
|
37322 | HotPixelSnapAction.prototype.getClass = function getClass () {
|
37323 | return HotPixelSnapAction
|
37324 | };
|
37325 |
|
37326 | return HotPixelSnapAction;
|
37327 | }(MonotoneChainSelectAction));
|
37328 |
|
37329 | var InteriorIntersectionFinderAdder = function InteriorIntersectionFinderAdder () {
|
37330 | this._li = null;
|
37331 | this._interiorIntersections = null;
|
37332 | var li = arguments[0];
|
37333 | this._li = li;
|
37334 | this._interiorIntersections = new ArrayList();
|
37335 | };
|
37336 | InteriorIntersectionFinderAdder.prototype.processIntersections = function processIntersections (e0, segIndex0, e1, segIndex1) {
|
37337 | var this$1 = this;
|
37338 |
|
37339 | if (e0 === e1 && segIndex0 === segIndex1) { return null }
|
37340 | var p00 = e0.getCoordinates()[segIndex0];
|
37341 | var p01 = e0.getCoordinates()[segIndex0 + 1];
|
37342 | var p10 = e1.getCoordinates()[segIndex1];
|
37343 | var p11 = e1.getCoordinates()[segIndex1 + 1];
|
37344 | this._li.computeIntersection(p00, p01, p10, p11);
|
37345 | if (this._li.hasIntersection()) {
|
37346 | if (this._li.isInteriorIntersection()) {
|
37347 | for (var intIndex = 0; intIndex < this._li.getIntersectionNum(); intIndex++) {
|
37348 | this$1._interiorIntersections.add(this$1._li.getIntersection(intIndex));
|
37349 | }
|
37350 | e0.addIntersections(this._li, segIndex0, 0);
|
37351 | e1.addIntersections(this._li, segIndex1, 1);
|
37352 | }
|
37353 | }
|
37354 | };
|
37355 | InteriorIntersectionFinderAdder.prototype.isDone = function isDone () {
|
37356 | return false
|
37357 | };
|
37358 | InteriorIntersectionFinderAdder.prototype.getInteriorIntersections = function getInteriorIntersections () {
|
37359 | return this._interiorIntersections
|
37360 | };
|
37361 | InteriorIntersectionFinderAdder.prototype.interfaces_ = function interfaces_ () {
|
37362 | return [SegmentIntersector]
|
37363 | };
|
37364 | InteriorIntersectionFinderAdder.prototype.getClass = function getClass () {
|
37365 | return InteriorIntersectionFinderAdder
|
37366 | };
|
37367 |
|
37368 | var MCIndexSnapRounder = function MCIndexSnapRounder () {
|
37369 | this._pm = null;
|
37370 | this._li = null;
|
37371 | this._scaleFactor = null;
|
37372 | this._noder = null;
|
37373 | this._pointSnapper = null;
|
37374 | this._nodedSegStrings = null;
|
37375 | var pm = arguments[0];
|
37376 | this._pm = pm;
|
37377 | this._li = new RobustLineIntersector();
|
37378 | this._li.setPrecisionModel(pm);
|
37379 | this._scaleFactor = pm.getScale();
|
37380 | };
|
37381 | MCIndexSnapRounder.prototype.checkCorrectness = function checkCorrectness (inputSegmentStrings) {
|
37382 | var resultSegStrings = NodedSegmentString.getNodedSubstrings(inputSegmentStrings);
|
37383 | var nv = new NodingValidator(resultSegStrings);
|
37384 | try {
|
37385 | nv.checkValid();
|
37386 | } catch (ex) {
|
37387 | if (ex instanceof Exception) {
|
37388 | ex.printStackTrace();
|
37389 | } else { throw ex }
|
37390 | } finally {}
|
37391 | };
|
37392 | MCIndexSnapRounder.prototype.getNodedSubstrings = function getNodedSubstrings () {
|
37393 | return NodedSegmentString.getNodedSubstrings(this._nodedSegStrings)
|
37394 | };
|
37395 | MCIndexSnapRounder.prototype.snapRound = function snapRound (segStrings, li) {
|
37396 | var intersections = this.findInteriorIntersections(segStrings, li);
|
37397 | this.computeIntersectionSnaps(intersections);
|
37398 | this.computeVertexSnaps(segStrings);
|
37399 | };
|
37400 | MCIndexSnapRounder.prototype.findInteriorIntersections = function findInteriorIntersections (segStrings, li) {
|
37401 | var intFinderAdder = new InteriorIntersectionFinderAdder(li);
|
37402 | this._noder.setSegmentIntersector(intFinderAdder);
|
37403 | this._noder.computeNodes(segStrings);
|
37404 | return intFinderAdder.getInteriorIntersections()
|
37405 | };
|
37406 | MCIndexSnapRounder.prototype.computeVertexSnaps = function computeVertexSnaps () {
|
37407 | var this$1 = this;
|
37408 |
|
37409 | if (hasInterface(arguments[0], Collection)) {
|
37410 | var edges = arguments[0];
|
37411 | for (var i0 = edges.iterator(); i0.hasNext();) {
|
37412 | var edge0 = i0.next();
|
37413 | this$1.computeVertexSnaps(edge0);
|
37414 | }
|
37415 | } else if (arguments[0] instanceof NodedSegmentString) {
|
37416 | var e = arguments[0];
|
37417 | var pts0 = e.getCoordinates();
|
37418 | for (var i = 0; i < pts0.length; i++) {
|
37419 | var hotPixel = new HotPixel(pts0[i], this$1._scaleFactor, this$1._li);
|
37420 | var isNodeAdded = this$1._pointSnapper.snap(hotPixel, e, i);
|
37421 | if (isNodeAdded) {
|
37422 | e.addIntersection(pts0[i], i);
|
37423 | }
|
37424 | }
|
37425 | }
|
37426 | };
|
37427 | MCIndexSnapRounder.prototype.computeNodes = function computeNodes (inputSegmentStrings) {
|
37428 | this._nodedSegStrings = inputSegmentStrings;
|
37429 | this._noder = new MCIndexNoder();
|
37430 | this._pointSnapper = new MCIndexPointSnapper(this._noder.getIndex());
|
37431 | this.snapRound(inputSegmentStrings, this._li);
|
37432 | };
|
37433 | MCIndexSnapRounder.prototype.computeIntersectionSnaps = function computeIntersectionSnaps (snapPts) {
|
37434 | var this$1 = this;
|
37435 |
|
37436 | for (var it = snapPts.iterator(); it.hasNext();) {
|
37437 | var snapPt = it.next();
|
37438 | var hotPixel = new HotPixel(snapPt, this$1._scaleFactor, this$1._li);
|
37439 | this$1._pointSnapper.snap(hotPixel);
|
37440 | }
|
37441 | };
|
37442 | MCIndexSnapRounder.prototype.interfaces_ = function interfaces_ () {
|
37443 | return [Noder]
|
37444 | };
|
37445 | MCIndexSnapRounder.prototype.getClass = function getClass () {
|
37446 | return MCIndexSnapRounder
|
37447 | };
|
37448 |
|
37449 | var BufferOp = function BufferOp () {
|
37450 | this._argGeom = null;
|
37451 | this._distance = null;
|
37452 | this._bufParams = new BufferParameters();
|
37453 | this._resultGeometry = null;
|
37454 | this._saveException = null;
|
37455 | if (arguments.length === 1) {
|
37456 | var g = arguments[0];
|
37457 | this._argGeom = g;
|
37458 | } else if (arguments.length === 2) {
|
37459 | var g$1 = arguments[0];
|
37460 | var bufParams = arguments[1];
|
37461 | this._argGeom = g$1;
|
37462 | this._bufParams = bufParams;
|
37463 | }
|
37464 | };
|
37465 |
|
37466 | var staticAccessors$32 = { CAP_ROUND: { configurable: true },CAP_BUTT: { configurable: true },CAP_FLAT: { configurable: true },CAP_SQUARE: { configurable: true },MAX_PRECISION_DIGITS: { configurable: true } };
|
37467 | BufferOp.prototype.bufferFixedPrecision = function bufferFixedPrecision (fixedPM) {
|
37468 | var noder = new ScaledNoder(new MCIndexSnapRounder(new PrecisionModel(1.0)), fixedPM.getScale());
|
37469 | var bufBuilder = new BufferBuilder(this._bufParams);
|
37470 | bufBuilder.setWorkingPrecisionModel(fixedPM);
|
37471 | bufBuilder.setNoder(noder);
|
37472 | this._resultGeometry = bufBuilder.buffer(this._argGeom, this._distance);
|
37473 | };
|
37474 | BufferOp.prototype.bufferReducedPrecision = function bufferReducedPrecision () {
|
37475 | var this$1 = this;
|
37476 |
|
37477 | if (arguments.length === 0) {
|
37478 | for (var precDigits = BufferOp.MAX_PRECISION_DIGITS; precDigits >= 0; precDigits--) {
|
37479 | try {
|
37480 | this$1.bufferReducedPrecision(precDigits);
|
37481 | } catch (ex) {
|
37482 | if (ex instanceof TopologyException) {
|
37483 | this$1._saveException = ex;
|
37484 | } else { throw ex }
|
37485 | } finally {}
|
37486 | if (this$1._resultGeometry !== null) { return null }
|
37487 | }
|
37488 | throw this._saveException
|
37489 | } else if (arguments.length === 1) {
|
37490 | var precisionDigits = arguments[0];
|
37491 | var sizeBasedScaleFactor = BufferOp.precisionScaleFactor(this._argGeom, this._distance, precisionDigits);
|
37492 | var fixedPM = new PrecisionModel(sizeBasedScaleFactor);
|
37493 | this.bufferFixedPrecision(fixedPM);
|
37494 | }
|
37495 | };
|
37496 | BufferOp.prototype.computeGeometry = function computeGeometry () {
|
37497 | this.bufferOriginalPrecision();
|
37498 | if (this._resultGeometry !== null) { return null }
|
37499 | var argPM = this._argGeom.getFactory().getPrecisionModel();
|
37500 | if (argPM.getType() === PrecisionModel.FIXED) { this.bufferFixedPrecision(argPM); } else { this.bufferReducedPrecision(); }
|
37501 | };
|
37502 | BufferOp.prototype.setQuadrantSegments = function setQuadrantSegments (quadrantSegments) {
|
37503 | this._bufParams.setQuadrantSegments(quadrantSegments);
|
37504 | };
|
37505 | BufferOp.prototype.bufferOriginalPrecision = function bufferOriginalPrecision () {
|
37506 | try {
|
37507 | var bufBuilder = new BufferBuilder(this._bufParams);
|
37508 | this._resultGeometry = bufBuilder.buffer(this._argGeom, this._distance);
|
37509 | } catch (ex) {
|
37510 | if (ex instanceof RuntimeException) {
|
37511 | this._saveException = ex;
|
37512 | } else { throw ex }
|
37513 | } finally {}
|
37514 | };
|
37515 | BufferOp.prototype.getResultGeometry = function getResultGeometry (distance) {
|
37516 | this._distance = distance;
|
37517 | this.computeGeometry();
|
37518 | return this._resultGeometry
|
37519 | };
|
37520 | BufferOp.prototype.setEndCapStyle = function setEndCapStyle (endCapStyle) {
|
37521 | this._bufParams.setEndCapStyle(endCapStyle);
|
37522 | };
|
37523 | BufferOp.prototype.interfaces_ = function interfaces_ () {
|
37524 | return []
|
37525 | };
|
37526 | BufferOp.prototype.getClass = function getClass () {
|
37527 | return BufferOp
|
37528 | };
|
37529 | BufferOp.bufferOp = function bufferOp () {
|
37530 | if (arguments.length === 2) {
|
37531 | var g = arguments[0];
|
37532 | var distance = arguments[1];
|
37533 | var gBuf = new BufferOp(g);
|
37534 | var geomBuf = gBuf.getResultGeometry(distance);
|
37535 | return geomBuf
|
37536 | } else if (arguments.length === 3) {
|
37537 | if (Number.isInteger(arguments[2]) && (arguments[0] instanceof Geometry && typeof arguments[1] === 'number')) {
|
37538 | var g$1 = arguments[0];
|
37539 | var distance$1 = arguments[1];
|
37540 | var quadrantSegments = arguments[2];
|
37541 | var bufOp = new BufferOp(g$1);
|
37542 | bufOp.setQuadrantSegments(quadrantSegments);
|
37543 | var geomBuf$1 = bufOp.getResultGeometry(distance$1);
|
37544 | return geomBuf$1
|
37545 | } else if (arguments[2] instanceof BufferParameters && (arguments[0] instanceof Geometry && typeof arguments[1] === 'number')) {
|
37546 | var g$2 = arguments[0];
|
37547 | var distance$2 = arguments[1];
|
37548 | var params = arguments[2];
|
37549 | var bufOp$1 = new BufferOp(g$2, params);
|
37550 | var geomBuf$2 = bufOp$1.getResultGeometry(distance$2);
|
37551 | return geomBuf$2
|
37552 | }
|
37553 | } else if (arguments.length === 4) {
|
37554 | var g$3 = arguments[0];
|
37555 | var distance$3 = arguments[1];
|
37556 | var quadrantSegments$1 = arguments[2];
|
37557 | var endCapStyle = arguments[3];
|
37558 | var bufOp$2 = new BufferOp(g$3);
|
37559 | bufOp$2.setQuadrantSegments(quadrantSegments$1);
|
37560 | bufOp$2.setEndCapStyle(endCapStyle);
|
37561 | var geomBuf$3 = bufOp$2.getResultGeometry(distance$3);
|
37562 | return geomBuf$3
|
37563 | }
|
37564 | };
|
37565 | BufferOp.precisionScaleFactor = function precisionScaleFactor (g, distance, maxPrecisionDigits) {
|
37566 | var env = g.getEnvelopeInternal();
|
37567 | var envMax = MathUtil.max(Math.abs(env.getMaxX()), Math.abs(env.getMaxY()), Math.abs(env.getMinX()), Math.abs(env.getMinY()));
|
37568 | var expandByDistance = distance > 0.0 ? distance : 0.0;
|
37569 | var bufEnvMax = envMax + 2 * expandByDistance;
|
37570 | var bufEnvPrecisionDigits = Math.trunc(Math.log(bufEnvMax) / Math.log(10) + 1.0);
|
37571 | var minUnitLog10 = maxPrecisionDigits - bufEnvPrecisionDigits;
|
37572 | var scaleFactor = Math.pow(10.0, minUnitLog10);
|
37573 | return scaleFactor
|
37574 | };
|
37575 | staticAccessors$32.CAP_ROUND.get = function () { return BufferParameters.CAP_ROUND };
|
37576 | staticAccessors$32.CAP_BUTT.get = function () { return BufferParameters.CAP_FLAT };
|
37577 | staticAccessors$32.CAP_FLAT.get = function () { return BufferParameters.CAP_FLAT };
|
37578 | staticAccessors$32.CAP_SQUARE.get = function () { return BufferParameters.CAP_SQUARE };
|
37579 | staticAccessors$32.MAX_PRECISION_DIGITS.get = function () { return 12 };
|
37580 |
|
37581 | Object.defineProperties( BufferOp, staticAccessors$32 );
|
37582 |
|
37583 | var PointPairDistance = function PointPairDistance () {
|
37584 | this._pt = [new Coordinate(), new Coordinate()];
|
37585 | this._distance = Double.NaN;
|
37586 | this._isNull = true;
|
37587 | };
|
37588 | PointPairDistance.prototype.getCoordinates = function getCoordinates () {
|
37589 | return this._pt
|
37590 | };
|
37591 | PointPairDistance.prototype.getCoordinate = function getCoordinate (i) {
|
37592 | return this._pt[i]
|
37593 | };
|
37594 | PointPairDistance.prototype.setMinimum = function setMinimum () {
|
37595 | if (arguments.length === 1) {
|
37596 | var ptDist = arguments[0];
|
37597 | this.setMinimum(ptDist._pt[0], ptDist._pt[1]);
|
37598 | } else if (arguments.length === 2) {
|
37599 | var p0 = arguments[0];
|
37600 | var p1 = arguments[1];
|
37601 | if (this._isNull) {
|
37602 | this.initialize(p0, p1);
|
37603 | return null
|
37604 | }
|
37605 | var dist = p0.distance(p1);
|
37606 | if (dist < this._distance) { this.initialize(p0, p1, dist); }
|
37607 | }
|
37608 | };
|
37609 | PointPairDistance.prototype.initialize = function initialize () {
|
37610 | if (arguments.length === 0) {
|
37611 | this._isNull = true;
|
37612 | } else if (arguments.length === 2) {
|
37613 | var p0 = arguments[0];
|
37614 | var p1 = arguments[1];
|
37615 | this._pt[0].setCoordinate(p0);
|
37616 | this._pt[1].setCoordinate(p1);
|
37617 | this._distance = p0.distance(p1);
|
37618 | this._isNull = false;
|
37619 | } else if (arguments.length === 3) {
|
37620 | var p0$1 = arguments[0];
|
37621 | var p1$1 = arguments[1];
|
37622 | var distance = arguments[2];
|
37623 | this._pt[0].setCoordinate(p0$1);
|
37624 | this._pt[1].setCoordinate(p1$1);
|
37625 | this._distance = distance;
|
37626 | this._isNull = false;
|
37627 | }
|
37628 | };
|
37629 | PointPairDistance.prototype.getDistance = function getDistance () {
|
37630 | return this._distance
|
37631 | };
|
37632 | PointPairDistance.prototype.setMaximum = function setMaximum () {
|
37633 | if (arguments.length === 1) {
|
37634 | var ptDist = arguments[0];
|
37635 | this.setMaximum(ptDist._pt[0], ptDist._pt[1]);
|
37636 | } else if (arguments.length === 2) {
|
37637 | var p0 = arguments[0];
|
37638 | var p1 = arguments[1];
|
37639 | if (this._isNull) {
|
37640 | this.initialize(p0, p1);
|
37641 | return null
|
37642 | }
|
37643 | var dist = p0.distance(p1);
|
37644 | if (dist > this._distance) { this.initialize(p0, p1, dist); }
|
37645 | }
|
37646 | };
|
37647 | PointPairDistance.prototype.interfaces_ = function interfaces_ () {
|
37648 | return []
|
37649 | };
|
37650 | PointPairDistance.prototype.getClass = function getClass () {
|
37651 | return PointPairDistance
|
37652 | };
|
37653 |
|
37654 | var DistanceToPointFinder = function DistanceToPointFinder () {};
|
37655 |
|
37656 | DistanceToPointFinder.prototype.interfaces_ = function interfaces_ () {
|
37657 | return []
|
37658 | };
|
37659 | DistanceToPointFinder.prototype.getClass = function getClass () {
|
37660 | return DistanceToPointFinder
|
37661 | };
|
37662 | DistanceToPointFinder.computeDistance = function computeDistance () {
|
37663 | if (arguments[2] instanceof PointPairDistance && (arguments[0] instanceof LineString$1 && arguments[1] instanceof Coordinate)) {
|
37664 | var line = arguments[0];
|
37665 | var pt = arguments[1];
|
37666 | var ptDist = arguments[2];
|
37667 | var coords = line.getCoordinates();
|
37668 | var tempSegment = new LineSegment();
|
37669 | for (var i = 0; i < coords.length - 1; i++) {
|
37670 | tempSegment.setCoordinates(coords[i], coords[i + 1]);
|
37671 | var closestPt = tempSegment.closestPoint(pt);
|
37672 | ptDist.setMinimum(closestPt, pt);
|
37673 | }
|
37674 | } else if (arguments[2] instanceof PointPairDistance && (arguments[0] instanceof Polygon && arguments[1] instanceof Coordinate)) {
|
37675 | var poly = arguments[0];
|
37676 | var pt$1 = arguments[1];
|
37677 | var ptDist$1 = arguments[2];
|
37678 | DistanceToPointFinder.computeDistance(poly.getExteriorRing(), pt$1, ptDist$1);
|
37679 | for (var i$1 = 0; i$1 < poly.getNumInteriorRing(); i$1++) {
|
37680 | DistanceToPointFinder.computeDistance(poly.getInteriorRingN(i$1), pt$1, ptDist$1);
|
37681 | }
|
37682 | } else if (arguments[2] instanceof PointPairDistance && (arguments[0] instanceof Geometry && arguments[1] instanceof Coordinate)) {
|
37683 | var geom = arguments[0];
|
37684 | var pt$2 = arguments[1];
|
37685 | var ptDist$2 = arguments[2];
|
37686 | if (geom instanceof LineString$1) {
|
37687 | DistanceToPointFinder.computeDistance(geom, pt$2, ptDist$2);
|
37688 | } else if (geom instanceof Polygon) {
|
37689 | DistanceToPointFinder.computeDistance(geom, pt$2, ptDist$2);
|
37690 | } else if (geom instanceof GeometryCollection) {
|
37691 | var gc = geom;
|
37692 | for (var i$2 = 0; i$2 < gc.getNumGeometries(); i$2++) {
|
37693 | var g = gc.getGeometryN(i$2);
|
37694 | DistanceToPointFinder.computeDistance(g, pt$2, ptDist$2);
|
37695 | }
|
37696 | } else {
|
37697 | ptDist$2.setMinimum(geom.getCoordinate(), pt$2);
|
37698 | }
|
37699 | } else if (arguments[2] instanceof PointPairDistance && (arguments[0] instanceof LineSegment && arguments[1] instanceof Coordinate)) {
|
37700 | var segment = arguments[0];
|
37701 | var pt$3 = arguments[1];
|
37702 | var ptDist$3 = arguments[2];
|
37703 | var closestPt$1 = segment.closestPoint(pt$3);
|
37704 | ptDist$3.setMinimum(closestPt$1, pt$3);
|
37705 | }
|
37706 | };
|
37707 |
|
37708 | var BufferCurveMaximumDistanceFinder = function BufferCurveMaximumDistanceFinder (inputGeom) {
|
37709 | this._maxPtDist = new PointPairDistance();
|
37710 | this._inputGeom = inputGeom || null;
|
37711 | };
|
37712 |
|
37713 | var staticAccessors$36 = { MaxPointDistanceFilter: { configurable: true },MaxMidpointDistanceFilter: { configurable: true } };
|
37714 | BufferCurveMaximumDistanceFinder.prototype.computeMaxMidpointDistance = function computeMaxMidpointDistance (curve) {
|
37715 | var distFilter = new MaxMidpointDistanceFilter(this._inputGeom);
|
37716 | curve.apply(distFilter);
|
37717 | this._maxPtDist.setMaximum(distFilter.getMaxPointDistance());
|
37718 | };
|
37719 | BufferCurveMaximumDistanceFinder.prototype.computeMaxVertexDistance = function computeMaxVertexDistance (curve) {
|
37720 | var distFilter = new MaxPointDistanceFilter(this._inputGeom);
|
37721 | curve.apply(distFilter);
|
37722 | this._maxPtDist.setMaximum(distFilter.getMaxPointDistance());
|
37723 | };
|
37724 | BufferCurveMaximumDistanceFinder.prototype.findDistance = function findDistance (bufferCurve) {
|
37725 | this.computeMaxVertexDistance(bufferCurve);
|
37726 | this.computeMaxMidpointDistance(bufferCurve);
|
37727 | return this._maxPtDist.getDistance()
|
37728 | };
|
37729 | BufferCurveMaximumDistanceFinder.prototype.getDistancePoints = function getDistancePoints () {
|
37730 | return this._maxPtDist
|
37731 | };
|
37732 | BufferCurveMaximumDistanceFinder.prototype.interfaces_ = function interfaces_ () {
|
37733 | return []
|
37734 | };
|
37735 | BufferCurveMaximumDistanceFinder.prototype.getClass = function getClass () {
|
37736 | return BufferCurveMaximumDistanceFinder
|
37737 | };
|
37738 | staticAccessors$36.MaxPointDistanceFilter.get = function () { return MaxPointDistanceFilter };
|
37739 | staticAccessors$36.MaxMidpointDistanceFilter.get = function () { return MaxMidpointDistanceFilter };
|
37740 |
|
37741 | Object.defineProperties( BufferCurveMaximumDistanceFinder, staticAccessors$36 );
|
37742 |
|
37743 | var MaxPointDistanceFilter = function MaxPointDistanceFilter (geom) {
|
37744 | this._maxPtDist = new PointPairDistance();
|
37745 | this._minPtDist = new PointPairDistance();
|
37746 | this._geom = geom || null;
|
37747 | };
|
37748 | MaxPointDistanceFilter.prototype.filter = function filter (pt) {
|
37749 | this._minPtDist.initialize();
|
37750 | DistanceToPointFinder.computeDistance(this._geom, pt, this._minPtDist);
|
37751 | this._maxPtDist.setMaximum(this._minPtDist);
|
37752 | };
|
37753 | MaxPointDistanceFilter.prototype.getMaxPointDistance = function getMaxPointDistance () {
|
37754 | return this._maxPtDist
|
37755 | };
|
37756 | MaxPointDistanceFilter.prototype.interfaces_ = function interfaces_ () {
|
37757 | return [CoordinateFilter]
|
37758 | };
|
37759 | MaxPointDistanceFilter.prototype.getClass = function getClass () {
|
37760 | return MaxPointDistanceFilter
|
37761 | };
|
37762 |
|
37763 | var MaxMidpointDistanceFilter = function MaxMidpointDistanceFilter (geom) {
|
37764 | this._maxPtDist = new PointPairDistance();
|
37765 | this._minPtDist = new PointPairDistance();
|
37766 | this._geom = geom || null;
|
37767 | };
|
37768 | MaxMidpointDistanceFilter.prototype.filter = function filter (seq, index) {
|
37769 | if (index === 0) { return null }
|
37770 | var p0 = seq.getCoordinate(index - 1);
|
37771 | var p1 = seq.getCoordinate(index);
|
37772 | var midPt = new Coordinate((p0.x + p1.x) / 2, (p0.y + p1.y) / 2);
|
37773 | this._minPtDist.initialize();
|
37774 | DistanceToPointFinder.computeDistance(this._geom, midPt, this._minPtDist);
|
37775 | this._maxPtDist.setMaximum(this._minPtDist);
|
37776 | };
|
37777 | MaxMidpointDistanceFilter.prototype.isDone = function isDone () {
|
37778 | return false
|
37779 | };
|
37780 | MaxMidpointDistanceFilter.prototype.isGeometryChanged = function isGeometryChanged () {
|
37781 | return false
|
37782 | };
|
37783 | MaxMidpointDistanceFilter.prototype.getMaxPointDistance = function getMaxPointDistance () {
|
37784 | return this._maxPtDist
|
37785 | };
|
37786 | MaxMidpointDistanceFilter.prototype.interfaces_ = function interfaces_ () {
|
37787 | return [CoordinateSequenceFilter]
|
37788 | };
|
37789 | MaxMidpointDistanceFilter.prototype.getClass = function getClass () {
|
37790 | return MaxMidpointDistanceFilter
|
37791 | };
|
37792 |
|
37793 | var PolygonExtracter = function PolygonExtracter (comps) {
|
37794 | this._comps = comps || null;
|
37795 | };
|
37796 | PolygonExtracter.prototype.filter = function filter (geom) {
|
37797 | if (geom instanceof Polygon) { this._comps.add(geom); }
|
37798 | };
|
37799 | PolygonExtracter.prototype.interfaces_ = function interfaces_ () {
|
37800 | return [GeometryFilter]
|
37801 | };
|
37802 | PolygonExtracter.prototype.getClass = function getClass () {
|
37803 | return PolygonExtracter
|
37804 | };
|
37805 | PolygonExtracter.getPolygons = function getPolygons () {
|
37806 | if (arguments.length === 1) {
|
37807 | var geom = arguments[0];
|
37808 | return PolygonExtracter.getPolygons(geom, new ArrayList())
|
37809 | } else if (arguments.length === 2) {
|
37810 | var geom$1 = arguments[0];
|
37811 | var list = arguments[1];
|
37812 | if (geom$1 instanceof Polygon) {
|
37813 | list.add(geom$1);
|
37814 | } else if (geom$1 instanceof GeometryCollection) {
|
37815 | geom$1.apply(new PolygonExtracter(list));
|
37816 | }
|
37817 | return list
|
37818 | }
|
37819 | };
|
37820 |
|
37821 | var LinearComponentExtracter = function LinearComponentExtracter () {
|
37822 | this._lines = null;
|
37823 | this._isForcedToLineString = false;
|
37824 | if (arguments.length === 1) {
|
37825 | var lines = arguments[0];
|
37826 | this._lines = lines;
|
37827 | } else if (arguments.length === 2) {
|
37828 | var lines$1 = arguments[0];
|
37829 | var isForcedToLineString = arguments[1];
|
37830 | this._lines = lines$1;
|
37831 | this._isForcedToLineString = isForcedToLineString;
|
37832 | }
|
37833 | };
|
37834 | LinearComponentExtracter.prototype.filter = function filter (geom) {
|
37835 | if (this._isForcedToLineString && geom instanceof LinearRing) {
|
37836 | var line = geom.getFactory().createLineString(geom.getCoordinateSequence());
|
37837 | this._lines.add(line);
|
37838 | return null
|
37839 | }
|
37840 | if (geom instanceof LineString$1) { this._lines.add(geom); }
|
37841 | };
|
37842 | LinearComponentExtracter.prototype.setForceToLineString = function setForceToLineString (isForcedToLineString) {
|
37843 | this._isForcedToLineString = isForcedToLineString;
|
37844 | };
|
37845 | LinearComponentExtracter.prototype.interfaces_ = function interfaces_ () {
|
37846 | return [GeometryComponentFilter]
|
37847 | };
|
37848 | LinearComponentExtracter.prototype.getClass = function getClass () {
|
37849 | return LinearComponentExtracter
|
37850 | };
|
37851 | LinearComponentExtracter.getGeometry = function getGeometry () {
|
37852 | if (arguments.length === 1) {
|
37853 | var geom = arguments[0];
|
37854 | return geom.getFactory().buildGeometry(LinearComponentExtracter.getLines(geom))
|
37855 | } else if (arguments.length === 2) {
|
37856 | var geom$1 = arguments[0];
|
37857 | var forceToLineString = arguments[1];
|
37858 | return geom$1.getFactory().buildGeometry(LinearComponentExtracter.getLines(geom$1, forceToLineString))
|
37859 | }
|
37860 | };
|
37861 | LinearComponentExtracter.getLines = function getLines () {
|
37862 | if (arguments.length === 1) {
|
37863 | var geom = arguments[0];
|
37864 | return LinearComponentExtracter.getLines(geom, false)
|
37865 | } else if (arguments.length === 2) {
|
37866 | if (hasInterface(arguments[0], Collection) && hasInterface(arguments[1], Collection)) {
|
37867 | var geoms = arguments[0];
|
37868 | var lines$1 = arguments[1];
|
37869 | for (var i = geoms.iterator(); i.hasNext();) {
|
37870 | var g = i.next();
|
37871 | LinearComponentExtracter.getLines(g, lines$1);
|
37872 | }
|
37873 | return lines$1
|
37874 | } else if (arguments[0] instanceof Geometry && typeof arguments[1] === 'boolean') {
|
37875 | var geom$1 = arguments[0];
|
37876 | var forceToLineString = arguments[1];
|
37877 | var lines = new ArrayList();
|
37878 | geom$1.apply(new LinearComponentExtracter(lines, forceToLineString));
|
37879 | return lines
|
37880 | } else if (arguments[0] instanceof Geometry && hasInterface(arguments[1], Collection)) {
|
37881 | var geom$2 = arguments[0];
|
37882 | var lines$2 = arguments[1];
|
37883 | if (geom$2 instanceof LineString$1) {
|
37884 | lines$2.add(geom$2);
|
37885 | } else {
|
37886 | geom$2.apply(new LinearComponentExtracter(lines$2));
|
37887 | }
|
37888 | return lines$2
|
37889 | }
|
37890 | } else if (arguments.length === 3) {
|
37891 | if (typeof arguments[2] === 'boolean' && (hasInterface(arguments[0], Collection) && hasInterface(arguments[1], Collection))) {
|
37892 | var geoms$1 = arguments[0];
|
37893 | var lines$3 = arguments[1];
|
37894 | var forceToLineString$1 = arguments[2];
|
37895 | for (var i$1 = geoms$1.iterator(); i$1.hasNext();) {
|
37896 | var g$1 = i$1.next();
|
37897 | LinearComponentExtracter.getLines(g$1, lines$3, forceToLineString$1);
|
37898 | }
|
37899 | return lines$3
|
37900 | } else if (typeof arguments[2] === 'boolean' && (arguments[0] instanceof Geometry && hasInterface(arguments[1], Collection))) {
|
37901 | var geom$3 = arguments[0];
|
37902 | var lines$4 = arguments[1];
|
37903 | var forceToLineString$2 = arguments[2];
|
37904 | geom$3.apply(new LinearComponentExtracter(lines$4, forceToLineString$2));
|
37905 | return lines$4
|
37906 | }
|
37907 | }
|
37908 | };
|
37909 |
|
37910 | var PointLocator = function PointLocator () {
|
37911 | this._boundaryRule = BoundaryNodeRule.OGC_SFS_BOUNDARY_RULE;
|
37912 | this._isIn = null;
|
37913 | this._numBoundaries = null;
|
37914 | if (arguments.length === 0) {} else if (arguments.length === 1) {
|
37915 | var boundaryRule = arguments[0];
|
37916 | if (boundaryRule === null) { throw new IllegalArgumentException('Rule must be non-null') }
|
37917 | this._boundaryRule = boundaryRule;
|
37918 | }
|
37919 | };
|
37920 | PointLocator.prototype.locateInternal = function locateInternal () {
|
37921 | var this$1 = this;
|
37922 |
|
37923 | if (arguments[0] instanceof Coordinate && arguments[1] instanceof Polygon) {
|
37924 | var p = arguments[0];
|
37925 | var poly = arguments[1];
|
37926 | if (poly.isEmpty()) { return Location.EXTERIOR }
|
37927 | var shell = poly.getExteriorRing();
|
37928 | var shellLoc = this.locateInPolygonRing(p, shell);
|
37929 | if (shellLoc === Location.EXTERIOR) { return Location.EXTERIOR }
|
37930 | if (shellLoc === Location.BOUNDARY) { return Location.BOUNDARY }
|
37931 | for (var i = 0; i < poly.getNumInteriorRing(); i++) {
|
37932 | var hole = poly.getInteriorRingN(i);
|
37933 | var holeLoc = this$1.locateInPolygonRing(p, hole);
|
37934 | if (holeLoc === Location.INTERIOR) { return Location.EXTERIOR }
|
37935 | if (holeLoc === Location.BOUNDARY) { return Location.BOUNDARY }
|
37936 | }
|
37937 | return Location.INTERIOR
|
37938 | } else if (arguments[0] instanceof Coordinate && arguments[1] instanceof LineString$1) {
|
37939 | var p$1 = arguments[0];
|
37940 | var l = arguments[1];
|
37941 | if (!l.getEnvelopeInternal().intersects(p$1)) { return Location.EXTERIOR }
|
37942 | var pt = l.getCoordinates();
|
37943 | if (!l.isClosed()) {
|
37944 | if (p$1.equals(pt[0]) || p$1.equals(pt[pt.length - 1])) {
|
37945 | return Location.BOUNDARY
|
37946 | }
|
37947 | }
|
37948 | if (CGAlgorithms.isOnLine(p$1, pt)) { return Location.INTERIOR }
|
37949 | return Location.EXTERIOR
|
37950 | } else if (arguments[0] instanceof Coordinate && arguments[1] instanceof Point) {
|
37951 | var p$2 = arguments[0];
|
37952 | var pt$1 = arguments[1];
|
37953 | var ptCoord = pt$1.getCoordinate();
|
37954 | if (ptCoord.equals2D(p$2)) { return Location.INTERIOR }
|
37955 | return Location.EXTERIOR
|
37956 | }
|
37957 | };
|
37958 | PointLocator.prototype.locateInPolygonRing = function locateInPolygonRing (p, ring) {
|
37959 | if (!ring.getEnvelopeInternal().intersects(p)) { return Location.EXTERIOR }
|
37960 | return CGAlgorithms.locatePointInRing(p, ring.getCoordinates())
|
37961 | };
|
37962 | PointLocator.prototype.intersects = function intersects (p, geom) {
|
37963 | return this.locate(p, geom) !== Location.EXTERIOR
|
37964 | };
|
37965 | PointLocator.prototype.updateLocationInfo = function updateLocationInfo (loc) {
|
37966 | if (loc === Location.INTERIOR) { this._isIn = true; }
|
37967 | if (loc === Location.BOUNDARY) { this._numBoundaries++; }
|
37968 | };
|
37969 | PointLocator.prototype.computeLocation = function computeLocation (p, geom) {
|
37970 | var this$1 = this;
|
37971 |
|
37972 | if (geom instanceof Point) {
|
37973 | this.updateLocationInfo(this.locateInternal(p, geom));
|
37974 | }
|
37975 | if (geom instanceof LineString$1) {
|
37976 | this.updateLocationInfo(this.locateInternal(p, geom));
|
37977 | } else if (geom instanceof Polygon) {
|
37978 | this.updateLocationInfo(this.locateInternal(p, geom));
|
37979 | } else if (geom instanceof MultiLineString) {
|
37980 | var ml = geom;
|
37981 | for (var i = 0; i < ml.getNumGeometries(); i++) {
|
37982 | var l = ml.getGeometryN(i);
|
37983 | this$1.updateLocationInfo(this$1.locateInternal(p, l));
|
37984 | }
|
37985 | } else if (geom instanceof MultiPolygon) {
|
37986 | var mpoly = geom;
|
37987 | for (var i$1 = 0; i$1 < mpoly.getNumGeometries(); i$1++) {
|
37988 | var poly = mpoly.getGeometryN(i$1);
|
37989 | this$1.updateLocationInfo(this$1.locateInternal(p, poly));
|
37990 | }
|
37991 | } else if (geom instanceof GeometryCollection) {
|
37992 | var geomi = new GeometryCollectionIterator(geom);
|
37993 | while (geomi.hasNext()) {
|
37994 | var g2 = geomi.next();
|
37995 | if (g2 !== geom) { this$1.computeLocation(p, g2); }
|
37996 | }
|
37997 | }
|
37998 | };
|
37999 | PointLocator.prototype.locate = function locate (p, geom) {
|
38000 | if (geom.isEmpty()) { return Location.EXTERIOR }
|
38001 | if (geom instanceof LineString$1) {
|
38002 | return this.locateInternal(p, geom)
|
38003 | } else if (geom instanceof Polygon) {
|
38004 | return this.locateInternal(p, geom)
|
38005 | }
|
38006 | this._isIn = false;
|
38007 | this._numBoundaries = 0;
|
38008 | this.computeLocation(p, geom);
|
38009 | if (this._boundaryRule.isInBoundary(this._numBoundaries)) { return Location.BOUNDARY }
|
38010 | if (this._numBoundaries > 0 || this._isIn) { return Location.INTERIOR }
|
38011 | return Location.EXTERIOR
|
38012 | };
|
38013 | PointLocator.prototype.interfaces_ = function interfaces_ () {
|
38014 | return []
|
38015 | };
|
38016 | PointLocator.prototype.getClass = function getClass () {
|
38017 | return PointLocator
|
38018 | };
|
38019 |
|
38020 | var GeometryLocation = function GeometryLocation () {
|
38021 | this._component = null;
|
38022 | this._segIndex = null;
|
38023 | this._pt = null;
|
38024 | if (arguments.length === 2) {
|
38025 | var component = arguments[0];
|
38026 | var pt = arguments[1];
|
38027 | GeometryLocation.call(this, component, GeometryLocation.INSIDE_AREA, pt);
|
38028 | } else if (arguments.length === 3) {
|
38029 | var component$1 = arguments[0];
|
38030 | var segIndex = arguments[1];
|
38031 | var pt$1 = arguments[2];
|
38032 | this._component = component$1;
|
38033 | this._segIndex = segIndex;
|
38034 | this._pt = pt$1;
|
38035 | }
|
38036 | };
|
38037 |
|
38038 | var staticAccessors$38 = { INSIDE_AREA: { configurable: true } };
|
38039 | GeometryLocation.prototype.isInsideArea = function isInsideArea () {
|
38040 | return this._segIndex === GeometryLocation.INSIDE_AREA
|
38041 | };
|
38042 | GeometryLocation.prototype.getCoordinate = function getCoordinate () {
|
38043 | return this._pt
|
38044 | };
|
38045 | GeometryLocation.prototype.getGeometryComponent = function getGeometryComponent () {
|
38046 | return this._component
|
38047 | };
|
38048 | GeometryLocation.prototype.getSegmentIndex = function getSegmentIndex () {
|
38049 | return this._segIndex
|
38050 | };
|
38051 | GeometryLocation.prototype.interfaces_ = function interfaces_ () {
|
38052 | return []
|
38053 | };
|
38054 | GeometryLocation.prototype.getClass = function getClass () {
|
38055 | return GeometryLocation
|
38056 | };
|
38057 | staticAccessors$38.INSIDE_AREA.get = function () { return -1 };
|
38058 |
|
38059 | Object.defineProperties( GeometryLocation, staticAccessors$38 );
|
38060 |
|
38061 | var PointExtracter = function PointExtracter (pts) {
|
38062 | this._pts = pts || null;
|
38063 | };
|
38064 | PointExtracter.prototype.filter = function filter (geom) {
|
38065 | if (geom instanceof Point) { this._pts.add(geom); }
|
38066 | };
|
38067 | PointExtracter.prototype.interfaces_ = function interfaces_ () {
|
38068 | return [GeometryFilter]
|
38069 | };
|
38070 | PointExtracter.prototype.getClass = function getClass () {
|
38071 | return PointExtracter
|
38072 | };
|
38073 | PointExtracter.getPoints = function getPoints () {
|
38074 | if (arguments.length === 1) {
|
38075 | var geom = arguments[0];
|
38076 | if (geom instanceof Point) {
|
38077 | return Collections.singletonList(geom)
|
38078 | }
|
38079 | return PointExtracter.getPoints(geom, new ArrayList())
|
38080 | } else if (arguments.length === 2) {
|
38081 | var geom$1 = arguments[0];
|
38082 | var list = arguments[1];
|
38083 | if (geom$1 instanceof Point) {
|
38084 | list.add(geom$1);
|
38085 | } else if (geom$1 instanceof GeometryCollection) {
|
38086 | geom$1.apply(new PointExtracter(list));
|
38087 | }
|
38088 | return list
|
38089 | }
|
38090 | };
|
38091 |
|
38092 | var ConnectedElementLocationFilter = function ConnectedElementLocationFilter () {
|
38093 | this._locations = null;
|
38094 | var locations = arguments[0];
|
38095 | this._locations = locations;
|
38096 | };
|
38097 | ConnectedElementLocationFilter.prototype.filter = function filter (geom) {
|
38098 | if (geom instanceof Point || geom instanceof LineString$1 || geom instanceof Polygon) { this._locations.add(new GeometryLocation(geom, 0, geom.getCoordinate())); }
|
38099 | };
|
38100 | ConnectedElementLocationFilter.prototype.interfaces_ = function interfaces_ () {
|
38101 | return [GeometryFilter]
|
38102 | };
|
38103 | ConnectedElementLocationFilter.prototype.getClass = function getClass () {
|
38104 | return ConnectedElementLocationFilter
|
38105 | };
|
38106 | ConnectedElementLocationFilter.getLocations = function getLocations (geom) {
|
38107 | var locations = new ArrayList();
|
38108 | geom.apply(new ConnectedElementLocationFilter(locations));
|
38109 | return locations
|
38110 | };
|
38111 |
|
38112 | var DistanceOp = function DistanceOp () {
|
38113 | this._geom = null;
|
38114 | this._terminateDistance = 0.0;
|
38115 | this._ptLocator = new PointLocator();
|
38116 | this._minDistanceLocation = null;
|
38117 | this._minDistance = Double.MAX_VALUE;
|
38118 | if (arguments.length === 2) {
|
38119 | var g0 = arguments[0];
|
38120 | var g1 = arguments[1];
|
38121 | this._geom = [g0, g1];
|
38122 | this._terminateDistance = 0.0;
|
38123 | } else if (arguments.length === 3) {
|
38124 | var g0$1 = arguments[0];
|
38125 | var g1$1 = arguments[1];
|
38126 | var terminateDistance = arguments[2];
|
38127 | this._geom = new Array(2).fill(null);
|
38128 | this._geom[0] = g0$1;
|
38129 | this._geom[1] = g1$1;
|
38130 | this._terminateDistance = terminateDistance;
|
38131 | }
|
38132 | };
|
38133 | DistanceOp.prototype.computeContainmentDistance = function computeContainmentDistance () {
|
38134 | var this$1 = this;
|
38135 |
|
38136 | if (arguments.length === 0) {
|
38137 | var locPtPoly = new Array(2).fill(null);
|
38138 | this.computeContainmentDistance(0, locPtPoly);
|
38139 | if (this._minDistance <= this._terminateDistance) { return null }
|
38140 | this.computeContainmentDistance(1, locPtPoly);
|
38141 | } else if (arguments.length === 2) {
|
38142 | var polyGeomIndex = arguments[0];
|
38143 | var locPtPoly$1 = arguments[1];
|
38144 | var locationsIndex = 1 - polyGeomIndex;
|
38145 | var polys = PolygonExtracter.getPolygons(this._geom[polyGeomIndex]);
|
38146 | if (polys.size() > 0) {
|
38147 | var insideLocs = ConnectedElementLocationFilter.getLocations(this._geom[locationsIndex]);
|
38148 | this.computeContainmentDistance(insideLocs, polys, locPtPoly$1);
|
38149 | if (this._minDistance <= this._terminateDistance) {
|
38150 | this._minDistanceLocation[locationsIndex] = locPtPoly$1[0];
|
38151 | this._minDistanceLocation[polyGeomIndex] = locPtPoly$1[1];
|
38152 | return null
|
38153 | }
|
38154 | }
|
38155 | } else if (arguments.length === 3) {
|
38156 | if (arguments[2] instanceof Array && (hasInterface(arguments[0], List) && hasInterface(arguments[1], List))) {
|
38157 | var locs = arguments[0];
|
38158 | var polys$1 = arguments[1];
|
38159 | var locPtPoly$2 = arguments[2];
|
38160 | for (var i = 0; i < locs.size(); i++) {
|
38161 | var loc = locs.get(i);
|
38162 | for (var j = 0; j < polys$1.size(); j++) {
|
38163 | this$1.computeContainmentDistance(loc, polys$1.get(j), locPtPoly$2);
|
38164 | if (this$1._minDistance <= this$1._terminateDistance) { return null }
|
38165 | }
|
38166 | }
|
38167 | } else if (arguments[2] instanceof Array && (arguments[0] instanceof GeometryLocation && arguments[1] instanceof Polygon)) {
|
38168 | var ptLoc = arguments[0];
|
38169 | var poly = arguments[1];
|
38170 | var locPtPoly$3 = arguments[2];
|
38171 | var pt = ptLoc.getCoordinate();
|
38172 | if (Location.EXTERIOR !== this._ptLocator.locate(pt, poly)) {
|
38173 | this._minDistance = 0.0;
|
38174 | locPtPoly$3[0] = ptLoc;
|
38175 | locPtPoly$3[1] = new GeometryLocation(poly, pt);
|
38176 |
|
38177 | return null
|
38178 | }
|
38179 | }
|
38180 | }
|
38181 | };
|
38182 | DistanceOp.prototype.computeMinDistanceLinesPoints = function computeMinDistanceLinesPoints (lines, points, locGeom) {
|
38183 | var this$1 = this;
|
38184 |
|
38185 | for (var i = 0; i < lines.size(); i++) {
|
38186 | var line = lines.get(i);
|
38187 | for (var j = 0; j < points.size(); j++) {
|
38188 | var pt = points.get(j);
|
38189 | this$1.computeMinDistance(line, pt, locGeom);
|
38190 | if (this$1._minDistance <= this$1._terminateDistance) { return null }
|
38191 | }
|
38192 | }
|
38193 | };
|
38194 | DistanceOp.prototype.computeFacetDistance = function computeFacetDistance () {
|
38195 | var locGeom = new Array(2).fill(null);
|
38196 | var lines0 = LinearComponentExtracter.getLines(this._geom[0]);
|
38197 | var lines1 = LinearComponentExtracter.getLines(this._geom[1]);
|
38198 | var pts0 = PointExtracter.getPoints(this._geom[0]);
|
38199 | var pts1 = PointExtracter.getPoints(this._geom[1]);
|
38200 | this.computeMinDistanceLines(lines0, lines1, locGeom);
|
38201 | this.updateMinDistance(locGeom, false);
|
38202 | if (this._minDistance <= this._terminateDistance) { return null }
|
38203 | locGeom[0] = null;
|
38204 | locGeom[1] = null;
|
38205 | this.computeMinDistanceLinesPoints(lines0, pts1, locGeom);
|
38206 | this.updateMinDistance(locGeom, false);
|
38207 | if (this._minDistance <= this._terminateDistance) { return null }
|
38208 | locGeom[0] = null;
|
38209 | locGeom[1] = null;
|
38210 | this.computeMinDistanceLinesPoints(lines1, pts0, locGeom);
|
38211 | this.updateMinDistance(locGeom, true);
|
38212 | if (this._minDistance <= this._terminateDistance) { return null }
|
38213 | locGeom[0] = null;
|
38214 | locGeom[1] = null;
|
38215 | this.computeMinDistancePoints(pts0, pts1, locGeom);
|
38216 | this.updateMinDistance(locGeom, false);
|
38217 | };
|
38218 | DistanceOp.prototype.nearestLocations = function nearestLocations () {
|
38219 | this.computeMinDistance();
|
38220 | return this._minDistanceLocation
|
38221 | };
|
38222 | DistanceOp.prototype.updateMinDistance = function updateMinDistance (locGeom, flip) {
|
38223 | if (locGeom[0] === null) { return null }
|
38224 | if (flip) {
|
38225 | this._minDistanceLocation[0] = locGeom[1];
|
38226 | this._minDistanceLocation[1] = locGeom[0];
|
38227 | } else {
|
38228 | this._minDistanceLocation[0] = locGeom[0];
|
38229 | this._minDistanceLocation[1] = locGeom[1];
|
38230 | }
|
38231 | };
|
38232 | DistanceOp.prototype.nearestPoints = function nearestPoints () {
|
38233 | this.computeMinDistance();
|
38234 | var nearestPts = [this._minDistanceLocation[0].getCoordinate(), this._minDistanceLocation[1].getCoordinate()];
|
38235 | return nearestPts
|
38236 | };
|
38237 | DistanceOp.prototype.computeMinDistance = function computeMinDistance () {
|
38238 | var this$1 = this;
|
38239 |
|
38240 | if (arguments.length === 0) {
|
38241 | if (this._minDistanceLocation !== null) { return null }
|
38242 | this._minDistanceLocation = new Array(2).fill(null);
|
38243 | this.computeContainmentDistance();
|
38244 | if (this._minDistance <= this._terminateDistance) { return null }
|
38245 | this.computeFacetDistance();
|
38246 | } else if (arguments.length === 3) {
|
38247 | if (arguments[2] instanceof Array && (arguments[0] instanceof LineString$1 && arguments[1] instanceof Point)) {
|
38248 | var line = arguments[0];
|
38249 | var pt = arguments[1];
|
38250 | var locGeom = arguments[2];
|
38251 | if (line.getEnvelopeInternal().distance(pt.getEnvelopeInternal()) > this._minDistance) { return null }
|
38252 | var coord0 = line.getCoordinates();
|
38253 | var coord = pt.getCoordinate();
|
38254 | for (var i = 0; i < coord0.length - 1; i++) {
|
38255 | var dist = CGAlgorithms.distancePointLine(coord, coord0[i], coord0[i + 1]);
|
38256 | if (dist < this$1._minDistance) {
|
38257 | this$1._minDistance = dist;
|
38258 | var seg = new LineSegment(coord0[i], coord0[i + 1]);
|
38259 | var segClosestPoint = seg.closestPoint(coord);
|
38260 | locGeom[0] = new GeometryLocation(line, i, segClosestPoint);
|
38261 | locGeom[1] = new GeometryLocation(pt, 0, coord);
|
38262 | }
|
38263 | if (this$1._minDistance <= this$1._terminateDistance) { return null }
|
38264 | }
|
38265 | } else if (arguments[2] instanceof Array && (arguments[0] instanceof LineString$1 && arguments[1] instanceof LineString$1)) {
|
38266 | var line0 = arguments[0];
|
38267 | var line1 = arguments[1];
|
38268 | var locGeom$1 = arguments[2];
|
38269 | if (line0.getEnvelopeInternal().distance(line1.getEnvelopeInternal()) > this._minDistance) { return null }
|
38270 | var coord0$1 = line0.getCoordinates();
|
38271 | var coord1 = line1.getCoordinates();
|
38272 | for (var i$1 = 0; i$1 < coord0$1.length - 1; i$1++) {
|
38273 | for (var j = 0; j < coord1.length - 1; j++) {
|
38274 | var dist$1 = CGAlgorithms.distanceLineLine(coord0$1[i$1], coord0$1[i$1 + 1], coord1[j], coord1[j + 1]);
|
38275 | if (dist$1 < this$1._minDistance) {
|
38276 | this$1._minDistance = dist$1;
|
38277 | var seg0 = new LineSegment(coord0$1[i$1], coord0$1[i$1 + 1]);
|
38278 | var seg1 = new LineSegment(coord1[j], coord1[j + 1]);
|
38279 | var closestPt = seg0.closestPoints(seg1);
|
38280 | locGeom$1[0] = new GeometryLocation(line0, i$1, closestPt[0]);
|
38281 | locGeom$1[1] = new GeometryLocation(line1, j, closestPt[1]);
|
38282 | }
|
38283 | if (this$1._minDistance <= this$1._terminateDistance) { return null }
|
38284 | }
|
38285 | }
|
38286 | }
|
38287 | }
|
38288 | };
|
38289 | DistanceOp.prototype.computeMinDistancePoints = function computeMinDistancePoints (points0, points1, locGeom) {
|
38290 | var this$1 = this;
|
38291 |
|
38292 | for (var i = 0; i < points0.size(); i++) {
|
38293 | var pt0 = points0.get(i);
|
38294 | for (var j = 0; j < points1.size(); j++) {
|
38295 | var pt1 = points1.get(j);
|
38296 | var dist = pt0.getCoordinate().distance(pt1.getCoordinate());
|
38297 | if (dist < this$1._minDistance) {
|
38298 | this$1._minDistance = dist;
|
38299 | locGeom[0] = new GeometryLocation(pt0, 0, pt0.getCoordinate());
|
38300 | locGeom[1] = new GeometryLocation(pt1, 0, pt1.getCoordinate());
|
38301 | }
|
38302 | if (this$1._minDistance <= this$1._terminateDistance) { return null }
|
38303 | }
|
38304 | }
|
38305 | };
|
38306 | DistanceOp.prototype.distance = function distance () {
|
38307 | if (this._geom[0] === null || this._geom[1] === null) { throw new IllegalArgumentException('null geometries are not supported') }
|
38308 | if (this._geom[0].isEmpty() || this._geom[1].isEmpty()) { return 0.0 }
|
38309 | this.computeMinDistance();
|
38310 | return this._minDistance
|
38311 | };
|
38312 | DistanceOp.prototype.computeMinDistanceLines = function computeMinDistanceLines (lines0, lines1, locGeom) {
|
38313 | var this$1 = this;
|
38314 |
|
38315 | for (var i = 0; i < lines0.size(); i++) {
|
38316 | var line0 = lines0.get(i);
|
38317 | for (var j = 0; j < lines1.size(); j++) {
|
38318 | var line1 = lines1.get(j);
|
38319 | this$1.computeMinDistance(line0, line1, locGeom);
|
38320 | if (this$1._minDistance <= this$1._terminateDistance) { return null }
|
38321 | }
|
38322 | }
|
38323 | };
|
38324 | DistanceOp.prototype.interfaces_ = function interfaces_ () {
|
38325 | return []
|
38326 | };
|
38327 | DistanceOp.prototype.getClass = function getClass () {
|
38328 | return DistanceOp
|
38329 | };
|
38330 | DistanceOp.distance = function distance (g0, g1) {
|
38331 | var distOp = new DistanceOp(g0, g1);
|
38332 | return distOp.distance()
|
38333 | };
|
38334 | DistanceOp.isWithinDistance = function isWithinDistance (g0, g1, distance) {
|
38335 | var distOp = new DistanceOp(g0, g1, distance);
|
38336 | return distOp.distance() <= distance
|
38337 | };
|
38338 | DistanceOp.nearestPoints = function nearestPoints (g0, g1) {
|
38339 | var distOp = new DistanceOp(g0, g1);
|
38340 | return distOp.nearestPoints()
|
38341 | };
|
38342 |
|
38343 | var PointPairDistance$2 = function PointPairDistance () {
|
38344 | this._pt = [new Coordinate(), new Coordinate()];
|
38345 | this._distance = Double.NaN;
|
38346 | this._isNull = true;
|
38347 | };
|
38348 | PointPairDistance$2.prototype.getCoordinates = function getCoordinates () {
|
38349 | return this._pt
|
38350 | };
|
38351 | PointPairDistance$2.prototype.getCoordinate = function getCoordinate (i) {
|
38352 | return this._pt[i]
|
38353 | };
|
38354 | PointPairDistance$2.prototype.setMinimum = function setMinimum () {
|
38355 | if (arguments.length === 1) {
|
38356 | var ptDist = arguments[0];
|
38357 | this.setMinimum(ptDist._pt[0], ptDist._pt[1]);
|
38358 | } else if (arguments.length === 2) {
|
38359 | var p0 = arguments[0];
|
38360 | var p1 = arguments[1];
|
38361 | if (this._isNull) {
|
38362 | this.initialize(p0, p1);
|
38363 | return null
|
38364 | }
|
38365 | var dist = p0.distance(p1);
|
38366 | if (dist < this._distance) { this.initialize(p0, p1, dist); }
|
38367 | }
|
38368 | };
|
38369 | PointPairDistance$2.prototype.initialize = function initialize () {
|
38370 | if (arguments.length === 0) {
|
38371 | this._isNull = true;
|
38372 | } else if (arguments.length === 2) {
|
38373 | var p0 = arguments[0];
|
38374 | var p1 = arguments[1];
|
38375 | this._pt[0].setCoordinate(p0);
|
38376 | this._pt[1].setCoordinate(p1);
|
38377 | this._distance = p0.distance(p1);
|
38378 | this._isNull = false;
|
38379 | } else if (arguments.length === 3) {
|
38380 | var p0$1 = arguments[0];
|
38381 | var p1$1 = arguments[1];
|
38382 | var distance = arguments[2];
|
38383 | this._pt[0].setCoordinate(p0$1);
|
38384 | this._pt[1].setCoordinate(p1$1);
|
38385 | this._distance = distance;
|
38386 | this._isNull = false;
|
38387 | }
|
38388 | };
|
38389 | PointPairDistance$2.prototype.toString = function toString () {
|
38390 | return WKTWriter.toLineString(this._pt[0], this._pt[1])
|
38391 | };
|
38392 | PointPairDistance$2.prototype.getDistance = function getDistance () {
|
38393 | return this._distance
|
38394 | };
|
38395 | PointPairDistance$2.prototype.setMaximum = function setMaximum () {
|
38396 | if (arguments.length === 1) {
|
38397 | var ptDist = arguments[0];
|
38398 | this.setMaximum(ptDist._pt[0], ptDist._pt[1]);
|
38399 | } else if (arguments.length === 2) {
|
38400 | var p0 = arguments[0];
|
38401 | var p1 = arguments[1];
|
38402 | if (this._isNull) {
|
38403 | this.initialize(p0, p1);
|
38404 | return null
|
38405 | }
|
38406 | var dist = p0.distance(p1);
|
38407 | if (dist > this._distance) { this.initialize(p0, p1, dist); }
|
38408 | }
|
38409 | };
|
38410 | PointPairDistance$2.prototype.interfaces_ = function interfaces_ () {
|
38411 | return []
|
38412 | };
|
38413 | PointPairDistance$2.prototype.getClass = function getClass () {
|
38414 | return PointPairDistance$2
|
38415 | };
|
38416 |
|
38417 | var DistanceToPoint = function DistanceToPoint () {};
|
38418 |
|
38419 | DistanceToPoint.prototype.interfaces_ = function interfaces_ () {
|
38420 | return []
|
38421 | };
|
38422 | DistanceToPoint.prototype.getClass = function getClass () {
|
38423 | return DistanceToPoint
|
38424 | };
|
38425 | DistanceToPoint.computeDistance = function computeDistance () {
|
38426 | if (arguments[2] instanceof PointPairDistance$2 && (arguments[0] instanceof LineString$1 && arguments[1] instanceof Coordinate)) {
|
38427 | var line = arguments[0];
|
38428 | var pt = arguments[1];
|
38429 | var ptDist = arguments[2];
|
38430 | var tempSegment = new LineSegment();
|
38431 | var coords = line.getCoordinates();
|
38432 | for (var i = 0; i < coords.length - 1; i++) {
|
38433 | tempSegment.setCoordinates(coords[i], coords[i + 1]);
|
38434 | var closestPt = tempSegment.closestPoint(pt);
|
38435 | ptDist.setMinimum(closestPt, pt);
|
38436 | }
|
38437 | } else if (arguments[2] instanceof PointPairDistance$2 && (arguments[0] instanceof Polygon && arguments[1] instanceof Coordinate)) {
|
38438 | var poly = arguments[0];
|
38439 | var pt$1 = arguments[1];
|
38440 | var ptDist$1 = arguments[2];
|
38441 | DistanceToPoint.computeDistance(poly.getExteriorRing(), pt$1, ptDist$1);
|
38442 | for (var i$1 = 0; i$1 < poly.getNumInteriorRing(); i$1++) {
|
38443 | DistanceToPoint.computeDistance(poly.getInteriorRingN(i$1), pt$1, ptDist$1);
|
38444 | }
|
38445 | } else if (arguments[2] instanceof PointPairDistance$2 && (arguments[0] instanceof Geometry && arguments[1] instanceof Coordinate)) {
|
38446 | var geom = arguments[0];
|
38447 | var pt$2 = arguments[1];
|
38448 | var ptDist$2 = arguments[2];
|
38449 | if (geom instanceof LineString$1) {
|
38450 | DistanceToPoint.computeDistance(geom, pt$2, ptDist$2);
|
38451 | } else if (geom instanceof Polygon) {
|
38452 | DistanceToPoint.computeDistance(geom, pt$2, ptDist$2);
|
38453 | } else if (geom instanceof GeometryCollection) {
|
38454 | var gc = geom;
|
38455 | for (var i$2 = 0; i$2 < gc.getNumGeometries(); i$2++) {
|
38456 | var g = gc.getGeometryN(i$2);
|
38457 | DistanceToPoint.computeDistance(g, pt$2, ptDist$2);
|
38458 | }
|
38459 | } else {
|
38460 | ptDist$2.setMinimum(geom.getCoordinate(), pt$2);
|
38461 | }
|
38462 | } else if (arguments[2] instanceof PointPairDistance$2 && (arguments[0] instanceof LineSegment && arguments[1] instanceof Coordinate)) {
|
38463 | var segment = arguments[0];
|
38464 | var pt$3 = arguments[1];
|
38465 | var ptDist$3 = arguments[2];
|
38466 | var closestPt$1 = segment.closestPoint(pt$3);
|
38467 | ptDist$3.setMinimum(closestPt$1, pt$3);
|
38468 | }
|
38469 | };
|
38470 |
|
38471 | var DiscreteHausdorffDistance = function DiscreteHausdorffDistance () {
|
38472 | this._g0 = null;
|
38473 | this._g1 = null;
|
38474 | this._ptDist = new PointPairDistance$2();
|
38475 | this._densifyFrac = 0.0;
|
38476 | var g0 = arguments[0];
|
38477 | var g1 = arguments[1];
|
38478 | this._g0 = g0;
|
38479 | this._g1 = g1;
|
38480 | };
|
38481 |
|
38482 | var staticAccessors$39 = { MaxPointDistanceFilter: { configurable: true },MaxDensifiedByFractionDistanceFilter: { configurable: true } };
|
38483 | DiscreteHausdorffDistance.prototype.getCoordinates = function getCoordinates () {
|
38484 | return this._ptDist.getCoordinates()
|
38485 | };
|
38486 | DiscreteHausdorffDistance.prototype.setDensifyFraction = function setDensifyFraction (densifyFrac) {
|
38487 | if (densifyFrac > 1.0 || densifyFrac <= 0.0) { throw new IllegalArgumentException('Fraction is not in range (0.0 - 1.0]') }
|
38488 | this._densifyFrac = densifyFrac;
|
38489 | };
|
38490 | DiscreteHausdorffDistance.prototype.compute = function compute (g0, g1) {
|
38491 | this.computeOrientedDistance(g0, g1, this._ptDist);
|
38492 | this.computeOrientedDistance(g1, g0, this._ptDist);
|
38493 | };
|
38494 | DiscreteHausdorffDistance.prototype.distance = function distance () {
|
38495 | this.compute(this._g0, this._g1);
|
38496 | return this._ptDist.getDistance()
|
38497 | };
|
38498 | DiscreteHausdorffDistance.prototype.computeOrientedDistance = function computeOrientedDistance (discreteGeom, geom, ptDist) {
|
38499 | var distFilter = new MaxPointDistanceFilter$1(geom);
|
38500 | discreteGeom.apply(distFilter);
|
38501 | ptDist.setMaximum(distFilter.getMaxPointDistance());
|
38502 | if (this._densifyFrac > 0) {
|
38503 | var fracFilter = new MaxDensifiedByFractionDistanceFilter(geom, this._densifyFrac);
|
38504 | discreteGeom.apply(fracFilter);
|
38505 | ptDist.setMaximum(fracFilter.getMaxPointDistance());
|
38506 | }
|
38507 | };
|
38508 | DiscreteHausdorffDistance.prototype.orientedDistance = function orientedDistance () {
|
38509 | this.computeOrientedDistance(this._g0, this._g1, this._ptDist);
|
38510 | return this._ptDist.getDistance()
|
38511 | };
|
38512 | DiscreteHausdorffDistance.prototype.interfaces_ = function interfaces_ () {
|
38513 | return []
|
38514 | };
|
38515 | DiscreteHausdorffDistance.prototype.getClass = function getClass () {
|
38516 | return DiscreteHausdorffDistance
|
38517 | };
|
38518 | DiscreteHausdorffDistance.distance = function distance () {
|
38519 | if (arguments.length === 2) {
|
38520 | var g0 = arguments[0];
|
38521 | var g1 = arguments[1];
|
38522 | var dist = new DiscreteHausdorffDistance(g0, g1);
|
38523 | return dist.distance()
|
38524 | } else if (arguments.length === 3) {
|
38525 | var g0$1 = arguments[0];
|
38526 | var g1$1 = arguments[1];
|
38527 | var densifyFrac = arguments[2];
|
38528 | var dist$1 = new DiscreteHausdorffDistance(g0$1, g1$1);
|
38529 | dist$1.setDensifyFraction(densifyFrac);
|
38530 | return dist$1.distance()
|
38531 | }
|
38532 | };
|
38533 | staticAccessors$39.MaxPointDistanceFilter.get = function () { return MaxPointDistanceFilter$1 };
|
38534 | staticAccessors$39.MaxDensifiedByFractionDistanceFilter.get = function () { return MaxDensifiedByFractionDistanceFilter };
|
38535 |
|
38536 | Object.defineProperties( DiscreteHausdorffDistance, staticAccessors$39 );
|
38537 |
|
38538 | var MaxPointDistanceFilter$1 = function MaxPointDistanceFilter () {
|
38539 | this._maxPtDist = new PointPairDistance$2();
|
38540 | this._minPtDist = new PointPairDistance$2();
|
38541 | this._euclideanDist = new DistanceToPoint();
|
38542 | this._geom = null;
|
38543 | var geom = arguments[0];
|
38544 | this._geom = geom;
|
38545 | };
|
38546 | MaxPointDistanceFilter$1.prototype.filter = function filter (pt) {
|
38547 | this._minPtDist.initialize();
|
38548 | DistanceToPoint.computeDistance(this._geom, pt, this._minPtDist);
|
38549 | this._maxPtDist.setMaximum(this._minPtDist);
|
38550 | };
|
38551 | MaxPointDistanceFilter$1.prototype.getMaxPointDistance = function getMaxPointDistance () {
|
38552 | return this._maxPtDist
|
38553 | };
|
38554 | MaxPointDistanceFilter$1.prototype.interfaces_ = function interfaces_ () {
|
38555 | return [CoordinateFilter]
|
38556 | };
|
38557 | MaxPointDistanceFilter$1.prototype.getClass = function getClass () {
|
38558 | return MaxPointDistanceFilter$1
|
38559 | };
|
38560 |
|
38561 | var MaxDensifiedByFractionDistanceFilter = function MaxDensifiedByFractionDistanceFilter () {
|
38562 | this._maxPtDist = new PointPairDistance$2();
|
38563 | this._minPtDist = new PointPairDistance$2();
|
38564 | this._geom = null;
|
38565 | this._numSubSegs = 0;
|
38566 | var geom = arguments[0];
|
38567 | var fraction = arguments[1];
|
38568 | this._geom = geom;
|
38569 | this._numSubSegs = Math.trunc(Math.round(1.0 / fraction));
|
38570 | };
|
38571 | MaxDensifiedByFractionDistanceFilter.prototype.filter = function filter (seq, index) {
|
38572 | var this$1 = this;
|
38573 |
|
38574 | if (index === 0) { return null }
|
38575 | var p0 = seq.getCoordinate(index - 1);
|
38576 | var p1 = seq.getCoordinate(index);
|
38577 | var delx = (p1.x - p0.x) / this._numSubSegs;
|
38578 | var dely = (p1.y - p0.y) / this._numSubSegs;
|
38579 | for (var i = 0; i < this._numSubSegs; i++) {
|
38580 | var x = p0.x + i * delx;
|
38581 | var y = p0.y + i * dely;
|
38582 | var pt = new Coordinate(x, y);
|
38583 | this$1._minPtDist.initialize();
|
38584 | DistanceToPoint.computeDistance(this$1._geom, pt, this$1._minPtDist);
|
38585 | this$1._maxPtDist.setMaximum(this$1._minPtDist);
|
38586 | }
|
38587 | };
|
38588 | MaxDensifiedByFractionDistanceFilter.prototype.isDone = function isDone () {
|
38589 | return false
|
38590 | };
|
38591 | MaxDensifiedByFractionDistanceFilter.prototype.isGeometryChanged = function isGeometryChanged () {
|
38592 | return false
|
38593 | };
|
38594 | MaxDensifiedByFractionDistanceFilter.prototype.getMaxPointDistance = function getMaxPointDistance () {
|
38595 | return this._maxPtDist
|
38596 | };
|
38597 | MaxDensifiedByFractionDistanceFilter.prototype.interfaces_ = function interfaces_ () {
|
38598 | return [CoordinateSequenceFilter]
|
38599 | };
|
38600 | MaxDensifiedByFractionDistanceFilter.prototype.getClass = function getClass () {
|
38601 | return MaxDensifiedByFractionDistanceFilter
|
38602 | };
|
38603 |
|
38604 | var BufferDistanceValidator = function BufferDistanceValidator (input, bufDistance, result) {
|
38605 | this._minValidDistance = null;
|
38606 | this._maxValidDistance = null;
|
38607 | this._minDistanceFound = null;
|
38608 | this._maxDistanceFound = null;
|
38609 | this._isValid = true;
|
38610 | this._errMsg = null;
|
38611 | this._errorLocation = null;
|
38612 | this._errorIndicator = null;
|
38613 | this._input = input || null;
|
38614 | this._bufDistance = bufDistance || null;
|
38615 | this._result = result || null;
|
38616 | };
|
38617 |
|
38618 | var staticAccessors$37 = { VERBOSE: { configurable: true },MAX_DISTANCE_DIFF_FRAC: { configurable: true } };
|
38619 | BufferDistanceValidator.prototype.checkMaximumDistance = function checkMaximumDistance (input, bufCurve, maxDist) {
|
38620 | var haus = new DiscreteHausdorffDistance(bufCurve, input);
|
38621 | haus.setDensifyFraction(0.25);
|
38622 | this._maxDistanceFound = haus.orientedDistance();
|
38623 | if (this._maxDistanceFound > maxDist) {
|
38624 | this._isValid = false;
|
38625 | var pts = haus.getCoordinates();
|
38626 | this._errorLocation = pts[1];
|
38627 | this._errorIndicator = input.getFactory().createLineString(pts);
|
38628 | this._errMsg = 'Distance between buffer curve and input is too large (' + this._maxDistanceFound + ' at ' + WKTWriter.toLineString(pts[0], pts[1]) + ')';
|
38629 | }
|
38630 | };
|
38631 | BufferDistanceValidator.prototype.isValid = function isValid () {
|
38632 | var posDistance = Math.abs(this._bufDistance);
|
38633 | var distDelta = BufferDistanceValidator.MAX_DISTANCE_DIFF_FRAC * posDistance;
|
38634 | this._minValidDistance = posDistance - distDelta;
|
38635 | this._maxValidDistance = posDistance + distDelta;
|
38636 | if (this._input.isEmpty() || this._result.isEmpty()) { return true }
|
38637 | if (this._bufDistance > 0.0) {
|
38638 | this.checkPositiveValid();
|
38639 | } else {
|
38640 | this.checkNegativeValid();
|
38641 | }
|
38642 | if (BufferDistanceValidator.VERBOSE) {
|
38643 | System.out.println('Min Dist= ' + this._minDistanceFound + ' err= ' + (1.0 - this._minDistanceFound / this._bufDistance) + ' Max Dist= ' + this._maxDistanceFound + ' err= ' + (this._maxDistanceFound / this._bufDistance - 1.0));
|
38644 | }
|
38645 | return this._isValid
|
38646 | };
|
38647 | BufferDistanceValidator.prototype.checkNegativeValid = function checkNegativeValid () {
|
38648 | if (!(this._input instanceof Polygon || this._input instanceof MultiPolygon || this._input instanceof GeometryCollection)) {
|
38649 | return null
|
38650 | }
|
38651 | var inputCurve = this.getPolygonLines(this._input);
|
38652 | this.checkMinimumDistance(inputCurve, this._result, this._minValidDistance);
|
38653 | if (!this._isValid) { return null }
|
38654 | this.checkMaximumDistance(inputCurve, this._result, this._maxValidDistance);
|
38655 | };
|
38656 | BufferDistanceValidator.prototype.getErrorIndicator = function getErrorIndicator () {
|
38657 | return this._errorIndicator
|
38658 | };
|
38659 | BufferDistanceValidator.prototype.checkMinimumDistance = function checkMinimumDistance (g1, g2, minDist) {
|
38660 | var distOp = new DistanceOp(g1, g2, minDist);
|
38661 | this._minDistanceFound = distOp.distance();
|
38662 | if (this._minDistanceFound < minDist) {
|
38663 | this._isValid = false;
|
38664 | var pts = distOp.nearestPoints();
|
38665 | this._errorLocation = distOp.nearestPoints()[1];
|
38666 | this._errorIndicator = g1.getFactory().createLineString(pts);
|
38667 | this._errMsg = 'Distance between buffer curve and input is too small (' + this._minDistanceFound + ' at ' + WKTWriter.toLineString(pts[0], pts[1]) + ' )';
|
38668 | }
|
38669 | };
|
38670 | BufferDistanceValidator.prototype.checkPositiveValid = function checkPositiveValid () {
|
38671 | var bufCurve = this._result.getBoundary();
|
38672 | this.checkMinimumDistance(this._input, bufCurve, this._minValidDistance);
|
38673 | if (!this._isValid) { return null }
|
38674 | this.checkMaximumDistance(this._input, bufCurve, this._maxValidDistance);
|
38675 | };
|
38676 | BufferDistanceValidator.prototype.getErrorLocation = function getErrorLocation () {
|
38677 | return this._errorLocation
|
38678 | };
|
38679 | BufferDistanceValidator.prototype.getPolygonLines = function getPolygonLines (g) {
|
38680 | var lines = new ArrayList();
|
38681 | var lineExtracter = new LinearComponentExtracter(lines);
|
38682 | var polys = PolygonExtracter.getPolygons(g);
|
38683 | for (var i = polys.iterator(); i.hasNext();) {
|
38684 | var poly = i.next();
|
38685 | poly.apply(lineExtracter);
|
38686 | }
|
38687 | return g.getFactory().buildGeometry(lines)
|
38688 | };
|
38689 | BufferDistanceValidator.prototype.getErrorMessage = function getErrorMessage () {
|
38690 | return this._errMsg
|
38691 | };
|
38692 | BufferDistanceValidator.prototype.interfaces_ = function interfaces_ () {
|
38693 | return []
|
38694 | };
|
38695 | BufferDistanceValidator.prototype.getClass = function getClass () {
|
38696 | return BufferDistanceValidator
|
38697 | };
|
38698 | staticAccessors$37.VERBOSE.get = function () { return false };
|
38699 | staticAccessors$37.MAX_DISTANCE_DIFF_FRAC.get = function () { return 0.012 };
|
38700 |
|
38701 | Object.defineProperties( BufferDistanceValidator, staticAccessors$37 );
|
38702 |
|
38703 | var BufferResultValidator = function BufferResultValidator (input, distance, result) {
|
38704 | this._isValid = true;
|
38705 | this._errorMsg = null;
|
38706 | this._errorLocation = null;
|
38707 | this._errorIndicator = null;
|
38708 | this._input = input || null;
|
38709 | this._distance = distance || null;
|
38710 | this._result = result || null;
|
38711 | };
|
38712 |
|
38713 | var staticAccessors$40 = { VERBOSE: { configurable: true },MAX_ENV_DIFF_FRAC: { configurable: true } };
|
38714 | BufferResultValidator.prototype.isValid = function isValid () {
|
38715 | this.checkPolygonal();
|
38716 | if (!this._isValid) { return this._isValid }
|
38717 | this.checkExpectedEmpty();
|
38718 | if (!this._isValid) { return this._isValid }
|
38719 | this.checkEnvelope();
|
38720 | if (!this._isValid) { return this._isValid }
|
38721 | this.checkArea();
|
38722 | if (!this._isValid) { return this._isValid }
|
38723 | this.checkDistance();
|
38724 | return this._isValid
|
38725 | };
|
38726 | BufferResultValidator.prototype.checkEnvelope = function checkEnvelope () {
|
38727 | if (this._distance < 0.0) { return null }
|
38728 | var padding = this._distance * BufferResultValidator.MAX_ENV_DIFF_FRAC;
|
38729 | if (padding === 0.0) { padding = 0.001; }
|
38730 | var expectedEnv = new Envelope(this._input.getEnvelopeInternal());
|
38731 | expectedEnv.expandBy(this._distance);
|
38732 | var bufEnv = new Envelope(this._result.getEnvelopeInternal());
|
38733 | bufEnv.expandBy(padding);
|
38734 | if (!bufEnv.contains(expectedEnv)) {
|
38735 | this._isValid = false;
|
38736 | this._errorMsg = 'Buffer envelope is incorrect';
|
38737 | this._errorIndicator = this._input.getFactory().toGeometry(bufEnv);
|
38738 | }
|
38739 | this.report('Envelope');
|
38740 | };
|
38741 | BufferResultValidator.prototype.checkDistance = function checkDistance () {
|
38742 | var distValid = new BufferDistanceValidator(this._input, this._distance, this._result);
|
38743 | if (!distValid.isValid()) {
|
38744 | this._isValid = false;
|
38745 | this._errorMsg = distValid.getErrorMessage();
|
38746 | this._errorLocation = distValid.getErrorLocation();
|
38747 | this._errorIndicator = distValid.getErrorIndicator();
|
38748 | }
|
38749 | this.report('Distance');
|
38750 | };
|
38751 | BufferResultValidator.prototype.checkArea = function checkArea () {
|
38752 | var inputArea = this._input.getArea();
|
38753 | var resultArea = this._result.getArea();
|
38754 | if (this._distance > 0.0 && inputArea > resultArea) {
|
38755 | this._isValid = false;
|
38756 | this._errorMsg = 'Area of positive buffer is smaller than input';
|
38757 | this._errorIndicator = this._result;
|
38758 | }
|
38759 | if (this._distance < 0.0 && inputArea < resultArea) {
|
38760 | this._isValid = false;
|
38761 | this._errorMsg = 'Area of negative buffer is larger than input';
|
38762 | this._errorIndicator = this._result;
|
38763 | }
|
38764 | this.report('Area');
|
38765 | };
|
38766 | BufferResultValidator.prototype.checkPolygonal = function checkPolygonal () {
|
38767 | if (!(this._result instanceof Polygon || this._result instanceof MultiPolygon)) { this._isValid = false; }
|
38768 | this._errorMsg = 'Result is not polygonal';
|
38769 | this._errorIndicator = this._result;
|
38770 | this.report('Polygonal');
|
38771 | };
|
38772 | BufferResultValidator.prototype.getErrorIndicator = function getErrorIndicator () {
|
38773 | return this._errorIndicator
|
38774 | };
|
38775 | BufferResultValidator.prototype.getErrorLocation = function getErrorLocation () {
|
38776 | return this._errorLocation
|
38777 | };
|
38778 | BufferResultValidator.prototype.checkExpectedEmpty = function checkExpectedEmpty () {
|
38779 | if (this._input.getDimension() >= 2) { return null }
|
38780 | if (this._distance > 0.0) { return null }
|
38781 | if (!this._result.isEmpty()) {
|
38782 | this._isValid = false;
|
38783 | this._errorMsg = 'Result is non-empty';
|
38784 | this._errorIndicator = this._result;
|
38785 | }
|
38786 | this.report('ExpectedEmpty');
|
38787 | };
|
38788 | BufferResultValidator.prototype.report = function report (checkName) {
|
38789 | if (!BufferResultValidator.VERBOSE) { return null }
|
38790 | System.out.println('Check ' + checkName + ': ' + (this._isValid ? 'passed' : 'FAILED'));
|
38791 | };
|
38792 | BufferResultValidator.prototype.getErrorMessage = function getErrorMessage () {
|
38793 | return this._errorMsg
|
38794 | };
|
38795 | BufferResultValidator.prototype.interfaces_ = function interfaces_ () {
|
38796 | return []
|
38797 | };
|
38798 | BufferResultValidator.prototype.getClass = function getClass () {
|
38799 | return BufferResultValidator
|
38800 | };
|
38801 | BufferResultValidator.isValidMsg = function isValidMsg (g, distance, result) {
|
38802 | var validator = new BufferResultValidator(g, distance, result);
|
38803 | if (!validator.isValid()) { return validator.getErrorMessage() }
|
38804 | return null
|
38805 | };
|
38806 | BufferResultValidator.isValid = function isValid (g, distance, result) {
|
38807 | var validator = new BufferResultValidator(g, distance, result);
|
38808 | if (validator.isValid()) { return true }
|
38809 | return false
|
38810 | };
|
38811 | staticAccessors$40.VERBOSE.get = function () { return false };
|
38812 | staticAccessors$40.MAX_ENV_DIFF_FRAC.get = function () { return 0.012 };
|
38813 |
|
38814 | Object.defineProperties( BufferResultValidator, staticAccessors$40 );
|
38815 |
|
38816 |
|
38817 |
|
38818 | var BasicSegmentString = function BasicSegmentString () {
|
38819 | this._pts = null;
|
38820 | this._data = null;
|
38821 | var pts = arguments[0];
|
38822 | var data = arguments[1];
|
38823 | this._pts = pts;
|
38824 | this._data = data;
|
38825 | };
|
38826 | BasicSegmentString.prototype.getCoordinates = function getCoordinates () {
|
38827 | return this._pts
|
38828 | };
|
38829 | BasicSegmentString.prototype.size = function size () {
|
38830 | return this._pts.length
|
38831 | };
|
38832 | BasicSegmentString.prototype.getCoordinate = function getCoordinate (i) {
|
38833 | return this._pts[i]
|
38834 | };
|
38835 | BasicSegmentString.prototype.isClosed = function isClosed () {
|
38836 | return this._pts[0].equals(this._pts[this._pts.length - 1])
|
38837 | };
|
38838 | BasicSegmentString.prototype.getSegmentOctant = function getSegmentOctant (index) {
|
38839 | if (index === this._pts.length - 1) { return -1 }
|
38840 | return Octant.octant(this.getCoordinate(index), this.getCoordinate(index + 1))
|
38841 | };
|
38842 | BasicSegmentString.prototype.setData = function setData (data) {
|
38843 | this._data = data;
|
38844 | };
|
38845 | BasicSegmentString.prototype.getData = function getData () {
|
38846 | return this._data
|
38847 | };
|
38848 | BasicSegmentString.prototype.toString = function toString () {
|
38849 | return WKTWriter.toLineString(new CoordinateArraySequence(this._pts))
|
38850 | };
|
38851 | BasicSegmentString.prototype.interfaces_ = function interfaces_ () {
|
38852 | return [SegmentString]
|
38853 | };
|
38854 | BasicSegmentString.prototype.getClass = function getClass () {
|
38855 | return BasicSegmentString
|
38856 | };
|
38857 |
|
38858 | var InteriorIntersectionFinder = function InteriorIntersectionFinder () {
|
38859 | this._findAllIntersections = false;
|
38860 | this._isCheckEndSegmentsOnly = false;
|
38861 | this._li = null;
|
38862 | this._interiorIntersection = null;
|
38863 | this._intSegments = null;
|
38864 | this._intersections = new ArrayList();
|
38865 | this._intersectionCount = 0;
|
38866 | this._keepIntersections = true;
|
38867 | var li = arguments[0];
|
38868 | this._li = li;
|
38869 | this._interiorIntersection = null;
|
38870 | };
|
38871 | InteriorIntersectionFinder.prototype.getInteriorIntersection = function getInteriorIntersection () {
|
38872 | return this._interiorIntersection
|
38873 | };
|
38874 | InteriorIntersectionFinder.prototype.setCheckEndSegmentsOnly = function setCheckEndSegmentsOnly (isCheckEndSegmentsOnly) {
|
38875 | this._isCheckEndSegmentsOnly = isCheckEndSegmentsOnly;
|
38876 | };
|
38877 | InteriorIntersectionFinder.prototype.getIntersectionSegments = function getIntersectionSegments () {
|
38878 | return this._intSegments
|
38879 | };
|
38880 | InteriorIntersectionFinder.prototype.count = function count () {
|
38881 | return this._intersectionCount
|
38882 | };
|
38883 | InteriorIntersectionFinder.prototype.getIntersections = function getIntersections () {
|
38884 | return this._intersections
|
38885 | };
|
38886 | InteriorIntersectionFinder.prototype.setFindAllIntersections = function setFindAllIntersections (findAllIntersections) {
|
38887 | this._findAllIntersections = findAllIntersections;
|
38888 | };
|
38889 | InteriorIntersectionFinder.prototype.setKeepIntersections = function setKeepIntersections (keepIntersections) {
|
38890 | this._keepIntersections = keepIntersections;
|
38891 | };
|
38892 | InteriorIntersectionFinder.prototype.processIntersections = function processIntersections (e0, segIndex0, e1, segIndex1) {
|
38893 | if (!this._findAllIntersections && this.hasIntersection()) { return null }
|
38894 | if (e0 === e1 && segIndex0 === segIndex1) { return null }
|
38895 | if (this._isCheckEndSegmentsOnly) {
|
38896 | var isEndSegPresent = this.isEndSegment(e0, segIndex0) || this.isEndSegment(e1, segIndex1);
|
38897 | if (!isEndSegPresent) { return null }
|
38898 | }
|
38899 | var p00 = e0.getCoordinates()[segIndex0];
|
38900 | var p01 = e0.getCoordinates()[segIndex0 + 1];
|
38901 | var p10 = e1.getCoordinates()[segIndex1];
|
38902 | var p11 = e1.getCoordinates()[segIndex1 + 1];
|
38903 | this._li.computeIntersection(p00, p01, p10, p11);
|
38904 | if (this._li.hasIntersection()) {
|
38905 | if (this._li.isInteriorIntersection()) {
|
38906 | this._intSegments = new Array(4).fill(null);
|
38907 | this._intSegments[0] = p00;
|
38908 | this._intSegments[1] = p01;
|
38909 | this._intSegments[2] = p10;
|
38910 | this._intSegments[3] = p11;
|
38911 | this._interiorIntersection = this._li.getIntersection(0);
|
38912 | if (this._keepIntersections) { this._intersections.add(this._interiorIntersection); }
|
38913 | this._intersectionCount++;
|
38914 | }
|
38915 | }
|
38916 | };
|
38917 | InteriorIntersectionFinder.prototype.isEndSegment = function isEndSegment (segStr, index) {
|
38918 | if (index === 0) { return true }
|
38919 | if (index >= segStr.size() - 2) { return true }
|
38920 | return false
|
38921 | };
|
38922 | InteriorIntersectionFinder.prototype.hasIntersection = function hasIntersection () {
|
38923 | return this._interiorIntersection !== null
|
38924 | };
|
38925 | InteriorIntersectionFinder.prototype.isDone = function isDone () {
|
38926 | if (this._findAllIntersections) { return false }
|
38927 | return this._interiorIntersection !== null
|
38928 | };
|
38929 | InteriorIntersectionFinder.prototype.interfaces_ = function interfaces_ () {
|
38930 | return [SegmentIntersector]
|
38931 | };
|
38932 | InteriorIntersectionFinder.prototype.getClass = function getClass () {
|
38933 | return InteriorIntersectionFinder
|
38934 | };
|
38935 | InteriorIntersectionFinder.createAllIntersectionsFinder = function createAllIntersectionsFinder (li) {
|
38936 | var finder = new InteriorIntersectionFinder(li);
|
38937 | finder.setFindAllIntersections(true);
|
38938 | return finder
|
38939 | };
|
38940 | InteriorIntersectionFinder.createAnyIntersectionFinder = function createAnyIntersectionFinder (li) {
|
38941 | return new InteriorIntersectionFinder(li)
|
38942 | };
|
38943 | InteriorIntersectionFinder.createIntersectionCounter = function createIntersectionCounter (li) {
|
38944 | var finder = new InteriorIntersectionFinder(li);
|
38945 | finder.setFindAllIntersections(true);
|
38946 | finder.setKeepIntersections(false);
|
38947 | return finder
|
38948 | };
|
38949 |
|
38950 | var FastNodingValidator = function FastNodingValidator () {
|
38951 | this._li = new RobustLineIntersector();
|
38952 | this._segStrings = null;
|
38953 | this._findAllIntersections = false;
|
38954 | this._segInt = null;
|
38955 | this._isValid = true;
|
38956 | var segStrings = arguments[0];
|
38957 | this._segStrings = segStrings;
|
38958 | };
|
38959 | FastNodingValidator.prototype.execute = function execute () {
|
38960 | if (this._segInt !== null) { return null }
|
38961 | this.checkInteriorIntersections();
|
38962 | };
|
38963 | FastNodingValidator.prototype.getIntersections = function getIntersections () {
|
38964 | return this._segInt.getIntersections()
|
38965 | };
|
38966 | FastNodingValidator.prototype.isValid = function isValid () {
|
38967 | this.execute();
|
38968 | return this._isValid
|
38969 | };
|
38970 | FastNodingValidator.prototype.setFindAllIntersections = function setFindAllIntersections (findAllIntersections) {
|
38971 | this._findAllIntersections = findAllIntersections;
|
38972 | };
|
38973 | FastNodingValidator.prototype.checkInteriorIntersections = function checkInteriorIntersections () {
|
38974 | this._isValid = true;
|
38975 | this._segInt = new InteriorIntersectionFinder(this._li);
|
38976 | this._segInt.setFindAllIntersections(this._findAllIntersections);
|
38977 | var noder = new MCIndexNoder();
|
38978 | noder.setSegmentIntersector(this._segInt);
|
38979 | noder.computeNodes(this._segStrings);
|
38980 | if (this._segInt.hasIntersection()) {
|
38981 | this._isValid = false;
|
38982 | return null
|
38983 | }
|
38984 | };
|
38985 | FastNodingValidator.prototype.checkValid = function checkValid () {
|
38986 | this.execute();
|
38987 | if (!this._isValid) { throw new TopologyException(this.getErrorMessage(), this._segInt.getInteriorIntersection()) }
|
38988 | };
|
38989 | FastNodingValidator.prototype.getErrorMessage = function getErrorMessage () {
|
38990 | if (this._isValid) { return 'no intersections found' }
|
38991 | var intSegs = this._segInt.getIntersectionSegments();
|
38992 | return 'found non-noded intersection between ' + WKTWriter.toLineString(intSegs[0], intSegs[1]) + ' and ' + WKTWriter.toLineString(intSegs[2], intSegs[3])
|
38993 | };
|
38994 | FastNodingValidator.prototype.interfaces_ = function interfaces_ () {
|
38995 | return []
|
38996 | };
|
38997 | FastNodingValidator.prototype.getClass = function getClass () {
|
38998 | return FastNodingValidator
|
38999 | };
|
39000 | FastNodingValidator.computeIntersections = function computeIntersections (segStrings) {
|
39001 | var nv = new FastNodingValidator(segStrings);
|
39002 | nv.setFindAllIntersections(true);
|
39003 | nv.isValid();
|
39004 | return nv.getIntersections()
|
39005 | };
|
39006 |
|
39007 | var EdgeNodingValidator = function EdgeNodingValidator () {
|
39008 | this._nv = null;
|
39009 | var edges = arguments[0];
|
39010 | this._nv = new FastNodingValidator(EdgeNodingValidator.toSegmentStrings(edges));
|
39011 | };
|
39012 | EdgeNodingValidator.prototype.checkValid = function checkValid () {
|
39013 | this._nv.checkValid();
|
39014 | };
|
39015 | EdgeNodingValidator.prototype.interfaces_ = function interfaces_ () {
|
39016 | return []
|
39017 | };
|
39018 | EdgeNodingValidator.prototype.getClass = function getClass () {
|
39019 | return EdgeNodingValidator
|
39020 | };
|
39021 | EdgeNodingValidator.toSegmentStrings = function toSegmentStrings (edges) {
|
39022 | var segStrings = new ArrayList();
|
39023 | for (var i = edges.iterator(); i.hasNext();) {
|
39024 | var e = i.next();
|
39025 | segStrings.add(new BasicSegmentString(e.getCoordinates(), e));
|
39026 | }
|
39027 | return segStrings
|
39028 | };
|
39029 | EdgeNodingValidator.checkValid = function checkValid (edges) {
|
39030 | var validator = new EdgeNodingValidator(edges);
|
39031 | validator.checkValid();
|
39032 | };
|
39033 |
|
39034 | var GeometryCollectionMapper = function GeometryCollectionMapper (mapOp) {
|
39035 | this._mapOp = mapOp;
|
39036 | };
|
39037 | GeometryCollectionMapper.prototype.map = function map (gc) {
|
39038 | var this$1 = this;
|
39039 |
|
39040 | var mapped = new ArrayList();
|
39041 | for (var i = 0; i < gc.getNumGeometries(); i++) {
|
39042 | var g = this$1._mapOp.map(gc.getGeometryN(i));
|
39043 | if (!g.isEmpty()) { mapped.add(g); }
|
39044 | }
|
39045 | return gc.getFactory().createGeometryCollection(GeometryFactory.toGeometryArray(mapped))
|
39046 | };
|
39047 | GeometryCollectionMapper.prototype.interfaces_ = function interfaces_ () {
|
39048 | return []
|
39049 | };
|
39050 | GeometryCollectionMapper.prototype.getClass = function getClass () {
|
39051 | return GeometryCollectionMapper
|
39052 | };
|
39053 | GeometryCollectionMapper.map = function map (gc, op) {
|
39054 | var mapper = new GeometryCollectionMapper(op);
|
39055 | return mapper.map(gc)
|
39056 | };
|
39057 |
|
39058 | var LineBuilder = function LineBuilder () {
|
39059 | this._op = null;
|
39060 | this._geometryFactory = null;
|
39061 | this._ptLocator = null;
|
39062 | this._lineEdgesList = new ArrayList();
|
39063 | this._resultLineList = new ArrayList();
|
39064 | var op = arguments[0];
|
39065 | var geometryFactory = arguments[1];
|
39066 | var ptLocator = arguments[2];
|
39067 | this._op = op;
|
39068 | this._geometryFactory = geometryFactory;
|
39069 | this._ptLocator = ptLocator;
|
39070 | };
|
39071 | LineBuilder.prototype.collectLines = function collectLines (opCode) {
|
39072 | var this$1 = this;
|
39073 |
|
39074 | for (var it = this._op.getGraph().getEdgeEnds().iterator(); it.hasNext();) {
|
39075 | var de = it.next();
|
39076 | this$1.collectLineEdge(de, opCode, this$1._lineEdgesList);
|
39077 | this$1.collectBoundaryTouchEdge(de, opCode, this$1._lineEdgesList);
|
39078 | }
|
39079 | };
|
39080 | LineBuilder.prototype.labelIsolatedLine = function labelIsolatedLine (e, targetIndex) {
|
39081 | var loc = this._ptLocator.locate(e.getCoordinate(), this._op.getArgGeometry(targetIndex));
|
39082 | e.getLabel().setLocation(targetIndex, loc);
|
39083 | };
|
39084 | LineBuilder.prototype.build = function build (opCode) {
|
39085 | this.findCoveredLineEdges();
|
39086 | this.collectLines(opCode);
|
39087 | this.buildLines(opCode);
|
39088 | return this._resultLineList
|
39089 | };
|
39090 | LineBuilder.prototype.collectLineEdge = function collectLineEdge (de, opCode, edges) {
|
39091 | var label = de.getLabel();
|
39092 | var e = de.getEdge();
|
39093 | if (de.isLineEdge()) {
|
39094 | if (!de.isVisited() && OverlayOp.isResultOfOp(label, opCode) && !e.isCovered()) {
|
39095 | edges.add(e);
|
39096 | de.setVisitedEdge(true);
|
39097 | }
|
39098 | }
|
39099 | };
|
39100 | LineBuilder.prototype.findCoveredLineEdges = function findCoveredLineEdges () {
|
39101 | var this$1 = this;
|
39102 |
|
39103 | for (var nodeit = this._op.getGraph().getNodes().iterator(); nodeit.hasNext();) {
|
39104 | var node = nodeit.next();
|
39105 | node.getEdges().findCoveredLineEdges();
|
39106 | }
|
39107 | for (var it = this._op.getGraph().getEdgeEnds().iterator(); it.hasNext();) {
|
39108 | var de = it.next();
|
39109 | var e = de.getEdge();
|
39110 | if (de.isLineEdge() && !e.isCoveredSet()) {
|
39111 | var isCovered = this$1._op.isCoveredByA(de.getCoordinate());
|
39112 | e.setCovered(isCovered);
|
39113 | }
|
39114 | }
|
39115 | };
|
39116 | LineBuilder.prototype.labelIsolatedLines = function labelIsolatedLines (edgesList) {
|
39117 | var this$1 = this;
|
39118 |
|
39119 | for (var it = edgesList.iterator(); it.hasNext();) {
|
39120 | var e = it.next();
|
39121 | var label = e.getLabel();
|
39122 | if (e.isIsolated()) {
|
39123 | if (label.isNull(0)) { this$1.labelIsolatedLine(e, 0); } else { this$1.labelIsolatedLine(e, 1); }
|
39124 | }
|
39125 | }
|
39126 | };
|
39127 | LineBuilder.prototype.buildLines = function buildLines (opCode) {
|
39128 | var this$1 = this;
|
39129 |
|
39130 | for (var it = this._lineEdgesList.iterator(); it.hasNext();) {
|
39131 | var e = it.next();
|
39132 |
|
39133 | var line = this$1._geometryFactory.createLineString(e.getCoordinates());
|
39134 | this$1._resultLineList.add(line);
|
39135 | e.setInResult(true);
|
39136 | }
|
39137 | };
|
39138 | LineBuilder.prototype.collectBoundaryTouchEdge = function collectBoundaryTouchEdge (de, opCode, edges) {
|
39139 | var label = de.getLabel();
|
39140 | if (de.isLineEdge()) { return null }
|
39141 | if (de.isVisited()) { return null }
|
39142 | if (de.isInteriorAreaEdge()) { return null }
|
39143 | if (de.getEdge().isInResult()) { return null }
|
39144 | Assert.isTrue(!(de.isInResult() || de.getSym().isInResult()) || !de.getEdge().isInResult());
|
39145 | if (OverlayOp.isResultOfOp(label, opCode) && opCode === OverlayOp.INTERSECTION) {
|
39146 | edges.add(de.getEdge());
|
39147 | de.setVisitedEdge(true);
|
39148 | }
|
39149 | };
|
39150 | LineBuilder.prototype.interfaces_ = function interfaces_ () {
|
39151 | return []
|
39152 | };
|
39153 | LineBuilder.prototype.getClass = function getClass () {
|
39154 | return LineBuilder
|
39155 | };
|
39156 |
|
39157 | var PointBuilder = function PointBuilder () {
|
39158 | this._op = null;
|
39159 | this._geometryFactory = null;
|
39160 | this._resultPointList = new ArrayList();
|
39161 | var op = arguments[0];
|
39162 | var geometryFactory = arguments[1];
|
39163 |
|
39164 | this._op = op;
|
39165 | this._geometryFactory = geometryFactory;
|
39166 | };
|
39167 | PointBuilder.prototype.filterCoveredNodeToPoint = function filterCoveredNodeToPoint (n) {
|
39168 | var coord = n.getCoordinate();
|
39169 | if (!this._op.isCoveredByLA(coord)) {
|
39170 | var pt = this._geometryFactory.createPoint(coord);
|
39171 | this._resultPointList.add(pt);
|
39172 | }
|
39173 | };
|
39174 | PointBuilder.prototype.extractNonCoveredResultNodes = function extractNonCoveredResultNodes (opCode) {
|
39175 | var this$1 = this;
|
39176 |
|
39177 | for (var nodeit = this._op.getGraph().getNodes().iterator(); nodeit.hasNext();) {
|
39178 | var n = nodeit.next();
|
39179 | if (n.isInResult()) { continue }
|
39180 | if (n.isIncidentEdgeInResult()) { continue }
|
39181 | if (n.getEdges().getDegree() === 0 || opCode === OverlayOp.INTERSECTION) {
|
39182 | var label = n.getLabel();
|
39183 | if (OverlayOp.isResultOfOp(label, opCode)) {
|
39184 | this$1.filterCoveredNodeToPoint(n);
|
39185 | }
|
39186 | }
|
39187 | }
|
39188 | };
|
39189 | PointBuilder.prototype.build = function build (opCode) {
|
39190 | this.extractNonCoveredResultNodes(opCode);
|
39191 | return this._resultPointList
|
39192 | };
|
39193 | PointBuilder.prototype.interfaces_ = function interfaces_ () {
|
39194 | return []
|
39195 | };
|
39196 | PointBuilder.prototype.getClass = function getClass () {
|
39197 | return PointBuilder
|
39198 | };
|
39199 |
|
39200 | var GeometryTransformer = function GeometryTransformer () {
|
39201 | this._inputGeom = null;
|
39202 | this._factory = null;
|
39203 | this._pruneEmptyGeometry = true;
|
39204 | this._preserveGeometryCollectionType = true;
|
39205 | this._preserveCollections = false;
|
39206 | this._preserveType = false;
|
39207 | };
|
39208 | GeometryTransformer.prototype.transformPoint = function transformPoint (geom, parent) {
|
39209 | return this._factory.createPoint(this.transformCoordinates(geom.getCoordinateSequence(), geom))
|
39210 | };
|
39211 | GeometryTransformer.prototype.transformPolygon = function transformPolygon (geom, parent) {
|
39212 | var this$1 = this;
|
39213 |
|
39214 | var isAllValidLinearRings = true;
|
39215 | var shell = this.transformLinearRing(geom.getExteriorRing(), geom);
|
39216 | if (shell === null || !(shell instanceof LinearRing) || shell.isEmpty()) { isAllValidLinearRings = false; }
|
39217 | var holes = new ArrayList();
|
39218 | for (var i = 0; i < geom.getNumInteriorRing(); i++) {
|
39219 | var hole = this$1.transformLinearRing(geom.getInteriorRingN(i), geom);
|
39220 | if (hole === null || hole.isEmpty()) {
|
39221 | continue
|
39222 | }
|
39223 | if (!(hole instanceof LinearRing)) { isAllValidLinearRings = false; }
|
39224 | holes.add(hole);
|
39225 | }
|
39226 | if (isAllValidLinearRings) { return this._factory.createPolygon(shell, holes.toArray([])); } else {
|
39227 | var components = new ArrayList();
|
39228 | if (shell !== null) { components.add(shell); }
|
39229 | components.addAll(holes);
|
39230 | return this._factory.buildGeometry(components)
|
39231 | }
|
39232 | };
|
39233 | GeometryTransformer.prototype.createCoordinateSequence = function createCoordinateSequence (coords) {
|
39234 | return this._factory.getCoordinateSequenceFactory().create(coords)
|
39235 | };
|
39236 | GeometryTransformer.prototype.getInputGeometry = function getInputGeometry () {
|
39237 | return this._inputGeom
|
39238 | };
|
39239 | GeometryTransformer.prototype.transformMultiLineString = function transformMultiLineString (geom, parent) {
|
39240 | var this$1 = this;
|
39241 |
|
39242 | var transGeomList = new ArrayList();
|
39243 | for (var i = 0; i < geom.getNumGeometries(); i++) {
|
39244 | var transformGeom = this$1.transformLineString(geom.getGeometryN(i), geom);
|
39245 | if (transformGeom === null) { continue }
|
39246 | if (transformGeom.isEmpty()) { continue }
|
39247 | transGeomList.add(transformGeom);
|
39248 | }
|
39249 | return this._factory.buildGeometry(transGeomList)
|
39250 | };
|
39251 | GeometryTransformer.prototype.transformCoordinates = function transformCoordinates (coords, parent) {
|
39252 | return this.copy(coords)
|
39253 | };
|
39254 | GeometryTransformer.prototype.transformLineString = function transformLineString (geom, parent) {
|
39255 | return this._factory.createLineString(this.transformCoordinates(geom.getCoordinateSequence(), geom))
|
39256 | };
|
39257 | GeometryTransformer.prototype.transformMultiPoint = function transformMultiPoint (geom, parent) {
|
39258 | var this$1 = this;
|
39259 |
|
39260 | var transGeomList = new ArrayList();
|
39261 | for (var i = 0; i < geom.getNumGeometries(); i++) {
|
39262 | var transformGeom = this$1.transformPoint(geom.getGeometryN(i), geom);
|
39263 | if (transformGeom === null) { continue }
|
39264 | if (transformGeom.isEmpty()) { continue }
|
39265 | transGeomList.add(transformGeom);
|
39266 | }
|
39267 | return this._factory.buildGeometry(transGeomList)
|
39268 | };
|
39269 | GeometryTransformer.prototype.transformMultiPolygon = function transformMultiPolygon (geom, parent) {
|
39270 | var this$1 = this;
|
39271 |
|
39272 | var transGeomList = new ArrayList();
|
39273 | for (var i = 0; i < geom.getNumGeometries(); i++) {
|
39274 | var transformGeom = this$1.transformPolygon(geom.getGeometryN(i), geom);
|
39275 | if (transformGeom === null) { continue }
|
39276 | if (transformGeom.isEmpty()) { continue }
|
39277 | transGeomList.add(transformGeom);
|
39278 | }
|
39279 | return this._factory.buildGeometry(transGeomList)
|
39280 | };
|
39281 | GeometryTransformer.prototype.copy = function copy (seq) {
|
39282 | return seq.copy()
|
39283 | };
|
39284 | GeometryTransformer.prototype.transformGeometryCollection = function transformGeometryCollection (geom, parent) {
|
39285 | var this$1 = this;
|
39286 |
|
39287 | var transGeomList = new ArrayList();
|
39288 | for (var i = 0; i < geom.getNumGeometries(); i++) {
|
39289 | var transformGeom = this$1.transform(geom.getGeometryN(i));
|
39290 | if (transformGeom === null) { continue }
|
39291 | if (this$1._pruneEmptyGeometry && transformGeom.isEmpty()) { continue }
|
39292 | transGeomList.add(transformGeom);
|
39293 | }
|
39294 | if (this._preserveGeometryCollectionType) { return this._factory.createGeometryCollection(GeometryFactory.toGeometryArray(transGeomList)) }
|
39295 | return this._factory.buildGeometry(transGeomList)
|
39296 | };
|
39297 | GeometryTransformer.prototype.transform = function transform (inputGeom) {
|
39298 | this._inputGeom = inputGeom;
|
39299 | this._factory = inputGeom.getFactory();
|
39300 | if (inputGeom instanceof Point) { return this.transformPoint(inputGeom, null) }
|
39301 | if (inputGeom instanceof MultiPoint) { return this.transformMultiPoint(inputGeom, null) }
|
39302 | if (inputGeom instanceof LinearRing) { return this.transformLinearRing(inputGeom, null) }
|
39303 | if (inputGeom instanceof LineString$1) { return this.transformLineString(inputGeom, null) }
|
39304 | if (inputGeom instanceof MultiLineString) { return this.transformMultiLineString(inputGeom, null) }
|
39305 | if (inputGeom instanceof Polygon) { return this.transformPolygon(inputGeom, null) }
|
39306 | if (inputGeom instanceof MultiPolygon) { return this.transformMultiPolygon(inputGeom, null) }
|
39307 | if (inputGeom instanceof GeometryCollection) { return this.transformGeometryCollection(inputGeom, null) }
|
39308 | throw new IllegalArgumentException('Unknown Geometry subtype: ' + inputGeom.getClass().getName())
|
39309 | };
|
39310 | GeometryTransformer.prototype.transformLinearRing = function transformLinearRing (geom, parent) {
|
39311 | var seq = this.transformCoordinates(geom.getCoordinateSequence(), geom);
|
39312 | if (seq === null) { return this._factory.createLinearRing(null) }
|
39313 | var seqSize = seq.size();
|
39314 | if (seqSize > 0 && seqSize < 4 && !this._preserveType) { return this._factory.createLineString(seq) }
|
39315 | return this._factory.createLinearRing(seq)
|
39316 | };
|
39317 | GeometryTransformer.prototype.interfaces_ = function interfaces_ () {
|
39318 | return []
|
39319 | };
|
39320 | GeometryTransformer.prototype.getClass = function getClass () {
|
39321 | return GeometryTransformer
|
39322 | };
|
39323 |
|
39324 | var LineStringSnapper = function LineStringSnapper () {
|
39325 | this._snapTolerance = 0.0;
|
39326 | this._srcPts = null;
|
39327 | this._seg = new LineSegment();
|
39328 | this._allowSnappingToSourceVertices = false;
|
39329 | this._isClosed = false;
|
39330 | if (arguments[0] instanceof LineString$1 && typeof arguments[1] === 'number') {
|
39331 | var srcLine = arguments[0];
|
39332 | var snapTolerance = arguments[1];
|
39333 | LineStringSnapper.call(this, srcLine.getCoordinates(), snapTolerance);
|
39334 | } else if (arguments[0] instanceof Array && typeof arguments[1] === 'number') {
|
39335 | var srcPts = arguments[0];
|
39336 | var snapTolerance$1 = arguments[1];
|
39337 | this._srcPts = srcPts;
|
39338 | this._isClosed = LineStringSnapper.isClosed(srcPts);
|
39339 | this._snapTolerance = snapTolerance$1;
|
39340 | }
|
39341 | };
|
39342 | LineStringSnapper.prototype.snapVertices = function snapVertices (srcCoords, snapPts) {
|
39343 | var this$1 = this;
|
39344 |
|
39345 | var end = this._isClosed ? srcCoords.size() - 1 : srcCoords.size();
|
39346 | for (var i = 0; i < end; i++) {
|
39347 | var srcPt = srcCoords.get(i);
|
39348 | var snapVert = this$1.findSnapForVertex(srcPt, snapPts);
|
39349 | if (snapVert !== null) {
|
39350 | srcCoords.set(i, new Coordinate(snapVert));
|
39351 | if (i === 0 && this$1._isClosed) { srcCoords.set(srcCoords.size() - 1, new Coordinate(snapVert)); }
|
39352 | }
|
39353 | }
|
39354 | };
|
39355 | LineStringSnapper.prototype.findSnapForVertex = function findSnapForVertex (pt, snapPts) {
|
39356 | var this$1 = this;
|
39357 |
|
39358 | for (var i = 0; i < snapPts.length; i++) {
|
39359 | if (pt.equals2D(snapPts[i])) { return null }
|
39360 | if (pt.distance(snapPts[i]) < this$1._snapTolerance) { return snapPts[i] }
|
39361 | }
|
39362 | return null
|
39363 | };
|
39364 | LineStringSnapper.prototype.snapTo = function snapTo (snapPts) {
|
39365 | var coordList = new CoordinateList(this._srcPts);
|
39366 | this.snapVertices(coordList, snapPts);
|
39367 | this.snapSegments(coordList, snapPts);
|
39368 | var newPts = coordList.toCoordinateArray();
|
39369 | return newPts
|
39370 | };
|
39371 | LineStringSnapper.prototype.snapSegments = function snapSegments (srcCoords, snapPts) {
|
39372 | var this$1 = this;
|
39373 |
|
39374 | if (snapPts.length === 0) { return null }
|
39375 | var distinctPtCount = snapPts.length;
|
39376 | if (snapPts[0].equals2D(snapPts[snapPts.length - 1])) { distinctPtCount = snapPts.length - 1; }
|
39377 | for (var i = 0; i < distinctPtCount; i++) {
|
39378 | var snapPt = snapPts[i];
|
39379 | var index = this$1.findSegmentIndexToSnap(snapPt, srcCoords);
|
39380 | if (index >= 0) {
|
39381 | srcCoords.add(index + 1, new Coordinate(snapPt), false);
|
39382 | }
|
39383 | }
|
39384 | };
|
39385 | LineStringSnapper.prototype.findSegmentIndexToSnap = function findSegmentIndexToSnap (snapPt, srcCoords) {
|
39386 | var this$1 = this;
|
39387 |
|
39388 | var minDist = Double.MAX_VALUE;
|
39389 | var snapIndex = -1;
|
39390 | for (var i = 0; i < srcCoords.size() - 1; i++) {
|
39391 | this$1._seg.p0 = srcCoords.get(i);
|
39392 | this$1._seg.p1 = srcCoords.get(i + 1);
|
39393 | if (this$1._seg.p0.equals2D(snapPt) || this$1._seg.p1.equals2D(snapPt)) {
|
39394 | if (this$1._allowSnappingToSourceVertices) { continue; } else { return -1 }
|
39395 | }
|
39396 | var dist = this$1._seg.distance(snapPt);
|
39397 | if (dist < this$1._snapTolerance && dist < minDist) {
|
39398 | minDist = dist;
|
39399 | snapIndex = i;
|
39400 | }
|
39401 | }
|
39402 | return snapIndex
|
39403 | };
|
39404 | LineStringSnapper.prototype.setAllowSnappingToSourceVertices = function setAllowSnappingToSourceVertices (allowSnappingToSourceVertices) {
|
39405 | this._allowSnappingToSourceVertices = allowSnappingToSourceVertices;
|
39406 | };
|
39407 | LineStringSnapper.prototype.interfaces_ = function interfaces_ () {
|
39408 | return []
|
39409 | };
|
39410 | LineStringSnapper.prototype.getClass = function getClass () {
|
39411 | return LineStringSnapper
|
39412 | };
|
39413 | LineStringSnapper.isClosed = function isClosed (pts) {
|
39414 | if (pts.length <= 1) { return false }
|
39415 | return pts[0].equals2D(pts[pts.length - 1])
|
39416 | };
|
39417 |
|
39418 | var GeometrySnapper = function GeometrySnapper (srcGeom) {
|
39419 | this._srcGeom = srcGeom || null;
|
39420 | };
|
39421 |
|
39422 | var staticAccessors$41 = { SNAP_PRECISION_FACTOR: { configurable: true } };
|
39423 | GeometrySnapper.prototype.snapTo = function snapTo (snapGeom, snapTolerance) {
|
39424 | var snapPts = this.extractTargetCoordinates(snapGeom);
|
39425 | var snapTrans = new SnapTransformer(snapTolerance, snapPts);
|
39426 | return snapTrans.transform(this._srcGeom)
|
39427 | };
|
39428 | GeometrySnapper.prototype.snapToSelf = function snapToSelf (snapTolerance, cleanResult) {
|
39429 | var snapPts = this.extractTargetCoordinates(this._srcGeom);
|
39430 | var snapTrans = new SnapTransformer(snapTolerance, snapPts, true);
|
39431 | var snappedGeom = snapTrans.transform(this._srcGeom);
|
39432 | var result = snappedGeom;
|
39433 | if (cleanResult && hasInterface(result, Polygonal)) {
|
39434 | result = snappedGeom.buffer(0);
|
39435 | }
|
39436 | return result
|
39437 | };
|
39438 | GeometrySnapper.prototype.computeSnapTolerance = function computeSnapTolerance (ringPts) {
|
39439 | var minSegLen = this.computeMinimumSegmentLength(ringPts);
|
39440 | var snapTol = minSegLen / 10;
|
39441 | return snapTol
|
39442 | };
|
39443 | GeometrySnapper.prototype.extractTargetCoordinates = function extractTargetCoordinates (g) {
|
39444 | var ptSet = new TreeSet();
|
39445 | var pts = g.getCoordinates();
|
39446 | for (var i = 0; i < pts.length; i++) {
|
39447 | ptSet.add(pts[i]);
|
39448 | }
|
39449 | return ptSet.toArray(new Array(0).fill(null))
|
39450 | };
|
39451 | GeometrySnapper.prototype.computeMinimumSegmentLength = function computeMinimumSegmentLength (pts) {
|
39452 | var minSegLen = Double.MAX_VALUE;
|
39453 | for (var i = 0; i < pts.length - 1; i++) {
|
39454 | var segLen = pts[i].distance(pts[i + 1]);
|
39455 | if (segLen < minSegLen) { minSegLen = segLen; }
|
39456 | }
|
39457 | return minSegLen
|
39458 | };
|
39459 | GeometrySnapper.prototype.interfaces_ = function interfaces_ () {
|
39460 | return []
|
39461 | };
|
39462 | GeometrySnapper.prototype.getClass = function getClass () {
|
39463 | return GeometrySnapper
|
39464 | };
|
39465 | GeometrySnapper.snap = function snap (g0, g1, snapTolerance) {
|
39466 | var snapGeom = new Array(2).fill(null);
|
39467 | var snapper0 = new GeometrySnapper(g0);
|
39468 | snapGeom[0] = snapper0.snapTo(g1, snapTolerance);
|
39469 | var snapper1 = new GeometrySnapper(g1);
|
39470 | snapGeom[1] = snapper1.snapTo(snapGeom[0], snapTolerance);
|
39471 | return snapGeom
|
39472 | };
|
39473 | GeometrySnapper.computeOverlaySnapTolerance = function computeOverlaySnapTolerance () {
|
39474 | if (arguments.length === 1) {
|
39475 | var g = arguments[0];
|
39476 | var snapTolerance = GeometrySnapper.computeSizeBasedSnapTolerance(g);
|
39477 | var pm = g.getPrecisionModel();
|
39478 | if (pm.getType() === PrecisionModel.FIXED) {
|
39479 | var fixedSnapTol = 1 / pm.getScale() * 2 / 1.415;
|
39480 | if (fixedSnapTol > snapTolerance) { snapTolerance = fixedSnapTol; }
|
39481 | }
|
39482 | return snapTolerance
|
39483 | } else if (arguments.length === 2) {
|
39484 | var g0 = arguments[0];
|
39485 | var g1 = arguments[1];
|
39486 | return Math.min(GeometrySnapper.computeOverlaySnapTolerance(g0), GeometrySnapper.computeOverlaySnapTolerance(g1))
|
39487 | }
|
39488 | };
|
39489 | GeometrySnapper.computeSizeBasedSnapTolerance = function computeSizeBasedSnapTolerance (g) {
|
39490 | var env = g.getEnvelopeInternal();
|
39491 | var minDimension = Math.min(env.getHeight(), env.getWidth());
|
39492 | var snapTol = minDimension * GeometrySnapper.SNAP_PRECISION_FACTOR;
|
39493 | return snapTol
|
39494 | };
|
39495 | GeometrySnapper.snapToSelf = function snapToSelf (geom, snapTolerance, cleanResult) {
|
39496 | var snapper0 = new GeometrySnapper(geom);
|
39497 | return snapper0.snapToSelf(snapTolerance, cleanResult)
|
39498 | };
|
39499 | staticAccessors$41.SNAP_PRECISION_FACTOR.get = function () { return 1e-9 };
|
39500 |
|
39501 | Object.defineProperties( GeometrySnapper, staticAccessors$41 );
|
39502 |
|
39503 | var SnapTransformer = (function (GeometryTransformer$$1) {
|
39504 | function SnapTransformer (snapTolerance, snapPts, isSelfSnap) {
|
39505 | GeometryTransformer$$1.call(this);
|
39506 | this._snapTolerance = snapTolerance || null;
|
39507 | this._snapPts = snapPts || null;
|
39508 | this._isSelfSnap = (isSelfSnap !== undefined) ? isSelfSnap : false;
|
39509 | }
|
39510 |
|
39511 | if ( GeometryTransformer$$1 ) SnapTransformer.__proto__ = GeometryTransformer$$1;
|
39512 | SnapTransformer.prototype = Object.create( GeometryTransformer$$1 && GeometryTransformer$$1.prototype );
|
39513 | SnapTransformer.prototype.constructor = SnapTransformer;
|
39514 | SnapTransformer.prototype.snapLine = function snapLine (srcPts, snapPts) {
|
39515 | var snapper = new LineStringSnapper(srcPts, this._snapTolerance);
|
39516 | snapper.setAllowSnappingToSourceVertices(this._isSelfSnap);
|
39517 | return snapper.snapTo(snapPts)
|
39518 | };
|
39519 | SnapTransformer.prototype.transformCoordinates = function transformCoordinates (coords, parent) {
|
39520 | var srcPts = coords.toCoordinateArray();
|
39521 | var newPts = this.snapLine(srcPts, this._snapPts);
|
39522 | return this._factory.getCoordinateSequenceFactory().create(newPts)
|
39523 | };
|
39524 | SnapTransformer.prototype.interfaces_ = function interfaces_ () {
|
39525 | return []
|
39526 | };
|
39527 | SnapTransformer.prototype.getClass = function getClass () {
|
39528 | return SnapTransformer
|
39529 | };
|
39530 |
|
39531 | return SnapTransformer;
|
39532 | }(GeometryTransformer));
|
39533 |
|
39534 | var CommonBits = function CommonBits () {
|
39535 | this._isFirst = true;
|
39536 | this._commonMantissaBitsCount = 53;
|
39537 | this._commonBits = 0;
|
39538 | this._commonSignExp = null;
|
39539 | };
|
39540 | CommonBits.prototype.getCommon = function getCommon () {
|
39541 | return Double.longBitsToDouble(this._commonBits)
|
39542 | };
|
39543 | CommonBits.prototype.add = function add (num) {
|
39544 | var numBits = Double.doubleToLongBits(num);
|
39545 | if (this._isFirst) {
|
39546 | this._commonBits = numBits;
|
39547 | this._commonSignExp = CommonBits.signExpBits(this._commonBits);
|
39548 | this._isFirst = false;
|
39549 | return null
|
39550 | }
|
39551 | var numSignExp = CommonBits.signExpBits(numBits);
|
39552 | if (numSignExp !== this._commonSignExp) {
|
39553 | this._commonBits = 0;
|
39554 | return null
|
39555 | }
|
39556 | this._commonMantissaBitsCount = CommonBits.numCommonMostSigMantissaBits(this._commonBits, numBits);
|
39557 | this._commonBits = CommonBits.zeroLowerBits(this._commonBits, 64 - (12 + this._commonMantissaBitsCount));
|
39558 | };
|
39559 | CommonBits.prototype.toString = function toString () {
|
39560 | if (arguments.length === 1) {
|
39561 | var bits = arguments[0];
|
39562 | var x = Double.longBitsToDouble(bits);
|
39563 | var numStr = Double.toBinaryString(bits);
|
39564 | var padStr = '0000000000000000000000000000000000000000000000000000000000000000' + numStr;
|
39565 | var bitStr = padStr.substring(padStr.length - 64);
|
39566 | var str = bitStr.substring(0, 1) + ' ' + bitStr.substring(1, 12) + '(exp) ' + bitStr.substring(12) + ' [ ' + x + ' ]';
|
39567 | return str
|
39568 | }
|
39569 | };
|
39570 | CommonBits.prototype.interfaces_ = function interfaces_ () {
|
39571 | return []
|
39572 | };
|
39573 | CommonBits.prototype.getClass = function getClass () {
|
39574 | return CommonBits
|
39575 | };
|
39576 | CommonBits.getBit = function getBit (bits, i) {
|
39577 | var mask = 1 << i;
|
39578 | return (bits & mask) !== 0 ? 1 : 0
|
39579 | };
|
39580 | CommonBits.signExpBits = function signExpBits (num) {
|
39581 | return num >> 52
|
39582 | };
|
39583 | CommonBits.zeroLowerBits = function zeroLowerBits (bits, nBits) {
|
39584 | var invMask = (1 << nBits) - 1;
|
39585 | var mask = ~invMask;
|
39586 | var zeroed = bits & mask;
|
39587 | return zeroed
|
39588 | };
|
39589 | CommonBits.numCommonMostSigMantissaBits = function numCommonMostSigMantissaBits (num1, num2) {
|
39590 | var count = 0;
|
39591 | for (var i = 52; i >= 0; i--) {
|
39592 | if (CommonBits.getBit(num1, i) !== CommonBits.getBit(num2, i)) { return count }
|
39593 | count++;
|
39594 | }
|
39595 | return 52
|
39596 | };
|
39597 |
|
39598 | var CommonBitsRemover = function CommonBitsRemover () {
|
39599 | this._commonCoord = null;
|
39600 | this._ccFilter = new CommonCoordinateFilter();
|
39601 | };
|
39602 |
|
39603 | var staticAccessors$42 = { CommonCoordinateFilter: { configurable: true },Translater: { configurable: true } };
|
39604 | CommonBitsRemover.prototype.addCommonBits = function addCommonBits (geom) {
|
39605 | var trans = new Translater(this._commonCoord);
|
39606 | geom.apply(trans);
|
39607 | geom.geometryChanged();
|
39608 | };
|
39609 | CommonBitsRemover.prototype.removeCommonBits = function removeCommonBits (geom) {
|
39610 | if (this._commonCoord.x === 0.0 && this._commonCoord.y === 0.0) { return geom }
|
39611 | var invCoord = new Coordinate(this._commonCoord);
|
39612 | invCoord.x = -invCoord.x;
|
39613 | invCoord.y = -invCoord.y;
|
39614 | var trans = new Translater(invCoord);
|
39615 | geom.apply(trans);
|
39616 | geom.geometryChanged();
|
39617 | return geom
|
39618 | };
|
39619 | CommonBitsRemover.prototype.getCommonCoordinate = function getCommonCoordinate () {
|
39620 | return this._commonCoord
|
39621 | };
|
39622 | CommonBitsRemover.prototype.add = function add (geom) {
|
39623 | geom.apply(this._ccFilter);
|
39624 | this._commonCoord = this._ccFilter.getCommonCoordinate();
|
39625 | };
|
39626 | CommonBitsRemover.prototype.interfaces_ = function interfaces_ () {
|
39627 | return []
|
39628 | };
|
39629 | CommonBitsRemover.prototype.getClass = function getClass () {
|
39630 | return CommonBitsRemover
|
39631 | };
|
39632 | staticAccessors$42.CommonCoordinateFilter.get = function () { return CommonCoordinateFilter };
|
39633 | staticAccessors$42.Translater.get = function () { return Translater };
|
39634 |
|
39635 | Object.defineProperties( CommonBitsRemover, staticAccessors$42 );
|
39636 |
|
39637 | var CommonCoordinateFilter = function CommonCoordinateFilter () {
|
39638 | this._commonBitsX = new CommonBits();
|
39639 | this._commonBitsY = new CommonBits();
|
39640 | };
|
39641 | CommonCoordinateFilter.prototype.filter = function filter (coord) {
|
39642 | this._commonBitsX.add(coord.x);
|
39643 | this._commonBitsY.add(coord.y);
|
39644 | };
|
39645 | CommonCoordinateFilter.prototype.getCommonCoordinate = function getCommonCoordinate () {
|
39646 | return new Coordinate(this._commonBitsX.getCommon(), this._commonBitsY.getCommon())
|
39647 | };
|
39648 | CommonCoordinateFilter.prototype.interfaces_ = function interfaces_ () {
|
39649 | return [CoordinateFilter]
|
39650 | };
|
39651 | CommonCoordinateFilter.prototype.getClass = function getClass () {
|
39652 | return CommonCoordinateFilter
|
39653 | };
|
39654 |
|
39655 | var Translater = function Translater () {
|
39656 | this.trans = null;
|
39657 | var trans = arguments[0];
|
39658 | this.trans = trans;
|
39659 | };
|
39660 | Translater.prototype.filter = function filter (seq, i) {
|
39661 | var xp = seq.getOrdinate(i, 0) + this.trans.x;
|
39662 | var yp = seq.getOrdinate(i, 1) + this.trans.y;
|
39663 | seq.setOrdinate(i, 0, xp);
|
39664 | seq.setOrdinate(i, 1, yp);
|
39665 | };
|
39666 | Translater.prototype.isDone = function isDone () {
|
39667 | return false
|
39668 | };
|
39669 | Translater.prototype.isGeometryChanged = function isGeometryChanged () {
|
39670 | return true
|
39671 | };
|
39672 | Translater.prototype.interfaces_ = function interfaces_ () {
|
39673 | return [CoordinateSequenceFilter]
|
39674 | };
|
39675 | Translater.prototype.getClass = function getClass () {
|
39676 | return Translater
|
39677 | };
|
39678 |
|
39679 | var SnapOverlayOp = function SnapOverlayOp (g1, g2) {
|
39680 | this._geom = new Array(2).fill(null);
|
39681 | this._snapTolerance = null;
|
39682 | this._cbr = null;
|
39683 | this._geom[0] = g1;
|
39684 | this._geom[1] = g2;
|
39685 | this.computeSnapTolerance();
|
39686 | };
|
39687 | SnapOverlayOp.prototype.selfSnap = function selfSnap (geom) {
|
39688 | var snapper0 = new GeometrySnapper(geom);
|
39689 | var snapGeom = snapper0.snapTo(geom, this._snapTolerance);
|
39690 | return snapGeom
|
39691 | };
|
39692 | SnapOverlayOp.prototype.removeCommonBits = function removeCommonBits (geom) {
|
39693 | this._cbr = new CommonBitsRemover();
|
39694 | this._cbr.add(geom[0]);
|
39695 | this._cbr.add(geom[1]);
|
39696 | var remGeom = new Array(2).fill(null);
|
39697 | remGeom[0] = this._cbr.removeCommonBits(geom[0].copy());
|
39698 | remGeom[1] = this._cbr.removeCommonBits(geom[1].copy());
|
39699 | return remGeom
|
39700 | };
|
39701 | SnapOverlayOp.prototype.prepareResult = function prepareResult (geom) {
|
39702 | this._cbr.addCommonBits(geom);
|
39703 | return geom
|
39704 | };
|
39705 | SnapOverlayOp.prototype.getResultGeometry = function getResultGeometry (opCode) {
|
39706 | var prepGeom = this.snap(this._geom);
|
39707 | var result = OverlayOp.overlayOp(prepGeom[0], prepGeom[1], opCode);
|
39708 | return this.prepareResult(result)
|
39709 | };
|
39710 | SnapOverlayOp.prototype.checkValid = function checkValid (g) {
|
39711 | if (!g.isValid()) {
|
39712 | System.out.println('Snapped geometry is invalid');
|
39713 | }
|
39714 | };
|
39715 | SnapOverlayOp.prototype.computeSnapTolerance = function computeSnapTolerance () {
|
39716 | this._snapTolerance = GeometrySnapper.computeOverlaySnapTolerance(this._geom[0], this._geom[1]);
|
39717 | };
|
39718 | SnapOverlayOp.prototype.snap = function snap (geom) {
|
39719 | var remGeom = this.removeCommonBits(geom);
|
39720 | var snapGeom = GeometrySnapper.snap(remGeom[0], remGeom[1], this._snapTolerance);
|
39721 | return snapGeom
|
39722 | };
|
39723 | SnapOverlayOp.prototype.interfaces_ = function interfaces_ () {
|
39724 | return []
|
39725 | };
|
39726 | SnapOverlayOp.prototype.getClass = function getClass () {
|
39727 | return SnapOverlayOp
|
39728 | };
|
39729 | SnapOverlayOp.overlayOp = function overlayOp (g0, g1, opCode) {
|
39730 | var op = new SnapOverlayOp(g0, g1);
|
39731 | return op.getResultGeometry(opCode)
|
39732 | };
|
39733 | SnapOverlayOp.union = function union (g0, g1) {
|
39734 | return SnapOverlayOp.overlayOp(g0, g1, OverlayOp.UNION)
|
39735 | };
|
39736 | SnapOverlayOp.intersection = function intersection (g0, g1) {
|
39737 | return SnapOverlayOp.overlayOp(g0, g1, OverlayOp.INTERSECTION)
|
39738 | };
|
39739 | SnapOverlayOp.symDifference = function symDifference (g0, g1) {
|
39740 | return SnapOverlayOp.overlayOp(g0, g1, OverlayOp.SYMDIFFERENCE)
|
39741 | };
|
39742 | SnapOverlayOp.difference = function difference (g0, g1) {
|
39743 | return SnapOverlayOp.overlayOp(g0, g1, OverlayOp.DIFFERENCE)
|
39744 | };
|
39745 |
|
39746 | var SnapIfNeededOverlayOp = function SnapIfNeededOverlayOp (g1, g2) {
|
39747 | this._geom = new Array(2).fill(null);
|
39748 | this._geom[0] = g1;
|
39749 | this._geom[1] = g2;
|
39750 | };
|
39751 | SnapIfNeededOverlayOp.prototype.getResultGeometry = function getResultGeometry (opCode) {
|
39752 | var result = null;
|
39753 | var isSuccess = false;
|
39754 | var savedException = null;
|
39755 | try {
|
39756 | result = OverlayOp.overlayOp(this._geom[0], this._geom[1], opCode);
|
39757 | var isValid = true;
|
39758 | if (isValid) { isSuccess = true; }
|
39759 | } catch (ex) {
|
39760 | if (ex instanceof RuntimeException) {
|
39761 | savedException = ex;
|
39762 | } else { throw ex }
|
39763 | } finally {}
|
39764 | if (!isSuccess) {
|
39765 | try {
|
39766 | result = SnapOverlayOp.overlayOp(this._geom[0], this._geom[1], opCode);
|
39767 | } catch (ex) {
|
39768 | if (ex instanceof RuntimeException) {
|
39769 | throw savedException
|
39770 | } else { throw ex }
|
39771 | } finally {}
|
39772 | }
|
39773 | return result
|
39774 | };
|
39775 | SnapIfNeededOverlayOp.prototype.interfaces_ = function interfaces_ () {
|
39776 | return []
|
39777 | };
|
39778 | SnapIfNeededOverlayOp.prototype.getClass = function getClass () {
|
39779 | return SnapIfNeededOverlayOp
|
39780 | };
|
39781 | SnapIfNeededOverlayOp.overlayOp = function overlayOp (g0, g1, opCode) {
|
39782 | var op = new SnapIfNeededOverlayOp(g0, g1);
|
39783 | return op.getResultGeometry(opCode)
|
39784 | };
|
39785 | SnapIfNeededOverlayOp.union = function union (g0, g1) {
|
39786 | return SnapIfNeededOverlayOp.overlayOp(g0, g1, OverlayOp.UNION)
|
39787 | };
|
39788 | SnapIfNeededOverlayOp.intersection = function intersection (g0, g1) {
|
39789 | return SnapIfNeededOverlayOp.overlayOp(g0, g1, OverlayOp.INTERSECTION)
|
39790 | };
|
39791 | SnapIfNeededOverlayOp.symDifference = function symDifference (g0, g1) {
|
39792 | return SnapIfNeededOverlayOp.overlayOp(g0, g1, OverlayOp.SYMDIFFERENCE)
|
39793 | };
|
39794 | SnapIfNeededOverlayOp.difference = function difference (g0, g1) {
|
39795 | return SnapIfNeededOverlayOp.overlayOp(g0, g1, OverlayOp.DIFFERENCE)
|
39796 | };
|
39797 |
|
39798 | var MonotoneChain$2 = function MonotoneChain () {
|
39799 | this.mce = null;
|
39800 | this.chainIndex = null;
|
39801 | var mce = arguments[0];
|
39802 | var chainIndex = arguments[1];
|
39803 | this.mce = mce;
|
39804 | this.chainIndex = chainIndex;
|
39805 | };
|
39806 | MonotoneChain$2.prototype.computeIntersections = function computeIntersections (mc, si) {
|
39807 | this.mce.computeIntersectsForChain(this.chainIndex, mc.mce, mc.chainIndex, si);
|
39808 | };
|
39809 | MonotoneChain$2.prototype.interfaces_ = function interfaces_ () {
|
39810 | return []
|
39811 | };
|
39812 | MonotoneChain$2.prototype.getClass = function getClass () {
|
39813 | return MonotoneChain$2
|
39814 | };
|
39815 |
|
39816 | var SweepLineEvent = function SweepLineEvent () {
|
39817 | this._label = null;
|
39818 | this._xValue = null;
|
39819 | this._eventType = null;
|
39820 | this._insertEvent = null;
|
39821 | this._deleteEventIndex = null;
|
39822 | this._obj = null;
|
39823 | if (arguments.length === 2) {
|
39824 | var x = arguments[0];
|
39825 | var insertEvent = arguments[1];
|
39826 | this._eventType = SweepLineEvent.DELETE;
|
39827 | this._xValue = x;
|
39828 | this._insertEvent = insertEvent;
|
39829 | } else if (arguments.length === 3) {
|
39830 | var label = arguments[0];
|
39831 | var x$1 = arguments[1];
|
39832 | var obj = arguments[2];
|
39833 | this._eventType = SweepLineEvent.INSERT;
|
39834 | this._label = label;
|
39835 | this._xValue = x$1;
|
39836 | this._obj = obj;
|
39837 | }
|
39838 | };
|
39839 |
|
39840 | var staticAccessors$43 = { INSERT: { configurable: true },DELETE: { configurable: true } };
|
39841 | SweepLineEvent.prototype.isDelete = function isDelete () {
|
39842 | return this._eventType === SweepLineEvent.DELETE
|
39843 | };
|
39844 | SweepLineEvent.prototype.setDeleteEventIndex = function setDeleteEventIndex (deleteEventIndex) {
|
39845 | this._deleteEventIndex = deleteEventIndex;
|
39846 | };
|
39847 | SweepLineEvent.prototype.getObject = function getObject () {
|
39848 | return this._obj
|
39849 | };
|
39850 | SweepLineEvent.prototype.compareTo = function compareTo (o) {
|
39851 | var pe = o;
|
39852 | if (this._xValue < pe._xValue) { return -1 }
|
39853 | if (this._xValue > pe._xValue) { return 1 }
|
39854 | if (this._eventType < pe._eventType) { return -1 }
|
39855 | if (this._eventType > pe._eventType) { return 1 }
|
39856 | return 0
|
39857 | };
|
39858 | SweepLineEvent.prototype.getInsertEvent = function getInsertEvent () {
|
39859 | return this._insertEvent
|
39860 | };
|
39861 | SweepLineEvent.prototype.isInsert = function isInsert () {
|
39862 | return this._eventType === SweepLineEvent.INSERT
|
39863 | };
|
39864 | SweepLineEvent.prototype.isSameLabel = function isSameLabel (ev) {
|
39865 | if (this._label === null) { return false }
|
39866 | return this._label === ev._label
|
39867 | };
|
39868 | SweepLineEvent.prototype.getDeleteEventIndex = function getDeleteEventIndex () {
|
39869 | return this._deleteEventIndex
|
39870 | };
|
39871 | SweepLineEvent.prototype.interfaces_ = function interfaces_ () {
|
39872 | return [Comparable]
|
39873 | };
|
39874 | SweepLineEvent.prototype.getClass = function getClass () {
|
39875 | return SweepLineEvent
|
39876 | };
|
39877 | staticAccessors$43.INSERT.get = function () { return 1 };
|
39878 | staticAccessors$43.DELETE.get = function () { return 2 };
|
39879 |
|
39880 | Object.defineProperties( SweepLineEvent, staticAccessors$43 );
|
39881 |
|
39882 | var EdgeSetIntersector = function EdgeSetIntersector () {};
|
39883 |
|
39884 | EdgeSetIntersector.prototype.interfaces_ = function interfaces_ () {
|
39885 | return []
|
39886 | };
|
39887 | EdgeSetIntersector.prototype.getClass = function getClass () {
|
39888 | return EdgeSetIntersector
|
39889 | };
|
39890 |
|
39891 | var SegmentIntersector$2 = function SegmentIntersector () {
|
39892 | this._hasIntersection = false;
|
39893 | this._hasProper = false;
|
39894 | this._hasProperInterior = false;
|
39895 | this._properIntersectionPoint = null;
|
39896 | this._li = null;
|
39897 | this._includeProper = null;
|
39898 | this._recordIsolated = null;
|
39899 | this._isSelfIntersection = null;
|
39900 | this._numIntersections = 0;
|
39901 | this.numTests = 0;
|
39902 | this._bdyNodes = null;
|
39903 | this._isDone = false;
|
39904 | this._isDoneWhenProperInt = false;
|
39905 | var li = arguments[0];
|
39906 | var includeProper = arguments[1];
|
39907 | var recordIsolated = arguments[2];
|
39908 | this._li = li;
|
39909 | this._includeProper = includeProper;
|
39910 | this._recordIsolated = recordIsolated;
|
39911 | };
|
39912 | SegmentIntersector$2.prototype.isTrivialIntersection = function isTrivialIntersection (e0, segIndex0, e1, segIndex1) {
|
39913 | if (e0 === e1) {
|
39914 | if (this._li.getIntersectionNum() === 1) {
|
39915 | if (SegmentIntersector$2.isAdjacentSegments(segIndex0, segIndex1)) { return true }
|
39916 | if (e0.isClosed()) {
|
39917 | var maxSegIndex = e0.getNumPoints() - 1;
|
39918 | if ((segIndex0 === 0 && segIndex1 === maxSegIndex) ||
|
39919 | (segIndex1 === 0 && segIndex0 === maxSegIndex)) {
|
39920 | return true
|
39921 | }
|
39922 | }
|
39923 | }
|
39924 | }
|
39925 | return false
|
39926 | };
|
39927 | SegmentIntersector$2.prototype.getProperIntersectionPoint = function getProperIntersectionPoint () {
|
39928 | return this._properIntersectionPoint
|
39929 | };
|
39930 | SegmentIntersector$2.prototype.setIsDoneIfProperInt = function setIsDoneIfProperInt (isDoneWhenProperInt) {
|
39931 | this._isDoneWhenProperInt = isDoneWhenProperInt;
|
39932 | };
|
39933 | SegmentIntersector$2.prototype.hasProperInteriorIntersection = function hasProperInteriorIntersection () {
|
39934 | return this._hasProperInterior
|
39935 | };
|
39936 | SegmentIntersector$2.prototype.isBoundaryPointInternal = function isBoundaryPointInternal (li, bdyNodes) {
|
39937 | for (var i = bdyNodes.iterator(); i.hasNext();) {
|
39938 | var node = i.next();
|
39939 | var pt = node.getCoordinate();
|
39940 | if (li.isIntersection(pt)) { return true }
|
39941 | }
|
39942 | return false
|
39943 | };
|
39944 | SegmentIntersector$2.prototype.hasProperIntersection = function hasProperIntersection () {
|
39945 | return this._hasProper
|
39946 | };
|
39947 | SegmentIntersector$2.prototype.hasIntersection = function hasIntersection () {
|
39948 | return this._hasIntersection
|
39949 | };
|
39950 | SegmentIntersector$2.prototype.isDone = function isDone () {
|
39951 | return this._isDone
|
39952 | };
|
39953 | SegmentIntersector$2.prototype.isBoundaryPoint = function isBoundaryPoint (li, bdyNodes) {
|
39954 | if (bdyNodes === null) { return false }
|
39955 | if (this.isBoundaryPointInternal(li, bdyNodes[0])) { return true }
|
39956 | if (this.isBoundaryPointInternal(li, bdyNodes[1])) { return true }
|
39957 | return false
|
39958 | };
|
39959 | SegmentIntersector$2.prototype.setBoundaryNodes = function setBoundaryNodes (bdyNodes0, bdyNodes1) {
|
39960 | this._bdyNodes = new Array(2).fill(null);
|
39961 | this._bdyNodes[0] = bdyNodes0;
|
39962 | this._bdyNodes[1] = bdyNodes1;
|
39963 | };
|
39964 | SegmentIntersector$2.prototype.addIntersections = function addIntersections (e0, segIndex0, e1, segIndex1) {
|
39965 | if (e0 === e1 && segIndex0 === segIndex1) { return null }
|
39966 | this.numTests++;
|
39967 | var p00 = e0.getCoordinates()[segIndex0];
|
39968 | var p01 = e0.getCoordinates()[segIndex0 + 1];
|
39969 | var p10 = e1.getCoordinates()[segIndex1];
|
39970 | var p11 = e1.getCoordinates()[segIndex1 + 1];
|
39971 | this._li.computeIntersection(p00, p01, p10, p11);
|
39972 | if (this._li.hasIntersection()) {
|
39973 | if (this._recordIsolated) {
|
39974 | e0.setIsolated(false);
|
39975 | e1.setIsolated(false);
|
39976 | }
|
39977 | this._numIntersections++;
|
39978 | if (!this.isTrivialIntersection(e0, segIndex0, e1, segIndex1)) {
|
39979 | this._hasIntersection = true;
|
39980 | if (this._includeProper || !this._li.isProper()) {
|
39981 | e0.addIntersections(this._li, segIndex0, 0);
|
39982 | e1.addIntersections(this._li, segIndex1, 1);
|
39983 | }
|
39984 | if (this._li.isProper()) {
|
39985 | this._properIntersectionPoint = this._li.getIntersection(0).copy();
|
39986 | this._hasProper = true;
|
39987 | if (this._isDoneWhenProperInt) {
|
39988 | this._isDone = true;
|
39989 | }
|
39990 | if (!this.isBoundaryPoint(this._li, this._bdyNodes)) { this._hasProperInterior = true; }
|
39991 | }
|
39992 | }
|
39993 | }
|
39994 | };
|
39995 | SegmentIntersector$2.prototype.interfaces_ = function interfaces_ () {
|
39996 | return []
|
39997 | };
|
39998 | SegmentIntersector$2.prototype.getClass = function getClass () {
|
39999 | return SegmentIntersector$2
|
40000 | };
|
40001 | SegmentIntersector$2.isAdjacentSegments = function isAdjacentSegments (i1, i2) {
|
40002 | return Math.abs(i1 - i2) === 1
|
40003 | };
|
40004 |
|
40005 | var SimpleMCSweepLineIntersector = (function (EdgeSetIntersector$$1) {
|
40006 | function SimpleMCSweepLineIntersector () {
|
40007 | EdgeSetIntersector$$1.call(this);
|
40008 | this.events = new ArrayList();
|
40009 | this.nOverlaps = null;
|
40010 | }
|
40011 |
|
40012 | if ( EdgeSetIntersector$$1 ) SimpleMCSweepLineIntersector.__proto__ = EdgeSetIntersector$$1;
|
40013 | SimpleMCSweepLineIntersector.prototype = Object.create( EdgeSetIntersector$$1 && EdgeSetIntersector$$1.prototype );
|
40014 | SimpleMCSweepLineIntersector.prototype.constructor = SimpleMCSweepLineIntersector;
|
40015 | SimpleMCSweepLineIntersector.prototype.prepareEvents = function prepareEvents () {
|
40016 | var this$1 = this;
|
40017 |
|
40018 | Collections.sort(this.events);
|
40019 | for (var i = 0; i < this.events.size(); i++) {
|
40020 | var ev = this$1.events.get(i);
|
40021 | if (ev.isDelete()) {
|
40022 | ev.getInsertEvent().setDeleteEventIndex(i);
|
40023 | }
|
40024 | }
|
40025 | };
|
40026 | SimpleMCSweepLineIntersector.prototype.computeIntersections = function computeIntersections () {
|
40027 | var this$1 = this;
|
40028 |
|
40029 | if (arguments.length === 1) {
|
40030 | var si = arguments[0];
|
40031 | this.nOverlaps = 0;
|
40032 | this.prepareEvents();
|
40033 | for (var i = 0; i < this.events.size(); i++) {
|
40034 | var ev = this$1.events.get(i);
|
40035 | if (ev.isInsert()) {
|
40036 | this$1.processOverlaps(i, ev.getDeleteEventIndex(), ev, si);
|
40037 | }
|
40038 | if (si.isDone()) {
|
40039 | break
|
40040 | }
|
40041 | }
|
40042 | } else if (arguments.length === 3) {
|
40043 | if (arguments[2] instanceof SegmentIntersector$2 && (hasInterface(arguments[0], List) && hasInterface(arguments[1], List))) {
|
40044 | var edges0 = arguments[0];
|
40045 | var edges1 = arguments[1];
|
40046 | var si$1 = arguments[2];
|
40047 | this.addEdges(edges0, edges0);
|
40048 | this.addEdges(edges1, edges1);
|
40049 | this.computeIntersections(si$1);
|
40050 | } else if (typeof arguments[2] === 'boolean' && (hasInterface(arguments[0], List) && arguments[1] instanceof SegmentIntersector$2)) {
|
40051 | var edges = arguments[0];
|
40052 | var si$2 = arguments[1];
|
40053 | var testAllSegments = arguments[2];
|
40054 | if (testAllSegments) { this.addEdges(edges, null); } else { this.addEdges(edges); }
|
40055 | this.computeIntersections(si$2);
|
40056 | }
|
40057 | }
|
40058 | };
|
40059 | SimpleMCSweepLineIntersector.prototype.addEdge = function addEdge (edge, edgeSet) {
|
40060 | var this$1 = this;
|
40061 |
|
40062 | var mce = edge.getMonotoneChainEdge();
|
40063 | var startIndex = mce.getStartIndexes();
|
40064 | for (var i = 0; i < startIndex.length - 1; i++) {
|
40065 | var mc = new MonotoneChain$2(mce, i);
|
40066 | var insertEvent = new SweepLineEvent(edgeSet, mce.getMinX(i), mc);
|
40067 | this$1.events.add(insertEvent);
|
40068 | this$1.events.add(new SweepLineEvent(mce.getMaxX(i), insertEvent));
|
40069 | }
|
40070 | };
|
40071 | SimpleMCSweepLineIntersector.prototype.processOverlaps = function processOverlaps (start, end, ev0, si) {
|
40072 | var this$1 = this;
|
40073 |
|
40074 | var mc0 = ev0.getObject();
|
40075 | for (var i = start; i < end; i++) {
|
40076 | var ev1 = this$1.events.get(i);
|
40077 | if (ev1.isInsert()) {
|
40078 | var mc1 = ev1.getObject();
|
40079 | if (!ev0.isSameLabel(ev1)) {
|
40080 | mc0.computeIntersections(mc1, si);
|
40081 | this$1.nOverlaps++;
|
40082 | }
|
40083 | }
|
40084 | }
|
40085 | };
|
40086 | SimpleMCSweepLineIntersector.prototype.addEdges = function addEdges () {
|
40087 | var this$1 = this;
|
40088 |
|
40089 | if (arguments.length === 1) {
|
40090 | var edges = arguments[0];
|
40091 | for (var i = edges.iterator(); i.hasNext();) {
|
40092 | var edge = i.next();
|
40093 | this$1.addEdge(edge, edge);
|
40094 | }
|
40095 | } else if (arguments.length === 2) {
|
40096 | var edges$1 = arguments[0];
|
40097 | var edgeSet = arguments[1];
|
40098 | for (var i$1 = edges$1.iterator(); i$1.hasNext();) {
|
40099 | var edge$1 = i$1.next();
|
40100 | this$1.addEdge(edge$1, edgeSet);
|
40101 | }
|
40102 | }
|
40103 | };
|
40104 | SimpleMCSweepLineIntersector.prototype.interfaces_ = function interfaces_ () {
|
40105 | return []
|
40106 | };
|
40107 | SimpleMCSweepLineIntersector.prototype.getClass = function getClass () {
|
40108 | return SimpleMCSweepLineIntersector
|
40109 | };
|
40110 |
|
40111 | return SimpleMCSweepLineIntersector;
|
40112 | }(EdgeSetIntersector));
|
40113 |
|
40114 | var IntervalRTreeNode = function IntervalRTreeNode () {
|
40115 | this._min = Double.POSITIVE_INFINITY;
|
40116 | this._max = Double.NEGATIVE_INFINITY;
|
40117 | };
|
40118 |
|
40119 | var staticAccessors$45 = { NodeComparator: { configurable: true } };
|
40120 | IntervalRTreeNode.prototype.getMin = function getMin () {
|
40121 | return this._min
|
40122 | };
|
40123 | IntervalRTreeNode.prototype.intersects = function intersects (queryMin, queryMax) {
|
40124 | if (this._min > queryMax || this._max < queryMin) { return false }
|
40125 | return true
|
40126 | };
|
40127 | IntervalRTreeNode.prototype.getMax = function getMax () {
|
40128 | return this._max
|
40129 | };
|
40130 | IntervalRTreeNode.prototype.toString = function toString () {
|
40131 | return WKTWriter.toLineString(new Coordinate(this._min, 0), new Coordinate(this._max, 0))
|
40132 | };
|
40133 | IntervalRTreeNode.prototype.interfaces_ = function interfaces_ () {
|
40134 | return []
|
40135 | };
|
40136 | IntervalRTreeNode.prototype.getClass = function getClass () {
|
40137 | return IntervalRTreeNode
|
40138 | };
|
40139 | staticAccessors$45.NodeComparator.get = function () { return NodeComparator };
|
40140 |
|
40141 | Object.defineProperties( IntervalRTreeNode, staticAccessors$45 );
|
40142 |
|
40143 | var NodeComparator = function NodeComparator () {};
|
40144 |
|
40145 | NodeComparator.prototype.compare = function compare (o1, o2) {
|
40146 | var n1 = o1;
|
40147 | var n2 = o2;
|
40148 | var mid1 = (n1._min + n1._max) / 2;
|
40149 | var mid2 = (n2._min + n2._max) / 2;
|
40150 | if (mid1 < mid2) { return -1 }
|
40151 | if (mid1 > mid2) { return 1 }
|
40152 | return 0
|
40153 | };
|
40154 | NodeComparator.prototype.interfaces_ = function interfaces_ () {
|
40155 | return [Comparator]
|
40156 | };
|
40157 | NodeComparator.prototype.getClass = function getClass () {
|
40158 | return NodeComparator
|
40159 | };
|
40160 |
|
40161 | var IntervalRTreeLeafNode = (function (IntervalRTreeNode$$1) {
|
40162 | function IntervalRTreeLeafNode () {
|
40163 | IntervalRTreeNode$$1.call(this);
|
40164 | this._item = null;
|
40165 | var min = arguments[0];
|
40166 | var max = arguments[1];
|
40167 | var item = arguments[2];
|
40168 | this._min = min;
|
40169 | this._max = max;
|
40170 | this._item = item;
|
40171 | }
|
40172 |
|
40173 | if ( IntervalRTreeNode$$1 ) IntervalRTreeLeafNode.__proto__ = IntervalRTreeNode$$1;
|
40174 | IntervalRTreeLeafNode.prototype = Object.create( IntervalRTreeNode$$1 && IntervalRTreeNode$$1.prototype );
|
40175 | IntervalRTreeLeafNode.prototype.constructor = IntervalRTreeLeafNode;
|
40176 | IntervalRTreeLeafNode.prototype.query = function query (queryMin, queryMax, visitor) {
|
40177 | if (!this.intersects(queryMin, queryMax)) { return null }
|
40178 | visitor.visitItem(this._item);
|
40179 | };
|
40180 | IntervalRTreeLeafNode.prototype.interfaces_ = function interfaces_ () {
|
40181 | return []
|
40182 | };
|
40183 | IntervalRTreeLeafNode.prototype.getClass = function getClass () {
|
40184 | return IntervalRTreeLeafNode
|
40185 | };
|
40186 |
|
40187 | return IntervalRTreeLeafNode;
|
40188 | }(IntervalRTreeNode));
|
40189 |
|
40190 | var IntervalRTreeBranchNode = (function (IntervalRTreeNode$$1) {
|
40191 | function IntervalRTreeBranchNode () {
|
40192 | IntervalRTreeNode$$1.call(this);
|
40193 | this._node1 = null;
|
40194 | this._node2 = null;
|
40195 | var n1 = arguments[0];
|
40196 | var n2 = arguments[1];
|
40197 | this._node1 = n1;
|
40198 | this._node2 = n2;
|
40199 | this.buildExtent(this._node1, this._node2);
|
40200 | }
|
40201 |
|
40202 | if ( IntervalRTreeNode$$1 ) IntervalRTreeBranchNode.__proto__ = IntervalRTreeNode$$1;
|
40203 | IntervalRTreeBranchNode.prototype = Object.create( IntervalRTreeNode$$1 && IntervalRTreeNode$$1.prototype );
|
40204 | IntervalRTreeBranchNode.prototype.constructor = IntervalRTreeBranchNode;
|
40205 | IntervalRTreeBranchNode.prototype.buildExtent = function buildExtent (n1, n2) {
|
40206 | this._min = Math.min(n1._min, n2._min);
|
40207 | this._max = Math.max(n1._max, n2._max);
|
40208 | };
|
40209 | IntervalRTreeBranchNode.prototype.query = function query (queryMin, queryMax, visitor) {
|
40210 | if (!this.intersects(queryMin, queryMax)) {
|
40211 | return null
|
40212 | }
|
40213 | if (this._node1 !== null) { this._node1.query(queryMin, queryMax, visitor); }
|
40214 | if (this._node2 !== null) { this._node2.query(queryMin, queryMax, visitor); }
|
40215 | };
|
40216 | IntervalRTreeBranchNode.prototype.interfaces_ = function interfaces_ () {
|
40217 | return []
|
40218 | };
|
40219 | IntervalRTreeBranchNode.prototype.getClass = function getClass () {
|
40220 | return IntervalRTreeBranchNode
|
40221 | };
|
40222 |
|
40223 | return IntervalRTreeBranchNode;
|
40224 | }(IntervalRTreeNode));
|
40225 |
|
40226 | var SortedPackedIntervalRTree = function SortedPackedIntervalRTree () {
|
40227 | this._leaves = new ArrayList();
|
40228 | this._root = null;
|
40229 | this._level = 0;
|
40230 | };
|
40231 | SortedPackedIntervalRTree.prototype.buildTree = function buildTree () {
|
40232 | var this$1 = this;
|
40233 |
|
40234 | Collections.sort(this._leaves, new IntervalRTreeNode.NodeComparator());
|
40235 | var src = this._leaves;
|
40236 | var temp = null;
|
40237 | var dest = new ArrayList();
|
40238 | while (true) {
|
40239 | this$1.buildLevel(src, dest);
|
40240 | if (dest.size() === 1) { return dest.get(0) }
|
40241 | temp = src;
|
40242 | src = dest;
|
40243 | dest = temp;
|
40244 | }
|
40245 | };
|
40246 | SortedPackedIntervalRTree.prototype.insert = function insert (min, max, item) {
|
40247 | if (this._root !== null) { throw new Error('Index cannot be added to once it has been queried') }
|
40248 | this._leaves.add(new IntervalRTreeLeafNode(min, max, item));
|
40249 | };
|
40250 | SortedPackedIntervalRTree.prototype.query = function query (min, max, visitor) {
|
40251 | this.init();
|
40252 | this._root.query(min, max, visitor);
|
40253 | };
|
40254 | SortedPackedIntervalRTree.prototype.buildRoot = function buildRoot () {
|
40255 | if (this._root !== null) { return null }
|
40256 | this._root = this.buildTree();
|
40257 | };
|
40258 | SortedPackedIntervalRTree.prototype.printNode = function printNode (node) {
|
40259 | System.out.println(WKTWriter.toLineString(new Coordinate(node._min, this._level), new Coordinate(node._max, this._level)));
|
40260 | };
|
40261 | SortedPackedIntervalRTree.prototype.init = function init () {
|
40262 | if (this._root !== null) { return null }
|
40263 | this.buildRoot();
|
40264 | };
|
40265 | SortedPackedIntervalRTree.prototype.buildLevel = function buildLevel (src, dest) {
|
40266 | this._level++;
|
40267 | dest.clear();
|
40268 | for (var i = 0; i < src.size(); i += 2) {
|
40269 | var n1 = src.get(i);
|
40270 | var n2 = i + 1 < src.size() ? src.get(i) : null;
|
40271 | if (n2 === null) {
|
40272 | dest.add(n1);
|
40273 | } else {
|
40274 | var node = new IntervalRTreeBranchNode(src.get(i), src.get(i + 1));
|
40275 | dest.add(node);
|
40276 | }
|
40277 | }
|
40278 | };
|
40279 | SortedPackedIntervalRTree.prototype.interfaces_ = function interfaces_ () {
|
40280 | return []
|
40281 | };
|
40282 | SortedPackedIntervalRTree.prototype.getClass = function getClass () {
|
40283 | return SortedPackedIntervalRTree
|
40284 | };
|
40285 |
|
40286 | var ArrayListVisitor = function ArrayListVisitor () {
|
40287 | this._items = new ArrayList();
|
40288 | };
|
40289 | ArrayListVisitor.prototype.visitItem = function visitItem (item) {
|
40290 | this._items.add(item);
|
40291 | };
|
40292 | ArrayListVisitor.prototype.getItems = function getItems () {
|
40293 | return this._items
|
40294 | };
|
40295 | ArrayListVisitor.prototype.interfaces_ = function interfaces_ () {
|
40296 | return [ItemVisitor]
|
40297 | };
|
40298 | ArrayListVisitor.prototype.getClass = function getClass () {
|
40299 | return ArrayListVisitor
|
40300 | };
|
40301 |
|
40302 | var IndexedPointInAreaLocator = function IndexedPointInAreaLocator () {
|
40303 | this._index = null;
|
40304 | var g = arguments[0];
|
40305 | if (!hasInterface(g, Polygonal)) { throw new IllegalArgumentException('Argument must be Polygonal') }
|
40306 | this._index = new IntervalIndexedGeometry(g);
|
40307 | };
|
40308 |
|
40309 | var staticAccessors$44 = { SegmentVisitor: { configurable: true },IntervalIndexedGeometry: { configurable: true } };
|
40310 | IndexedPointInAreaLocator.prototype.locate = function locate (p) {
|
40311 | var rcc = new RayCrossingCounter(p);
|
40312 | var visitor = new SegmentVisitor(rcc);
|
40313 | this._index.query(p.y, p.y, visitor);
|
40314 | return rcc.getLocation()
|
40315 | };
|
40316 | IndexedPointInAreaLocator.prototype.interfaces_ = function interfaces_ () {
|
40317 | return [PointOnGeometryLocator]
|
40318 | };
|
40319 | IndexedPointInAreaLocator.prototype.getClass = function getClass () {
|
40320 | return IndexedPointInAreaLocator
|
40321 | };
|
40322 | staticAccessors$44.SegmentVisitor.get = function () { return SegmentVisitor };
|
40323 | staticAccessors$44.IntervalIndexedGeometry.get = function () { return IntervalIndexedGeometry };
|
40324 |
|
40325 | Object.defineProperties( IndexedPointInAreaLocator, staticAccessors$44 );
|
40326 |
|
40327 | var SegmentVisitor = function SegmentVisitor () {
|
40328 | this._counter = null;
|
40329 | var counter = arguments[0];
|
40330 | this._counter = counter;
|
40331 | };
|
40332 | SegmentVisitor.prototype.visitItem = function visitItem (item) {
|
40333 | var seg = item;
|
40334 | this._counter.countSegment(seg.getCoordinate(0), seg.getCoordinate(1));
|
40335 | };
|
40336 | SegmentVisitor.prototype.interfaces_ = function interfaces_ () {
|
40337 | return [ItemVisitor]
|
40338 | };
|
40339 | SegmentVisitor.prototype.getClass = function getClass () {
|
40340 | return SegmentVisitor
|
40341 | };
|
40342 |
|
40343 | var IntervalIndexedGeometry = function IntervalIndexedGeometry () {
|
40344 | this._index = new SortedPackedIntervalRTree();
|
40345 | var geom = arguments[0];
|
40346 | this.init(geom);
|
40347 | };
|
40348 | IntervalIndexedGeometry.prototype.init = function init (geom) {
|
40349 | var this$1 = this;
|
40350 |
|
40351 | var lines = LinearComponentExtracter.getLines(geom);
|
40352 | for (var i = lines.iterator(); i.hasNext();) {
|
40353 | var line = i.next();
|
40354 | var pts = line.getCoordinates();
|
40355 | this$1.addLine(pts);
|
40356 | }
|
40357 | };
|
40358 | IntervalIndexedGeometry.prototype.addLine = function addLine (pts) {
|
40359 | var this$1 = this;
|
40360 |
|
40361 | for (var i = 1; i < pts.length; i++) {
|
40362 | var seg = new LineSegment(pts[i - 1], pts[i]);
|
40363 | var min = Math.min(seg.p0.y, seg.p1.y);
|
40364 | var max = Math.max(seg.p0.y, seg.p1.y);
|
40365 | this$1._index.insert(min, max, seg);
|
40366 | }
|
40367 | };
|
40368 | IntervalIndexedGeometry.prototype.query = function query () {
|
40369 | if (arguments.length === 2) {
|
40370 | var min = arguments[0];
|
40371 | var max = arguments[1];
|
40372 | var visitor = new ArrayListVisitor();
|
40373 | this._index.query(min, max, visitor);
|
40374 | return visitor.getItems()
|
40375 | } else if (arguments.length === 3) {
|
40376 | var min$1 = arguments[0];
|
40377 | var max$1 = arguments[1];
|
40378 | var visitor$1 = arguments[2];
|
40379 | this._index.query(min$1, max$1, visitor$1);
|
40380 | }
|
40381 | };
|
40382 | IntervalIndexedGeometry.prototype.interfaces_ = function interfaces_ () {
|
40383 | return []
|
40384 | };
|
40385 | IntervalIndexedGeometry.prototype.getClass = function getClass () {
|
40386 | return IntervalIndexedGeometry
|
40387 | };
|
40388 |
|
40389 | var GeometryGraph = (function (PlanarGraph$$1) {
|
40390 | function GeometryGraph () {
|
40391 | PlanarGraph$$1.call(this);
|
40392 | this._parentGeom = null;
|
40393 | this._lineEdgeMap = new HashMap();
|
40394 | this._boundaryNodeRule = null;
|
40395 | this._useBoundaryDeterminationRule = true;
|
40396 | this._argIndex = null;
|
40397 | this._boundaryNodes = null;
|
40398 | this._hasTooFewPoints = false;
|
40399 | this._invalidPoint = null;
|
40400 | this._areaPtLocator = null;
|
40401 | this._ptLocator = new PointLocator();
|
40402 | if (arguments.length === 2) {
|
40403 | var argIndex = arguments[0];
|
40404 | var parentGeom = arguments[1];
|
40405 | var boundaryNodeRule = BoundaryNodeRule.OGC_SFS_BOUNDARY_RULE;
|
40406 | this._argIndex = argIndex;
|
40407 | this._parentGeom = parentGeom;
|
40408 | this._boundaryNodeRule = boundaryNodeRule;
|
40409 | if (parentGeom !== null) {
|
40410 | this.add(parentGeom);
|
40411 | }
|
40412 | } else if (arguments.length === 3) {
|
40413 | var argIndex$1 = arguments[0];
|
40414 | var parentGeom$1 = arguments[1];
|
40415 | var boundaryNodeRule$1 = arguments[2];
|
40416 | this._argIndex = argIndex$1;
|
40417 | this._parentGeom = parentGeom$1;
|
40418 | this._boundaryNodeRule = boundaryNodeRule$1;
|
40419 | if (parentGeom$1 !== null) {
|
40420 | this.add(parentGeom$1);
|
40421 | }
|
40422 | }
|
40423 | }
|
40424 |
|
40425 | if ( PlanarGraph$$1 ) GeometryGraph.__proto__ = PlanarGraph$$1;
|
40426 | GeometryGraph.prototype = Object.create( PlanarGraph$$1 && PlanarGraph$$1.prototype );
|
40427 | GeometryGraph.prototype.constructor = GeometryGraph;
|
40428 | GeometryGraph.prototype.insertBoundaryPoint = function insertBoundaryPoint (argIndex, coord) {
|
40429 | var n = this._nodes.addNode(coord);
|
40430 | var lbl = n.getLabel();
|
40431 | var boundaryCount = 1;
|
40432 | var loc = Location.NONE;
|
40433 | loc = lbl.getLocation(argIndex, Position.ON);
|
40434 | if (loc === Location.BOUNDARY) { boundaryCount++; }
|
40435 | var newLoc = GeometryGraph.determineBoundary(this._boundaryNodeRule, boundaryCount);
|
40436 | lbl.setLocation(argIndex, newLoc);
|
40437 | };
|
40438 | GeometryGraph.prototype.computeSelfNodes = function computeSelfNodes () {
|
40439 | if (arguments.length === 2) {
|
40440 | var li = arguments[0];
|
40441 | var computeRingSelfNodes = arguments[1];
|
40442 | return this.computeSelfNodes(li, computeRingSelfNodes, false)
|
40443 | } else if (arguments.length === 3) {
|
40444 | var li$1 = arguments[0];
|
40445 | var computeRingSelfNodes$1 = arguments[1];
|
40446 | var isDoneIfProperInt = arguments[2];
|
40447 | var si = new SegmentIntersector$2(li$1, true, false);
|
40448 | si.setIsDoneIfProperInt(isDoneIfProperInt);
|
40449 | var esi = this.createEdgeSetIntersector();
|
40450 | var isRings = this._parentGeom instanceof LinearRing || this._parentGeom instanceof Polygon || this._parentGeom instanceof MultiPolygon;
|
40451 | var computeAllSegments = computeRingSelfNodes$1 || !isRings;
|
40452 | esi.computeIntersections(this._edges, si, computeAllSegments);
|
40453 | this.addSelfIntersectionNodes(this._argIndex);
|
40454 | return si
|
40455 | }
|
40456 | };
|
40457 | GeometryGraph.prototype.computeSplitEdges = function computeSplitEdges (edgelist) {
|
40458 | for (var i = this._edges.iterator(); i.hasNext();) {
|
40459 | var e = i.next();
|
40460 | e.eiList.addSplitEdges(edgelist);
|
40461 | }
|
40462 | };
|
40463 | GeometryGraph.prototype.computeEdgeIntersections = function computeEdgeIntersections (g, li, includeProper) {
|
40464 | var si = new SegmentIntersector$2(li, includeProper, true);
|
40465 | si.setBoundaryNodes(this.getBoundaryNodes(), g.getBoundaryNodes());
|
40466 | var esi = this.createEdgeSetIntersector();
|
40467 | esi.computeIntersections(this._edges, g._edges, si);
|
40468 | return si
|
40469 | };
|
40470 | GeometryGraph.prototype.getGeometry = function getGeometry () {
|
40471 | return this._parentGeom
|
40472 | };
|
40473 | GeometryGraph.prototype.getBoundaryNodeRule = function getBoundaryNodeRule () {
|
40474 | return this._boundaryNodeRule
|
40475 | };
|
40476 | GeometryGraph.prototype.hasTooFewPoints = function hasTooFewPoints () {
|
40477 | return this._hasTooFewPoints
|
40478 | };
|
40479 | GeometryGraph.prototype.addPoint = function addPoint () {
|
40480 | if (arguments[0] instanceof Point) {
|
40481 | var p = arguments[0];
|
40482 | var coord = p.getCoordinate();
|
40483 | this.insertPoint(this._argIndex, coord, Location.INTERIOR);
|
40484 | } else if (arguments[0] instanceof Coordinate) {
|
40485 | var pt = arguments[0];
|
40486 | this.insertPoint(this._argIndex, pt, Location.INTERIOR);
|
40487 | }
|
40488 | };
|
40489 | GeometryGraph.prototype.addPolygon = function addPolygon (p) {
|
40490 | var this$1 = this;
|
40491 |
|
40492 | this.addPolygonRing(p.getExteriorRing(), Location.EXTERIOR, Location.INTERIOR);
|
40493 | for (var i = 0; i < p.getNumInteriorRing(); i++) {
|
40494 | var hole = p.getInteriorRingN(i);
|
40495 | this$1.addPolygonRing(hole, Location.INTERIOR, Location.EXTERIOR);
|
40496 | }
|
40497 | };
|
40498 | GeometryGraph.prototype.addEdge = function addEdge (e) {
|
40499 | this.insertEdge(e);
|
40500 | var coord = e.getCoordinates();
|
40501 | this.insertPoint(this._argIndex, coord[0], Location.BOUNDARY);
|
40502 | this.insertPoint(this._argIndex, coord[coord.length - 1], Location.BOUNDARY);
|
40503 | };
|
40504 | GeometryGraph.prototype.addLineString = function addLineString (line) {
|
40505 | var coord = CoordinateArrays.removeRepeatedPoints(line.getCoordinates());
|
40506 | if (coord.length < 2) {
|
40507 | this._hasTooFewPoints = true;
|
40508 | this._invalidPoint = coord[0];
|
40509 | return null
|
40510 | }
|
40511 | var e = new Edge$1(coord, new Label(this._argIndex, Location.INTERIOR));
|
40512 | this._lineEdgeMap.put(line, e);
|
40513 | this.insertEdge(e);
|
40514 | Assert.isTrue(coord.length >= 2, 'found LineString with single point');
|
40515 | this.insertBoundaryPoint(this._argIndex, coord[0]);
|
40516 | this.insertBoundaryPoint(this._argIndex, coord[coord.length - 1]);
|
40517 | };
|
40518 | GeometryGraph.prototype.getInvalidPoint = function getInvalidPoint () {
|
40519 | return this._invalidPoint
|
40520 | };
|
40521 | GeometryGraph.prototype.getBoundaryPoints = function getBoundaryPoints () {
|
40522 | var coll = this.getBoundaryNodes();
|
40523 | var pts = new Array(coll.size()).fill(null);
|
40524 | var i = 0;
|
40525 | for (var it = coll.iterator(); it.hasNext();) {
|
40526 | var node = it.next();
|
40527 | pts[i++] = node.getCoordinate().copy();
|
40528 | }
|
40529 | return pts
|
40530 | };
|
40531 | GeometryGraph.prototype.getBoundaryNodes = function getBoundaryNodes () {
|
40532 | if (this._boundaryNodes === null) { this._boundaryNodes = this._nodes.getBoundaryNodes(this._argIndex); }
|
40533 | return this._boundaryNodes
|
40534 | };
|
40535 | GeometryGraph.prototype.addSelfIntersectionNode = function addSelfIntersectionNode (argIndex, coord, loc) {
|
40536 | if (this.isBoundaryNode(argIndex, coord)) { return null }
|
40537 | if (loc === Location.BOUNDARY && this._useBoundaryDeterminationRule) { this.insertBoundaryPoint(argIndex, coord); } else { this.insertPoint(argIndex, coord, loc); }
|
40538 | };
|
40539 | GeometryGraph.prototype.addPolygonRing = function addPolygonRing (lr, cwLeft, cwRight) {
|
40540 | if (lr.isEmpty()) { return null }
|
40541 | var coord = CoordinateArrays.removeRepeatedPoints(lr.getCoordinates());
|
40542 | if (coord.length < 4) {
|
40543 | this._hasTooFewPoints = true;
|
40544 | this._invalidPoint = coord[0];
|
40545 | return null
|
40546 | }
|
40547 | var left = cwLeft;
|
40548 | var right = cwRight;
|
40549 | if (CGAlgorithms.isCCW(coord)) {
|
40550 | left = cwRight;
|
40551 | right = cwLeft;
|
40552 | }
|
40553 | var e = new Edge$1(coord, new Label(this._argIndex, Location.BOUNDARY, left, right));
|
40554 | this._lineEdgeMap.put(lr, e);
|
40555 | this.insertEdge(e);
|
40556 | this.insertPoint(this._argIndex, coord[0], Location.BOUNDARY);
|
40557 | };
|
40558 | GeometryGraph.prototype.insertPoint = function insertPoint (argIndex, coord, onLocation) {
|
40559 | var n = this._nodes.addNode(coord);
|
40560 | var lbl = n.getLabel();
|
40561 | if (lbl === null) {
|
40562 | n._label = new Label(argIndex, onLocation);
|
40563 | } else { lbl.setLocation(argIndex, onLocation); }
|
40564 | };
|
40565 | GeometryGraph.prototype.createEdgeSetIntersector = function createEdgeSetIntersector () {
|
40566 | return new SimpleMCSweepLineIntersector()
|
40567 | };
|
40568 | GeometryGraph.prototype.addSelfIntersectionNodes = function addSelfIntersectionNodes (argIndex) {
|
40569 | var this$1 = this;
|
40570 |
|
40571 | for (var i = this._edges.iterator(); i.hasNext();) {
|
40572 | var e = i.next();
|
40573 | var eLoc = e.getLabel().getLocation(argIndex);
|
40574 | for (var eiIt = e.eiList.iterator(); eiIt.hasNext();) {
|
40575 | var ei = eiIt.next();
|
40576 | this$1.addSelfIntersectionNode(argIndex, ei.coord, eLoc);
|
40577 | }
|
40578 | }
|
40579 | };
|
40580 | GeometryGraph.prototype.add = function add () {
|
40581 | if (arguments.length === 1) {
|
40582 | var g = arguments[0];
|
40583 | if (g.isEmpty()) { return null }
|
40584 | if (g instanceof MultiPolygon) { this._useBoundaryDeterminationRule = false; }
|
40585 | if (g instanceof Polygon) { this.addPolygon(g); }
|
40586 | else if (g instanceof LineString$1) { this.addLineString(g); }
|
40587 | else if (g instanceof Point) { this.addPoint(g); }
|
40588 | else if (g instanceof MultiPoint) { this.addCollection(g); }
|
40589 | else if (g instanceof MultiLineString) { this.addCollection(g); }
|
40590 | else if (g instanceof MultiPolygon) { this.addCollection(g); }
|
40591 | else if (g instanceof GeometryCollection) { this.addCollection(g); }
|
40592 | else { throw new Error(g.getClass().getName()) }
|
40593 | } else { return PlanarGraph$$1.prototype.add.apply(this, arguments) }
|
40594 | };
|
40595 | GeometryGraph.prototype.addCollection = function addCollection (gc) {
|
40596 | var this$1 = this;
|
40597 |
|
40598 | for (var i = 0; i < gc.getNumGeometries(); i++) {
|
40599 | var g = gc.getGeometryN(i);
|
40600 | this$1.add(g);
|
40601 | }
|
40602 | };
|
40603 | GeometryGraph.prototype.locate = function locate (pt) {
|
40604 | if (hasInterface(this._parentGeom, Polygonal) && this._parentGeom.getNumGeometries() > 50) {
|
40605 | if (this._areaPtLocator === null) {
|
40606 | this._areaPtLocator = new IndexedPointInAreaLocator(this._parentGeom);
|
40607 | }
|
40608 | return this._areaPtLocator.locate(pt)
|
40609 | }
|
40610 | return this._ptLocator.locate(pt, this._parentGeom)
|
40611 | };
|
40612 | GeometryGraph.prototype.findEdge = function findEdge () {
|
40613 | if (arguments.length === 1) {
|
40614 | var line = arguments[0];
|
40615 | return this._lineEdgeMap.get(line)
|
40616 | } else { return PlanarGraph$$1.prototype.findEdge.apply(this, arguments) }
|
40617 | };
|
40618 | GeometryGraph.prototype.interfaces_ = function interfaces_ () {
|
40619 | return []
|
40620 | };
|
40621 | GeometryGraph.prototype.getClass = function getClass () {
|
40622 | return GeometryGraph
|
40623 | };
|
40624 | GeometryGraph.determineBoundary = function determineBoundary (boundaryNodeRule, boundaryCount) {
|
40625 | return boundaryNodeRule.isInBoundary(boundaryCount) ? Location.BOUNDARY : Location.INTERIOR
|
40626 | };
|
40627 |
|
40628 | return GeometryGraph;
|
40629 | }(PlanarGraph));
|
40630 |
|
40631 | var GeometryGraphOp = function GeometryGraphOp () {
|
40632 | this._li = new RobustLineIntersector();
|
40633 | this._resultPrecisionModel = null;
|
40634 | this._arg = null;
|
40635 | if (arguments.length === 1) {
|
40636 | var g0 = arguments[0];
|
40637 | this.setComputationPrecision(g0.getPrecisionModel());
|
40638 | this._arg = new Array(1).fill(null);
|
40639 | this._arg[0] = new GeometryGraph(0, g0);
|
40640 | } else if (arguments.length === 2) {
|
40641 | var g0$1 = arguments[0];
|
40642 | var g1 = arguments[1];
|
40643 | var boundaryNodeRule = BoundaryNodeRule.OGC_SFS_BOUNDARY_RULE;
|
40644 | if (g0$1.getPrecisionModel().compareTo(g1.getPrecisionModel()) >= 0) { this.setComputationPrecision(g0$1.getPrecisionModel()); } else { this.setComputationPrecision(g1.getPrecisionModel()); }
|
40645 | this._arg = new Array(2).fill(null);
|
40646 | this._arg[0] = new GeometryGraph(0, g0$1, boundaryNodeRule);
|
40647 | this._arg[1] = new GeometryGraph(1, g1, boundaryNodeRule);
|
40648 | } else if (arguments.length === 3) {
|
40649 | var g0$2 = arguments[0];
|
40650 | var g1$1 = arguments[1];
|
40651 | var boundaryNodeRule$1 = arguments[2];
|
40652 | if (g0$2.getPrecisionModel().compareTo(g1$1.getPrecisionModel()) >= 0) { this.setComputationPrecision(g0$2.getPrecisionModel()); } else { this.setComputationPrecision(g1$1.getPrecisionModel()); }
|
40653 | this._arg = new Array(2).fill(null);
|
40654 | this._arg[0] = new GeometryGraph(0, g0$2, boundaryNodeRule$1);
|
40655 | this._arg[1] = new GeometryGraph(1, g1$1, boundaryNodeRule$1);
|
40656 | }
|
40657 | };
|
40658 | GeometryGraphOp.prototype.getArgGeometry = function getArgGeometry (i) {
|
40659 | return this._arg[i].getGeometry()
|
40660 | };
|
40661 | GeometryGraphOp.prototype.setComputationPrecision = function setComputationPrecision (pm) {
|
40662 | this._resultPrecisionModel = pm;
|
40663 | this._li.setPrecisionModel(this._resultPrecisionModel);
|
40664 | };
|
40665 | GeometryGraphOp.prototype.interfaces_ = function interfaces_ () {
|
40666 | return []
|
40667 | };
|
40668 | GeometryGraphOp.prototype.getClass = function getClass () {
|
40669 | return GeometryGraphOp
|
40670 | };
|
40671 |
|
40672 |
|
40673 |
|
40674 | var GeometryMapper = function GeometryMapper () {};
|
40675 |
|
40676 | GeometryMapper.prototype.interfaces_ = function interfaces_ () {
|
40677 | return []
|
40678 | };
|
40679 | GeometryMapper.prototype.getClass = function getClass () {
|
40680 | return GeometryMapper
|
40681 | };
|
40682 | GeometryMapper.map = function map () {
|
40683 | if (arguments[0] instanceof Geometry && hasInterface(arguments[1], GeometryMapper.MapOp)) {
|
40684 | var geom = arguments[0];
|
40685 | var op = arguments[1];
|
40686 | var mapped = new ArrayList();
|
40687 | for (var i = 0; i < geom.getNumGeometries(); i++) {
|
40688 | var g = op.map(geom.getGeometryN(i));
|
40689 | if (g !== null) { mapped.add(g); }
|
40690 | }
|
40691 | return geom.getFactory().buildGeometry(mapped)
|
40692 | } else if (hasInterface(arguments[0], Collection) && hasInterface(arguments[1], GeometryMapper.MapOp)) {
|
40693 | var geoms = arguments[0];
|
40694 | var op$1 = arguments[1];
|
40695 | var mapped$1 = new ArrayList();
|
40696 | for (var i$1 = geoms.iterator(); i$1.hasNext();) {
|
40697 | var g$1 = i$1.next();
|
40698 | var gr = op$1.map(g$1);
|
40699 | if (gr !== null) { mapped$1.add(gr); }
|
40700 | }
|
40701 | return mapped$1
|
40702 | }
|
40703 | };
|
40704 | GeometryMapper.MapOp = function MapOp () {};
|
40705 |
|
40706 | var OverlayOp = (function (GeometryGraphOp) {
|
40707 | function OverlayOp () {
|
40708 | var g0 = arguments[0];
|
40709 | var g1 = arguments[1];
|
40710 | GeometryGraphOp.call(this, g0, g1);
|
40711 | this._ptLocator = new PointLocator();
|
40712 | this._geomFact = null;
|
40713 | this._resultGeom = null;
|
40714 | this._graph = null;
|
40715 | this._edgeList = new EdgeList();
|
40716 | this._resultPolyList = new ArrayList();
|
40717 | this._resultLineList = new ArrayList();
|
40718 | this._resultPointList = new ArrayList();
|
40719 | this._graph = new PlanarGraph(new OverlayNodeFactory());
|
40720 | this._geomFact = g0.getFactory();
|
40721 | }
|
40722 |
|
40723 | if ( GeometryGraphOp ) OverlayOp.__proto__ = GeometryGraphOp;
|
40724 | OverlayOp.prototype = Object.create( GeometryGraphOp && GeometryGraphOp.prototype );
|
40725 | OverlayOp.prototype.constructor = OverlayOp;
|
40726 | OverlayOp.prototype.insertUniqueEdge = function insertUniqueEdge (e) {
|
40727 | var existingEdge = this._edgeList.findEqualEdge(e);
|
40728 | if (existingEdge !== null) {
|
40729 | var existingLabel = existingEdge.getLabel();
|
40730 | var labelToMerge = e.getLabel();
|
40731 | if (!existingEdge.isPointwiseEqual(e)) {
|
40732 | labelToMerge = new Label(e.getLabel());
|
40733 | labelToMerge.flip();
|
40734 | }
|
40735 | var depth = existingEdge.getDepth();
|
40736 | if (depth.isNull()) {
|
40737 | depth.add(existingLabel);
|
40738 | }
|
40739 | depth.add(labelToMerge);
|
40740 | existingLabel.merge(labelToMerge);
|
40741 | } else {
|
40742 | this._edgeList.add(e);
|
40743 | }
|
40744 | };
|
40745 | OverlayOp.prototype.getGraph = function getGraph () {
|
40746 | return this._graph
|
40747 | };
|
40748 | OverlayOp.prototype.cancelDuplicateResultEdges = function cancelDuplicateResultEdges () {
|
40749 | for (var it = this._graph.getEdgeEnds().iterator(); it.hasNext();) {
|
40750 | var de = it.next();
|
40751 | var sym = de.getSym();
|
40752 | if (de.isInResult() && sym.isInResult()) {
|
40753 | de.setInResult(false);
|
40754 | sym.setInResult(false);
|
40755 | }
|
40756 | }
|
40757 | };
|
40758 | OverlayOp.prototype.isCoveredByLA = function isCoveredByLA (coord) {
|
40759 | if (this.isCovered(coord, this._resultLineList)) { return true }
|
40760 | if (this.isCovered(coord, this._resultPolyList)) { return true }
|
40761 | return false
|
40762 | };
|
40763 | OverlayOp.prototype.computeGeometry = function computeGeometry (resultPointList, resultLineList, resultPolyList, opcode) {
|
40764 | var geomList = new ArrayList();
|
40765 | geomList.addAll(resultPointList);
|
40766 | geomList.addAll(resultLineList);
|
40767 | geomList.addAll(resultPolyList);
|
40768 | if (geomList.isEmpty()) { return OverlayOp.createEmptyResult(opcode, this._arg[0].getGeometry(), this._arg[1].getGeometry(), this._geomFact) }
|
40769 | return this._geomFact.buildGeometry(geomList)
|
40770 | };
|
40771 | OverlayOp.prototype.mergeSymLabels = function mergeSymLabels () {
|
40772 | for (var nodeit = this._graph.getNodes().iterator(); nodeit.hasNext();) {
|
40773 | var node = nodeit.next();
|
40774 | node.getEdges().mergeSymLabels();
|
40775 | }
|
40776 | };
|
40777 | OverlayOp.prototype.isCovered = function isCovered (coord, geomList) {
|
40778 | var this$1 = this;
|
40779 |
|
40780 | for (var it = geomList.iterator(); it.hasNext();) {
|
40781 | var geom = it.next();
|
40782 | var loc = this$1._ptLocator.locate(coord, geom);
|
40783 | if (loc !== Location.EXTERIOR) { return true }
|
40784 | }
|
40785 | return false
|
40786 | };
|
40787 | OverlayOp.prototype.replaceCollapsedEdges = function replaceCollapsedEdges () {
|
40788 | var newEdges = new ArrayList();
|
40789 | for (var it = this._edgeList.iterator(); it.hasNext();) {
|
40790 | var e = it.next();
|
40791 | if (e.isCollapsed()) {
|
40792 | it.remove();
|
40793 | newEdges.add(e.getCollapsedEdge());
|
40794 | }
|
40795 | }
|
40796 | this._edgeList.addAll(newEdges);
|
40797 | };
|
40798 | OverlayOp.prototype.updateNodeLabelling = function updateNodeLabelling () {
|
40799 | for (var nodeit = this._graph.getNodes().iterator(); nodeit.hasNext();) {
|
40800 | var node = nodeit.next();
|
40801 | var lbl = node.getEdges().getLabel();
|
40802 | node.getLabel().merge(lbl);
|
40803 | }
|
40804 | };
|
40805 | OverlayOp.prototype.getResultGeometry = function getResultGeometry (overlayOpCode) {
|
40806 | this.computeOverlay(overlayOpCode);
|
40807 | return this._resultGeom
|
40808 | };
|
40809 | OverlayOp.prototype.insertUniqueEdges = function insertUniqueEdges (edges) {
|
40810 | var this$1 = this;
|
40811 |
|
40812 | for (var i = edges.iterator(); i.hasNext();) {
|
40813 | var e = i.next();
|
40814 | this$1.insertUniqueEdge(e);
|
40815 | }
|
40816 | };
|
40817 | OverlayOp.prototype.computeOverlay = function computeOverlay (opCode) {
|
40818 | this.copyPoints(0);
|
40819 | this.copyPoints(1);
|
40820 | this._arg[0].computeSelfNodes(this._li, false);
|
40821 | this._arg[1].computeSelfNodes(this._li, false);
|
40822 | this._arg[0].computeEdgeIntersections(this._arg[1], this._li, true);
|
40823 | var baseSplitEdges = new ArrayList();
|
40824 | this._arg[0].computeSplitEdges(baseSplitEdges);
|
40825 | this._arg[1].computeSplitEdges(baseSplitEdges);
|
40826 |
|
40827 | this.insertUniqueEdges(baseSplitEdges);
|
40828 | this.computeLabelsFromDepths();
|
40829 | this.replaceCollapsedEdges();
|
40830 | EdgeNodingValidator.checkValid(this._edgeList.getEdges());
|
40831 | this._graph.addEdges(this._edgeList.getEdges());
|
40832 | this.computeLabelling();
|
40833 | this.labelIncompleteNodes();
|
40834 | this.findResultAreaEdges(opCode);
|
40835 | this.cancelDuplicateResultEdges();
|
40836 | var polyBuilder = new PolygonBuilder(this._geomFact);
|
40837 | polyBuilder.add(this._graph);
|
40838 | this._resultPolyList = polyBuilder.getPolygons();
|
40839 | var lineBuilder = new LineBuilder(this, this._geomFact, this._ptLocator);
|
40840 | this._resultLineList = lineBuilder.build(opCode);
|
40841 | var pointBuilder = new PointBuilder(this, this._geomFact, this._ptLocator);
|
40842 | this._resultPointList = pointBuilder.build(opCode);
|
40843 | this._resultGeom = this.computeGeometry(this._resultPointList, this._resultLineList, this._resultPolyList, opCode);
|
40844 | };
|
40845 | OverlayOp.prototype.labelIncompleteNode = function labelIncompleteNode (n, targetIndex) {
|
40846 | var loc = this._ptLocator.locate(n.getCoordinate(), this._arg[targetIndex].getGeometry());
|
40847 | n.getLabel().setLocation(targetIndex, loc);
|
40848 | };
|
40849 | OverlayOp.prototype.copyPoints = function copyPoints (argIndex) {
|
40850 | var this$1 = this;
|
40851 |
|
40852 | for (var i = this._arg[argIndex].getNodeIterator(); i.hasNext();) {
|
40853 | var graphNode = i.next();
|
40854 | var newNode = this$1._graph.addNode(graphNode.getCoordinate());
|
40855 | newNode.setLabel(argIndex, graphNode.getLabel().getLocation(argIndex));
|
40856 | }
|
40857 | };
|
40858 | OverlayOp.prototype.findResultAreaEdges = function findResultAreaEdges (opCode) {
|
40859 | for (var it = this._graph.getEdgeEnds().iterator(); it.hasNext();) {
|
40860 | var de = it.next();
|
40861 | var label = de.getLabel();
|
40862 | if (label.isArea() && !de.isInteriorAreaEdge() && OverlayOp.isResultOfOp(label.getLocation(0, Position.RIGHT), label.getLocation(1, Position.RIGHT), opCode)) {
|
40863 | de.setInResult(true);
|
40864 | }
|
40865 | }
|
40866 | };
|
40867 | OverlayOp.prototype.computeLabelsFromDepths = function computeLabelsFromDepths () {
|
40868 | for (var it = this._edgeList.iterator(); it.hasNext();) {
|
40869 | var e = it.next();
|
40870 | var lbl = e.getLabel();
|
40871 | var depth = e.getDepth();
|
40872 | if (!depth.isNull()) {
|
40873 | depth.normalize();
|
40874 | for (var i = 0; i < 2; i++) {
|
40875 | if (!lbl.isNull(i) && lbl.isArea() && !depth.isNull(i)) {
|
40876 | if (depth.getDelta(i) === 0) {
|
40877 | lbl.toLine(i);
|
40878 | } else {
|
40879 | Assert.isTrue(!depth.isNull(i, Position.LEFT), 'depth of LEFT side has not been initialized');
|
40880 | lbl.setLocation(i, Position.LEFT, depth.getLocation(i, Position.LEFT));
|
40881 | Assert.isTrue(!depth.isNull(i, Position.RIGHT), 'depth of RIGHT side has not been initialized');
|
40882 | lbl.setLocation(i, Position.RIGHT, depth.getLocation(i, Position.RIGHT));
|
40883 | }
|
40884 | }
|
40885 | }
|
40886 | }
|
40887 | }
|
40888 | };
|
40889 | OverlayOp.prototype.computeLabelling = function computeLabelling () {
|
40890 | var this$1 = this;
|
40891 |
|
40892 | for (var nodeit = this._graph.getNodes().iterator(); nodeit.hasNext();) {
|
40893 | var node = nodeit.next();
|
40894 | node.getEdges().computeLabelling(this$1._arg);
|
40895 | }
|
40896 | this.mergeSymLabels();
|
40897 | this.updateNodeLabelling();
|
40898 | };
|
40899 | OverlayOp.prototype.labelIncompleteNodes = function labelIncompleteNodes () {
|
40900 | var this$1 = this;
|
40901 |
|
40902 |
|
40903 | for (var ni = this._graph.getNodes().iterator(); ni.hasNext();) {
|
40904 | var n = ni.next();
|
40905 | var label = n.getLabel();
|
40906 | if (n.isIsolated()) {
|
40907 |
|
40908 | if (label.isNull(0)) { this$1.labelIncompleteNode(n, 0); } else { this$1.labelIncompleteNode(n, 1); }
|
40909 | }
|
40910 | n.getEdges().updateLabelling(label);
|
40911 | }
|
40912 | };
|
40913 | OverlayOp.prototype.isCoveredByA = function isCoveredByA (coord) {
|
40914 | if (this.isCovered(coord, this._resultPolyList)) { return true }
|
40915 | return false
|
40916 | };
|
40917 | OverlayOp.prototype.interfaces_ = function interfaces_ () {
|
40918 | return []
|
40919 | };
|
40920 | OverlayOp.prototype.getClass = function getClass () {
|
40921 | return OverlayOp
|
40922 | };
|
40923 |
|
40924 | return OverlayOp;
|
40925 | }(GeometryGraphOp));
|
40926 |
|
40927 | OverlayOp.overlayOp = function (geom0, geom1, opCode) {
|
40928 | var gov = new OverlayOp(geom0, geom1);
|
40929 | var geomOv = gov.getResultGeometry(opCode);
|
40930 | return geomOv
|
40931 | };
|
40932 | OverlayOp.intersection = function (g, other) {
|
40933 | if (g.isEmpty() || other.isEmpty()) { return OverlayOp.createEmptyResult(OverlayOp.INTERSECTION, g, other, g.getFactory()) }
|
40934 | if (g.isGeometryCollection()) {
|
40935 | var g2 = other;
|
40936 | return GeometryCollectionMapper.map(g, {
|
40937 | interfaces_: function () {
|
40938 | return [GeometryMapper.MapOp]
|
40939 | },
|
40940 | map: function (g) {
|
40941 | return g.intersection(g2)
|
40942 | }
|
40943 | })
|
40944 | }
|
40945 | g.checkNotGeometryCollection(g);
|
40946 | g.checkNotGeometryCollection(other);
|
40947 | return SnapIfNeededOverlayOp.overlayOp(g, other, OverlayOp.INTERSECTION)
|
40948 | };
|
40949 | OverlayOp.symDifference = function (g, other) {
|
40950 | if (g.isEmpty() || other.isEmpty()) {
|
40951 | if (g.isEmpty() && other.isEmpty()) { return OverlayOp.createEmptyResult(OverlayOp.SYMDIFFERENCE, g, other, g.getFactory()) }
|
40952 | if (g.isEmpty()) { return other.copy() }
|
40953 | if (other.isEmpty()) { return g.copy() }
|
40954 | }
|
40955 | g.checkNotGeometryCollection(g);
|
40956 | g.checkNotGeometryCollection(other);
|
40957 | return SnapIfNeededOverlayOp.overlayOp(g, other, OverlayOp.SYMDIFFERENCE)
|
40958 | };
|
40959 | OverlayOp.resultDimension = function (opCode, g0, g1) {
|
40960 | var dim0 = g0.getDimension();
|
40961 | var dim1 = g1.getDimension();
|
40962 | var resultDimension = -1;
|
40963 | switch (opCode) {
|
40964 | case OverlayOp.INTERSECTION:
|
40965 | resultDimension = Math.min(dim0, dim1);
|
40966 | break
|
40967 | case OverlayOp.UNION:
|
40968 | resultDimension = Math.max(dim0, dim1);
|
40969 | break
|
40970 | case OverlayOp.DIFFERENCE:
|
40971 | resultDimension = dim0;
|
40972 | break
|
40973 | case OverlayOp.SYMDIFFERENCE:
|
40974 | resultDimension = Math.max(dim0, dim1);
|
40975 | break
|
40976 | default:
|
40977 | }
|
40978 | return resultDimension
|
40979 | };
|
40980 | OverlayOp.createEmptyResult = function (overlayOpCode, a, b, geomFact) {
|
40981 | var result = null;
|
40982 | switch (OverlayOp.resultDimension(overlayOpCode, a, b)) {
|
40983 | case -1:
|
40984 | result = geomFact.createGeometryCollection(new Array(0).fill(null));
|
40985 | break
|
40986 | case 0:
|
40987 | result = geomFact.createPoint();
|
40988 | break
|
40989 | case 1:
|
40990 | result = geomFact.createLineString();
|
40991 | break
|
40992 | case 2:
|
40993 | result = geomFact.createPolygon();
|
40994 | break
|
40995 | default:
|
40996 | }
|
40997 | return result
|
40998 | };
|
40999 | OverlayOp.difference = function (g, other) {
|
41000 | if (g.isEmpty()) { return OverlayOp.createEmptyResult(OverlayOp.DIFFERENCE, g, other, g.getFactory()) }
|
41001 | if (other.isEmpty()) { return g.copy() }
|
41002 | g.checkNotGeometryCollection(g);
|
41003 | g.checkNotGeometryCollection(other);
|
41004 | return SnapIfNeededOverlayOp.overlayOp(g, other, OverlayOp.DIFFERENCE)
|
41005 | };
|
41006 | OverlayOp.isResultOfOp = function () {
|
41007 | if (arguments.length === 2) {
|
41008 | var label = arguments[0];
|
41009 | var opCode = arguments[1];
|
41010 | var loc0 = label.getLocation(0);
|
41011 | var loc1 = label.getLocation(1);
|
41012 | return OverlayOp.isResultOfOp(loc0, loc1, opCode)
|
41013 | } else if (arguments.length === 3) {
|
41014 | var loc0$1 = arguments[0];
|
41015 | var loc1$1 = arguments[1];
|
41016 | var overlayOpCode = arguments[2];
|
41017 | if (loc0$1 === Location.BOUNDARY) { loc0$1 = Location.INTERIOR; }
|
41018 | if (loc1$1 === Location.BOUNDARY) { loc1$1 = Location.INTERIOR; }
|
41019 | switch (overlayOpCode) {
|
41020 | case OverlayOp.INTERSECTION:
|
41021 | return loc0$1 === Location.INTERIOR && loc1$1 === Location.INTERIOR
|
41022 | case OverlayOp.UNION:
|
41023 | return loc0$1 === Location.INTERIOR || loc1$1 === Location.INTERIOR
|
41024 | case OverlayOp.DIFFERENCE:
|
41025 | return loc0$1 === Location.INTERIOR && loc1$1 !== Location.INTERIOR
|
41026 | case OverlayOp.SYMDIFFERENCE:
|
41027 | return (loc0$1 === Location.INTERIOR && loc1$1 !== Location.INTERIOR) || (loc0$1 !== Location.INTERIOR && loc1$1 === Location.INTERIOR)
|
41028 | default:
|
41029 | }
|
41030 | return false
|
41031 | }
|
41032 | };
|
41033 | OverlayOp.INTERSECTION = 1;
|
41034 | OverlayOp.UNION = 2;
|
41035 | OverlayOp.DIFFERENCE = 3;
|
41036 | OverlayOp.SYMDIFFERENCE = 4;
|
41037 |
|
41038 | var FuzzyPointLocator = function FuzzyPointLocator () {
|
41039 | this._g = null;
|
41040 | this._boundaryDistanceTolerance = null;
|
41041 | this._linework = null;
|
41042 | this._ptLocator = new PointLocator();
|
41043 | this._seg = new LineSegment();
|
41044 | var g = arguments[0];
|
41045 | var boundaryDistanceTolerance = arguments[1];
|
41046 | this._g = g;
|
41047 | this._boundaryDistanceTolerance = boundaryDistanceTolerance;
|
41048 | this._linework = this.extractLinework(g);
|
41049 | };
|
41050 | FuzzyPointLocator.prototype.isWithinToleranceOfBoundary = function isWithinToleranceOfBoundary (pt) {
|
41051 | var this$1 = this;
|
41052 |
|
41053 | for (var i = 0; i < this._linework.getNumGeometries(); i++) {
|
41054 | var line = this$1._linework.getGeometryN(i);
|
41055 | var seq = line.getCoordinateSequence();
|
41056 | for (var j = 0; j < seq.size() - 1; j++) {
|
41057 | seq.getCoordinate(j, this$1._seg.p0);
|
41058 | seq.getCoordinate(j + 1, this$1._seg.p1);
|
41059 | var dist = this$1._seg.distance(pt);
|
41060 | if (dist <= this$1._boundaryDistanceTolerance) { return true }
|
41061 | }
|
41062 | }
|
41063 | return false
|
41064 | };
|
41065 | FuzzyPointLocator.prototype.getLocation = function getLocation (pt) {
|
41066 | if (this.isWithinToleranceOfBoundary(pt)) { return Location.BOUNDARY }
|
41067 | return this._ptLocator.locate(pt, this._g)
|
41068 | };
|
41069 | FuzzyPointLocator.prototype.extractLinework = function extractLinework (g) {
|
41070 | var extracter = new PolygonalLineworkExtracter();
|
41071 | g.apply(extracter);
|
41072 | var linework = extracter.getLinework();
|
41073 | var lines = GeometryFactory.toLineStringArray(linework);
|
41074 | return g.getFactory().createMultiLineString(lines)
|
41075 | };
|
41076 | FuzzyPointLocator.prototype.interfaces_ = function interfaces_ () {
|
41077 | return []
|
41078 | };
|
41079 | FuzzyPointLocator.prototype.getClass = function getClass () {
|
41080 | return FuzzyPointLocator
|
41081 | };
|
41082 |
|
41083 | var PolygonalLineworkExtracter = function PolygonalLineworkExtracter () {
|
41084 | this._linework = null;
|
41085 | this._linework = new ArrayList();
|
41086 | };
|
41087 | PolygonalLineworkExtracter.prototype.getLinework = function getLinework () {
|
41088 | return this._linework
|
41089 | };
|
41090 | PolygonalLineworkExtracter.prototype.filter = function filter (g) {
|
41091 | var this$1 = this;
|
41092 |
|
41093 | if (g instanceof Polygon) {
|
41094 | var poly = g;
|
41095 | this._linework.add(poly.getExteriorRing());
|
41096 | for (var i = 0; i < poly.getNumInteriorRing(); i++) {
|
41097 | this$1._linework.add(poly.getInteriorRingN(i));
|
41098 | }
|
41099 | }
|
41100 | };
|
41101 | PolygonalLineworkExtracter.prototype.interfaces_ = function interfaces_ () {
|
41102 | return [GeometryFilter]
|
41103 | };
|
41104 | PolygonalLineworkExtracter.prototype.getClass = function getClass () {
|
41105 | return PolygonalLineworkExtracter
|
41106 | };
|
41107 |
|
41108 | var OffsetPointGenerator = function OffsetPointGenerator () {
|
41109 | this._g = null;
|
41110 | this._doLeft = true;
|
41111 | this._doRight = true;
|
41112 | var g = arguments[0];
|
41113 | this._g = g;
|
41114 | };
|
41115 | OffsetPointGenerator.prototype.extractPoints = function extractPoints (line, offsetDistance, offsetPts) {
|
41116 | var this$1 = this;
|
41117 |
|
41118 | var pts = line.getCoordinates();
|
41119 | for (var i = 0; i < pts.length - 1; i++) {
|
41120 | this$1.computeOffsetPoints(pts[i], pts[i + 1], offsetDistance, offsetPts);
|
41121 | }
|
41122 | };
|
41123 | OffsetPointGenerator.prototype.setSidesToGenerate = function setSidesToGenerate (doLeft, doRight) {
|
41124 | this._doLeft = doLeft;
|
41125 | this._doRight = doRight;
|
41126 | };
|
41127 | OffsetPointGenerator.prototype.getPoints = function getPoints (offsetDistance) {
|
41128 | var this$1 = this;
|
41129 |
|
41130 | var offsetPts = new ArrayList();
|
41131 | var lines = LinearComponentExtracter.getLines(this._g);
|
41132 | for (var i = lines.iterator(); i.hasNext();) {
|
41133 | var line = i.next();
|
41134 | this$1.extractPoints(line, offsetDistance, offsetPts);
|
41135 | }
|
41136 | return offsetPts
|
41137 | };
|
41138 | OffsetPointGenerator.prototype.computeOffsetPoints = function computeOffsetPoints (p0, p1, offsetDistance, offsetPts) {
|
41139 | var dx = p1.x - p0.x;
|
41140 | var dy = p1.y - p0.y;
|
41141 | var len = Math.sqrt(dx * dx + dy * dy);
|
41142 | var ux = offsetDistance * dx / len;
|
41143 | var uy = offsetDistance * dy / len;
|
41144 | var midX = (p1.x + p0.x) / 2;
|
41145 | var midY = (p1.y + p0.y) / 2;
|
41146 | if (this._doLeft) {
|
41147 | var offsetLeft = new Coordinate(midX - uy, midY + ux);
|
41148 | offsetPts.add(offsetLeft);
|
41149 | }
|
41150 | if (this._doRight) {
|
41151 | var offsetRight = new Coordinate(midX + uy, midY - ux);
|
41152 | offsetPts.add(offsetRight);
|
41153 | }
|
41154 | };
|
41155 | OffsetPointGenerator.prototype.interfaces_ = function interfaces_ () {
|
41156 | return []
|
41157 | };
|
41158 | OffsetPointGenerator.prototype.getClass = function getClass () {
|
41159 | return OffsetPointGenerator
|
41160 | };
|
41161 |
|
41162 | var OverlayResultValidator = function OverlayResultValidator () {
|
41163 | this._geom = null;
|
41164 | this._locFinder = null;
|
41165 | this._location = new Array(3).fill(null);
|
41166 | this._invalidLocation = null;
|
41167 | this._boundaryDistanceTolerance = OverlayResultValidator.TOLERANCE;
|
41168 | this._testCoords = new ArrayList();
|
41169 | var a = arguments[0];
|
41170 | var b = arguments[1];
|
41171 | var result = arguments[2];
|
41172 | this._boundaryDistanceTolerance = OverlayResultValidator.computeBoundaryDistanceTolerance(a, b);
|
41173 | this._geom = [a, b, result];
|
41174 | this._locFinder = [new FuzzyPointLocator(this._geom[0], this._boundaryDistanceTolerance), new FuzzyPointLocator(this._geom[1], this._boundaryDistanceTolerance), new FuzzyPointLocator(this._geom[2], this._boundaryDistanceTolerance)];
|
41175 | };
|
41176 |
|
41177 | var staticAccessors$46 = { TOLERANCE: { configurable: true } };
|
41178 | OverlayResultValidator.prototype.reportResult = function reportResult (overlayOp, location, expectedInterior) {
|
41179 | System.out.println('Overlay result invalid - A:' + Location.toLocationSymbol(location[0]) + ' B:' + Location.toLocationSymbol(location[1]) + ' expected:' + (expectedInterior ? 'i' : 'e') + ' actual:' + Location.toLocationSymbol(location[2]));
|
41180 | };
|
41181 | OverlayResultValidator.prototype.isValid = function isValid (overlayOp) {
|
41182 | this.addTestPts(this._geom[0]);
|
41183 | this.addTestPts(this._geom[1]);
|
41184 | var isValid = this.checkValid(overlayOp);
|
41185 | return isValid
|
41186 | };
|
41187 | OverlayResultValidator.prototype.checkValid = function checkValid () {
|
41188 | var this$1 = this;
|
41189 |
|
41190 | if (arguments.length === 1) {
|
41191 | var overlayOp = arguments[0];
|
41192 | for (var i = 0; i < this._testCoords.size(); i++) {
|
41193 | var pt = this$1._testCoords.get(i);
|
41194 | if (!this$1.checkValid(overlayOp, pt)) {
|
41195 | this$1._invalidLocation = pt;
|
41196 | return false
|
41197 | }
|
41198 | }
|
41199 | return true
|
41200 | } else if (arguments.length === 2) {
|
41201 | var overlayOp$1 = arguments[0];
|
41202 | var pt$1 = arguments[1];
|
41203 | this._location[0] = this._locFinder[0].getLocation(pt$1);
|
41204 | this._location[1] = this._locFinder[1].getLocation(pt$1);
|
41205 | this._location[2] = this._locFinder[2].getLocation(pt$1);
|
41206 | if (OverlayResultValidator.hasLocation(this._location, Location.BOUNDARY)) { return true }
|
41207 | return this.isValidResult(overlayOp$1, this._location)
|
41208 | }
|
41209 | };
|
41210 | OverlayResultValidator.prototype.addTestPts = function addTestPts (g) {
|
41211 | var ptGen = new OffsetPointGenerator(g);
|
41212 | this._testCoords.addAll(ptGen.getPoints(5 * this._boundaryDistanceTolerance));
|
41213 | };
|
41214 | OverlayResultValidator.prototype.isValidResult = function isValidResult (overlayOp, location) {
|
41215 | var expectedInterior = OverlayOp.isResultOfOp(location[0], location[1], overlayOp);
|
41216 | var resultInInterior = location[2] === Location.INTERIOR;
|
41217 | var isValid = !(expectedInterior ^ resultInInterior);
|
41218 | if (!isValid) { this.reportResult(overlayOp, location, expectedInterior); }
|
41219 | return isValid
|
41220 | };
|
41221 | OverlayResultValidator.prototype.getInvalidLocation = function getInvalidLocation () {
|
41222 | return this._invalidLocation
|
41223 | };
|
41224 | OverlayResultValidator.prototype.interfaces_ = function interfaces_ () {
|
41225 | return []
|
41226 | };
|
41227 | OverlayResultValidator.prototype.getClass = function getClass () {
|
41228 | return OverlayResultValidator
|
41229 | };
|
41230 | OverlayResultValidator.hasLocation = function hasLocation (location, loc) {
|
41231 | for (var i = 0; i < 3; i++) {
|
41232 | if (location[i] === loc) { return true }
|
41233 | }
|
41234 | return false
|
41235 | };
|
41236 | OverlayResultValidator.computeBoundaryDistanceTolerance = function computeBoundaryDistanceTolerance (g0, g1) {
|
41237 | return Math.min(GeometrySnapper.computeSizeBasedSnapTolerance(g0), GeometrySnapper.computeSizeBasedSnapTolerance(g1))
|
41238 | };
|
41239 | OverlayResultValidator.isValid = function isValid (a, b, overlayOp, result) {
|
41240 | var validator = new OverlayResultValidator(a, b, result);
|
41241 | return validator.isValid(overlayOp)
|
41242 | };
|
41243 | staticAccessors$46.TOLERANCE.get = function () { return 0.000001 };
|
41244 |
|
41245 | Object.defineProperties( OverlayResultValidator, staticAccessors$46 );
|
41246 |
|
41247 |
|
41248 |
|
41249 | var GeometryCombiner = function GeometryCombiner (geoms) {
|
41250 | this._geomFactory = null;
|
41251 | this._skipEmpty = false;
|
41252 | this._inputGeoms = null;
|
41253 | this._geomFactory = GeometryCombiner.extractFactory(geoms);
|
41254 | this._inputGeoms = geoms;
|
41255 | };
|
41256 | GeometryCombiner.prototype.extractElements = function extractElements (geom, elems) {
|
41257 | var this$1 = this;
|
41258 |
|
41259 | if (geom === null) { return null }
|
41260 | for (var i = 0; i < geom.getNumGeometries(); i++) {
|
41261 | var elemGeom = geom.getGeometryN(i);
|
41262 | if (this$1._skipEmpty && elemGeom.isEmpty()) { continue }
|
41263 | elems.add(elemGeom);
|
41264 | }
|
41265 | };
|
41266 | GeometryCombiner.prototype.combine = function combine () {
|
41267 | var this$1 = this;
|
41268 |
|
41269 | var elems = new ArrayList();
|
41270 | for (var i = this._inputGeoms.iterator(); i.hasNext();) {
|
41271 | var g = i.next();
|
41272 | this$1.extractElements(g, elems);
|
41273 | }
|
41274 | if (elems.size() === 0) {
|
41275 | if (this._geomFactory !== null) {
|
41276 | return this._geomFactory.createGeometryCollection(null)
|
41277 | }
|
41278 | return null
|
41279 | }
|
41280 | return this._geomFactory.buildGeometry(elems)
|
41281 | };
|
41282 | GeometryCombiner.prototype.interfaces_ = function interfaces_ () {
|
41283 | return []
|
41284 | };
|
41285 | GeometryCombiner.prototype.getClass = function getClass () {
|
41286 | return GeometryCombiner
|
41287 | };
|
41288 | GeometryCombiner.combine = function combine () {
|
41289 | if (arguments.length === 1) {
|
41290 | var geoms = arguments[0];
|
41291 | var combiner = new GeometryCombiner(geoms);
|
41292 | return combiner.combine()
|
41293 | } else if (arguments.length === 2) {
|
41294 | var g0 = arguments[0];
|
41295 | var g1 = arguments[1];
|
41296 | var combiner$1 = new GeometryCombiner(GeometryCombiner.createList(g0, g1));
|
41297 | return combiner$1.combine()
|
41298 | } else if (arguments.length === 3) {
|
41299 | var g0$1 = arguments[0];
|
41300 | var g1$1 = arguments[1];
|
41301 | var g2 = arguments[2];
|
41302 | var combiner$2 = new GeometryCombiner(GeometryCombiner.createList(g0$1, g1$1, g2));
|
41303 | return combiner$2.combine()
|
41304 | }
|
41305 | };
|
41306 | GeometryCombiner.extractFactory = function extractFactory (geoms) {
|
41307 | if (geoms.isEmpty()) { return null }
|
41308 | return geoms.iterator().next().getFactory()
|
41309 | };
|
41310 | GeometryCombiner.createList = function createList () {
|
41311 | if (arguments.length === 2) {
|
41312 | var obj0 = arguments[0];
|
41313 | var obj1 = arguments[1];
|
41314 | var list = new ArrayList();
|
41315 | list.add(obj0);
|
41316 | list.add(obj1);
|
41317 | return list
|
41318 | } else if (arguments.length === 3) {
|
41319 | var obj0$1 = arguments[0];
|
41320 | var obj1$1 = arguments[1];
|
41321 | var obj2 = arguments[2];
|
41322 | var list$1 = new ArrayList();
|
41323 | list$1.add(obj0$1);
|
41324 | list$1.add(obj1$1);
|
41325 | list$1.add(obj2);
|
41326 | return list$1
|
41327 | }
|
41328 | };
|
41329 |
|
41330 | var CascadedPolygonUnion = function CascadedPolygonUnion () {
|
41331 | this._inputPolys = null;
|
41332 | this._geomFactory = null;
|
41333 | var polys = arguments[0];
|
41334 | this._inputPolys = polys;
|
41335 | if (this._inputPolys === null) { this._inputPolys = new ArrayList(); }
|
41336 | };
|
41337 |
|
41338 | var staticAccessors$47 = { STRTREE_NODE_CAPACITY: { configurable: true } };
|
41339 | CascadedPolygonUnion.prototype.reduceToGeometries = function reduceToGeometries (geomTree) {
|
41340 | var this$1 = this;
|
41341 |
|
41342 | var geoms = new ArrayList();
|
41343 | for (var i = geomTree.iterator(); i.hasNext();) {
|
41344 | var o = i.next();
|
41345 | var geom = null;
|
41346 | if (hasInterface(o, List)) {
|
41347 | geom = this$1.unionTree(o);
|
41348 | } else if (o instanceof Geometry) {
|
41349 | geom = o;
|
41350 | }
|
41351 | geoms.add(geom);
|
41352 | }
|
41353 | return geoms
|
41354 | };
|
41355 | CascadedPolygonUnion.prototype.extractByEnvelope = function extractByEnvelope (env, geom, disjointGeoms) {
|
41356 | var intersectingGeoms = new ArrayList();
|
41357 | for (var i = 0; i < geom.getNumGeometries(); i++) {
|
41358 | var elem = geom.getGeometryN(i);
|
41359 | if (elem.getEnvelopeInternal().intersects(env)) { intersectingGeoms.add(elem); } else { disjointGeoms.add(elem); }
|
41360 | }
|
41361 | return this._geomFactory.buildGeometry(intersectingGeoms)
|
41362 | };
|
41363 | CascadedPolygonUnion.prototype.unionOptimized = function unionOptimized (g0, g1) {
|
41364 | var g0Env = g0.getEnvelopeInternal();
|
41365 | var g1Env = g1.getEnvelopeInternal();
|
41366 | if (!g0Env.intersects(g1Env)) {
|
41367 | var combo = GeometryCombiner.combine(g0, g1);
|
41368 | return combo
|
41369 | }
|
41370 | if (g0.getNumGeometries() <= 1 && g1.getNumGeometries() <= 1) { return this.unionActual(g0, g1) }
|
41371 | var commonEnv = g0Env.intersection(g1Env);
|
41372 | return this.unionUsingEnvelopeIntersection(g0, g1, commonEnv)
|
41373 | };
|
41374 | CascadedPolygonUnion.prototype.union = function union () {
|
41375 | if (this._inputPolys === null) { throw new Error('union() method cannot be called twice') }
|
41376 | if (this._inputPolys.isEmpty()) { return null }
|
41377 | this._geomFactory = this._inputPolys.iterator().next().getFactory();
|
41378 | var index = new STRtree(CascadedPolygonUnion.STRTREE_NODE_CAPACITY);
|
41379 | for (var i = this._inputPolys.iterator(); i.hasNext();) {
|
41380 | var item = i.next();
|
41381 | index.insert(item.getEnvelopeInternal(), item);
|
41382 | }
|
41383 | this._inputPolys = null;
|
41384 | var itemTree = index.itemsTree();
|
41385 | var unionAll = this.unionTree(itemTree);
|
41386 | return unionAll
|
41387 | };
|
41388 | CascadedPolygonUnion.prototype.binaryUnion = function binaryUnion () {
|
41389 | if (arguments.length === 1) {
|
41390 | var geoms = arguments[0];
|
41391 | return this.binaryUnion(geoms, 0, geoms.size())
|
41392 | } else if (arguments.length === 3) {
|
41393 | var geoms$1 = arguments[0];
|
41394 | var start = arguments[1];
|
41395 | var end = arguments[2];
|
41396 | if (end - start <= 1) {
|
41397 | var g0 = CascadedPolygonUnion.getGeometry(geoms$1, start);
|
41398 | return this.unionSafe(g0, null)
|
41399 | } else if (end - start === 2) {
|
41400 | return this.unionSafe(CascadedPolygonUnion.getGeometry(geoms$1, start), CascadedPolygonUnion.getGeometry(geoms$1, start + 1))
|
41401 | } else {
|
41402 | var mid = Math.trunc((end + start) / 2);
|
41403 | var g0$1 = this.binaryUnion(geoms$1, start, mid);
|
41404 | var g1 = this.binaryUnion(geoms$1, mid, end);
|
41405 | return this.unionSafe(g0$1, g1)
|
41406 | }
|
41407 | }
|
41408 | };
|
41409 | CascadedPolygonUnion.prototype.repeatedUnion = function repeatedUnion (geoms) {
|
41410 | var union = null;
|
41411 | for (var i = geoms.iterator(); i.hasNext();) {
|
41412 | var g = i.next();
|
41413 | if (union === null) { union = g.copy(); } else { union = union.union(g); }
|
41414 | }
|
41415 | return union
|
41416 | };
|
41417 | CascadedPolygonUnion.prototype.unionSafe = function unionSafe (g0, g1) {
|
41418 | if (g0 === null && g1 === null) { return null }
|
41419 | if (g0 === null) { return g1.copy() }
|
41420 | if (g1 === null) { return g0.copy() }
|
41421 | return this.unionOptimized(g0, g1)
|
41422 | };
|
41423 | CascadedPolygonUnion.prototype.unionActual = function unionActual (g0, g1) {
|
41424 | return CascadedPolygonUnion.restrictToPolygons(g0.union(g1))
|
41425 | };
|
41426 | CascadedPolygonUnion.prototype.unionTree = function unionTree (geomTree) {
|
41427 | var geoms = this.reduceToGeometries(geomTree);
|
41428 | var union = this.binaryUnion(geoms);
|
41429 | return union
|
41430 | };
|
41431 | CascadedPolygonUnion.prototype.unionUsingEnvelopeIntersection = function unionUsingEnvelopeIntersection (g0, g1, common) {
|
41432 | var disjointPolys = new ArrayList();
|
41433 | var g0Int = this.extractByEnvelope(common, g0, disjointPolys);
|
41434 | var g1Int = this.extractByEnvelope(common, g1, disjointPolys);
|
41435 | var union = this.unionActual(g0Int, g1Int);
|
41436 | disjointPolys.add(union);
|
41437 | var overallUnion = GeometryCombiner.combine(disjointPolys);
|
41438 | return overallUnion
|
41439 | };
|
41440 | CascadedPolygonUnion.prototype.bufferUnion = function bufferUnion () {
|
41441 | if (arguments.length === 1) {
|
41442 | var geoms = arguments[0];
|
41443 | var factory = geoms.get(0).getFactory();
|
41444 | var gColl = factory.buildGeometry(geoms);
|
41445 | var unionAll = gColl.buffer(0.0);
|
41446 | return unionAll
|
41447 | } else if (arguments.length === 2) {
|
41448 | var g0 = arguments[0];
|
41449 | var g1 = arguments[1];
|
41450 | var factory$1 = g0.getFactory();
|
41451 | var gColl$1 = factory$1.createGeometryCollection([g0, g1]);
|
41452 | var unionAll$1 = gColl$1.buffer(0.0);
|
41453 | return unionAll$1
|
41454 | }
|
41455 | };
|
41456 | CascadedPolygonUnion.prototype.interfaces_ = function interfaces_ () {
|
41457 | return []
|
41458 | };
|
41459 | CascadedPolygonUnion.prototype.getClass = function getClass () {
|
41460 | return CascadedPolygonUnion
|
41461 | };
|
41462 | CascadedPolygonUnion.restrictToPolygons = function restrictToPolygons (g) {
|
41463 | if (hasInterface(g, Polygonal)) {
|
41464 | return g
|
41465 | }
|
41466 | var polygons = PolygonExtracter.getPolygons(g);
|
41467 | if (polygons.size() === 1) { return polygons.get(0) }
|
41468 | return g.getFactory().createMultiPolygon(GeometryFactory.toPolygonArray(polygons))
|
41469 | };
|
41470 | CascadedPolygonUnion.getGeometry = function getGeometry (list, index) {
|
41471 | if (index >= list.size()) { return null }
|
41472 | return list.get(index)
|
41473 | };
|
41474 | CascadedPolygonUnion.union = function union (polys) {
|
41475 | var op = new CascadedPolygonUnion(polys);
|
41476 | return op.union()
|
41477 | };
|
41478 | staticAccessors$47.STRTREE_NODE_CAPACITY.get = function () { return 4 };
|
41479 |
|
41480 | Object.defineProperties( CascadedPolygonUnion, staticAccessors$47 );
|
41481 |
|
41482 | var UnionOp = function UnionOp () {};
|
41483 |
|
41484 | UnionOp.prototype.interfaces_ = function interfaces_ () {
|
41485 | return []
|
41486 | };
|
41487 | UnionOp.prototype.getClass = function getClass () {
|
41488 | return UnionOp
|
41489 | };
|
41490 | UnionOp.union = function union (g, other) {
|
41491 | if (g.isEmpty() || other.isEmpty()) {
|
41492 | if (g.isEmpty() && other.isEmpty()) { return OverlayOp.createEmptyResult(OverlayOp.UNION, g, other, g.getFactory()) }
|
41493 | if (g.isEmpty()) { return other.copy() }
|
41494 | if (other.isEmpty()) { return g.copy() }
|
41495 | }
|
41496 | g.checkNotGeometryCollection(g);
|
41497 | g.checkNotGeometryCollection(other);
|
41498 | return SnapIfNeededOverlayOp.overlayOp(g, other, OverlayOp.UNION)
|
41499 | };
|
41500 |
|
41501 |
|
41502 |
|
41503 |
|
41504 |
|
41505 |
|
41506 |
|
41507 |
|
41508 |
|
41509 |
|
41510 |
|
41511 |
|
41512 |
|
41513 |
|
41514 |
|
41515 |
|
41516 |
|
41517 |
|
41518 |
|
41519 |
|
41520 |
|
41521 |
|
41522 |
|
41523 |
|
41524 |
|
41525 |
|
41526 |
|
41527 |
|
41528 |
|
41529 |
|
41530 |
|
41531 |
|
41532 |
|
41533 |
|
41534 |
|
41535 | function difference(polygon1, polygon2) {
|
41536 | var geom1 = getGeom(polygon1);
|
41537 | var geom2 = getGeom(polygon2);
|
41538 | var properties = polygon1.properties || {};
|
41539 |
|
41540 |
|
41541 | geom1 = removeEmptyPolygon(geom1);
|
41542 | geom2 = removeEmptyPolygon(geom2);
|
41543 | if (!geom1) return null;
|
41544 | if (!geom2) return feature(geom1, properties);
|
41545 |
|
41546 |
|
41547 | var reader = new GeoJSONReader();
|
41548 | var a = reader.read(geom1);
|
41549 | var b = reader.read(geom2);
|
41550 | var differenced = OverlayOp.difference(a, b);
|
41551 | if (differenced.isEmpty()) return null;
|
41552 | var writer = new GeoJSONWriter();
|
41553 | var geom = writer.write(differenced);
|
41554 |
|
41555 | return feature(geom, properties);
|
41556 | }
|
41557 |
|
41558 |
|
41559 |
|
41560 |
|
41561 |
|
41562 |
|
41563 |
|
41564 |
|
41565 | function removeEmptyPolygon(geom) {
|
41566 | switch (geom.type) {
|
41567 | case 'Polygon':
|
41568 | if (area$1(geom) > 1) return geom;
|
41569 | return null;
|
41570 | case 'MultiPolygon':
|
41571 | var coordinates = [];
|
41572 | flattenEach(geom, function (feature$$1) {
|
41573 | if (area$1(feature$$1) > 1) coordinates.push(feature$$1.geometry.coordinates);
|
41574 | });
|
41575 | if (coordinates.length) return {type: 'MultiPolygon', coordinates: coordinates};
|
41576 | }
|
41577 | }
|
41578 |
|
41579 |
|
41580 |
|
41581 |
|
41582 |
|
41583 |
|
41584 |
|
41585 |
|
41586 | var adder = function() {
|
41587 | return new Adder;
|
41588 | };
|
41589 |
|
41590 | function Adder() {
|
41591 | this.reset();
|
41592 | }
|
41593 |
|
41594 | Adder.prototype = {
|
41595 | constructor: Adder,
|
41596 | reset: function() {
|
41597 | this.s =
|
41598 | this.t = 0;
|
41599 | },
|
41600 | add: function(y) {
|
41601 | add$1(temp, y, this.t);
|
41602 | add$1(this, temp.s, this.s);
|
41603 | if (this.s) this.t += temp.t;
|
41604 | else this.s = temp.t;
|
41605 | },
|
41606 | valueOf: function() {
|
41607 | return this.s;
|
41608 | }
|
41609 | };
|
41610 |
|
41611 | var temp = new Adder;
|
41612 |
|
41613 | function add$1(adder, a, b) {
|
41614 | var x = adder.s = a + b,
|
41615 | bv = x - a,
|
41616 | av = x - bv;
|
41617 | adder.t = (a - av) + (b - bv);
|
41618 | }
|
41619 |
|
41620 | var epsilon$1 = 1e-6;
|
41621 |
|
41622 | var pi = Math.PI;
|
41623 | var halfPi = pi / 2;
|
41624 | var quarterPi = pi / 4;
|
41625 | var tau = pi * 2;
|
41626 |
|
41627 | var degrees = 180 / pi;
|
41628 | var radians = pi / 180;
|
41629 |
|
41630 | var abs = Math.abs;
|
41631 | var atan = Math.atan;
|
41632 | var atan2 = Math.atan2;
|
41633 | var cos = Math.cos;
|
41634 |
|
41635 | var exp = Math.exp;
|
41636 |
|
41637 | var log = Math.log;
|
41638 |
|
41639 | var sin = Math.sin;
|
41640 |
|
41641 | var sqrt = Math.sqrt;
|
41642 | var tan = Math.tan;
|
41643 |
|
41644 | function acos(x) {
|
41645 | return x > 1 ? 0 : x < -1 ? pi : Math.acos(x);
|
41646 | }
|
41647 |
|
41648 | function asin(x) {
|
41649 | return x > 1 ? halfPi : x < -1 ? -halfPi : Math.asin(x);
|
41650 | }
|
41651 |
|
41652 | function noop() {}
|
41653 |
|
41654 | function streamGeometry(geometry, stream) {
|
41655 | if (geometry && streamGeometryType.hasOwnProperty(geometry.type)) {
|
41656 | streamGeometryType[geometry.type](geometry, stream);
|
41657 | }
|
41658 | }
|
41659 |
|
41660 | var streamObjectType = {
|
41661 | Feature: function(object, stream) {
|
41662 | streamGeometry(object.geometry, stream);
|
41663 | },
|
41664 | FeatureCollection: function(object, stream) {
|
41665 | var features = object.features, i = -1, n = features.length;
|
41666 | while (++i < n) streamGeometry(features[i].geometry, stream);
|
41667 | }
|
41668 | };
|
41669 |
|
41670 | var streamGeometryType = {
|
41671 | Sphere: function(object, stream) {
|
41672 | stream.sphere();
|
41673 | },
|
41674 | Point: function(object, stream) {
|
41675 | object = object.coordinates;
|
41676 | stream.point(object[0], object[1], object[2]);
|
41677 | },
|
41678 | MultiPoint: function(object, stream) {
|
41679 | var coordinates = object.coordinates, i = -1, n = coordinates.length;
|
41680 | while (++i < n) object = coordinates[i], stream.point(object[0], object[1], object[2]);
|
41681 | },
|
41682 | LineString: function(object, stream) {
|
41683 | streamLine(object.coordinates, stream, 0);
|
41684 | },
|
41685 | MultiLineString: function(object, stream) {
|
41686 | var coordinates = object.coordinates, i = -1, n = coordinates.length;
|
41687 | while (++i < n) streamLine(coordinates[i], stream, 0);
|
41688 | },
|
41689 | Polygon: function(object, stream) {
|
41690 | streamPolygon(object.coordinates, stream);
|
41691 | },
|
41692 | MultiPolygon: function(object, stream) {
|
41693 | var coordinates = object.coordinates, i = -1, n = coordinates.length;
|
41694 | while (++i < n) streamPolygon(coordinates[i], stream);
|
41695 | },
|
41696 | GeometryCollection: function(object, stream) {
|
41697 | var geometries = object.geometries, i = -1, n = geometries.length;
|
41698 | while (++i < n) streamGeometry(geometries[i], stream);
|
41699 | }
|
41700 | };
|
41701 |
|
41702 | function streamLine(coordinates, stream, closed) {
|
41703 | var i = -1, n = coordinates.length - closed, coordinate;
|
41704 | stream.lineStart();
|
41705 | while (++i < n) coordinate = coordinates[i], stream.point(coordinate[0], coordinate[1], coordinate[2]);
|
41706 | stream.lineEnd();
|
41707 | }
|
41708 |
|
41709 | function streamPolygon(coordinates, stream) {
|
41710 | var i = -1, n = coordinates.length;
|
41711 | stream.polygonStart();
|
41712 | while (++i < n) streamLine(coordinates[i], stream, 1);
|
41713 | stream.polygonEnd();
|
41714 | }
|
41715 |
|
41716 | var geoStream = function(object, stream) {
|
41717 | if (object && streamObjectType.hasOwnProperty(object.type)) {
|
41718 | streamObjectType[object.type](object, stream);
|
41719 | } else {
|
41720 | streamGeometry(object, stream);
|
41721 | }
|
41722 | };
|
41723 |
|
41724 | var areaRingSum = adder();
|
41725 |
|
41726 | var areaSum = adder();
|
41727 |
|
41728 | function spherical(cartesian) {
|
41729 | return [atan2(cartesian[1], cartesian[0]), asin(cartesian[2])];
|
41730 | }
|
41731 |
|
41732 | function cartesian(spherical) {
|
41733 | var lambda = spherical[0], phi = spherical[1], cosPhi = cos(phi);
|
41734 | return [cosPhi * cos(lambda), cosPhi * sin(lambda), sin(phi)];
|
41735 | }
|
41736 |
|
41737 | function cartesianDot(a, b) {
|
41738 | return a[0] * b[0] + a[1] * b[1] + a[2] * b[2];
|
41739 | }
|
41740 |
|
41741 | function cartesianCross(a, b) {
|
41742 | return [a[1] * b[2] - a[2] * b[1], a[2] * b[0] - a[0] * b[2], a[0] * b[1] - a[1] * b[0]];
|
41743 | }
|
41744 |
|
41745 |
|
41746 | function cartesianAddInPlace(a, b) {
|
41747 | a[0] += b[0], a[1] += b[1], a[2] += b[2];
|
41748 | }
|
41749 |
|
41750 | function cartesianScale(vector, k) {
|
41751 | return [vector[0] * k, vector[1] * k, vector[2] * k];
|
41752 | }
|
41753 |
|
41754 |
|
41755 | function cartesianNormalizeInPlace(d) {
|
41756 | var l = sqrt(d[0] * d[0] + d[1] * d[1] + d[2] * d[2]);
|
41757 | d[0] /= l, d[1] /= l, d[2] /= l;
|
41758 | }
|
41759 |
|
41760 | var deltaSum = adder();
|
41761 |
|
41762 | var compose = function(a, b) {
|
41763 |
|
41764 | function compose(x, y) {
|
41765 | return x = a(x, y), b(x[0], x[1]);
|
41766 | }
|
41767 |
|
41768 | if (a.invert && b.invert) compose.invert = function(x, y) {
|
41769 | return x = b.invert(x, y), x && a.invert(x[0], x[1]);
|
41770 | };
|
41771 |
|
41772 | return compose;
|
41773 | };
|
41774 |
|
41775 | function rotationIdentity(lambda, phi) {
|
41776 | return [lambda > pi ? lambda - tau : lambda < -pi ? lambda + tau : lambda, phi];
|
41777 | }
|
41778 |
|
41779 | rotationIdentity.invert = rotationIdentity;
|
41780 |
|
41781 | function rotateRadians(deltaLambda, deltaPhi, deltaGamma) {
|
41782 | return (deltaLambda %= tau) ? (deltaPhi || deltaGamma ? compose(rotationLambda(deltaLambda), rotationPhiGamma(deltaPhi, deltaGamma))
|
41783 | : rotationLambda(deltaLambda))
|
41784 | : (deltaPhi || deltaGamma ? rotationPhiGamma(deltaPhi, deltaGamma)
|
41785 | : rotationIdentity);
|
41786 | }
|
41787 |
|
41788 | function forwardRotationLambda(deltaLambda) {
|
41789 | return function(lambda, phi) {
|
41790 | return lambda += deltaLambda, [lambda > pi ? lambda - tau : lambda < -pi ? lambda + tau : lambda, phi];
|
41791 | };
|
41792 | }
|
41793 |
|
41794 | function rotationLambda(deltaLambda) {
|
41795 | var rotation = forwardRotationLambda(deltaLambda);
|
41796 | rotation.invert = forwardRotationLambda(-deltaLambda);
|
41797 | return rotation;
|
41798 | }
|
41799 |
|
41800 | function rotationPhiGamma(deltaPhi, deltaGamma) {
|
41801 | var cosDeltaPhi = cos(deltaPhi),
|
41802 | sinDeltaPhi = sin(deltaPhi),
|
41803 | cosDeltaGamma = cos(deltaGamma),
|
41804 | sinDeltaGamma = sin(deltaGamma);
|
41805 |
|
41806 | function rotation(lambda, phi) {
|
41807 | var cosPhi = cos(phi),
|
41808 | x = cos(lambda) * cosPhi,
|
41809 | y = sin(lambda) * cosPhi,
|
41810 | z = sin(phi),
|
41811 | k = z * cosDeltaPhi + x * sinDeltaPhi;
|
41812 | return [
|
41813 | atan2(y * cosDeltaGamma - k * sinDeltaGamma, x * cosDeltaPhi - z * sinDeltaPhi),
|
41814 | asin(k * cosDeltaGamma + y * sinDeltaGamma)
|
41815 | ];
|
41816 | }
|
41817 |
|
41818 | rotation.invert = function(lambda, phi) {
|
41819 | var cosPhi = cos(phi),
|
41820 | x = cos(lambda) * cosPhi,
|
41821 | y = sin(lambda) * cosPhi,
|
41822 | z = sin(phi),
|
41823 | k = z * cosDeltaGamma - y * sinDeltaGamma;
|
41824 | return [
|
41825 | atan2(y * cosDeltaGamma + z * sinDeltaGamma, x * cosDeltaPhi + k * sinDeltaPhi),
|
41826 | asin(k * cosDeltaPhi - x * sinDeltaPhi)
|
41827 | ];
|
41828 | };
|
41829 |
|
41830 | return rotation;
|
41831 | }
|
41832 |
|
41833 | var rotation = function(rotate) {
|
41834 | rotate = rotateRadians(rotate[0] * radians, rotate[1] * radians, rotate.length > 2 ? rotate[2] * radians : 0);
|
41835 |
|
41836 | function forward(coordinates) {
|
41837 | coordinates = rotate(coordinates[0] * radians, coordinates[1] * radians);
|
41838 | return coordinates[0] *= degrees, coordinates[1] *= degrees, coordinates;
|
41839 | }
|
41840 |
|
41841 | forward.invert = function(coordinates) {
|
41842 | coordinates = rotate.invert(coordinates[0] * radians, coordinates[1] * radians);
|
41843 | return coordinates[0] *= degrees, coordinates[1] *= degrees, coordinates;
|
41844 | };
|
41845 |
|
41846 | return forward;
|
41847 | };
|
41848 |
|
41849 |
|
41850 | function circleStream(stream, radius, delta, direction, t0, t1) {
|
41851 | if (!delta) return;
|
41852 | var cosRadius = cos(radius),
|
41853 | sinRadius = sin(radius),
|
41854 | step = direction * delta;
|
41855 | if (t0 == null) {
|
41856 | t0 = radius + direction * tau;
|
41857 | t1 = radius - step / 2;
|
41858 | } else {
|
41859 | t0 = circleRadius(cosRadius, t0);
|
41860 | t1 = circleRadius(cosRadius, t1);
|
41861 | if (direction > 0 ? t0 < t1 : t0 > t1) t0 += direction * tau;
|
41862 | }
|
41863 | for (var point, t = t0; direction > 0 ? t > t1 : t < t1; t -= step) {
|
41864 | point = spherical([cosRadius, -sinRadius * cos(t), -sinRadius * sin(t)]);
|
41865 | stream.point(point[0], point[1]);
|
41866 | }
|
41867 | }
|
41868 |
|
41869 |
|
41870 | function circleRadius(cosRadius, point) {
|
41871 | point = cartesian(point), point[0] -= cosRadius;
|
41872 | cartesianNormalizeInPlace(point);
|
41873 | var radius = acos(-point[1]);
|
41874 | return ((-point[2] < 0 ? -radius : radius) + tau - epsilon$1) % tau;
|
41875 | }
|
41876 |
|
41877 | var clipBuffer = function() {
|
41878 | var lines = [],
|
41879 | line;
|
41880 | return {
|
41881 | point: function(x, y) {
|
41882 | line.push([x, y]);
|
41883 | },
|
41884 | lineStart: function() {
|
41885 | lines.push(line = []);
|
41886 | },
|
41887 | lineEnd: noop,
|
41888 | rejoin: function() {
|
41889 | if (lines.length > 1) lines.push(lines.pop().concat(lines.shift()));
|
41890 | },
|
41891 | result: function() {
|
41892 | var result = lines;
|
41893 | lines = [];
|
41894 | line = null;
|
41895 | return result;
|
41896 | }
|
41897 | };
|
41898 | };
|
41899 |
|
41900 | var clipLine = function(a, b, x0, y0, x1, y1) {
|
41901 | var ax = a[0],
|
41902 | ay = a[1],
|
41903 | bx = b[0],
|
41904 | by = b[1],
|
41905 | t0 = 0,
|
41906 | t1 = 1,
|
41907 | dx = bx - ax,
|
41908 | dy = by - ay,
|
41909 | r;
|
41910 |
|
41911 | r = x0 - ax;
|
41912 | if (!dx && r > 0) return;
|
41913 | r /= dx;
|
41914 | if (dx < 0) {
|
41915 | if (r < t0) return;
|
41916 | if (r < t1) t1 = r;
|
41917 | } else if (dx > 0) {
|
41918 | if (r > t1) return;
|
41919 | if (r > t0) t0 = r;
|
41920 | }
|
41921 |
|
41922 | r = x1 - ax;
|
41923 | if (!dx && r < 0) return;
|
41924 | r /= dx;
|
41925 | if (dx < 0) {
|
41926 | if (r > t1) return;
|
41927 | if (r > t0) t0 = r;
|
41928 | } else if (dx > 0) {
|
41929 | if (r < t0) return;
|
41930 | if (r < t1) t1 = r;
|
41931 | }
|
41932 |
|
41933 | r = y0 - ay;
|
41934 | if (!dy && r > 0) return;
|
41935 | r /= dy;
|
41936 | if (dy < 0) {
|
41937 | if (r < t0) return;
|
41938 | if (r < t1) t1 = r;
|
41939 | } else if (dy > 0) {
|
41940 | if (r > t1) return;
|
41941 | if (r > t0) t0 = r;
|
41942 | }
|
41943 |
|
41944 | r = y1 - ay;
|
41945 | if (!dy && r < 0) return;
|
41946 | r /= dy;
|
41947 | if (dy < 0) {
|
41948 | if (r > t1) return;
|
41949 | if (r > t0) t0 = r;
|
41950 | } else if (dy > 0) {
|
41951 | if (r < t0) return;
|
41952 | if (r < t1) t1 = r;
|
41953 | }
|
41954 |
|
41955 | if (t0 > 0) a[0] = ax + t0 * dx, a[1] = ay + t0 * dy;
|
41956 | if (t1 < 1) b[0] = ax + t1 * dx, b[1] = ay + t1 * dy;
|
41957 | return true;
|
41958 | };
|
41959 |
|
41960 | var pointEqual = function(a, b) {
|
41961 | return abs(a[0] - b[0]) < epsilon$1 && abs(a[1] - b[1]) < epsilon$1;
|
41962 | };
|
41963 |
|
41964 | function Intersection(point, points, other, entry) {
|
41965 | this.x = point;
|
41966 | this.z = points;
|
41967 | this.o = other;
|
41968 | this.e = entry;
|
41969 | this.v = false;
|
41970 | this.n = this.p = null;
|
41971 | }
|
41972 |
|
41973 |
|
41974 |
|
41975 |
|
41976 | var clipPolygon$1 = function(segments, compareIntersection, startInside, interpolate, stream) {
|
41977 | var subject = [],
|
41978 | clip = [],
|
41979 | i,
|
41980 | n;
|
41981 |
|
41982 | segments.forEach(function(segment) {
|
41983 | if ((n = segment.length - 1) <= 0) return;
|
41984 | var n, p0 = segment[0], p1 = segment[n], x;
|
41985 |
|
41986 |
|
41987 |
|
41988 |
|
41989 | if (pointEqual(p0, p1)) {
|
41990 | stream.lineStart();
|
41991 | for (i = 0; i < n; ++i) stream.point((p0 = segment[i])[0], p0[1]);
|
41992 | stream.lineEnd();
|
41993 | return;
|
41994 | }
|
41995 |
|
41996 | subject.push(x = new Intersection(p0, segment, null, true));
|
41997 | clip.push(x.o = new Intersection(p0, null, x, false));
|
41998 | subject.push(x = new Intersection(p1, segment, null, false));
|
41999 | clip.push(x.o = new Intersection(p1, null, x, true));
|
42000 | });
|
42001 |
|
42002 | if (!subject.length) return;
|
42003 |
|
42004 | clip.sort(compareIntersection);
|
42005 | link(subject);
|
42006 | link(clip);
|
42007 |
|
42008 | for (i = 0, n = clip.length; i < n; ++i) {
|
42009 | clip[i].e = startInside = !startInside;
|
42010 | }
|
42011 |
|
42012 | var start = subject[0],
|
42013 | points,
|
42014 | point;
|
42015 |
|
42016 | while (1) {
|
42017 |
|
42018 | var current = start,
|
42019 | isSubject = true;
|
42020 | while (current.v) if ((current = current.n) === start) return;
|
42021 | points = current.z;
|
42022 | stream.lineStart();
|
42023 | do {
|
42024 | current.v = current.o.v = true;
|
42025 | if (current.e) {
|
42026 | if (isSubject) {
|
42027 | for (i = 0, n = points.length; i < n; ++i) stream.point((point = points[i])[0], point[1]);
|
42028 | } else {
|
42029 | interpolate(current.x, current.n.x, 1, stream);
|
42030 | }
|
42031 | current = current.n;
|
42032 | } else {
|
42033 | if (isSubject) {
|
42034 | points = current.p.z;
|
42035 | for (i = points.length - 1; i >= 0; --i) stream.point((point = points[i])[0], point[1]);
|
42036 | } else {
|
42037 | interpolate(current.x, current.p.x, -1, stream);
|
42038 | }
|
42039 | current = current.p;
|
42040 | }
|
42041 | current = current.o;
|
42042 | points = current.z;
|
42043 | isSubject = !isSubject;
|
42044 | } while (!current.v);
|
42045 | stream.lineEnd();
|
42046 | }
|
42047 | };
|
42048 |
|
42049 | function link(array) {
|
42050 | if (!(n = array.length)) return;
|
42051 | var n,
|
42052 | i = 0,
|
42053 | a = array[0],
|
42054 | b;
|
42055 | while (++i < n) {
|
42056 | a.n = b = array[i];
|
42057 | b.p = a;
|
42058 | a = b;
|
42059 | }
|
42060 | a.n = b = array[0];
|
42061 | b.p = a;
|
42062 | }
|
42063 |
|
42064 | var ascending = function(a, b) {
|
42065 | return a < b ? -1 : a > b ? 1 : a >= b ? 0 : NaN;
|
42066 | };
|
42067 |
|
42068 | var bisector = function(compare) {
|
42069 | if (compare.length === 1) compare = ascendingComparator(compare);
|
42070 | return {
|
42071 | left: function(a, x, lo, hi) {
|
42072 | if (lo == null) lo = 0;
|
42073 | if (hi == null) hi = a.length;
|
42074 | while (lo < hi) {
|
42075 | var mid = lo + hi >>> 1;
|
42076 | if (compare(a[mid], x) < 0) lo = mid + 1;
|
42077 | else hi = mid;
|
42078 | }
|
42079 | return lo;
|
42080 | },
|
42081 | right: function(a, x, lo, hi) {
|
42082 | if (lo == null) lo = 0;
|
42083 | if (hi == null) hi = a.length;
|
42084 | while (lo < hi) {
|
42085 | var mid = lo + hi >>> 1;
|
42086 | if (compare(a[mid], x) > 0) hi = mid;
|
42087 | else lo = mid + 1;
|
42088 | }
|
42089 | return lo;
|
42090 | }
|
42091 | };
|
42092 | };
|
42093 |
|
42094 | function ascendingComparator(f) {
|
42095 | return function(d, x) {
|
42096 | return ascending(f(d), x);
|
42097 | };
|
42098 | }
|
42099 |
|
42100 | var ascendingBisect = bisector(ascending);
|
42101 |
|
42102 | var merge$1 = function(arrays) {
|
42103 | var n = arrays.length,
|
42104 | m,
|
42105 | i = -1,
|
42106 | j = 0,
|
42107 | merged,
|
42108 | array;
|
42109 |
|
42110 | while (++i < n) j += arrays[i].length;
|
42111 | merged = new Array(j);
|
42112 |
|
42113 | while (--n >= 0) {
|
42114 | array = arrays[n];
|
42115 | m = array.length;
|
42116 | while (--m >= 0) {
|
42117 | merged[--j] = array[m];
|
42118 | }
|
42119 | }
|
42120 |
|
42121 | return merged;
|
42122 | };
|
42123 |
|
42124 | var clipMax = 1e9;
|
42125 | var clipMin = -clipMax;
|
42126 |
|
42127 |
|
42128 |
|
42129 |
|
42130 | function clipExtent(x0, y0, x1, y1) {
|
42131 |
|
42132 | function visible(x, y) {
|
42133 | return x0 <= x && x <= x1 && y0 <= y && y <= y1;
|
42134 | }
|
42135 |
|
42136 | function interpolate(from, to, direction, stream) {
|
42137 | var a = 0, a1 = 0;
|
42138 | if (from == null
|
42139 | || (a = corner(from, direction)) !== (a1 = corner(to, direction))
|
42140 | || comparePoint(from, to) < 0 ^ direction > 0) {
|
42141 | do stream.point(a === 0 || a === 3 ? x0 : x1, a > 1 ? y1 : y0);
|
42142 | while ((a = (a + direction + 4) % 4) !== a1);
|
42143 | } else {
|
42144 | stream.point(to[0], to[1]);
|
42145 | }
|
42146 | }
|
42147 |
|
42148 | function corner(p, direction) {
|
42149 | return abs(p[0] - x0) < epsilon$1 ? direction > 0 ? 0 : 3
|
42150 | : abs(p[0] - x1) < epsilon$1 ? direction > 0 ? 2 : 1
|
42151 | : abs(p[1] - y0) < epsilon$1 ? direction > 0 ? 1 : 0
|
42152 | : direction > 0 ? 3 : 2;
|
42153 | }
|
42154 |
|
42155 | function compareIntersection(a, b) {
|
42156 | return comparePoint(a.x, b.x);
|
42157 | }
|
42158 |
|
42159 | function comparePoint(a, b) {
|
42160 | var ca = corner(a, 1),
|
42161 | cb = corner(b, 1);
|
42162 | return ca !== cb ? ca - cb
|
42163 | : ca === 0 ? b[1] - a[1]
|
42164 | : ca === 1 ? a[0] - b[0]
|
42165 | : ca === 2 ? a[1] - b[1]
|
42166 | : b[0] - a[0];
|
42167 | }
|
42168 |
|
42169 | return function(stream) {
|
42170 | var activeStream = stream,
|
42171 | bufferStream = clipBuffer(),
|
42172 | segments,
|
42173 | polygon,
|
42174 | ring,
|
42175 | x__, y__, v__,
|
42176 | x_, y_, v_,
|
42177 | first,
|
42178 | clean;
|
42179 |
|
42180 | var clipStream = {
|
42181 | point: point,
|
42182 | lineStart: lineStart,
|
42183 | lineEnd: lineEnd,
|
42184 | polygonStart: polygonStart,
|
42185 | polygonEnd: polygonEnd
|
42186 | };
|
42187 |
|
42188 | function point(x, y) {
|
42189 | if (visible(x, y)) activeStream.point(x, y);
|
42190 | }
|
42191 |
|
42192 | function polygonInside() {
|
42193 | var winding = 0;
|
42194 |
|
42195 | for (var i = 0, n = polygon.length; i < n; ++i) {
|
42196 | for (var ring = polygon[i], j = 1, m = ring.length, point = ring[0], a0, a1, b0 = point[0], b1 = point[1]; j < m; ++j) {
|
42197 | a0 = b0, a1 = b1, point = ring[j], b0 = point[0], b1 = point[1];
|
42198 | if (a1 <= y1) { if (b1 > y1 && (b0 - a0) * (y1 - a1) > (b1 - a1) * (x0 - a0)) ++winding; }
|
42199 | else { if (b1 <= y1 && (b0 - a0) * (y1 - a1) < (b1 - a1) * (x0 - a0)) --winding; }
|
42200 | }
|
42201 | }
|
42202 |
|
42203 | return winding;
|
42204 | }
|
42205 |
|
42206 |
|
42207 | function polygonStart() {
|
42208 | activeStream = bufferStream, segments = [], polygon = [], clean = true;
|
42209 | }
|
42210 |
|
42211 | function polygonEnd() {
|
42212 | var startInside = polygonInside(),
|
42213 | cleanInside = clean && startInside,
|
42214 | visible = (segments = merge$1(segments)).length;
|
42215 | if (cleanInside || visible) {
|
42216 | stream.polygonStart();
|
42217 | if (cleanInside) {
|
42218 | stream.lineStart();
|
42219 | interpolate(null, null, 1, stream);
|
42220 | stream.lineEnd();
|
42221 | }
|
42222 | if (visible) {
|
42223 | clipPolygon$1(segments, compareIntersection, startInside, interpolate, stream);
|
42224 | }
|
42225 | stream.polygonEnd();
|
42226 | }
|
42227 | activeStream = stream, segments = polygon = ring = null;
|
42228 | }
|
42229 |
|
42230 | function lineStart() {
|
42231 | clipStream.point = linePoint;
|
42232 | if (polygon) polygon.push(ring = []);
|
42233 | first = true;
|
42234 | v_ = false;
|
42235 | x_ = y_ = NaN;
|
42236 | }
|
42237 |
|
42238 |
|
42239 |
|
42240 |
|
42241 | function lineEnd() {
|
42242 | if (segments) {
|
42243 | linePoint(x__, y__);
|
42244 | if (v__ && v_) bufferStream.rejoin();
|
42245 | segments.push(bufferStream.result());
|
42246 | }
|
42247 | clipStream.point = point;
|
42248 | if (v_) activeStream.lineEnd();
|
42249 | }
|
42250 |
|
42251 | function linePoint(x, y) {
|
42252 | var v = visible(x, y);
|
42253 | if (polygon) ring.push([x, y]);
|
42254 | if (first) {
|
42255 | x__ = x, y__ = y, v__ = v;
|
42256 | first = false;
|
42257 | if (v) {
|
42258 | activeStream.lineStart();
|
42259 | activeStream.point(x, y);
|
42260 | }
|
42261 | } else {
|
42262 | if (v && v_) activeStream.point(x, y);
|
42263 | else {
|
42264 | var a = [x_ = Math.max(clipMin, Math.min(clipMax, x_)), y_ = Math.max(clipMin, Math.min(clipMax, y_))],
|
42265 | b = [x = Math.max(clipMin, Math.min(clipMax, x)), y = Math.max(clipMin, Math.min(clipMax, y))];
|
42266 | if (clipLine(a, b, x0, y0, x1, y1)) {
|
42267 | if (!v_) {
|
42268 | activeStream.lineStart();
|
42269 | activeStream.point(a[0], a[1]);
|
42270 | }
|
42271 | activeStream.point(b[0], b[1]);
|
42272 | if (!v) activeStream.lineEnd();
|
42273 | clean = false;
|
42274 | } else if (v) {
|
42275 | activeStream.lineStart();
|
42276 | activeStream.point(x, y);
|
42277 | clean = false;
|
42278 | }
|
42279 | }
|
42280 | }
|
42281 | x_ = x, y_ = y, v_ = v;
|
42282 | }
|
42283 |
|
42284 | return clipStream;
|
42285 | };
|
42286 | }
|
42287 |
|
42288 | var sum$1 = adder();
|
42289 |
|
42290 | var polygonContains = function(polygon, point) {
|
42291 | var lambda = point[0],
|
42292 | phi = point[1],
|
42293 | normal = [sin(lambda), -cos(lambda), 0],
|
42294 | angle = 0,
|
42295 | winding = 0;
|
42296 |
|
42297 | sum$1.reset();
|
42298 |
|
42299 | for (var i = 0, n = polygon.length; i < n; ++i) {
|
42300 | if (!(m = (ring = polygon[i]).length)) continue;
|
42301 | var ring,
|
42302 | m,
|
42303 | point0 = ring[m - 1],
|
42304 | lambda0 = point0[0],
|
42305 | phi0 = point0[1] / 2 + quarterPi,
|
42306 | sinPhi0 = sin(phi0),
|
42307 | cosPhi0 = cos(phi0);
|
42308 |
|
42309 | for (var j = 0; j < m; ++j, lambda0 = lambda1, sinPhi0 = sinPhi1, cosPhi0 = cosPhi1, point0 = point1) {
|
42310 | var point1 = ring[j],
|
42311 | lambda1 = point1[0],
|
42312 | phi1 = point1[1] / 2 + quarterPi,
|
42313 | sinPhi1 = sin(phi1),
|
42314 | cosPhi1 = cos(phi1),
|
42315 | delta = lambda1 - lambda0,
|
42316 | sign = delta >= 0 ? 1 : -1,
|
42317 | absDelta = sign * delta,
|
42318 | antimeridian = absDelta > pi,
|
42319 | k = sinPhi0 * sinPhi1;
|
42320 |
|
42321 | sum$1.add(atan2(k * sign * sin(absDelta), cosPhi0 * cosPhi1 + k * cos(absDelta)));
|
42322 | angle += antimeridian ? delta + sign * tau : delta;
|
42323 |
|
42324 |
|
42325 |
|
42326 | if (antimeridian ^ lambda0 >= lambda ^ lambda1 >= lambda) {
|
42327 | var arc = cartesianCross(cartesian(point0), cartesian(point1));
|
42328 | cartesianNormalizeInPlace(arc);
|
42329 | var intersection = cartesianCross(normal, arc);
|
42330 | cartesianNormalizeInPlace(intersection);
|
42331 | var phiArc = (antimeridian ^ delta >= 0 ? -1 : 1) * asin(intersection[2]);
|
42332 | if (phi > phiArc || phi === phiArc && (arc[0] || arc[1])) {
|
42333 | winding += antimeridian ^ delta >= 0 ? 1 : -1;
|
42334 | }
|
42335 | }
|
42336 | }
|
42337 | }
|
42338 |
|
42339 |
|
42340 |
|
42341 |
|
42342 |
|
42343 |
|
42344 |
|
42345 |
|
42346 |
|
42347 |
|
42348 |
|
42349 |
|
42350 | return (angle < -epsilon$1 || angle < epsilon$1 && sum$1 < -epsilon$1) ^ (winding & 1);
|
42351 | };
|
42352 |
|
42353 | var lengthSum = adder();
|
42354 |
|
42355 | var identity$2 = function(x) {
|
42356 | return x;
|
42357 | };
|
42358 |
|
42359 | var areaSum$1 = adder();
|
42360 | var areaRingSum$1 = adder();
|
42361 |
|
42362 | var x0$2 = Infinity;
|
42363 | var y0$2 = x0$2;
|
42364 | var x1 = -x0$2;
|
42365 | var y1 = x1;
|
42366 |
|
42367 | var boundsStream$1 = {
|
42368 | point: boundsPoint$1,
|
42369 | lineStart: noop,
|
42370 | lineEnd: noop,
|
42371 | polygonStart: noop,
|
42372 | polygonEnd: noop,
|
42373 | result: function() {
|
42374 | var bounds = [[x0$2, y0$2], [x1, y1]];
|
42375 | x1 = y1 = -(y0$2 = x0$2 = Infinity);
|
42376 | return bounds;
|
42377 | }
|
42378 | };
|
42379 |
|
42380 | function boundsPoint$1(x, y) {
|
42381 | if (x < x0$2) x0$2 = x;
|
42382 | if (x > x1) x1 = x;
|
42383 | if (y < y0$2) y0$2 = y;
|
42384 | if (y > y1) y1 = y;
|
42385 | }
|
42386 |
|
42387 | var lengthSum$1 = adder();
|
42388 |
|
42389 | var clip = function(pointVisible, clipLine, interpolate, start) {
|
42390 | return function(rotate, sink) {
|
42391 | var line = clipLine(sink),
|
42392 | rotatedStart = rotate.invert(start[0], start[1]),
|
42393 | ringBuffer = clipBuffer(),
|
42394 | ringSink = clipLine(ringBuffer),
|
42395 | polygonStarted = false,
|
42396 | polygon,
|
42397 | segments,
|
42398 | ring;
|
42399 |
|
42400 | var clip = {
|
42401 | point: point,
|
42402 | lineStart: lineStart,
|
42403 | lineEnd: lineEnd,
|
42404 | polygonStart: function() {
|
42405 | clip.point = pointRing;
|
42406 | clip.lineStart = ringStart;
|
42407 | clip.lineEnd = ringEnd;
|
42408 | segments = [];
|
42409 | polygon = [];
|
42410 | },
|
42411 | polygonEnd: function() {
|
42412 | clip.point = point;
|
42413 | clip.lineStart = lineStart;
|
42414 | clip.lineEnd = lineEnd;
|
42415 | segments = merge$1(segments);
|
42416 | var startInside = polygonContains(polygon, rotatedStart);
|
42417 | if (segments.length) {
|
42418 | if (!polygonStarted) sink.polygonStart(), polygonStarted = true;
|
42419 | clipPolygon$1(segments, compareIntersection, startInside, interpolate, sink);
|
42420 | } else if (startInside) {
|
42421 | if (!polygonStarted) sink.polygonStart(), polygonStarted = true;
|
42422 | sink.lineStart();
|
42423 | interpolate(null, null, 1, sink);
|
42424 | sink.lineEnd();
|
42425 | }
|
42426 | if (polygonStarted) sink.polygonEnd(), polygonStarted = false;
|
42427 | segments = polygon = null;
|
42428 | },
|
42429 | sphere: function() {
|
42430 | sink.polygonStart();
|
42431 | sink.lineStart();
|
42432 | interpolate(null, null, 1, sink);
|
42433 | sink.lineEnd();
|
42434 | sink.polygonEnd();
|
42435 | }
|
42436 | };
|
42437 |
|
42438 | function point(lambda, phi) {
|
42439 | var point = rotate(lambda, phi);
|
42440 | if (pointVisible(lambda = point[0], phi = point[1])) sink.point(lambda, phi);
|
42441 | }
|
42442 |
|
42443 | function pointLine(lambda, phi) {
|
42444 | var point = rotate(lambda, phi);
|
42445 | line.point(point[0], point[1]);
|
42446 | }
|
42447 |
|
42448 | function lineStart() {
|
42449 | clip.point = pointLine;
|
42450 | line.lineStart();
|
42451 | }
|
42452 |
|
42453 | function lineEnd() {
|
42454 | clip.point = point;
|
42455 | line.lineEnd();
|
42456 | }
|
42457 |
|
42458 | function pointRing(lambda, phi) {
|
42459 | ring.push([lambda, phi]);
|
42460 | var point = rotate(lambda, phi);
|
42461 | ringSink.point(point[0], point[1]);
|
42462 | }
|
42463 |
|
42464 | function ringStart() {
|
42465 | ringSink.lineStart();
|
42466 | ring = [];
|
42467 | }
|
42468 |
|
42469 | function ringEnd() {
|
42470 | pointRing(ring[0][0], ring[0][1]);
|
42471 | ringSink.lineEnd();
|
42472 |
|
42473 | var clean = ringSink.clean(),
|
42474 | ringSegments = ringBuffer.result(),
|
42475 | i, n = ringSegments.length, m,
|
42476 | segment,
|
42477 | point;
|
42478 |
|
42479 | ring.pop();
|
42480 | polygon.push(ring);
|
42481 | ring = null;
|
42482 |
|
42483 | if (!n) return;
|
42484 |
|
42485 |
|
42486 | if (clean & 1) {
|
42487 | segment = ringSegments[0];
|
42488 | if ((m = segment.length - 1) > 0) {
|
42489 | if (!polygonStarted) sink.polygonStart(), polygonStarted = true;
|
42490 | sink.lineStart();
|
42491 | for (i = 0; i < m; ++i) sink.point((point = segment[i])[0], point[1]);
|
42492 | sink.lineEnd();
|
42493 | }
|
42494 | return;
|
42495 | }
|
42496 |
|
42497 |
|
42498 |
|
42499 | if (n > 1 && clean & 2) ringSegments.push(ringSegments.pop().concat(ringSegments.shift()));
|
42500 |
|
42501 | segments.push(ringSegments.filter(validSegment));
|
42502 | }
|
42503 |
|
42504 | return clip;
|
42505 | };
|
42506 | };
|
42507 |
|
42508 | function validSegment(segment) {
|
42509 | return segment.length > 1;
|
42510 | }
|
42511 |
|
42512 |
|
42513 |
|
42514 | function compareIntersection(a, b) {
|
42515 | return ((a = a.x)[0] < 0 ? a[1] - halfPi - epsilon$1 : halfPi - a[1])
|
42516 | - ((b = b.x)[0] < 0 ? b[1] - halfPi - epsilon$1 : halfPi - b[1]);
|
42517 | }
|
42518 |
|
42519 | var clipAntimeridian = clip(
|
42520 | function() { return true; },
|
42521 | clipAntimeridianLine,
|
42522 | clipAntimeridianInterpolate,
|
42523 | [-pi, -halfPi]
|
42524 | );
|
42525 |
|
42526 |
|
42527 |
|
42528 |
|
42529 | function clipAntimeridianLine(stream) {
|
42530 | var lambda0 = NaN,
|
42531 | phi0 = NaN,
|
42532 | sign0 = NaN,
|
42533 | clean;
|
42534 |
|
42535 | return {
|
42536 | lineStart: function() {
|
42537 | stream.lineStart();
|
42538 | clean = 1;
|
42539 | },
|
42540 | point: function(lambda1, phi1) {
|
42541 | var sign1 = lambda1 > 0 ? pi : -pi,
|
42542 | delta = abs(lambda1 - lambda0);
|
42543 | if (abs(delta - pi) < epsilon$1) {
|
42544 | stream.point(lambda0, phi0 = (phi0 + phi1) / 2 > 0 ? halfPi : -halfPi);
|
42545 | stream.point(sign0, phi0);
|
42546 | stream.lineEnd();
|
42547 | stream.lineStart();
|
42548 | stream.point(sign1, phi0);
|
42549 | stream.point(lambda1, phi0);
|
42550 | clean = 0;
|
42551 | } else if (sign0 !== sign1 && delta >= pi) {
|
42552 | if (abs(lambda0 - sign0) < epsilon$1) lambda0 -= sign0 * epsilon$1;
|
42553 | if (abs(lambda1 - sign1) < epsilon$1) lambda1 -= sign1 * epsilon$1;
|
42554 | phi0 = clipAntimeridianIntersect(lambda0, phi0, lambda1, phi1);
|
42555 | stream.point(sign0, phi0);
|
42556 | stream.lineEnd();
|
42557 | stream.lineStart();
|
42558 | stream.point(sign1, phi0);
|
42559 | clean = 0;
|
42560 | }
|
42561 | stream.point(lambda0 = lambda1, phi0 = phi1);
|
42562 | sign0 = sign1;
|
42563 | },
|
42564 | lineEnd: function() {
|
42565 | stream.lineEnd();
|
42566 | lambda0 = phi0 = NaN;
|
42567 | },
|
42568 | clean: function() {
|
42569 | return 2 - clean;
|
42570 | }
|
42571 | };
|
42572 | }
|
42573 |
|
42574 | function clipAntimeridianIntersect(lambda0, phi0, lambda1, phi1) {
|
42575 | var cosPhi0,
|
42576 | cosPhi1,
|
42577 | sinLambda0Lambda1 = sin(lambda0 - lambda1);
|
42578 | return abs(sinLambda0Lambda1) > epsilon$1
|
42579 | ? atan((sin(phi0) * (cosPhi1 = cos(phi1)) * sin(lambda1)
|
42580 | - sin(phi1) * (cosPhi0 = cos(phi0)) * sin(lambda0))
|
42581 | / (cosPhi0 * cosPhi1 * sinLambda0Lambda1))
|
42582 | : (phi0 + phi1) / 2;
|
42583 | }
|
42584 |
|
42585 | function clipAntimeridianInterpolate(from, to, direction, stream) {
|
42586 | var phi;
|
42587 | if (from == null) {
|
42588 | phi = direction * halfPi;
|
42589 | stream.point(-pi, phi);
|
42590 | stream.point(0, phi);
|
42591 | stream.point(pi, phi);
|
42592 | stream.point(pi, 0);
|
42593 | stream.point(pi, -phi);
|
42594 | stream.point(0, -phi);
|
42595 | stream.point(-pi, -phi);
|
42596 | stream.point(-pi, 0);
|
42597 | stream.point(-pi, phi);
|
42598 | } else if (abs(from[0] - to[0]) > epsilon$1) {
|
42599 | var lambda = from[0] < to[0] ? pi : -pi;
|
42600 | phi = direction * lambda / 2;
|
42601 | stream.point(-lambda, phi);
|
42602 | stream.point(0, phi);
|
42603 | stream.point(lambda, phi);
|
42604 | } else {
|
42605 | stream.point(to[0], to[1]);
|
42606 | }
|
42607 | }
|
42608 |
|
42609 | var clipCircle = function(radius, delta) {
|
42610 | var cr = cos(radius),
|
42611 | smallRadius = cr > 0,
|
42612 | notHemisphere = abs(cr) > epsilon$1;
|
42613 |
|
42614 | function interpolate(from, to, direction, stream) {
|
42615 | circleStream(stream, radius, delta, direction, from, to);
|
42616 | }
|
42617 |
|
42618 | function visible(lambda, phi) {
|
42619 | return cos(lambda) * cos(phi) > cr;
|
42620 | }
|
42621 |
|
42622 |
|
42623 |
|
42624 |
|
42625 |
|
42626 | function clipLine(stream) {
|
42627 | var point0,
|
42628 | c0,
|
42629 | v0,
|
42630 | v00,
|
42631 | clean;
|
42632 | return {
|
42633 | lineStart: function() {
|
42634 | v00 = v0 = false;
|
42635 | clean = 1;
|
42636 | },
|
42637 | point: function(lambda, phi) {
|
42638 | var point1 = [lambda, phi],
|
42639 | point2,
|
42640 | v = visible(lambda, phi),
|
42641 | c = smallRadius
|
42642 | ? v ? 0 : code(lambda, phi)
|
42643 | : v ? code(lambda + (lambda < 0 ? pi : -pi), phi) : 0;
|
42644 | if (!point0 && (v00 = v0 = v)) stream.lineStart();
|
42645 |
|
42646 |
|
42647 | if (v !== v0) {
|
42648 | point2 = intersect(point0, point1);
|
42649 | if (!point2 || pointEqual(point0, point2) || pointEqual(point1, point2)) {
|
42650 | point1[0] += epsilon$1;
|
42651 | point1[1] += epsilon$1;
|
42652 | v = visible(point1[0], point1[1]);
|
42653 | }
|
42654 | }
|
42655 | if (v !== v0) {
|
42656 | clean = 0;
|
42657 | if (v) {
|
42658 |
|
42659 | stream.lineStart();
|
42660 | point2 = intersect(point1, point0);
|
42661 | stream.point(point2[0], point2[1]);
|
42662 | } else {
|
42663 |
|
42664 | point2 = intersect(point0, point1);
|
42665 | stream.point(point2[0], point2[1]);
|
42666 | stream.lineEnd();
|
42667 | }
|
42668 | point0 = point2;
|
42669 | } else if (notHemisphere && point0 && smallRadius ^ v) {
|
42670 | var t;
|
42671 |
|
42672 |
|
42673 | if (!(c & c0) && (t = intersect(point1, point0, true))) {
|
42674 | clean = 0;
|
42675 | if (smallRadius) {
|
42676 | stream.lineStart();
|
42677 | stream.point(t[0][0], t[0][1]);
|
42678 | stream.point(t[1][0], t[1][1]);
|
42679 | stream.lineEnd();
|
42680 | } else {
|
42681 | stream.point(t[1][0], t[1][1]);
|
42682 | stream.lineEnd();
|
42683 | stream.lineStart();
|
42684 | stream.point(t[0][0], t[0][1]);
|
42685 | }
|
42686 | }
|
42687 | }
|
42688 | if (v && (!point0 || !pointEqual(point0, point1))) {
|
42689 | stream.point(point1[0], point1[1]);
|
42690 | }
|
42691 | point0 = point1, v0 = v, c0 = c;
|
42692 | },
|
42693 | lineEnd: function() {
|
42694 | if (v0) stream.lineEnd();
|
42695 | point0 = null;
|
42696 | },
|
42697 |
|
42698 |
|
42699 | clean: function() {
|
42700 | return clean | ((v00 && v0) << 1);
|
42701 | }
|
42702 | };
|
42703 | }
|
42704 |
|
42705 |
|
42706 | function intersect(a, b, two) {
|
42707 | var pa = cartesian(a),
|
42708 | pb = cartesian(b);
|
42709 |
|
42710 |
|
42711 |
|
42712 | var n1 = [1, 0, 0],
|
42713 | n2 = cartesianCross(pa, pb),
|
42714 | n2n2 = cartesianDot(n2, n2),
|
42715 | n1n2 = n2[0],
|
42716 | determinant = n2n2 - n1n2 * n1n2;
|
42717 |
|
42718 |
|
42719 | if (!determinant) return !two && a;
|
42720 |
|
42721 | var c1 = cr * n2n2 / determinant,
|
42722 | c2 = -cr * n1n2 / determinant,
|
42723 | n1xn2 = cartesianCross(n1, n2),
|
42724 | A = cartesianScale(n1, c1),
|
42725 | B = cartesianScale(n2, c2);
|
42726 | cartesianAddInPlace(A, B);
|
42727 |
|
42728 |
|
42729 | var u = n1xn2,
|
42730 | w = cartesianDot(A, u),
|
42731 | uu = cartesianDot(u, u),
|
42732 | t2 = w * w - uu * (cartesianDot(A, A) - 1);
|
42733 |
|
42734 | if (t2 < 0) return;
|
42735 |
|
42736 | var t = sqrt(t2),
|
42737 | q = cartesianScale(u, (-w - t) / uu);
|
42738 | cartesianAddInPlace(q, A);
|
42739 | q = spherical(q);
|
42740 |
|
42741 | if (!two) return q;
|
42742 |
|
42743 |
|
42744 | var lambda0 = a[0],
|
42745 | lambda1 = b[0],
|
42746 | phi0 = a[1],
|
42747 | phi1 = b[1],
|
42748 | z;
|
42749 |
|
42750 | if (lambda1 < lambda0) z = lambda0, lambda0 = lambda1, lambda1 = z;
|
42751 |
|
42752 | var delta = lambda1 - lambda0,
|
42753 | polar = abs(delta - pi) < epsilon$1,
|
42754 | meridian = polar || delta < epsilon$1;
|
42755 |
|
42756 | if (!polar && phi1 < phi0) z = phi0, phi0 = phi1, phi1 = z;
|
42757 |
|
42758 |
|
42759 | if (meridian
|
42760 | ? polar
|
42761 | ? phi0 + phi1 > 0 ^ q[1] < (abs(q[0] - lambda0) < epsilon$1 ? phi0 : phi1)
|
42762 | : phi0 <= q[1] && q[1] <= phi1
|
42763 | : delta > pi ^ (lambda0 <= q[0] && q[0] <= lambda1)) {
|
42764 | var q1 = cartesianScale(u, (-w + t) / uu);
|
42765 | cartesianAddInPlace(q1, A);
|
42766 | return [q, spherical(q1)];
|
42767 | }
|
42768 | }
|
42769 |
|
42770 |
|
42771 |
|
42772 | function code(lambda, phi) {
|
42773 | var r = smallRadius ? radius : pi - radius,
|
42774 | code = 0;
|
42775 | if (lambda < -r) code |= 1;
|
42776 | else if (lambda > r) code |= 2;
|
42777 | if (phi < -r) code |= 4;
|
42778 | else if (phi > r) code |= 8;
|
42779 | return code;
|
42780 | }
|
42781 |
|
42782 | return clip(visible, clipLine, interpolate, smallRadius ? [0, -radius] : [-pi, radius - pi]);
|
42783 | };
|
42784 |
|
42785 | function transformer(methods) {
|
42786 | return function(stream) {
|
42787 | var s = new TransformStream;
|
42788 | for (var key in methods) s[key] = methods[key];
|
42789 | s.stream = stream;
|
42790 | return s;
|
42791 | };
|
42792 | }
|
42793 |
|
42794 | function TransformStream() {}
|
42795 |
|
42796 | TransformStream.prototype = {
|
42797 | constructor: TransformStream,
|
42798 | point: function(x, y) { this.stream.point(x, y); },
|
42799 | sphere: function() { this.stream.sphere(); },
|
42800 | lineStart: function() { this.stream.lineStart(); },
|
42801 | lineEnd: function() { this.stream.lineEnd(); },
|
42802 | polygonStart: function() { this.stream.polygonStart(); },
|
42803 | polygonEnd: function() { this.stream.polygonEnd(); }
|
42804 | };
|
42805 |
|
42806 | function fitExtent(projection, extent, object) {
|
42807 | var w = extent[1][0] - extent[0][0],
|
42808 | h = extent[1][1] - extent[0][1],
|
42809 | clip = projection.clipExtent && projection.clipExtent();
|
42810 |
|
42811 | projection
|
42812 | .scale(150)
|
42813 | .translate([0, 0]);
|
42814 |
|
42815 | if (clip != null) projection.clipExtent(null);
|
42816 |
|
42817 | geoStream(object, projection.stream(boundsStream$1));
|
42818 |
|
42819 | var b = boundsStream$1.result(),
|
42820 | k = Math.min(w / (b[1][0] - b[0][0]), h / (b[1][1] - b[0][1])),
|
42821 | x = +extent[0][0] + (w - k * (b[1][0] + b[0][0])) / 2,
|
42822 | y = +extent[0][1] + (h - k * (b[1][1] + b[0][1])) / 2;
|
42823 |
|
42824 | if (clip != null) projection.clipExtent(clip);
|
42825 |
|
42826 | return projection
|
42827 | .scale(k * 150)
|
42828 | .translate([x, y]);
|
42829 | }
|
42830 |
|
42831 | function fitSize(projection, size, object) {
|
42832 | return fitExtent(projection, [[0, 0], size], object);
|
42833 | }
|
42834 |
|
42835 | var maxDepth = 16;
|
42836 | var cosMinDistance = cos(30 * radians);
|
42837 |
|
42838 | var resample = function(project, delta2) {
|
42839 | return +delta2 ? resample$1(project, delta2) : resampleNone(project);
|
42840 | };
|
42841 |
|
42842 | function resampleNone(project) {
|
42843 | return transformer({
|
42844 | point: function(x, y) {
|
42845 | x = project(x, y);
|
42846 | this.stream.point(x[0], x[1]);
|
42847 | }
|
42848 | });
|
42849 | }
|
42850 |
|
42851 | function resample$1(project, delta2) {
|
42852 |
|
42853 | function resampleLineTo(x0, y0, lambda0, a0, b0, c0, x1, y1, lambda1, a1, b1, c1, depth, stream) {
|
42854 | var dx = x1 - x0,
|
42855 | dy = y1 - y0,
|
42856 | d2 = dx * dx + dy * dy;
|
42857 | if (d2 > 4 * delta2 && depth--) {
|
42858 | var a = a0 + a1,
|
42859 | b = b0 + b1,
|
42860 | c = c0 + c1,
|
42861 | m = sqrt(a * a + b * b + c * c),
|
42862 | phi2 = asin(c /= m),
|
42863 | lambda2 = abs(abs(c) - 1) < epsilon$1 || abs(lambda0 - lambda1) < epsilon$1 ? (lambda0 + lambda1) / 2 : atan2(b, a),
|
42864 | p = project(lambda2, phi2),
|
42865 | x2 = p[0],
|
42866 | y2 = p[1],
|
42867 | dx2 = x2 - x0,
|
42868 | dy2 = y2 - y0,
|
42869 | dz = dy * dx2 - dx * dy2;
|
42870 | if (dz * dz / d2 > delta2
|
42871 | || abs((dx * dx2 + dy * dy2) / d2 - 0.5) > 0.3
|
42872 | || a0 * a1 + b0 * b1 + c0 * c1 < cosMinDistance) {
|
42873 | resampleLineTo(x0, y0, lambda0, a0, b0, c0, x2, y2, lambda2, a /= m, b /= m, c, depth, stream);
|
42874 | stream.point(x2, y2);
|
42875 | resampleLineTo(x2, y2, lambda2, a, b, c, x1, y1, lambda1, a1, b1, c1, depth, stream);
|
42876 | }
|
42877 | }
|
42878 | }
|
42879 | return function(stream) {
|
42880 | var lambda00, x00, y00, a00, b00, c00,
|
42881 | lambda0, x0, y0, a0, b0, c0;
|
42882 |
|
42883 | var resampleStream = {
|
42884 | point: point,
|
42885 | lineStart: lineStart,
|
42886 | lineEnd: lineEnd,
|
42887 | polygonStart: function() { stream.polygonStart(); resampleStream.lineStart = ringStart; },
|
42888 | polygonEnd: function() { stream.polygonEnd(); resampleStream.lineStart = lineStart; }
|
42889 | };
|
42890 |
|
42891 | function point(x, y) {
|
42892 | x = project(x, y);
|
42893 | stream.point(x[0], x[1]);
|
42894 | }
|
42895 |
|
42896 | function lineStart() {
|
42897 | x0 = NaN;
|
42898 | resampleStream.point = linePoint;
|
42899 | stream.lineStart();
|
42900 | }
|
42901 |
|
42902 | function linePoint(lambda, phi) {
|
42903 | var c = cartesian([lambda, phi]), p = project(lambda, phi);
|
42904 | resampleLineTo(x0, y0, lambda0, a0, b0, c0, x0 = p[0], y0 = p[1], lambda0 = lambda, a0 = c[0], b0 = c[1], c0 = c[2], maxDepth, stream);
|
42905 | stream.point(x0, y0);
|
42906 | }
|
42907 |
|
42908 | function lineEnd() {
|
42909 | resampleStream.point = point;
|
42910 | stream.lineEnd();
|
42911 | }
|
42912 |
|
42913 | function ringStart() {
|
42914 | lineStart();
|
42915 | resampleStream.point = ringPoint;
|
42916 | resampleStream.lineEnd = ringEnd;
|
42917 | }
|
42918 |
|
42919 | function ringPoint(lambda, phi) {
|
42920 | linePoint(lambda00 = lambda, phi), x00 = x0, y00 = y0, a00 = a0, b00 = b0, c00 = c0;
|
42921 | resampleStream.point = linePoint;
|
42922 | }
|
42923 |
|
42924 | function ringEnd() {
|
42925 | resampleLineTo(x0, y0, lambda0, a0, b0, c0, x00, y00, lambda00, a00, b00, c00, maxDepth, stream);
|
42926 | resampleStream.lineEnd = lineEnd;
|
42927 | lineEnd();
|
42928 | }
|
42929 |
|
42930 | return resampleStream;
|
42931 | };
|
42932 | }
|
42933 |
|
42934 | var transformRadians = transformer({
|
42935 | point: function(x, y) {
|
42936 | this.stream.point(x * radians, y * radians);
|
42937 | }
|
42938 | });
|
42939 |
|
42940 | function projection(project) {
|
42941 | return projectionMutator(function() { return project; })();
|
42942 | }
|
42943 |
|
42944 | function projectionMutator(projectAt) {
|
42945 | var project,
|
42946 | k = 150,
|
42947 | x = 480, y = 250,
|
42948 | dx, dy, lambda = 0, phi = 0,
|
42949 | deltaLambda = 0, deltaPhi = 0, deltaGamma = 0, rotate, projectRotate,
|
42950 | theta = null, preclip = clipAntimeridian,
|
42951 | x0 = null, y0, x1, y1, postclip = identity$2,
|
42952 | delta2 = 0.5, projectResample = resample(projectTransform, delta2),
|
42953 | cache,
|
42954 | cacheStream;
|
42955 |
|
42956 | function projection(point) {
|
42957 | point = projectRotate(point[0] * radians, point[1] * radians);
|
42958 | return [point[0] * k + dx, dy - point[1] * k];
|
42959 | }
|
42960 |
|
42961 | function invert(point) {
|
42962 | point = projectRotate.invert((point[0] - dx) / k, (dy - point[1]) / k);
|
42963 | return point && [point[0] * degrees, point[1] * degrees];
|
42964 | }
|
42965 |
|
42966 | function projectTransform(x, y) {
|
42967 | return x = project(x, y), [x[0] * k + dx, dy - x[1] * k];
|
42968 | }
|
42969 |
|
42970 | projection.stream = function(stream) {
|
42971 | return cache && cacheStream === stream ? cache : cache = transformRadians(preclip(rotate, projectResample(postclip(cacheStream = stream))));
|
42972 | };
|
42973 |
|
42974 | projection.clipAngle = function(_) {
|
42975 | return arguments.length ? (preclip = +_ ? clipCircle(theta = _ * radians, 6 * radians) : (theta = null, clipAntimeridian), reset()) : theta * degrees;
|
42976 | };
|
42977 |
|
42978 | projection.clipExtent = function(_) {
|
42979 | return arguments.length ? (postclip = _ == null ? (x0 = y0 = x1 = y1 = null, identity$2) : clipExtent(x0 = +_[0][0], y0 = +_[0][1], x1 = +_[1][0], y1 = +_[1][1]), reset()) : x0 == null ? null : [[x0, y0], [x1, y1]];
|
42980 | };
|
42981 |
|
42982 | projection.scale = function(_) {
|
42983 | return arguments.length ? (k = +_, recenter()) : k;
|
42984 | };
|
42985 |
|
42986 | projection.translate = function(_) {
|
42987 | return arguments.length ? (x = +_[0], y = +_[1], recenter()) : [x, y];
|
42988 | };
|
42989 |
|
42990 | projection.center = function(_) {
|
42991 | return arguments.length ? (lambda = _[0] % 360 * radians, phi = _[1] % 360 * radians, recenter()) : [lambda * degrees, phi * degrees];
|
42992 | };
|
42993 |
|
42994 | projection.rotate = function(_) {
|
42995 | return arguments.length ? (deltaLambda = _[0] % 360 * radians, deltaPhi = _[1] % 360 * radians, deltaGamma = _.length > 2 ? _[2] % 360 * radians : 0, recenter()) : [deltaLambda * degrees, deltaPhi * degrees, deltaGamma * degrees];
|
42996 | };
|
42997 |
|
42998 | projection.precision = function(_) {
|
42999 | return arguments.length ? (projectResample = resample(projectTransform, delta2 = _ * _), reset()) : sqrt(delta2);
|
43000 | };
|
43001 |
|
43002 | projection.fitExtent = function(extent$$1, object) {
|
43003 | return fitExtent(projection, extent$$1, object);
|
43004 | };
|
43005 |
|
43006 | projection.fitSize = function(size, object) {
|
43007 | return fitSize(projection, size, object);
|
43008 | };
|
43009 |
|
43010 | function recenter() {
|
43011 | projectRotate = compose(rotate = rotateRadians(deltaLambda, deltaPhi, deltaGamma), project);
|
43012 | var center = project(lambda, phi);
|
43013 | dx = x - center[0] * k;
|
43014 | dy = y + center[1] * k;
|
43015 | return reset();
|
43016 | }
|
43017 |
|
43018 | function reset() {
|
43019 | cache = cacheStream = null;
|
43020 | return projection;
|
43021 | }
|
43022 |
|
43023 | return function() {
|
43024 | project = projectAt.apply(this, arguments);
|
43025 | projection.invert = project.invert && invert;
|
43026 | return recenter();
|
43027 | };
|
43028 | }
|
43029 |
|
43030 | function mercatorRaw(lambda, phi) {
|
43031 | return [lambda, log(tan((halfPi + phi) / 2))];
|
43032 | }
|
43033 |
|
43034 | mercatorRaw.invert = function(x, y) {
|
43035 | return [x, 2 * atan(exp(y)) - halfPi];
|
43036 | };
|
43037 |
|
43038 | function mercatorProjection(project) {
|
43039 | var m = projection(project),
|
43040 | center = m.center,
|
43041 | scale = m.scale,
|
43042 | translate = m.translate,
|
43043 | clipExtent = m.clipExtent,
|
43044 | x0 = null, y0, x1, y1;
|
43045 |
|
43046 | m.scale = function(_) {
|
43047 | return arguments.length ? (scale(_), reclip()) : scale();
|
43048 | };
|
43049 |
|
43050 | m.translate = function(_) {
|
43051 | return arguments.length ? (translate(_), reclip()) : translate();
|
43052 | };
|
43053 |
|
43054 | m.center = function(_) {
|
43055 | return arguments.length ? (center(_), reclip()) : center();
|
43056 | };
|
43057 |
|
43058 | m.clipExtent = function(_) {
|
43059 | return arguments.length ? (_ == null ? x0 = y0 = x1 = y1 = null : (x0 = +_[0][0], y0 = +_[0][1], x1 = +_[1][0], y1 = +_[1][1]), reclip()) : x0 == null ? null : [[x0, y0], [x1, y1]];
|
43060 | };
|
43061 |
|
43062 | function reclip() {
|
43063 | var k = pi * scale(),
|
43064 | t = m(rotation(m.rotate()).invert([0, 0]));
|
43065 | return clipExtent(x0 == null
|
43066 | ? [[t[0] - k, t[1] - k], [t[0] + k, t[1] + k]] : project === mercatorRaw
|
43067 | ? [[Math.max(t[0] - k, x0), y0], [Math.min(t[0] + k, x1), y1]]
|
43068 | : [[x0, Math.max(t[1] - k, y0)], [x1, Math.min(t[1] + k, y1)]]);
|
43069 | }
|
43070 |
|
43071 | return reclip();
|
43072 | }
|
43073 |
|
43074 | function transverseMercatorRaw(lambda, phi) {
|
43075 | return [log(tan((halfPi + phi) / 2)), -lambda];
|
43076 | }
|
43077 |
|
43078 | transverseMercatorRaw.invert = function(x, y) {
|
43079 | return [-y, 2 * atan(exp(x)) - halfPi];
|
43080 | };
|
43081 |
|
43082 | var geoTransverseMercator = function() {
|
43083 | var m = mercatorProjection(transverseMercatorRaw),
|
43084 | center = m.center,
|
43085 | rotate = m.rotate;
|
43086 |
|
43087 | m.center = function(_) {
|
43088 | return arguments.length ? center([-_[1], _[0]]) : (_ = center(), [_[1], -_[0]]);
|
43089 | };
|
43090 |
|
43091 | m.rotate = function(_) {
|
43092 | return arguments.length ? rotate([_[0], _[1], _.length > 2 ? _[2] + 90 : 90]) : (_ = rotate(), [_[0], _[1], _[2] - 90]);
|
43093 | };
|
43094 |
|
43095 | return rotate([0, 0, 90])
|
43096 | .scale(159.155);
|
43097 | };
|
43098 |
|
43099 |
|
43100 |
|
43101 |
|
43102 |
|
43103 |
|
43104 |
|
43105 |
|
43106 |
|
43107 |
|
43108 |
|
43109 |
|
43110 |
|
43111 |
|
43112 |
|
43113 |
|
43114 |
|
43115 |
|
43116 |
|
43117 |
|
43118 |
|
43119 |
|
43120 |
|
43121 |
|
43122 | function buffer$1(geojson, radius, options) {
|
43123 |
|
43124 | options = options || {};
|
43125 | var units = options.units;
|
43126 | var steps = options.steps || 64;
|
43127 |
|
43128 |
|
43129 | if (!geojson) throw new Error('geojson is required');
|
43130 | if (typeof options !== 'object') throw new Error('options must be an object');
|
43131 | if (typeof steps !== 'number') throw new Error('steps must be an number');
|
43132 |
|
43133 |
|
43134 | if (radius === undefined) throw new Error('radius is required');
|
43135 | if (steps <= 0) throw new Error('steps must be greater than 0');
|
43136 |
|
43137 |
|
43138 | steps = steps || 64;
|
43139 | units = units || 'kilometers';
|
43140 |
|
43141 | var results = [];
|
43142 | switch (geojson.type) {
|
43143 | case 'GeometryCollection':
|
43144 | geomEach(geojson, function (geometry$$1) {
|
43145 | var buffered = bufferFeature(geometry$$1, radius, units, steps);
|
43146 | if (buffered) results.push(buffered);
|
43147 | });
|
43148 | return featureCollection(results);
|
43149 | case 'FeatureCollection':
|
43150 | featureEach(geojson, function (feature$$1) {
|
43151 | var multiBuffered = bufferFeature(feature$$1, radius, units, steps);
|
43152 | if (multiBuffered) {
|
43153 | featureEach(multiBuffered, function (buffered) {
|
43154 | if (buffered) results.push(buffered);
|
43155 | });
|
43156 | }
|
43157 | });
|
43158 | return featureCollection(results);
|
43159 | }
|
43160 | return bufferFeature(geojson, radius, units, steps);
|
43161 | }
|
43162 |
|
43163 |
|
43164 |
|
43165 |
|
43166 |
|
43167 |
|
43168 |
|
43169 |
|
43170 |
|
43171 |
|
43172 |
|
43173 | function bufferFeature(geojson, radius, units, steps) {
|
43174 | var properties = geojson.properties || {};
|
43175 | var geometry$$1 = (geojson.type === 'Feature') ? geojson.geometry : geojson;
|
43176 |
|
43177 |
|
43178 | if (geometry$$1.type === 'GeometryCollection') {
|
43179 | var results = [];
|
43180 | geomEach(geojson, function (geometry$$1) {
|
43181 | var buffered = bufferFeature(geometry$$1, radius, units, steps);
|
43182 | if (buffered) results.push(buffered);
|
43183 | });
|
43184 | return featureCollection(results);
|
43185 | }
|
43186 |
|
43187 |
|
43188 | var projected;
|
43189 | var bbox$$1 = bbox(geojson);
|
43190 | var needsTransverseMercator = bbox$$1[1] > 50 && bbox$$1[3] > 50;
|
43191 |
|
43192 | if (needsTransverseMercator) {
|
43193 | projected = {
|
43194 | type: geometry$$1.type,
|
43195 | coordinates: projectCoords(geometry$$1.coordinates, defineProjection(geometry$$1))
|
43196 | };
|
43197 | } else {
|
43198 | projected = toMercator(geometry$$1);
|
43199 | }
|
43200 |
|
43201 |
|
43202 | var reader = new GeoJSONReader();
|
43203 | var geom = reader.read(projected);
|
43204 | var distance = radiansToLength(lengthToRadians(radius, units), 'meters');
|
43205 | var buffered = BufferOp.bufferOp(geom, distance);
|
43206 | var writer = new GeoJSONWriter();
|
43207 | buffered = writer.write(buffered);
|
43208 |
|
43209 |
|
43210 | if (coordsIsNaN(buffered.coordinates)) return undefined;
|
43211 |
|
43212 |
|
43213 | var result;
|
43214 | if (needsTransverseMercator) {
|
43215 | result = {
|
43216 | type: buffered.type,
|
43217 | coordinates: unprojectCoords(buffered.coordinates, defineProjection(geometry$$1))
|
43218 | };
|
43219 | } else {
|
43220 | result = toWgs84(buffered);
|
43221 | }
|
43222 |
|
43223 | return (result.geometry) ? result : feature(result, properties);
|
43224 | }
|
43225 |
|
43226 |
|
43227 |
|
43228 |
|
43229 |
|
43230 |
|
43231 |
|
43232 |
|
43233 | function coordsIsNaN(coords) {
|
43234 | if (Array.isArray(coords[0])) return coordsIsNaN(coords[0]);
|
43235 | return isNaN(coords[0]);
|
43236 | }
|
43237 |
|
43238 |
|
43239 |
|
43240 |
|
43241 |
|
43242 |
|
43243 |
|
43244 |
|
43245 |
|
43246 | function projectCoords(coords, proj) {
|
43247 | if (typeof coords[0] !== 'object') return proj(coords);
|
43248 | return coords.map(function (coord) {
|
43249 | return projectCoords(coord, proj);
|
43250 | });
|
43251 | }
|
43252 |
|
43253 |
|
43254 |
|
43255 |
|
43256 |
|
43257 |
|
43258 |
|
43259 |
|
43260 |
|
43261 | function unprojectCoords(coords, proj) {
|
43262 | if (typeof coords[0] !== 'object') return proj.invert(coords);
|
43263 | return coords.map(function (coord) {
|
43264 | return unprojectCoords(coord, proj);
|
43265 | });
|
43266 | }
|
43267 |
|
43268 |
|
43269 |
|
43270 |
|
43271 |
|
43272 |
|
43273 |
|
43274 |
|
43275 | function defineProjection(geojson) {
|
43276 | var coords = center(geojson).geometry.coordinates.reverse();
|
43277 | var rotate = coords.map(function (coord) { return -coord; });
|
43278 | return geoTransverseMercator()
|
43279 | .center(coords)
|
43280 | .rotate(rotate)
|
43281 | .scale(earthRadius);
|
43282 | }
|
43283 |
|
43284 |
|
43285 |
|
43286 |
|
43287 |
|
43288 |
|
43289 |
|
43290 |
|
43291 |
|
43292 |
|
43293 |
|
43294 |
|
43295 |
|
43296 |
|
43297 |
|
43298 |
|
43299 |
|
43300 |
|
43301 |
|
43302 |
|
43303 |
|
43304 |
|
43305 |
|
43306 |
|
43307 |
|
43308 |
|
43309 |
|
43310 |
|
43311 | function union() {
|
43312 | var reader = new GeoJSONReader();
|
43313 | var result = reader.read(JSON.stringify(arguments[0].geometry));
|
43314 |
|
43315 | for (var i = 1; i < arguments.length; i++) {
|
43316 | result = UnionOp.union(result, reader.read(JSON.stringify(arguments[i].geometry)));
|
43317 | }
|
43318 |
|
43319 | var writer = new GeoJSONWriter();
|
43320 | result = writer.write(result);
|
43321 |
|
43322 | return {
|
43323 | type: 'Feature',
|
43324 | geometry: result,
|
43325 | properties: arguments[0].properties
|
43326 | };
|
43327 | }
|
43328 |
|
43329 |
|
43330 |
|
43331 |
|
43332 |
|
43333 |
|
43334 |
|
43335 |
|
43336 |
|
43337 |
|
43338 |
|
43339 |
|
43340 |
|
43341 |
|
43342 |
|
43343 |
|
43344 |
|
43345 |
|
43346 |
|
43347 |
|
43348 |
|
43349 |
|
43350 |
|
43351 |
|
43352 |
|
43353 |
|
43354 |
|
43355 |
|
43356 |
|
43357 |
|
43358 |
|
43359 |
|
43360 |
|
43361 |
|
43362 | function intersect$2(poly1, poly2) {
|
43363 | var geom1 = getGeom(poly1);
|
43364 | var geom2 = getGeom(poly2);
|
43365 |
|
43366 |
|
43367 |
|
43368 |
|
43369 |
|
43370 | if (cleanCoords(truncate(geom2, {precision: 4})).coordinates[0].length < 4) return null;
|
43371 | if (cleanCoords(truncate(geom1, {precision: 4})).coordinates[0].length < 4) return null;
|
43372 |
|
43373 | var reader = new GeoJSONReader();
|
43374 | var a = reader.read(truncate(geom1));
|
43375 | var b = reader.read(truncate(geom2));
|
43376 | var intersection = OverlayOp.intersection(a, b);
|
43377 |
|
43378 |
|
43379 | if (intersection.isEmpty()) return null;
|
43380 |
|
43381 | var writer = new GeoJSONWriter();
|
43382 | var geom = writer.write(intersection);
|
43383 | return feature(geom);
|
43384 | }
|
43385 |
|
43386 |
|
43387 |
|
43388 |
|
43389 |
|
43390 |
|
43391 |
|
43392 |
|
43393 |
|
43394 |
|
43395 |
|
43396 |
|
43397 |
|
43398 |
|
43399 |
|
43400 |
|
43401 |
|
43402 |
|
43403 |
|
43404 | function _getClosest(item, array, getDiff) {
|
43405 | var closest,
|
43406 | diff;
|
43407 |
|
43408 | if (!Array.isArray(array)) {
|
43409 | throw new Error('Get closest expects an array as second argument');
|
43410 | }
|
43411 |
|
43412 | array.forEach(function (comparedItem, comparedItemIndex) {
|
43413 | var thisDiff = getDiff(comparedItem, item);
|
43414 |
|
43415 | if (thisDiff >= 0 && (typeof diff == 'undefined' || thisDiff < diff)) {
|
43416 | diff = thisDiff;
|
43417 | closest = comparedItemIndex;
|
43418 | }
|
43419 | });
|
43420 |
|
43421 | return closest;
|
43422 | }
|
43423 |
|
43424 |
|
43425 |
|
43426 |
|
43427 |
|
43428 |
|
43429 |
|
43430 |
|
43431 |
|
43432 |
|
43433 |
|
43434 |
|
43435 |
|
43436 |
|
43437 |
|
43438 |
|
43439 |
|
43440 |
|
43441 |
|
43442 |
|
43443 |
|
43444 |
|
43445 |
|
43446 |
|
43447 |
|
43448 | function closestGreaterNumber(item, array) {
|
43449 | return _getClosest(item, array, function (comparedItem, item) {
|
43450 | return comparedItem - item;
|
43451 | });
|
43452 | }
|
43453 |
|
43454 |
|
43455 |
|
43456 |
|
43457 |
|
43458 |
|
43459 |
|
43460 |
|
43461 |
|
43462 |
|
43463 |
|
43464 |
|
43465 |
|
43466 |
|
43467 |
|
43468 |
|
43469 |
|
43470 |
|
43471 |
|
43472 |
|
43473 |
|
43474 |
|
43475 |
|
43476 |
|
43477 |
|
43478 |
|
43479 |
|
43480 |
|
43481 |
|
43482 |
|
43483 |
|
43484 |
|
43485 |
|
43486 |
|
43487 |
|
43488 |
|
43489 |
|
43490 |
|
43491 |
|
43492 |
|
43493 |
|
43494 |
|
43495 |
|
43496 |
|
43497 |
|
43498 |
|
43499 |
|
43500 |
|
43501 |
|
43502 |
|
43503 |
|
43504 |
|
43505 |
|
43506 |
|
43507 |
|
43508 |
|
43509 |
|
43510 | function dissolve$1(featureCollection$$1, options) {
|
43511 |
|
43512 | options = options || {};
|
43513 | if (!isObject(options)) throw new Error('options is invalid');
|
43514 | var propertyName = options.propertyName;
|
43515 |
|
43516 |
|
43517 | collectionOf(featureCollection$$1, 'Polygon', 'dissolve');
|
43518 |
|
43519 |
|
43520 | var fc = clone(featureCollection$$1);
|
43521 | var features = fc.features;
|
43522 |
|
43523 | var originalIndexOfItemsRemoved = [];
|
43524 |
|
43525 | features.forEach(function (f, i) {
|
43526 | f.properties.origIndexPosition = i;
|
43527 | });
|
43528 | var tree = geojsonRbush();
|
43529 | tree.load(fc);
|
43530 |
|
43531 | for (var i in features) {
|
43532 | var polygon$$1 = features[i];
|
43533 |
|
43534 | var featureChanged = false;
|
43535 |
|
43536 | tree.search(polygon$$1).features.forEach(function (potentialMatchingFeature) {
|
43537 | polygon$$1 = features[i];
|
43538 |
|
43539 | var matchFeaturePosition = potentialMatchingFeature.properties.origIndexPosition;
|
43540 |
|
43541 | if (originalIndexOfItemsRemoved.length > 0 && matchFeaturePosition !== 0) {
|
43542 | if (matchFeaturePosition > originalIndexOfItemsRemoved[originalIndexOfItemsRemoved.length - 1]) {
|
43543 | matchFeaturePosition = matchFeaturePosition - (originalIndexOfItemsRemoved.length);
|
43544 | } else {
|
43545 | var closestNumber$$1 = closestGreaterNumber(matchFeaturePosition, originalIndexOfItemsRemoved);
|
43546 | if (closestNumber$$1 !== 0) {
|
43547 | matchFeaturePosition = matchFeaturePosition - closestNumber$$1;
|
43548 | }
|
43549 | }
|
43550 | }
|
43551 |
|
43552 | if (matchFeaturePosition === +i) return;
|
43553 |
|
43554 | var matchFeature = features[matchFeaturePosition];
|
43555 | if (!matchFeature || !polygon$$1) return;
|
43556 |
|
43557 | if (propertyName !== undefined &&
|
43558 | matchFeature.properties[propertyName] !== polygon$$1.properties[propertyName]) return;
|
43559 |
|
43560 | if (!booleanOverlap(polygon$$1, matchFeature) || !ringsIntersect(polygon$$1, matchFeature)) return;
|
43561 |
|
43562 | features[i] = union(polygon$$1, matchFeature);
|
43563 |
|
43564 | originalIndexOfItemsRemoved.push(potentialMatchingFeature.properties.origIndexPosition);
|
43565 | originalIndexOfItemsRemoved.sort(function (a, b) {
|
43566 | return a - b;
|
43567 | });
|
43568 |
|
43569 | tree.remove(potentialMatchingFeature);
|
43570 | features.splice(matchFeaturePosition, 1);
|
43571 | polygon$$1.properties.origIndexPosition = i;
|
43572 | tree.remove(polygon$$1, function (a, b) {
|
43573 | return a.properties.origIndexPosition === b.properties.origIndexPosition;
|
43574 | });
|
43575 | featureChanged = true;
|
43576 | });
|
43577 |
|
43578 | if (featureChanged) {
|
43579 | if (!polygon$$1) continue;
|
43580 | polygon$$1.properties.origIndexPosition = i;
|
43581 | tree.insert(polygon$$1);
|
43582 | i--;
|
43583 | }
|
43584 | }
|
43585 |
|
43586 | features.forEach(function (f) {
|
43587 | delete f.properties.origIndexPosition;
|
43588 | delete f.bbox;
|
43589 | });
|
43590 |
|
43591 | return fc;
|
43592 | }
|
43593 |
|
43594 | function ringsIntersect(poly1, poly2) {
|
43595 | var line1 = lineString(coordAll(poly1));
|
43596 | var line2 = lineString(coordAll(poly2));
|
43597 | var points$$1 = lineIntersect(line1, line2).features;
|
43598 | return points$$1.length > 0;
|
43599 | }
|
43600 |
|
43601 |
|
43602 |
|
43603 |
|
43604 |
|
43605 |
|
43606 |
|
43607 |
|
43608 |
|
43609 |
|
43610 |
|
43611 |
|
43612 |
|
43613 |
|
43614 |
|
43615 |
|
43616 |
|
43617 |
|
43618 |
|
43619 |
|
43620 |
|
43621 |
|
43622 |
|
43623 |
|
43624 |
|
43625 |
|
43626 | function hexGrid(bbox, cellSide, options) {
|
43627 |
|
43628 | options = options || {};
|
43629 | if (!isObject(options)) throw new Error('options is invalid');
|
43630 |
|
43631 | var properties = options.properties || {};
|
43632 | var triangles = options.triangles;
|
43633 | var mask = options.mask;
|
43634 |
|
43635 |
|
43636 | if (cellSide === null || cellSide === undefined) throw new Error('cellSide is required');
|
43637 | if (!isNumber(cellSide)) throw new Error('cellSide is invalid');
|
43638 | if (!bbox) throw new Error('bbox is required');
|
43639 | if (!Array.isArray(bbox)) throw new Error('bbox must be array');
|
43640 | if (bbox.length !== 4) throw new Error('bbox must contain 4 numbers');
|
43641 | if (mask && ['Polygon', 'MultiPolygon'].indexOf(getType(mask)) === -1) throw new Error('options.mask must be a (Multi)Polygon');
|
43642 |
|
43643 | var west = bbox[0];
|
43644 | var south = bbox[1];
|
43645 | var east = bbox[2];
|
43646 | var north = bbox[3];
|
43647 | var centerY = (south + north) / 2;
|
43648 | var centerX = (west + east) / 2;
|
43649 |
|
43650 |
|
43651 | var xFraction = cellSide * 2 / (distance([west, centerY], [east, centerY], options));
|
43652 | var cellWidth = xFraction * (east - west);
|
43653 | var yFraction = cellSide * 2 / (distance([centerX, south], [centerX, north], options));
|
43654 | var cellHeight = yFraction * (north - south);
|
43655 | var radius = cellWidth / 2;
|
43656 |
|
43657 | var hex_width = radius * 2;
|
43658 | var hex_height = Math.sqrt(3) / 2 * cellHeight;
|
43659 |
|
43660 | var box_width = east - west;
|
43661 | var box_height = north - south;
|
43662 |
|
43663 | var x_interval = 3 / 4 * hex_width;
|
43664 | var y_interval = hex_height;
|
43665 |
|
43666 |
|
43667 | var x_span = (box_width - hex_width) / (hex_width - radius / 2);
|
43668 | var x_count = Math.floor(x_span);
|
43669 |
|
43670 | var x_adjust = ((x_count * x_interval - radius / 2) - box_width) / 2 - radius / 2 + x_interval / 2;
|
43671 |
|
43672 |
|
43673 | var y_count = Math.floor((box_height - hex_height) / hex_height);
|
43674 |
|
43675 | var y_adjust = (box_height - y_count * hex_height) / 2;
|
43676 |
|
43677 | var hasOffsetY = y_count * hex_height - box_height > hex_height / 2;
|
43678 | if (hasOffsetY) {
|
43679 | y_adjust -= hex_height / 4;
|
43680 | }
|
43681 |
|
43682 |
|
43683 | var cosines = [];
|
43684 | var sines = [];
|
43685 | for (var i = 0; i < 6; i++) {
|
43686 | var angle = 2 * Math.PI / 6 * i;
|
43687 | cosines.push(Math.cos(angle));
|
43688 | sines.push(Math.sin(angle));
|
43689 | }
|
43690 |
|
43691 | var results = [];
|
43692 | for (var x = 0; x <= x_count; x++) {
|
43693 | for (var y = 0; y <= y_count; y++) {
|
43694 |
|
43695 | var isOdd = x % 2 === 1;
|
43696 | if (y === 0 && isOdd) continue;
|
43697 | if (y === 0 && hasOffsetY) continue;
|
43698 |
|
43699 | var center_x = x * x_interval + west - x_adjust;
|
43700 | var center_y = y * y_interval + south + y_adjust;
|
43701 |
|
43702 | if (isOdd) {
|
43703 | center_y -= hex_height / 2;
|
43704 | }
|
43705 |
|
43706 | if (triangles === true) {
|
43707 | hexTriangles(
|
43708 | [center_x, center_y],
|
43709 | cellWidth / 2,
|
43710 | cellHeight / 2,
|
43711 | properties,
|
43712 | cosines,
|
43713 | sines).forEach(function (triangle) {
|
43714 | if (mask) {
|
43715 | if (intersect$2(mask, triangle)) results.push(triangle);
|
43716 | } else {
|
43717 | results.push(triangle);
|
43718 | }
|
43719 | });
|
43720 | } else {
|
43721 | var hex = hexagon(
|
43722 | [center_x, center_y],
|
43723 | cellWidth / 2,
|
43724 | cellHeight / 2,
|
43725 | properties,
|
43726 | cosines,
|
43727 | sines
|
43728 | );
|
43729 | if (mask) {
|
43730 | if (intersect$2(mask, hex)) results.push(hex);
|
43731 | } else {
|
43732 | results.push(hex);
|
43733 | }
|
43734 | }
|
43735 | }
|
43736 | }
|
43737 |
|
43738 | return featureCollection(results);
|
43739 | }
|
43740 |
|
43741 |
|
43742 |
|
43743 |
|
43744 |
|
43745 |
|
43746 |
|
43747 |
|
43748 |
|
43749 |
|
43750 |
|
43751 |
|
43752 |
|
43753 | function hexagon(center, rx, ry, properties, cosines, sines) {
|
43754 | var vertices = [];
|
43755 | for (var i = 0; i < 6; i++) {
|
43756 | var x = center[0] + rx * cosines[i];
|
43757 | var y = center[1] + ry * sines[i];
|
43758 | vertices.push([x, y]);
|
43759 | }
|
43760 |
|
43761 | vertices.push(vertices[0].slice());
|
43762 | return polygon([vertices], properties);
|
43763 | }
|
43764 |
|
43765 |
|
43766 |
|
43767 |
|
43768 |
|
43769 |
|
43770 |
|
43771 |
|
43772 |
|
43773 |
|
43774 |
|
43775 |
|
43776 |
|
43777 | function hexTriangles(center, rx, ry, properties, cosines, sines) {
|
43778 | var triangles = [];
|
43779 | for (var i = 0; i < 6; i++) {
|
43780 | var vertices = [];
|
43781 | vertices.push(center);
|
43782 | vertices.push([
|
43783 | center[0] + rx * cosines[i],
|
43784 | center[1] + ry * sines[i]
|
43785 | ]);
|
43786 | vertices.push([
|
43787 | center[0] + rx * cosines[(i + 1) % 6],
|
43788 | center[1] + ry * sines[(i + 1) % 6]
|
43789 | ]);
|
43790 | vertices.push(center);
|
43791 | triangles.push(polygon([vertices], properties));
|
43792 | }
|
43793 | return triangles;
|
43794 | }
|
43795 |
|
43796 |
|
43797 |
|
43798 |
|
43799 |
|
43800 |
|
43801 |
|
43802 |
|
43803 |
|
43804 |
|
43805 |
|
43806 |
|
43807 |
|
43808 |
|
43809 |
|
43810 |
|
43811 |
|
43812 | function mask(polygon$$1, mask) {
|
43813 |
|
43814 | var maskPolygon = createMask(mask);
|
43815 |
|
43816 |
|
43817 | var separated = separatePolygons(polygon$$1);
|
43818 | var polygonOuters = separated[0];
|
43819 | var polygonInners = separated[1];
|
43820 |
|
43821 |
|
43822 | polygonOuters = unionPolygons(polygonOuters);
|
43823 | polygonInners = unionPolygons(polygonInners);
|
43824 |
|
43825 |
|
43826 | var masked = buildMask(maskPolygon, polygonOuters, polygonInners);
|
43827 | return masked;
|
43828 | }
|
43829 |
|
43830 |
|
43831 |
|
43832 |
|
43833 |
|
43834 |
|
43835 |
|
43836 |
|
43837 |
|
43838 |
|
43839 | function buildMask(maskPolygon, polygonOuters, polygonInners) {
|
43840 | var coordinates = [];
|
43841 | coordinates.push(maskPolygon.geometry.coordinates[0]);
|
43842 |
|
43843 | flattenEach(polygonOuters, function (feature$$1) {
|
43844 | coordinates.push(feature$$1.geometry.coordinates[0]);
|
43845 | });
|
43846 |
|
43847 | flattenEach(polygonInners, function (feature$$1) {
|
43848 | coordinates.push(feature$$1.geometry.coordinates[0]);
|
43849 | });
|
43850 | return polygon(coordinates);
|
43851 | }
|
43852 |
|
43853 |
|
43854 |
|
43855 |
|
43856 |
|
43857 |
|
43858 |
|
43859 |
|
43860 | function separatePolygons(poly) {
|
43861 | var outers = [];
|
43862 | var inners = [];
|
43863 | flattenEach(poly, function (feature$$1) {
|
43864 | var coordinates = feature$$1.geometry.coordinates;
|
43865 | var featureOuter = coordinates[0];
|
43866 | var featureInner = coordinates.slice(1);
|
43867 | outers.push(polygon([featureOuter]));
|
43868 | featureInner.forEach(function (inner) {
|
43869 | inners.push(polygon([inner]));
|
43870 | });
|
43871 | });
|
43872 | return [featureCollection(outers), featureCollection(inners)];
|
43873 | }
|
43874 |
|
43875 |
|
43876 |
|
43877 |
|
43878 |
|
43879 |
|
43880 |
|
43881 |
|
43882 | function createMask(mask) {
|
43883 | var world = [[[180, 90], [-180, 90], [-180, -90], [180, -90], [180, 90]]];
|
43884 | var coordinates = mask && mask.geometry.coordinates || world;
|
43885 | return polygon(coordinates);
|
43886 | }
|
43887 |
|
43888 |
|
43889 |
|
43890 |
|
43891 |
|
43892 |
|
43893 |
|
43894 |
|
43895 | function unionPolygons(polygons$$1) {
|
43896 | if (polygons$$1.features.length <= 1) return polygons$$1;
|
43897 |
|
43898 | var tree = createIndex(polygons$$1);
|
43899 | var results = [];
|
43900 | var removed = {};
|
43901 |
|
43902 | flattenEach(polygons$$1, function (currentFeature, currentIndex) {
|
43903 |
|
43904 | if (removed[currentIndex]) return true;
|
43905 |
|
43906 |
|
43907 | tree.remove({index: currentIndex}, filterByIndex);
|
43908 | removed[currentIndex] = true;
|
43909 |
|
43910 |
|
43911 | while (true) {
|
43912 | var bbox$$1 = bbox(currentFeature);
|
43913 | var search = tree.search({
|
43914 | minX: bbox$$1[0],
|
43915 | minY: bbox$$1[1],
|
43916 | maxX: bbox$$1[2],
|
43917 | maxY: bbox$$1[3]
|
43918 | });
|
43919 | if (search.length > 0) {
|
43920 | var polys = search.map(function (item) {
|
43921 | removed[item.index] = true;
|
43922 | tree.remove({index: item.index}, filterByIndex);
|
43923 | return item.geojson;
|
43924 | });
|
43925 | polys.push(currentFeature);
|
43926 | currentFeature = union.apply(this, polys);
|
43927 | }
|
43928 |
|
43929 | if (search.length === 0) break;
|
43930 | }
|
43931 | results.push(currentFeature);
|
43932 | });
|
43933 |
|
43934 | return featureCollection(results);
|
43935 | }
|
43936 |
|
43937 |
|
43938 |
|
43939 |
|
43940 |
|
43941 |
|
43942 |
|
43943 |
|
43944 |
|
43945 | function filterByIndex(a, b) {
|
43946 | return a.index === b.index;
|
43947 | }
|
43948 |
|
43949 |
|
43950 |
|
43951 |
|
43952 |
|
43953 |
|
43954 |
|
43955 |
|
43956 | function createIndex(features) {
|
43957 | var tree = rbush_1();
|
43958 | var load = [];
|
43959 | flattenEach(features, function (feature$$1, index) {
|
43960 | var bbox$$1 = bbox(feature$$1);
|
43961 | load.push({
|
43962 | minX: bbox$$1[0],
|
43963 | minY: bbox$$1[1],
|
43964 | maxX: bbox$$1[2],
|
43965 | maxY: bbox$$1[3],
|
43966 | geojson: feature$$1,
|
43967 | index: index
|
43968 | });
|
43969 | });
|
43970 | tree.load(load);
|
43971 | return tree;
|
43972 | }
|
43973 |
|
43974 |
|
43975 |
|
43976 |
|
43977 |
|
43978 |
|
43979 |
|
43980 |
|
43981 |
|
43982 |
|
43983 |
|
43984 |
|
43985 |
|
43986 |
|
43987 |
|
43988 |
|
43989 |
|
43990 |
|
43991 |
|
43992 |
|
43993 |
|
43994 |
|
43995 | function squareGrid(bbox, cellSide, options) {
|
43996 |
|
43997 | options = options || {};
|
43998 | if (!isObject(options)) throw new Error('options is invalid');
|
43999 |
|
44000 | var properties = options.properties;
|
44001 | var mask = options.mask;
|
44002 |
|
44003 |
|
44004 | var results = [];
|
44005 |
|
44006 |
|
44007 | if (cellSide === null || cellSide === undefined) throw new Error('cellSide is required');
|
44008 | if (!isNumber(cellSide)) throw new Error('cellSide is invalid');
|
44009 | if (!bbox) throw new Error('bbox is required');
|
44010 | if (!Array.isArray(bbox)) throw new Error('bbox must be array');
|
44011 | if (bbox.length !== 4) throw new Error('bbox must contain 4 numbers');
|
44012 | if (mask && ['Polygon', 'MultiPolygon'].indexOf(getType(mask)) === -1) throw new Error('options.mask must be a (Multi)Polygon');
|
44013 |
|
44014 | var west = bbox[0];
|
44015 | var south = bbox[1];
|
44016 | var east = bbox[2];
|
44017 | var north = bbox[3];
|
44018 |
|
44019 | var xFraction = cellSide / (distance([west, south], [east, south], options));
|
44020 | var cellWidth = xFraction * (east - west);
|
44021 | var yFraction = cellSide / (distance([west, south], [west, north], options));
|
44022 | var cellHeight = yFraction * (north - south);
|
44023 |
|
44024 |
|
44025 | var bboxWidth = (east - west);
|
44026 | var bboxHeight = (north - south);
|
44027 | var columns = Math.floor(bboxWidth / cellWidth);
|
44028 | var rows = Math.floor(bboxHeight / cellHeight);
|
44029 |
|
44030 |
|
44031 | var deltaX = (bboxWidth - columns * cellWidth) / 2;
|
44032 | var deltaY = (bboxHeight - rows * cellHeight) / 2;
|
44033 |
|
44034 |
|
44035 | var currentX = west + deltaX;
|
44036 | for (var column = 0; column < columns; column++) {
|
44037 | var currentY = south + deltaY;
|
44038 | for (var row = 0; row < rows; row++) {
|
44039 | var cellPoly = polygon([[
|
44040 | [currentX, currentY],
|
44041 | [currentX, currentY + cellHeight],
|
44042 | [currentX + cellWidth, currentY + cellHeight],
|
44043 | [currentX + cellWidth, currentY],
|
44044 | [currentX, currentY]
|
44045 | ]], properties);
|
44046 | if (mask) {
|
44047 | if (intersect$2(mask, cellPoly)) results.push(cellPoly);
|
44048 | } else {
|
44049 | results.push(cellPoly);
|
44050 | }
|
44051 |
|
44052 | currentY += cellHeight;
|
44053 | }
|
44054 | currentX += cellWidth;
|
44055 | }
|
44056 | return featureCollection(results);
|
44057 | }
|
44058 |
|
44059 |
|
44060 |
|
44061 |
|
44062 |
|
44063 |
|
44064 |
|
44065 |
|
44066 |
|
44067 |
|
44068 |
|
44069 |
|
44070 |
|
44071 |
|
44072 |
|
44073 |
|
44074 |
|
44075 |
|
44076 |
|
44077 |
|
44078 |
|
44079 |
|
44080 | function triangleGrid(bbox, cellSide, options) {
|
44081 |
|
44082 | options = options || {};
|
44083 | if (!isObject(options)) throw new Error('options is invalid');
|
44084 |
|
44085 | var properties = options.properties;
|
44086 | var mask = options.mask;
|
44087 |
|
44088 |
|
44089 | var results = [];
|
44090 |
|
44091 |
|
44092 | if (cellSide === null || cellSide === undefined) throw new Error('cellSide is required');
|
44093 | if (!isNumber(cellSide)) throw new Error('cellSide is invalid');
|
44094 | if (!bbox) throw new Error('bbox is required');
|
44095 | if (!Array.isArray(bbox)) throw new Error('bbox must be array');
|
44096 | if (bbox.length !== 4) throw new Error('bbox must contain 4 numbers');
|
44097 | if (mask && ['Polygon', 'MultiPolygon'].indexOf(getType(mask)) === -1) throw new Error('options.mask must be a (Multi)Polygon');
|
44098 |
|
44099 |
|
44100 | var xFraction = cellSide / (distance([bbox[0], bbox[1]], [bbox[2], bbox[1]], options));
|
44101 | var cellWidth = xFraction * (bbox[2] - bbox[0]);
|
44102 | var yFraction = cellSide / (distance([bbox[0], bbox[1]], [bbox[0], bbox[3]], options));
|
44103 | var cellHeight = yFraction * (bbox[3] - bbox[1]);
|
44104 |
|
44105 | var xi = 0;
|
44106 | var currentX = bbox[0];
|
44107 | while (currentX <= bbox[2]) {
|
44108 | var yi = 0;
|
44109 | var currentY = bbox[1];
|
44110 | while (currentY <= bbox[3]) {
|
44111 | var cellTriangle1 = null;
|
44112 | var cellTriangle2 = null;
|
44113 |
|
44114 | if (xi % 2 === 0 && yi % 2 === 0) {
|
44115 | cellTriangle1 = polygon([[
|
44116 | [currentX, currentY],
|
44117 | [currentX, currentY + cellHeight],
|
44118 | [currentX + cellWidth, currentY],
|
44119 | [currentX, currentY]
|
44120 | ]], properties);
|
44121 | cellTriangle2 = polygon([[
|
44122 | [currentX, currentY + cellHeight],
|
44123 | [currentX + cellWidth, currentY + cellHeight],
|
44124 | [currentX + cellWidth, currentY],
|
44125 | [currentX, currentY + cellHeight]
|
44126 | ]], properties);
|
44127 | } else if (xi % 2 === 0 && yi % 2 === 1) {
|
44128 | cellTriangle1 = polygon([[
|
44129 | [currentX, currentY],
|
44130 | [currentX + cellWidth, currentY + cellHeight],
|
44131 | [currentX + cellWidth, currentY],
|
44132 | [currentX, currentY]
|
44133 | ]], properties);
|
44134 | cellTriangle2 = polygon([[
|
44135 | [currentX, currentY],
|
44136 | [currentX, currentY + cellHeight],
|
44137 | [currentX + cellWidth, currentY + cellHeight],
|
44138 | [currentX, currentY]
|
44139 | ]], properties);
|
44140 | } else if (yi % 2 === 0 && xi % 2 === 1) {
|
44141 | cellTriangle1 = polygon([[
|
44142 | [currentX, currentY],
|
44143 | [currentX, currentY + cellHeight],
|
44144 | [currentX + cellWidth, currentY + cellHeight],
|
44145 | [currentX, currentY]
|
44146 | ]], properties);
|
44147 | cellTriangle2 = polygon([[
|
44148 | [currentX, currentY],
|
44149 | [currentX + cellWidth, currentY + cellHeight],
|
44150 | [currentX + cellWidth, currentY],
|
44151 | [currentX, currentY]
|
44152 | ]], properties);
|
44153 | } else if (yi % 2 === 1 && xi % 2 === 1) {
|
44154 | cellTriangle1 = polygon([[
|
44155 | [currentX, currentY],
|
44156 | [currentX, currentY + cellHeight],
|
44157 | [currentX + cellWidth, currentY],
|
44158 | [currentX, currentY]
|
44159 | ]], properties);
|
44160 | cellTriangle2 = polygon([[
|
44161 | [currentX, currentY + cellHeight],
|
44162 | [currentX + cellWidth, currentY + cellHeight],
|
44163 | [currentX + cellWidth, currentY],
|
44164 | [currentX, currentY + cellHeight]
|
44165 | ]], properties);
|
44166 | }
|
44167 | if (mask) {
|
44168 | if (intersect$2(mask, cellTriangle1)) results.push(cellTriangle1);
|
44169 | if (intersect$2(mask, cellTriangle2)) results.push(cellTriangle2);
|
44170 | } else {
|
44171 | results.push(cellTriangle1);
|
44172 | results.push(cellTriangle2);
|
44173 | }
|
44174 |
|
44175 | currentY += cellHeight;
|
44176 | yi++;
|
44177 | }
|
44178 | xi++;
|
44179 | currentX += cellWidth;
|
44180 | }
|
44181 | return featureCollection(results);
|
44182 | }
|
44183 |
|
44184 |
|
44185 |
|
44186 |
|
44187 |
|
44188 |
|
44189 |
|
44190 |
|
44191 |
|
44192 |
|
44193 |
|
44194 |
|
44195 |
|
44196 |
|
44197 |
|
44198 |
|
44199 |
|
44200 |
|
44201 |
|
44202 |
|
44203 |
|
44204 |
|
44205 |
|
44206 |
|
44207 |
|
44208 |
|
44209 | function interpolate$1(points$$1, cellSize, options) {
|
44210 |
|
44211 | options = options || {};
|
44212 | if (typeof options !== 'object') throw new Error('options is invalid');
|
44213 | var gridType = options.gridType;
|
44214 | var property = options.property;
|
44215 | var weight = options.weight;
|
44216 |
|
44217 |
|
44218 | if (!points$$1) throw new Error('points is required');
|
44219 | collectionOf(points$$1, 'Point', 'input must contain Points');
|
44220 | if (!cellSize) throw new Error('cellSize is required');
|
44221 | if (weight !== undefined && typeof weight !== 'number') throw new Error('weight must be a number');
|
44222 |
|
44223 |
|
44224 | property = property || 'elevation';
|
44225 | gridType = gridType || 'square';
|
44226 | weight = weight || 1;
|
44227 |
|
44228 | var box = bbox(points$$1);
|
44229 | var grid;
|
44230 | switch (gridType) {
|
44231 | case 'point':
|
44232 | case 'points':
|
44233 | grid = pointGrid(box, cellSize, options);
|
44234 | break;
|
44235 | case 'square':
|
44236 | case 'squares':
|
44237 | grid = squareGrid(box, cellSize, options);
|
44238 | break;
|
44239 | case 'hex':
|
44240 | case 'hexes':
|
44241 | grid = hexGrid(box, cellSize, options);
|
44242 | break;
|
44243 | case 'triangle':
|
44244 | case 'triangles':
|
44245 | grid = triangleGrid(box, cellSize, options);
|
44246 | break;
|
44247 | default:
|
44248 | throw new Error('invalid gridType');
|
44249 | }
|
44250 | var results = [];
|
44251 | featureEach(grid, function (gridFeature) {
|
44252 | var zw = 0;
|
44253 | var sw = 0;
|
44254 |
|
44255 | featureEach(points$$1, function (point$$1) {
|
44256 | var gridPoint = (gridType === 'point') ? gridFeature : centroid(gridFeature);
|
44257 | var d = distance(gridPoint, point$$1, options);
|
44258 | var zValue;
|
44259 |
|
44260 | if (property !== undefined) zValue = point$$1.properties[property];
|
44261 | if (zValue === undefined) zValue = point$$1.geometry.coordinates[2];
|
44262 | if (zValue === undefined) throw new Error('zValue is missing');
|
44263 | if (d === 0) zw = zValue;
|
44264 | var w = 1.0 / Math.pow(d, weight);
|
44265 | sw += w;
|
44266 | zw += w * zValue;
|
44267 | });
|
44268 |
|
44269 | var newFeature = clone(gridFeature);
|
44270 | newFeature.properties[property] = zw / sw;
|
44271 | results.push(newFeature);
|
44272 | });
|
44273 | return featureCollection(results);
|
44274 | }
|
44275 |
|
44276 |
|
44277 |
|
44278 |
|
44279 |
|
44280 |
|
44281 |
|
44282 |
|
44283 |
|
44284 | export { main_es$3 as projection, main_es$4 as random, main_es$5 as clusters, main_es$1 as helpers, main_es$2 as invariant, main_es as meta, isolines, convex, pointsWithinPolygon, concave, collect, flip, simplify, bezier as bezierSpline, tag, sample, envelope, square, circle, midpoint, center, centerOfMass, centroid, combine, distance, explode, bbox, tesselate, bboxPolygon, booleanPointInPolygon, nearestPoint, nearestPointOnLine, nearestPointToLine, planepoint, tin, bearing, destination, kinks, pointOnFeature, area$1 as area, along, length, lineSlice, lineSliceAlong, pointGrid, truncate, flatten, lineIntersect, lineChunk, unkinkPolygon, greatCircle, lineSegment, lineSplit, lineArc, polygonToLine, lineToPolygon, bboxClip, lineOverlap, sector, rhumbBearing, rhumbDistance, rhumbDestination, polygonTangents, rewind, isobands, transformRotate, transformScale, transformTranslate, lineOffset, polygonize$1 as polygonize, booleanDisjoint, booleanContains, booleanCrosses, booleanClockwise, booleanOverlap, booleanPointOnLine, booleanEqual, booleanWithin, clone, cleanCoords, clustersDbscan, clustersKmeans, pointToLineDistance, booleanParallel, shortestPath, voronoi$1 as voronoi, ellipse, centerMean, centerMedian, standardDeviationalEllipse, difference, buffer$1 as buffer, union, intersect$2 as intersect, dissolve$1 as dissolve, hexGrid, mask, squareGrid, triangleGrid, interpolate$1 as interpolate, pointOnFeature as pointOnSurface, polygonToLine as polygonToLineString, lineToPolygon as lineStringToPolygon, booleanPointInPolygon as inside, pointsWithinPolygon as within, bezier, nearestPoint as nearest, nearestPointOnLine as pointOnLine, length as lineDistance, radiansToDegrees as radians2degrees, degreesToRadians as degrees2radians, lengthToDegrees as distanceToDegrees, lengthToRadians as distanceToRadians, radiansToLength as radiansToDistance, bearingToAzimuth as bearingToAngle, convertLength as convertDistance, toMercator, toWgs84, randomPosition, randomPoint, randomPolygon, randomLineString, getCluster, clusterEach, clusterReduce, createBins, applyFilter, propertiesContainsFilter, filterProperties, earthRadius, factors, unitsFactors, areaFactors, feature, geometry, point, points, polygon, polygons, lineString, lineStrings, featureCollection, multiLineString, multiPoint, multiPolygon, geometryCollection, round, radiansToLength, lengthToRadians, lengthToDegrees, bearingToAzimuth, radiansToDegrees, degreesToRadians, convertLength, convertArea, isNumber, isObject, validateBBox, validateId, getCoord, getCoords, containsNumber, geojsonType, featureOf, collectionOf, getGeom, getGeomType, getType, coordEach, coordReduce, propEach, propReduce, featureEach, featureReduce, coordAll, geomEach, geomReduce, flattenEach, flattenReduce, segmentEach, segmentReduce, lineEach, lineReduce };
|