node-red-contrib-tak-registration 0.13.0 → 0.14.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/node_modules/@turf/along/README.md +3 -5
- package/node_modules/@turf/along/dist/cjs/index.cjs.map +1 -1
- package/node_modules/@turf/along/dist/cjs/index.d.cts +3 -3
- package/node_modules/@turf/along/dist/esm/index.d.ts +3 -3
- package/node_modules/@turf/along/dist/esm/index.js.map +1 -1
- package/node_modules/@turf/along/package.json +13 -13
- package/node_modules/@turf/angle/dist/cjs/index.cjs +10 -7
- package/node_modules/@turf/angle/dist/cjs/index.cjs.map +1 -1
- package/node_modules/@turf/angle/dist/cjs/index.d.cts +1 -1
- package/node_modules/@turf/angle/dist/esm/index.d.ts +1 -1
- package/node_modules/@turf/angle/dist/esm/index.js +10 -7
- package/node_modules/@turf/angle/dist/esm/index.js.map +1 -1
- package/node_modules/@turf/angle/package.json +15 -15
- package/node_modules/@turf/area/dist/cjs/index.cjs +1 -2
- package/node_modules/@turf/area/dist/cjs/index.cjs.map +1 -1
- package/node_modules/@turf/area/dist/cjs/index.d.cts +1 -1
- package/node_modules/@turf/area/dist/esm/index.d.ts +1 -1
- package/node_modules/@turf/area/dist/esm/index.js +1 -2
- package/node_modules/@turf/area/dist/esm/index.js.map +1 -1
- package/node_modules/@turf/area/package.json +10 -10
- package/node_modules/@turf/bbox/dist/cjs/index.cjs.map +1 -1
- package/node_modules/@turf/bbox/dist/cjs/index.d.cts +1 -1
- package/node_modules/@turf/bbox/dist/esm/index.d.ts +1 -1
- package/node_modules/@turf/bbox/dist/esm/index.js.map +1 -1
- package/node_modules/@turf/bbox/package.json +10 -10
- package/node_modules/@turf/bbox-clip/dist/cjs/index.cjs +9 -18
- package/node_modules/@turf/bbox-clip/dist/cjs/index.cjs.map +1 -1
- package/node_modules/@turf/bbox-clip/dist/cjs/index.d.cts +1 -1
- package/node_modules/@turf/bbox-clip/dist/esm/index.d.ts +1 -1
- package/node_modules/@turf/bbox-clip/dist/esm/index.js +9 -18
- package/node_modules/@turf/bbox-clip/dist/esm/index.js.map +1 -1
- package/node_modules/@turf/bbox-clip/package.json +11 -11
- package/node_modules/@turf/bbox-polygon/README.md +6 -6
- package/node_modules/@turf/bbox-polygon/dist/cjs/index.cjs.map +1 -1
- package/node_modules/@turf/bbox-polygon/dist/cjs/index.d.cts +2 -2
- package/node_modules/@turf/bbox-polygon/dist/esm/index.d.ts +2 -2
- package/node_modules/@turf/bbox-polygon/dist/esm/index.js.map +1 -1
- package/node_modules/@turf/bbox-polygon/package.json +9 -9
- package/node_modules/@turf/bearing/dist/cjs/index.cjs.map +1 -1
- package/node_modules/@turf/bearing/dist/cjs/index.d.cts +1 -1
- package/node_modules/@turf/bearing/dist/esm/index.d.ts +1 -1
- package/node_modules/@turf/bearing/dist/esm/index.js.map +1 -1
- package/node_modules/@turf/bearing/package.json +11 -11
- package/node_modules/@turf/bezier-spline/dist/cjs/index.cjs.map +1 -1
- package/node_modules/@turf/bezier-spline/dist/cjs/index.d.cts +1 -1
- package/node_modules/@turf/bezier-spline/dist/esm/index.d.ts +1 -1
- package/node_modules/@turf/bezier-spline/dist/esm/index.js.map +1 -1
- package/node_modules/@turf/bezier-spline/package.json +10 -10
- package/node_modules/@turf/boolean-clockwise/dist/cjs/index.cjs.map +1 -1
- package/node_modules/@turf/boolean-clockwise/dist/cjs/index.d.cts +1 -1
- package/node_modules/@turf/boolean-clockwise/dist/esm/index.d.ts +1 -1
- package/node_modules/@turf/boolean-clockwise/dist/esm/index.js.map +1 -1
- package/node_modules/@turf/boolean-clockwise/package.json +10 -10
- package/node_modules/@turf/boolean-concave/dist/cjs/index.cjs.map +1 -1
- package/node_modules/@turf/boolean-concave/dist/cjs/index.d.cts +1 -1
- package/node_modules/@turf/boolean-concave/dist/esm/index.d.ts +1 -1
- package/node_modules/@turf/boolean-concave/dist/esm/index.js.map +1 -1
- package/node_modules/@turf/boolean-concave/package.json +10 -10
- package/node_modules/@turf/boolean-contains/dist/cjs/index.cjs.map +1 -1
- package/node_modules/@turf/boolean-contains/dist/cjs/index.d.cts +1 -1
- package/node_modules/@turf/boolean-contains/dist/esm/index.d.ts +1 -1
- package/node_modules/@turf/boolean-contains/dist/esm/index.js.map +1 -1
- package/node_modules/@turf/boolean-contains/package.json +13 -13
- package/node_modules/@turf/boolean-crosses/dist/cjs/index.cjs.map +1 -1
- package/node_modules/@turf/boolean-crosses/dist/cjs/index.d.cts +1 -1
- package/node_modules/@turf/boolean-crosses/dist/esm/index.d.ts +1 -1
- package/node_modules/@turf/boolean-crosses/dist/esm/index.js.map +1 -1
- package/node_modules/@turf/boolean-crosses/package.json +13 -13
- package/node_modules/@turf/boolean-disjoint/README.md +1 -1
- package/node_modules/@turf/boolean-disjoint/dist/cjs/index.cjs +3 -3
- package/node_modules/@turf/boolean-disjoint/dist/cjs/index.cjs.map +1 -1
- package/node_modules/@turf/boolean-disjoint/dist/cjs/index.d.cts +3 -3
- package/node_modules/@turf/boolean-disjoint/dist/esm/index.d.ts +3 -3
- package/node_modules/@turf/boolean-disjoint/dist/esm/index.js +3 -3
- package/node_modules/@turf/boolean-disjoint/dist/esm/index.js.map +1 -1
- package/node_modules/@turf/boolean-disjoint/package.json +13 -13
- package/node_modules/@turf/boolean-equal/dist/cjs/index.cjs +1 -2
- package/node_modules/@turf/boolean-equal/dist/cjs/index.cjs.map +1 -1
- package/node_modules/@turf/boolean-equal/dist/cjs/index.d.cts +1 -1
- package/node_modules/@turf/boolean-equal/dist/esm/index.d.ts +1 -1
- package/node_modules/@turf/boolean-equal/dist/esm/index.js +1 -2
- package/node_modules/@turf/boolean-equal/dist/esm/index.js.map +1 -1
- package/node_modules/@turf/boolean-equal/package.json +11 -11
- package/node_modules/@turf/boolean-intersects/dist/cjs/index.cjs +3 -3
- package/node_modules/@turf/boolean-intersects/dist/cjs/index.cjs.map +1 -1
- package/node_modules/@turf/boolean-intersects/dist/cjs/index.d.cts +3 -3
- package/node_modules/@turf/boolean-intersects/dist/esm/index.d.ts +3 -3
- package/node_modules/@turf/boolean-intersects/dist/esm/index.js +3 -3
- package/node_modules/@turf/boolean-intersects/dist/esm/index.js.map +1 -1
- package/node_modules/@turf/boolean-intersects/package.json +11 -11
- package/node_modules/@turf/boolean-overlap/dist/cjs/index.cjs +3 -6
- package/node_modules/@turf/boolean-overlap/dist/cjs/index.cjs.map +1 -1
- package/node_modules/@turf/boolean-overlap/dist/cjs/index.d.cts +1 -1
- package/node_modules/@turf/boolean-overlap/dist/esm/index.d.ts +1 -1
- package/node_modules/@turf/boolean-overlap/dist/esm/index.js +3 -6
- package/node_modules/@turf/boolean-overlap/dist/esm/index.js.map +1 -1
- package/node_modules/@turf/boolean-overlap/package.json +13 -13
- package/node_modules/@turf/boolean-parallel/dist/cjs/index.cjs +7 -14
- package/node_modules/@turf/boolean-parallel/dist/cjs/index.cjs.map +1 -1
- package/node_modules/@turf/boolean-parallel/dist/cjs/index.d.cts +1 -1
- package/node_modules/@turf/boolean-parallel/dist/esm/index.d.ts +1 -1
- package/node_modules/@turf/boolean-parallel/dist/esm/index.js +7 -14
- package/node_modules/@turf/boolean-parallel/dist/esm/index.js.map +1 -1
- package/node_modules/@turf/boolean-parallel/package.json +12 -12
- package/node_modules/@turf/boolean-point-in-polygon/dist/cjs/index.cjs +2 -4
- package/node_modules/@turf/boolean-point-in-polygon/dist/cjs/index.cjs.map +1 -1
- package/node_modules/@turf/boolean-point-in-polygon/dist/cjs/index.d.cts +1 -1
- package/node_modules/@turf/boolean-point-in-polygon/dist/esm/index.d.ts +1 -1
- package/node_modules/@turf/boolean-point-in-polygon/dist/esm/index.js +2 -4
- package/node_modules/@turf/boolean-point-in-polygon/dist/esm/index.js.map +1 -1
- package/node_modules/@turf/boolean-point-in-polygon/package.json +10 -10
- package/node_modules/@turf/boolean-point-on-line/dist/cjs/index.cjs +10 -0
- package/node_modules/@turf/boolean-point-on-line/dist/cjs/index.cjs.map +1 -1
- package/node_modules/@turf/boolean-point-on-line/dist/cjs/index.d.cts +1 -1
- package/node_modules/@turf/boolean-point-on-line/dist/esm/index.d.ts +1 -1
- package/node_modules/@turf/boolean-point-on-line/dist/esm/index.js +10 -0
- package/node_modules/@turf/boolean-point-on-line/dist/esm/index.js.map +1 -1
- package/node_modules/@turf/boolean-point-on-line/package.json +10 -10
- package/node_modules/@turf/boolean-touches/dist/cjs/index.cjs +2 -4
- package/node_modules/@turf/boolean-touches/dist/cjs/index.cjs.map +1 -1
- package/node_modules/@turf/boolean-touches/dist/cjs/index.d.cts +2 -1
- package/node_modules/@turf/boolean-touches/dist/esm/index.d.ts +2 -1
- package/node_modules/@turf/boolean-touches/dist/esm/index.js +2 -4
- package/node_modules/@turf/boolean-touches/dist/esm/index.js.map +1 -1
- package/node_modules/@turf/boolean-touches/package.json +12 -12
- package/node_modules/@turf/boolean-valid/dist/cjs/index.cjs +14 -28
- package/node_modules/@turf/boolean-valid/dist/cjs/index.cjs.map +1 -1
- package/node_modules/@turf/boolean-valid/dist/cjs/index.d.cts +1 -1
- package/node_modules/@turf/boolean-valid/dist/esm/index.d.ts +1 -1
- package/node_modules/@turf/boolean-valid/dist/esm/index.js +14 -28
- package/node_modules/@turf/boolean-valid/dist/esm/index.js.map +1 -1
- package/node_modules/@turf/boolean-valid/package.json +17 -17
- package/node_modules/@turf/boolean-within/dist/cjs/index.cjs +4 -8
- package/node_modules/@turf/boolean-within/dist/cjs/index.cjs.map +1 -1
- package/node_modules/@turf/boolean-within/dist/cjs/index.d.cts +1 -1
- package/node_modules/@turf/boolean-within/dist/esm/index.d.ts +1 -1
- package/node_modules/@turf/boolean-within/dist/esm/index.js +4 -8
- package/node_modules/@turf/boolean-within/dist/esm/index.js.map +1 -1
- package/node_modules/@turf/boolean-within/package.json +13 -13
- package/node_modules/@turf/buffer/dist/cjs/index.cjs +12 -24
- package/node_modules/@turf/buffer/dist/cjs/index.cjs.map +1 -1
- package/node_modules/@turf/buffer/dist/esm/index.js +12 -24
- package/node_modules/@turf/buffer/dist/esm/index.js.map +1 -1
- package/node_modules/@turf/buffer/package.json +12 -12
- package/node_modules/@turf/center/dist/cjs/index.cjs.map +1 -1
- package/node_modules/@turf/center/dist/cjs/index.d.cts +1 -1
- package/node_modules/@turf/center/dist/esm/index.d.ts +1 -1
- package/node_modules/@turf/center/dist/esm/index.js.map +1 -1
- package/node_modules/@turf/center/package.json +12 -12
- package/node_modules/@turf/center-mean/dist/cjs/index.cjs.map +1 -1
- package/node_modules/@turf/center-mean/dist/cjs/index.d.cts +1 -1
- package/node_modules/@turf/center-mean/dist/esm/index.d.ts +1 -1
- package/node_modules/@turf/center-mean/dist/esm/index.js.map +1 -1
- package/node_modules/@turf/center-mean/package.json +13 -13
- package/node_modules/@turf/center-median/dist/cjs/index.cjs +5 -10
- package/node_modules/@turf/center-median/dist/cjs/index.cjs.map +1 -1
- package/node_modules/@turf/center-median/dist/cjs/index.d.cts +1 -1
- package/node_modules/@turf/center-median/dist/esm/index.d.ts +1 -1
- package/node_modules/@turf/center-median/dist/esm/index.js +5 -10
- package/node_modules/@turf/center-median/dist/esm/index.js.map +1 -1
- package/node_modules/@turf/center-median/package.json +17 -17
- package/node_modules/@turf/center-of-mass/dist/cjs/index.cjs +2 -4
- package/node_modules/@turf/center-of-mass/dist/cjs/index.cjs.map +1 -1
- package/node_modules/@turf/center-of-mass/dist/cjs/index.d.cts +1 -1
- package/node_modules/@turf/center-of-mass/dist/esm/index.d.ts +1 -1
- package/node_modules/@turf/center-of-mass/dist/esm/index.js +2 -4
- package/node_modules/@turf/center-of-mass/dist/esm/index.js.map +1 -1
- package/node_modules/@turf/center-of-mass/package.json +13 -13
- package/node_modules/@turf/centroid/dist/cjs/index.cjs.map +1 -1
- package/node_modules/@turf/centroid/dist/cjs/index.d.cts +1 -1
- package/node_modules/@turf/centroid/dist/esm/index.d.ts +1 -1
- package/node_modules/@turf/centroid/dist/esm/index.js.map +1 -1
- package/node_modules/@turf/centroid/package.json +10 -10
- package/node_modules/@turf/circle/dist/cjs/index.cjs.map +1 -1
- package/node_modules/@turf/circle/dist/cjs/index.d.cts +1 -1
- package/node_modules/@turf/circle/dist/esm/index.d.ts +1 -1
- package/node_modules/@turf/circle/dist/esm/index.js.map +1 -1
- package/node_modules/@turf/circle/package.json +11 -11
- package/node_modules/@turf/clean-coords/dist/cjs/index.cjs +4 -8
- package/node_modules/@turf/clean-coords/dist/cjs/index.cjs.map +1 -1
- package/node_modules/@turf/clean-coords/dist/cjs/index.d.cts +1 -1
- package/node_modules/@turf/clean-coords/dist/esm/index.d.ts +1 -1
- package/node_modules/@turf/clean-coords/dist/esm/index.js +4 -8
- package/node_modules/@turf/clean-coords/dist/esm/index.js.map +1 -1
- package/node_modules/@turf/clean-coords/package.json +11 -11
- package/node_modules/@turf/clone/dist/cjs/index.cjs.map +1 -1
- package/node_modules/@turf/clone/dist/cjs/index.d.cts +1 -1
- package/node_modules/@turf/clone/dist/esm/index.d.ts +1 -1
- package/node_modules/@turf/clone/dist/esm/index.js.map +1 -1
- package/node_modules/@turf/clone/package.json +10 -10
- package/node_modules/@turf/clusters/README.md +8 -2
- package/node_modules/@turf/clusters/dist/cjs/index.cjs +9 -18
- package/node_modules/@turf/clusters/dist/cjs/index.cjs.map +1 -1
- package/node_modules/@turf/clusters/dist/cjs/index.d.cts +9 -8
- package/node_modules/@turf/clusters/dist/esm/index.d.ts +9 -8
- package/node_modules/@turf/clusters/dist/esm/index.js +9 -18
- package/node_modules/@turf/clusters/dist/esm/index.js.map +1 -1
- package/node_modules/@turf/clusters/package.json +10 -10
- package/node_modules/@turf/clusters-dbscan/README.md +38 -15
- package/node_modules/@turf/clusters-dbscan/dist/cjs/index.cjs +2 -4
- package/node_modules/@turf/clusters-dbscan/dist/cjs/index.cjs.map +1 -1
- package/node_modules/@turf/clusters-dbscan/dist/cjs/index.d.cts +16 -3
- package/node_modules/@turf/clusters-dbscan/dist/esm/index.d.ts +16 -3
- package/node_modules/@turf/clusters-dbscan/dist/esm/index.js +2 -4
- package/node_modules/@turf/clusters-dbscan/dist/esm/index.js.map +1 -1
- package/node_modules/@turf/clusters-dbscan/package.json +14 -14
- package/node_modules/@turf/clusters-kmeans/dist/cjs/index.cjs +2 -4
- package/node_modules/@turf/clusters-kmeans/dist/cjs/index.cjs.map +1 -1
- package/node_modules/@turf/clusters-kmeans/dist/cjs/index.d.cts +1 -1
- package/node_modules/@turf/clusters-kmeans/dist/esm/index.d.ts +1 -1
- package/node_modules/@turf/clusters-kmeans/dist/esm/index.js +2 -4
- package/node_modules/@turf/clusters-kmeans/dist/esm/index.js.map +1 -1
- package/node_modules/@turf/clusters-kmeans/package.json +15 -15
- package/node_modules/@turf/collect/dist/cjs/index.cjs.map +1 -1
- package/node_modules/@turf/collect/dist/cjs/index.d.cts +1 -1
- package/node_modules/@turf/collect/dist/esm/index.d.ts +1 -1
- package/node_modules/@turf/collect/dist/esm/index.js.map +1 -1
- package/node_modules/@turf/collect/package.json +11 -11
- package/node_modules/@turf/combine/dist/cjs/index.cjs.map +1 -1
- package/node_modules/@turf/combine/dist/cjs/index.d.cts +1 -1
- package/node_modules/@turf/combine/dist/esm/index.d.ts +1 -1
- package/node_modules/@turf/combine/dist/esm/index.js.map +1 -1
- package/node_modules/@turf/combine/package.json +10 -10
- package/node_modules/@turf/concave/dist/cjs/index.cjs.map +1 -1
- package/node_modules/@turf/concave/dist/cjs/index.d.cts +1 -1
- package/node_modules/@turf/concave/dist/esm/index.d.ts +1 -1
- package/node_modules/@turf/concave/dist/esm/index.js.map +1 -1
- package/node_modules/@turf/concave/package.json +14 -14
- package/node_modules/@turf/convex/dist/cjs/index.cjs.map +1 -1
- package/node_modules/@turf/convex/dist/cjs/index.d.cts +1 -1
- package/node_modules/@turf/convex/dist/esm/index.d.ts +1 -1
- package/node_modules/@turf/convex/dist/esm/index.js.map +1 -1
- package/node_modules/@turf/convex/package.json +10 -10
- package/node_modules/@turf/destination/dist/cjs/index.cjs.map +1 -1
- package/node_modules/@turf/destination/dist/cjs/index.d.cts +1 -1
- package/node_modules/@turf/destination/dist/esm/index.d.ts +1 -1
- package/node_modules/@turf/destination/dist/esm/index.js.map +1 -1
- package/node_modules/@turf/destination/package.json +11 -11
- package/node_modules/@turf/difference/dist/cjs/index.cjs +8 -10
- package/node_modules/@turf/difference/dist/cjs/index.cjs.map +1 -1
- package/node_modules/@turf/difference/dist/cjs/index.d.cts +1 -1
- package/node_modules/@turf/difference/dist/esm/index.d.ts +1 -1
- package/node_modules/@turf/difference/dist/esm/index.js +7 -9
- package/node_modules/@turf/difference/dist/esm/index.js.map +1 -1
- package/node_modules/@turf/difference/package.json +11 -11
- package/node_modules/@turf/dissolve/README.md +11 -12
- package/node_modules/@turf/dissolve/dist/cjs/index.cjs +5 -6
- package/node_modules/@turf/dissolve/dist/cjs/index.cjs.map +1 -1
- package/node_modules/@turf/dissolve/dist/cjs/index.d.cts +3 -3
- package/node_modules/@turf/dissolve/dist/esm/index.d.ts +3 -3
- package/node_modules/@turf/dissolve/dist/esm/index.js +4 -5
- package/node_modules/@turf/dissolve/dist/esm/index.js.map +1 -1
- package/node_modules/@turf/dissolve/package.json +13 -13
- package/node_modules/@turf/distance/dist/cjs/index.cjs.map +1 -1
- package/node_modules/@turf/distance/dist/cjs/index.d.cts +1 -1
- package/node_modules/@turf/distance/dist/esm/index.d.ts +1 -1
- package/node_modules/@turf/distance/dist/esm/index.js.map +1 -1
- package/node_modules/@turf/distance/package.json +10 -10
- package/node_modules/@turf/distance-weight/dist/cjs/index.cjs.map +1 -1
- package/node_modules/@turf/distance-weight/dist/cjs/index.d.cts +3 -1
- package/node_modules/@turf/distance-weight/dist/esm/index.d.ts +3 -1
- package/node_modules/@turf/distance-weight/dist/esm/index.js.map +1 -1
- package/node_modules/@turf/distance-weight/package.json +12 -12
- package/node_modules/@turf/ellipse/dist/cjs/index.cjs +8 -16
- package/node_modules/@turf/ellipse/dist/cjs/index.cjs.map +1 -1
- package/node_modules/@turf/ellipse/dist/esm/index.js +8 -16
- package/node_modules/@turf/ellipse/dist/esm/index.js.map +1 -1
- package/node_modules/@turf/ellipse/package.json +16 -16
- package/node_modules/@turf/envelope/dist/cjs/index.cjs.map +1 -1
- package/node_modules/@turf/envelope/dist/cjs/index.d.cts +1 -1
- package/node_modules/@turf/envelope/dist/esm/index.d.ts +1 -1
- package/node_modules/@turf/envelope/dist/esm/index.js.map +1 -1
- package/node_modules/@turf/envelope/package.json +11 -11
- package/node_modules/@turf/explode/dist/cjs/index.cjs.map +1 -1
- package/node_modules/@turf/explode/dist/cjs/index.d.cts +1 -1
- package/node_modules/@turf/explode/dist/esm/index.d.ts +1 -1
- package/node_modules/@turf/explode/dist/esm/index.js.map +1 -1
- package/node_modules/@turf/explode/package.json +10 -10
- package/node_modules/@turf/flatten/dist/cjs/index.cjs +1 -2
- package/node_modules/@turf/flatten/dist/cjs/index.cjs.map +1 -1
- package/node_modules/@turf/flatten/dist/cjs/index.d.cts +1 -1
- package/node_modules/@turf/flatten/dist/esm/index.d.ts +1 -1
- package/node_modules/@turf/flatten/dist/esm/index.js +1 -2
- package/node_modules/@turf/flatten/dist/esm/index.js.map +1 -1
- package/node_modules/@turf/flatten/package.json +10 -10
- package/node_modules/@turf/flip/dist/cjs/index.cjs +3 -6
- package/node_modules/@turf/flip/dist/cjs/index.cjs.map +1 -1
- package/node_modules/@turf/flip/dist/cjs/index.d.cts +1 -1
- package/node_modules/@turf/flip/dist/esm/index.d.ts +1 -1
- package/node_modules/@turf/flip/dist/esm/index.js +3 -6
- package/node_modules/@turf/flip/dist/esm/index.js.map +1 -1
- package/node_modules/@turf/flip/package.json +11 -11
- package/node_modules/@turf/geojson-rbush/dist/cjs/index.cjs +9 -18
- package/node_modules/@turf/geojson-rbush/dist/cjs/index.cjs.map +1 -1
- package/node_modules/@turf/geojson-rbush/dist/esm/index.js +9 -18
- package/node_modules/@turf/geojson-rbush/dist/esm/index.js.map +1 -1
- package/node_modules/@turf/geojson-rbush/package.json +11 -11
- package/node_modules/@turf/great-circle/README.md +2 -1
- package/node_modules/@turf/great-circle/dist/cjs/index.cjs +7 -2
- package/node_modules/@turf/great-circle/dist/cjs/index.cjs.map +1 -1
- package/node_modules/@turf/great-circle/dist/esm/index.js +7 -2
- package/node_modules/@turf/great-circle/dist/esm/index.js.map +1 -1
- package/node_modules/@turf/great-circle/package.json +9 -9
- package/node_modules/@turf/helpers/README.md +199 -154
- package/node_modules/@turf/helpers/dist/cjs/index.cjs +10 -7
- package/node_modules/@turf/helpers/dist/cjs/index.cjs.map +1 -1
- package/node_modules/@turf/helpers/dist/cjs/index.d.cts +149 -110
- package/node_modules/@turf/helpers/dist/esm/index.d.ts +149 -110
- package/node_modules/@turf/helpers/dist/esm/index.js +10 -7
- package/node_modules/@turf/helpers/dist/esm/index.js.map +1 -1
- package/node_modules/@turf/helpers/package.json +8 -8
- package/node_modules/@turf/hex-grid/dist/cjs/index.cjs +2 -4
- package/node_modules/@turf/hex-grid/dist/cjs/index.cjs.map +1 -1
- package/node_modules/@turf/hex-grid/dist/cjs/index.d.cts +1 -1
- package/node_modules/@turf/hex-grid/dist/esm/index.d.ts +1 -1
- package/node_modules/@turf/hex-grid/dist/esm/index.js +2 -4
- package/node_modules/@turf/hex-grid/dist/esm/index.js.map +1 -1
- package/node_modules/@turf/hex-grid/package.json +14 -14
- package/node_modules/@turf/interpolate/README.md +5 -2
- package/node_modules/@turf/interpolate/dist/cjs/index.cjs +10 -15
- package/node_modules/@turf/interpolate/dist/cjs/index.cjs.map +1 -1
- package/node_modules/@turf/interpolate/dist/cjs/index.d.cts +3 -1
- package/node_modules/@turf/interpolate/dist/esm/index.d.ts +3 -1
- package/node_modules/@turf/interpolate/dist/esm/index.js +11 -16
- package/node_modules/@turf/interpolate/dist/esm/index.js.map +1 -1
- package/node_modules/@turf/interpolate/package.json +18 -18
- package/node_modules/@turf/intersect/dist/cjs/index.cjs +7 -11
- package/node_modules/@turf/intersect/dist/cjs/index.cjs.map +1 -1
- package/node_modules/@turf/intersect/dist/cjs/index.d.cts +1 -1
- package/node_modules/@turf/intersect/dist/esm/index.d.ts +1 -1
- package/node_modules/@turf/intersect/dist/esm/index.js +6 -10
- package/node_modules/@turf/intersect/dist/esm/index.js.map +1 -1
- package/node_modules/@turf/intersect/package.json +11 -11
- package/node_modules/@turf/invariant/README.md +4 -0
- package/node_modules/@turf/invariant/dist/cjs/index.cjs.map +1 -1
- package/node_modules/@turf/invariant/dist/cjs/index.d.cts +6 -6
- package/node_modules/@turf/invariant/dist/esm/index.d.ts +6 -6
- package/node_modules/@turf/invariant/dist/esm/index.js.map +1 -1
- package/node_modules/@turf/invariant/package.json +9 -9
- package/node_modules/@turf/isobands/dist/cjs/index.cjs +10 -20
- package/node_modules/@turf/isobands/dist/cjs/index.cjs.map +1 -1
- package/node_modules/@turf/isobands/dist/cjs/index.d.cts +1 -1
- package/node_modules/@turf/isobands/dist/esm/index.d.ts +1 -1
- package/node_modules/@turf/isobands/dist/esm/index.js +10 -20
- package/node_modules/@turf/isobands/dist/esm/index.js.map +1 -1
- package/node_modules/@turf/isobands/package.json +20 -20
- package/node_modules/@turf/isolines/dist/cjs/index.cjs +10 -20
- package/node_modules/@turf/isolines/dist/cjs/index.cjs.map +1 -1
- package/node_modules/@turf/isolines/dist/cjs/index.d.cts +1 -1
- package/node_modules/@turf/isolines/dist/esm/index.d.ts +1 -1
- package/node_modules/@turf/isolines/dist/esm/index.js +10 -20
- package/node_modules/@turf/isolines/dist/esm/index.js.map +1 -1
- package/node_modules/@turf/isolines/package.json +17 -17
- package/node_modules/@turf/jsts/dist/jsts.min.js +1 -1
- package/node_modules/@turf/jsts/dist/jsts.min.js.map +1 -0
- package/node_modules/@turf/jsts/package.json +17 -17
- package/node_modules/@turf/kinks/dist/cjs/index.cjs.map +1 -1
- package/node_modules/@turf/kinks/dist/cjs/index.d.cts +1 -1
- package/node_modules/@turf/kinks/dist/esm/index.d.ts +1 -1
- package/node_modules/@turf/kinks/dist/esm/index.js.map +1 -1
- package/node_modules/@turf/kinks/package.json +10 -10
- package/node_modules/@turf/length/dist/cjs/index.cjs.map +1 -1
- package/node_modules/@turf/length/dist/cjs/index.d.cts +1 -1
- package/node_modules/@turf/length/dist/esm/index.d.ts +1 -1
- package/node_modules/@turf/length/dist/esm/index.js.map +1 -1
- package/node_modules/@turf/length/package.json +11 -11
- package/node_modules/@turf/line-arc/dist/cjs/index.cjs.map +1 -1
- package/node_modules/@turf/line-arc/dist/cjs/index.d.cts +1 -1
- package/node_modules/@turf/line-arc/dist/esm/index.d.ts +1 -1
- package/node_modules/@turf/line-arc/dist/esm/index.js.map +1 -1
- package/node_modules/@turf/line-arc/package.json +12 -12
- package/node_modules/@turf/line-chunk/dist/cjs/index.cjs +3 -6
- package/node_modules/@turf/line-chunk/dist/cjs/index.cjs.map +1 -1
- package/node_modules/@turf/line-chunk/dist/esm/index.js +3 -6
- package/node_modules/@turf/line-chunk/dist/esm/index.js.map +1 -1
- package/node_modules/@turf/line-chunk/package.json +11 -11
- package/node_modules/@turf/line-intersect/README.md +1 -1
- package/node_modules/@turf/line-intersect/dist/cjs/index.cjs +3 -5
- package/node_modules/@turf/line-intersect/dist/cjs/index.cjs.map +1 -1
- package/node_modules/@turf/line-intersect/dist/cjs/index.d.cts +2 -2
- package/node_modules/@turf/line-intersect/dist/esm/index.d.ts +2 -2
- package/node_modules/@turf/line-intersect/dist/esm/index.js +3 -5
- package/node_modules/@turf/line-intersect/dist/esm/index.js.map +1 -1
- package/node_modules/@turf/line-intersect/package.json +10 -10
- package/node_modules/@turf/line-offset/dist/cjs/index.cjs +3 -6
- package/node_modules/@turf/line-offset/dist/cjs/index.cjs.map +1 -1
- package/node_modules/@turf/line-offset/dist/esm/index.js +3 -6
- package/node_modules/@turf/line-offset/dist/esm/index.js.map +1 -1
- package/node_modules/@turf/line-offset/package.json +10 -10
- package/node_modules/@turf/line-overlap/dist/cjs/index.cjs +10 -20
- package/node_modules/@turf/line-overlap/dist/cjs/index.cjs.map +1 -1
- package/node_modules/@turf/line-overlap/dist/cjs/index.d.cts +1 -1
- package/node_modules/@turf/line-overlap/dist/esm/index.d.ts +1 -1
- package/node_modules/@turf/line-overlap/dist/esm/index.js +10 -20
- package/node_modules/@turf/line-overlap/dist/esm/index.js.map +1 -1
- package/node_modules/@turf/line-overlap/package.json +15 -15
- package/node_modules/@turf/line-segment/dist/cjs/index.cjs.map +1 -1
- package/node_modules/@turf/line-segment/dist/cjs/index.d.cts +1 -1
- package/node_modules/@turf/line-segment/dist/esm/index.d.ts +1 -1
- package/node_modules/@turf/line-segment/dist/esm/index.js.map +1 -1
- package/node_modules/@turf/line-segment/package.json +11 -11
- package/node_modules/@turf/line-slice/dist/cjs/index.cjs.map +1 -1
- package/node_modules/@turf/line-slice/dist/esm/index.js.map +1 -1
- package/node_modules/@turf/line-slice/package.json +10 -10
- package/node_modules/@turf/line-slice-along/dist/cjs/index.cjs +5 -10
- package/node_modules/@turf/line-slice-along/dist/cjs/index.cjs.map +1 -1
- package/node_modules/@turf/line-slice-along/dist/esm/index.js +5 -10
- package/node_modules/@turf/line-slice-along/dist/esm/index.js.map +1 -1
- package/node_modules/@turf/line-slice-along/package.json +12 -12
- package/node_modules/@turf/line-split/dist/cjs/index.cjs +7 -14
- package/node_modules/@turf/line-split/dist/cjs/index.cjs.map +1 -1
- package/node_modules/@turf/line-split/dist/esm/index.js +7 -14
- package/node_modules/@turf/line-split/dist/esm/index.js.map +1 -1
- package/node_modules/@turf/line-split/package.json +16 -16
- package/node_modules/@turf/line-to-polygon/dist/cjs/index.cjs +4 -8
- package/node_modules/@turf/line-to-polygon/dist/cjs/index.cjs.map +1 -1
- package/node_modules/@turf/line-to-polygon/dist/cjs/index.d.cts +1 -1
- package/node_modules/@turf/line-to-polygon/dist/esm/index.d.ts +1 -1
- package/node_modules/@turf/line-to-polygon/dist/esm/index.js +4 -8
- package/node_modules/@turf/line-to-polygon/dist/esm/index.js.map +1 -1
- package/node_modules/@turf/line-to-polygon/package.json +12 -12
- package/node_modules/@turf/mask/dist/cjs/index.cjs +7 -7
- package/node_modules/@turf/mask/dist/cjs/index.cjs.map +1 -1
- package/node_modules/@turf/mask/dist/cjs/index.d.cts +1 -1
- package/node_modules/@turf/mask/dist/esm/index.d.ts +1 -1
- package/node_modules/@turf/mask/dist/esm/index.js +6 -6
- package/node_modules/@turf/mask/dist/esm/index.js.map +1 -1
- package/node_modules/@turf/mask/package.json +11 -11
- package/node_modules/@turf/meta/README.md +145 -93
- package/node_modules/@turf/meta/dist/cjs/index.cjs +22 -44
- package/node_modules/@turf/meta/dist/cjs/index.cjs.map +1 -1
- package/node_modules/@turf/meta/dist/esm/index.js +22 -44
- package/node_modules/@turf/meta/dist/esm/index.js.map +1 -1
- package/node_modules/@turf/meta/package.json +7 -7
- package/node_modules/@turf/midpoint/dist/cjs/index.cjs.map +1 -1
- package/node_modules/@turf/midpoint/dist/cjs/index.d.cts +1 -1
- package/node_modules/@turf/midpoint/dist/esm/index.d.ts +1 -1
- package/node_modules/@turf/midpoint/dist/esm/index.js.map +1 -1
- package/node_modules/@turf/midpoint/package.json +12 -12
- package/node_modules/@turf/moran-index/README.md +25 -47
- package/node_modules/@turf/moran-index/dist/cjs/index.cjs.map +1 -1
- package/node_modules/@turf/moran-index/dist/cjs/index.d.cts +16 -8
- package/node_modules/@turf/moran-index/dist/esm/index.d.ts +16 -8
- package/node_modules/@turf/moran-index/dist/esm/index.js.map +1 -1
- package/node_modules/@turf/moran-index/package.json +11 -11
- package/node_modules/@turf/nearest-neighbor-analysis/README.md +50 -21
- package/node_modules/@turf/nearest-neighbor-analysis/dist/cjs/index.cjs.map +1 -1
- package/node_modules/@turf/nearest-neighbor-analysis/dist/cjs/index.d.cts +25 -6
- package/node_modules/@turf/nearest-neighbor-analysis/dist/esm/index.d.ts +25 -6
- package/node_modules/@turf/nearest-neighbor-analysis/dist/esm/index.js.map +1 -1
- package/node_modules/@turf/nearest-neighbor-analysis/package.json +17 -17
- package/node_modules/@turf/nearest-point/dist/cjs/index.cjs +2 -4
- package/node_modules/@turf/nearest-point/dist/cjs/index.cjs.map +1 -1
- package/node_modules/@turf/nearest-point/dist/cjs/index.d.cts +1 -1
- package/node_modules/@turf/nearest-point/dist/esm/index.d.ts +1 -1
- package/node_modules/@turf/nearest-point/dist/esm/index.js +2 -4
- package/node_modules/@turf/nearest-point/dist/esm/index.js.map +1 -1
- package/node_modules/@turf/nearest-point/package.json +12 -12
- package/node_modules/@turf/nearest-point-on-line/README.md +9 -9
- package/node_modules/@turf/nearest-point-on-line/dist/cjs/index.cjs +97 -53
- package/node_modules/@turf/nearest-point-on-line/dist/cjs/index.cjs.map +1 -1
- package/node_modules/@turf/nearest-point-on-line/dist/cjs/index.d.cts +2 -2
- package/node_modules/@turf/nearest-point-on-line/dist/esm/index.d.ts +2 -2
- package/node_modules/@turf/nearest-point-on-line/dist/esm/index.js +99 -55
- package/node_modules/@turf/nearest-point-on-line/dist/esm/index.js.map +1 -1
- package/node_modules/@turf/nearest-point-on-line/package.json +15 -18
- package/node_modules/@turf/nearest-point-to-line/README.md +1 -9
- package/node_modules/@turf/nearest-point-to-line/dist/cjs/index.cjs.map +1 -1
- package/node_modules/@turf/nearest-point-to-line/dist/cjs/index.d.cts +1 -1
- package/node_modules/@turf/nearest-point-to-line/dist/esm/index.d.ts +1 -1
- package/node_modules/@turf/nearest-point-to-line/dist/esm/index.js.map +1 -1
- package/node_modules/@turf/nearest-point-to-line/package.json +14 -14
- package/node_modules/@turf/planepoint/dist/cjs/index.cjs.map +1 -1
- package/node_modules/@turf/planepoint/dist/cjs/index.d.cts +1 -1
- package/node_modules/@turf/planepoint/dist/esm/index.d.ts +1 -1
- package/node_modules/@turf/planepoint/dist/esm/index.js.map +1 -1
- package/node_modules/@turf/planepoint/package.json +10 -10
- package/node_modules/@turf/point-grid/dist/cjs/index.cjs +2 -4
- package/node_modules/@turf/point-grid/dist/cjs/index.cjs.map +1 -1
- package/node_modules/@turf/point-grid/dist/cjs/index.d.cts +1 -1
- package/node_modules/@turf/point-grid/dist/esm/index.d.ts +1 -1
- package/node_modules/@turf/point-grid/dist/esm/index.js +2 -4
- package/node_modules/@turf/point-grid/dist/esm/index.js.map +1 -1
- package/node_modules/@turf/point-grid/package.json +14 -14
- package/node_modules/@turf/point-on-feature/dist/cjs/index.cjs.map +1 -1
- package/node_modules/@turf/point-on-feature/dist/cjs/index.d.cts +1 -1
- package/node_modules/@turf/point-on-feature/dist/esm/index.d.ts +1 -1
- package/node_modules/@turf/point-on-feature/dist/esm/index.js.map +1 -1
- package/node_modules/@turf/point-on-feature/package.json +15 -15
- package/node_modules/@turf/point-to-line-distance/README.md +10 -10
- package/node_modules/@turf/point-to-line-distance/dist/cjs/index.cjs +21 -19
- package/node_modules/@turf/point-to-line-distance/dist/cjs/index.cjs.map +1 -1
- package/node_modules/@turf/point-to-line-distance/dist/cjs/index.d.cts +3 -3
- package/node_modules/@turf/point-to-line-distance/dist/esm/index.d.ts +3 -3
- package/node_modules/@turf/point-to-line-distance/dist/esm/index.js +22 -20
- package/node_modules/@turf/point-to-line-distance/dist/esm/index.js.map +1 -1
- package/node_modules/@turf/point-to-line-distance/package.json +18 -17
- package/node_modules/@turf/point-to-polygon-distance/LICENSE +20 -0
- package/node_modules/@turf/point-to-polygon-distance/README.md +61 -0
- package/node_modules/@turf/point-to-polygon-distance/dist/cjs/index.cjs +49 -0
- package/node_modules/@turf/point-to-polygon-distance/dist/cjs/index.cjs.map +1 -0
- package/node_modules/@turf/point-to-polygon-distance/dist/cjs/index.d.cts +23 -0
- package/node_modules/@turf/point-to-polygon-distance/dist/esm/index.d.ts +23 -0
- package/node_modules/@turf/point-to-polygon-distance/dist/esm/index.js +49 -0
- package/node_modules/@turf/point-to-polygon-distance/dist/esm/index.js.map +1 -0
- package/node_modules/@turf/point-to-polygon-distance/package.json +80 -0
- package/node_modules/@turf/points-within-polygon/dist/cjs/index.cjs.map +1 -1
- package/node_modules/@turf/points-within-polygon/dist/cjs/index.d.cts +1 -1
- package/node_modules/@turf/points-within-polygon/dist/esm/index.d.ts +1 -1
- package/node_modules/@turf/points-within-polygon/dist/esm/index.js.map +1 -1
- package/node_modules/@turf/points-within-polygon/package.json +11 -11
- package/node_modules/@turf/polygon-smooth/dist/cjs/index.cjs +1 -2
- package/node_modules/@turf/polygon-smooth/dist/cjs/index.cjs.map +1 -1
- package/node_modules/@turf/polygon-smooth/dist/cjs/index.d.cts +1 -1
- package/node_modules/@turf/polygon-smooth/dist/esm/index.d.ts +1 -1
- package/node_modules/@turf/polygon-smooth/dist/esm/index.js +1 -2
- package/node_modules/@turf/polygon-smooth/dist/esm/index.js.map +1 -1
- package/node_modules/@turf/polygon-smooth/package.json +10 -10
- package/node_modules/@turf/polygon-tangents/dist/cjs/index.cjs +1 -2
- package/node_modules/@turf/polygon-tangents/dist/cjs/index.cjs.map +1 -1
- package/node_modules/@turf/polygon-tangents/dist/cjs/index.d.cts +1 -1
- package/node_modules/@turf/polygon-tangents/dist/esm/index.d.ts +1 -1
- package/node_modules/@turf/polygon-tangents/dist/esm/index.js +1 -2
- package/node_modules/@turf/polygon-tangents/dist/esm/index.js.map +1 -1
- package/node_modules/@turf/polygon-tangents/package.json +14 -14
- package/node_modules/@turf/polygon-to-line/dist/cjs/index.cjs.map +1 -1
- package/node_modules/@turf/polygon-to-line/dist/cjs/index.d.cts +1 -1
- package/node_modules/@turf/polygon-to-line/dist/esm/index.d.ts +1 -1
- package/node_modules/@turf/polygon-to-line/dist/esm/index.js.map +1 -1
- package/node_modules/@turf/polygon-to-line/package.json +10 -10
- package/node_modules/@turf/polygonize/dist/cjs/index.cjs +20 -40
- package/node_modules/@turf/polygonize/dist/cjs/index.cjs.map +1 -1
- package/node_modules/@turf/polygonize/dist/cjs/index.d.cts +1 -1
- package/node_modules/@turf/polygonize/dist/esm/index.d.ts +1 -1
- package/node_modules/@turf/polygonize/dist/esm/index.js +20 -40
- package/node_modules/@turf/polygonize/dist/esm/index.js.map +1 -1
- package/node_modules/@turf/polygonize/package.json +13 -13
- package/node_modules/@turf/projection/README.md +2 -2
- package/node_modules/@turf/projection/dist/cjs/index.cjs +6 -12
- package/node_modules/@turf/projection/dist/cjs/index.cjs.map +1 -1
- package/node_modules/@turf/projection/dist/cjs/index.d.cts +2 -2
- package/node_modules/@turf/projection/dist/esm/index.d.ts +2 -2
- package/node_modules/@turf/projection/dist/esm/index.js +6 -12
- package/node_modules/@turf/projection/dist/esm/index.js.map +1 -1
- package/node_modules/@turf/projection/package.json +12 -12
- package/node_modules/@turf/quadrat-analysis/README.md +10 -10
- package/node_modules/@turf/quadrat-analysis/dist/cjs/index.cjs.map +1 -1
- package/node_modules/@turf/quadrat-analysis/dist/cjs/index.d.cts +4 -4
- package/node_modules/@turf/quadrat-analysis/dist/esm/index.d.ts +4 -4
- package/node_modules/@turf/quadrat-analysis/dist/esm/index.js.map +1 -1
- package/node_modules/@turf/quadrat-analysis/package.json +18 -18
- package/node_modules/@turf/random/README.md +27 -29
- package/node_modules/@turf/random/dist/cjs/index.cjs +1 -3
- package/node_modules/@turf/random/dist/cjs/index.cjs.map +1 -1
- package/node_modules/@turf/random/dist/cjs/index.d.cts +11 -11
- package/node_modules/@turf/random/dist/esm/index.d.ts +11 -11
- package/node_modules/@turf/random/dist/esm/index.js +1 -3
- package/node_modules/@turf/random/dist/esm/index.js.map +1 -1
- package/node_modules/@turf/random/package.json +9 -9
- package/node_modules/@turf/rectangle-grid/dist/cjs/index.cjs.map +1 -1
- package/node_modules/@turf/rectangle-grid/dist/cjs/index.d.cts +1 -1
- package/node_modules/@turf/rectangle-grid/dist/esm/index.d.ts +1 -1
- package/node_modules/@turf/rectangle-grid/dist/esm/index.js.map +1 -1
- package/node_modules/@turf/rectangle-grid/package.json +13 -13
- package/node_modules/@turf/rewind/dist/cjs/index.cjs +3 -6
- package/node_modules/@turf/rewind/dist/cjs/index.cjs.map +1 -1
- package/node_modules/@turf/rewind/dist/cjs/index.d.cts +1 -1
- package/node_modules/@turf/rewind/dist/esm/index.d.ts +1 -1
- package/node_modules/@turf/rewind/dist/esm/index.js +3 -6
- package/node_modules/@turf/rewind/dist/esm/index.js.map +1 -1
- package/node_modules/@turf/rewind/package.json +13 -13
- package/node_modules/@turf/rhumb-bearing/README.md +1 -1
- package/node_modules/@turf/rhumb-bearing/dist/cjs/index.cjs.map +1 -1
- package/node_modules/@turf/rhumb-bearing/dist/cjs/index.d.cts +1 -1
- package/node_modules/@turf/rhumb-bearing/dist/esm/index.d.ts +1 -1
- package/node_modules/@turf/rhumb-bearing/dist/esm/index.js.map +1 -1
- package/node_modules/@turf/rhumb-bearing/package.json +11 -11
- package/node_modules/@turf/rhumb-destination/dist/cjs/index.cjs +1 -2
- package/node_modules/@turf/rhumb-destination/dist/cjs/index.cjs.map +1 -1
- package/node_modules/@turf/rhumb-destination/dist/cjs/index.d.cts +1 -1
- package/node_modules/@turf/rhumb-destination/dist/esm/index.d.ts +1 -1
- package/node_modules/@turf/rhumb-destination/dist/esm/index.js +1 -2
- package/node_modules/@turf/rhumb-destination/dist/esm/index.js.map +1 -1
- package/node_modules/@turf/rhumb-destination/package.json +11 -11
- package/node_modules/@turf/rhumb-distance/README.md +1 -1
- package/node_modules/@turf/rhumb-distance/dist/cjs/index.cjs.map +1 -1
- package/node_modules/@turf/rhumb-distance/dist/cjs/index.d.cts +1 -1
- package/node_modules/@turf/rhumb-distance/dist/esm/index.d.ts +1 -1
- package/node_modules/@turf/rhumb-distance/dist/esm/index.js.map +1 -1
- package/node_modules/@turf/rhumb-distance/package.json +11 -11
- package/node_modules/@turf/sample/README.md +2 -1
- package/node_modules/@turf/sample/dist/cjs/index.cjs +3 -6
- package/node_modules/@turf/sample/dist/cjs/index.cjs.map +1 -1
- package/node_modules/@turf/sample/dist/cjs/index.d.cts +1 -1
- package/node_modules/@turf/sample/dist/esm/index.d.ts +1 -1
- package/node_modules/@turf/sample/dist/esm/index.js +3 -6
- package/node_modules/@turf/sample/dist/esm/index.js.map +1 -1
- package/node_modules/@turf/sample/package.json +9 -9
- package/node_modules/@turf/sector/dist/cjs/index.cjs +4 -8
- package/node_modules/@turf/sector/dist/cjs/index.cjs.map +1 -1
- package/node_modules/@turf/sector/dist/cjs/index.d.cts +1 -1
- package/node_modules/@turf/sector/dist/esm/index.d.ts +1 -1
- package/node_modules/@turf/sector/dist/esm/index.js +4 -8
- package/node_modules/@turf/sector/dist/esm/index.js.map +1 -1
- package/node_modules/@turf/sector/package.json +14 -14
- package/node_modules/@turf/shortest-path/README.md +13 -19
- package/node_modules/@turf/shortest-path/dist/cjs/index.cjs +3 -6
- package/node_modules/@turf/shortest-path/dist/cjs/index.cjs.map +1 -1
- package/node_modules/@turf/shortest-path/dist/cjs/index.d.cts +5 -5
- package/node_modules/@turf/shortest-path/dist/esm/index.d.ts +5 -5
- package/node_modules/@turf/shortest-path/dist/esm/index.js +3 -6
- package/node_modules/@turf/shortest-path/dist/esm/index.js.map +1 -1
- package/node_modules/@turf/shortest-path/package.json +18 -18
- package/node_modules/@turf/simplify/dist/cjs/index.cjs +8 -16
- package/node_modules/@turf/simplify/dist/cjs/index.cjs.map +1 -1
- package/node_modules/@turf/simplify/dist/cjs/index.d.cts +1 -1
- package/node_modules/@turf/simplify/dist/esm/index.d.ts +1 -1
- package/node_modules/@turf/simplify/dist/esm/index.js +8 -16
- package/node_modules/@turf/simplify/dist/esm/index.js.map +1 -1
- package/node_modules/@turf/simplify/package.json +13 -13
- package/node_modules/@turf/square/dist/cjs/index.cjs.map +1 -1
- package/node_modules/@turf/square/dist/cjs/index.d.cts +1 -1
- package/node_modules/@turf/square/dist/esm/index.d.ts +1 -1
- package/node_modules/@turf/square/dist/esm/index.js.map +1 -1
- package/node_modules/@turf/square/package.json +10 -10
- package/node_modules/@turf/square-grid/dist/cjs/index.cjs.map +1 -1
- package/node_modules/@turf/square-grid/dist/cjs/index.d.cts +1 -1
- package/node_modules/@turf/square-grid/dist/esm/index.d.ts +1 -1
- package/node_modules/@turf/square-grid/dist/esm/index.js.map +1 -1
- package/node_modules/@turf/square-grid/package.json +12 -12
- package/node_modules/@turf/standard-deviational-ellipse/dist/cjs/index.cjs +3 -6
- package/node_modules/@turf/standard-deviational-ellipse/dist/cjs/index.cjs.map +1 -1
- package/node_modules/@turf/standard-deviational-ellipse/dist/cjs/index.d.cts +1 -1
- package/node_modules/@turf/standard-deviational-ellipse/dist/esm/index.d.ts +1 -1
- package/node_modules/@turf/standard-deviational-ellipse/dist/esm/index.js +3 -6
- package/node_modules/@turf/standard-deviational-ellipse/dist/esm/index.js.map +1 -1
- package/node_modules/@turf/standard-deviational-ellipse/package.json +16 -16
- package/node_modules/@turf/tag/dist/cjs/index.cjs +1 -2
- package/node_modules/@turf/tag/dist/cjs/index.cjs.map +1 -1
- package/node_modules/@turf/tag/dist/cjs/index.d.cts +1 -1
- package/node_modules/@turf/tag/dist/esm/index.d.ts +1 -1
- package/node_modules/@turf/tag/dist/esm/index.js +1 -2
- package/node_modules/@turf/tag/dist/esm/index.js.map +1 -1
- package/node_modules/@turf/tag/package.json +12 -12
- package/node_modules/@turf/tesselate/dist/cjs/index.cjs +1 -2
- package/node_modules/@turf/tesselate/dist/cjs/index.cjs.map +1 -1
- package/node_modules/@turf/tesselate/dist/cjs/index.d.cts +1 -1
- package/node_modules/@turf/tesselate/dist/esm/index.d.ts +1 -1
- package/node_modules/@turf/tesselate/dist/esm/index.js +1 -2
- package/node_modules/@turf/tesselate/dist/esm/index.js.map +1 -1
- package/node_modules/@turf/tesselate/package.json +9 -9
- package/node_modules/@turf/tin/dist/cjs/index.cjs +13 -14
- package/node_modules/@turf/tin/dist/cjs/index.cjs.map +1 -1
- package/node_modules/@turf/tin/dist/cjs/index.d.cts +1 -1
- package/node_modules/@turf/tin/dist/esm/index.d.ts +1 -1
- package/node_modules/@turf/tin/dist/esm/index.js +13 -14
- package/node_modules/@turf/tin/dist/esm/index.js.map +1 -1
- package/node_modules/@turf/tin/package.json +9 -9
- package/node_modules/@turf/transform-rotate/dist/cjs/index.cjs +4 -8
- package/node_modules/@turf/transform-rotate/dist/cjs/index.cjs.map +1 -1
- package/node_modules/@turf/transform-rotate/dist/cjs/index.d.cts +1 -1
- package/node_modules/@turf/transform-rotate/dist/esm/index.d.ts +1 -1
- package/node_modules/@turf/transform-rotate/dist/esm/index.js +4 -8
- package/node_modules/@turf/transform-rotate/dist/esm/index.js.map +1 -1
- package/node_modules/@turf/transform-rotate/package.json +17 -17
- package/node_modules/@turf/transform-scale/dist/cjs/index.cjs +18 -12
- package/node_modules/@turf/transform-scale/dist/cjs/index.cjs.map +1 -1
- package/node_modules/@turf/transform-scale/dist/cjs/index.d.cts +1 -1
- package/node_modules/@turf/transform-scale/dist/esm/index.d.ts +1 -1
- package/node_modules/@turf/transform-scale/dist/esm/index.js +18 -12
- package/node_modules/@turf/transform-scale/dist/esm/index.js.map +1 -1
- package/node_modules/@turf/transform-scale/package.json +21 -21
- package/node_modules/@turf/transform-translate/dist/cjs/index.cjs +4 -8
- package/node_modules/@turf/transform-translate/dist/cjs/index.cjs.map +1 -1
- package/node_modules/@turf/transform-translate/dist/cjs/index.d.cts +1 -1
- package/node_modules/@turf/transform-translate/dist/esm/index.d.ts +1 -1
- package/node_modules/@turf/transform-translate/dist/esm/index.js +4 -8
- package/node_modules/@turf/transform-translate/dist/esm/index.js.map +1 -1
- package/node_modules/@turf/transform-translate/package.json +14 -14
- package/node_modules/@turf/triangle-grid/dist/cjs/index.cjs.map +1 -1
- package/node_modules/@turf/triangle-grid/dist/cjs/index.d.cts +1 -1
- package/node_modules/@turf/triangle-grid/dist/esm/index.d.ts +1 -1
- package/node_modules/@turf/triangle-grid/dist/esm/index.js.map +1 -1
- package/node_modules/@turf/triangle-grid/package.json +13 -13
- package/node_modules/@turf/truncate/dist/cjs/index.cjs +3 -6
- package/node_modules/@turf/truncate/dist/cjs/index.cjs.map +1 -1
- package/node_modules/@turf/truncate/dist/cjs/index.d.cts +1 -1
- package/node_modules/@turf/truncate/dist/esm/index.d.ts +1 -1
- package/node_modules/@turf/truncate/dist/esm/index.js +3 -6
- package/node_modules/@turf/truncate/dist/esm/index.js.map +1 -1
- package/node_modules/@turf/truncate/package.json +10 -10
- package/node_modules/@turf/turf/dist/cjs/index.cjs +3 -1
- package/node_modules/@turf/turf/dist/cjs/index.cjs.map +1 -1
- package/node_modules/@turf/turf/dist/cjs/index.d.cts +1 -0
- package/node_modules/@turf/turf/dist/esm/index.d.ts +1 -0
- package/node_modules/@turf/turf/dist/esm/index.js +2 -0
- package/node_modules/@turf/turf/dist/esm/index.js.map +1 -1
- package/node_modules/@turf/turf/package.json +126 -125
- package/node_modules/@turf/turf/turf.min.js +3 -26
- package/node_modules/@turf/union/README.md +44 -24
- package/node_modules/@turf/union/dist/cjs/index.cjs +9 -12
- package/node_modules/@turf/union/dist/cjs/index.cjs.map +1 -1
- package/node_modules/@turf/union/dist/cjs/index.d.cts +40 -21
- package/node_modules/@turf/union/dist/esm/index.d.ts +40 -21
- package/node_modules/@turf/union/dist/esm/index.js +8 -11
- package/node_modules/@turf/union/dist/esm/index.js.map +1 -1
- package/node_modules/@turf/union/package.json +11 -11
- package/node_modules/@turf/unkink-polygon/dist/cjs/index.cjs +14 -28
- package/node_modules/@turf/unkink-polygon/dist/cjs/index.cjs.map +1 -1
- package/node_modules/@turf/unkink-polygon/dist/cjs/index.d.cts +1 -1
- package/node_modules/@turf/unkink-polygon/dist/esm/index.d.ts +1 -1
- package/node_modules/@turf/unkink-polygon/dist/esm/index.js +14 -28
- package/node_modules/@turf/unkink-polygon/dist/esm/index.js.map +1 -1
- package/node_modules/@turf/unkink-polygon/package.json +13 -13
- package/node_modules/@turf/voronoi/dist/cjs/index.cjs +3 -6
- package/node_modules/@turf/voronoi/dist/cjs/index.cjs.map +1 -1
- package/node_modules/@turf/voronoi/dist/cjs/index.d.cts +1 -1
- package/node_modules/@turf/voronoi/dist/esm/index.d.ts +1 -1
- package/node_modules/@turf/voronoi/dist/esm/index.js +3 -6
- package/node_modules/@turf/voronoi/dist/esm/index.js.map +1 -1
- package/node_modules/@turf/voronoi/package.json +11 -11
- package/node_modules/@types/geojson/README.md +1 -1
- package/node_modules/@types/geojson/index.d.ts +4 -1
- package/node_modules/@types/geojson/package.json +4 -3
- package/node_modules/@types/node/README.md +2 -2
- package/node_modules/@types/node/assert.d.ts +2 -2
- package/node_modules/@types/node/compatibility/disposable.d.ts +16 -0
- package/node_modules/@types/node/compatibility/index.d.ts +9 -0
- package/node_modules/@types/node/compatibility/indexable.d.ts +23 -0
- package/node_modules/@types/node/compatibility/iterators.d.ts +21 -0
- package/node_modules/@types/node/crypto.d.ts +33 -9
- package/node_modules/@types/node/events.d.ts +3 -3
- package/node_modules/@types/node/fs/promises.d.ts +16 -5
- package/node_modules/@types/node/fs.d.ts +14 -8
- package/node_modules/@types/node/globals.d.ts +25 -54
- package/node_modules/@types/node/http.d.ts +38 -1
- package/node_modules/@types/node/http2.d.ts +4 -1
- package/node_modules/@types/node/https.d.ts +0 -1
- package/node_modules/@types/node/index.d.ts +8 -10
- package/node_modules/@types/node/module.d.ts +112 -4
- package/node_modules/@types/node/net.d.ts +3 -0
- package/node_modules/@types/node/package.json +5 -9
- package/node_modules/@types/node/perf_hooks.d.ts +24 -0
- package/node_modules/@types/node/process.d.ts +96 -12
- package/node_modules/@types/node/readline/promises.d.ts +14 -2
- package/node_modules/@types/node/readline.d.ts +58 -9
- package/node_modules/@types/node/sqlite.d.ts +30 -9
- package/node_modules/@types/node/stream/promises.d.ts +8 -1
- package/node_modules/@types/node/stream/web.d.ts +5 -2
- package/node_modules/@types/node/stream.d.ts +2 -2
- package/node_modules/@types/node/test.d.ts +155 -5
- package/node_modules/@types/node/timers/promises.d.ts +1 -1
- package/node_modules/@types/node/tls.d.ts +6 -0
- package/node_modules/@types/node/ts5.6/index.d.ts +8 -10
- package/node_modules/@types/node/url.d.ts +7 -4
- package/node_modules/@types/node/util.d.ts +80 -10
- package/node_modules/@types/node/v8.d.ts +1 -1
- package/node_modules/@types/node/vm.d.ts +81 -27
- package/node_modules/@types/node/worker_threads.d.ts +34 -1
- package/node_modules/axios/CHANGELOG.md +49 -0
- package/node_modules/axios/README.md +20 -8
- package/node_modules/axios/dist/axios.js +34 -63
- package/node_modules/axios/dist/axios.js.map +1 -1
- package/node_modules/axios/dist/axios.min.js +1 -1
- package/node_modules/axios/dist/axios.min.js.map +1 -1
- package/node_modules/axios/dist/browser/axios.cjs +40 -71
- package/node_modules/axios/dist/browser/axios.cjs.map +1 -1
- package/node_modules/axios/dist/esm/axios.js +40 -71
- package/node_modules/axios/dist/esm/axios.js.map +1 -1
- package/node_modules/axios/dist/esm/axios.min.js +1 -1
- package/node_modules/axios/dist/esm/axios.min.js.map +1 -1
- package/node_modules/axios/dist/node/axios.cjs +45 -75
- package/node_modules/axios/dist/node/axios.cjs.map +1 -1
- package/node_modules/axios/index.d.cts +5 -1
- package/node_modules/axios/index.d.ts +8 -1
- package/node_modules/axios/lib/adapters/http.js +4 -4
- package/node_modules/axios/lib/core/Axios.js +7 -2
- package/node_modules/axios/lib/core/mergeConfig.js +5 -5
- package/node_modules/axios/lib/env/data.js +1 -1
- package/node_modules/axios/lib/helpers/buildURL.js +7 -1
- package/node_modules/axios/lib/helpers/formDataToStream.js +2 -2
- package/node_modules/axios/lib/helpers/isURLSameOrigin.js +12 -65
- package/node_modules/axios/lib/helpers/validator.js +8 -0
- package/node_modules/axios/package.json +3 -3
- package/node_modules/bignumber.js/CHANGELOG.md +295 -0
- package/node_modules/bignumber.js/LICENCE.md +26 -0
- package/node_modules/bignumber.js/README.md +286 -0
- package/node_modules/bignumber.js/bignumber.d.ts +1831 -0
- package/node_modules/bignumber.js/bignumber.js +2922 -0
- package/node_modules/bignumber.js/bignumber.mjs +2907 -0
- package/node_modules/bignumber.js/doc/API.html +2249 -0
- package/node_modules/bignumber.js/package.json +50 -0
- package/node_modules/fast-xml-parser/CHANGELOG.md +4 -0
- package/node_modules/fast-xml-parser/README.md +3 -2
- package/node_modules/fast-xml-parser/package.json +1 -1
- package/node_modules/fast-xml-parser/src/v5/XmlPartReader.js +21 -17
- package/node_modules/fast-xml-parser/src/xmlparser/DocTypeReader.js +1 -0
- package/node_modules/long/index.d.ts +1 -456
- package/node_modules/long/package.json +1 -1
- package/node_modules/long/umd/index.d.ts +456 -1
- package/node_modules/point-in-polygon-hao/README.md +8 -7
- package/node_modules/point-in-polygon-hao/dist/cjs/index.cjs +322 -0
- package/node_modules/point-in-polygon-hao/dist/esm/index.d.ts +10 -0
- package/node_modules/point-in-polygon-hao/dist/esm/index.js +56 -0
- package/node_modules/point-in-polygon-hao/dist/pointInPolygon.js +286 -42
- package/node_modules/point-in-polygon-hao/dist/pointInPolygon.min.js +1 -1
- package/node_modules/point-in-polygon-hao/package.json +24 -20
- package/node_modules/polyclip-ts/LICENSE +21 -0
- package/node_modules/{polygon-clipping → polyclip-ts}/README.md +35 -36
- package/node_modules/polyclip-ts/dist/cjs/index.cjs +1179 -0
- package/node_modules/polyclip-ts/dist/cjs/index.cjs.map +1 -0
- package/node_modules/polyclip-ts/dist/cjs/index.d.cts +12 -0
- package/node_modules/polyclip-ts/dist/esm/index.d.ts +12 -0
- package/node_modules/polyclip-ts/dist/esm/index.js +1138 -0
- package/node_modules/polyclip-ts/dist/esm/index.js.map +1 -0
- package/node_modules/polyclip-ts/dist/polyclip-ts.umd.js +4811 -0
- package/node_modules/polyclip-ts/dist/polyclip-ts.umd.min.js +2 -0
- package/node_modules/polyclip-ts/package.json +72 -0
- package/node_modules/splaytree-ts/LICENSE +29 -0
- package/node_modules/splaytree-ts/README.md +296 -0
- package/node_modules/splaytree-ts/dist/cjs/index.cjs +714 -0
- package/node_modules/splaytree-ts/dist/cjs/index.cjs.map +1 -0
- package/node_modules/splaytree-ts/dist/cjs/index.d.cts +105 -0
- package/node_modules/splaytree-ts/dist/esm/index.d.ts +105 -0
- package/node_modules/splaytree-ts/dist/esm/index.js +688 -0
- package/node_modules/splaytree-ts/dist/esm/index.js.map +1 -0
- package/node_modules/splaytree-ts/dist/splaytree-ts.umd.js +736 -0
- package/node_modules/splaytree-ts/dist/splaytree-ts.umd.min.js +2 -0
- package/node_modules/splaytree-ts/package.json +59 -0
- package/node_modules/tslib/modules/index.d.ts +1 -0
- package/node_modules/tslib/modules/index.js +2 -0
- package/node_modules/tslib/package.json +1 -1
- package/node_modules/tslib/tslib.d.ts +7 -0
- package/node_modules/tslib/tslib.es6.js +24 -1
- package/node_modules/tslib/tslib.es6.mjs +24 -1
- package/node_modules/tslib/tslib.js +56 -1
- package/node_modules/undici-types/eventsource.d.ts +0 -2
- package/node_modules/undici-types/filereader.d.ts +1 -1
- package/node_modules/undici-types/interceptors.d.ts +3 -1
- package/node_modules/undici-types/package.json +1 -1
- package/node_modules/undici-types/patch.d.ts +0 -38
- package/node_modules/undici-types/websocket.d.ts +0 -2
- package/node_modules/uuid/README.md +82 -156
- package/node_modules/uuid/dist/cjs/index.d.ts +15 -0
- package/node_modules/uuid/dist/cjs/index.js +31 -0
- package/node_modules/uuid/dist/cjs/max.d.ts +2 -0
- package/node_modules/uuid/dist/cjs/max.js +3 -0
- package/node_modules/uuid/dist/cjs/md5.d.ts +4 -0
- package/node_modules/uuid/dist/cjs/md5.js +13 -0
- package/node_modules/uuid/dist/cjs/native.d.ts +6 -0
- package/node_modules/uuid/dist/cjs/native.js +4 -0
- package/node_modules/uuid/dist/cjs/nil.d.ts +2 -0
- package/node_modules/uuid/dist/cjs/nil.js +3 -0
- package/node_modules/uuid/dist/cjs/package.json +1 -0
- package/node_modules/uuid/dist/cjs/parse.d.ts +2 -0
- package/node_modules/uuid/dist/cjs/parse.js +11 -0
- package/node_modules/uuid/dist/cjs/regex.d.ts +2 -0
- package/node_modules/uuid/dist/cjs/regex.js +3 -0
- package/node_modules/uuid/dist/cjs/rng.d.ts +1 -0
- package/node_modules/uuid/dist/cjs/rng.js +13 -0
- package/node_modules/uuid/dist/cjs/sha1.d.ts +4 -0
- package/node_modules/uuid/dist/cjs/sha1.js +13 -0
- package/node_modules/uuid/dist/cjs/stringify.d.ts +3 -0
- package/node_modules/uuid/dist/cjs/stringify.js +39 -0
- package/node_modules/uuid/dist/cjs/types.d.ts +21 -0
- package/node_modules/uuid/dist/cjs/types.js +2 -0
- package/node_modules/uuid/dist/cjs/uuid-bin.d.ts +1 -0
- package/node_modules/uuid/dist/cjs/uuid-bin.js +72 -0
- package/node_modules/uuid/dist/cjs/v1.d.ts +11 -0
- package/node_modules/uuid/dist/cjs/v1.js +87 -0
- package/node_modules/uuid/dist/cjs/v1ToV6.d.ts +2 -0
- package/node_modules/uuid/dist/cjs/v1ToV6.js +13 -0
- package/node_modules/uuid/dist/cjs/v3.d.ts +9 -0
- package/node_modules/uuid/dist/cjs/v3.js +14 -0
- package/node_modules/uuid/dist/cjs/v35.d.ts +7 -0
- package/node_modules/uuid/dist/cjs/v35.js +41 -0
- package/node_modules/uuid/dist/cjs/v4.d.ts +4 -0
- package/node_modules/uuid/dist/cjs/v4.js +29 -0
- package/node_modules/uuid/dist/cjs/v5.d.ts +9 -0
- package/node_modules/uuid/dist/cjs/v5.js +14 -0
- package/node_modules/uuid/dist/cjs/v6.d.ts +4 -0
- package/node_modules/uuid/dist/cjs/v6.js +19 -0
- package/node_modules/uuid/dist/cjs/v6ToV1.d.ts +2 -0
- package/node_modules/uuid/dist/cjs/v6ToV1.js +13 -0
- package/node_modules/uuid/dist/cjs/v7.d.ts +9 -0
- package/node_modules/uuid/dist/cjs/v7.js +69 -0
- package/node_modules/uuid/dist/cjs/validate.d.ts +2 -0
- package/node_modules/uuid/dist/cjs/validate.js +7 -0
- package/node_modules/uuid/dist/cjs/version.d.ts +2 -0
- package/node_modules/uuid/dist/cjs/version.js +10 -0
- package/node_modules/uuid/dist/cjs-browser/index.d.ts +15 -0
- package/node_modules/uuid/dist/cjs-browser/index.js +31 -0
- package/node_modules/uuid/dist/cjs-browser/max.d.ts +2 -0
- package/node_modules/uuid/dist/cjs-browser/max.js +3 -0
- package/node_modules/uuid/dist/cjs-browser/md5.d.ts +2 -0
- package/node_modules/uuid/dist/cjs-browser/md5.js +137 -0
- package/node_modules/uuid/dist/cjs-browser/native.d.ts +4 -0
- package/node_modules/uuid/dist/cjs-browser/native.js +4 -0
- package/node_modules/uuid/dist/cjs-browser/nil.d.ts +2 -0
- package/node_modules/uuid/dist/cjs-browser/nil.js +3 -0
- package/node_modules/uuid/dist/cjs-browser/package.json +1 -0
- package/node_modules/uuid/dist/cjs-browser/parse.d.ts +2 -0
- package/node_modules/uuid/dist/cjs-browser/parse.js +11 -0
- package/node_modules/uuid/dist/cjs-browser/regex.d.ts +2 -0
- package/node_modules/uuid/dist/cjs-browser/regex.js +3 -0
- package/node_modules/uuid/dist/cjs-browser/rng.d.ts +1 -0
- package/node_modules/uuid/dist/cjs-browser/rng.js +14 -0
- package/node_modules/uuid/dist/cjs-browser/sha1.d.ts +2 -0
- package/node_modules/uuid/dist/cjs-browser/sha1.js +72 -0
- package/node_modules/uuid/dist/cjs-browser/stringify.d.ts +3 -0
- package/node_modules/uuid/dist/cjs-browser/stringify.js +39 -0
- package/node_modules/uuid/dist/cjs-browser/types.d.ts +21 -0
- package/node_modules/uuid/dist/cjs-browser/types.js +2 -0
- package/node_modules/uuid/dist/cjs-browser/uuid-bin.d.ts +1 -0
- package/node_modules/uuid/dist/cjs-browser/uuid-bin.js +72 -0
- package/node_modules/uuid/dist/cjs-browser/v1.d.ts +11 -0
- package/node_modules/uuid/dist/cjs-browser/v1.js +87 -0
- package/node_modules/uuid/dist/cjs-browser/v1ToV6.d.ts +2 -0
- package/node_modules/uuid/dist/cjs-browser/v1ToV6.js +13 -0
- package/node_modules/uuid/dist/cjs-browser/v3.d.ts +9 -0
- package/node_modules/uuid/dist/cjs-browser/v3.js +14 -0
- package/node_modules/uuid/dist/cjs-browser/v35.d.ts +7 -0
- package/node_modules/uuid/dist/cjs-browser/v35.js +41 -0
- package/node_modules/uuid/dist/cjs-browser/v4.d.ts +4 -0
- package/node_modules/uuid/dist/cjs-browser/v4.js +29 -0
- package/node_modules/uuid/dist/cjs-browser/v5.d.ts +9 -0
- package/node_modules/uuid/dist/cjs-browser/v5.js +14 -0
- package/node_modules/uuid/dist/cjs-browser/v6.d.ts +4 -0
- package/node_modules/uuid/dist/cjs-browser/v6.js +19 -0
- package/node_modules/uuid/dist/cjs-browser/v6ToV1.d.ts +2 -0
- package/node_modules/uuid/dist/cjs-browser/v6ToV1.js +13 -0
- package/node_modules/uuid/dist/cjs-browser/v7.d.ts +9 -0
- package/node_modules/uuid/dist/cjs-browser/v7.js +69 -0
- package/node_modules/uuid/dist/cjs-browser/validate.d.ts +2 -0
- package/node_modules/uuid/dist/cjs-browser/validate.js +7 -0
- package/node_modules/uuid/dist/cjs-browser/version.d.ts +2 -0
- package/node_modules/uuid/dist/cjs-browser/version.js +10 -0
- package/node_modules/uuid/dist/esm/bin/uuid +2 -0
- package/node_modules/uuid/dist/esm/index.d.ts +15 -0
- package/node_modules/uuid/dist/{esm-node → esm}/index.js +1 -1
- package/node_modules/uuid/dist/esm/max.d.ts +2 -0
- package/node_modules/uuid/dist/esm/max.js +1 -0
- package/node_modules/uuid/dist/esm/md5.d.ts +4 -0
- package/node_modules/uuid/dist/esm/md5.js +11 -0
- package/node_modules/uuid/dist/esm/native.d.ts +6 -0
- package/node_modules/uuid/dist/esm/native.js +2 -0
- package/node_modules/uuid/dist/esm/nil.d.ts +2 -0
- package/node_modules/uuid/dist/esm/nil.js +1 -0
- package/node_modules/uuid/dist/esm/parse.d.ts +2 -0
- package/node_modules/uuid/dist/esm/parse.js +9 -0
- package/node_modules/uuid/dist/esm/regex.d.ts +2 -0
- package/node_modules/uuid/dist/{esm-node → esm}/regex.js +1 -1
- package/node_modules/uuid/dist/esm/rng.d.ts +1 -0
- package/node_modules/uuid/dist/esm/rng.js +10 -0
- package/node_modules/uuid/dist/esm/sha1.d.ts +4 -0
- package/node_modules/uuid/dist/esm/sha1.js +11 -0
- package/node_modules/uuid/dist/esm/stringify.d.ts +3 -0
- package/node_modules/uuid/dist/esm/stringify.js +35 -0
- package/node_modules/uuid/dist/esm/types.d.ts +21 -0
- package/node_modules/uuid/dist/esm/types.js +1 -0
- package/node_modules/uuid/dist/esm/uuid-bin.d.ts +1 -0
- package/node_modules/uuid/dist/esm/uuid-bin.js +70 -0
- package/node_modules/uuid/dist/esm/v1.d.ts +11 -0
- package/node_modules/uuid/dist/esm/v1.js +83 -0
- package/node_modules/uuid/dist/esm/v1ToV6.d.ts +2 -0
- package/node_modules/uuid/dist/esm/v1ToV6.js +10 -0
- package/node_modules/uuid/dist/esm/v3.d.ts +9 -0
- package/node_modules/uuid/dist/esm/v3.js +9 -0
- package/node_modules/uuid/dist/esm/v35.d.ts +7 -0
- package/node_modules/uuid/dist/esm/v35.js +36 -0
- package/node_modules/uuid/dist/esm/v4.d.ts +4 -0
- package/node_modules/uuid/dist/esm/v4.js +27 -0
- package/node_modules/uuid/dist/esm/v5.d.ts +9 -0
- package/node_modules/uuid/dist/esm/v5.js +9 -0
- package/node_modules/uuid/dist/esm/v6.d.ts +4 -0
- package/node_modules/uuid/dist/esm/v6.js +17 -0
- package/node_modules/uuid/dist/esm/v6ToV1.d.ts +2 -0
- package/node_modules/uuid/dist/esm/v6ToV1.js +10 -0
- package/node_modules/uuid/dist/esm/v7.d.ts +9 -0
- package/node_modules/uuid/dist/esm/v7.js +65 -0
- package/node_modules/uuid/dist/esm/validate.d.ts +2 -0
- package/node_modules/uuid/dist/esm/validate.js +5 -0
- package/node_modules/uuid/dist/esm/version.d.ts +2 -0
- package/node_modules/uuid/dist/esm/version.js +8 -0
- package/node_modules/uuid/dist/esm-browser/index.d.ts +15 -0
- package/node_modules/uuid/dist/esm-browser/index.js +1 -1
- package/node_modules/uuid/dist/esm-browser/max.d.ts +2 -0
- package/node_modules/uuid/dist/esm-browser/max.js +1 -1
- package/node_modules/uuid/dist/esm-browser/md5.d.ts +2 -0
- package/node_modules/uuid/dist/esm-browser/md5.js +113 -172
- package/node_modules/uuid/dist/esm-browser/native.d.ts +4 -0
- package/node_modules/uuid/dist/esm-browser/native.js +2 -4
- package/node_modules/uuid/dist/esm-browser/nil.d.ts +2 -0
- package/node_modules/uuid/dist/esm-browser/nil.js +1 -1
- package/node_modules/uuid/dist/esm-browser/parse.d.ts +2 -0
- package/node_modules/uuid/dist/esm-browser/parse.js +6 -34
- package/node_modules/uuid/dist/esm-browser/regex.d.ts +2 -0
- package/node_modules/uuid/dist/esm-browser/regex.js +1 -1
- package/node_modules/uuid/dist/esm-browser/rng.d.ts +1 -0
- package/node_modules/uuid/dist/esm-browser/rng.js +8 -14
- package/node_modules/uuid/dist/esm-browser/sha1.d.ts +2 -0
- package/node_modules/uuid/dist/esm-browser/sha1.js +62 -68
- package/node_modules/uuid/dist/esm-browser/stringify.d.ts +3 -0
- package/node_modules/uuid/dist/esm-browser/stringify.js +29 -25
- package/node_modules/uuid/dist/esm-browser/types.d.ts +21 -0
- package/node_modules/uuid/dist/esm-browser/types.js +1 -0
- package/node_modules/uuid/dist/esm-browser/uuid-bin.d.ts +1 -0
- package/node_modules/uuid/dist/esm-browser/uuid-bin.js +70 -0
- package/node_modules/uuid/dist/esm-browser/v1.d.ts +11 -0
- package/node_modules/uuid/dist/esm-browser/v1.js +75 -117
- package/node_modules/uuid/dist/esm-browser/v1ToV6.d.ts +2 -0
- package/node_modules/uuid/dist/esm-browser/v1ToV6.js +6 -16
- package/node_modules/uuid/dist/esm-browser/v3.d.ts +9 -0
- package/node_modules/uuid/dist/esm-browser/v3.js +8 -3
- package/node_modules/uuid/dist/esm-browser/v35.d.ts +7 -0
- package/node_modules/uuid/dist/esm-browser/v35.js +28 -47
- package/node_modules/uuid/dist/esm-browser/v4.d.ts +4 -0
- package/node_modules/uuid/dist/esm-browser/v4.js +21 -19
- package/node_modules/uuid/dist/esm-browser/v5.d.ts +9 -0
- package/node_modules/uuid/dist/esm-browser/v5.js +8 -3
- package/node_modules/uuid/dist/esm-browser/v6.d.ts +4 -0
- package/node_modules/uuid/dist/esm-browser/v6.js +13 -32
- package/node_modules/uuid/dist/esm-browser/v6ToV1.d.ts +2 -0
- package/node_modules/uuid/dist/esm-browser/v6ToV1.js +5 -15
- package/node_modules/uuid/dist/esm-browser/v7.d.ts +9 -0
- package/node_modules/uuid/dist/esm-browser/v7.js +58 -139
- package/node_modules/uuid/dist/esm-browser/validate.d.ts +2 -0
- package/node_modules/uuid/dist/esm-browser/validate.js +2 -2
- package/node_modules/uuid/dist/esm-browser/version.d.ts +2 -0
- package/node_modules/uuid/dist/esm-browser/version.js +5 -5
- package/node_modules/uuid/package.json +65 -75
- package/package.json +6 -6
- package/tak-registration.js +1 -4
- package/node_modules/@types/node/globals.global.d.ts +0 -1
- package/node_modules/point-in-polygon-hao/.eslintrc +0 -10
- package/node_modules/point-in-polygon-hao/CHANGES.md +0 -8
- package/node_modules/point-in-polygon-hao/FUNDING.yml +0 -2
- package/node_modules/point-in-polygon-hao/dist/pointInPolygon.mjs +0 -76
- package/node_modules/point-in-polygon-hao/rollup.config.js +0 -19
- package/node_modules/point-in-polygon-hao/src/index.js +0 -74
- package/node_modules/polygon-clipping/LICENSE.md +0 -11
- package/node_modules/polygon-clipping/dist/polygon-clipping.cjs.js +0 -1803
- package/node_modules/polygon-clipping/dist/polygon-clipping.d.ts +0 -14
- package/node_modules/polygon-clipping/dist/polygon-clipping.esm.js +0 -1532
- package/node_modules/polygon-clipping/dist/polygon-clipping.umd.js +0 -2496
- package/node_modules/polygon-clipping/dist/polygon-clipping.umd.min.js +0 -24
- package/node_modules/polygon-clipping/dist/polygon-clipping.umd.min.js.map +0 -1
- package/node_modules/polygon-clipping/package.json +0 -79
- package/node_modules/splaytree/Readme.md +0 -222
- package/node_modules/splaytree/dist/splay.esm.js +0 -686
- package/node_modules/splaytree/dist/splay.esm.js.map +0 -1
- package/node_modules/splaytree/dist/splay.js +0 -694
- package/node_modules/splaytree/dist/splay.js.map +0 -1
- package/node_modules/splaytree/package.json +0 -91
- package/node_modules/splaytree/src/index.ts +0 -679
- package/node_modules/splaytree/src/node.ts +0 -15
- package/node_modules/splaytree/src/types.ts +0 -2
- package/node_modules/splaytree/typings/index.d.ts +0 -82
- package/node_modules/splaytree/typings/node.d.ts +0 -8
- package/node_modules/splaytree/typings/types.d.ts +0 -2
- package/node_modules/uuid/CHANGELOG.md +0 -292
- package/node_modules/uuid/CONTRIBUTING.md +0 -18
- package/node_modules/uuid/dist/bin/uuid +0 -2
- package/node_modules/uuid/dist/commonjs-browser/index.js +0 -104
- package/node_modules/uuid/dist/commonjs-browser/max.js +0 -7
- package/node_modules/uuid/dist/commonjs-browser/md5.js +0 -200
- package/node_modules/uuid/dist/commonjs-browser/native.js +0 -10
- package/node_modules/uuid/dist/commonjs-browser/nil.js +0 -7
- package/node_modules/uuid/dist/commonjs-browser/parse.js +0 -44
- package/node_modules/uuid/dist/commonjs-browser/regex.js +0 -7
- package/node_modules/uuid/dist/commonjs-browser/rng.js +0 -23
- package/node_modules/uuid/dist/commonjs-browser/sha1.js +0 -82
- package/node_modules/uuid/dist/commonjs-browser/stringify.js +0 -38
- package/node_modules/uuid/dist/commonjs-browser/v1.js +0 -131
- package/node_modules/uuid/dist/commonjs-browser/v1ToV6.js +0 -26
- package/node_modules/uuid/dist/commonjs-browser/v3.js +0 -11
- package/node_modules/uuid/dist/commonjs-browser/v35.js +0 -63
- package/node_modules/uuid/dist/commonjs-browser/v4.js +0 -32
- package/node_modules/uuid/dist/commonjs-browser/v5.js +0 -11
- package/node_modules/uuid/dist/commonjs-browser/v6.js +0 -42
- package/node_modules/uuid/dist/commonjs-browser/v6ToV1.js +0 -26
- package/node_modules/uuid/dist/commonjs-browser/v7.js +0 -152
- package/node_modules/uuid/dist/commonjs-browser/validate.js +0 -12
- package/node_modules/uuid/dist/commonjs-browser/version.js +0 -15
- package/node_modules/uuid/dist/esm-node/max.js +0 -1
- package/node_modules/uuid/dist/esm-node/md5.js +0 -10
- package/node_modules/uuid/dist/esm-node/native.js +0 -4
- package/node_modules/uuid/dist/esm-node/nil.js +0 -1
- package/node_modules/uuid/dist/esm-node/parse.js +0 -37
- package/node_modules/uuid/dist/esm-node/rng.js +0 -10
- package/node_modules/uuid/dist/esm-node/sha1.js +0 -10
- package/node_modules/uuid/dist/esm-node/stringify.js +0 -31
- package/node_modules/uuid/dist/esm-node/v1.js +0 -125
- package/node_modules/uuid/dist/esm-node/v1ToV6.js +0 -20
- package/node_modules/uuid/dist/esm-node/v3.js +0 -4
- package/node_modules/uuid/dist/esm-node/v35.js +0 -55
- package/node_modules/uuid/dist/esm-node/v4.js +0 -25
- package/node_modules/uuid/dist/esm-node/v5.js +0 -4
- package/node_modules/uuid/dist/esm-node/v6.js +0 -32
- package/node_modules/uuid/dist/esm-node/v6ToV1.js +0 -20
- package/node_modules/uuid/dist/esm-node/v7.js +0 -146
- package/node_modules/uuid/dist/esm-node/validate.js +0 -5
- package/node_modules/uuid/dist/esm-node/version.js +0 -8
- package/node_modules/uuid/dist/index.js +0 -104
- package/node_modules/uuid/dist/max.js +0 -7
- package/node_modules/uuid/dist/md5-browser.js +0 -200
- package/node_modules/uuid/dist/md5.js +0 -17
- package/node_modules/uuid/dist/native-browser.js +0 -10
- package/node_modules/uuid/dist/native.js +0 -11
- package/node_modules/uuid/dist/nil.js +0 -7
- package/node_modules/uuid/dist/parse.js +0 -44
- package/node_modules/uuid/dist/regex.js +0 -7
- package/node_modules/uuid/dist/rng-browser.js +0 -23
- package/node_modules/uuid/dist/rng.js +0 -17
- package/node_modules/uuid/dist/sha1-browser.js +0 -82
- package/node_modules/uuid/dist/sha1.js +0 -17
- package/node_modules/uuid/dist/stringify.js +0 -38
- package/node_modules/uuid/dist/uuid-bin.js +0 -75
- package/node_modules/uuid/dist/v1.js +0 -131
- package/node_modules/uuid/dist/v1ToV6.js +0 -26
- package/node_modules/uuid/dist/v3.js +0 -11
- package/node_modules/uuid/dist/v35.js +0 -63
- package/node_modules/uuid/dist/v4.js +0 -32
- package/node_modules/uuid/dist/v5.js +0 -11
- package/node_modules/uuid/dist/v6.js +0 -38
- package/node_modules/uuid/dist/v6ToV1.js +0 -26
- package/node_modules/uuid/dist/v7.js +0 -152
- package/node_modules/uuid/dist/validate.js +0 -12
- package/node_modules/uuid/dist/version.js +0 -15
- package/node_modules/uuid/wrapper.mjs +0 -15
- /package/node_modules/point-in-polygon-hao/{index.d.ts → dist/cjs/index.d.cts} +0 -0
- /package/node_modules/{polygon-clipping → point-in-polygon-hao}/node_modules/robust-predicates/LICENSE +0 -0
- /package/node_modules/{polygon-clipping → point-in-polygon-hao}/node_modules/robust-predicates/README.md +0 -0
- /package/node_modules/{polygon-clipping → point-in-polygon-hao}/node_modules/robust-predicates/esm/incircle.js +0 -0
- /package/node_modules/{polygon-clipping → point-in-polygon-hao}/node_modules/robust-predicates/esm/insphere.js +0 -0
- /package/node_modules/{polygon-clipping → point-in-polygon-hao}/node_modules/robust-predicates/esm/orient2d.js +0 -0
- /package/node_modules/{polygon-clipping → point-in-polygon-hao}/node_modules/robust-predicates/esm/orient3d.js +0 -0
- /package/node_modules/{polygon-clipping → point-in-polygon-hao}/node_modules/robust-predicates/esm/util.js +0 -0
- /package/node_modules/{polygon-clipping → point-in-polygon-hao}/node_modules/robust-predicates/index.d.ts +0 -0
- /package/node_modules/{polygon-clipping → point-in-polygon-hao}/node_modules/robust-predicates/index.js +0 -0
- /package/node_modules/{polygon-clipping → point-in-polygon-hao}/node_modules/robust-predicates/package.json +0 -0
- /package/node_modules/{polygon-clipping → point-in-polygon-hao}/node_modules/robust-predicates/umd/incircle.js +0 -0
- /package/node_modules/{polygon-clipping → point-in-polygon-hao}/node_modules/robust-predicates/umd/incircle.min.js +0 -0
- /package/node_modules/{polygon-clipping → point-in-polygon-hao}/node_modules/robust-predicates/umd/insphere.js +0 -0
- /package/node_modules/{polygon-clipping → point-in-polygon-hao}/node_modules/robust-predicates/umd/insphere.min.js +0 -0
- /package/node_modules/{polygon-clipping → point-in-polygon-hao}/node_modules/robust-predicates/umd/orient2d.js +0 -0
- /package/node_modules/{polygon-clipping → point-in-polygon-hao}/node_modules/robust-predicates/umd/orient2d.min.js +0 -0
- /package/node_modules/{polygon-clipping → point-in-polygon-hao}/node_modules/robust-predicates/umd/orient3d.js +0 -0
- /package/node_modules/{polygon-clipping → point-in-polygon-hao}/node_modules/robust-predicates/umd/orient3d.min.js +0 -0
- /package/node_modules/{polygon-clipping → point-in-polygon-hao}/node_modules/robust-predicates/umd/predicates.js +0 -0
- /package/node_modules/{polygon-clipping → point-in-polygon-hao}/node_modules/robust-predicates/umd/predicates.min.js +0 -0
|
@@ -0,0 +1,4811 @@
|
|
|
1
|
+
// polyclip-ts v0.16.8 Copyright (c) 2022 Luiz Felipe Machado Barboza
|
|
2
|
+
(function (global, factory) {
|
|
3
|
+
typeof exports === 'object' && typeof module !== 'undefined' ? factory(exports) :
|
|
4
|
+
typeof define === 'function' && define.amd ? define(['exports'], factory) :
|
|
5
|
+
(global = typeof globalThis !== 'undefined' ? globalThis : global || self, factory(global.polyclip = global.polyclip || {}));
|
|
6
|
+
})(this, (function (exports) { 'use strict';
|
|
7
|
+
|
|
8
|
+
var version = "0.16.8";
|
|
9
|
+
|
|
10
|
+
var constant = (x) => {
|
|
11
|
+
return () => {
|
|
12
|
+
return x;
|
|
13
|
+
};
|
|
14
|
+
};
|
|
15
|
+
|
|
16
|
+
var compare$1 = (eps) => {
|
|
17
|
+
const almostEqual = eps ? (a, b) => b.minus(a).abs().isLessThanOrEqualTo(eps)
|
|
18
|
+
: constant(false);
|
|
19
|
+
return (a, b) => {
|
|
20
|
+
if (almostEqual(a, b))
|
|
21
|
+
return 0;
|
|
22
|
+
return a.comparedTo(b);
|
|
23
|
+
};
|
|
24
|
+
};
|
|
25
|
+
|
|
26
|
+
function orient (eps) {
|
|
27
|
+
const almostCollinear = eps ? (area2, ax, ay, cx, cy) => area2.exponentiatedBy(2).isLessThanOrEqualTo(cx.minus(ax).exponentiatedBy(2).plus(cy.minus(ay).exponentiatedBy(2))
|
|
28
|
+
.times(eps))
|
|
29
|
+
: constant(false);
|
|
30
|
+
return (a, b, c) => {
|
|
31
|
+
const ax = a.x, ay = a.y, cx = c.x, cy = c.y;
|
|
32
|
+
const area2 = ay.minus(cy).times(b.x.minus(cx)).minus(ax.minus(cx).times(b.y.minus(cy)));
|
|
33
|
+
if (almostCollinear(area2, ax, ay, cx, cy))
|
|
34
|
+
return 0;
|
|
35
|
+
return area2.comparedTo(0);
|
|
36
|
+
};
|
|
37
|
+
}
|
|
38
|
+
|
|
39
|
+
/*
|
|
40
|
+
* bignumber.js v9.1.0
|
|
41
|
+
* A JavaScript library for arbitrary-precision arithmetic.
|
|
42
|
+
* https://github.com/MikeMcl/bignumber.js
|
|
43
|
+
* Copyright (c) 2022 Michael Mclaughlin <M8ch88l@gmail.com>
|
|
44
|
+
* MIT Licensed.
|
|
45
|
+
*
|
|
46
|
+
* BigNumber.prototype methods | BigNumber methods
|
|
47
|
+
* |
|
|
48
|
+
* absoluteValue abs | clone
|
|
49
|
+
* comparedTo | config set
|
|
50
|
+
* decimalPlaces dp | DECIMAL_PLACES
|
|
51
|
+
* dividedBy div | ROUNDING_MODE
|
|
52
|
+
* dividedToIntegerBy idiv | EXPONENTIAL_AT
|
|
53
|
+
* exponentiatedBy pow | RANGE
|
|
54
|
+
* integerValue | CRYPTO
|
|
55
|
+
* isEqualTo eq | MODULO_MODE
|
|
56
|
+
* isFinite | POW_PRECISION
|
|
57
|
+
* isGreaterThan gt | FORMAT
|
|
58
|
+
* isGreaterThanOrEqualTo gte | ALPHABET
|
|
59
|
+
* isInteger | isBigNumber
|
|
60
|
+
* isLessThan lt | maximum max
|
|
61
|
+
* isLessThanOrEqualTo lte | minimum min
|
|
62
|
+
* isNaN | random
|
|
63
|
+
* isNegative | sum
|
|
64
|
+
* isPositive |
|
|
65
|
+
* isZero |
|
|
66
|
+
* minus |
|
|
67
|
+
* modulo mod |
|
|
68
|
+
* multipliedBy times |
|
|
69
|
+
* negated |
|
|
70
|
+
* plus |
|
|
71
|
+
* precision sd |
|
|
72
|
+
* shiftedBy |
|
|
73
|
+
* squareRoot sqrt |
|
|
74
|
+
* toExponential |
|
|
75
|
+
* toFixed |
|
|
76
|
+
* toFormat |
|
|
77
|
+
* toFraction |
|
|
78
|
+
* toJSON |
|
|
79
|
+
* toNumber |
|
|
80
|
+
* toPrecision |
|
|
81
|
+
* toString |
|
|
82
|
+
* valueOf |
|
|
83
|
+
*
|
|
84
|
+
*/
|
|
85
|
+
|
|
86
|
+
|
|
87
|
+
var
|
|
88
|
+
isNumeric = /^-?(?:\d+(?:\.\d*)?|\.\d+)(?:e[+-]?\d+)?$/i,
|
|
89
|
+
mathceil = Math.ceil,
|
|
90
|
+
mathfloor = Math.floor,
|
|
91
|
+
|
|
92
|
+
bignumberError = '[BigNumber Error] ',
|
|
93
|
+
tooManyDigits = bignumberError + 'Number primitive has more than 15 significant digits: ',
|
|
94
|
+
|
|
95
|
+
BASE = 1e14,
|
|
96
|
+
LOG_BASE = 14,
|
|
97
|
+
MAX_SAFE_INTEGER = 0x1fffffffffffff, // 2^53 - 1
|
|
98
|
+
// MAX_INT32 = 0x7fffffff, // 2^31 - 1
|
|
99
|
+
POWS_TEN = [1, 10, 100, 1e3, 1e4, 1e5, 1e6, 1e7, 1e8, 1e9, 1e10, 1e11, 1e12, 1e13],
|
|
100
|
+
SQRT_BASE = 1e7,
|
|
101
|
+
|
|
102
|
+
// EDITABLE
|
|
103
|
+
// The limit on the value of DECIMAL_PLACES, TO_EXP_NEG, TO_EXP_POS, MIN_EXP, MAX_EXP, and
|
|
104
|
+
// the arguments to toExponential, toFixed, toFormat, and toPrecision.
|
|
105
|
+
MAX = 1E9; // 0 to MAX_INT32
|
|
106
|
+
|
|
107
|
+
|
|
108
|
+
/*
|
|
109
|
+
* Create and return a BigNumber constructor.
|
|
110
|
+
*/
|
|
111
|
+
function clone(configObject) {
|
|
112
|
+
var div, convertBase, parseNumeric,
|
|
113
|
+
P = BigNumber.prototype = { constructor: BigNumber, toString: null, valueOf: null },
|
|
114
|
+
ONE = new BigNumber(1),
|
|
115
|
+
|
|
116
|
+
|
|
117
|
+
//----------------------------- EDITABLE CONFIG DEFAULTS -------------------------------
|
|
118
|
+
|
|
119
|
+
|
|
120
|
+
// The default values below must be integers within the inclusive ranges stated.
|
|
121
|
+
// The values can also be changed at run-time using BigNumber.set.
|
|
122
|
+
|
|
123
|
+
// The maximum number of decimal places for operations involving division.
|
|
124
|
+
DECIMAL_PLACES = 20, // 0 to MAX
|
|
125
|
+
|
|
126
|
+
// The rounding mode used when rounding to the above decimal places, and when using
|
|
127
|
+
// toExponential, toFixed, toFormat and toPrecision, and round (default value).
|
|
128
|
+
// UP 0 Away from zero.
|
|
129
|
+
// DOWN 1 Towards zero.
|
|
130
|
+
// CEIL 2 Towards +Infinity.
|
|
131
|
+
// FLOOR 3 Towards -Infinity.
|
|
132
|
+
// HALF_UP 4 Towards nearest neighbour. If equidistant, up.
|
|
133
|
+
// HALF_DOWN 5 Towards nearest neighbour. If equidistant, down.
|
|
134
|
+
// HALF_EVEN 6 Towards nearest neighbour. If equidistant, towards even neighbour.
|
|
135
|
+
// HALF_CEIL 7 Towards nearest neighbour. If equidistant, towards +Infinity.
|
|
136
|
+
// HALF_FLOOR 8 Towards nearest neighbour. If equidistant, towards -Infinity.
|
|
137
|
+
ROUNDING_MODE = 4, // 0 to 8
|
|
138
|
+
|
|
139
|
+
// EXPONENTIAL_AT : [TO_EXP_NEG , TO_EXP_POS]
|
|
140
|
+
|
|
141
|
+
// The exponent value at and beneath which toString returns exponential notation.
|
|
142
|
+
// Number type: -7
|
|
143
|
+
TO_EXP_NEG = -7, // 0 to -MAX
|
|
144
|
+
|
|
145
|
+
// The exponent value at and above which toString returns exponential notation.
|
|
146
|
+
// Number type: 21
|
|
147
|
+
TO_EXP_POS = 21, // 0 to MAX
|
|
148
|
+
|
|
149
|
+
// RANGE : [MIN_EXP, MAX_EXP]
|
|
150
|
+
|
|
151
|
+
// The minimum exponent value, beneath which underflow to zero occurs.
|
|
152
|
+
// Number type: -324 (5e-324)
|
|
153
|
+
MIN_EXP = -1e7, // -1 to -MAX
|
|
154
|
+
|
|
155
|
+
// The maximum exponent value, above which overflow to Infinity occurs.
|
|
156
|
+
// Number type: 308 (1.7976931348623157e+308)
|
|
157
|
+
// For MAX_EXP > 1e7, e.g. new BigNumber('1e100000000').plus(1) may be slow.
|
|
158
|
+
MAX_EXP = 1e7, // 1 to MAX
|
|
159
|
+
|
|
160
|
+
// Whether to use cryptographically-secure random number generation, if available.
|
|
161
|
+
CRYPTO = false, // true or false
|
|
162
|
+
|
|
163
|
+
// The modulo mode used when calculating the modulus: a mod n.
|
|
164
|
+
// The quotient (q = a / n) is calculated according to the corresponding rounding mode.
|
|
165
|
+
// The remainder (r) is calculated as: r = a - n * q.
|
|
166
|
+
//
|
|
167
|
+
// UP 0 The remainder is positive if the dividend is negative, else is negative.
|
|
168
|
+
// DOWN 1 The remainder has the same sign as the dividend.
|
|
169
|
+
// This modulo mode is commonly known as 'truncated division' and is
|
|
170
|
+
// equivalent to (a % n) in JavaScript.
|
|
171
|
+
// FLOOR 3 The remainder has the same sign as the divisor (Python %).
|
|
172
|
+
// HALF_EVEN 6 This modulo mode implements the IEEE 754 remainder function.
|
|
173
|
+
// EUCLID 9 Euclidian division. q = sign(n) * floor(a / abs(n)).
|
|
174
|
+
// The remainder is always positive.
|
|
175
|
+
//
|
|
176
|
+
// The truncated division, floored division, Euclidian division and IEEE 754 remainder
|
|
177
|
+
// modes are commonly used for the modulus operation.
|
|
178
|
+
// Although the other rounding modes can also be used, they may not give useful results.
|
|
179
|
+
MODULO_MODE = 1, // 0 to 9
|
|
180
|
+
|
|
181
|
+
// The maximum number of significant digits of the result of the exponentiatedBy operation.
|
|
182
|
+
// If POW_PRECISION is 0, there will be unlimited significant digits.
|
|
183
|
+
POW_PRECISION = 0, // 0 to MAX
|
|
184
|
+
|
|
185
|
+
// The format specification used by the BigNumber.prototype.toFormat method.
|
|
186
|
+
FORMAT = {
|
|
187
|
+
prefix: '',
|
|
188
|
+
groupSize: 3,
|
|
189
|
+
secondaryGroupSize: 0,
|
|
190
|
+
groupSeparator: ',',
|
|
191
|
+
decimalSeparator: '.',
|
|
192
|
+
fractionGroupSize: 0,
|
|
193
|
+
fractionGroupSeparator: '\xA0', // non-breaking space
|
|
194
|
+
suffix: ''
|
|
195
|
+
},
|
|
196
|
+
|
|
197
|
+
// The alphabet used for base conversion. It must be at least 2 characters long, with no '+',
|
|
198
|
+
// '-', '.', whitespace, or repeated character.
|
|
199
|
+
// '0123456789abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ$_'
|
|
200
|
+
ALPHABET = '0123456789abcdefghijklmnopqrstuvwxyz',
|
|
201
|
+
alphabetHasNormalDecimalDigits = true;
|
|
202
|
+
|
|
203
|
+
|
|
204
|
+
//------------------------------------------------------------------------------------------
|
|
205
|
+
|
|
206
|
+
|
|
207
|
+
// CONSTRUCTOR
|
|
208
|
+
|
|
209
|
+
|
|
210
|
+
/*
|
|
211
|
+
* The BigNumber constructor and exported function.
|
|
212
|
+
* Create and return a new instance of a BigNumber object.
|
|
213
|
+
*
|
|
214
|
+
* v {number|string|BigNumber} A numeric value.
|
|
215
|
+
* [b] {number} The base of v. Integer, 2 to ALPHABET.length inclusive.
|
|
216
|
+
*/
|
|
217
|
+
function BigNumber(v, b) {
|
|
218
|
+
var alphabet, c, caseChanged, e, i, isNum, len, str,
|
|
219
|
+
x = this;
|
|
220
|
+
|
|
221
|
+
// Enable constructor call without `new`.
|
|
222
|
+
if (!(x instanceof BigNumber)) return new BigNumber(v, b);
|
|
223
|
+
|
|
224
|
+
if (b == null) {
|
|
225
|
+
|
|
226
|
+
if (v && v._isBigNumber === true) {
|
|
227
|
+
x.s = v.s;
|
|
228
|
+
|
|
229
|
+
if (!v.c || v.e > MAX_EXP) {
|
|
230
|
+
x.c = x.e = null;
|
|
231
|
+
} else if (v.e < MIN_EXP) {
|
|
232
|
+
x.c = [x.e = 0];
|
|
233
|
+
} else {
|
|
234
|
+
x.e = v.e;
|
|
235
|
+
x.c = v.c.slice();
|
|
236
|
+
}
|
|
237
|
+
|
|
238
|
+
return;
|
|
239
|
+
}
|
|
240
|
+
|
|
241
|
+
if ((isNum = typeof v == 'number') && v * 0 == 0) {
|
|
242
|
+
|
|
243
|
+
// Use `1 / n` to handle minus zero also.
|
|
244
|
+
x.s = 1 / v < 0 ? (v = -v, -1) : 1;
|
|
245
|
+
|
|
246
|
+
// Fast path for integers, where n < 2147483648 (2**31).
|
|
247
|
+
if (v === ~~v) {
|
|
248
|
+
for (e = 0, i = v; i >= 10; i /= 10, e++);
|
|
249
|
+
|
|
250
|
+
if (e > MAX_EXP) {
|
|
251
|
+
x.c = x.e = null;
|
|
252
|
+
} else {
|
|
253
|
+
x.e = e;
|
|
254
|
+
x.c = [v];
|
|
255
|
+
}
|
|
256
|
+
|
|
257
|
+
return;
|
|
258
|
+
}
|
|
259
|
+
|
|
260
|
+
str = String(v);
|
|
261
|
+
} else {
|
|
262
|
+
|
|
263
|
+
if (!isNumeric.test(str = String(v))) return parseNumeric(x, str, isNum);
|
|
264
|
+
|
|
265
|
+
x.s = str.charCodeAt(0) == 45 ? (str = str.slice(1), -1) : 1;
|
|
266
|
+
}
|
|
267
|
+
|
|
268
|
+
// Decimal point?
|
|
269
|
+
if ((e = str.indexOf('.')) > -1) str = str.replace('.', '');
|
|
270
|
+
|
|
271
|
+
// Exponential form?
|
|
272
|
+
if ((i = str.search(/e/i)) > 0) {
|
|
273
|
+
|
|
274
|
+
// Determine exponent.
|
|
275
|
+
if (e < 0) e = i;
|
|
276
|
+
e += +str.slice(i + 1);
|
|
277
|
+
str = str.substring(0, i);
|
|
278
|
+
} else if (e < 0) {
|
|
279
|
+
|
|
280
|
+
// Integer.
|
|
281
|
+
e = str.length;
|
|
282
|
+
}
|
|
283
|
+
|
|
284
|
+
} else {
|
|
285
|
+
|
|
286
|
+
// '[BigNumber Error] Base {not a primitive number|not an integer|out of range}: {b}'
|
|
287
|
+
intCheck(b, 2, ALPHABET.length, 'Base');
|
|
288
|
+
|
|
289
|
+
// Allow exponential notation to be used with base 10 argument, while
|
|
290
|
+
// also rounding to DECIMAL_PLACES as with other bases.
|
|
291
|
+
if (b == 10 && alphabetHasNormalDecimalDigits) {
|
|
292
|
+
x = new BigNumber(v);
|
|
293
|
+
return round(x, DECIMAL_PLACES + x.e + 1, ROUNDING_MODE);
|
|
294
|
+
}
|
|
295
|
+
|
|
296
|
+
str = String(v);
|
|
297
|
+
|
|
298
|
+
if (isNum = typeof v == 'number') {
|
|
299
|
+
|
|
300
|
+
// Avoid potential interpretation of Infinity and NaN as base 44+ values.
|
|
301
|
+
if (v * 0 != 0) return parseNumeric(x, str, isNum, b);
|
|
302
|
+
|
|
303
|
+
x.s = 1 / v < 0 ? (str = str.slice(1), -1) : 1;
|
|
304
|
+
|
|
305
|
+
// '[BigNumber Error] Number primitive has more than 15 significant digits: {n}'
|
|
306
|
+
if (BigNumber.DEBUG && str.replace(/^0\.0*|\./, '').length > 15) {
|
|
307
|
+
throw Error
|
|
308
|
+
(tooManyDigits + v);
|
|
309
|
+
}
|
|
310
|
+
} else {
|
|
311
|
+
x.s = str.charCodeAt(0) === 45 ? (str = str.slice(1), -1) : 1;
|
|
312
|
+
}
|
|
313
|
+
|
|
314
|
+
alphabet = ALPHABET.slice(0, b);
|
|
315
|
+
e = i = 0;
|
|
316
|
+
|
|
317
|
+
// Check that str is a valid base b number.
|
|
318
|
+
// Don't use RegExp, so alphabet can contain special characters.
|
|
319
|
+
for (len = str.length; i < len; i++) {
|
|
320
|
+
if (alphabet.indexOf(c = str.charAt(i)) < 0) {
|
|
321
|
+
if (c == '.') {
|
|
322
|
+
|
|
323
|
+
// If '.' is not the first character and it has not be found before.
|
|
324
|
+
if (i > e) {
|
|
325
|
+
e = len;
|
|
326
|
+
continue;
|
|
327
|
+
}
|
|
328
|
+
} else if (!caseChanged) {
|
|
329
|
+
|
|
330
|
+
// Allow e.g. hexadecimal 'FF' as well as 'ff'.
|
|
331
|
+
if (str == str.toUpperCase() && (str = str.toLowerCase()) ||
|
|
332
|
+
str == str.toLowerCase() && (str = str.toUpperCase())) {
|
|
333
|
+
caseChanged = true;
|
|
334
|
+
i = -1;
|
|
335
|
+
e = 0;
|
|
336
|
+
continue;
|
|
337
|
+
}
|
|
338
|
+
}
|
|
339
|
+
|
|
340
|
+
return parseNumeric(x, String(v), isNum, b);
|
|
341
|
+
}
|
|
342
|
+
}
|
|
343
|
+
|
|
344
|
+
// Prevent later check for length on converted number.
|
|
345
|
+
isNum = false;
|
|
346
|
+
str = convertBase(str, b, 10, x.s);
|
|
347
|
+
|
|
348
|
+
// Decimal point?
|
|
349
|
+
if ((e = str.indexOf('.')) > -1) str = str.replace('.', '');
|
|
350
|
+
else e = str.length;
|
|
351
|
+
}
|
|
352
|
+
|
|
353
|
+
// Determine leading zeros.
|
|
354
|
+
for (i = 0; str.charCodeAt(i) === 48; i++);
|
|
355
|
+
|
|
356
|
+
// Determine trailing zeros.
|
|
357
|
+
for (len = str.length; str.charCodeAt(--len) === 48;);
|
|
358
|
+
|
|
359
|
+
if (str = str.slice(i, ++len)) {
|
|
360
|
+
len -= i;
|
|
361
|
+
|
|
362
|
+
// '[BigNumber Error] Number primitive has more than 15 significant digits: {n}'
|
|
363
|
+
if (isNum && BigNumber.DEBUG &&
|
|
364
|
+
len > 15 && (v > MAX_SAFE_INTEGER || v !== mathfloor(v))) {
|
|
365
|
+
throw Error
|
|
366
|
+
(tooManyDigits + (x.s * v));
|
|
367
|
+
}
|
|
368
|
+
|
|
369
|
+
// Overflow?
|
|
370
|
+
if ((e = e - i - 1) > MAX_EXP) {
|
|
371
|
+
|
|
372
|
+
// Infinity.
|
|
373
|
+
x.c = x.e = null;
|
|
374
|
+
|
|
375
|
+
// Underflow?
|
|
376
|
+
} else if (e < MIN_EXP) {
|
|
377
|
+
|
|
378
|
+
// Zero.
|
|
379
|
+
x.c = [x.e = 0];
|
|
380
|
+
} else {
|
|
381
|
+
x.e = e;
|
|
382
|
+
x.c = [];
|
|
383
|
+
|
|
384
|
+
// Transform base
|
|
385
|
+
|
|
386
|
+
// e is the base 10 exponent.
|
|
387
|
+
// i is where to slice str to get the first element of the coefficient array.
|
|
388
|
+
i = (e + 1) % LOG_BASE;
|
|
389
|
+
if (e < 0) i += LOG_BASE; // i < 1
|
|
390
|
+
|
|
391
|
+
if (i < len) {
|
|
392
|
+
if (i) x.c.push(+str.slice(0, i));
|
|
393
|
+
|
|
394
|
+
for (len -= LOG_BASE; i < len;) {
|
|
395
|
+
x.c.push(+str.slice(i, i += LOG_BASE));
|
|
396
|
+
}
|
|
397
|
+
|
|
398
|
+
i = LOG_BASE - (str = str.slice(i)).length;
|
|
399
|
+
} else {
|
|
400
|
+
i -= len;
|
|
401
|
+
}
|
|
402
|
+
|
|
403
|
+
for (; i--; str += '0');
|
|
404
|
+
x.c.push(+str);
|
|
405
|
+
}
|
|
406
|
+
} else {
|
|
407
|
+
|
|
408
|
+
// Zero.
|
|
409
|
+
x.c = [x.e = 0];
|
|
410
|
+
}
|
|
411
|
+
}
|
|
412
|
+
|
|
413
|
+
|
|
414
|
+
// CONSTRUCTOR PROPERTIES
|
|
415
|
+
|
|
416
|
+
|
|
417
|
+
BigNumber.clone = clone;
|
|
418
|
+
|
|
419
|
+
BigNumber.ROUND_UP = 0;
|
|
420
|
+
BigNumber.ROUND_DOWN = 1;
|
|
421
|
+
BigNumber.ROUND_CEIL = 2;
|
|
422
|
+
BigNumber.ROUND_FLOOR = 3;
|
|
423
|
+
BigNumber.ROUND_HALF_UP = 4;
|
|
424
|
+
BigNumber.ROUND_HALF_DOWN = 5;
|
|
425
|
+
BigNumber.ROUND_HALF_EVEN = 6;
|
|
426
|
+
BigNumber.ROUND_HALF_CEIL = 7;
|
|
427
|
+
BigNumber.ROUND_HALF_FLOOR = 8;
|
|
428
|
+
BigNumber.EUCLID = 9;
|
|
429
|
+
|
|
430
|
+
|
|
431
|
+
/*
|
|
432
|
+
* Configure infrequently-changing library-wide settings.
|
|
433
|
+
*
|
|
434
|
+
* Accept an object with the following optional properties (if the value of a property is
|
|
435
|
+
* a number, it must be an integer within the inclusive range stated):
|
|
436
|
+
*
|
|
437
|
+
* DECIMAL_PLACES {number} 0 to MAX
|
|
438
|
+
* ROUNDING_MODE {number} 0 to 8
|
|
439
|
+
* EXPONENTIAL_AT {number|number[]} -MAX to MAX or [-MAX to 0, 0 to MAX]
|
|
440
|
+
* RANGE {number|number[]} -MAX to MAX (not zero) or [-MAX to -1, 1 to MAX]
|
|
441
|
+
* CRYPTO {boolean} true or false
|
|
442
|
+
* MODULO_MODE {number} 0 to 9
|
|
443
|
+
* POW_PRECISION {number} 0 to MAX
|
|
444
|
+
* ALPHABET {string} A string of two or more unique characters which does
|
|
445
|
+
* not contain '.'.
|
|
446
|
+
* FORMAT {object} An object with some of the following properties:
|
|
447
|
+
* prefix {string}
|
|
448
|
+
* groupSize {number}
|
|
449
|
+
* secondaryGroupSize {number}
|
|
450
|
+
* groupSeparator {string}
|
|
451
|
+
* decimalSeparator {string}
|
|
452
|
+
* fractionGroupSize {number}
|
|
453
|
+
* fractionGroupSeparator {string}
|
|
454
|
+
* suffix {string}
|
|
455
|
+
*
|
|
456
|
+
* (The values assigned to the above FORMAT object properties are not checked for validity.)
|
|
457
|
+
*
|
|
458
|
+
* E.g.
|
|
459
|
+
* BigNumber.config({ DECIMAL_PLACES : 20, ROUNDING_MODE : 4 })
|
|
460
|
+
*
|
|
461
|
+
* Ignore properties/parameters set to null or undefined, except for ALPHABET.
|
|
462
|
+
*
|
|
463
|
+
* Return an object with the properties current values.
|
|
464
|
+
*/
|
|
465
|
+
BigNumber.config = BigNumber.set = function (obj) {
|
|
466
|
+
var p, v;
|
|
467
|
+
|
|
468
|
+
if (obj != null) {
|
|
469
|
+
|
|
470
|
+
if (typeof obj == 'object') {
|
|
471
|
+
|
|
472
|
+
// DECIMAL_PLACES {number} Integer, 0 to MAX inclusive.
|
|
473
|
+
// '[BigNumber Error] DECIMAL_PLACES {not a primitive number|not an integer|out of range}: {v}'
|
|
474
|
+
if (obj.hasOwnProperty(p = 'DECIMAL_PLACES')) {
|
|
475
|
+
v = obj[p];
|
|
476
|
+
intCheck(v, 0, MAX, p);
|
|
477
|
+
DECIMAL_PLACES = v;
|
|
478
|
+
}
|
|
479
|
+
|
|
480
|
+
// ROUNDING_MODE {number} Integer, 0 to 8 inclusive.
|
|
481
|
+
// '[BigNumber Error] ROUNDING_MODE {not a primitive number|not an integer|out of range}: {v}'
|
|
482
|
+
if (obj.hasOwnProperty(p = 'ROUNDING_MODE')) {
|
|
483
|
+
v = obj[p];
|
|
484
|
+
intCheck(v, 0, 8, p);
|
|
485
|
+
ROUNDING_MODE = v;
|
|
486
|
+
}
|
|
487
|
+
|
|
488
|
+
// EXPONENTIAL_AT {number|number[]}
|
|
489
|
+
// Integer, -MAX to MAX inclusive or
|
|
490
|
+
// [integer -MAX to 0 inclusive, 0 to MAX inclusive].
|
|
491
|
+
// '[BigNumber Error] EXPONENTIAL_AT {not a primitive number|not an integer|out of range}: {v}'
|
|
492
|
+
if (obj.hasOwnProperty(p = 'EXPONENTIAL_AT')) {
|
|
493
|
+
v = obj[p];
|
|
494
|
+
if (v && v.pop) {
|
|
495
|
+
intCheck(v[0], -MAX, 0, p);
|
|
496
|
+
intCheck(v[1], 0, MAX, p);
|
|
497
|
+
TO_EXP_NEG = v[0];
|
|
498
|
+
TO_EXP_POS = v[1];
|
|
499
|
+
} else {
|
|
500
|
+
intCheck(v, -MAX, MAX, p);
|
|
501
|
+
TO_EXP_NEG = -(TO_EXP_POS = v < 0 ? -v : v);
|
|
502
|
+
}
|
|
503
|
+
}
|
|
504
|
+
|
|
505
|
+
// RANGE {number|number[]} Non-zero integer, -MAX to MAX inclusive or
|
|
506
|
+
// [integer -MAX to -1 inclusive, integer 1 to MAX inclusive].
|
|
507
|
+
// '[BigNumber Error] RANGE {not a primitive number|not an integer|out of range|cannot be zero}: {v}'
|
|
508
|
+
if (obj.hasOwnProperty(p = 'RANGE')) {
|
|
509
|
+
v = obj[p];
|
|
510
|
+
if (v && v.pop) {
|
|
511
|
+
intCheck(v[0], -MAX, -1, p);
|
|
512
|
+
intCheck(v[1], 1, MAX, p);
|
|
513
|
+
MIN_EXP = v[0];
|
|
514
|
+
MAX_EXP = v[1];
|
|
515
|
+
} else {
|
|
516
|
+
intCheck(v, -MAX, MAX, p);
|
|
517
|
+
if (v) {
|
|
518
|
+
MIN_EXP = -(MAX_EXP = v < 0 ? -v : v);
|
|
519
|
+
} else {
|
|
520
|
+
throw Error
|
|
521
|
+
(bignumberError + p + ' cannot be zero: ' + v);
|
|
522
|
+
}
|
|
523
|
+
}
|
|
524
|
+
}
|
|
525
|
+
|
|
526
|
+
// CRYPTO {boolean} true or false.
|
|
527
|
+
// '[BigNumber Error] CRYPTO not true or false: {v}'
|
|
528
|
+
// '[BigNumber Error] crypto unavailable'
|
|
529
|
+
if (obj.hasOwnProperty(p = 'CRYPTO')) {
|
|
530
|
+
v = obj[p];
|
|
531
|
+
if (v === !!v) {
|
|
532
|
+
if (v) {
|
|
533
|
+
if (typeof crypto != 'undefined' && crypto &&
|
|
534
|
+
(crypto.getRandomValues || crypto.randomBytes)) {
|
|
535
|
+
CRYPTO = v;
|
|
536
|
+
} else {
|
|
537
|
+
CRYPTO = !v;
|
|
538
|
+
throw Error
|
|
539
|
+
(bignumberError + 'crypto unavailable');
|
|
540
|
+
}
|
|
541
|
+
} else {
|
|
542
|
+
CRYPTO = v;
|
|
543
|
+
}
|
|
544
|
+
} else {
|
|
545
|
+
throw Error
|
|
546
|
+
(bignumberError + p + ' not true or false: ' + v);
|
|
547
|
+
}
|
|
548
|
+
}
|
|
549
|
+
|
|
550
|
+
// MODULO_MODE {number} Integer, 0 to 9 inclusive.
|
|
551
|
+
// '[BigNumber Error] MODULO_MODE {not a primitive number|not an integer|out of range}: {v}'
|
|
552
|
+
if (obj.hasOwnProperty(p = 'MODULO_MODE')) {
|
|
553
|
+
v = obj[p];
|
|
554
|
+
intCheck(v, 0, 9, p);
|
|
555
|
+
MODULO_MODE = v;
|
|
556
|
+
}
|
|
557
|
+
|
|
558
|
+
// POW_PRECISION {number} Integer, 0 to MAX inclusive.
|
|
559
|
+
// '[BigNumber Error] POW_PRECISION {not a primitive number|not an integer|out of range}: {v}'
|
|
560
|
+
if (obj.hasOwnProperty(p = 'POW_PRECISION')) {
|
|
561
|
+
v = obj[p];
|
|
562
|
+
intCheck(v, 0, MAX, p);
|
|
563
|
+
POW_PRECISION = v;
|
|
564
|
+
}
|
|
565
|
+
|
|
566
|
+
// FORMAT {object}
|
|
567
|
+
// '[BigNumber Error] FORMAT not an object: {v}'
|
|
568
|
+
if (obj.hasOwnProperty(p = 'FORMAT')) {
|
|
569
|
+
v = obj[p];
|
|
570
|
+
if (typeof v == 'object') FORMAT = v;
|
|
571
|
+
else throw Error
|
|
572
|
+
(bignumberError + p + ' not an object: ' + v);
|
|
573
|
+
}
|
|
574
|
+
|
|
575
|
+
// ALPHABET {string}
|
|
576
|
+
// '[BigNumber Error] ALPHABET invalid: {v}'
|
|
577
|
+
if (obj.hasOwnProperty(p = 'ALPHABET')) {
|
|
578
|
+
v = obj[p];
|
|
579
|
+
|
|
580
|
+
// Disallow if less than two characters,
|
|
581
|
+
// or if it contains '+', '-', '.', whitespace, or a repeated character.
|
|
582
|
+
if (typeof v == 'string' && !/^.?$|[+\-.\s]|(.).*\1/.test(v)) {
|
|
583
|
+
alphabetHasNormalDecimalDigits = v.slice(0, 10) == '0123456789';
|
|
584
|
+
ALPHABET = v;
|
|
585
|
+
} else {
|
|
586
|
+
throw Error
|
|
587
|
+
(bignumberError + p + ' invalid: ' + v);
|
|
588
|
+
}
|
|
589
|
+
}
|
|
590
|
+
|
|
591
|
+
} else {
|
|
592
|
+
|
|
593
|
+
// '[BigNumber Error] Object expected: {v}'
|
|
594
|
+
throw Error
|
|
595
|
+
(bignumberError + 'Object expected: ' + obj);
|
|
596
|
+
}
|
|
597
|
+
}
|
|
598
|
+
|
|
599
|
+
return {
|
|
600
|
+
DECIMAL_PLACES: DECIMAL_PLACES,
|
|
601
|
+
ROUNDING_MODE: ROUNDING_MODE,
|
|
602
|
+
EXPONENTIAL_AT: [TO_EXP_NEG, TO_EXP_POS],
|
|
603
|
+
RANGE: [MIN_EXP, MAX_EXP],
|
|
604
|
+
CRYPTO: CRYPTO,
|
|
605
|
+
MODULO_MODE: MODULO_MODE,
|
|
606
|
+
POW_PRECISION: POW_PRECISION,
|
|
607
|
+
FORMAT: FORMAT,
|
|
608
|
+
ALPHABET: ALPHABET
|
|
609
|
+
};
|
|
610
|
+
};
|
|
611
|
+
|
|
612
|
+
|
|
613
|
+
/*
|
|
614
|
+
* Return true if v is a BigNumber instance, otherwise return false.
|
|
615
|
+
*
|
|
616
|
+
* If BigNumber.DEBUG is true, throw if a BigNumber instance is not well-formed.
|
|
617
|
+
*
|
|
618
|
+
* v {any}
|
|
619
|
+
*
|
|
620
|
+
* '[BigNumber Error] Invalid BigNumber: {v}'
|
|
621
|
+
*/
|
|
622
|
+
BigNumber.isBigNumber = function (v) {
|
|
623
|
+
if (!v || v._isBigNumber !== true) return false;
|
|
624
|
+
if (!BigNumber.DEBUG) return true;
|
|
625
|
+
|
|
626
|
+
var i, n,
|
|
627
|
+
c = v.c,
|
|
628
|
+
e = v.e,
|
|
629
|
+
s = v.s;
|
|
630
|
+
|
|
631
|
+
out: if ({}.toString.call(c) == '[object Array]') {
|
|
632
|
+
|
|
633
|
+
if ((s === 1 || s === -1) && e >= -MAX && e <= MAX && e === mathfloor(e)) {
|
|
634
|
+
|
|
635
|
+
// If the first element is zero, the BigNumber value must be zero.
|
|
636
|
+
if (c[0] === 0) {
|
|
637
|
+
if (e === 0 && c.length === 1) return true;
|
|
638
|
+
break out;
|
|
639
|
+
}
|
|
640
|
+
|
|
641
|
+
// Calculate number of digits that c[0] should have, based on the exponent.
|
|
642
|
+
i = (e + 1) % LOG_BASE;
|
|
643
|
+
if (i < 1) i += LOG_BASE;
|
|
644
|
+
|
|
645
|
+
// Calculate number of digits of c[0].
|
|
646
|
+
//if (Math.ceil(Math.log(c[0] + 1) / Math.LN10) == i) {
|
|
647
|
+
if (String(c[0]).length == i) {
|
|
648
|
+
|
|
649
|
+
for (i = 0; i < c.length; i++) {
|
|
650
|
+
n = c[i];
|
|
651
|
+
if (n < 0 || n >= BASE || n !== mathfloor(n)) break out;
|
|
652
|
+
}
|
|
653
|
+
|
|
654
|
+
// Last element cannot be zero, unless it is the only element.
|
|
655
|
+
if (n !== 0) return true;
|
|
656
|
+
}
|
|
657
|
+
}
|
|
658
|
+
|
|
659
|
+
// Infinity/NaN
|
|
660
|
+
} else if (c === null && e === null && (s === null || s === 1 || s === -1)) {
|
|
661
|
+
return true;
|
|
662
|
+
}
|
|
663
|
+
|
|
664
|
+
throw Error
|
|
665
|
+
(bignumberError + 'Invalid BigNumber: ' + v);
|
|
666
|
+
};
|
|
667
|
+
|
|
668
|
+
|
|
669
|
+
/*
|
|
670
|
+
* Return a new BigNumber whose value is the maximum of the arguments.
|
|
671
|
+
*
|
|
672
|
+
* arguments {number|string|BigNumber}
|
|
673
|
+
*/
|
|
674
|
+
BigNumber.maximum = BigNumber.max = function () {
|
|
675
|
+
return maxOrMin(arguments, P.lt);
|
|
676
|
+
};
|
|
677
|
+
|
|
678
|
+
|
|
679
|
+
/*
|
|
680
|
+
* Return a new BigNumber whose value is the minimum of the arguments.
|
|
681
|
+
*
|
|
682
|
+
* arguments {number|string|BigNumber}
|
|
683
|
+
*/
|
|
684
|
+
BigNumber.minimum = BigNumber.min = function () {
|
|
685
|
+
return maxOrMin(arguments, P.gt);
|
|
686
|
+
};
|
|
687
|
+
|
|
688
|
+
|
|
689
|
+
/*
|
|
690
|
+
* Return a new BigNumber with a random value equal to or greater than 0 and less than 1,
|
|
691
|
+
* and with dp, or DECIMAL_PLACES if dp is omitted, decimal places (or less if trailing
|
|
692
|
+
* zeros are produced).
|
|
693
|
+
*
|
|
694
|
+
* [dp] {number} Decimal places. Integer, 0 to MAX inclusive.
|
|
695
|
+
*
|
|
696
|
+
* '[BigNumber Error] Argument {not a primitive number|not an integer|out of range}: {dp}'
|
|
697
|
+
* '[BigNumber Error] crypto unavailable'
|
|
698
|
+
*/
|
|
699
|
+
BigNumber.random = (function () {
|
|
700
|
+
var pow2_53 = 0x20000000000000;
|
|
701
|
+
|
|
702
|
+
// Return a 53 bit integer n, where 0 <= n < 9007199254740992.
|
|
703
|
+
// Check if Math.random() produces more than 32 bits of randomness.
|
|
704
|
+
// If it does, assume at least 53 bits are produced, otherwise assume at least 30 bits.
|
|
705
|
+
// 0x40000000 is 2^30, 0x800000 is 2^23, 0x1fffff is 2^21 - 1.
|
|
706
|
+
var random53bitInt = (Math.random() * pow2_53) & 0x1fffff
|
|
707
|
+
? function () { return mathfloor(Math.random() * pow2_53); }
|
|
708
|
+
: function () { return ((Math.random() * 0x40000000 | 0) * 0x800000) +
|
|
709
|
+
(Math.random() * 0x800000 | 0); };
|
|
710
|
+
|
|
711
|
+
return function (dp) {
|
|
712
|
+
var a, b, e, k, v,
|
|
713
|
+
i = 0,
|
|
714
|
+
c = [],
|
|
715
|
+
rand = new BigNumber(ONE);
|
|
716
|
+
|
|
717
|
+
if (dp == null) dp = DECIMAL_PLACES;
|
|
718
|
+
else intCheck(dp, 0, MAX);
|
|
719
|
+
|
|
720
|
+
k = mathceil(dp / LOG_BASE);
|
|
721
|
+
|
|
722
|
+
if (CRYPTO) {
|
|
723
|
+
|
|
724
|
+
// Browsers supporting crypto.getRandomValues.
|
|
725
|
+
if (crypto.getRandomValues) {
|
|
726
|
+
|
|
727
|
+
a = crypto.getRandomValues(new Uint32Array(k *= 2));
|
|
728
|
+
|
|
729
|
+
for (; i < k;) {
|
|
730
|
+
|
|
731
|
+
// 53 bits:
|
|
732
|
+
// ((Math.pow(2, 32) - 1) * Math.pow(2, 21)).toString(2)
|
|
733
|
+
// 11111 11111111 11111111 11111111 11100000 00000000 00000000
|
|
734
|
+
// ((Math.pow(2, 32) - 1) >>> 11).toString(2)
|
|
735
|
+
// 11111 11111111 11111111
|
|
736
|
+
// 0x20000 is 2^21.
|
|
737
|
+
v = a[i] * 0x20000 + (a[i + 1] >>> 11);
|
|
738
|
+
|
|
739
|
+
// Rejection sampling:
|
|
740
|
+
// 0 <= v < 9007199254740992
|
|
741
|
+
// Probability that v >= 9e15, is
|
|
742
|
+
// 7199254740992 / 9007199254740992 ~= 0.0008, i.e. 1 in 1251
|
|
743
|
+
if (v >= 9e15) {
|
|
744
|
+
b = crypto.getRandomValues(new Uint32Array(2));
|
|
745
|
+
a[i] = b[0];
|
|
746
|
+
a[i + 1] = b[1];
|
|
747
|
+
} else {
|
|
748
|
+
|
|
749
|
+
// 0 <= v <= 8999999999999999
|
|
750
|
+
// 0 <= (v % 1e14) <= 99999999999999
|
|
751
|
+
c.push(v % 1e14);
|
|
752
|
+
i += 2;
|
|
753
|
+
}
|
|
754
|
+
}
|
|
755
|
+
i = k / 2;
|
|
756
|
+
|
|
757
|
+
// Node.js supporting crypto.randomBytes.
|
|
758
|
+
} else if (crypto.randomBytes) {
|
|
759
|
+
|
|
760
|
+
// buffer
|
|
761
|
+
a = crypto.randomBytes(k *= 7);
|
|
762
|
+
|
|
763
|
+
for (; i < k;) {
|
|
764
|
+
|
|
765
|
+
// 0x1000000000000 is 2^48, 0x10000000000 is 2^40
|
|
766
|
+
// 0x100000000 is 2^32, 0x1000000 is 2^24
|
|
767
|
+
// 11111 11111111 11111111 11111111 11111111 11111111 11111111
|
|
768
|
+
// 0 <= v < 9007199254740992
|
|
769
|
+
v = ((a[i] & 31) * 0x1000000000000) + (a[i + 1] * 0x10000000000) +
|
|
770
|
+
(a[i + 2] * 0x100000000) + (a[i + 3] * 0x1000000) +
|
|
771
|
+
(a[i + 4] << 16) + (a[i + 5] << 8) + a[i + 6];
|
|
772
|
+
|
|
773
|
+
if (v >= 9e15) {
|
|
774
|
+
crypto.randomBytes(7).copy(a, i);
|
|
775
|
+
} else {
|
|
776
|
+
|
|
777
|
+
// 0 <= (v % 1e14) <= 99999999999999
|
|
778
|
+
c.push(v % 1e14);
|
|
779
|
+
i += 7;
|
|
780
|
+
}
|
|
781
|
+
}
|
|
782
|
+
i = k / 7;
|
|
783
|
+
} else {
|
|
784
|
+
CRYPTO = false;
|
|
785
|
+
throw Error
|
|
786
|
+
(bignumberError + 'crypto unavailable');
|
|
787
|
+
}
|
|
788
|
+
}
|
|
789
|
+
|
|
790
|
+
// Use Math.random.
|
|
791
|
+
if (!CRYPTO) {
|
|
792
|
+
|
|
793
|
+
for (; i < k;) {
|
|
794
|
+
v = random53bitInt();
|
|
795
|
+
if (v < 9e15) c[i++] = v % 1e14;
|
|
796
|
+
}
|
|
797
|
+
}
|
|
798
|
+
|
|
799
|
+
k = c[--i];
|
|
800
|
+
dp %= LOG_BASE;
|
|
801
|
+
|
|
802
|
+
// Convert trailing digits to zeros according to dp.
|
|
803
|
+
if (k && dp) {
|
|
804
|
+
v = POWS_TEN[LOG_BASE - dp];
|
|
805
|
+
c[i] = mathfloor(k / v) * v;
|
|
806
|
+
}
|
|
807
|
+
|
|
808
|
+
// Remove trailing elements which are zero.
|
|
809
|
+
for (; c[i] === 0; c.pop(), i--);
|
|
810
|
+
|
|
811
|
+
// Zero?
|
|
812
|
+
if (i < 0) {
|
|
813
|
+
c = [e = 0];
|
|
814
|
+
} else {
|
|
815
|
+
|
|
816
|
+
// Remove leading elements which are zero and adjust exponent accordingly.
|
|
817
|
+
for (e = -1 ; c[0] === 0; c.splice(0, 1), e -= LOG_BASE);
|
|
818
|
+
|
|
819
|
+
// Count the digits of the first element of c to determine leading zeros, and...
|
|
820
|
+
for (i = 1, v = c[0]; v >= 10; v /= 10, i++);
|
|
821
|
+
|
|
822
|
+
// adjust the exponent accordingly.
|
|
823
|
+
if (i < LOG_BASE) e -= LOG_BASE - i;
|
|
824
|
+
}
|
|
825
|
+
|
|
826
|
+
rand.e = e;
|
|
827
|
+
rand.c = c;
|
|
828
|
+
return rand;
|
|
829
|
+
};
|
|
830
|
+
})();
|
|
831
|
+
|
|
832
|
+
|
|
833
|
+
/*
|
|
834
|
+
* Return a BigNumber whose value is the sum of the arguments.
|
|
835
|
+
*
|
|
836
|
+
* arguments {number|string|BigNumber}
|
|
837
|
+
*/
|
|
838
|
+
BigNumber.sum = function () {
|
|
839
|
+
var i = 1,
|
|
840
|
+
args = arguments,
|
|
841
|
+
sum = new BigNumber(args[0]);
|
|
842
|
+
for (; i < args.length;) sum = sum.plus(args[i++]);
|
|
843
|
+
return sum;
|
|
844
|
+
};
|
|
845
|
+
|
|
846
|
+
|
|
847
|
+
// PRIVATE FUNCTIONS
|
|
848
|
+
|
|
849
|
+
|
|
850
|
+
// Called by BigNumber and BigNumber.prototype.toString.
|
|
851
|
+
convertBase = (function () {
|
|
852
|
+
var decimal = '0123456789';
|
|
853
|
+
|
|
854
|
+
/*
|
|
855
|
+
* Convert string of baseIn to an array of numbers of baseOut.
|
|
856
|
+
* Eg. toBaseOut('255', 10, 16) returns [15, 15].
|
|
857
|
+
* Eg. toBaseOut('ff', 16, 10) returns [2, 5, 5].
|
|
858
|
+
*/
|
|
859
|
+
function toBaseOut(str, baseIn, baseOut, alphabet) {
|
|
860
|
+
var j,
|
|
861
|
+
arr = [0],
|
|
862
|
+
arrL,
|
|
863
|
+
i = 0,
|
|
864
|
+
len = str.length;
|
|
865
|
+
|
|
866
|
+
for (; i < len;) {
|
|
867
|
+
for (arrL = arr.length; arrL--; arr[arrL] *= baseIn);
|
|
868
|
+
|
|
869
|
+
arr[0] += alphabet.indexOf(str.charAt(i++));
|
|
870
|
+
|
|
871
|
+
for (j = 0; j < arr.length; j++) {
|
|
872
|
+
|
|
873
|
+
if (arr[j] > baseOut - 1) {
|
|
874
|
+
if (arr[j + 1] == null) arr[j + 1] = 0;
|
|
875
|
+
arr[j + 1] += arr[j] / baseOut | 0;
|
|
876
|
+
arr[j] %= baseOut;
|
|
877
|
+
}
|
|
878
|
+
}
|
|
879
|
+
}
|
|
880
|
+
|
|
881
|
+
return arr.reverse();
|
|
882
|
+
}
|
|
883
|
+
|
|
884
|
+
// Convert a numeric string of baseIn to a numeric string of baseOut.
|
|
885
|
+
// If the caller is toString, we are converting from base 10 to baseOut.
|
|
886
|
+
// If the caller is BigNumber, we are converting from baseIn to base 10.
|
|
887
|
+
return function (str, baseIn, baseOut, sign, callerIsToString) {
|
|
888
|
+
var alphabet, d, e, k, r, x, xc, y,
|
|
889
|
+
i = str.indexOf('.'),
|
|
890
|
+
dp = DECIMAL_PLACES,
|
|
891
|
+
rm = ROUNDING_MODE;
|
|
892
|
+
|
|
893
|
+
// Non-integer.
|
|
894
|
+
if (i >= 0) {
|
|
895
|
+
k = POW_PRECISION;
|
|
896
|
+
|
|
897
|
+
// Unlimited precision.
|
|
898
|
+
POW_PRECISION = 0;
|
|
899
|
+
str = str.replace('.', '');
|
|
900
|
+
y = new BigNumber(baseIn);
|
|
901
|
+
x = y.pow(str.length - i);
|
|
902
|
+
POW_PRECISION = k;
|
|
903
|
+
|
|
904
|
+
// Convert str as if an integer, then restore the fraction part by dividing the
|
|
905
|
+
// result by its base raised to a power.
|
|
906
|
+
|
|
907
|
+
y.c = toBaseOut(toFixedPoint(coeffToString(x.c), x.e, '0'),
|
|
908
|
+
10, baseOut, decimal);
|
|
909
|
+
y.e = y.c.length;
|
|
910
|
+
}
|
|
911
|
+
|
|
912
|
+
// Convert the number as integer.
|
|
913
|
+
|
|
914
|
+
xc = toBaseOut(str, baseIn, baseOut, callerIsToString
|
|
915
|
+
? (alphabet = ALPHABET, decimal)
|
|
916
|
+
: (alphabet = decimal, ALPHABET));
|
|
917
|
+
|
|
918
|
+
// xc now represents str as an integer and converted to baseOut. e is the exponent.
|
|
919
|
+
e = k = xc.length;
|
|
920
|
+
|
|
921
|
+
// Remove trailing zeros.
|
|
922
|
+
for (; xc[--k] == 0; xc.pop());
|
|
923
|
+
|
|
924
|
+
// Zero?
|
|
925
|
+
if (!xc[0]) return alphabet.charAt(0);
|
|
926
|
+
|
|
927
|
+
// Does str represent an integer? If so, no need for the division.
|
|
928
|
+
if (i < 0) {
|
|
929
|
+
--e;
|
|
930
|
+
} else {
|
|
931
|
+
x.c = xc;
|
|
932
|
+
x.e = e;
|
|
933
|
+
|
|
934
|
+
// The sign is needed for correct rounding.
|
|
935
|
+
x.s = sign;
|
|
936
|
+
x = div(x, y, dp, rm, baseOut);
|
|
937
|
+
xc = x.c;
|
|
938
|
+
r = x.r;
|
|
939
|
+
e = x.e;
|
|
940
|
+
}
|
|
941
|
+
|
|
942
|
+
// xc now represents str converted to baseOut.
|
|
943
|
+
|
|
944
|
+
// THe index of the rounding digit.
|
|
945
|
+
d = e + dp + 1;
|
|
946
|
+
|
|
947
|
+
// The rounding digit: the digit to the right of the digit that may be rounded up.
|
|
948
|
+
i = xc[d];
|
|
949
|
+
|
|
950
|
+
// Look at the rounding digits and mode to determine whether to round up.
|
|
951
|
+
|
|
952
|
+
k = baseOut / 2;
|
|
953
|
+
r = r || d < 0 || xc[d + 1] != null;
|
|
954
|
+
|
|
955
|
+
r = rm < 4 ? (i != null || r) && (rm == 0 || rm == (x.s < 0 ? 3 : 2))
|
|
956
|
+
: i > k || i == k &&(rm == 4 || r || rm == 6 && xc[d - 1] & 1 ||
|
|
957
|
+
rm == (x.s < 0 ? 8 : 7));
|
|
958
|
+
|
|
959
|
+
// If the index of the rounding digit is not greater than zero, or xc represents
|
|
960
|
+
// zero, then the result of the base conversion is zero or, if rounding up, a value
|
|
961
|
+
// such as 0.00001.
|
|
962
|
+
if (d < 1 || !xc[0]) {
|
|
963
|
+
|
|
964
|
+
// 1^-dp or 0
|
|
965
|
+
str = r ? toFixedPoint(alphabet.charAt(1), -dp, alphabet.charAt(0)) : alphabet.charAt(0);
|
|
966
|
+
} else {
|
|
967
|
+
|
|
968
|
+
// Truncate xc to the required number of decimal places.
|
|
969
|
+
xc.length = d;
|
|
970
|
+
|
|
971
|
+
// Round up?
|
|
972
|
+
if (r) {
|
|
973
|
+
|
|
974
|
+
// Rounding up may mean the previous digit has to be rounded up and so on.
|
|
975
|
+
for (--baseOut; ++xc[--d] > baseOut;) {
|
|
976
|
+
xc[d] = 0;
|
|
977
|
+
|
|
978
|
+
if (!d) {
|
|
979
|
+
++e;
|
|
980
|
+
xc = [1].concat(xc);
|
|
981
|
+
}
|
|
982
|
+
}
|
|
983
|
+
}
|
|
984
|
+
|
|
985
|
+
// Determine trailing zeros.
|
|
986
|
+
for (k = xc.length; !xc[--k];);
|
|
987
|
+
|
|
988
|
+
// E.g. [4, 11, 15] becomes 4bf.
|
|
989
|
+
for (i = 0, str = ''; i <= k; str += alphabet.charAt(xc[i++]));
|
|
990
|
+
|
|
991
|
+
// Add leading zeros, decimal point and trailing zeros as required.
|
|
992
|
+
str = toFixedPoint(str, e, alphabet.charAt(0));
|
|
993
|
+
}
|
|
994
|
+
|
|
995
|
+
// The caller will add the sign.
|
|
996
|
+
return str;
|
|
997
|
+
};
|
|
998
|
+
})();
|
|
999
|
+
|
|
1000
|
+
|
|
1001
|
+
// Perform division in the specified base. Called by div and convertBase.
|
|
1002
|
+
div = (function () {
|
|
1003
|
+
|
|
1004
|
+
// Assume non-zero x and k.
|
|
1005
|
+
function multiply(x, k, base) {
|
|
1006
|
+
var m, temp, xlo, xhi,
|
|
1007
|
+
carry = 0,
|
|
1008
|
+
i = x.length,
|
|
1009
|
+
klo = k % SQRT_BASE,
|
|
1010
|
+
khi = k / SQRT_BASE | 0;
|
|
1011
|
+
|
|
1012
|
+
for (x = x.slice(); i--;) {
|
|
1013
|
+
xlo = x[i] % SQRT_BASE;
|
|
1014
|
+
xhi = x[i] / SQRT_BASE | 0;
|
|
1015
|
+
m = khi * xlo + xhi * klo;
|
|
1016
|
+
temp = klo * xlo + ((m % SQRT_BASE) * SQRT_BASE) + carry;
|
|
1017
|
+
carry = (temp / base | 0) + (m / SQRT_BASE | 0) + khi * xhi;
|
|
1018
|
+
x[i] = temp % base;
|
|
1019
|
+
}
|
|
1020
|
+
|
|
1021
|
+
if (carry) x = [carry].concat(x);
|
|
1022
|
+
|
|
1023
|
+
return x;
|
|
1024
|
+
}
|
|
1025
|
+
|
|
1026
|
+
function compare(a, b, aL, bL) {
|
|
1027
|
+
var i, cmp;
|
|
1028
|
+
|
|
1029
|
+
if (aL != bL) {
|
|
1030
|
+
cmp = aL > bL ? 1 : -1;
|
|
1031
|
+
} else {
|
|
1032
|
+
|
|
1033
|
+
for (i = cmp = 0; i < aL; i++) {
|
|
1034
|
+
|
|
1035
|
+
if (a[i] != b[i]) {
|
|
1036
|
+
cmp = a[i] > b[i] ? 1 : -1;
|
|
1037
|
+
break;
|
|
1038
|
+
}
|
|
1039
|
+
}
|
|
1040
|
+
}
|
|
1041
|
+
|
|
1042
|
+
return cmp;
|
|
1043
|
+
}
|
|
1044
|
+
|
|
1045
|
+
function subtract(a, b, aL, base) {
|
|
1046
|
+
var i = 0;
|
|
1047
|
+
|
|
1048
|
+
// Subtract b from a.
|
|
1049
|
+
for (; aL--;) {
|
|
1050
|
+
a[aL] -= i;
|
|
1051
|
+
i = a[aL] < b[aL] ? 1 : 0;
|
|
1052
|
+
a[aL] = i * base + a[aL] - b[aL];
|
|
1053
|
+
}
|
|
1054
|
+
|
|
1055
|
+
// Remove leading zeros.
|
|
1056
|
+
for (; !a[0] && a.length > 1; a.splice(0, 1));
|
|
1057
|
+
}
|
|
1058
|
+
|
|
1059
|
+
// x: dividend, y: divisor.
|
|
1060
|
+
return function (x, y, dp, rm, base) {
|
|
1061
|
+
var cmp, e, i, more, n, prod, prodL, q, qc, rem, remL, rem0, xi, xL, yc0,
|
|
1062
|
+
yL, yz,
|
|
1063
|
+
s = x.s == y.s ? 1 : -1,
|
|
1064
|
+
xc = x.c,
|
|
1065
|
+
yc = y.c;
|
|
1066
|
+
|
|
1067
|
+
// Either NaN, Infinity or 0?
|
|
1068
|
+
if (!xc || !xc[0] || !yc || !yc[0]) {
|
|
1069
|
+
|
|
1070
|
+
return new BigNumber(
|
|
1071
|
+
|
|
1072
|
+
// Return NaN if either NaN, or both Infinity or 0.
|
|
1073
|
+
!x.s || !y.s || (xc ? yc && xc[0] == yc[0] : !yc) ? NaN :
|
|
1074
|
+
|
|
1075
|
+
// Return ±0 if x is ±0 or y is ±Infinity, or return ±Infinity as y is ±0.
|
|
1076
|
+
xc && xc[0] == 0 || !yc ? s * 0 : s / 0
|
|
1077
|
+
);
|
|
1078
|
+
}
|
|
1079
|
+
|
|
1080
|
+
q = new BigNumber(s);
|
|
1081
|
+
qc = q.c = [];
|
|
1082
|
+
e = x.e - y.e;
|
|
1083
|
+
s = dp + e + 1;
|
|
1084
|
+
|
|
1085
|
+
if (!base) {
|
|
1086
|
+
base = BASE;
|
|
1087
|
+
e = bitFloor(x.e / LOG_BASE) - bitFloor(y.e / LOG_BASE);
|
|
1088
|
+
s = s / LOG_BASE | 0;
|
|
1089
|
+
}
|
|
1090
|
+
|
|
1091
|
+
// Result exponent may be one less then the current value of e.
|
|
1092
|
+
// The coefficients of the BigNumbers from convertBase may have trailing zeros.
|
|
1093
|
+
for (i = 0; yc[i] == (xc[i] || 0); i++);
|
|
1094
|
+
|
|
1095
|
+
if (yc[i] > (xc[i] || 0)) e--;
|
|
1096
|
+
|
|
1097
|
+
if (s < 0) {
|
|
1098
|
+
qc.push(1);
|
|
1099
|
+
more = true;
|
|
1100
|
+
} else {
|
|
1101
|
+
xL = xc.length;
|
|
1102
|
+
yL = yc.length;
|
|
1103
|
+
i = 0;
|
|
1104
|
+
s += 2;
|
|
1105
|
+
|
|
1106
|
+
// Normalise xc and yc so highest order digit of yc is >= base / 2.
|
|
1107
|
+
|
|
1108
|
+
n = mathfloor(base / (yc[0] + 1));
|
|
1109
|
+
|
|
1110
|
+
// Not necessary, but to handle odd bases where yc[0] == (base / 2) - 1.
|
|
1111
|
+
// if (n > 1 || n++ == 1 && yc[0] < base / 2) {
|
|
1112
|
+
if (n > 1) {
|
|
1113
|
+
yc = multiply(yc, n, base);
|
|
1114
|
+
xc = multiply(xc, n, base);
|
|
1115
|
+
yL = yc.length;
|
|
1116
|
+
xL = xc.length;
|
|
1117
|
+
}
|
|
1118
|
+
|
|
1119
|
+
xi = yL;
|
|
1120
|
+
rem = xc.slice(0, yL);
|
|
1121
|
+
remL = rem.length;
|
|
1122
|
+
|
|
1123
|
+
// Add zeros to make remainder as long as divisor.
|
|
1124
|
+
for (; remL < yL; rem[remL++] = 0);
|
|
1125
|
+
yz = yc.slice();
|
|
1126
|
+
yz = [0].concat(yz);
|
|
1127
|
+
yc0 = yc[0];
|
|
1128
|
+
if (yc[1] >= base / 2) yc0++;
|
|
1129
|
+
// Not necessary, but to prevent trial digit n > base, when using base 3.
|
|
1130
|
+
// else if (base == 3 && yc0 == 1) yc0 = 1 + 1e-15;
|
|
1131
|
+
|
|
1132
|
+
do {
|
|
1133
|
+
n = 0;
|
|
1134
|
+
|
|
1135
|
+
// Compare divisor and remainder.
|
|
1136
|
+
cmp = compare(yc, rem, yL, remL);
|
|
1137
|
+
|
|
1138
|
+
// If divisor < remainder.
|
|
1139
|
+
if (cmp < 0) {
|
|
1140
|
+
|
|
1141
|
+
// Calculate trial digit, n.
|
|
1142
|
+
|
|
1143
|
+
rem0 = rem[0];
|
|
1144
|
+
if (yL != remL) rem0 = rem0 * base + (rem[1] || 0);
|
|
1145
|
+
|
|
1146
|
+
// n is how many times the divisor goes into the current remainder.
|
|
1147
|
+
n = mathfloor(rem0 / yc0);
|
|
1148
|
+
|
|
1149
|
+
// Algorithm:
|
|
1150
|
+
// product = divisor multiplied by trial digit (n).
|
|
1151
|
+
// Compare product and remainder.
|
|
1152
|
+
// If product is greater than remainder:
|
|
1153
|
+
// Subtract divisor from product, decrement trial digit.
|
|
1154
|
+
// Subtract product from remainder.
|
|
1155
|
+
// If product was less than remainder at the last compare:
|
|
1156
|
+
// Compare new remainder and divisor.
|
|
1157
|
+
// If remainder is greater than divisor:
|
|
1158
|
+
// Subtract divisor from remainder, increment trial digit.
|
|
1159
|
+
|
|
1160
|
+
if (n > 1) {
|
|
1161
|
+
|
|
1162
|
+
// n may be > base only when base is 3.
|
|
1163
|
+
if (n >= base) n = base - 1;
|
|
1164
|
+
|
|
1165
|
+
// product = divisor * trial digit.
|
|
1166
|
+
prod = multiply(yc, n, base);
|
|
1167
|
+
prodL = prod.length;
|
|
1168
|
+
remL = rem.length;
|
|
1169
|
+
|
|
1170
|
+
// Compare product and remainder.
|
|
1171
|
+
// If product > remainder then trial digit n too high.
|
|
1172
|
+
// n is 1 too high about 5% of the time, and is not known to have
|
|
1173
|
+
// ever been more than 1 too high.
|
|
1174
|
+
while (compare(prod, rem, prodL, remL) == 1) {
|
|
1175
|
+
n--;
|
|
1176
|
+
|
|
1177
|
+
// Subtract divisor from product.
|
|
1178
|
+
subtract(prod, yL < prodL ? yz : yc, prodL, base);
|
|
1179
|
+
prodL = prod.length;
|
|
1180
|
+
cmp = 1;
|
|
1181
|
+
}
|
|
1182
|
+
} else {
|
|
1183
|
+
|
|
1184
|
+
// n is 0 or 1, cmp is -1.
|
|
1185
|
+
// If n is 0, there is no need to compare yc and rem again below,
|
|
1186
|
+
// so change cmp to 1 to avoid it.
|
|
1187
|
+
// If n is 1, leave cmp as -1, so yc and rem are compared again.
|
|
1188
|
+
if (n == 0) {
|
|
1189
|
+
|
|
1190
|
+
// divisor < remainder, so n must be at least 1.
|
|
1191
|
+
cmp = n = 1;
|
|
1192
|
+
}
|
|
1193
|
+
|
|
1194
|
+
// product = divisor
|
|
1195
|
+
prod = yc.slice();
|
|
1196
|
+
prodL = prod.length;
|
|
1197
|
+
}
|
|
1198
|
+
|
|
1199
|
+
if (prodL < remL) prod = [0].concat(prod);
|
|
1200
|
+
|
|
1201
|
+
// Subtract product from remainder.
|
|
1202
|
+
subtract(rem, prod, remL, base);
|
|
1203
|
+
remL = rem.length;
|
|
1204
|
+
|
|
1205
|
+
// If product was < remainder.
|
|
1206
|
+
if (cmp == -1) {
|
|
1207
|
+
|
|
1208
|
+
// Compare divisor and new remainder.
|
|
1209
|
+
// If divisor < new remainder, subtract divisor from remainder.
|
|
1210
|
+
// Trial digit n too low.
|
|
1211
|
+
// n is 1 too low about 5% of the time, and very rarely 2 too low.
|
|
1212
|
+
while (compare(yc, rem, yL, remL) < 1) {
|
|
1213
|
+
n++;
|
|
1214
|
+
|
|
1215
|
+
// Subtract divisor from remainder.
|
|
1216
|
+
subtract(rem, yL < remL ? yz : yc, remL, base);
|
|
1217
|
+
remL = rem.length;
|
|
1218
|
+
}
|
|
1219
|
+
}
|
|
1220
|
+
} else if (cmp === 0) {
|
|
1221
|
+
n++;
|
|
1222
|
+
rem = [0];
|
|
1223
|
+
} // else cmp === 1 and n will be 0
|
|
1224
|
+
|
|
1225
|
+
// Add the next digit, n, to the result array.
|
|
1226
|
+
qc[i++] = n;
|
|
1227
|
+
|
|
1228
|
+
// Update the remainder.
|
|
1229
|
+
if (rem[0]) {
|
|
1230
|
+
rem[remL++] = xc[xi] || 0;
|
|
1231
|
+
} else {
|
|
1232
|
+
rem = [xc[xi]];
|
|
1233
|
+
remL = 1;
|
|
1234
|
+
}
|
|
1235
|
+
} while ((xi++ < xL || rem[0] != null) && s--);
|
|
1236
|
+
|
|
1237
|
+
more = rem[0] != null;
|
|
1238
|
+
|
|
1239
|
+
// Leading zero?
|
|
1240
|
+
if (!qc[0]) qc.splice(0, 1);
|
|
1241
|
+
}
|
|
1242
|
+
|
|
1243
|
+
if (base == BASE) {
|
|
1244
|
+
|
|
1245
|
+
// To calculate q.e, first get the number of digits of qc[0].
|
|
1246
|
+
for (i = 1, s = qc[0]; s >= 10; s /= 10, i++);
|
|
1247
|
+
|
|
1248
|
+
round(q, dp + (q.e = i + e * LOG_BASE - 1) + 1, rm, more);
|
|
1249
|
+
|
|
1250
|
+
// Caller is convertBase.
|
|
1251
|
+
} else {
|
|
1252
|
+
q.e = e;
|
|
1253
|
+
q.r = +more;
|
|
1254
|
+
}
|
|
1255
|
+
|
|
1256
|
+
return q;
|
|
1257
|
+
};
|
|
1258
|
+
})();
|
|
1259
|
+
|
|
1260
|
+
|
|
1261
|
+
/*
|
|
1262
|
+
* Return a string representing the value of BigNumber n in fixed-point or exponential
|
|
1263
|
+
* notation rounded to the specified decimal places or significant digits.
|
|
1264
|
+
*
|
|
1265
|
+
* n: a BigNumber.
|
|
1266
|
+
* i: the index of the last digit required (i.e. the digit that may be rounded up).
|
|
1267
|
+
* rm: the rounding mode.
|
|
1268
|
+
* id: 1 (toExponential) or 2 (toPrecision).
|
|
1269
|
+
*/
|
|
1270
|
+
function format(n, i, rm, id) {
|
|
1271
|
+
var c0, e, ne, len, str;
|
|
1272
|
+
|
|
1273
|
+
if (rm == null) rm = ROUNDING_MODE;
|
|
1274
|
+
else intCheck(rm, 0, 8);
|
|
1275
|
+
|
|
1276
|
+
if (!n.c) return n.toString();
|
|
1277
|
+
|
|
1278
|
+
c0 = n.c[0];
|
|
1279
|
+
ne = n.e;
|
|
1280
|
+
|
|
1281
|
+
if (i == null) {
|
|
1282
|
+
str = coeffToString(n.c);
|
|
1283
|
+
str = id == 1 || id == 2 && (ne <= TO_EXP_NEG || ne >= TO_EXP_POS)
|
|
1284
|
+
? toExponential(str, ne)
|
|
1285
|
+
: toFixedPoint(str, ne, '0');
|
|
1286
|
+
} else {
|
|
1287
|
+
n = round(new BigNumber(n), i, rm);
|
|
1288
|
+
|
|
1289
|
+
// n.e may have changed if the value was rounded up.
|
|
1290
|
+
e = n.e;
|
|
1291
|
+
|
|
1292
|
+
str = coeffToString(n.c);
|
|
1293
|
+
len = str.length;
|
|
1294
|
+
|
|
1295
|
+
// toPrecision returns exponential notation if the number of significant digits
|
|
1296
|
+
// specified is less than the number of digits necessary to represent the integer
|
|
1297
|
+
// part of the value in fixed-point notation.
|
|
1298
|
+
|
|
1299
|
+
// Exponential notation.
|
|
1300
|
+
if (id == 1 || id == 2 && (i <= e || e <= TO_EXP_NEG)) {
|
|
1301
|
+
|
|
1302
|
+
// Append zeros?
|
|
1303
|
+
for (; len < i; str += '0', len++);
|
|
1304
|
+
str = toExponential(str, e);
|
|
1305
|
+
|
|
1306
|
+
// Fixed-point notation.
|
|
1307
|
+
} else {
|
|
1308
|
+
i -= ne;
|
|
1309
|
+
str = toFixedPoint(str, e, '0');
|
|
1310
|
+
|
|
1311
|
+
// Append zeros?
|
|
1312
|
+
if (e + 1 > len) {
|
|
1313
|
+
if (--i > 0) for (str += '.'; i--; str += '0');
|
|
1314
|
+
} else {
|
|
1315
|
+
i += e - len;
|
|
1316
|
+
if (i > 0) {
|
|
1317
|
+
if (e + 1 == len) str += '.';
|
|
1318
|
+
for (; i--; str += '0');
|
|
1319
|
+
}
|
|
1320
|
+
}
|
|
1321
|
+
}
|
|
1322
|
+
}
|
|
1323
|
+
|
|
1324
|
+
return n.s < 0 && c0 ? '-' + str : str;
|
|
1325
|
+
}
|
|
1326
|
+
|
|
1327
|
+
|
|
1328
|
+
// Handle BigNumber.max and BigNumber.min.
|
|
1329
|
+
function maxOrMin(args, method) {
|
|
1330
|
+
var n,
|
|
1331
|
+
i = 1,
|
|
1332
|
+
m = new BigNumber(args[0]);
|
|
1333
|
+
|
|
1334
|
+
for (; i < args.length; i++) {
|
|
1335
|
+
n = new BigNumber(args[i]);
|
|
1336
|
+
|
|
1337
|
+
// If any number is NaN, return NaN.
|
|
1338
|
+
if (!n.s) {
|
|
1339
|
+
m = n;
|
|
1340
|
+
break;
|
|
1341
|
+
} else if (method.call(m, n)) {
|
|
1342
|
+
m = n;
|
|
1343
|
+
}
|
|
1344
|
+
}
|
|
1345
|
+
|
|
1346
|
+
return m;
|
|
1347
|
+
}
|
|
1348
|
+
|
|
1349
|
+
|
|
1350
|
+
/*
|
|
1351
|
+
* Strip trailing zeros, calculate base 10 exponent and check against MIN_EXP and MAX_EXP.
|
|
1352
|
+
* Called by minus, plus and times.
|
|
1353
|
+
*/
|
|
1354
|
+
function normalise(n, c, e) {
|
|
1355
|
+
var i = 1,
|
|
1356
|
+
j = c.length;
|
|
1357
|
+
|
|
1358
|
+
// Remove trailing zeros.
|
|
1359
|
+
for (; !c[--j]; c.pop());
|
|
1360
|
+
|
|
1361
|
+
// Calculate the base 10 exponent. First get the number of digits of c[0].
|
|
1362
|
+
for (j = c[0]; j >= 10; j /= 10, i++);
|
|
1363
|
+
|
|
1364
|
+
// Overflow?
|
|
1365
|
+
if ((e = i + e * LOG_BASE - 1) > MAX_EXP) {
|
|
1366
|
+
|
|
1367
|
+
// Infinity.
|
|
1368
|
+
n.c = n.e = null;
|
|
1369
|
+
|
|
1370
|
+
// Underflow?
|
|
1371
|
+
} else if (e < MIN_EXP) {
|
|
1372
|
+
|
|
1373
|
+
// Zero.
|
|
1374
|
+
n.c = [n.e = 0];
|
|
1375
|
+
} else {
|
|
1376
|
+
n.e = e;
|
|
1377
|
+
n.c = c;
|
|
1378
|
+
}
|
|
1379
|
+
|
|
1380
|
+
return n;
|
|
1381
|
+
}
|
|
1382
|
+
|
|
1383
|
+
|
|
1384
|
+
// Handle values that fail the validity test in BigNumber.
|
|
1385
|
+
parseNumeric = (function () {
|
|
1386
|
+
var basePrefix = /^(-?)0([xbo])(?=\w[\w.]*$)/i,
|
|
1387
|
+
dotAfter = /^([^.]+)\.$/,
|
|
1388
|
+
dotBefore = /^\.([^.]+)$/,
|
|
1389
|
+
isInfinityOrNaN = /^-?(Infinity|NaN)$/,
|
|
1390
|
+
whitespaceOrPlus = /^\s*\+(?=[\w.])|^\s+|\s+$/g;
|
|
1391
|
+
|
|
1392
|
+
return function (x, str, isNum, b) {
|
|
1393
|
+
var base,
|
|
1394
|
+
s = isNum ? str : str.replace(whitespaceOrPlus, '');
|
|
1395
|
+
|
|
1396
|
+
// No exception on ±Infinity or NaN.
|
|
1397
|
+
if (isInfinityOrNaN.test(s)) {
|
|
1398
|
+
x.s = isNaN(s) ? null : s < 0 ? -1 : 1;
|
|
1399
|
+
} else {
|
|
1400
|
+
if (!isNum) {
|
|
1401
|
+
|
|
1402
|
+
// basePrefix = /^(-?)0([xbo])(?=\w[\w.]*$)/i
|
|
1403
|
+
s = s.replace(basePrefix, function (m, p1, p2) {
|
|
1404
|
+
base = (p2 = p2.toLowerCase()) == 'x' ? 16 : p2 == 'b' ? 2 : 8;
|
|
1405
|
+
return !b || b == base ? p1 : m;
|
|
1406
|
+
});
|
|
1407
|
+
|
|
1408
|
+
if (b) {
|
|
1409
|
+
base = b;
|
|
1410
|
+
|
|
1411
|
+
// E.g. '1.' to '1', '.1' to '0.1'
|
|
1412
|
+
s = s.replace(dotAfter, '$1').replace(dotBefore, '0.$1');
|
|
1413
|
+
}
|
|
1414
|
+
|
|
1415
|
+
if (str != s) return new BigNumber(s, base);
|
|
1416
|
+
}
|
|
1417
|
+
|
|
1418
|
+
// '[BigNumber Error] Not a number: {n}'
|
|
1419
|
+
// '[BigNumber Error] Not a base {b} number: {n}'
|
|
1420
|
+
if (BigNumber.DEBUG) {
|
|
1421
|
+
throw Error
|
|
1422
|
+
(bignumberError + 'Not a' + (b ? ' base ' + b : '') + ' number: ' + str);
|
|
1423
|
+
}
|
|
1424
|
+
|
|
1425
|
+
// NaN
|
|
1426
|
+
x.s = null;
|
|
1427
|
+
}
|
|
1428
|
+
|
|
1429
|
+
x.c = x.e = null;
|
|
1430
|
+
}
|
|
1431
|
+
})();
|
|
1432
|
+
|
|
1433
|
+
|
|
1434
|
+
/*
|
|
1435
|
+
* Round x to sd significant digits using rounding mode rm. Check for over/under-flow.
|
|
1436
|
+
* If r is truthy, it is known that there are more digits after the rounding digit.
|
|
1437
|
+
*/
|
|
1438
|
+
function round(x, sd, rm, r) {
|
|
1439
|
+
var d, i, j, k, n, ni, rd,
|
|
1440
|
+
xc = x.c,
|
|
1441
|
+
pows10 = POWS_TEN;
|
|
1442
|
+
|
|
1443
|
+
// if x is not Infinity or NaN...
|
|
1444
|
+
if (xc) {
|
|
1445
|
+
|
|
1446
|
+
// rd is the rounding digit, i.e. the digit after the digit that may be rounded up.
|
|
1447
|
+
// n is a base 1e14 number, the value of the element of array x.c containing rd.
|
|
1448
|
+
// ni is the index of n within x.c.
|
|
1449
|
+
// d is the number of digits of n.
|
|
1450
|
+
// i is the index of rd within n including leading zeros.
|
|
1451
|
+
// j is the actual index of rd within n (if < 0, rd is a leading zero).
|
|
1452
|
+
out: {
|
|
1453
|
+
|
|
1454
|
+
// Get the number of digits of the first element of xc.
|
|
1455
|
+
for (d = 1, k = xc[0]; k >= 10; k /= 10, d++);
|
|
1456
|
+
i = sd - d;
|
|
1457
|
+
|
|
1458
|
+
// If the rounding digit is in the first element of xc...
|
|
1459
|
+
if (i < 0) {
|
|
1460
|
+
i += LOG_BASE;
|
|
1461
|
+
j = sd;
|
|
1462
|
+
n = xc[ni = 0];
|
|
1463
|
+
|
|
1464
|
+
// Get the rounding digit at index j of n.
|
|
1465
|
+
rd = n / pows10[d - j - 1] % 10 | 0;
|
|
1466
|
+
} else {
|
|
1467
|
+
ni = mathceil((i + 1) / LOG_BASE);
|
|
1468
|
+
|
|
1469
|
+
if (ni >= xc.length) {
|
|
1470
|
+
|
|
1471
|
+
if (r) {
|
|
1472
|
+
|
|
1473
|
+
// Needed by sqrt.
|
|
1474
|
+
for (; xc.length <= ni; xc.push(0));
|
|
1475
|
+
n = rd = 0;
|
|
1476
|
+
d = 1;
|
|
1477
|
+
i %= LOG_BASE;
|
|
1478
|
+
j = i - LOG_BASE + 1;
|
|
1479
|
+
} else {
|
|
1480
|
+
break out;
|
|
1481
|
+
}
|
|
1482
|
+
} else {
|
|
1483
|
+
n = k = xc[ni];
|
|
1484
|
+
|
|
1485
|
+
// Get the number of digits of n.
|
|
1486
|
+
for (d = 1; k >= 10; k /= 10, d++);
|
|
1487
|
+
|
|
1488
|
+
// Get the index of rd within n.
|
|
1489
|
+
i %= LOG_BASE;
|
|
1490
|
+
|
|
1491
|
+
// Get the index of rd within n, adjusted for leading zeros.
|
|
1492
|
+
// The number of leading zeros of n is given by LOG_BASE - d.
|
|
1493
|
+
j = i - LOG_BASE + d;
|
|
1494
|
+
|
|
1495
|
+
// Get the rounding digit at index j of n.
|
|
1496
|
+
rd = j < 0 ? 0 : n / pows10[d - j - 1] % 10 | 0;
|
|
1497
|
+
}
|
|
1498
|
+
}
|
|
1499
|
+
|
|
1500
|
+
r = r || sd < 0 ||
|
|
1501
|
+
|
|
1502
|
+
// Are there any non-zero digits after the rounding digit?
|
|
1503
|
+
// The expression n % pows10[d - j - 1] returns all digits of n to the right
|
|
1504
|
+
// of the digit at j, e.g. if n is 908714 and j is 2, the expression gives 714.
|
|
1505
|
+
xc[ni + 1] != null || (j < 0 ? n : n % pows10[d - j - 1]);
|
|
1506
|
+
|
|
1507
|
+
r = rm < 4
|
|
1508
|
+
? (rd || r) && (rm == 0 || rm == (x.s < 0 ? 3 : 2))
|
|
1509
|
+
: rd > 5 || rd == 5 && (rm == 4 || r || rm == 6 &&
|
|
1510
|
+
|
|
1511
|
+
// Check whether the digit to the left of the rounding digit is odd.
|
|
1512
|
+
((i > 0 ? j > 0 ? n / pows10[d - j] : 0 : xc[ni - 1]) % 10) & 1 ||
|
|
1513
|
+
rm == (x.s < 0 ? 8 : 7));
|
|
1514
|
+
|
|
1515
|
+
if (sd < 1 || !xc[0]) {
|
|
1516
|
+
xc.length = 0;
|
|
1517
|
+
|
|
1518
|
+
if (r) {
|
|
1519
|
+
|
|
1520
|
+
// Convert sd to decimal places.
|
|
1521
|
+
sd -= x.e + 1;
|
|
1522
|
+
|
|
1523
|
+
// 1, 0.1, 0.01, 0.001, 0.0001 etc.
|
|
1524
|
+
xc[0] = pows10[(LOG_BASE - sd % LOG_BASE) % LOG_BASE];
|
|
1525
|
+
x.e = -sd || 0;
|
|
1526
|
+
} else {
|
|
1527
|
+
|
|
1528
|
+
// Zero.
|
|
1529
|
+
xc[0] = x.e = 0;
|
|
1530
|
+
}
|
|
1531
|
+
|
|
1532
|
+
return x;
|
|
1533
|
+
}
|
|
1534
|
+
|
|
1535
|
+
// Remove excess digits.
|
|
1536
|
+
if (i == 0) {
|
|
1537
|
+
xc.length = ni;
|
|
1538
|
+
k = 1;
|
|
1539
|
+
ni--;
|
|
1540
|
+
} else {
|
|
1541
|
+
xc.length = ni + 1;
|
|
1542
|
+
k = pows10[LOG_BASE - i];
|
|
1543
|
+
|
|
1544
|
+
// E.g. 56700 becomes 56000 if 7 is the rounding digit.
|
|
1545
|
+
// j > 0 means i > number of leading zeros of n.
|
|
1546
|
+
xc[ni] = j > 0 ? mathfloor(n / pows10[d - j] % pows10[j]) * k : 0;
|
|
1547
|
+
}
|
|
1548
|
+
|
|
1549
|
+
// Round up?
|
|
1550
|
+
if (r) {
|
|
1551
|
+
|
|
1552
|
+
for (; ;) {
|
|
1553
|
+
|
|
1554
|
+
// If the digit to be rounded up is in the first element of xc...
|
|
1555
|
+
if (ni == 0) {
|
|
1556
|
+
|
|
1557
|
+
// i will be the length of xc[0] before k is added.
|
|
1558
|
+
for (i = 1, j = xc[0]; j >= 10; j /= 10, i++);
|
|
1559
|
+
j = xc[0] += k;
|
|
1560
|
+
for (k = 1; j >= 10; j /= 10, k++);
|
|
1561
|
+
|
|
1562
|
+
// if i != k the length has increased.
|
|
1563
|
+
if (i != k) {
|
|
1564
|
+
x.e++;
|
|
1565
|
+
if (xc[0] == BASE) xc[0] = 1;
|
|
1566
|
+
}
|
|
1567
|
+
|
|
1568
|
+
break;
|
|
1569
|
+
} else {
|
|
1570
|
+
xc[ni] += k;
|
|
1571
|
+
if (xc[ni] != BASE) break;
|
|
1572
|
+
xc[ni--] = 0;
|
|
1573
|
+
k = 1;
|
|
1574
|
+
}
|
|
1575
|
+
}
|
|
1576
|
+
}
|
|
1577
|
+
|
|
1578
|
+
// Remove trailing zeros.
|
|
1579
|
+
for (i = xc.length; xc[--i] === 0; xc.pop());
|
|
1580
|
+
}
|
|
1581
|
+
|
|
1582
|
+
// Overflow? Infinity.
|
|
1583
|
+
if (x.e > MAX_EXP) {
|
|
1584
|
+
x.c = x.e = null;
|
|
1585
|
+
|
|
1586
|
+
// Underflow? Zero.
|
|
1587
|
+
} else if (x.e < MIN_EXP) {
|
|
1588
|
+
x.c = [x.e = 0];
|
|
1589
|
+
}
|
|
1590
|
+
}
|
|
1591
|
+
|
|
1592
|
+
return x;
|
|
1593
|
+
}
|
|
1594
|
+
|
|
1595
|
+
|
|
1596
|
+
function valueOf(n) {
|
|
1597
|
+
var str,
|
|
1598
|
+
e = n.e;
|
|
1599
|
+
|
|
1600
|
+
if (e === null) return n.toString();
|
|
1601
|
+
|
|
1602
|
+
str = coeffToString(n.c);
|
|
1603
|
+
|
|
1604
|
+
str = e <= TO_EXP_NEG || e >= TO_EXP_POS
|
|
1605
|
+
? toExponential(str, e)
|
|
1606
|
+
: toFixedPoint(str, e, '0');
|
|
1607
|
+
|
|
1608
|
+
return n.s < 0 ? '-' + str : str;
|
|
1609
|
+
}
|
|
1610
|
+
|
|
1611
|
+
|
|
1612
|
+
// PROTOTYPE/INSTANCE METHODS
|
|
1613
|
+
|
|
1614
|
+
|
|
1615
|
+
/*
|
|
1616
|
+
* Return a new BigNumber whose value is the absolute value of this BigNumber.
|
|
1617
|
+
*/
|
|
1618
|
+
P.absoluteValue = P.abs = function () {
|
|
1619
|
+
var x = new BigNumber(this);
|
|
1620
|
+
if (x.s < 0) x.s = 1;
|
|
1621
|
+
return x;
|
|
1622
|
+
};
|
|
1623
|
+
|
|
1624
|
+
|
|
1625
|
+
/*
|
|
1626
|
+
* Return
|
|
1627
|
+
* 1 if the value of this BigNumber is greater than the value of BigNumber(y, b),
|
|
1628
|
+
* -1 if the value of this BigNumber is less than the value of BigNumber(y, b),
|
|
1629
|
+
* 0 if they have the same value,
|
|
1630
|
+
* or null if the value of either is NaN.
|
|
1631
|
+
*/
|
|
1632
|
+
P.comparedTo = function (y, b) {
|
|
1633
|
+
return compare(this, new BigNumber(y, b));
|
|
1634
|
+
};
|
|
1635
|
+
|
|
1636
|
+
|
|
1637
|
+
/*
|
|
1638
|
+
* If dp is undefined or null or true or false, return the number of decimal places of the
|
|
1639
|
+
* value of this BigNumber, or null if the value of this BigNumber is ±Infinity or NaN.
|
|
1640
|
+
*
|
|
1641
|
+
* Otherwise, if dp is a number, return a new BigNumber whose value is the value of this
|
|
1642
|
+
* BigNumber rounded to a maximum of dp decimal places using rounding mode rm, or
|
|
1643
|
+
* ROUNDING_MODE if rm is omitted.
|
|
1644
|
+
*
|
|
1645
|
+
* [dp] {number} Decimal places: integer, 0 to MAX inclusive.
|
|
1646
|
+
* [rm] {number} Rounding mode. Integer, 0 to 8 inclusive.
|
|
1647
|
+
*
|
|
1648
|
+
* '[BigNumber Error] Argument {not a primitive number|not an integer|out of range}: {dp|rm}'
|
|
1649
|
+
*/
|
|
1650
|
+
P.decimalPlaces = P.dp = function (dp, rm) {
|
|
1651
|
+
var c, n, v,
|
|
1652
|
+
x = this;
|
|
1653
|
+
|
|
1654
|
+
if (dp != null) {
|
|
1655
|
+
intCheck(dp, 0, MAX);
|
|
1656
|
+
if (rm == null) rm = ROUNDING_MODE;
|
|
1657
|
+
else intCheck(rm, 0, 8);
|
|
1658
|
+
|
|
1659
|
+
return round(new BigNumber(x), dp + x.e + 1, rm);
|
|
1660
|
+
}
|
|
1661
|
+
|
|
1662
|
+
if (!(c = x.c)) return null;
|
|
1663
|
+
n = ((v = c.length - 1) - bitFloor(this.e / LOG_BASE)) * LOG_BASE;
|
|
1664
|
+
|
|
1665
|
+
// Subtract the number of trailing zeros of the last number.
|
|
1666
|
+
if (v = c[v]) for (; v % 10 == 0; v /= 10, n--);
|
|
1667
|
+
if (n < 0) n = 0;
|
|
1668
|
+
|
|
1669
|
+
return n;
|
|
1670
|
+
};
|
|
1671
|
+
|
|
1672
|
+
|
|
1673
|
+
/*
|
|
1674
|
+
* n / 0 = I
|
|
1675
|
+
* n / N = N
|
|
1676
|
+
* n / I = 0
|
|
1677
|
+
* 0 / n = 0
|
|
1678
|
+
* 0 / 0 = N
|
|
1679
|
+
* 0 / N = N
|
|
1680
|
+
* 0 / I = 0
|
|
1681
|
+
* N / n = N
|
|
1682
|
+
* N / 0 = N
|
|
1683
|
+
* N / N = N
|
|
1684
|
+
* N / I = N
|
|
1685
|
+
* I / n = I
|
|
1686
|
+
* I / 0 = I
|
|
1687
|
+
* I / N = N
|
|
1688
|
+
* I / I = N
|
|
1689
|
+
*
|
|
1690
|
+
* Return a new BigNumber whose value is the value of this BigNumber divided by the value of
|
|
1691
|
+
* BigNumber(y, b), rounded according to DECIMAL_PLACES and ROUNDING_MODE.
|
|
1692
|
+
*/
|
|
1693
|
+
P.dividedBy = P.div = function (y, b) {
|
|
1694
|
+
return div(this, new BigNumber(y, b), DECIMAL_PLACES, ROUNDING_MODE);
|
|
1695
|
+
};
|
|
1696
|
+
|
|
1697
|
+
|
|
1698
|
+
/*
|
|
1699
|
+
* Return a new BigNumber whose value is the integer part of dividing the value of this
|
|
1700
|
+
* BigNumber by the value of BigNumber(y, b).
|
|
1701
|
+
*/
|
|
1702
|
+
P.dividedToIntegerBy = P.idiv = function (y, b) {
|
|
1703
|
+
return div(this, new BigNumber(y, b), 0, 1);
|
|
1704
|
+
};
|
|
1705
|
+
|
|
1706
|
+
|
|
1707
|
+
/*
|
|
1708
|
+
* Return a BigNumber whose value is the value of this BigNumber exponentiated by n.
|
|
1709
|
+
*
|
|
1710
|
+
* If m is present, return the result modulo m.
|
|
1711
|
+
* If n is negative round according to DECIMAL_PLACES and ROUNDING_MODE.
|
|
1712
|
+
* If POW_PRECISION is non-zero and m is not present, round to POW_PRECISION using ROUNDING_MODE.
|
|
1713
|
+
*
|
|
1714
|
+
* The modular power operation works efficiently when x, n, and m are integers, otherwise it
|
|
1715
|
+
* is equivalent to calculating x.exponentiatedBy(n).modulo(m) with a POW_PRECISION of 0.
|
|
1716
|
+
*
|
|
1717
|
+
* n {number|string|BigNumber} The exponent. An integer.
|
|
1718
|
+
* [m] {number|string|BigNumber} The modulus.
|
|
1719
|
+
*
|
|
1720
|
+
* '[BigNumber Error] Exponent not an integer: {n}'
|
|
1721
|
+
*/
|
|
1722
|
+
P.exponentiatedBy = P.pow = function (n, m) {
|
|
1723
|
+
var half, isModExp, i, k, more, nIsBig, nIsNeg, nIsOdd, y,
|
|
1724
|
+
x = this;
|
|
1725
|
+
|
|
1726
|
+
n = new BigNumber(n);
|
|
1727
|
+
|
|
1728
|
+
// Allow NaN and ±Infinity, but not other non-integers.
|
|
1729
|
+
if (n.c && !n.isInteger()) {
|
|
1730
|
+
throw Error
|
|
1731
|
+
(bignumberError + 'Exponent not an integer: ' + valueOf(n));
|
|
1732
|
+
}
|
|
1733
|
+
|
|
1734
|
+
if (m != null) m = new BigNumber(m);
|
|
1735
|
+
|
|
1736
|
+
// Exponent of MAX_SAFE_INTEGER is 15.
|
|
1737
|
+
nIsBig = n.e > 14;
|
|
1738
|
+
|
|
1739
|
+
// If x is NaN, ±Infinity, ±0 or ±1, or n is ±Infinity, NaN or ±0.
|
|
1740
|
+
if (!x.c || !x.c[0] || x.c[0] == 1 && !x.e && x.c.length == 1 || !n.c || !n.c[0]) {
|
|
1741
|
+
|
|
1742
|
+
// The sign of the result of pow when x is negative depends on the evenness of n.
|
|
1743
|
+
// If +n overflows to ±Infinity, the evenness of n would be not be known.
|
|
1744
|
+
y = new BigNumber(Math.pow(+valueOf(x), nIsBig ? 2 - isOdd(n) : +valueOf(n)));
|
|
1745
|
+
return m ? y.mod(m) : y;
|
|
1746
|
+
}
|
|
1747
|
+
|
|
1748
|
+
nIsNeg = n.s < 0;
|
|
1749
|
+
|
|
1750
|
+
if (m) {
|
|
1751
|
+
|
|
1752
|
+
// x % m returns NaN if abs(m) is zero, or m is NaN.
|
|
1753
|
+
if (m.c ? !m.c[0] : !m.s) return new BigNumber(NaN);
|
|
1754
|
+
|
|
1755
|
+
isModExp = !nIsNeg && x.isInteger() && m.isInteger();
|
|
1756
|
+
|
|
1757
|
+
if (isModExp) x = x.mod(m);
|
|
1758
|
+
|
|
1759
|
+
// Overflow to ±Infinity: >=2**1e10 or >=1.0000024**1e15.
|
|
1760
|
+
// Underflow to ±0: <=0.79**1e10 or <=0.9999975**1e15.
|
|
1761
|
+
} else if (n.e > 9 && (x.e > 0 || x.e < -1 || (x.e == 0
|
|
1762
|
+
// [1, 240000000]
|
|
1763
|
+
? x.c[0] > 1 || nIsBig && x.c[1] >= 24e7
|
|
1764
|
+
// [80000000000000] [99999750000000]
|
|
1765
|
+
: x.c[0] < 8e13 || nIsBig && x.c[0] <= 9999975e7))) {
|
|
1766
|
+
|
|
1767
|
+
// If x is negative and n is odd, k = -0, else k = 0.
|
|
1768
|
+
k = x.s < 0 && isOdd(n) ? -0 : 0;
|
|
1769
|
+
|
|
1770
|
+
// If x >= 1, k = ±Infinity.
|
|
1771
|
+
if (x.e > -1) k = 1 / k;
|
|
1772
|
+
|
|
1773
|
+
// If n is negative return ±0, else return ±Infinity.
|
|
1774
|
+
return new BigNumber(nIsNeg ? 1 / k : k);
|
|
1775
|
+
|
|
1776
|
+
} else if (POW_PRECISION) {
|
|
1777
|
+
|
|
1778
|
+
// Truncating each coefficient array to a length of k after each multiplication
|
|
1779
|
+
// equates to truncating significant digits to POW_PRECISION + [28, 41],
|
|
1780
|
+
// i.e. there will be a minimum of 28 guard digits retained.
|
|
1781
|
+
k = mathceil(POW_PRECISION / LOG_BASE + 2);
|
|
1782
|
+
}
|
|
1783
|
+
|
|
1784
|
+
if (nIsBig) {
|
|
1785
|
+
half = new BigNumber(0.5);
|
|
1786
|
+
if (nIsNeg) n.s = 1;
|
|
1787
|
+
nIsOdd = isOdd(n);
|
|
1788
|
+
} else {
|
|
1789
|
+
i = Math.abs(+valueOf(n));
|
|
1790
|
+
nIsOdd = i % 2;
|
|
1791
|
+
}
|
|
1792
|
+
|
|
1793
|
+
y = new BigNumber(ONE);
|
|
1794
|
+
|
|
1795
|
+
// Performs 54 loop iterations for n of 9007199254740991.
|
|
1796
|
+
for (; ;) {
|
|
1797
|
+
|
|
1798
|
+
if (nIsOdd) {
|
|
1799
|
+
y = y.times(x);
|
|
1800
|
+
if (!y.c) break;
|
|
1801
|
+
|
|
1802
|
+
if (k) {
|
|
1803
|
+
if (y.c.length > k) y.c.length = k;
|
|
1804
|
+
} else if (isModExp) {
|
|
1805
|
+
y = y.mod(m); //y = y.minus(div(y, m, 0, MODULO_MODE).times(m));
|
|
1806
|
+
}
|
|
1807
|
+
}
|
|
1808
|
+
|
|
1809
|
+
if (i) {
|
|
1810
|
+
i = mathfloor(i / 2);
|
|
1811
|
+
if (i === 0) break;
|
|
1812
|
+
nIsOdd = i % 2;
|
|
1813
|
+
} else {
|
|
1814
|
+
n = n.times(half);
|
|
1815
|
+
round(n, n.e + 1, 1);
|
|
1816
|
+
|
|
1817
|
+
if (n.e > 14) {
|
|
1818
|
+
nIsOdd = isOdd(n);
|
|
1819
|
+
} else {
|
|
1820
|
+
i = +valueOf(n);
|
|
1821
|
+
if (i === 0) break;
|
|
1822
|
+
nIsOdd = i % 2;
|
|
1823
|
+
}
|
|
1824
|
+
}
|
|
1825
|
+
|
|
1826
|
+
x = x.times(x);
|
|
1827
|
+
|
|
1828
|
+
if (k) {
|
|
1829
|
+
if (x.c && x.c.length > k) x.c.length = k;
|
|
1830
|
+
} else if (isModExp) {
|
|
1831
|
+
x = x.mod(m); //x = x.minus(div(x, m, 0, MODULO_MODE).times(m));
|
|
1832
|
+
}
|
|
1833
|
+
}
|
|
1834
|
+
|
|
1835
|
+
if (isModExp) return y;
|
|
1836
|
+
if (nIsNeg) y = ONE.div(y);
|
|
1837
|
+
|
|
1838
|
+
return m ? y.mod(m) : k ? round(y, POW_PRECISION, ROUNDING_MODE, more) : y;
|
|
1839
|
+
};
|
|
1840
|
+
|
|
1841
|
+
|
|
1842
|
+
/*
|
|
1843
|
+
* Return a new BigNumber whose value is the value of this BigNumber rounded to an integer
|
|
1844
|
+
* using rounding mode rm, or ROUNDING_MODE if rm is omitted.
|
|
1845
|
+
*
|
|
1846
|
+
* [rm] {number} Rounding mode. Integer, 0 to 8 inclusive.
|
|
1847
|
+
*
|
|
1848
|
+
* '[BigNumber Error] Argument {not a primitive number|not an integer|out of range}: {rm}'
|
|
1849
|
+
*/
|
|
1850
|
+
P.integerValue = function (rm) {
|
|
1851
|
+
var n = new BigNumber(this);
|
|
1852
|
+
if (rm == null) rm = ROUNDING_MODE;
|
|
1853
|
+
else intCheck(rm, 0, 8);
|
|
1854
|
+
return round(n, n.e + 1, rm);
|
|
1855
|
+
};
|
|
1856
|
+
|
|
1857
|
+
|
|
1858
|
+
/*
|
|
1859
|
+
* Return true if the value of this BigNumber is equal to the value of BigNumber(y, b),
|
|
1860
|
+
* otherwise return false.
|
|
1861
|
+
*/
|
|
1862
|
+
P.isEqualTo = P.eq = function (y, b) {
|
|
1863
|
+
return compare(this, new BigNumber(y, b)) === 0;
|
|
1864
|
+
};
|
|
1865
|
+
|
|
1866
|
+
|
|
1867
|
+
/*
|
|
1868
|
+
* Return true if the value of this BigNumber is a finite number, otherwise return false.
|
|
1869
|
+
*/
|
|
1870
|
+
P.isFinite = function () {
|
|
1871
|
+
return !!this.c;
|
|
1872
|
+
};
|
|
1873
|
+
|
|
1874
|
+
|
|
1875
|
+
/*
|
|
1876
|
+
* Return true if the value of this BigNumber is greater than the value of BigNumber(y, b),
|
|
1877
|
+
* otherwise return false.
|
|
1878
|
+
*/
|
|
1879
|
+
P.isGreaterThan = P.gt = function (y, b) {
|
|
1880
|
+
return compare(this, new BigNumber(y, b)) > 0;
|
|
1881
|
+
};
|
|
1882
|
+
|
|
1883
|
+
|
|
1884
|
+
/*
|
|
1885
|
+
* Return true if the value of this BigNumber is greater than or equal to the value of
|
|
1886
|
+
* BigNumber(y, b), otherwise return false.
|
|
1887
|
+
*/
|
|
1888
|
+
P.isGreaterThanOrEqualTo = P.gte = function (y, b) {
|
|
1889
|
+
return (b = compare(this, new BigNumber(y, b))) === 1 || b === 0;
|
|
1890
|
+
|
|
1891
|
+
};
|
|
1892
|
+
|
|
1893
|
+
|
|
1894
|
+
/*
|
|
1895
|
+
* Return true if the value of this BigNumber is an integer, otherwise return false.
|
|
1896
|
+
*/
|
|
1897
|
+
P.isInteger = function () {
|
|
1898
|
+
return !!this.c && bitFloor(this.e / LOG_BASE) > this.c.length - 2;
|
|
1899
|
+
};
|
|
1900
|
+
|
|
1901
|
+
|
|
1902
|
+
/*
|
|
1903
|
+
* Return true if the value of this BigNumber is less than the value of BigNumber(y, b),
|
|
1904
|
+
* otherwise return false.
|
|
1905
|
+
*/
|
|
1906
|
+
P.isLessThan = P.lt = function (y, b) {
|
|
1907
|
+
return compare(this, new BigNumber(y, b)) < 0;
|
|
1908
|
+
};
|
|
1909
|
+
|
|
1910
|
+
|
|
1911
|
+
/*
|
|
1912
|
+
* Return true if the value of this BigNumber is less than or equal to the value of
|
|
1913
|
+
* BigNumber(y, b), otherwise return false.
|
|
1914
|
+
*/
|
|
1915
|
+
P.isLessThanOrEqualTo = P.lte = function (y, b) {
|
|
1916
|
+
return (b = compare(this, new BigNumber(y, b))) === -1 || b === 0;
|
|
1917
|
+
};
|
|
1918
|
+
|
|
1919
|
+
|
|
1920
|
+
/*
|
|
1921
|
+
* Return true if the value of this BigNumber is NaN, otherwise return false.
|
|
1922
|
+
*/
|
|
1923
|
+
P.isNaN = function () {
|
|
1924
|
+
return !this.s;
|
|
1925
|
+
};
|
|
1926
|
+
|
|
1927
|
+
|
|
1928
|
+
/*
|
|
1929
|
+
* Return true if the value of this BigNumber is negative, otherwise return false.
|
|
1930
|
+
*/
|
|
1931
|
+
P.isNegative = function () {
|
|
1932
|
+
return this.s < 0;
|
|
1933
|
+
};
|
|
1934
|
+
|
|
1935
|
+
|
|
1936
|
+
/*
|
|
1937
|
+
* Return true if the value of this BigNumber is positive, otherwise return false.
|
|
1938
|
+
*/
|
|
1939
|
+
P.isPositive = function () {
|
|
1940
|
+
return this.s > 0;
|
|
1941
|
+
};
|
|
1942
|
+
|
|
1943
|
+
|
|
1944
|
+
/*
|
|
1945
|
+
* Return true if the value of this BigNumber is 0 or -0, otherwise return false.
|
|
1946
|
+
*/
|
|
1947
|
+
P.isZero = function () {
|
|
1948
|
+
return !!this.c && this.c[0] == 0;
|
|
1949
|
+
};
|
|
1950
|
+
|
|
1951
|
+
|
|
1952
|
+
/*
|
|
1953
|
+
* n - 0 = n
|
|
1954
|
+
* n - N = N
|
|
1955
|
+
* n - I = -I
|
|
1956
|
+
* 0 - n = -n
|
|
1957
|
+
* 0 - 0 = 0
|
|
1958
|
+
* 0 - N = N
|
|
1959
|
+
* 0 - I = -I
|
|
1960
|
+
* N - n = N
|
|
1961
|
+
* N - 0 = N
|
|
1962
|
+
* N - N = N
|
|
1963
|
+
* N - I = N
|
|
1964
|
+
* I - n = I
|
|
1965
|
+
* I - 0 = I
|
|
1966
|
+
* I - N = N
|
|
1967
|
+
* I - I = N
|
|
1968
|
+
*
|
|
1969
|
+
* Return a new BigNumber whose value is the value of this BigNumber minus the value of
|
|
1970
|
+
* BigNumber(y, b).
|
|
1971
|
+
*/
|
|
1972
|
+
P.minus = function (y, b) {
|
|
1973
|
+
var i, j, t, xLTy,
|
|
1974
|
+
x = this,
|
|
1975
|
+
a = x.s;
|
|
1976
|
+
|
|
1977
|
+
y = new BigNumber(y, b);
|
|
1978
|
+
b = y.s;
|
|
1979
|
+
|
|
1980
|
+
// Either NaN?
|
|
1981
|
+
if (!a || !b) return new BigNumber(NaN);
|
|
1982
|
+
|
|
1983
|
+
// Signs differ?
|
|
1984
|
+
if (a != b) {
|
|
1985
|
+
y.s = -b;
|
|
1986
|
+
return x.plus(y);
|
|
1987
|
+
}
|
|
1988
|
+
|
|
1989
|
+
var xe = x.e / LOG_BASE,
|
|
1990
|
+
ye = y.e / LOG_BASE,
|
|
1991
|
+
xc = x.c,
|
|
1992
|
+
yc = y.c;
|
|
1993
|
+
|
|
1994
|
+
if (!xe || !ye) {
|
|
1995
|
+
|
|
1996
|
+
// Either Infinity?
|
|
1997
|
+
if (!xc || !yc) return xc ? (y.s = -b, y) : new BigNumber(yc ? x : NaN);
|
|
1998
|
+
|
|
1999
|
+
// Either zero?
|
|
2000
|
+
if (!xc[0] || !yc[0]) {
|
|
2001
|
+
|
|
2002
|
+
// Return y if y is non-zero, x if x is non-zero, or zero if both are zero.
|
|
2003
|
+
return yc[0] ? (y.s = -b, y) : new BigNumber(xc[0] ? x :
|
|
2004
|
+
|
|
2005
|
+
// IEEE 754 (2008) 6.3: n - n = -0 when rounding to -Infinity
|
|
2006
|
+
ROUNDING_MODE == 3 ? -0 : 0);
|
|
2007
|
+
}
|
|
2008
|
+
}
|
|
2009
|
+
|
|
2010
|
+
xe = bitFloor(xe);
|
|
2011
|
+
ye = bitFloor(ye);
|
|
2012
|
+
xc = xc.slice();
|
|
2013
|
+
|
|
2014
|
+
// Determine which is the bigger number.
|
|
2015
|
+
if (a = xe - ye) {
|
|
2016
|
+
|
|
2017
|
+
if (xLTy = a < 0) {
|
|
2018
|
+
a = -a;
|
|
2019
|
+
t = xc;
|
|
2020
|
+
} else {
|
|
2021
|
+
ye = xe;
|
|
2022
|
+
t = yc;
|
|
2023
|
+
}
|
|
2024
|
+
|
|
2025
|
+
t.reverse();
|
|
2026
|
+
|
|
2027
|
+
// Prepend zeros to equalise exponents.
|
|
2028
|
+
for (b = a; b--; t.push(0));
|
|
2029
|
+
t.reverse();
|
|
2030
|
+
} else {
|
|
2031
|
+
|
|
2032
|
+
// Exponents equal. Check digit by digit.
|
|
2033
|
+
j = (xLTy = (a = xc.length) < (b = yc.length)) ? a : b;
|
|
2034
|
+
|
|
2035
|
+
for (a = b = 0; b < j; b++) {
|
|
2036
|
+
|
|
2037
|
+
if (xc[b] != yc[b]) {
|
|
2038
|
+
xLTy = xc[b] < yc[b];
|
|
2039
|
+
break;
|
|
2040
|
+
}
|
|
2041
|
+
}
|
|
2042
|
+
}
|
|
2043
|
+
|
|
2044
|
+
// x < y? Point xc to the array of the bigger number.
|
|
2045
|
+
if (xLTy) t = xc, xc = yc, yc = t, y.s = -y.s;
|
|
2046
|
+
|
|
2047
|
+
b = (j = yc.length) - (i = xc.length);
|
|
2048
|
+
|
|
2049
|
+
// Append zeros to xc if shorter.
|
|
2050
|
+
// No need to add zeros to yc if shorter as subtract only needs to start at yc.length.
|
|
2051
|
+
if (b > 0) for (; b--; xc[i++] = 0);
|
|
2052
|
+
b = BASE - 1;
|
|
2053
|
+
|
|
2054
|
+
// Subtract yc from xc.
|
|
2055
|
+
for (; j > a;) {
|
|
2056
|
+
|
|
2057
|
+
if (xc[--j] < yc[j]) {
|
|
2058
|
+
for (i = j; i && !xc[--i]; xc[i] = b);
|
|
2059
|
+
--xc[i];
|
|
2060
|
+
xc[j] += BASE;
|
|
2061
|
+
}
|
|
2062
|
+
|
|
2063
|
+
xc[j] -= yc[j];
|
|
2064
|
+
}
|
|
2065
|
+
|
|
2066
|
+
// Remove leading zeros and adjust exponent accordingly.
|
|
2067
|
+
for (; xc[0] == 0; xc.splice(0, 1), --ye);
|
|
2068
|
+
|
|
2069
|
+
// Zero?
|
|
2070
|
+
if (!xc[0]) {
|
|
2071
|
+
|
|
2072
|
+
// Following IEEE 754 (2008) 6.3,
|
|
2073
|
+
// n - n = +0 but n - n = -0 when rounding towards -Infinity.
|
|
2074
|
+
y.s = ROUNDING_MODE == 3 ? -1 : 1;
|
|
2075
|
+
y.c = [y.e = 0];
|
|
2076
|
+
return y;
|
|
2077
|
+
}
|
|
2078
|
+
|
|
2079
|
+
// No need to check for Infinity as +x - +y != Infinity && -x - -y != Infinity
|
|
2080
|
+
// for finite x and y.
|
|
2081
|
+
return normalise(y, xc, ye);
|
|
2082
|
+
};
|
|
2083
|
+
|
|
2084
|
+
|
|
2085
|
+
/*
|
|
2086
|
+
* n % 0 = N
|
|
2087
|
+
* n % N = N
|
|
2088
|
+
* n % I = n
|
|
2089
|
+
* 0 % n = 0
|
|
2090
|
+
* -0 % n = -0
|
|
2091
|
+
* 0 % 0 = N
|
|
2092
|
+
* 0 % N = N
|
|
2093
|
+
* 0 % I = 0
|
|
2094
|
+
* N % n = N
|
|
2095
|
+
* N % 0 = N
|
|
2096
|
+
* N % N = N
|
|
2097
|
+
* N % I = N
|
|
2098
|
+
* I % n = N
|
|
2099
|
+
* I % 0 = N
|
|
2100
|
+
* I % N = N
|
|
2101
|
+
* I % I = N
|
|
2102
|
+
*
|
|
2103
|
+
* Return a new BigNumber whose value is the value of this BigNumber modulo the value of
|
|
2104
|
+
* BigNumber(y, b). The result depends on the value of MODULO_MODE.
|
|
2105
|
+
*/
|
|
2106
|
+
P.modulo = P.mod = function (y, b) {
|
|
2107
|
+
var q, s,
|
|
2108
|
+
x = this;
|
|
2109
|
+
|
|
2110
|
+
y = new BigNumber(y, b);
|
|
2111
|
+
|
|
2112
|
+
// Return NaN if x is Infinity or NaN, or y is NaN or zero.
|
|
2113
|
+
if (!x.c || !y.s || y.c && !y.c[0]) {
|
|
2114
|
+
return new BigNumber(NaN);
|
|
2115
|
+
|
|
2116
|
+
// Return x if y is Infinity or x is zero.
|
|
2117
|
+
} else if (!y.c || x.c && !x.c[0]) {
|
|
2118
|
+
return new BigNumber(x);
|
|
2119
|
+
}
|
|
2120
|
+
|
|
2121
|
+
if (MODULO_MODE == 9) {
|
|
2122
|
+
|
|
2123
|
+
// Euclidian division: q = sign(y) * floor(x / abs(y))
|
|
2124
|
+
// r = x - qy where 0 <= r < abs(y)
|
|
2125
|
+
s = y.s;
|
|
2126
|
+
y.s = 1;
|
|
2127
|
+
q = div(x, y, 0, 3);
|
|
2128
|
+
y.s = s;
|
|
2129
|
+
q.s *= s;
|
|
2130
|
+
} else {
|
|
2131
|
+
q = div(x, y, 0, MODULO_MODE);
|
|
2132
|
+
}
|
|
2133
|
+
|
|
2134
|
+
y = x.minus(q.times(y));
|
|
2135
|
+
|
|
2136
|
+
// To match JavaScript %, ensure sign of zero is sign of dividend.
|
|
2137
|
+
if (!y.c[0] && MODULO_MODE == 1) y.s = x.s;
|
|
2138
|
+
|
|
2139
|
+
return y;
|
|
2140
|
+
};
|
|
2141
|
+
|
|
2142
|
+
|
|
2143
|
+
/*
|
|
2144
|
+
* n * 0 = 0
|
|
2145
|
+
* n * N = N
|
|
2146
|
+
* n * I = I
|
|
2147
|
+
* 0 * n = 0
|
|
2148
|
+
* 0 * 0 = 0
|
|
2149
|
+
* 0 * N = N
|
|
2150
|
+
* 0 * I = N
|
|
2151
|
+
* N * n = N
|
|
2152
|
+
* N * 0 = N
|
|
2153
|
+
* N * N = N
|
|
2154
|
+
* N * I = N
|
|
2155
|
+
* I * n = I
|
|
2156
|
+
* I * 0 = N
|
|
2157
|
+
* I * N = N
|
|
2158
|
+
* I * I = I
|
|
2159
|
+
*
|
|
2160
|
+
* Return a new BigNumber whose value is the value of this BigNumber multiplied by the value
|
|
2161
|
+
* of BigNumber(y, b).
|
|
2162
|
+
*/
|
|
2163
|
+
P.multipliedBy = P.times = function (y, b) {
|
|
2164
|
+
var c, e, i, j, k, m, xcL, xlo, xhi, ycL, ylo, yhi, zc,
|
|
2165
|
+
base, sqrtBase,
|
|
2166
|
+
x = this,
|
|
2167
|
+
xc = x.c,
|
|
2168
|
+
yc = (y = new BigNumber(y, b)).c;
|
|
2169
|
+
|
|
2170
|
+
// Either NaN, ±Infinity or ±0?
|
|
2171
|
+
if (!xc || !yc || !xc[0] || !yc[0]) {
|
|
2172
|
+
|
|
2173
|
+
// Return NaN if either is NaN, or one is 0 and the other is Infinity.
|
|
2174
|
+
if (!x.s || !y.s || xc && !xc[0] && !yc || yc && !yc[0] && !xc) {
|
|
2175
|
+
y.c = y.e = y.s = null;
|
|
2176
|
+
} else {
|
|
2177
|
+
y.s *= x.s;
|
|
2178
|
+
|
|
2179
|
+
// Return ±Infinity if either is ±Infinity.
|
|
2180
|
+
if (!xc || !yc) {
|
|
2181
|
+
y.c = y.e = null;
|
|
2182
|
+
|
|
2183
|
+
// Return ±0 if either is ±0.
|
|
2184
|
+
} else {
|
|
2185
|
+
y.c = [0];
|
|
2186
|
+
y.e = 0;
|
|
2187
|
+
}
|
|
2188
|
+
}
|
|
2189
|
+
|
|
2190
|
+
return y;
|
|
2191
|
+
}
|
|
2192
|
+
|
|
2193
|
+
e = bitFloor(x.e / LOG_BASE) + bitFloor(y.e / LOG_BASE);
|
|
2194
|
+
y.s *= x.s;
|
|
2195
|
+
xcL = xc.length;
|
|
2196
|
+
ycL = yc.length;
|
|
2197
|
+
|
|
2198
|
+
// Ensure xc points to longer array and xcL to its length.
|
|
2199
|
+
if (xcL < ycL) zc = xc, xc = yc, yc = zc, i = xcL, xcL = ycL, ycL = i;
|
|
2200
|
+
|
|
2201
|
+
// Initialise the result array with zeros.
|
|
2202
|
+
for (i = xcL + ycL, zc = []; i--; zc.push(0));
|
|
2203
|
+
|
|
2204
|
+
base = BASE;
|
|
2205
|
+
sqrtBase = SQRT_BASE;
|
|
2206
|
+
|
|
2207
|
+
for (i = ycL; --i >= 0;) {
|
|
2208
|
+
c = 0;
|
|
2209
|
+
ylo = yc[i] % sqrtBase;
|
|
2210
|
+
yhi = yc[i] / sqrtBase | 0;
|
|
2211
|
+
|
|
2212
|
+
for (k = xcL, j = i + k; j > i;) {
|
|
2213
|
+
xlo = xc[--k] % sqrtBase;
|
|
2214
|
+
xhi = xc[k] / sqrtBase | 0;
|
|
2215
|
+
m = yhi * xlo + xhi * ylo;
|
|
2216
|
+
xlo = ylo * xlo + ((m % sqrtBase) * sqrtBase) + zc[j] + c;
|
|
2217
|
+
c = (xlo / base | 0) + (m / sqrtBase | 0) + yhi * xhi;
|
|
2218
|
+
zc[j--] = xlo % base;
|
|
2219
|
+
}
|
|
2220
|
+
|
|
2221
|
+
zc[j] = c;
|
|
2222
|
+
}
|
|
2223
|
+
|
|
2224
|
+
if (c) {
|
|
2225
|
+
++e;
|
|
2226
|
+
} else {
|
|
2227
|
+
zc.splice(0, 1);
|
|
2228
|
+
}
|
|
2229
|
+
|
|
2230
|
+
return normalise(y, zc, e);
|
|
2231
|
+
};
|
|
2232
|
+
|
|
2233
|
+
|
|
2234
|
+
/*
|
|
2235
|
+
* Return a new BigNumber whose value is the value of this BigNumber negated,
|
|
2236
|
+
* i.e. multiplied by -1.
|
|
2237
|
+
*/
|
|
2238
|
+
P.negated = function () {
|
|
2239
|
+
var x = new BigNumber(this);
|
|
2240
|
+
x.s = -x.s || null;
|
|
2241
|
+
return x;
|
|
2242
|
+
};
|
|
2243
|
+
|
|
2244
|
+
|
|
2245
|
+
/*
|
|
2246
|
+
* n + 0 = n
|
|
2247
|
+
* n + N = N
|
|
2248
|
+
* n + I = I
|
|
2249
|
+
* 0 + n = n
|
|
2250
|
+
* 0 + 0 = 0
|
|
2251
|
+
* 0 + N = N
|
|
2252
|
+
* 0 + I = I
|
|
2253
|
+
* N + n = N
|
|
2254
|
+
* N + 0 = N
|
|
2255
|
+
* N + N = N
|
|
2256
|
+
* N + I = N
|
|
2257
|
+
* I + n = I
|
|
2258
|
+
* I + 0 = I
|
|
2259
|
+
* I + N = N
|
|
2260
|
+
* I + I = I
|
|
2261
|
+
*
|
|
2262
|
+
* Return a new BigNumber whose value is the value of this BigNumber plus the value of
|
|
2263
|
+
* BigNumber(y, b).
|
|
2264
|
+
*/
|
|
2265
|
+
P.plus = function (y, b) {
|
|
2266
|
+
var t,
|
|
2267
|
+
x = this,
|
|
2268
|
+
a = x.s;
|
|
2269
|
+
|
|
2270
|
+
y = new BigNumber(y, b);
|
|
2271
|
+
b = y.s;
|
|
2272
|
+
|
|
2273
|
+
// Either NaN?
|
|
2274
|
+
if (!a || !b) return new BigNumber(NaN);
|
|
2275
|
+
|
|
2276
|
+
// Signs differ?
|
|
2277
|
+
if (a != b) {
|
|
2278
|
+
y.s = -b;
|
|
2279
|
+
return x.minus(y);
|
|
2280
|
+
}
|
|
2281
|
+
|
|
2282
|
+
var xe = x.e / LOG_BASE,
|
|
2283
|
+
ye = y.e / LOG_BASE,
|
|
2284
|
+
xc = x.c,
|
|
2285
|
+
yc = y.c;
|
|
2286
|
+
|
|
2287
|
+
if (!xe || !ye) {
|
|
2288
|
+
|
|
2289
|
+
// Return ±Infinity if either ±Infinity.
|
|
2290
|
+
if (!xc || !yc) return new BigNumber(a / 0);
|
|
2291
|
+
|
|
2292
|
+
// Either zero?
|
|
2293
|
+
// Return y if y is non-zero, x if x is non-zero, or zero if both are zero.
|
|
2294
|
+
if (!xc[0] || !yc[0]) return yc[0] ? y : new BigNumber(xc[0] ? x : a * 0);
|
|
2295
|
+
}
|
|
2296
|
+
|
|
2297
|
+
xe = bitFloor(xe);
|
|
2298
|
+
ye = bitFloor(ye);
|
|
2299
|
+
xc = xc.slice();
|
|
2300
|
+
|
|
2301
|
+
// Prepend zeros to equalise exponents. Faster to use reverse then do unshifts.
|
|
2302
|
+
if (a = xe - ye) {
|
|
2303
|
+
if (a > 0) {
|
|
2304
|
+
ye = xe;
|
|
2305
|
+
t = yc;
|
|
2306
|
+
} else {
|
|
2307
|
+
a = -a;
|
|
2308
|
+
t = xc;
|
|
2309
|
+
}
|
|
2310
|
+
|
|
2311
|
+
t.reverse();
|
|
2312
|
+
for (; a--; t.push(0));
|
|
2313
|
+
t.reverse();
|
|
2314
|
+
}
|
|
2315
|
+
|
|
2316
|
+
a = xc.length;
|
|
2317
|
+
b = yc.length;
|
|
2318
|
+
|
|
2319
|
+
// Point xc to the longer array, and b to the shorter length.
|
|
2320
|
+
if (a - b < 0) t = yc, yc = xc, xc = t, b = a;
|
|
2321
|
+
|
|
2322
|
+
// Only start adding at yc.length - 1 as the further digits of xc can be ignored.
|
|
2323
|
+
for (a = 0; b;) {
|
|
2324
|
+
a = (xc[--b] = xc[b] + yc[b] + a) / BASE | 0;
|
|
2325
|
+
xc[b] = BASE === xc[b] ? 0 : xc[b] % BASE;
|
|
2326
|
+
}
|
|
2327
|
+
|
|
2328
|
+
if (a) {
|
|
2329
|
+
xc = [a].concat(xc);
|
|
2330
|
+
++ye;
|
|
2331
|
+
}
|
|
2332
|
+
|
|
2333
|
+
// No need to check for zero, as +x + +y != 0 && -x + -y != 0
|
|
2334
|
+
// ye = MAX_EXP + 1 possible
|
|
2335
|
+
return normalise(y, xc, ye);
|
|
2336
|
+
};
|
|
2337
|
+
|
|
2338
|
+
|
|
2339
|
+
/*
|
|
2340
|
+
* If sd is undefined or null or true or false, return the number of significant digits of
|
|
2341
|
+
* the value of this BigNumber, or null if the value of this BigNumber is ±Infinity or NaN.
|
|
2342
|
+
* If sd is true include integer-part trailing zeros in the count.
|
|
2343
|
+
*
|
|
2344
|
+
* Otherwise, if sd is a number, return a new BigNumber whose value is the value of this
|
|
2345
|
+
* BigNumber rounded to a maximum of sd significant digits using rounding mode rm, or
|
|
2346
|
+
* ROUNDING_MODE if rm is omitted.
|
|
2347
|
+
*
|
|
2348
|
+
* sd {number|boolean} number: significant digits: integer, 1 to MAX inclusive.
|
|
2349
|
+
* boolean: whether to count integer-part trailing zeros: true or false.
|
|
2350
|
+
* [rm] {number} Rounding mode. Integer, 0 to 8 inclusive.
|
|
2351
|
+
*
|
|
2352
|
+
* '[BigNumber Error] Argument {not a primitive number|not an integer|out of range}: {sd|rm}'
|
|
2353
|
+
*/
|
|
2354
|
+
P.precision = P.sd = function (sd, rm) {
|
|
2355
|
+
var c, n, v,
|
|
2356
|
+
x = this;
|
|
2357
|
+
|
|
2358
|
+
if (sd != null && sd !== !!sd) {
|
|
2359
|
+
intCheck(sd, 1, MAX);
|
|
2360
|
+
if (rm == null) rm = ROUNDING_MODE;
|
|
2361
|
+
else intCheck(rm, 0, 8);
|
|
2362
|
+
|
|
2363
|
+
return round(new BigNumber(x), sd, rm);
|
|
2364
|
+
}
|
|
2365
|
+
|
|
2366
|
+
if (!(c = x.c)) return null;
|
|
2367
|
+
v = c.length - 1;
|
|
2368
|
+
n = v * LOG_BASE + 1;
|
|
2369
|
+
|
|
2370
|
+
if (v = c[v]) {
|
|
2371
|
+
|
|
2372
|
+
// Subtract the number of trailing zeros of the last element.
|
|
2373
|
+
for (; v % 10 == 0; v /= 10, n--);
|
|
2374
|
+
|
|
2375
|
+
// Add the number of digits of the first element.
|
|
2376
|
+
for (v = c[0]; v >= 10; v /= 10, n++);
|
|
2377
|
+
}
|
|
2378
|
+
|
|
2379
|
+
if (sd && x.e + 1 > n) n = x.e + 1;
|
|
2380
|
+
|
|
2381
|
+
return n;
|
|
2382
|
+
};
|
|
2383
|
+
|
|
2384
|
+
|
|
2385
|
+
/*
|
|
2386
|
+
* Return a new BigNumber whose value is the value of this BigNumber shifted by k places
|
|
2387
|
+
* (powers of 10). Shift to the right if n > 0, and to the left if n < 0.
|
|
2388
|
+
*
|
|
2389
|
+
* k {number} Integer, -MAX_SAFE_INTEGER to MAX_SAFE_INTEGER inclusive.
|
|
2390
|
+
*
|
|
2391
|
+
* '[BigNumber Error] Argument {not a primitive number|not an integer|out of range}: {k}'
|
|
2392
|
+
*/
|
|
2393
|
+
P.shiftedBy = function (k) {
|
|
2394
|
+
intCheck(k, -MAX_SAFE_INTEGER, MAX_SAFE_INTEGER);
|
|
2395
|
+
return this.times('1e' + k);
|
|
2396
|
+
};
|
|
2397
|
+
|
|
2398
|
+
|
|
2399
|
+
/*
|
|
2400
|
+
* sqrt(-n) = N
|
|
2401
|
+
* sqrt(N) = N
|
|
2402
|
+
* sqrt(-I) = N
|
|
2403
|
+
* sqrt(I) = I
|
|
2404
|
+
* sqrt(0) = 0
|
|
2405
|
+
* sqrt(-0) = -0
|
|
2406
|
+
*
|
|
2407
|
+
* Return a new BigNumber whose value is the square root of the value of this BigNumber,
|
|
2408
|
+
* rounded according to DECIMAL_PLACES and ROUNDING_MODE.
|
|
2409
|
+
*/
|
|
2410
|
+
P.squareRoot = P.sqrt = function () {
|
|
2411
|
+
var m, n, r, rep, t,
|
|
2412
|
+
x = this,
|
|
2413
|
+
c = x.c,
|
|
2414
|
+
s = x.s,
|
|
2415
|
+
e = x.e,
|
|
2416
|
+
dp = DECIMAL_PLACES + 4,
|
|
2417
|
+
half = new BigNumber('0.5');
|
|
2418
|
+
|
|
2419
|
+
// Negative/NaN/Infinity/zero?
|
|
2420
|
+
if (s !== 1 || !c || !c[0]) {
|
|
2421
|
+
return new BigNumber(!s || s < 0 && (!c || c[0]) ? NaN : c ? x : 1 / 0);
|
|
2422
|
+
}
|
|
2423
|
+
|
|
2424
|
+
// Initial estimate.
|
|
2425
|
+
s = Math.sqrt(+valueOf(x));
|
|
2426
|
+
|
|
2427
|
+
// Math.sqrt underflow/overflow?
|
|
2428
|
+
// Pass x to Math.sqrt as integer, then adjust the exponent of the result.
|
|
2429
|
+
if (s == 0 || s == 1 / 0) {
|
|
2430
|
+
n = coeffToString(c);
|
|
2431
|
+
if ((n.length + e) % 2 == 0) n += '0';
|
|
2432
|
+
s = Math.sqrt(+n);
|
|
2433
|
+
e = bitFloor((e + 1) / 2) - (e < 0 || e % 2);
|
|
2434
|
+
|
|
2435
|
+
if (s == 1 / 0) {
|
|
2436
|
+
n = '5e' + e;
|
|
2437
|
+
} else {
|
|
2438
|
+
n = s.toExponential();
|
|
2439
|
+
n = n.slice(0, n.indexOf('e') + 1) + e;
|
|
2440
|
+
}
|
|
2441
|
+
|
|
2442
|
+
r = new BigNumber(n);
|
|
2443
|
+
} else {
|
|
2444
|
+
r = new BigNumber(s + '');
|
|
2445
|
+
}
|
|
2446
|
+
|
|
2447
|
+
// Check for zero.
|
|
2448
|
+
// r could be zero if MIN_EXP is changed after the this value was created.
|
|
2449
|
+
// This would cause a division by zero (x/t) and hence Infinity below, which would cause
|
|
2450
|
+
// coeffToString to throw.
|
|
2451
|
+
if (r.c[0]) {
|
|
2452
|
+
e = r.e;
|
|
2453
|
+
s = e + dp;
|
|
2454
|
+
if (s < 3) s = 0;
|
|
2455
|
+
|
|
2456
|
+
// Newton-Raphson iteration.
|
|
2457
|
+
for (; ;) {
|
|
2458
|
+
t = r;
|
|
2459
|
+
r = half.times(t.plus(div(x, t, dp, 1)));
|
|
2460
|
+
|
|
2461
|
+
if (coeffToString(t.c).slice(0, s) === (n = coeffToString(r.c)).slice(0, s)) {
|
|
2462
|
+
|
|
2463
|
+
// The exponent of r may here be one less than the final result exponent,
|
|
2464
|
+
// e.g 0.0009999 (e-4) --> 0.001 (e-3), so adjust s so the rounding digits
|
|
2465
|
+
// are indexed correctly.
|
|
2466
|
+
if (r.e < e) --s;
|
|
2467
|
+
n = n.slice(s - 3, s + 1);
|
|
2468
|
+
|
|
2469
|
+
// The 4th rounding digit may be in error by -1 so if the 4 rounding digits
|
|
2470
|
+
// are 9999 or 4999 (i.e. approaching a rounding boundary) continue the
|
|
2471
|
+
// iteration.
|
|
2472
|
+
if (n == '9999' || !rep && n == '4999') {
|
|
2473
|
+
|
|
2474
|
+
// On the first iteration only, check to see if rounding up gives the
|
|
2475
|
+
// exact result as the nines may infinitely repeat.
|
|
2476
|
+
if (!rep) {
|
|
2477
|
+
round(t, t.e + DECIMAL_PLACES + 2, 0);
|
|
2478
|
+
|
|
2479
|
+
if (t.times(t).eq(x)) {
|
|
2480
|
+
r = t;
|
|
2481
|
+
break;
|
|
2482
|
+
}
|
|
2483
|
+
}
|
|
2484
|
+
|
|
2485
|
+
dp += 4;
|
|
2486
|
+
s += 4;
|
|
2487
|
+
rep = 1;
|
|
2488
|
+
} else {
|
|
2489
|
+
|
|
2490
|
+
// If rounding digits are null, 0{0,4} or 50{0,3}, check for exact
|
|
2491
|
+
// result. If not, then there are further digits and m will be truthy.
|
|
2492
|
+
if (!+n || !+n.slice(1) && n.charAt(0) == '5') {
|
|
2493
|
+
|
|
2494
|
+
// Truncate to the first rounding digit.
|
|
2495
|
+
round(r, r.e + DECIMAL_PLACES + 2, 1);
|
|
2496
|
+
m = !r.times(r).eq(x);
|
|
2497
|
+
}
|
|
2498
|
+
|
|
2499
|
+
break;
|
|
2500
|
+
}
|
|
2501
|
+
}
|
|
2502
|
+
}
|
|
2503
|
+
}
|
|
2504
|
+
|
|
2505
|
+
return round(r, r.e + DECIMAL_PLACES + 1, ROUNDING_MODE, m);
|
|
2506
|
+
};
|
|
2507
|
+
|
|
2508
|
+
|
|
2509
|
+
/*
|
|
2510
|
+
* Return a string representing the value of this BigNumber in exponential notation and
|
|
2511
|
+
* rounded using ROUNDING_MODE to dp fixed decimal places.
|
|
2512
|
+
*
|
|
2513
|
+
* [dp] {number} Decimal places. Integer, 0 to MAX inclusive.
|
|
2514
|
+
* [rm] {number} Rounding mode. Integer, 0 to 8 inclusive.
|
|
2515
|
+
*
|
|
2516
|
+
* '[BigNumber Error] Argument {not a primitive number|not an integer|out of range}: {dp|rm}'
|
|
2517
|
+
*/
|
|
2518
|
+
P.toExponential = function (dp, rm) {
|
|
2519
|
+
if (dp != null) {
|
|
2520
|
+
intCheck(dp, 0, MAX);
|
|
2521
|
+
dp++;
|
|
2522
|
+
}
|
|
2523
|
+
return format(this, dp, rm, 1);
|
|
2524
|
+
};
|
|
2525
|
+
|
|
2526
|
+
|
|
2527
|
+
/*
|
|
2528
|
+
* Return a string representing the value of this BigNumber in fixed-point notation rounding
|
|
2529
|
+
* to dp fixed decimal places using rounding mode rm, or ROUNDING_MODE if rm is omitted.
|
|
2530
|
+
*
|
|
2531
|
+
* Note: as with JavaScript's number type, (-0).toFixed(0) is '0',
|
|
2532
|
+
* but e.g. (-0.00001).toFixed(0) is '-0'.
|
|
2533
|
+
*
|
|
2534
|
+
* [dp] {number} Decimal places. Integer, 0 to MAX inclusive.
|
|
2535
|
+
* [rm] {number} Rounding mode. Integer, 0 to 8 inclusive.
|
|
2536
|
+
*
|
|
2537
|
+
* '[BigNumber Error] Argument {not a primitive number|not an integer|out of range}: {dp|rm}'
|
|
2538
|
+
*/
|
|
2539
|
+
P.toFixed = function (dp, rm) {
|
|
2540
|
+
if (dp != null) {
|
|
2541
|
+
intCheck(dp, 0, MAX);
|
|
2542
|
+
dp = dp + this.e + 1;
|
|
2543
|
+
}
|
|
2544
|
+
return format(this, dp, rm);
|
|
2545
|
+
};
|
|
2546
|
+
|
|
2547
|
+
|
|
2548
|
+
/*
|
|
2549
|
+
* Return a string representing the value of this BigNumber in fixed-point notation rounded
|
|
2550
|
+
* using rm or ROUNDING_MODE to dp decimal places, and formatted according to the properties
|
|
2551
|
+
* of the format or FORMAT object (see BigNumber.set).
|
|
2552
|
+
*
|
|
2553
|
+
* The formatting object may contain some or all of the properties shown below.
|
|
2554
|
+
*
|
|
2555
|
+
* FORMAT = {
|
|
2556
|
+
* prefix: '',
|
|
2557
|
+
* groupSize: 3,
|
|
2558
|
+
* secondaryGroupSize: 0,
|
|
2559
|
+
* groupSeparator: ',',
|
|
2560
|
+
* decimalSeparator: '.',
|
|
2561
|
+
* fractionGroupSize: 0,
|
|
2562
|
+
* fractionGroupSeparator: '\xA0', // non-breaking space
|
|
2563
|
+
* suffix: ''
|
|
2564
|
+
* };
|
|
2565
|
+
*
|
|
2566
|
+
* [dp] {number} Decimal places. Integer, 0 to MAX inclusive.
|
|
2567
|
+
* [rm] {number} Rounding mode. Integer, 0 to 8 inclusive.
|
|
2568
|
+
* [format] {object} Formatting options. See FORMAT pbject above.
|
|
2569
|
+
*
|
|
2570
|
+
* '[BigNumber Error] Argument {not a primitive number|not an integer|out of range}: {dp|rm}'
|
|
2571
|
+
* '[BigNumber Error] Argument not an object: {format}'
|
|
2572
|
+
*/
|
|
2573
|
+
P.toFormat = function (dp, rm, format) {
|
|
2574
|
+
var str,
|
|
2575
|
+
x = this;
|
|
2576
|
+
|
|
2577
|
+
if (format == null) {
|
|
2578
|
+
if (dp != null && rm && typeof rm == 'object') {
|
|
2579
|
+
format = rm;
|
|
2580
|
+
rm = null;
|
|
2581
|
+
} else if (dp && typeof dp == 'object') {
|
|
2582
|
+
format = dp;
|
|
2583
|
+
dp = rm = null;
|
|
2584
|
+
} else {
|
|
2585
|
+
format = FORMAT;
|
|
2586
|
+
}
|
|
2587
|
+
} else if (typeof format != 'object') {
|
|
2588
|
+
throw Error
|
|
2589
|
+
(bignumberError + 'Argument not an object: ' + format);
|
|
2590
|
+
}
|
|
2591
|
+
|
|
2592
|
+
str = x.toFixed(dp, rm);
|
|
2593
|
+
|
|
2594
|
+
if (x.c) {
|
|
2595
|
+
var i,
|
|
2596
|
+
arr = str.split('.'),
|
|
2597
|
+
g1 = +format.groupSize,
|
|
2598
|
+
g2 = +format.secondaryGroupSize,
|
|
2599
|
+
groupSeparator = format.groupSeparator || '',
|
|
2600
|
+
intPart = arr[0],
|
|
2601
|
+
fractionPart = arr[1],
|
|
2602
|
+
isNeg = x.s < 0,
|
|
2603
|
+
intDigits = isNeg ? intPart.slice(1) : intPart,
|
|
2604
|
+
len = intDigits.length;
|
|
2605
|
+
|
|
2606
|
+
if (g2) i = g1, g1 = g2, g2 = i, len -= i;
|
|
2607
|
+
|
|
2608
|
+
if (g1 > 0 && len > 0) {
|
|
2609
|
+
i = len % g1 || g1;
|
|
2610
|
+
intPart = intDigits.substr(0, i);
|
|
2611
|
+
for (; i < len; i += g1) intPart += groupSeparator + intDigits.substr(i, g1);
|
|
2612
|
+
if (g2 > 0) intPart += groupSeparator + intDigits.slice(i);
|
|
2613
|
+
if (isNeg) intPart = '-' + intPart;
|
|
2614
|
+
}
|
|
2615
|
+
|
|
2616
|
+
str = fractionPart
|
|
2617
|
+
? intPart + (format.decimalSeparator || '') + ((g2 = +format.fractionGroupSize)
|
|
2618
|
+
? fractionPart.replace(new RegExp('\\d{' + g2 + '}\\B', 'g'),
|
|
2619
|
+
'$&' + (format.fractionGroupSeparator || ''))
|
|
2620
|
+
: fractionPart)
|
|
2621
|
+
: intPart;
|
|
2622
|
+
}
|
|
2623
|
+
|
|
2624
|
+
return (format.prefix || '') + str + (format.suffix || '');
|
|
2625
|
+
};
|
|
2626
|
+
|
|
2627
|
+
|
|
2628
|
+
/*
|
|
2629
|
+
* Return an array of two BigNumbers representing the value of this BigNumber as a simple
|
|
2630
|
+
* fraction with an integer numerator and an integer denominator.
|
|
2631
|
+
* The denominator will be a positive non-zero value less than or equal to the specified
|
|
2632
|
+
* maximum denominator. If a maximum denominator is not specified, the denominator will be
|
|
2633
|
+
* the lowest value necessary to represent the number exactly.
|
|
2634
|
+
*
|
|
2635
|
+
* [md] {number|string|BigNumber} Integer >= 1, or Infinity. The maximum denominator.
|
|
2636
|
+
*
|
|
2637
|
+
* '[BigNumber Error] Argument {not an integer|out of range} : {md}'
|
|
2638
|
+
*/
|
|
2639
|
+
P.toFraction = function (md) {
|
|
2640
|
+
var d, d0, d1, d2, e, exp, n, n0, n1, q, r, s,
|
|
2641
|
+
x = this,
|
|
2642
|
+
xc = x.c;
|
|
2643
|
+
|
|
2644
|
+
if (md != null) {
|
|
2645
|
+
n = new BigNumber(md);
|
|
2646
|
+
|
|
2647
|
+
// Throw if md is less than one or is not an integer, unless it is Infinity.
|
|
2648
|
+
if (!n.isInteger() && (n.c || n.s !== 1) || n.lt(ONE)) {
|
|
2649
|
+
throw Error
|
|
2650
|
+
(bignumberError + 'Argument ' +
|
|
2651
|
+
(n.isInteger() ? 'out of range: ' : 'not an integer: ') + valueOf(n));
|
|
2652
|
+
}
|
|
2653
|
+
}
|
|
2654
|
+
|
|
2655
|
+
if (!xc) return new BigNumber(x);
|
|
2656
|
+
|
|
2657
|
+
d = new BigNumber(ONE);
|
|
2658
|
+
n1 = d0 = new BigNumber(ONE);
|
|
2659
|
+
d1 = n0 = new BigNumber(ONE);
|
|
2660
|
+
s = coeffToString(xc);
|
|
2661
|
+
|
|
2662
|
+
// Determine initial denominator.
|
|
2663
|
+
// d is a power of 10 and the minimum max denominator that specifies the value exactly.
|
|
2664
|
+
e = d.e = s.length - x.e - 1;
|
|
2665
|
+
d.c[0] = POWS_TEN[(exp = e % LOG_BASE) < 0 ? LOG_BASE + exp : exp];
|
|
2666
|
+
md = !md || n.comparedTo(d) > 0 ? (e > 0 ? d : n1) : n;
|
|
2667
|
+
|
|
2668
|
+
exp = MAX_EXP;
|
|
2669
|
+
MAX_EXP = 1 / 0;
|
|
2670
|
+
n = new BigNumber(s);
|
|
2671
|
+
|
|
2672
|
+
// n0 = d1 = 0
|
|
2673
|
+
n0.c[0] = 0;
|
|
2674
|
+
|
|
2675
|
+
for (; ;) {
|
|
2676
|
+
q = div(n, d, 0, 1);
|
|
2677
|
+
d2 = d0.plus(q.times(d1));
|
|
2678
|
+
if (d2.comparedTo(md) == 1) break;
|
|
2679
|
+
d0 = d1;
|
|
2680
|
+
d1 = d2;
|
|
2681
|
+
n1 = n0.plus(q.times(d2 = n1));
|
|
2682
|
+
n0 = d2;
|
|
2683
|
+
d = n.minus(q.times(d2 = d));
|
|
2684
|
+
n = d2;
|
|
2685
|
+
}
|
|
2686
|
+
|
|
2687
|
+
d2 = div(md.minus(d0), d1, 0, 1);
|
|
2688
|
+
n0 = n0.plus(d2.times(n1));
|
|
2689
|
+
d0 = d0.plus(d2.times(d1));
|
|
2690
|
+
n0.s = n1.s = x.s;
|
|
2691
|
+
e = e * 2;
|
|
2692
|
+
|
|
2693
|
+
// Determine which fraction is closer to x, n0/d0 or n1/d1
|
|
2694
|
+
r = div(n1, d1, e, ROUNDING_MODE).minus(x).abs().comparedTo(
|
|
2695
|
+
div(n0, d0, e, ROUNDING_MODE).minus(x).abs()) < 1 ? [n1, d1] : [n0, d0];
|
|
2696
|
+
|
|
2697
|
+
MAX_EXP = exp;
|
|
2698
|
+
|
|
2699
|
+
return r;
|
|
2700
|
+
};
|
|
2701
|
+
|
|
2702
|
+
|
|
2703
|
+
/*
|
|
2704
|
+
* Return the value of this BigNumber converted to a number primitive.
|
|
2705
|
+
*/
|
|
2706
|
+
P.toNumber = function () {
|
|
2707
|
+
return +valueOf(this);
|
|
2708
|
+
};
|
|
2709
|
+
|
|
2710
|
+
|
|
2711
|
+
/*
|
|
2712
|
+
* Return a string representing the value of this BigNumber rounded to sd significant digits
|
|
2713
|
+
* using rounding mode rm or ROUNDING_MODE. If sd is less than the number of digits
|
|
2714
|
+
* necessary to represent the integer part of the value in fixed-point notation, then use
|
|
2715
|
+
* exponential notation.
|
|
2716
|
+
*
|
|
2717
|
+
* [sd] {number} Significant digits. Integer, 1 to MAX inclusive.
|
|
2718
|
+
* [rm] {number} Rounding mode. Integer, 0 to 8 inclusive.
|
|
2719
|
+
*
|
|
2720
|
+
* '[BigNumber Error] Argument {not a primitive number|not an integer|out of range}: {sd|rm}'
|
|
2721
|
+
*/
|
|
2722
|
+
P.toPrecision = function (sd, rm) {
|
|
2723
|
+
if (sd != null) intCheck(sd, 1, MAX);
|
|
2724
|
+
return format(this, sd, rm, 2);
|
|
2725
|
+
};
|
|
2726
|
+
|
|
2727
|
+
|
|
2728
|
+
/*
|
|
2729
|
+
* Return a string representing the value of this BigNumber in base b, or base 10 if b is
|
|
2730
|
+
* omitted. If a base is specified, including base 10, round according to DECIMAL_PLACES and
|
|
2731
|
+
* ROUNDING_MODE. If a base is not specified, and this BigNumber has a positive exponent
|
|
2732
|
+
* that is equal to or greater than TO_EXP_POS, or a negative exponent equal to or less than
|
|
2733
|
+
* TO_EXP_NEG, return exponential notation.
|
|
2734
|
+
*
|
|
2735
|
+
* [b] {number} Integer, 2 to ALPHABET.length inclusive.
|
|
2736
|
+
*
|
|
2737
|
+
* '[BigNumber Error] Base {not a primitive number|not an integer|out of range}: {b}'
|
|
2738
|
+
*/
|
|
2739
|
+
P.toString = function (b) {
|
|
2740
|
+
var str,
|
|
2741
|
+
n = this,
|
|
2742
|
+
s = n.s,
|
|
2743
|
+
e = n.e;
|
|
2744
|
+
|
|
2745
|
+
// Infinity or NaN?
|
|
2746
|
+
if (e === null) {
|
|
2747
|
+
if (s) {
|
|
2748
|
+
str = 'Infinity';
|
|
2749
|
+
if (s < 0) str = '-' + str;
|
|
2750
|
+
} else {
|
|
2751
|
+
str = 'NaN';
|
|
2752
|
+
}
|
|
2753
|
+
} else {
|
|
2754
|
+
if (b == null) {
|
|
2755
|
+
str = e <= TO_EXP_NEG || e >= TO_EXP_POS
|
|
2756
|
+
? toExponential(coeffToString(n.c), e)
|
|
2757
|
+
: toFixedPoint(coeffToString(n.c), e, '0');
|
|
2758
|
+
} else if (b === 10 && alphabetHasNormalDecimalDigits) {
|
|
2759
|
+
n = round(new BigNumber(n), DECIMAL_PLACES + e + 1, ROUNDING_MODE);
|
|
2760
|
+
str = toFixedPoint(coeffToString(n.c), n.e, '0');
|
|
2761
|
+
} else {
|
|
2762
|
+
intCheck(b, 2, ALPHABET.length, 'Base');
|
|
2763
|
+
str = convertBase(toFixedPoint(coeffToString(n.c), e, '0'), 10, b, s, true);
|
|
2764
|
+
}
|
|
2765
|
+
|
|
2766
|
+
if (s < 0 && n.c[0]) str = '-' + str;
|
|
2767
|
+
}
|
|
2768
|
+
|
|
2769
|
+
return str;
|
|
2770
|
+
};
|
|
2771
|
+
|
|
2772
|
+
|
|
2773
|
+
/*
|
|
2774
|
+
* Return as toString, but do not accept a base argument, and include the minus sign for
|
|
2775
|
+
* negative zero.
|
|
2776
|
+
*/
|
|
2777
|
+
P.valueOf = P.toJSON = function () {
|
|
2778
|
+
return valueOf(this);
|
|
2779
|
+
};
|
|
2780
|
+
|
|
2781
|
+
|
|
2782
|
+
P._isBigNumber = true;
|
|
2783
|
+
|
|
2784
|
+
P[Symbol.toStringTag] = 'BigNumber';
|
|
2785
|
+
|
|
2786
|
+
// Node.js v10.12.0+
|
|
2787
|
+
P[Symbol.for('nodejs.util.inspect.custom')] = P.valueOf;
|
|
2788
|
+
|
|
2789
|
+
if (configObject != null) BigNumber.set(configObject);
|
|
2790
|
+
|
|
2791
|
+
return BigNumber;
|
|
2792
|
+
}
|
|
2793
|
+
|
|
2794
|
+
|
|
2795
|
+
// PRIVATE HELPER FUNCTIONS
|
|
2796
|
+
|
|
2797
|
+
// These functions don't need access to variables,
|
|
2798
|
+
// e.g. DECIMAL_PLACES, in the scope of the `clone` function above.
|
|
2799
|
+
|
|
2800
|
+
|
|
2801
|
+
function bitFloor(n) {
|
|
2802
|
+
var i = n | 0;
|
|
2803
|
+
return n > 0 || n === i ? i : i - 1;
|
|
2804
|
+
}
|
|
2805
|
+
|
|
2806
|
+
|
|
2807
|
+
// Return a coefficient array as a string of base 10 digits.
|
|
2808
|
+
function coeffToString(a) {
|
|
2809
|
+
var s, z,
|
|
2810
|
+
i = 1,
|
|
2811
|
+
j = a.length,
|
|
2812
|
+
r = a[0] + '';
|
|
2813
|
+
|
|
2814
|
+
for (; i < j;) {
|
|
2815
|
+
s = a[i++] + '';
|
|
2816
|
+
z = LOG_BASE - s.length;
|
|
2817
|
+
for (; z--; s = '0' + s);
|
|
2818
|
+
r += s;
|
|
2819
|
+
}
|
|
2820
|
+
|
|
2821
|
+
// Determine trailing zeros.
|
|
2822
|
+
for (j = r.length; r.charCodeAt(--j) === 48;);
|
|
2823
|
+
|
|
2824
|
+
return r.slice(0, j + 1 || 1);
|
|
2825
|
+
}
|
|
2826
|
+
|
|
2827
|
+
|
|
2828
|
+
// Compare the value of BigNumbers x and y.
|
|
2829
|
+
function compare(x, y) {
|
|
2830
|
+
var a, b,
|
|
2831
|
+
xc = x.c,
|
|
2832
|
+
yc = y.c,
|
|
2833
|
+
i = x.s,
|
|
2834
|
+
j = y.s,
|
|
2835
|
+
k = x.e,
|
|
2836
|
+
l = y.e;
|
|
2837
|
+
|
|
2838
|
+
// Either NaN?
|
|
2839
|
+
if (!i || !j) return null;
|
|
2840
|
+
|
|
2841
|
+
a = xc && !xc[0];
|
|
2842
|
+
b = yc && !yc[0];
|
|
2843
|
+
|
|
2844
|
+
// Either zero?
|
|
2845
|
+
if (a || b) return a ? b ? 0 : -j : i;
|
|
2846
|
+
|
|
2847
|
+
// Signs differ?
|
|
2848
|
+
if (i != j) return i;
|
|
2849
|
+
|
|
2850
|
+
a = i < 0;
|
|
2851
|
+
b = k == l;
|
|
2852
|
+
|
|
2853
|
+
// Either Infinity?
|
|
2854
|
+
if (!xc || !yc) return b ? 0 : !xc ^ a ? 1 : -1;
|
|
2855
|
+
|
|
2856
|
+
// Compare exponents.
|
|
2857
|
+
if (!b) return k > l ^ a ? 1 : -1;
|
|
2858
|
+
|
|
2859
|
+
j = (k = xc.length) < (l = yc.length) ? k : l;
|
|
2860
|
+
|
|
2861
|
+
// Compare digit by digit.
|
|
2862
|
+
for (i = 0; i < j; i++) if (xc[i] != yc[i]) return xc[i] > yc[i] ^ a ? 1 : -1;
|
|
2863
|
+
|
|
2864
|
+
// Compare lengths.
|
|
2865
|
+
return k == l ? 0 : k > l ^ a ? 1 : -1;
|
|
2866
|
+
}
|
|
2867
|
+
|
|
2868
|
+
|
|
2869
|
+
/*
|
|
2870
|
+
* Check that n is a primitive number, an integer, and in range, otherwise throw.
|
|
2871
|
+
*/
|
|
2872
|
+
function intCheck(n, min, max, name) {
|
|
2873
|
+
if (n < min || n > max || n !== mathfloor(n)) {
|
|
2874
|
+
throw Error
|
|
2875
|
+
(bignumberError + (name || 'Argument') + (typeof n == 'number'
|
|
2876
|
+
? n < min || n > max ? ' out of range: ' : ' not an integer: '
|
|
2877
|
+
: ' not a primitive number: ') + String(n));
|
|
2878
|
+
}
|
|
2879
|
+
}
|
|
2880
|
+
|
|
2881
|
+
|
|
2882
|
+
// Assumes finite n.
|
|
2883
|
+
function isOdd(n) {
|
|
2884
|
+
var k = n.c.length - 1;
|
|
2885
|
+
return bitFloor(n.e / LOG_BASE) == k && n.c[k] % 2 != 0;
|
|
2886
|
+
}
|
|
2887
|
+
|
|
2888
|
+
|
|
2889
|
+
function toExponential(str, e) {
|
|
2890
|
+
return (str.length > 1 ? str.charAt(0) + '.' + str.slice(1) : str) +
|
|
2891
|
+
(e < 0 ? 'e' : 'e+') + e;
|
|
2892
|
+
}
|
|
2893
|
+
|
|
2894
|
+
|
|
2895
|
+
function toFixedPoint(str, e, z) {
|
|
2896
|
+
var len, zs;
|
|
2897
|
+
|
|
2898
|
+
// Negative exponent?
|
|
2899
|
+
if (e < 0) {
|
|
2900
|
+
|
|
2901
|
+
// Prepend zeros.
|
|
2902
|
+
for (zs = z + '.'; ++e; zs += z);
|
|
2903
|
+
str = zs + str;
|
|
2904
|
+
|
|
2905
|
+
// Positive exponent
|
|
2906
|
+
} else {
|
|
2907
|
+
len = str.length;
|
|
2908
|
+
|
|
2909
|
+
// Append zeros.
|
|
2910
|
+
if (++e > len) {
|
|
2911
|
+
for (zs = z, e -= len; --e; zs += z);
|
|
2912
|
+
str += zs;
|
|
2913
|
+
} else if (e < len) {
|
|
2914
|
+
str = str.slice(0, e) + '.' + str.slice(e);
|
|
2915
|
+
}
|
|
2916
|
+
}
|
|
2917
|
+
|
|
2918
|
+
return str;
|
|
2919
|
+
}
|
|
2920
|
+
|
|
2921
|
+
|
|
2922
|
+
// EXPORT
|
|
2923
|
+
|
|
2924
|
+
|
|
2925
|
+
var BigNumber = clone();
|
|
2926
|
+
|
|
2927
|
+
// src/index.ts
|
|
2928
|
+
var SplayTreeNode = class {
|
|
2929
|
+
key;
|
|
2930
|
+
left = null;
|
|
2931
|
+
right = null;
|
|
2932
|
+
constructor(key) {
|
|
2933
|
+
this.key = key;
|
|
2934
|
+
}
|
|
2935
|
+
};
|
|
2936
|
+
var SplayTreeSetNode = class extends SplayTreeNode {
|
|
2937
|
+
constructor(key) {
|
|
2938
|
+
super(key);
|
|
2939
|
+
}
|
|
2940
|
+
};
|
|
2941
|
+
var SplayTree = class {
|
|
2942
|
+
size = 0;
|
|
2943
|
+
modificationCount = 0;
|
|
2944
|
+
splayCount = 0;
|
|
2945
|
+
splay(key) {
|
|
2946
|
+
const root = this.root;
|
|
2947
|
+
if (root == null) {
|
|
2948
|
+
this.compare(key, key);
|
|
2949
|
+
return -1;
|
|
2950
|
+
}
|
|
2951
|
+
let right = null;
|
|
2952
|
+
let newTreeRight = null;
|
|
2953
|
+
let left = null;
|
|
2954
|
+
let newTreeLeft = null;
|
|
2955
|
+
let current = root;
|
|
2956
|
+
const compare = this.compare;
|
|
2957
|
+
let comp;
|
|
2958
|
+
while (true) {
|
|
2959
|
+
comp = compare(current.key, key);
|
|
2960
|
+
if (comp > 0) {
|
|
2961
|
+
let currentLeft = current.left;
|
|
2962
|
+
if (currentLeft == null) break;
|
|
2963
|
+
comp = compare(currentLeft.key, key);
|
|
2964
|
+
if (comp > 0) {
|
|
2965
|
+
current.left = currentLeft.right;
|
|
2966
|
+
currentLeft.right = current;
|
|
2967
|
+
current = currentLeft;
|
|
2968
|
+
currentLeft = current.left;
|
|
2969
|
+
if (currentLeft == null) break;
|
|
2970
|
+
}
|
|
2971
|
+
if (right == null) {
|
|
2972
|
+
newTreeRight = current;
|
|
2973
|
+
} else {
|
|
2974
|
+
right.left = current;
|
|
2975
|
+
}
|
|
2976
|
+
right = current;
|
|
2977
|
+
current = currentLeft;
|
|
2978
|
+
} else if (comp < 0) {
|
|
2979
|
+
let currentRight = current.right;
|
|
2980
|
+
if (currentRight == null) break;
|
|
2981
|
+
comp = compare(currentRight.key, key);
|
|
2982
|
+
if (comp < 0) {
|
|
2983
|
+
current.right = currentRight.left;
|
|
2984
|
+
currentRight.left = current;
|
|
2985
|
+
current = currentRight;
|
|
2986
|
+
currentRight = current.right;
|
|
2987
|
+
if (currentRight == null) break;
|
|
2988
|
+
}
|
|
2989
|
+
if (left == null) {
|
|
2990
|
+
newTreeLeft = current;
|
|
2991
|
+
} else {
|
|
2992
|
+
left.right = current;
|
|
2993
|
+
}
|
|
2994
|
+
left = current;
|
|
2995
|
+
current = currentRight;
|
|
2996
|
+
} else {
|
|
2997
|
+
break;
|
|
2998
|
+
}
|
|
2999
|
+
}
|
|
3000
|
+
if (left != null) {
|
|
3001
|
+
left.right = current.left;
|
|
3002
|
+
current.left = newTreeLeft;
|
|
3003
|
+
}
|
|
3004
|
+
if (right != null) {
|
|
3005
|
+
right.left = current.right;
|
|
3006
|
+
current.right = newTreeRight;
|
|
3007
|
+
}
|
|
3008
|
+
if (this.root !== current) {
|
|
3009
|
+
this.root = current;
|
|
3010
|
+
this.splayCount++;
|
|
3011
|
+
}
|
|
3012
|
+
return comp;
|
|
3013
|
+
}
|
|
3014
|
+
splayMin(node) {
|
|
3015
|
+
let current = node;
|
|
3016
|
+
let nextLeft = current.left;
|
|
3017
|
+
while (nextLeft != null) {
|
|
3018
|
+
const left = nextLeft;
|
|
3019
|
+
current.left = left.right;
|
|
3020
|
+
left.right = current;
|
|
3021
|
+
current = left;
|
|
3022
|
+
nextLeft = current.left;
|
|
3023
|
+
}
|
|
3024
|
+
return current;
|
|
3025
|
+
}
|
|
3026
|
+
splayMax(node) {
|
|
3027
|
+
let current = node;
|
|
3028
|
+
let nextRight = current.right;
|
|
3029
|
+
while (nextRight != null) {
|
|
3030
|
+
const right = nextRight;
|
|
3031
|
+
current.right = right.left;
|
|
3032
|
+
right.left = current;
|
|
3033
|
+
current = right;
|
|
3034
|
+
nextRight = current.right;
|
|
3035
|
+
}
|
|
3036
|
+
return current;
|
|
3037
|
+
}
|
|
3038
|
+
_delete(key) {
|
|
3039
|
+
if (this.root == null) return null;
|
|
3040
|
+
const comp = this.splay(key);
|
|
3041
|
+
if (comp != 0) return null;
|
|
3042
|
+
let root = this.root;
|
|
3043
|
+
const result = root;
|
|
3044
|
+
const left = root.left;
|
|
3045
|
+
this.size--;
|
|
3046
|
+
if (left == null) {
|
|
3047
|
+
this.root = root.right;
|
|
3048
|
+
} else {
|
|
3049
|
+
const right = root.right;
|
|
3050
|
+
root = this.splayMax(left);
|
|
3051
|
+
root.right = right;
|
|
3052
|
+
this.root = root;
|
|
3053
|
+
}
|
|
3054
|
+
this.modificationCount++;
|
|
3055
|
+
return result;
|
|
3056
|
+
}
|
|
3057
|
+
addNewRoot(node, comp) {
|
|
3058
|
+
this.size++;
|
|
3059
|
+
this.modificationCount++;
|
|
3060
|
+
const root = this.root;
|
|
3061
|
+
if (root == null) {
|
|
3062
|
+
this.root = node;
|
|
3063
|
+
return;
|
|
3064
|
+
}
|
|
3065
|
+
if (comp < 0) {
|
|
3066
|
+
node.left = root;
|
|
3067
|
+
node.right = root.right;
|
|
3068
|
+
root.right = null;
|
|
3069
|
+
} else {
|
|
3070
|
+
node.right = root;
|
|
3071
|
+
node.left = root.left;
|
|
3072
|
+
root.left = null;
|
|
3073
|
+
}
|
|
3074
|
+
this.root = node;
|
|
3075
|
+
}
|
|
3076
|
+
_first() {
|
|
3077
|
+
const root = this.root;
|
|
3078
|
+
if (root == null) return null;
|
|
3079
|
+
this.root = this.splayMin(root);
|
|
3080
|
+
return this.root;
|
|
3081
|
+
}
|
|
3082
|
+
_last() {
|
|
3083
|
+
const root = this.root;
|
|
3084
|
+
if (root == null) return null;
|
|
3085
|
+
this.root = this.splayMax(root);
|
|
3086
|
+
return this.root;
|
|
3087
|
+
}
|
|
3088
|
+
clear() {
|
|
3089
|
+
this.root = null;
|
|
3090
|
+
this.size = 0;
|
|
3091
|
+
this.modificationCount++;
|
|
3092
|
+
}
|
|
3093
|
+
has(key) {
|
|
3094
|
+
return this.validKey(key) && this.splay(key) == 0;
|
|
3095
|
+
}
|
|
3096
|
+
defaultCompare() {
|
|
3097
|
+
return (a, b) => a < b ? -1 : a > b ? 1 : 0;
|
|
3098
|
+
}
|
|
3099
|
+
wrap() {
|
|
3100
|
+
return {
|
|
3101
|
+
getRoot: () => {
|
|
3102
|
+
return this.root;
|
|
3103
|
+
},
|
|
3104
|
+
setRoot: (root) => {
|
|
3105
|
+
this.root = root;
|
|
3106
|
+
},
|
|
3107
|
+
getSize: () => {
|
|
3108
|
+
return this.size;
|
|
3109
|
+
},
|
|
3110
|
+
getModificationCount: () => {
|
|
3111
|
+
return this.modificationCount;
|
|
3112
|
+
},
|
|
3113
|
+
getSplayCount: () => {
|
|
3114
|
+
return this.splayCount;
|
|
3115
|
+
},
|
|
3116
|
+
setSplayCount: (count) => {
|
|
3117
|
+
this.splayCount = count;
|
|
3118
|
+
},
|
|
3119
|
+
splay: (key) => {
|
|
3120
|
+
return this.splay(key);
|
|
3121
|
+
},
|
|
3122
|
+
has: (key) => {
|
|
3123
|
+
return this.has(key);
|
|
3124
|
+
}
|
|
3125
|
+
};
|
|
3126
|
+
}
|
|
3127
|
+
};
|
|
3128
|
+
var SplayTreeSet = class _SplayTreeSet extends SplayTree {
|
|
3129
|
+
root = null;
|
|
3130
|
+
compare;
|
|
3131
|
+
validKey;
|
|
3132
|
+
constructor(compare, isValidKey) {
|
|
3133
|
+
super();
|
|
3134
|
+
this.compare = compare ?? this.defaultCompare();
|
|
3135
|
+
this.validKey = isValidKey ?? ((v) => v != null && v != void 0);
|
|
3136
|
+
}
|
|
3137
|
+
delete(element) {
|
|
3138
|
+
if (!this.validKey(element)) return false;
|
|
3139
|
+
return this._delete(element) != null;
|
|
3140
|
+
}
|
|
3141
|
+
deleteAll(elements) {
|
|
3142
|
+
for (const element of elements) {
|
|
3143
|
+
this.delete(element);
|
|
3144
|
+
}
|
|
3145
|
+
}
|
|
3146
|
+
forEach(f) {
|
|
3147
|
+
const nodes = this[Symbol.iterator]();
|
|
3148
|
+
let result;
|
|
3149
|
+
while (result = nodes.next(), !result.done) {
|
|
3150
|
+
f(result.value, result.value, this);
|
|
3151
|
+
}
|
|
3152
|
+
}
|
|
3153
|
+
add(element) {
|
|
3154
|
+
const compare = this.splay(element);
|
|
3155
|
+
if (compare != 0) this.addNewRoot(new SplayTreeSetNode(element), compare);
|
|
3156
|
+
return this;
|
|
3157
|
+
}
|
|
3158
|
+
addAndReturn(element) {
|
|
3159
|
+
const compare = this.splay(element);
|
|
3160
|
+
if (compare != 0) this.addNewRoot(new SplayTreeSetNode(element), compare);
|
|
3161
|
+
return this.root.key;
|
|
3162
|
+
}
|
|
3163
|
+
addAll(elements) {
|
|
3164
|
+
for (const element of elements) {
|
|
3165
|
+
this.add(element);
|
|
3166
|
+
}
|
|
3167
|
+
}
|
|
3168
|
+
isEmpty() {
|
|
3169
|
+
return this.root == null;
|
|
3170
|
+
}
|
|
3171
|
+
isNotEmpty() {
|
|
3172
|
+
return this.root != null;
|
|
3173
|
+
}
|
|
3174
|
+
single() {
|
|
3175
|
+
if (this.size == 0) throw "Bad state: No element";
|
|
3176
|
+
if (this.size > 1) throw "Bad state: Too many element";
|
|
3177
|
+
return this.root.key;
|
|
3178
|
+
}
|
|
3179
|
+
first() {
|
|
3180
|
+
if (this.size == 0) throw "Bad state: No element";
|
|
3181
|
+
return this._first().key;
|
|
3182
|
+
}
|
|
3183
|
+
last() {
|
|
3184
|
+
if (this.size == 0) throw "Bad state: No element";
|
|
3185
|
+
return this._last().key;
|
|
3186
|
+
}
|
|
3187
|
+
lastBefore(element) {
|
|
3188
|
+
if (element == null) throw "Invalid arguments(s)";
|
|
3189
|
+
if (this.root == null) return null;
|
|
3190
|
+
const comp = this.splay(element);
|
|
3191
|
+
if (comp < 0) return this.root.key;
|
|
3192
|
+
let node = this.root.left;
|
|
3193
|
+
if (node == null) return null;
|
|
3194
|
+
let nodeRight = node.right;
|
|
3195
|
+
while (nodeRight != null) {
|
|
3196
|
+
node = nodeRight;
|
|
3197
|
+
nodeRight = node.right;
|
|
3198
|
+
}
|
|
3199
|
+
return node.key;
|
|
3200
|
+
}
|
|
3201
|
+
firstAfter(element) {
|
|
3202
|
+
if (element == null) throw "Invalid arguments(s)";
|
|
3203
|
+
if (this.root == null) return null;
|
|
3204
|
+
const comp = this.splay(element);
|
|
3205
|
+
if (comp > 0) return this.root.key;
|
|
3206
|
+
let node = this.root.right;
|
|
3207
|
+
if (node == null) return null;
|
|
3208
|
+
let nodeLeft = node.left;
|
|
3209
|
+
while (nodeLeft != null) {
|
|
3210
|
+
node = nodeLeft;
|
|
3211
|
+
nodeLeft = node.left;
|
|
3212
|
+
}
|
|
3213
|
+
return node.key;
|
|
3214
|
+
}
|
|
3215
|
+
retainAll(elements) {
|
|
3216
|
+
const retainSet = new _SplayTreeSet(this.compare, this.validKey);
|
|
3217
|
+
const modificationCount = this.modificationCount;
|
|
3218
|
+
for (const object of elements) {
|
|
3219
|
+
if (modificationCount != this.modificationCount) {
|
|
3220
|
+
throw "Concurrent modification during iteration.";
|
|
3221
|
+
}
|
|
3222
|
+
if (this.validKey(object) && this.splay(object) == 0) {
|
|
3223
|
+
retainSet.add(this.root.key);
|
|
3224
|
+
}
|
|
3225
|
+
}
|
|
3226
|
+
if (retainSet.size != this.size) {
|
|
3227
|
+
this.root = retainSet.root;
|
|
3228
|
+
this.size = retainSet.size;
|
|
3229
|
+
this.modificationCount++;
|
|
3230
|
+
}
|
|
3231
|
+
}
|
|
3232
|
+
lookup(object) {
|
|
3233
|
+
if (!this.validKey(object)) return null;
|
|
3234
|
+
const comp = this.splay(object);
|
|
3235
|
+
if (comp != 0) return null;
|
|
3236
|
+
return this.root.key;
|
|
3237
|
+
}
|
|
3238
|
+
intersection(other) {
|
|
3239
|
+
const result = new _SplayTreeSet(this.compare, this.validKey);
|
|
3240
|
+
for (const element of this) {
|
|
3241
|
+
if (other.has(element)) result.add(element);
|
|
3242
|
+
}
|
|
3243
|
+
return result;
|
|
3244
|
+
}
|
|
3245
|
+
difference(other) {
|
|
3246
|
+
const result = new _SplayTreeSet(this.compare, this.validKey);
|
|
3247
|
+
for (const element of this) {
|
|
3248
|
+
if (!other.has(element)) result.add(element);
|
|
3249
|
+
}
|
|
3250
|
+
return result;
|
|
3251
|
+
}
|
|
3252
|
+
union(other) {
|
|
3253
|
+
const u = this.clone();
|
|
3254
|
+
u.addAll(other);
|
|
3255
|
+
return u;
|
|
3256
|
+
}
|
|
3257
|
+
clone() {
|
|
3258
|
+
const set = new _SplayTreeSet(this.compare, this.validKey);
|
|
3259
|
+
set.size = this.size;
|
|
3260
|
+
set.root = this.copyNode(this.root);
|
|
3261
|
+
return set;
|
|
3262
|
+
}
|
|
3263
|
+
copyNode(node) {
|
|
3264
|
+
if (node == null) return null;
|
|
3265
|
+
function copyChildren(node2, dest) {
|
|
3266
|
+
let left;
|
|
3267
|
+
let right;
|
|
3268
|
+
do {
|
|
3269
|
+
left = node2.left;
|
|
3270
|
+
right = node2.right;
|
|
3271
|
+
if (left != null) {
|
|
3272
|
+
const newLeft = new SplayTreeSetNode(left.key);
|
|
3273
|
+
dest.left = newLeft;
|
|
3274
|
+
copyChildren(left, newLeft);
|
|
3275
|
+
}
|
|
3276
|
+
if (right != null) {
|
|
3277
|
+
const newRight = new SplayTreeSetNode(right.key);
|
|
3278
|
+
dest.right = newRight;
|
|
3279
|
+
node2 = right;
|
|
3280
|
+
dest = newRight;
|
|
3281
|
+
}
|
|
3282
|
+
} while (right != null);
|
|
3283
|
+
}
|
|
3284
|
+
const result = new SplayTreeSetNode(node.key);
|
|
3285
|
+
copyChildren(node, result);
|
|
3286
|
+
return result;
|
|
3287
|
+
}
|
|
3288
|
+
toSet() {
|
|
3289
|
+
return this.clone();
|
|
3290
|
+
}
|
|
3291
|
+
entries() {
|
|
3292
|
+
return new SplayTreeSetEntryIterableIterator(this.wrap());
|
|
3293
|
+
}
|
|
3294
|
+
keys() {
|
|
3295
|
+
return this[Symbol.iterator]();
|
|
3296
|
+
}
|
|
3297
|
+
values() {
|
|
3298
|
+
return this[Symbol.iterator]();
|
|
3299
|
+
}
|
|
3300
|
+
[Symbol.iterator]() {
|
|
3301
|
+
return new SplayTreeKeyIterableIterator(this.wrap());
|
|
3302
|
+
}
|
|
3303
|
+
[Symbol.toStringTag] = "[object Set]";
|
|
3304
|
+
};
|
|
3305
|
+
var SplayTreeIterableIterator = class {
|
|
3306
|
+
tree;
|
|
3307
|
+
path = new Array();
|
|
3308
|
+
modificationCount = null;
|
|
3309
|
+
splayCount;
|
|
3310
|
+
constructor(tree) {
|
|
3311
|
+
this.tree = tree;
|
|
3312
|
+
this.splayCount = tree.getSplayCount();
|
|
3313
|
+
}
|
|
3314
|
+
[Symbol.iterator]() {
|
|
3315
|
+
return this;
|
|
3316
|
+
}
|
|
3317
|
+
next() {
|
|
3318
|
+
if (this.moveNext()) return { done: false, value: this.current() };
|
|
3319
|
+
return { done: true, value: null };
|
|
3320
|
+
}
|
|
3321
|
+
current() {
|
|
3322
|
+
if (!this.path.length) return null;
|
|
3323
|
+
const node = this.path[this.path.length - 1];
|
|
3324
|
+
return this.getValue(node);
|
|
3325
|
+
}
|
|
3326
|
+
rebuildPath(key) {
|
|
3327
|
+
this.path.splice(0, this.path.length);
|
|
3328
|
+
this.tree.splay(key);
|
|
3329
|
+
this.path.push(this.tree.getRoot());
|
|
3330
|
+
this.splayCount = this.tree.getSplayCount();
|
|
3331
|
+
}
|
|
3332
|
+
findLeftMostDescendent(node) {
|
|
3333
|
+
while (node != null) {
|
|
3334
|
+
this.path.push(node);
|
|
3335
|
+
node = node.left;
|
|
3336
|
+
}
|
|
3337
|
+
}
|
|
3338
|
+
moveNext() {
|
|
3339
|
+
if (this.modificationCount != this.tree.getModificationCount()) {
|
|
3340
|
+
if (this.modificationCount == null) {
|
|
3341
|
+
this.modificationCount = this.tree.getModificationCount();
|
|
3342
|
+
let node2 = this.tree.getRoot();
|
|
3343
|
+
while (node2 != null) {
|
|
3344
|
+
this.path.push(node2);
|
|
3345
|
+
node2 = node2.left;
|
|
3346
|
+
}
|
|
3347
|
+
return this.path.length > 0;
|
|
3348
|
+
}
|
|
3349
|
+
throw "Concurrent modification during iteration.";
|
|
3350
|
+
}
|
|
3351
|
+
if (!this.path.length) return false;
|
|
3352
|
+
if (this.splayCount != this.tree.getSplayCount()) {
|
|
3353
|
+
this.rebuildPath(this.path[this.path.length - 1].key);
|
|
3354
|
+
}
|
|
3355
|
+
let node = this.path[this.path.length - 1];
|
|
3356
|
+
let next = node.right;
|
|
3357
|
+
if (next != null) {
|
|
3358
|
+
while (next != null) {
|
|
3359
|
+
this.path.push(next);
|
|
3360
|
+
next = next.left;
|
|
3361
|
+
}
|
|
3362
|
+
return true;
|
|
3363
|
+
}
|
|
3364
|
+
this.path.pop();
|
|
3365
|
+
while (this.path.length && this.path[this.path.length - 1].right === node) {
|
|
3366
|
+
node = this.path.pop();
|
|
3367
|
+
}
|
|
3368
|
+
return this.path.length > 0;
|
|
3369
|
+
}
|
|
3370
|
+
};
|
|
3371
|
+
var SplayTreeKeyIterableIterator = class extends SplayTreeIterableIterator {
|
|
3372
|
+
getValue(node) {
|
|
3373
|
+
return node.key;
|
|
3374
|
+
}
|
|
3375
|
+
};
|
|
3376
|
+
var SplayTreeSetEntryIterableIterator = class extends SplayTreeIterableIterator {
|
|
3377
|
+
getValue(node) {
|
|
3378
|
+
return [node.key, node.key];
|
|
3379
|
+
}
|
|
3380
|
+
};
|
|
3381
|
+
|
|
3382
|
+
var identity = (x) => {
|
|
3383
|
+
return x;
|
|
3384
|
+
};
|
|
3385
|
+
|
|
3386
|
+
var snap = (eps) => {
|
|
3387
|
+
if (eps) {
|
|
3388
|
+
const xTree = new SplayTreeSet(compare$1(eps));
|
|
3389
|
+
const yTree = new SplayTreeSet(compare$1(eps));
|
|
3390
|
+
const snapCoord = (coord, tree) => {
|
|
3391
|
+
return tree.addAndReturn(coord);
|
|
3392
|
+
};
|
|
3393
|
+
const snap = (v) => {
|
|
3394
|
+
return {
|
|
3395
|
+
x: snapCoord(v.x, xTree),
|
|
3396
|
+
y: snapCoord(v.y, yTree),
|
|
3397
|
+
};
|
|
3398
|
+
};
|
|
3399
|
+
snap({ x: new BigNumber(0), y: new BigNumber(0) });
|
|
3400
|
+
return snap;
|
|
3401
|
+
}
|
|
3402
|
+
return identity;
|
|
3403
|
+
};
|
|
3404
|
+
|
|
3405
|
+
const set = (eps) => {
|
|
3406
|
+
return {
|
|
3407
|
+
set: (eps) => { precision = set(eps); },
|
|
3408
|
+
reset: () => set(eps),
|
|
3409
|
+
compare: compare$1(eps),
|
|
3410
|
+
snap: snap(eps),
|
|
3411
|
+
orient: orient(eps)
|
|
3412
|
+
};
|
|
3413
|
+
};
|
|
3414
|
+
let precision = set();
|
|
3415
|
+
|
|
3416
|
+
/**
|
|
3417
|
+
* A bounding box has the format:
|
|
3418
|
+
*
|
|
3419
|
+
* { ll: { x: xmin, y: ymin }, ur: { x: xmax, y: ymax } }
|
|
3420
|
+
*
|
|
3421
|
+
*/
|
|
3422
|
+
const isInBbox = (bbox, point) => {
|
|
3423
|
+
return (bbox.ll.x.isLessThanOrEqualTo(point.x) &&
|
|
3424
|
+
point.x.isLessThanOrEqualTo(bbox.ur.x) &&
|
|
3425
|
+
bbox.ll.y.isLessThanOrEqualTo(point.y) &&
|
|
3426
|
+
point.y.isLessThanOrEqualTo(bbox.ur.y));
|
|
3427
|
+
};
|
|
3428
|
+
/* Returns either null, or a bbox (aka an ordered pair of points)
|
|
3429
|
+
* If there is only one point of overlap, a bbox with identical points
|
|
3430
|
+
* will be returned */
|
|
3431
|
+
const getBboxOverlap = (b1, b2) => {
|
|
3432
|
+
// check if the bboxes overlap at all
|
|
3433
|
+
if (b2.ur.x.isLessThan(b1.ll.x) ||
|
|
3434
|
+
b1.ur.x.isLessThan(b2.ll.x) ||
|
|
3435
|
+
b2.ur.y.isLessThan(b1.ll.y) ||
|
|
3436
|
+
b1.ur.y.isLessThan(b2.ll.y))
|
|
3437
|
+
return null;
|
|
3438
|
+
// find the middle two X values
|
|
3439
|
+
const lowerX = b1.ll.x.isLessThan(b2.ll.x) ? b2.ll.x : b1.ll.x;
|
|
3440
|
+
const upperX = b1.ur.x.isLessThan(b2.ur.x) ? b1.ur.x : b2.ur.x;
|
|
3441
|
+
// find the middle two Y values
|
|
3442
|
+
const lowerY = b1.ll.y.isLessThan(b2.ll.y) ? b2.ll.y : b1.ll.y;
|
|
3443
|
+
const upperY = b1.ur.y.isLessThan(b2.ur.y) ? b1.ur.y : b2.ur.y;
|
|
3444
|
+
// put those middle values together to get the overlap
|
|
3445
|
+
return { ll: { x: lowerX, y: lowerY }, ur: { x: upperX, y: upperY } };
|
|
3446
|
+
};
|
|
3447
|
+
|
|
3448
|
+
/* Cross Product of two vectors with first point at origin */
|
|
3449
|
+
const crossProduct = (a, b) => a.x.times(b.y).minus(a.y.times(b.x));
|
|
3450
|
+
/* Dot Product of two vectors with first point at origin */
|
|
3451
|
+
const dotProduct = (a, b) => a.x.times(b.x).plus(a.y.times(b.y));
|
|
3452
|
+
const length = (v) => dotProduct(v, v).sqrt();
|
|
3453
|
+
/* Get the sine of the angle from pShared -> pAngle to pShaed -> pBase */
|
|
3454
|
+
const sineOfAngle = (pShared, pBase, pAngle) => {
|
|
3455
|
+
const vBase = { x: pBase.x.minus(pShared.x), y: pBase.y.minus(pShared.y) };
|
|
3456
|
+
const vAngle = { x: pAngle.x.minus(pShared.x), y: pAngle.y.minus(pShared.y) };
|
|
3457
|
+
return crossProduct(vAngle, vBase).div(length(vAngle)).div(length(vBase));
|
|
3458
|
+
};
|
|
3459
|
+
/* Get the cosine of the angle from pShared -> pAngle to pShaed -> pBase */
|
|
3460
|
+
const cosineOfAngle = (pShared, pBase, pAngle) => {
|
|
3461
|
+
const vBase = { x: pBase.x.minus(pShared.x), y: pBase.y.minus(pShared.y) };
|
|
3462
|
+
const vAngle = { x: pAngle.x.minus(pShared.x), y: pAngle.y.minus(pShared.y) };
|
|
3463
|
+
return dotProduct(vAngle, vBase).div(length(vAngle)).div(length(vBase));
|
|
3464
|
+
};
|
|
3465
|
+
/* Get the x coordinate where the given line (defined by a point and vector)
|
|
3466
|
+
* crosses the horizontal line with the given y coordiante.
|
|
3467
|
+
* In the case of parrallel lines (including overlapping ones) returns null. */
|
|
3468
|
+
const horizontalIntersection = (pt, v, y) => {
|
|
3469
|
+
if (v.y.isZero())
|
|
3470
|
+
return null;
|
|
3471
|
+
return { x: pt.x.plus((v.x.div(v.y)).times(y.minus(pt.y))), y: y };
|
|
3472
|
+
};
|
|
3473
|
+
/* Get the y coordinate where the given line (defined by a point and vector)
|
|
3474
|
+
* crosses the vertical line with the given x coordiante.
|
|
3475
|
+
* In the case of parrallel lines (including overlapping ones) returns null. */
|
|
3476
|
+
const verticalIntersection = (pt, v, x) => {
|
|
3477
|
+
if (v.x.isZero())
|
|
3478
|
+
return null;
|
|
3479
|
+
return { x: x, y: pt.y.plus((v.y.div(v.x)).times(x.minus(pt.x))) };
|
|
3480
|
+
};
|
|
3481
|
+
/* Get the intersection of two lines, each defined by a base point and a vector.
|
|
3482
|
+
* In the case of parrallel lines (including overlapping ones) returns null. */
|
|
3483
|
+
const intersection$1 = (pt1, v1, pt2, v2) => {
|
|
3484
|
+
// take some shortcuts for vertical and horizontal lines
|
|
3485
|
+
// this also ensures we don't calculate an intersection and then discover
|
|
3486
|
+
// it's actually outside the bounding box of the line
|
|
3487
|
+
if (v1.x.isZero())
|
|
3488
|
+
return verticalIntersection(pt2, v2, pt1.x);
|
|
3489
|
+
if (v2.x.isZero())
|
|
3490
|
+
return verticalIntersection(pt1, v1, pt2.x);
|
|
3491
|
+
if (v1.y.isZero())
|
|
3492
|
+
return horizontalIntersection(pt2, v2, pt1.y);
|
|
3493
|
+
if (v2.y.isZero())
|
|
3494
|
+
return horizontalIntersection(pt1, v1, pt2.y);
|
|
3495
|
+
// General case for non-overlapping segments.
|
|
3496
|
+
// This algorithm is based on Schneider and Eberly.
|
|
3497
|
+
// http://www.cimec.org.ar/~ncalvo/Schneider_Eberly.pdf - pg 244
|
|
3498
|
+
const kross = crossProduct(v1, v2);
|
|
3499
|
+
if (kross.isZero())
|
|
3500
|
+
return null;
|
|
3501
|
+
const ve = { x: pt2.x.minus(pt1.x), y: pt2.y.minus(pt1.y) };
|
|
3502
|
+
const d1 = crossProduct(ve, v1).div(kross);
|
|
3503
|
+
const d2 = crossProduct(ve, v2).div(kross);
|
|
3504
|
+
// take the average of the two calculations to minimize rounding error
|
|
3505
|
+
const x1 = pt1.x.plus(d2.times(v1.x)), x2 = pt2.x.plus(d1.times(v2.x));
|
|
3506
|
+
const y1 = pt1.y.plus(d2.times(v1.y)), y2 = pt2.y.plus(d1.times(v2.y));
|
|
3507
|
+
const x = x1.plus(x2).div(2);
|
|
3508
|
+
const y = y1.plus(y2).div(2);
|
|
3509
|
+
return { x: x, y: y };
|
|
3510
|
+
};
|
|
3511
|
+
|
|
3512
|
+
class SweepEvent {
|
|
3513
|
+
point;
|
|
3514
|
+
isLeft;
|
|
3515
|
+
segment;
|
|
3516
|
+
otherSE;
|
|
3517
|
+
consumedBy;
|
|
3518
|
+
// for ordering sweep events in the sweep event queue
|
|
3519
|
+
static compare(a, b) {
|
|
3520
|
+
// favor event with a point that the sweep line hits first
|
|
3521
|
+
const ptCmp = SweepEvent.comparePoints(a.point, b.point);
|
|
3522
|
+
if (ptCmp !== 0)
|
|
3523
|
+
return ptCmp;
|
|
3524
|
+
// the points are the same, so link them if needed
|
|
3525
|
+
if (a.point !== b.point)
|
|
3526
|
+
a.link(b);
|
|
3527
|
+
// favor right events over left
|
|
3528
|
+
if (a.isLeft !== b.isLeft)
|
|
3529
|
+
return a.isLeft ? 1 : -1;
|
|
3530
|
+
// we have two matching left or right endpoints
|
|
3531
|
+
// ordering of this case is the same as for their segments
|
|
3532
|
+
return Segment.compare(a.segment, b.segment);
|
|
3533
|
+
}
|
|
3534
|
+
// for ordering points in sweep line order
|
|
3535
|
+
static comparePoints(aPt, bPt) {
|
|
3536
|
+
if (aPt.x.isLessThan(bPt.x))
|
|
3537
|
+
return -1;
|
|
3538
|
+
if (aPt.x.isGreaterThan(bPt.x))
|
|
3539
|
+
return 1;
|
|
3540
|
+
if (aPt.y.isLessThan(bPt.y))
|
|
3541
|
+
return -1;
|
|
3542
|
+
if (aPt.y.isGreaterThan(bPt.y))
|
|
3543
|
+
return 1;
|
|
3544
|
+
return 0;
|
|
3545
|
+
}
|
|
3546
|
+
// Warning: 'point' input will be modified and re-used (for performance)
|
|
3547
|
+
constructor(point, isLeft) {
|
|
3548
|
+
if (point.events === undefined)
|
|
3549
|
+
point.events = [this];
|
|
3550
|
+
else
|
|
3551
|
+
point.events.push(this);
|
|
3552
|
+
this.point = point;
|
|
3553
|
+
this.isLeft = isLeft;
|
|
3554
|
+
// this.segment, this.otherSE set by factory
|
|
3555
|
+
}
|
|
3556
|
+
link(other) {
|
|
3557
|
+
if (other.point === this.point) {
|
|
3558
|
+
throw new Error("Tried to link already linked events");
|
|
3559
|
+
}
|
|
3560
|
+
const otherEvents = other.point.events;
|
|
3561
|
+
for (let i = 0, iMax = otherEvents.length; i < iMax; i++) {
|
|
3562
|
+
const evt = otherEvents[i];
|
|
3563
|
+
this.point.events.push(evt);
|
|
3564
|
+
evt.point = this.point;
|
|
3565
|
+
}
|
|
3566
|
+
this.checkForConsuming();
|
|
3567
|
+
}
|
|
3568
|
+
/* Do a pass over our linked events and check to see if any pair
|
|
3569
|
+
* of segments match, and should be consumed. */
|
|
3570
|
+
checkForConsuming() {
|
|
3571
|
+
// FIXME: The loops in this method run O(n^2) => no good.
|
|
3572
|
+
// Maintain little ordered sweep event trees?
|
|
3573
|
+
// Can we maintaining an ordering that avoids the need
|
|
3574
|
+
// for the re-sorting with getLeftmostComparator in geom-out?
|
|
3575
|
+
// Compare each pair of events to see if other events also match
|
|
3576
|
+
const numEvents = this.point.events.length;
|
|
3577
|
+
for (let i = 0; i < numEvents; i++) {
|
|
3578
|
+
const evt1 = this.point.events[i];
|
|
3579
|
+
if (evt1.segment.consumedBy !== undefined)
|
|
3580
|
+
continue;
|
|
3581
|
+
for (let j = i + 1; j < numEvents; j++) {
|
|
3582
|
+
const evt2 = this.point.events[j];
|
|
3583
|
+
if (evt2.consumedBy !== undefined)
|
|
3584
|
+
continue;
|
|
3585
|
+
if (evt1.otherSE.point.events !== evt2.otherSE.point.events)
|
|
3586
|
+
continue;
|
|
3587
|
+
evt1.segment.consume(evt2.segment);
|
|
3588
|
+
}
|
|
3589
|
+
}
|
|
3590
|
+
}
|
|
3591
|
+
getAvailableLinkedEvents() {
|
|
3592
|
+
// point.events is always of length 2 or greater
|
|
3593
|
+
const events = [];
|
|
3594
|
+
for (let i = 0, iMax = this.point.events.length; i < iMax; i++) {
|
|
3595
|
+
const evt = this.point.events[i];
|
|
3596
|
+
if (evt !== this && !evt.segment.ringOut && evt.segment.isInResult()) {
|
|
3597
|
+
events.push(evt);
|
|
3598
|
+
}
|
|
3599
|
+
}
|
|
3600
|
+
return events;
|
|
3601
|
+
}
|
|
3602
|
+
/**
|
|
3603
|
+
* Returns a comparator function for sorting linked events that will
|
|
3604
|
+
* favor the event that will give us the smallest left-side angle.
|
|
3605
|
+
* All ring construction starts as low as possible heading to the right,
|
|
3606
|
+
* so by always turning left as sharp as possible we'll get polygons
|
|
3607
|
+
* without uncessary loops & holes.
|
|
3608
|
+
*
|
|
3609
|
+
* The comparator function has a compute cache such that it avoids
|
|
3610
|
+
* re-computing already-computed values.
|
|
3611
|
+
*/
|
|
3612
|
+
getLeftmostComparator(baseEvent) {
|
|
3613
|
+
const cache = new Map();
|
|
3614
|
+
const fillCache = (linkedEvent) => {
|
|
3615
|
+
const nextEvent = linkedEvent.otherSE;
|
|
3616
|
+
cache.set(linkedEvent, {
|
|
3617
|
+
sine: sineOfAngle(this.point, baseEvent.point, nextEvent.point),
|
|
3618
|
+
cosine: cosineOfAngle(this.point, baseEvent.point, nextEvent.point),
|
|
3619
|
+
});
|
|
3620
|
+
};
|
|
3621
|
+
return (a, b) => {
|
|
3622
|
+
if (!cache.has(a))
|
|
3623
|
+
fillCache(a);
|
|
3624
|
+
if (!cache.has(b))
|
|
3625
|
+
fillCache(b);
|
|
3626
|
+
const { sine: asine, cosine: acosine } = cache.get(a);
|
|
3627
|
+
const { sine: bsine, cosine: bcosine } = cache.get(b);
|
|
3628
|
+
// both on or above x-axis
|
|
3629
|
+
if (asine.isGreaterThanOrEqualTo(0) && bsine.isGreaterThanOrEqualTo(0)) {
|
|
3630
|
+
if (acosine.isLessThan(bcosine))
|
|
3631
|
+
return 1;
|
|
3632
|
+
if (acosine.isGreaterThan(bcosine))
|
|
3633
|
+
return -1;
|
|
3634
|
+
return 0;
|
|
3635
|
+
}
|
|
3636
|
+
// both below x-axis
|
|
3637
|
+
if (asine.isLessThan(0) && bsine.isLessThan(0)) {
|
|
3638
|
+
if (acosine.isLessThan(bcosine))
|
|
3639
|
+
return -1;
|
|
3640
|
+
if (acosine.isGreaterThan(bcosine))
|
|
3641
|
+
return 1;
|
|
3642
|
+
return 0;
|
|
3643
|
+
}
|
|
3644
|
+
// one above x-axis, one below
|
|
3645
|
+
if (bsine.isLessThan(asine))
|
|
3646
|
+
return -1;
|
|
3647
|
+
if (bsine.isGreaterThan(asine))
|
|
3648
|
+
return 1;
|
|
3649
|
+
return 0;
|
|
3650
|
+
};
|
|
3651
|
+
}
|
|
3652
|
+
}
|
|
3653
|
+
|
|
3654
|
+
// Give segments unique ID's to get consistent sorting of
|
|
3655
|
+
// segments and sweep events when all else is identical
|
|
3656
|
+
let segmentId = 0;
|
|
3657
|
+
class Segment {
|
|
3658
|
+
id;
|
|
3659
|
+
leftSE;
|
|
3660
|
+
rightSE;
|
|
3661
|
+
rings;
|
|
3662
|
+
windings;
|
|
3663
|
+
ringOut;
|
|
3664
|
+
consumedBy;
|
|
3665
|
+
prev;
|
|
3666
|
+
_prevInResult;
|
|
3667
|
+
_beforeState;
|
|
3668
|
+
_afterState;
|
|
3669
|
+
_isInResult;
|
|
3670
|
+
/* This compare() function is for ordering segments in the sweep
|
|
3671
|
+
* line tree, and does so according to the following criteria:
|
|
3672
|
+
*
|
|
3673
|
+
* Consider the vertical line that lies an infinestimal step to the
|
|
3674
|
+
* right of the right-more of the two left endpoints of the input
|
|
3675
|
+
* segments. Imagine slowly moving a point up from negative infinity
|
|
3676
|
+
* in the increasing y direction. Which of the two segments will that
|
|
3677
|
+
* point intersect first? That segment comes 'before' the other one.
|
|
3678
|
+
*
|
|
3679
|
+
* If neither segment would be intersected by such a line, (if one
|
|
3680
|
+
* or more of the segments are vertical) then the line to be considered
|
|
3681
|
+
* is directly on the right-more of the two left inputs.
|
|
3682
|
+
*/
|
|
3683
|
+
static compare(a, b) {
|
|
3684
|
+
const alx = a.leftSE.point.x;
|
|
3685
|
+
const blx = b.leftSE.point.x;
|
|
3686
|
+
const arx = a.rightSE.point.x;
|
|
3687
|
+
const brx = b.rightSE.point.x;
|
|
3688
|
+
// check if they're even in the same vertical plane
|
|
3689
|
+
if (brx.isLessThan(alx))
|
|
3690
|
+
return 1;
|
|
3691
|
+
if (arx.isLessThan(blx))
|
|
3692
|
+
return -1;
|
|
3693
|
+
const aly = a.leftSE.point.y;
|
|
3694
|
+
const bly = b.leftSE.point.y;
|
|
3695
|
+
const ary = a.rightSE.point.y;
|
|
3696
|
+
const bry = b.rightSE.point.y;
|
|
3697
|
+
// is left endpoint of segment B the right-more?
|
|
3698
|
+
if (alx.isLessThan(blx)) {
|
|
3699
|
+
// are the two segments in the same horizontal plane?
|
|
3700
|
+
if (bly.isLessThan(aly) && bly.isLessThan(ary))
|
|
3701
|
+
return 1;
|
|
3702
|
+
if (bly.isGreaterThan(aly) && bly.isGreaterThan(ary))
|
|
3703
|
+
return -1;
|
|
3704
|
+
// is the B left endpoint colinear to segment A?
|
|
3705
|
+
const aCmpBLeft = a.comparePoint(b.leftSE.point);
|
|
3706
|
+
if (aCmpBLeft < 0)
|
|
3707
|
+
return 1;
|
|
3708
|
+
if (aCmpBLeft > 0)
|
|
3709
|
+
return -1;
|
|
3710
|
+
// is the A right endpoint colinear to segment B ?
|
|
3711
|
+
const bCmpARight = b.comparePoint(a.rightSE.point);
|
|
3712
|
+
if (bCmpARight !== 0)
|
|
3713
|
+
return bCmpARight;
|
|
3714
|
+
// colinear segments, consider the one with left-more
|
|
3715
|
+
// left endpoint to be first (arbitrary?)
|
|
3716
|
+
return -1;
|
|
3717
|
+
}
|
|
3718
|
+
// is left endpoint of segment A the right-more?
|
|
3719
|
+
if (alx.isGreaterThan(blx)) {
|
|
3720
|
+
if (aly.isLessThan(bly) && aly.isLessThan(bry))
|
|
3721
|
+
return -1;
|
|
3722
|
+
if (aly.isGreaterThan(bly) && aly.isGreaterThan(bry))
|
|
3723
|
+
return 1;
|
|
3724
|
+
// is the A left endpoint colinear to segment B?
|
|
3725
|
+
const bCmpALeft = b.comparePoint(a.leftSE.point);
|
|
3726
|
+
if (bCmpALeft !== 0)
|
|
3727
|
+
return bCmpALeft;
|
|
3728
|
+
// is the B right endpoint colinear to segment A?
|
|
3729
|
+
const aCmpBRight = a.comparePoint(b.rightSE.point);
|
|
3730
|
+
if (aCmpBRight < 0)
|
|
3731
|
+
return 1;
|
|
3732
|
+
if (aCmpBRight > 0)
|
|
3733
|
+
return -1;
|
|
3734
|
+
// colinear segments, consider the one with left-more
|
|
3735
|
+
// left endpoint to be first (arbitrary?)
|
|
3736
|
+
return 1;
|
|
3737
|
+
}
|
|
3738
|
+
// if we get here, the two left endpoints are in the same
|
|
3739
|
+
// vertical plane, ie alx === blx
|
|
3740
|
+
// consider the lower left-endpoint to come first
|
|
3741
|
+
if (aly.isLessThan(bly))
|
|
3742
|
+
return -1;
|
|
3743
|
+
if (aly.isGreaterThan(bly))
|
|
3744
|
+
return 1;
|
|
3745
|
+
// left endpoints are identical
|
|
3746
|
+
// check for colinearity by using the left-more right endpoint
|
|
3747
|
+
// is the A right endpoint more left-more?
|
|
3748
|
+
if (arx.isLessThan(brx)) {
|
|
3749
|
+
const bCmpARight = b.comparePoint(a.rightSE.point);
|
|
3750
|
+
if (bCmpARight !== 0)
|
|
3751
|
+
return bCmpARight;
|
|
3752
|
+
}
|
|
3753
|
+
// is the B right endpoint more left-more?
|
|
3754
|
+
if (arx.isGreaterThan(brx)) {
|
|
3755
|
+
const aCmpBRight = a.comparePoint(b.rightSE.point);
|
|
3756
|
+
if (aCmpBRight < 0)
|
|
3757
|
+
return 1;
|
|
3758
|
+
if (aCmpBRight > 0)
|
|
3759
|
+
return -1;
|
|
3760
|
+
}
|
|
3761
|
+
if (!arx.eq(brx)) {
|
|
3762
|
+
// are these two [almost] vertical segments with opposite orientation?
|
|
3763
|
+
// if so, the one with the lower right endpoint comes first
|
|
3764
|
+
const ay = ary.minus(aly);
|
|
3765
|
+
const ax = arx.minus(alx);
|
|
3766
|
+
const by = bry.minus(bly);
|
|
3767
|
+
const bx = brx.minus(blx);
|
|
3768
|
+
if (ay.isGreaterThan(ax) && by.isLessThan(bx))
|
|
3769
|
+
return 1;
|
|
3770
|
+
if (ay.isLessThan(ax) && by.isGreaterThan(bx))
|
|
3771
|
+
return -1;
|
|
3772
|
+
}
|
|
3773
|
+
// we have colinear segments with matching orientation
|
|
3774
|
+
// consider the one with more left-more right endpoint to be first
|
|
3775
|
+
if (arx.isGreaterThan(brx))
|
|
3776
|
+
return 1;
|
|
3777
|
+
if (arx.isLessThan(brx))
|
|
3778
|
+
return -1;
|
|
3779
|
+
// if we get here, two two right endpoints are in the same
|
|
3780
|
+
// vertical plane, ie arx === brx
|
|
3781
|
+
// consider the lower right-endpoint to come first
|
|
3782
|
+
if (ary.isLessThan(bry))
|
|
3783
|
+
return -1;
|
|
3784
|
+
if (ary.isGreaterThan(bry))
|
|
3785
|
+
return 1;
|
|
3786
|
+
// right endpoints identical as well, so the segments are idential
|
|
3787
|
+
// fall back on creation order as consistent tie-breaker
|
|
3788
|
+
if (a.id < b.id)
|
|
3789
|
+
return -1;
|
|
3790
|
+
if (a.id > b.id)
|
|
3791
|
+
return 1;
|
|
3792
|
+
// identical segment, ie a === b
|
|
3793
|
+
return 0;
|
|
3794
|
+
}
|
|
3795
|
+
/* Warning: a reference to ringWindings input will be stored,
|
|
3796
|
+
* and possibly will be later modified */
|
|
3797
|
+
constructor(leftSE, rightSE, rings, windings) {
|
|
3798
|
+
this.id = ++segmentId;
|
|
3799
|
+
this.leftSE = leftSE;
|
|
3800
|
+
leftSE.segment = this;
|
|
3801
|
+
leftSE.otherSE = rightSE;
|
|
3802
|
+
this.rightSE = rightSE;
|
|
3803
|
+
rightSE.segment = this;
|
|
3804
|
+
rightSE.otherSE = leftSE;
|
|
3805
|
+
this.rings = rings;
|
|
3806
|
+
this.windings = windings;
|
|
3807
|
+
// left unset for performance, set later in algorithm
|
|
3808
|
+
// this.ringOut, this.consumedBy, this.prev
|
|
3809
|
+
}
|
|
3810
|
+
static fromRing(pt1, pt2, ring) {
|
|
3811
|
+
let leftPt, rightPt, winding;
|
|
3812
|
+
// ordering the two points according to sweep line ordering
|
|
3813
|
+
const cmpPts = SweepEvent.comparePoints(pt1, pt2);
|
|
3814
|
+
if (cmpPts < 0) {
|
|
3815
|
+
leftPt = pt1;
|
|
3816
|
+
rightPt = pt2;
|
|
3817
|
+
winding = 1;
|
|
3818
|
+
}
|
|
3819
|
+
else if (cmpPts > 0) {
|
|
3820
|
+
leftPt = pt2;
|
|
3821
|
+
rightPt = pt1;
|
|
3822
|
+
winding = -1;
|
|
3823
|
+
}
|
|
3824
|
+
else
|
|
3825
|
+
throw new Error(`Tried to create degenerate segment at [${pt1.x}, ${pt1.y}]`);
|
|
3826
|
+
const leftSE = new SweepEvent(leftPt, true);
|
|
3827
|
+
const rightSE = new SweepEvent(rightPt, false);
|
|
3828
|
+
return new Segment(leftSE, rightSE, [ring], [winding]);
|
|
3829
|
+
}
|
|
3830
|
+
/* When a segment is split, the rightSE is replaced with a new sweep event */
|
|
3831
|
+
replaceRightSE(newRightSE) {
|
|
3832
|
+
this.rightSE = newRightSE;
|
|
3833
|
+
this.rightSE.segment = this;
|
|
3834
|
+
this.rightSE.otherSE = this.leftSE;
|
|
3835
|
+
this.leftSE.otherSE = this.rightSE;
|
|
3836
|
+
}
|
|
3837
|
+
bbox() {
|
|
3838
|
+
const y1 = this.leftSE.point.y;
|
|
3839
|
+
const y2 = this.rightSE.point.y;
|
|
3840
|
+
return {
|
|
3841
|
+
ll: { x: this.leftSE.point.x, y: y1.isLessThan(y2) ? y1 : y2 },
|
|
3842
|
+
ur: { x: this.rightSE.point.x, y: y1.isGreaterThan(y2) ? y1 : y2 },
|
|
3843
|
+
};
|
|
3844
|
+
}
|
|
3845
|
+
/* A vector from the left point to the right */
|
|
3846
|
+
vector() {
|
|
3847
|
+
return {
|
|
3848
|
+
x: this.rightSE.point.x.minus(this.leftSE.point.x),
|
|
3849
|
+
y: this.rightSE.point.y.minus(this.leftSE.point.y),
|
|
3850
|
+
};
|
|
3851
|
+
}
|
|
3852
|
+
isAnEndpoint(pt) {
|
|
3853
|
+
return ((pt.x.eq(this.leftSE.point.x) && pt.y.eq(this.leftSE.point.y)) ||
|
|
3854
|
+
(pt.x.eq(this.rightSE.point.x) && pt.y.eq(this.rightSE.point.y)));
|
|
3855
|
+
}
|
|
3856
|
+
/* Compare this segment with a point.
|
|
3857
|
+
*
|
|
3858
|
+
* A point P is considered to be colinear to a segment if there
|
|
3859
|
+
* exists a distance D such that if we travel along the segment
|
|
3860
|
+
* from one * endpoint towards the other a distance D, we find
|
|
3861
|
+
* ourselves at point P.
|
|
3862
|
+
*
|
|
3863
|
+
* Return value indicates:
|
|
3864
|
+
*
|
|
3865
|
+
* 1: point lies above the segment (to the left of vertical)
|
|
3866
|
+
* 0: point is colinear to segment
|
|
3867
|
+
* -1: point lies below the segment (to the right of vertical)
|
|
3868
|
+
*/
|
|
3869
|
+
comparePoint(point) {
|
|
3870
|
+
return precision.orient(this.leftSE.point, point, this.rightSE.point);
|
|
3871
|
+
}
|
|
3872
|
+
/**
|
|
3873
|
+
* Given another segment, returns the first non-trivial intersection
|
|
3874
|
+
* between the two segments (in terms of sweep line ordering), if it exists.
|
|
3875
|
+
*
|
|
3876
|
+
* A 'non-trivial' intersection is one that will cause one or both of the
|
|
3877
|
+
* segments to be split(). As such, 'trivial' vs. 'non-trivial' intersection:
|
|
3878
|
+
*
|
|
3879
|
+
* * endpoint of segA with endpoint of segB --> trivial
|
|
3880
|
+
* * endpoint of segA with point along segB --> non-trivial
|
|
3881
|
+
* * endpoint of segB with point along segA --> non-trivial
|
|
3882
|
+
* * point along segA with point along segB --> non-trivial
|
|
3883
|
+
*
|
|
3884
|
+
* If no non-trivial intersection exists, return null
|
|
3885
|
+
* Else, return null.
|
|
3886
|
+
*/
|
|
3887
|
+
getIntersection(other) {
|
|
3888
|
+
// If bboxes don't overlap, there can't be any intersections
|
|
3889
|
+
const tBbox = this.bbox();
|
|
3890
|
+
const oBbox = other.bbox();
|
|
3891
|
+
const bboxOverlap = getBboxOverlap(tBbox, oBbox);
|
|
3892
|
+
if (bboxOverlap === null)
|
|
3893
|
+
return null;
|
|
3894
|
+
// We first check to see if the endpoints can be considered intersections.
|
|
3895
|
+
// This will 'snap' intersections to endpoints if possible, and will
|
|
3896
|
+
// handle cases of colinearity.
|
|
3897
|
+
const tlp = this.leftSE.point;
|
|
3898
|
+
const trp = this.rightSE.point;
|
|
3899
|
+
const olp = other.leftSE.point;
|
|
3900
|
+
const orp = other.rightSE.point;
|
|
3901
|
+
// does each endpoint touch the other segment?
|
|
3902
|
+
// note that we restrict the 'touching' definition to only allow segments
|
|
3903
|
+
// to touch endpoints that lie forward from where we are in the sweep line pass
|
|
3904
|
+
const touchesOtherLSE = isInBbox(tBbox, olp) && this.comparePoint(olp) === 0;
|
|
3905
|
+
const touchesThisLSE = isInBbox(oBbox, tlp) && other.comparePoint(tlp) === 0;
|
|
3906
|
+
const touchesOtherRSE = isInBbox(tBbox, orp) && this.comparePoint(orp) === 0;
|
|
3907
|
+
const touchesThisRSE = isInBbox(oBbox, trp) && other.comparePoint(trp) === 0;
|
|
3908
|
+
// do left endpoints match?
|
|
3909
|
+
if (touchesThisLSE && touchesOtherLSE) {
|
|
3910
|
+
// these two cases are for colinear segments with matching left
|
|
3911
|
+
// endpoints, and one segment being longer than the other
|
|
3912
|
+
if (touchesThisRSE && !touchesOtherRSE)
|
|
3913
|
+
return trp;
|
|
3914
|
+
if (!touchesThisRSE && touchesOtherRSE)
|
|
3915
|
+
return orp;
|
|
3916
|
+
// either the two segments match exactly (two trival intersections)
|
|
3917
|
+
// or just on their left endpoint (one trivial intersection
|
|
3918
|
+
return null;
|
|
3919
|
+
}
|
|
3920
|
+
// does this left endpoint matches (other doesn't)
|
|
3921
|
+
if (touchesThisLSE) {
|
|
3922
|
+
// check for segments that just intersect on opposing endpoints
|
|
3923
|
+
if (touchesOtherRSE) {
|
|
3924
|
+
if (tlp.x.eq(orp.x) && tlp.y.eq(orp.y))
|
|
3925
|
+
return null;
|
|
3926
|
+
}
|
|
3927
|
+
// t-intersection on left endpoint
|
|
3928
|
+
return tlp;
|
|
3929
|
+
}
|
|
3930
|
+
// does other left endpoint matches (this doesn't)
|
|
3931
|
+
if (touchesOtherLSE) {
|
|
3932
|
+
// check for segments that just intersect on opposing endpoints
|
|
3933
|
+
if (touchesThisRSE) {
|
|
3934
|
+
if (trp.x.eq(olp.x) && trp.y.eq(olp.y))
|
|
3935
|
+
return null;
|
|
3936
|
+
}
|
|
3937
|
+
// t-intersection on left endpoint
|
|
3938
|
+
return olp;
|
|
3939
|
+
}
|
|
3940
|
+
// trivial intersection on right endpoints
|
|
3941
|
+
if (touchesThisRSE && touchesOtherRSE)
|
|
3942
|
+
return null;
|
|
3943
|
+
// t-intersections on just one right endpoint
|
|
3944
|
+
if (touchesThisRSE)
|
|
3945
|
+
return trp;
|
|
3946
|
+
if (touchesOtherRSE)
|
|
3947
|
+
return orp;
|
|
3948
|
+
// None of our endpoints intersect. Look for a general intersection between
|
|
3949
|
+
// infinite lines laid over the segments
|
|
3950
|
+
const pt = intersection$1(tlp, this.vector(), olp, other.vector());
|
|
3951
|
+
// are the segments parrallel? Note that if they were colinear with overlap,
|
|
3952
|
+
// they would have an endpoint intersection and that case was already handled above
|
|
3953
|
+
if (pt === null)
|
|
3954
|
+
return null;
|
|
3955
|
+
// is the intersection found between the lines not on the segments?
|
|
3956
|
+
if (!isInBbox(bboxOverlap, pt))
|
|
3957
|
+
return null;
|
|
3958
|
+
// round the the computed point if needed
|
|
3959
|
+
return precision.snap(pt);
|
|
3960
|
+
}
|
|
3961
|
+
/**
|
|
3962
|
+
* Split the given segment into multiple segments on the given points.
|
|
3963
|
+
* * Each existing segment will retain its leftSE and a new rightSE will be
|
|
3964
|
+
* generated for it.
|
|
3965
|
+
* * A new segment will be generated which will adopt the original segment's
|
|
3966
|
+
* rightSE, and a new leftSE will be generated for it.
|
|
3967
|
+
* * If there are more than two points given to split on, new segments
|
|
3968
|
+
* in the middle will be generated with new leftSE and rightSE's.
|
|
3969
|
+
* * An array of the newly generated SweepEvents will be returned.
|
|
3970
|
+
*
|
|
3971
|
+
* Warning: input array of points is modified
|
|
3972
|
+
*/
|
|
3973
|
+
split(point) {
|
|
3974
|
+
const newEvents = [];
|
|
3975
|
+
const alreadyLinked = point.events !== undefined;
|
|
3976
|
+
const newLeftSE = new SweepEvent(point, true);
|
|
3977
|
+
const newRightSE = new SweepEvent(point, false);
|
|
3978
|
+
const oldRightSE = this.rightSE;
|
|
3979
|
+
this.replaceRightSE(newRightSE);
|
|
3980
|
+
newEvents.push(newRightSE);
|
|
3981
|
+
newEvents.push(newLeftSE);
|
|
3982
|
+
const newSeg = new Segment(newLeftSE, oldRightSE, this.rings.slice(), this.windings.slice());
|
|
3983
|
+
// when splitting a nearly vertical downward-facing segment,
|
|
3984
|
+
// sometimes one of the resulting new segments is vertical, in which
|
|
3985
|
+
// case its left and right events may need to be swapped
|
|
3986
|
+
if (SweepEvent.comparePoints(newSeg.leftSE.point, newSeg.rightSE.point) > 0) {
|
|
3987
|
+
newSeg.swapEvents();
|
|
3988
|
+
}
|
|
3989
|
+
if (SweepEvent.comparePoints(this.leftSE.point, this.rightSE.point) > 0) {
|
|
3990
|
+
this.swapEvents();
|
|
3991
|
+
}
|
|
3992
|
+
// in the point we just used to create new sweep events with was already
|
|
3993
|
+
// linked to other events, we need to check if either of the affected
|
|
3994
|
+
// segments should be consumed
|
|
3995
|
+
if (alreadyLinked) {
|
|
3996
|
+
newLeftSE.checkForConsuming();
|
|
3997
|
+
newRightSE.checkForConsuming();
|
|
3998
|
+
}
|
|
3999
|
+
return newEvents;
|
|
4000
|
+
}
|
|
4001
|
+
/* Swap which event is left and right */
|
|
4002
|
+
swapEvents() {
|
|
4003
|
+
const tmpEvt = this.rightSE;
|
|
4004
|
+
this.rightSE = this.leftSE;
|
|
4005
|
+
this.leftSE = tmpEvt;
|
|
4006
|
+
this.leftSE.isLeft = true;
|
|
4007
|
+
this.rightSE.isLeft = false;
|
|
4008
|
+
for (let i = 0, iMax = this.windings.length; i < iMax; i++) {
|
|
4009
|
+
this.windings[i] *= -1;
|
|
4010
|
+
}
|
|
4011
|
+
}
|
|
4012
|
+
/* Consume another segment. We take their rings under our wing
|
|
4013
|
+
* and mark them as consumed. Use for perfectly overlapping segments */
|
|
4014
|
+
consume(other) {
|
|
4015
|
+
let consumer = this;
|
|
4016
|
+
let consumee = other;
|
|
4017
|
+
while (consumer.consumedBy)
|
|
4018
|
+
consumer = consumer.consumedBy;
|
|
4019
|
+
while (consumee.consumedBy)
|
|
4020
|
+
consumee = consumee.consumedBy;
|
|
4021
|
+
const cmp = Segment.compare(consumer, consumee);
|
|
4022
|
+
if (cmp === 0)
|
|
4023
|
+
return; // already consumed
|
|
4024
|
+
// the winner of the consumption is the earlier segment
|
|
4025
|
+
// according to sweep line ordering
|
|
4026
|
+
if (cmp > 0) {
|
|
4027
|
+
const tmp = consumer;
|
|
4028
|
+
consumer = consumee;
|
|
4029
|
+
consumee = tmp;
|
|
4030
|
+
}
|
|
4031
|
+
// make sure a segment doesn't consume it's prev
|
|
4032
|
+
if (consumer.prev === consumee) {
|
|
4033
|
+
const tmp = consumer;
|
|
4034
|
+
consumer = consumee;
|
|
4035
|
+
consumee = tmp;
|
|
4036
|
+
}
|
|
4037
|
+
for (let i = 0, iMax = consumee.rings.length; i < iMax; i++) {
|
|
4038
|
+
const ring = consumee.rings[i];
|
|
4039
|
+
const winding = consumee.windings[i];
|
|
4040
|
+
const index = consumer.rings.indexOf(ring);
|
|
4041
|
+
if (index === -1) {
|
|
4042
|
+
consumer.rings.push(ring);
|
|
4043
|
+
consumer.windings.push(winding);
|
|
4044
|
+
}
|
|
4045
|
+
else
|
|
4046
|
+
consumer.windings[index] += winding;
|
|
4047
|
+
}
|
|
4048
|
+
consumee.rings = null;
|
|
4049
|
+
consumee.windings = null;
|
|
4050
|
+
consumee.consumedBy = consumer;
|
|
4051
|
+
// mark sweep events consumed as to maintain ordering in sweep event queue
|
|
4052
|
+
consumee.leftSE.consumedBy = consumer.leftSE;
|
|
4053
|
+
consumee.rightSE.consumedBy = consumer.rightSE;
|
|
4054
|
+
}
|
|
4055
|
+
/* The first segment previous segment chain that is in the result */
|
|
4056
|
+
prevInResult() {
|
|
4057
|
+
if (this._prevInResult !== undefined)
|
|
4058
|
+
return this._prevInResult;
|
|
4059
|
+
if (!this.prev)
|
|
4060
|
+
this._prevInResult = null;
|
|
4061
|
+
else if (this.prev.isInResult())
|
|
4062
|
+
this._prevInResult = this.prev;
|
|
4063
|
+
else
|
|
4064
|
+
this._prevInResult = this.prev.prevInResult();
|
|
4065
|
+
return this._prevInResult;
|
|
4066
|
+
}
|
|
4067
|
+
beforeState() {
|
|
4068
|
+
if (this._beforeState !== undefined)
|
|
4069
|
+
return this._beforeState;
|
|
4070
|
+
if (!this.prev)
|
|
4071
|
+
this._beforeState = {
|
|
4072
|
+
rings: [],
|
|
4073
|
+
windings: [],
|
|
4074
|
+
multiPolys: [],
|
|
4075
|
+
};
|
|
4076
|
+
else {
|
|
4077
|
+
const seg = this.prev.consumedBy || this.prev;
|
|
4078
|
+
this._beforeState = seg.afterState();
|
|
4079
|
+
}
|
|
4080
|
+
return this._beforeState;
|
|
4081
|
+
}
|
|
4082
|
+
afterState() {
|
|
4083
|
+
if (this._afterState !== undefined)
|
|
4084
|
+
return this._afterState;
|
|
4085
|
+
const beforeState = this.beforeState();
|
|
4086
|
+
this._afterState = {
|
|
4087
|
+
rings: beforeState.rings.slice(0),
|
|
4088
|
+
windings: beforeState.windings.slice(0),
|
|
4089
|
+
multiPolys: [],
|
|
4090
|
+
};
|
|
4091
|
+
const ringsAfter = this._afterState.rings;
|
|
4092
|
+
const windingsAfter = this._afterState.windings;
|
|
4093
|
+
const mpsAfter = this._afterState.multiPolys;
|
|
4094
|
+
// calculate ringsAfter, windingsAfter
|
|
4095
|
+
for (let i = 0, iMax = this.rings.length; i < iMax; i++) {
|
|
4096
|
+
const ring = this.rings[i];
|
|
4097
|
+
const winding = this.windings[i];
|
|
4098
|
+
const index = ringsAfter.indexOf(ring);
|
|
4099
|
+
if (index === -1) {
|
|
4100
|
+
ringsAfter.push(ring);
|
|
4101
|
+
windingsAfter.push(winding);
|
|
4102
|
+
}
|
|
4103
|
+
else
|
|
4104
|
+
windingsAfter[index] += winding;
|
|
4105
|
+
}
|
|
4106
|
+
// calcualte polysAfter
|
|
4107
|
+
const polysAfter = [];
|
|
4108
|
+
const polysExclude = [];
|
|
4109
|
+
for (let i = 0, iMax = ringsAfter.length; i < iMax; i++) {
|
|
4110
|
+
if (windingsAfter[i] === 0)
|
|
4111
|
+
continue; // non-zero rule
|
|
4112
|
+
const ring = ringsAfter[i];
|
|
4113
|
+
const poly = ring.poly;
|
|
4114
|
+
if (polysExclude.indexOf(poly) !== -1)
|
|
4115
|
+
continue;
|
|
4116
|
+
if (ring.isExterior)
|
|
4117
|
+
polysAfter.push(poly);
|
|
4118
|
+
else {
|
|
4119
|
+
if (polysExclude.indexOf(poly) === -1)
|
|
4120
|
+
polysExclude.push(poly);
|
|
4121
|
+
const index = polysAfter.indexOf(ring.poly);
|
|
4122
|
+
if (index !== -1)
|
|
4123
|
+
polysAfter.splice(index, 1);
|
|
4124
|
+
}
|
|
4125
|
+
}
|
|
4126
|
+
// calculate multiPolysAfter
|
|
4127
|
+
for (let i = 0, iMax = polysAfter.length; i < iMax; i++) {
|
|
4128
|
+
const mp = polysAfter[i].multiPoly;
|
|
4129
|
+
if (mpsAfter.indexOf(mp) === -1)
|
|
4130
|
+
mpsAfter.push(mp);
|
|
4131
|
+
}
|
|
4132
|
+
return this._afterState;
|
|
4133
|
+
}
|
|
4134
|
+
/* Is this segment part of the final result? */
|
|
4135
|
+
isInResult() {
|
|
4136
|
+
// if we've been consumed, we're not in the result
|
|
4137
|
+
if (this.consumedBy)
|
|
4138
|
+
return false;
|
|
4139
|
+
if (this._isInResult !== undefined)
|
|
4140
|
+
return this._isInResult;
|
|
4141
|
+
const mpsBefore = this.beforeState().multiPolys;
|
|
4142
|
+
const mpsAfter = this.afterState().multiPolys;
|
|
4143
|
+
switch (operation.type) {
|
|
4144
|
+
case "union": {
|
|
4145
|
+
// UNION - included iff:
|
|
4146
|
+
// * On one side of us there is 0 poly interiors AND
|
|
4147
|
+
// * On the other side there is 1 or more.
|
|
4148
|
+
const noBefores = mpsBefore.length === 0;
|
|
4149
|
+
const noAfters = mpsAfter.length === 0;
|
|
4150
|
+
this._isInResult = noBefores !== noAfters;
|
|
4151
|
+
break;
|
|
4152
|
+
}
|
|
4153
|
+
case "intersection": {
|
|
4154
|
+
// INTERSECTION - included iff:
|
|
4155
|
+
// * on one side of us all multipolys are rep. with poly interiors AND
|
|
4156
|
+
// * on the other side of us, not all multipolys are repsented
|
|
4157
|
+
// with poly interiors
|
|
4158
|
+
let least;
|
|
4159
|
+
let most;
|
|
4160
|
+
if (mpsBefore.length < mpsAfter.length) {
|
|
4161
|
+
least = mpsBefore.length;
|
|
4162
|
+
most = mpsAfter.length;
|
|
4163
|
+
}
|
|
4164
|
+
else {
|
|
4165
|
+
least = mpsAfter.length;
|
|
4166
|
+
most = mpsBefore.length;
|
|
4167
|
+
}
|
|
4168
|
+
this._isInResult = most === operation.numMultiPolys && least < most;
|
|
4169
|
+
break;
|
|
4170
|
+
}
|
|
4171
|
+
case "xor": {
|
|
4172
|
+
// XOR - included iff:
|
|
4173
|
+
// * the difference between the number of multipolys represented
|
|
4174
|
+
// with poly interiors on our two sides is an odd number
|
|
4175
|
+
const diff = Math.abs(mpsBefore.length - mpsAfter.length);
|
|
4176
|
+
this._isInResult = diff % 2 === 1;
|
|
4177
|
+
break;
|
|
4178
|
+
}
|
|
4179
|
+
case "difference": {
|
|
4180
|
+
// DIFFERENCE included iff:
|
|
4181
|
+
// * on exactly one side, we have just the subject
|
|
4182
|
+
const isJustSubject = (mps) => mps.length === 1 && mps[0].isSubject;
|
|
4183
|
+
this._isInResult = isJustSubject(mpsBefore) !== isJustSubject(mpsAfter);
|
|
4184
|
+
break;
|
|
4185
|
+
}
|
|
4186
|
+
}
|
|
4187
|
+
return this._isInResult;
|
|
4188
|
+
}
|
|
4189
|
+
}
|
|
4190
|
+
|
|
4191
|
+
class RingIn {
|
|
4192
|
+
poly;
|
|
4193
|
+
isExterior;
|
|
4194
|
+
segments;
|
|
4195
|
+
bbox;
|
|
4196
|
+
constructor(geomRing, poly, isExterior) {
|
|
4197
|
+
if (!Array.isArray(geomRing) || geomRing.length === 0) {
|
|
4198
|
+
throw new Error("Input geometry is not a valid Polygon or MultiPolygon");
|
|
4199
|
+
}
|
|
4200
|
+
this.poly = poly;
|
|
4201
|
+
this.isExterior = isExterior;
|
|
4202
|
+
this.segments = [];
|
|
4203
|
+
if (typeof geomRing[0][0] !== "number" ||
|
|
4204
|
+
typeof geomRing[0][1] !== "number") {
|
|
4205
|
+
throw new Error("Input geometry is not a valid Polygon or MultiPolygon");
|
|
4206
|
+
}
|
|
4207
|
+
const firstPoint = precision.snap({ x: new BigNumber(geomRing[0][0]), y: new BigNumber(geomRing[0][1]) });
|
|
4208
|
+
this.bbox = {
|
|
4209
|
+
ll: { x: firstPoint.x, y: firstPoint.y },
|
|
4210
|
+
ur: { x: firstPoint.x, y: firstPoint.y },
|
|
4211
|
+
};
|
|
4212
|
+
let prevPoint = firstPoint;
|
|
4213
|
+
for (let i = 1, iMax = geomRing.length; i < iMax; i++) {
|
|
4214
|
+
if (typeof geomRing[i][0] !== "number" ||
|
|
4215
|
+
typeof geomRing[i][1] !== "number") {
|
|
4216
|
+
throw new Error("Input geometry is not a valid Polygon or MultiPolygon");
|
|
4217
|
+
}
|
|
4218
|
+
const point = precision.snap({ x: new BigNumber(geomRing[i][0]), y: new BigNumber(geomRing[i][1]) });
|
|
4219
|
+
// skip repeated points
|
|
4220
|
+
if (point.x.eq(prevPoint.x) && point.y.eq(prevPoint.y))
|
|
4221
|
+
continue;
|
|
4222
|
+
this.segments.push(Segment.fromRing(prevPoint, point, this));
|
|
4223
|
+
if (point.x.isLessThan(this.bbox.ll.x))
|
|
4224
|
+
this.bbox.ll.x = point.x;
|
|
4225
|
+
if (point.y.isLessThan(this.bbox.ll.y))
|
|
4226
|
+
this.bbox.ll.y = point.y;
|
|
4227
|
+
if (point.x.isGreaterThan(this.bbox.ur.x))
|
|
4228
|
+
this.bbox.ur.x = point.x;
|
|
4229
|
+
if (point.y.isGreaterThan(this.bbox.ur.y))
|
|
4230
|
+
this.bbox.ur.y = point.y;
|
|
4231
|
+
prevPoint = point;
|
|
4232
|
+
}
|
|
4233
|
+
// add segment from last to first if last is not the same as first
|
|
4234
|
+
if (!firstPoint.x.eq(prevPoint.x) || !firstPoint.y.eq(prevPoint.y)) {
|
|
4235
|
+
this.segments.push(Segment.fromRing(prevPoint, firstPoint, this));
|
|
4236
|
+
}
|
|
4237
|
+
}
|
|
4238
|
+
getSweepEvents() {
|
|
4239
|
+
const sweepEvents = [];
|
|
4240
|
+
for (let i = 0, iMax = this.segments.length; i < iMax; i++) {
|
|
4241
|
+
const segment = this.segments[i];
|
|
4242
|
+
sweepEvents.push(segment.leftSE);
|
|
4243
|
+
sweepEvents.push(segment.rightSE);
|
|
4244
|
+
}
|
|
4245
|
+
return sweepEvents;
|
|
4246
|
+
}
|
|
4247
|
+
}
|
|
4248
|
+
class PolyIn {
|
|
4249
|
+
multiPoly;
|
|
4250
|
+
exteriorRing;
|
|
4251
|
+
interiorRings;
|
|
4252
|
+
bbox;
|
|
4253
|
+
constructor(geomPoly, multiPoly) {
|
|
4254
|
+
if (!Array.isArray(geomPoly)) {
|
|
4255
|
+
throw new Error("Input geometry is not a valid Polygon or MultiPolygon");
|
|
4256
|
+
}
|
|
4257
|
+
this.exteriorRing = new RingIn(geomPoly[0], this, true);
|
|
4258
|
+
// copy by value
|
|
4259
|
+
this.bbox = {
|
|
4260
|
+
ll: { x: this.exteriorRing.bbox.ll.x, y: this.exteriorRing.bbox.ll.y },
|
|
4261
|
+
ur: { x: this.exteriorRing.bbox.ur.x, y: this.exteriorRing.bbox.ur.y },
|
|
4262
|
+
};
|
|
4263
|
+
this.interiorRings = [];
|
|
4264
|
+
for (let i = 1, iMax = geomPoly.length; i < iMax; i++) {
|
|
4265
|
+
const ring = new RingIn(geomPoly[i], this, false);
|
|
4266
|
+
if (ring.bbox.ll.x.isLessThan(this.bbox.ll.x))
|
|
4267
|
+
this.bbox.ll.x = ring.bbox.ll.x;
|
|
4268
|
+
if (ring.bbox.ll.y.isLessThan(this.bbox.ll.y))
|
|
4269
|
+
this.bbox.ll.y = ring.bbox.ll.y;
|
|
4270
|
+
if (ring.bbox.ur.x.isGreaterThan(this.bbox.ur.x))
|
|
4271
|
+
this.bbox.ur.x = ring.bbox.ur.x;
|
|
4272
|
+
if (ring.bbox.ur.y.isGreaterThan(this.bbox.ur.y))
|
|
4273
|
+
this.bbox.ur.y = ring.bbox.ur.y;
|
|
4274
|
+
this.interiorRings.push(ring);
|
|
4275
|
+
}
|
|
4276
|
+
this.multiPoly = multiPoly;
|
|
4277
|
+
}
|
|
4278
|
+
getSweepEvents() {
|
|
4279
|
+
const sweepEvents = this.exteriorRing.getSweepEvents();
|
|
4280
|
+
for (let i = 0, iMax = this.interiorRings.length; i < iMax; i++) {
|
|
4281
|
+
const ringSweepEvents = this.interiorRings[i].getSweepEvents();
|
|
4282
|
+
for (let j = 0, jMax = ringSweepEvents.length; j < jMax; j++) {
|
|
4283
|
+
sweepEvents.push(ringSweepEvents[j]);
|
|
4284
|
+
}
|
|
4285
|
+
}
|
|
4286
|
+
return sweepEvents;
|
|
4287
|
+
}
|
|
4288
|
+
}
|
|
4289
|
+
class MultiPolyIn {
|
|
4290
|
+
isSubject;
|
|
4291
|
+
polys;
|
|
4292
|
+
bbox;
|
|
4293
|
+
constructor(geom, isSubject) {
|
|
4294
|
+
if (!Array.isArray(geom)) {
|
|
4295
|
+
throw new Error("Input geometry is not a valid Polygon or MultiPolygon");
|
|
4296
|
+
}
|
|
4297
|
+
try {
|
|
4298
|
+
// if the input looks like a polygon, convert it to a multipolygon
|
|
4299
|
+
if (typeof geom[0][0][0] === "number")
|
|
4300
|
+
geom = [geom];
|
|
4301
|
+
}
|
|
4302
|
+
catch (ex) {
|
|
4303
|
+
// The input is either malformed or has empty arrays.
|
|
4304
|
+
// In either case, it will be handled later on.
|
|
4305
|
+
}
|
|
4306
|
+
this.polys = [];
|
|
4307
|
+
this.bbox = {
|
|
4308
|
+
ll: { x: new BigNumber(Number.POSITIVE_INFINITY), y: new BigNumber(Number.POSITIVE_INFINITY) },
|
|
4309
|
+
ur: { x: new BigNumber(Number.NEGATIVE_INFINITY), y: new BigNumber(Number.NEGATIVE_INFINITY) },
|
|
4310
|
+
};
|
|
4311
|
+
for (let i = 0, iMax = geom.length; i < iMax; i++) {
|
|
4312
|
+
const poly = new PolyIn(geom[i], this);
|
|
4313
|
+
if (poly.bbox.ll.x.isLessThan(this.bbox.ll.x))
|
|
4314
|
+
this.bbox.ll.x = poly.bbox.ll.x;
|
|
4315
|
+
if (poly.bbox.ll.y.isLessThan(this.bbox.ll.y))
|
|
4316
|
+
this.bbox.ll.y = poly.bbox.ll.y;
|
|
4317
|
+
if (poly.bbox.ur.x.isGreaterThan(this.bbox.ur.x))
|
|
4318
|
+
this.bbox.ur.x = poly.bbox.ur.x;
|
|
4319
|
+
if (poly.bbox.ur.y.isGreaterThan(this.bbox.ur.y))
|
|
4320
|
+
this.bbox.ur.y = poly.bbox.ur.y;
|
|
4321
|
+
this.polys.push(poly);
|
|
4322
|
+
}
|
|
4323
|
+
this.isSubject = isSubject;
|
|
4324
|
+
}
|
|
4325
|
+
getSweepEvents() {
|
|
4326
|
+
const sweepEvents = [];
|
|
4327
|
+
for (let i = 0, iMax = this.polys.length; i < iMax; i++) {
|
|
4328
|
+
const polySweepEvents = this.polys[i].getSweepEvents();
|
|
4329
|
+
for (let j = 0, jMax = polySweepEvents.length; j < jMax; j++) {
|
|
4330
|
+
sweepEvents.push(polySweepEvents[j]);
|
|
4331
|
+
}
|
|
4332
|
+
}
|
|
4333
|
+
return sweepEvents;
|
|
4334
|
+
}
|
|
4335
|
+
}
|
|
4336
|
+
|
|
4337
|
+
class RingOut {
|
|
4338
|
+
events;
|
|
4339
|
+
poly;
|
|
4340
|
+
_isExteriorRing;
|
|
4341
|
+
_enclosingRing;
|
|
4342
|
+
/* Given the segments from the sweep line pass, compute & return a series
|
|
4343
|
+
* of closed rings from all the segments marked to be part of the result */
|
|
4344
|
+
static factory(allSegments) {
|
|
4345
|
+
const ringsOut = [];
|
|
4346
|
+
for (let i = 0, iMax = allSegments.length; i < iMax; i++) {
|
|
4347
|
+
const segment = allSegments[i];
|
|
4348
|
+
if (!segment.isInResult() || segment.ringOut)
|
|
4349
|
+
continue;
|
|
4350
|
+
let prevEvent = null;
|
|
4351
|
+
let event = segment.leftSE;
|
|
4352
|
+
let nextEvent = segment.rightSE;
|
|
4353
|
+
const events = [event];
|
|
4354
|
+
const startingPoint = event.point;
|
|
4355
|
+
const intersectionLEs = [];
|
|
4356
|
+
/* Walk the chain of linked events to form a closed ring */
|
|
4357
|
+
while (true) {
|
|
4358
|
+
prevEvent = event;
|
|
4359
|
+
event = nextEvent;
|
|
4360
|
+
events.push(event);
|
|
4361
|
+
/* Is the ring complete? */
|
|
4362
|
+
if (event.point === startingPoint)
|
|
4363
|
+
break;
|
|
4364
|
+
while (true) {
|
|
4365
|
+
const availableLEs = event.getAvailableLinkedEvents();
|
|
4366
|
+
/* Did we hit a dead end? This shouldn't happen. Indicates some earlier
|
|
4367
|
+
* part of the algorithm malfunctioned... please file a bug report. */
|
|
4368
|
+
if (availableLEs.length === 0) {
|
|
4369
|
+
const firstPt = events[0].point;
|
|
4370
|
+
const lastPt = events[events.length - 1].point;
|
|
4371
|
+
throw new Error(`Unable to complete output ring starting at [${firstPt.x},` +
|
|
4372
|
+
` ${firstPt.y}]. Last matching segment found ends at` +
|
|
4373
|
+
` [${lastPt.x}, ${lastPt.y}].`);
|
|
4374
|
+
}
|
|
4375
|
+
/* Only one way to go, so cotinue on the path */
|
|
4376
|
+
if (availableLEs.length === 1) {
|
|
4377
|
+
nextEvent = availableLEs[0].otherSE;
|
|
4378
|
+
break;
|
|
4379
|
+
}
|
|
4380
|
+
/* We must have an intersection. Check for a completed loop */
|
|
4381
|
+
let indexLE = null;
|
|
4382
|
+
for (let j = 0, jMax = intersectionLEs.length; j < jMax; j++) {
|
|
4383
|
+
if (intersectionLEs[j].point === event.point) {
|
|
4384
|
+
indexLE = j;
|
|
4385
|
+
break;
|
|
4386
|
+
}
|
|
4387
|
+
}
|
|
4388
|
+
/* Found a completed loop. Cut that off and make a ring */
|
|
4389
|
+
if (indexLE !== null) {
|
|
4390
|
+
const intersectionLE = intersectionLEs.splice(indexLE)[0];
|
|
4391
|
+
const ringEvents = events.splice(intersectionLE.index);
|
|
4392
|
+
ringEvents.unshift(ringEvents[0].otherSE);
|
|
4393
|
+
ringsOut.push(new RingOut(ringEvents.reverse()));
|
|
4394
|
+
continue;
|
|
4395
|
+
}
|
|
4396
|
+
/* register the intersection */
|
|
4397
|
+
intersectionLEs.push({
|
|
4398
|
+
index: events.length,
|
|
4399
|
+
point: event.point,
|
|
4400
|
+
});
|
|
4401
|
+
/* Choose the left-most option to continue the walk */
|
|
4402
|
+
const comparator = event.getLeftmostComparator(prevEvent);
|
|
4403
|
+
nextEvent = availableLEs.sort(comparator)[0].otherSE;
|
|
4404
|
+
break;
|
|
4405
|
+
}
|
|
4406
|
+
}
|
|
4407
|
+
ringsOut.push(new RingOut(events));
|
|
4408
|
+
}
|
|
4409
|
+
return ringsOut;
|
|
4410
|
+
}
|
|
4411
|
+
constructor(events) {
|
|
4412
|
+
this.events = events;
|
|
4413
|
+
for (let i = 0, iMax = events.length; i < iMax; i++) {
|
|
4414
|
+
events[i].segment.ringOut = this;
|
|
4415
|
+
}
|
|
4416
|
+
this.poly = null;
|
|
4417
|
+
}
|
|
4418
|
+
getGeom() {
|
|
4419
|
+
// Remove superfluous points (ie extra points along a straight line),
|
|
4420
|
+
let prevPt = this.events[0].point;
|
|
4421
|
+
const points = [prevPt];
|
|
4422
|
+
for (let i = 1, iMax = this.events.length - 1; i < iMax; i++) {
|
|
4423
|
+
const pt = this.events[i].point;
|
|
4424
|
+
const nextPt = this.events[i + 1].point;
|
|
4425
|
+
if (precision.orient(pt, prevPt, nextPt) === 0)
|
|
4426
|
+
continue;
|
|
4427
|
+
points.push(pt);
|
|
4428
|
+
prevPt = pt;
|
|
4429
|
+
}
|
|
4430
|
+
// ring was all (within rounding error of angle calc) colinear points
|
|
4431
|
+
if (points.length === 1)
|
|
4432
|
+
return null;
|
|
4433
|
+
// check if the starting point is necessary
|
|
4434
|
+
const pt = points[0];
|
|
4435
|
+
const nextPt = points[1];
|
|
4436
|
+
if (precision.orient(pt, prevPt, nextPt) === 0)
|
|
4437
|
+
points.shift();
|
|
4438
|
+
points.push(points[0]);
|
|
4439
|
+
const step = this.isExteriorRing() ? 1 : -1;
|
|
4440
|
+
const iStart = this.isExteriorRing() ? 0 : points.length - 1;
|
|
4441
|
+
const iEnd = this.isExteriorRing() ? points.length : -1;
|
|
4442
|
+
const orderedPoints = [];
|
|
4443
|
+
for (let i = iStart; i != iEnd; i += step)
|
|
4444
|
+
orderedPoints.push([points[i].x.toNumber(), points[i].y.toNumber()]);
|
|
4445
|
+
return orderedPoints;
|
|
4446
|
+
}
|
|
4447
|
+
isExteriorRing() {
|
|
4448
|
+
if (this._isExteriorRing === undefined) {
|
|
4449
|
+
const enclosing = this.enclosingRing();
|
|
4450
|
+
this._isExteriorRing = enclosing ? !enclosing.isExteriorRing() : true;
|
|
4451
|
+
}
|
|
4452
|
+
return this._isExteriorRing;
|
|
4453
|
+
}
|
|
4454
|
+
enclosingRing() {
|
|
4455
|
+
if (this._enclosingRing === undefined) {
|
|
4456
|
+
this._enclosingRing = this._calcEnclosingRing();
|
|
4457
|
+
}
|
|
4458
|
+
return this._enclosingRing;
|
|
4459
|
+
}
|
|
4460
|
+
/* Returns the ring that encloses this one, if any */
|
|
4461
|
+
_calcEnclosingRing() {
|
|
4462
|
+
// start with the ealier sweep line event so that the prevSeg
|
|
4463
|
+
// chain doesn't lead us inside of a loop of ours
|
|
4464
|
+
let leftMostEvt = this.events[0];
|
|
4465
|
+
for (let i = 1, iMax = this.events.length; i < iMax; i++) {
|
|
4466
|
+
const evt = this.events[i];
|
|
4467
|
+
if (SweepEvent.compare(leftMostEvt, evt) > 0)
|
|
4468
|
+
leftMostEvt = evt;
|
|
4469
|
+
}
|
|
4470
|
+
let prevSeg = leftMostEvt.segment.prevInResult();
|
|
4471
|
+
let prevPrevSeg = prevSeg ? prevSeg.prevInResult() : null;
|
|
4472
|
+
while (true) {
|
|
4473
|
+
// no segment found, thus no ring can enclose us
|
|
4474
|
+
if (!prevSeg)
|
|
4475
|
+
return null;
|
|
4476
|
+
// no segments below prev segment found, thus the ring of the prev
|
|
4477
|
+
// segment must loop back around and enclose us
|
|
4478
|
+
if (!prevPrevSeg)
|
|
4479
|
+
return prevSeg.ringOut;
|
|
4480
|
+
// if the two segments are of different rings, the ring of the prev
|
|
4481
|
+
// segment must either loop around us or the ring of the prev prev
|
|
4482
|
+
// seg, which would make us and the ring of the prev peers
|
|
4483
|
+
if (prevPrevSeg.ringOut !== prevSeg.ringOut) {
|
|
4484
|
+
if (prevPrevSeg.ringOut?.enclosingRing() !== prevSeg.ringOut) {
|
|
4485
|
+
return prevSeg.ringOut;
|
|
4486
|
+
}
|
|
4487
|
+
else
|
|
4488
|
+
return prevSeg.ringOut?.enclosingRing();
|
|
4489
|
+
}
|
|
4490
|
+
// two segments are from the same ring, so this was a penisula
|
|
4491
|
+
// of that ring. iterate downward, keep searching
|
|
4492
|
+
prevSeg = prevPrevSeg.prevInResult();
|
|
4493
|
+
prevPrevSeg = prevSeg ? prevSeg.prevInResult() : null;
|
|
4494
|
+
}
|
|
4495
|
+
}
|
|
4496
|
+
}
|
|
4497
|
+
class PolyOut {
|
|
4498
|
+
exteriorRing;
|
|
4499
|
+
interiorRings;
|
|
4500
|
+
constructor(exteriorRing) {
|
|
4501
|
+
this.exteriorRing = exteriorRing;
|
|
4502
|
+
exteriorRing.poly = this;
|
|
4503
|
+
this.interiorRings = [];
|
|
4504
|
+
}
|
|
4505
|
+
addInterior(ring) {
|
|
4506
|
+
this.interiorRings.push(ring);
|
|
4507
|
+
ring.poly = this;
|
|
4508
|
+
}
|
|
4509
|
+
getGeom() {
|
|
4510
|
+
const geom0 = this.exteriorRing.getGeom();
|
|
4511
|
+
// exterior ring was all (within rounding error of angle calc) colinear points
|
|
4512
|
+
if (geom0 === null)
|
|
4513
|
+
return null;
|
|
4514
|
+
const geom = [geom0];
|
|
4515
|
+
for (let i = 0, iMax = this.interiorRings.length; i < iMax; i++) {
|
|
4516
|
+
const ringGeom = this.interiorRings[i].getGeom();
|
|
4517
|
+
// interior ring was all (within rounding error of angle calc) colinear points
|
|
4518
|
+
if (ringGeom === null)
|
|
4519
|
+
continue;
|
|
4520
|
+
geom.push(ringGeom);
|
|
4521
|
+
}
|
|
4522
|
+
return geom;
|
|
4523
|
+
}
|
|
4524
|
+
}
|
|
4525
|
+
class MultiPolyOut {
|
|
4526
|
+
rings;
|
|
4527
|
+
polys;
|
|
4528
|
+
constructor(rings) {
|
|
4529
|
+
this.rings = rings;
|
|
4530
|
+
this.polys = this._composePolys(rings);
|
|
4531
|
+
}
|
|
4532
|
+
getGeom() {
|
|
4533
|
+
const geom = [];
|
|
4534
|
+
for (let i = 0, iMax = this.polys.length; i < iMax; i++) {
|
|
4535
|
+
const polyGeom = this.polys[i].getGeom();
|
|
4536
|
+
// exterior ring was all (within rounding error of angle calc) colinear points
|
|
4537
|
+
if (polyGeom === null)
|
|
4538
|
+
continue;
|
|
4539
|
+
geom.push(polyGeom);
|
|
4540
|
+
}
|
|
4541
|
+
return geom;
|
|
4542
|
+
}
|
|
4543
|
+
_composePolys(rings) {
|
|
4544
|
+
const polys = [];
|
|
4545
|
+
for (let i = 0, iMax = rings.length; i < iMax; i++) {
|
|
4546
|
+
const ring = rings[i];
|
|
4547
|
+
if (ring.poly)
|
|
4548
|
+
continue;
|
|
4549
|
+
if (ring.isExteriorRing())
|
|
4550
|
+
polys.push(new PolyOut(ring));
|
|
4551
|
+
else {
|
|
4552
|
+
const enclosingRing = ring.enclosingRing();
|
|
4553
|
+
if (!enclosingRing?.poly)
|
|
4554
|
+
polys.push(new PolyOut(enclosingRing));
|
|
4555
|
+
enclosingRing?.poly?.addInterior(ring);
|
|
4556
|
+
}
|
|
4557
|
+
}
|
|
4558
|
+
return polys;
|
|
4559
|
+
}
|
|
4560
|
+
}
|
|
4561
|
+
|
|
4562
|
+
/**
|
|
4563
|
+
* NOTE: We must be careful not to change any segments while
|
|
4564
|
+
* they are in the SplayTree. AFAIK, there's no way to tell
|
|
4565
|
+
* the tree to rebalance itself - thus before splitting
|
|
4566
|
+
* a segment that's in the tree, we remove it from the tree,
|
|
4567
|
+
* do the split, then re-insert it. (Even though splitting a
|
|
4568
|
+
* segment *shouldn't* change its correct position in the
|
|
4569
|
+
* sweep line tree, the reality is because of rounding errors,
|
|
4570
|
+
* it sometimes does.)
|
|
4571
|
+
*/
|
|
4572
|
+
class SweepLine {
|
|
4573
|
+
queue;
|
|
4574
|
+
tree;
|
|
4575
|
+
segments;
|
|
4576
|
+
constructor(queue, comparator = Segment.compare) {
|
|
4577
|
+
this.queue = queue;
|
|
4578
|
+
this.tree = new SplayTreeSet(comparator);
|
|
4579
|
+
this.segments = [];
|
|
4580
|
+
}
|
|
4581
|
+
process(event) {
|
|
4582
|
+
const segment = event.segment;
|
|
4583
|
+
const newEvents = [];
|
|
4584
|
+
// if we've already been consumed by another segment,
|
|
4585
|
+
// clean up our body parts and get out
|
|
4586
|
+
if (event.consumedBy) {
|
|
4587
|
+
if (event.isLeft)
|
|
4588
|
+
this.queue.delete(event.otherSE);
|
|
4589
|
+
else
|
|
4590
|
+
this.tree.delete(segment);
|
|
4591
|
+
return newEvents;
|
|
4592
|
+
}
|
|
4593
|
+
if (event.isLeft)
|
|
4594
|
+
this.tree.add(segment);
|
|
4595
|
+
let prevSeg = segment;
|
|
4596
|
+
let nextSeg = segment;
|
|
4597
|
+
// skip consumed segments still in tree
|
|
4598
|
+
do {
|
|
4599
|
+
prevSeg = this.tree.lastBefore(prevSeg);
|
|
4600
|
+
} while (prevSeg != null && prevSeg.consumedBy != undefined);
|
|
4601
|
+
// skip consumed segments still in tree
|
|
4602
|
+
do {
|
|
4603
|
+
nextSeg = this.tree.firstAfter(nextSeg);
|
|
4604
|
+
} while (nextSeg != null && nextSeg.consumedBy != undefined);
|
|
4605
|
+
if (event.isLeft) {
|
|
4606
|
+
// Check for intersections against the previous segment in the sweep line
|
|
4607
|
+
let prevMySplitter = null;
|
|
4608
|
+
if (prevSeg) {
|
|
4609
|
+
const prevInter = prevSeg.getIntersection(segment);
|
|
4610
|
+
if (prevInter !== null) {
|
|
4611
|
+
if (!segment.isAnEndpoint(prevInter))
|
|
4612
|
+
prevMySplitter = prevInter;
|
|
4613
|
+
if (!prevSeg.isAnEndpoint(prevInter)) {
|
|
4614
|
+
const newEventsFromSplit = this._splitSafely(prevSeg, prevInter);
|
|
4615
|
+
for (let i = 0, iMax = newEventsFromSplit.length; i < iMax; i++) {
|
|
4616
|
+
newEvents.push(newEventsFromSplit[i]);
|
|
4617
|
+
}
|
|
4618
|
+
}
|
|
4619
|
+
}
|
|
4620
|
+
}
|
|
4621
|
+
// Check for intersections against the next segment in the sweep line
|
|
4622
|
+
let nextMySplitter = null;
|
|
4623
|
+
if (nextSeg) {
|
|
4624
|
+
const nextInter = nextSeg.getIntersection(segment);
|
|
4625
|
+
if (nextInter !== null) {
|
|
4626
|
+
if (!segment.isAnEndpoint(nextInter))
|
|
4627
|
+
nextMySplitter = nextInter;
|
|
4628
|
+
if (!nextSeg.isAnEndpoint(nextInter)) {
|
|
4629
|
+
const newEventsFromSplit = this._splitSafely(nextSeg, nextInter);
|
|
4630
|
+
for (let i = 0, iMax = newEventsFromSplit.length; i < iMax; i++) {
|
|
4631
|
+
newEvents.push(newEventsFromSplit[i]);
|
|
4632
|
+
}
|
|
4633
|
+
}
|
|
4634
|
+
}
|
|
4635
|
+
}
|
|
4636
|
+
// For simplicity, even if we find more than one intersection we only
|
|
4637
|
+
// spilt on the 'earliest' (sweep-line style) of the intersections.
|
|
4638
|
+
// The other intersection will be handled in a future process().
|
|
4639
|
+
if (prevMySplitter !== null || nextMySplitter !== null) {
|
|
4640
|
+
let mySplitter = null;
|
|
4641
|
+
if (prevMySplitter === null)
|
|
4642
|
+
mySplitter = nextMySplitter;
|
|
4643
|
+
else if (nextMySplitter === null)
|
|
4644
|
+
mySplitter = prevMySplitter;
|
|
4645
|
+
else {
|
|
4646
|
+
const cmpSplitters = SweepEvent.comparePoints(prevMySplitter, nextMySplitter);
|
|
4647
|
+
mySplitter = cmpSplitters <= 0 ? prevMySplitter : nextMySplitter;
|
|
4648
|
+
}
|
|
4649
|
+
// Rounding errors can cause changes in ordering,
|
|
4650
|
+
// so remove afected segments and right sweep events before splitting
|
|
4651
|
+
this.queue.delete(segment.rightSE);
|
|
4652
|
+
newEvents.push(segment.rightSE);
|
|
4653
|
+
const newEventsFromSplit = segment.split(mySplitter);
|
|
4654
|
+
for (let i = 0, iMax = newEventsFromSplit.length; i < iMax; i++) {
|
|
4655
|
+
newEvents.push(newEventsFromSplit[i]);
|
|
4656
|
+
}
|
|
4657
|
+
}
|
|
4658
|
+
if (newEvents.length > 0) {
|
|
4659
|
+
// We found some intersections, so re-do the current event to
|
|
4660
|
+
// make sure sweep line ordering is totally consistent for later
|
|
4661
|
+
// use with the segment 'prev' pointers
|
|
4662
|
+
this.tree.delete(segment);
|
|
4663
|
+
newEvents.push(event);
|
|
4664
|
+
}
|
|
4665
|
+
else {
|
|
4666
|
+
// done with left event
|
|
4667
|
+
this.segments.push(segment);
|
|
4668
|
+
segment.prev = prevSeg;
|
|
4669
|
+
}
|
|
4670
|
+
}
|
|
4671
|
+
else {
|
|
4672
|
+
// event.isRight
|
|
4673
|
+
// since we're about to be removed from the sweep line, check for
|
|
4674
|
+
// intersections between our previous and next segments
|
|
4675
|
+
if (prevSeg && nextSeg) {
|
|
4676
|
+
const inter = prevSeg.getIntersection(nextSeg);
|
|
4677
|
+
if (inter !== null) {
|
|
4678
|
+
if (!prevSeg.isAnEndpoint(inter)) {
|
|
4679
|
+
const newEventsFromSplit = this._splitSafely(prevSeg, inter);
|
|
4680
|
+
for (let i = 0, iMax = newEventsFromSplit.length; i < iMax; i++) {
|
|
4681
|
+
newEvents.push(newEventsFromSplit[i]);
|
|
4682
|
+
}
|
|
4683
|
+
}
|
|
4684
|
+
if (!nextSeg.isAnEndpoint(inter)) {
|
|
4685
|
+
const newEventsFromSplit = this._splitSafely(nextSeg, inter);
|
|
4686
|
+
for (let i = 0, iMax = newEventsFromSplit.length; i < iMax; i++) {
|
|
4687
|
+
newEvents.push(newEventsFromSplit[i]);
|
|
4688
|
+
}
|
|
4689
|
+
}
|
|
4690
|
+
}
|
|
4691
|
+
}
|
|
4692
|
+
this.tree.delete(segment);
|
|
4693
|
+
}
|
|
4694
|
+
return newEvents;
|
|
4695
|
+
}
|
|
4696
|
+
/* Safely split a segment that is currently in the datastructures
|
|
4697
|
+
* IE - a segment other than the one that is currently being processed. */
|
|
4698
|
+
_splitSafely(seg, pt) {
|
|
4699
|
+
// Rounding errors can cause changes in ordering,
|
|
4700
|
+
// so remove afected segments and right sweep events before splitting
|
|
4701
|
+
// removeNode() doesn't work, so have re-find the seg
|
|
4702
|
+
// https://github.com/w8r/splay-tree/pull/5
|
|
4703
|
+
this.tree.delete(seg);
|
|
4704
|
+
const rightSE = seg.rightSE;
|
|
4705
|
+
this.queue.delete(rightSE);
|
|
4706
|
+
const newEvents = seg.split(pt);
|
|
4707
|
+
newEvents.push(rightSE);
|
|
4708
|
+
// splitting can trigger consumption
|
|
4709
|
+
if (seg.consumedBy === undefined)
|
|
4710
|
+
this.tree.add(seg);
|
|
4711
|
+
return newEvents;
|
|
4712
|
+
}
|
|
4713
|
+
}
|
|
4714
|
+
|
|
4715
|
+
class Operation {
|
|
4716
|
+
type;
|
|
4717
|
+
numMultiPolys;
|
|
4718
|
+
run(type, geom, moreGeoms) {
|
|
4719
|
+
operation.type = type;
|
|
4720
|
+
/* Convert inputs to MultiPoly objects */
|
|
4721
|
+
const multipolys = [new MultiPolyIn(geom, true)];
|
|
4722
|
+
for (let i = 0, iMax = moreGeoms.length; i < iMax; i++) {
|
|
4723
|
+
multipolys.push(new MultiPolyIn(moreGeoms[i], false));
|
|
4724
|
+
}
|
|
4725
|
+
operation.numMultiPolys = multipolys.length;
|
|
4726
|
+
/* BBox optimization for difference operation
|
|
4727
|
+
* If the bbox of a multipolygon that's part of the clipping doesn't
|
|
4728
|
+
* intersect the bbox of the subject at all, we can just drop that
|
|
4729
|
+
* multiploygon. */
|
|
4730
|
+
if (operation.type === "difference") {
|
|
4731
|
+
// in place removal
|
|
4732
|
+
const subject = multipolys[0];
|
|
4733
|
+
let i = 1;
|
|
4734
|
+
while (i < multipolys.length) {
|
|
4735
|
+
if (getBboxOverlap(multipolys[i].bbox, subject.bbox) !== null)
|
|
4736
|
+
i++;
|
|
4737
|
+
else
|
|
4738
|
+
multipolys.splice(i, 1);
|
|
4739
|
+
}
|
|
4740
|
+
}
|
|
4741
|
+
/* BBox optimization for intersection operation
|
|
4742
|
+
* If we can find any pair of multipolygons whose bbox does not overlap,
|
|
4743
|
+
* then the result will be empty. */
|
|
4744
|
+
if (operation.type === "intersection") {
|
|
4745
|
+
// TODO: this is O(n^2) in number of polygons. By sorting the bboxes,
|
|
4746
|
+
// it could be optimized to O(n * ln(n))
|
|
4747
|
+
for (let i = 0, iMax = multipolys.length; i < iMax; i++) {
|
|
4748
|
+
const mpA = multipolys[i];
|
|
4749
|
+
for (let j = i + 1, jMax = multipolys.length; j < jMax; j++) {
|
|
4750
|
+
if (getBboxOverlap(mpA.bbox, multipolys[j].bbox) === null)
|
|
4751
|
+
return [];
|
|
4752
|
+
}
|
|
4753
|
+
}
|
|
4754
|
+
}
|
|
4755
|
+
/* Put segment endpoints in a priority queue */
|
|
4756
|
+
const queue = new SplayTreeSet(SweepEvent.compare);
|
|
4757
|
+
for (let i = 0, iMax = multipolys.length; i < iMax; i++) {
|
|
4758
|
+
const sweepEvents = multipolys[i].getSweepEvents();
|
|
4759
|
+
for (let j = 0, jMax = sweepEvents.length; j < jMax; j++) {
|
|
4760
|
+
queue.add(sweepEvents[j]);
|
|
4761
|
+
}
|
|
4762
|
+
}
|
|
4763
|
+
/* Pass the sweep line over those endpoints */
|
|
4764
|
+
const sweepLine = new SweepLine(queue);
|
|
4765
|
+
let evt = null;
|
|
4766
|
+
if (queue.size != 0) {
|
|
4767
|
+
evt = queue.first();
|
|
4768
|
+
queue.delete(evt);
|
|
4769
|
+
}
|
|
4770
|
+
while (evt) {
|
|
4771
|
+
const newEvents = sweepLine.process(evt);
|
|
4772
|
+
for (let i = 0, iMax = newEvents.length; i < iMax; i++) {
|
|
4773
|
+
const evt = newEvents[i];
|
|
4774
|
+
if (evt.consumedBy === undefined)
|
|
4775
|
+
queue.add(evt);
|
|
4776
|
+
}
|
|
4777
|
+
if (queue.size != 0) {
|
|
4778
|
+
evt = queue.first();
|
|
4779
|
+
queue.delete(evt);
|
|
4780
|
+
}
|
|
4781
|
+
else {
|
|
4782
|
+
evt = null;
|
|
4783
|
+
}
|
|
4784
|
+
}
|
|
4785
|
+
// free some memory we don't need anymore
|
|
4786
|
+
precision.reset();
|
|
4787
|
+
/* Collect and compile segments we're keeping into a multipolygon */
|
|
4788
|
+
const ringsOut = RingOut.factory(sweepLine.segments);
|
|
4789
|
+
const result = new MultiPolyOut(ringsOut);
|
|
4790
|
+
return result.getGeom();
|
|
4791
|
+
}
|
|
4792
|
+
}
|
|
4793
|
+
// singleton available by import
|
|
4794
|
+
const operation = new Operation();
|
|
4795
|
+
|
|
4796
|
+
const union = (geom, ...moreGeoms) => operation.run("union", geom, moreGeoms);
|
|
4797
|
+
const intersection = (geom, ...moreGeoms) => operation.run("intersection", geom, moreGeoms);
|
|
4798
|
+
const xor = (geom, ...moreGeoms) => operation.run("xor", geom, moreGeoms);
|
|
4799
|
+
const difference = (geom, ...moreGeoms) => operation.run("difference", geom, moreGeoms);
|
|
4800
|
+
const setPrecision = precision.set;
|
|
4801
|
+
|
|
4802
|
+
exports.difference = difference;
|
|
4803
|
+
exports.intersection = intersection;
|
|
4804
|
+
exports.setPrecision = setPrecision;
|
|
4805
|
+
exports.union = union;
|
|
4806
|
+
exports.version = version;
|
|
4807
|
+
exports.xor = xor;
|
|
4808
|
+
|
|
4809
|
+
Object.defineProperty(exports, '__esModule', { value: true });
|
|
4810
|
+
|
|
4811
|
+
}));
|