paper 0.17.0 → 1.0.0-rc.1
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/CHANGELOG.md +199 -0
- package/LICENSE.txt +1 -1
- package/MIGRATION.md +402 -0
- package/README.md +137 -143
- package/dist/esm/anim/Tween.js +404 -0
- package/dist/esm/basic/Line.js +252 -0
- package/dist/esm/basic/Matrix.js +603 -0
- package/dist/esm/basic/Point.js +738 -0
- package/dist/esm/basic/Rectangle.js +788 -0
- package/dist/esm/basic/Size.js +368 -0
- package/dist/esm/boolean/graph.js +950 -0
- package/dist/esm/boolean/index.js +143 -0
- package/dist/esm/boolean/operations.js +94 -0
- package/dist/esm/boolean/split.js +89 -0
- package/dist/esm/canvas/blendModes.js +115 -0
- package/dist/esm/canvas/canvasProvider.js +102 -0
- package/dist/esm/constants.js +130 -0
- package/dist/esm/core/Base.js +52 -0
- package/dist/esm/core/Emitter.js +215 -0
- package/dist/esm/core/features.js +53 -0
- package/dist/esm/core/serialization.js +174 -0
- package/dist/esm/core.js +15 -0
- package/dist/esm/dom/domElement.js +112 -0
- package/dist/esm/dom/domEvent.js +106 -0
- package/dist/esm/env.js +66 -0
- package/dist/esm/event/DrawEvent.js +38 -0
- package/dist/esm/event/Event.js +79 -0
- package/dist/esm/event/Key.js +236 -0
- package/dist/esm/event/KeyEvent.js +39 -0
- package/dist/esm/event/MouseEvent.js +91 -0
- package/dist/esm/hosted/HostItem.js +60 -0
- package/dist/esm/hosted/Hosting.js +1061 -0
- package/dist/esm/hosted/index.js +20 -0
- package/dist/esm/index.js +38 -0
- package/dist/esm/internal.js +115 -0
- package/dist/esm/item/Effect.js +256 -0
- package/dist/esm/item/EffectInstance.js +184 -0
- package/dist/esm/item/Group.js +293 -0
- package/dist/esm/item/HitResult.js +126 -0
- package/dist/esm/item/Item.js +3339 -0
- package/dist/esm/item/ItemDefinition.js +95 -0
- package/dist/esm/item/Layer.js +69 -0
- package/dist/esm/item/Project.js +1013 -0
- package/dist/esm/item/Raster.js +722 -0
- package/dist/esm/item/Shape.js +355 -0
- package/dist/esm/item/SymbolDefinition.js +68 -0
- package/dist/esm/item/SymbolItem.js +131 -0
- package/dist/esm/item/bounds.js +324 -0
- package/dist/esm/item/draw.js +525 -0
- package/dist/esm/item/effects.js +124 -0
- package/dist/esm/item/expand.js +87 -0
- package/dist/esm/item/hitTest.js +203 -0
- package/dist/esm/item/hosting.js +12 -0
- package/dist/esm/item/props.js +12 -0
- package/dist/esm/item/query.js +139 -0
- package/dist/esm/item/sampling.js +67 -0
- package/dist/esm/item/transform.js +128 -0
- package/dist/esm/net/http.js +26 -0
- package/dist/esm/node/CanvasAdapter.js +137 -0
- package/dist/esm/node/index.js +150 -0
- package/dist/esm/node/peers.js +27 -0
- package/dist/esm/offset/curves.js +866 -0
- package/dist/esm/offset/index.js +70 -0
- package/dist/esm/offset/offset.js +178 -0
- package/dist/esm/offset/outline.js +91 -0
- package/dist/esm/offset/pen.js +298 -0
- package/dist/esm/offset/profile.js +772 -0
- package/dist/esm/offset/round.js +213 -0
- package/dist/esm/offset/sweep.js +100 -0
- package/dist/esm/paperscript/PaperScript.js +832 -0
- package/dist/esm/paperscript/autoload.js +27 -0
- package/dist/esm/paperscript/index.js +17 -0
- package/dist/esm/path/CompoundPath.js +367 -0
- package/dist/esm/path/Curve.js +996 -0
- package/dist/esm/path/CurveLocation.js +462 -0
- package/dist/esm/path/Path.js +1761 -0
- package/dist/esm/path/PathFlattener.js +186 -0
- package/dist/esm/path/PathItem.js +757 -0
- package/dist/esm/path/Segment.js +640 -0
- package/dist/esm/path/SegmentPoint.js +106 -0
- package/dist/esm/path/StrokeProfile.js +387 -0
- package/dist/esm/path/StrokeProfileStop.js +207 -0
- package/dist/esm/path/boolean.js +284 -0
- package/dist/esm/path/bounds.js +257 -0
- package/dist/esm/path/crossing.js +114 -0
- package/dist/esm/path/draw.js +161 -0
- package/dist/esm/path/hitTest.js +259 -0
- package/dist/esm/path/offset.js +152 -0
- package/dist/esm/path/shapes.js +231 -0
- package/dist/esm/path/smooth.js +84 -0
- package/dist/esm/path/values.js +40 -0
- package/dist/esm/scope/PaperScope.js +288 -0
- package/dist/esm/scope/PaperScopeItem.js +74 -0
- package/dist/esm/smoothing/index.js +71 -0
- package/dist/esm/style/Color.js +917 -0
- package/dist/esm/style/Gradient.js +191 -0
- package/dist/esm/style/GradientStop.js +168 -0
- package/dist/esm/style/PatternDefinition.js +383 -0
- package/dist/esm/style/Style.js +503 -0
- package/dist/esm/svg/index.js +27 -0
- package/dist/esm/svg/svgElement.js +97 -0
- package/dist/esm/svg/svgExport.js +847 -0
- package/dist/esm/svg/svgImport.js +1101 -0
- package/dist/esm/svg/svgStyles.js +96 -0
- package/dist/esm/text/AreaText.js +190 -0
- package/dist/esm/text/PathText.js +111 -0
- package/dist/esm/text/PointText.js +92 -0
- package/dist/esm/text/TextItem.js +538 -0
- package/dist/esm/text/TextRange.js +169 -0
- package/dist/esm/text/TextStory.js +394 -0
- package/dist/esm/text/areaLayout.js +439 -0
- package/dist/esm/text/layout.js +265 -0
- package/dist/esm/text/measure.js +57 -0
- package/dist/esm/text/pathLayout.js +93 -0
- package/dist/esm/tool/Tool.js +284 -0
- package/dist/esm/tool/ToolEvent.js +232 -0
- package/dist/esm/util/Formatter.js +57 -0
- package/dist/esm/util/collisions.js +216 -0
- package/dist/esm/util/list.js +110 -0
- package/dist/esm/util/numerical.js +656 -0
- package/dist/esm/util/object.js +81 -0
- package/dist/esm/util/string.js +29 -0
- package/dist/esm/util/uid.js +31 -0
- package/dist/esm/values/arcs.js +243 -0
- package/dist/esm/values/curve.js +975 -0
- package/dist/esm/values/fit.js +290 -0
- package/dist/esm/values/index.js +23 -0
- package/dist/esm/values/intersections.js +869 -0
- package/dist/esm/values/matrix.js +114 -0
- package/dist/esm/values/path.js +174 -0
- package/dist/esm/values/profile.js +221 -0
- package/dist/esm/values/region.js +63 -0
- package/dist/esm/values/smooth.js +248 -0
- package/dist/esm/values/svg.js +287 -0
- package/dist/esm/view/CanvasView.js +106 -0
- package/dist/esm/view/View.js +775 -0
- package/dist/esm/view/input.js +527 -0
- package/dist/paper-full.js +32941 -26371
- package/dist/paper-full.min.js +36 -31
- package/dist/paper-hosted.js +33623 -27236
- package/dist/paper-hosted.min.js +37 -0
- package/dist/paper-slim.js +28581 -0
- package/dist/paper-slim.min.js +17 -0
- package/dist/types/anim/Tween.d.ts +164 -0
- package/dist/types/basic/Line.d.ts +136 -0
- package/dist/types/basic/Matrix.d.ts +387 -0
- package/dist/types/basic/Point.d.ts +781 -0
- package/dist/types/basic/Rectangle.d.ts +550 -0
- package/dist/types/basic/Size.d.ts +457 -0
- package/dist/types/boolean/graph.d.ts +123 -0
- package/dist/types/boolean/index.d.ts +74 -0
- package/dist/types/boolean/operations.d.ts +9 -0
- package/dist/types/boolean/split.d.ts +19 -0
- package/dist/types/canvas/blendModes.d.ts +18 -0
- package/dist/types/canvas/canvasProvider.d.ts +32 -0
- package/dist/types/constants.d.ts +112 -0
- package/dist/types/core/Base.d.ts +50 -0
- package/dist/types/core/Emitter.d.ts +49 -0
- package/dist/types/core/features.d.ts +41 -0
- package/dist/types/core/serialization.d.ts +44 -0
- package/dist/types/core.d.ts +18 -0
- package/dist/types/dom/domElement.d.ts +33 -0
- package/dist/types/dom/domEvent.d.ts +29 -0
- package/dist/types/env.d.ts +26 -0
- package/dist/types/event/DrawEvent.d.ts +27 -0
- package/dist/types/event/Event.d.ts +47 -0
- package/dist/types/event/Key.d.ts +82 -0
- package/dist/types/event/KeyEvent.d.ts +35 -0
- package/dist/types/event/MouseEvent.d.ts +78 -0
- package/dist/types/hosted/HostItem.d.ts +26 -0
- package/dist/types/hosted/Hosting.d.ts +273 -0
- package/dist/types/hosted/index.d.ts +10 -0
- package/dist/types/index.d.ts +64 -0
- package/dist/types/internal.d.ts +101 -0
- package/dist/types/item/Effect.d.ts +128 -0
- package/dist/types/item/EffectInstance.d.ts +81 -0
- package/dist/types/item/Group.d.ts +225 -0
- package/dist/types/item/HitResult.d.ts +94 -0
- package/dist/types/item/Item.d.ts +2927 -0
- package/dist/types/item/ItemDefinition.d.ts +25 -0
- package/dist/types/item/Layer.d.ts +80 -0
- package/dist/types/item/Project.d.ts +748 -0
- package/dist/types/item/Raster.d.ts +431 -0
- package/dist/types/item/Shape.d.ts +219 -0
- package/dist/types/item/SymbolDefinition.d.ts +98 -0
- package/dist/types/item/SymbolItem.d.ts +92 -0
- package/dist/types/item/bounds.d.ts +56 -0
- package/dist/types/item/draw.d.ts +23 -0
- package/dist/types/item/effects.d.ts +22 -0
- package/dist/types/item/expand.d.ts +7 -0
- package/dist/types/item/hitTest.d.ts +10 -0
- package/dist/types/item/hosting.d.ts +20 -0
- package/dist/types/item/props.d.ts +35 -0
- package/dist/types/item/query.d.ts +14 -0
- package/dist/types/item/sampling.d.ts +5 -0
- package/dist/types/item/transform.d.ts +3 -0
- package/dist/types/net/http.d.ts +6 -0
- package/dist/types/node/CanvasAdapter.d.ts +19 -0
- package/dist/types/node/index.d.ts +60 -0
- package/dist/types/node/peers.d.ts +2 -0
- package/dist/types/offset/curves.d.ts +22 -0
- package/dist/types/offset/index.d.ts +65 -0
- package/dist/types/offset/offset.d.ts +18 -0
- package/dist/types/offset/outline.d.ts +14 -0
- package/dist/types/offset/pen.d.ts +36 -0
- package/dist/types/offset/profile.d.ts +37 -0
- package/dist/types/offset/round.d.ts +18 -0
- package/dist/types/offset/sweep.d.ts +44 -0
- package/dist/types/paperscript/PaperScript.d.ts +114 -0
- package/dist/types/paperscript/autoload.d.ts +1 -0
- package/dist/types/paperscript/index.d.ts +7 -0
- package/dist/types/path/CompoundPath.d.ts +183 -0
- package/dist/types/path/Curve.d.ts +567 -0
- package/dist/types/path/CurveLocation.d.ts +164 -0
- package/dist/types/path/Path.d.ts +1361 -0
- package/dist/types/path/PathFlattener.d.ts +48 -0
- package/dist/types/path/PathItem.d.ts +1190 -0
- package/dist/types/path/Segment.d.ts +335 -0
- package/dist/types/path/SegmentPoint.d.ts +1 -0
- package/dist/types/path/StrokeProfile.d.ts +74 -0
- package/dist/types/path/StrokeProfileStop.d.ts +110 -0
- package/dist/types/path/boolean.d.ts +24 -0
- package/dist/types/path/bounds.d.ts +24 -0
- package/dist/types/path/crossing.d.ts +2 -0
- package/dist/types/path/draw.d.ts +6 -0
- package/dist/types/path/hitTest.d.ts +8 -0
- package/dist/types/path/offset.d.ts +14 -0
- package/dist/types/path/shapes.d.ts +20 -0
- package/dist/types/path/smooth.d.ts +18 -0
- package/dist/types/path/values.d.ts +8 -0
- package/dist/types/scope/PaperScope.d.ts +182 -0
- package/dist/types/scope/PaperScopeItem.d.ts +26 -0
- package/dist/types/smoothing/index.d.ts +26 -0
- package/dist/types/style/Color.d.ts +829 -0
- package/dist/types/style/Gradient.d.ts +130 -0
- package/dist/types/style/GradientStop.d.ts +126 -0
- package/dist/types/style/PatternDefinition.d.ts +185 -0
- package/dist/types/style/Style.d.ts +757 -0
- package/dist/types/svg/index.d.ts +14 -0
- package/dist/types/svg/svgElement.d.ts +32 -0
- package/dist/types/svg/svgExport.d.ts +19 -0
- package/dist/types/svg/svgImport.d.ts +13 -0
- package/dist/types/svg/svgStyles.d.ts +20 -0
- package/dist/types/text/AreaText.d.ts +104 -0
- package/dist/types/text/PathText.d.ts +78 -0
- package/dist/types/text/PointText.d.ts +50 -0
- package/dist/types/text/TextItem.d.ts +163 -0
- package/dist/types/text/TextRange.d.ts +98 -0
- package/dist/types/text/TextStory.d.ts +119 -0
- package/dist/types/text/areaLayout.d.ts +3 -0
- package/dist/types/text/layout.d.ts +43 -0
- package/dist/types/text/measure.d.ts +7 -0
- package/dist/types/text/pathLayout.d.ts +3 -0
- package/dist/types/tool/Tool.d.ts +356 -0
- package/dist/types/tool/ToolEvent.d.ts +134 -0
- package/dist/types/util/Formatter.d.ts +34 -0
- package/dist/types/util/collisions.d.ts +77 -0
- package/dist/types/util/list.d.ts +23 -0
- package/dist/types/util/numerical.d.ts +196 -0
- package/dist/types/util/object.d.ts +19 -0
- package/dist/types/util/string.d.ts +12 -0
- package/dist/types/util/uid.d.ts +7 -0
- package/dist/types/values/arcs.d.ts +10 -0
- package/dist/types/values/curve.d.ts +42 -0
- package/dist/types/values/fit.d.ts +26 -0
- package/dist/types/values/index.d.ts +10 -0
- package/dist/types/values/intersections.d.ts +11 -0
- package/dist/types/values/matrix.d.ts +19 -0
- package/dist/types/values/path.d.ts +26 -0
- package/dist/types/values/profile.d.ts +41 -0
- package/dist/types/values/region.d.ts +13 -0
- package/dist/types/values/smooth.d.ts +39 -0
- package/dist/types/values/svg.d.ts +47 -0
- package/dist/types/view/CanvasView.d.ts +37 -0
- package/dist/types/view/View.d.ts +700 -0
- package/dist/types/view/input.d.ts +28 -0
- package/package.json +89 -59
- package/dist/docs/assets/css/docs.css +0 -414
- package/dist/docs/assets/js/codemirror.js +0 -4
- package/dist/docs/assets/js/docs.js +0 -493
- package/dist/docs/assets/js/jquery.js +0 -6
- package/dist/docs/assets/js/paper.js +0 -27591
- package/dist/docs/classes/AreaText.html +0 -9186
- package/dist/docs/classes/ChangeFlag.html +0 -385
- package/dist/docs/classes/Color.html +0 -2402
- package/dist/docs/classes/CompoundPath.html +0 -10018
- package/dist/docs/classes/Curve.html +0 -2326
- package/dist/docs/classes/CurveLocation.html +0 -673
- package/dist/docs/classes/DrawEvent.html +0 -69
- package/dist/docs/classes/Effect.html +0 -434
- package/dist/docs/classes/EffectInstance.html +0 -304
- package/dist/docs/classes/Event.html +0 -177
- package/dist/docs/classes/Gradient.html +0 -241
- package/dist/docs/classes/GradientStop.html +0 -274
- package/dist/docs/classes/Group.html +0 -7688
- package/dist/docs/classes/HitResult.html +0 -241
- package/dist/docs/classes/HostItem.html +0 -7314
- package/dist/docs/classes/Item.html +0 -7427
- package/dist/docs/classes/Key.html +0 -140
- package/dist/docs/classes/KeyEvent.html +0 -309
- package/dist/docs/classes/Layer.html +0 -7671
- package/dist/docs/classes/Matrix.html +0 -1745
- package/dist/docs/classes/MouseEvent.html +0 -356
- package/dist/docs/classes/PaperScope.html +0 -548
- package/dist/docs/classes/PaperScript.html +0 -204
- package/dist/docs/classes/Path.html +0 -13007
- package/dist/docs/classes/PathItem.html +0 -9780
- package/dist/docs/classes/PathText.html +0 -9056
- package/dist/docs/classes/PatternDefinition.html +0 -367
- package/dist/docs/classes/Point.html +0 -2860
- package/dist/docs/classes/PointText.html +0 -8967
- package/dist/docs/classes/Project.html +0 -1774
- package/dist/docs/classes/Raster.html +0 -8547
- package/dist/docs/classes/Rectangle.html +0 -1698
- package/dist/docs/classes/Segment.html +0 -1017
- package/dist/docs/classes/Shape.html +0 -8048
- package/dist/docs/classes/Size.html +0 -1915
- package/dist/docs/classes/StrokeProfileStop.html +0 -346
- package/dist/docs/classes/Style.html +0 -1765
- package/dist/docs/classes/SymbolDefinition.html +0 -338
- package/dist/docs/classes/SymbolItem.html +0 -7477
- package/dist/docs/classes/TextItem.html +0 -8810
- package/dist/docs/classes/TextRange.html +0 -186
- package/dist/docs/classes/TextStory.html +0 -355
- package/dist/docs/classes/Tool.html +0 -888
- package/dist/docs/classes/ToolEvent.html +0 -525
- package/dist/docs/classes/Tween.html +0 -390
- package/dist/docs/classes/View.html +0 -2108
- package/dist/docs/classes/global.html +0 -426
- package/dist/docs/classes/index.html +0 -88
- package/dist/docs/index.html +0 -11
- package/dist/node/browser.js +0 -15
- package/dist/node/canvas.js +0 -68
- package/dist/node/extend.js +0 -156
- package/dist/node/self.js +0 -67
- package/dist/paper-core.d.ts +0 -1
- package/dist/paper-core.js +0 -25636
- package/dist/paper-core.min.js +0 -32
- package/dist/paper.d.ts +0 -10481
- package/examples/Animated/AnimatedStar.html +0 -53
- package/examples/Animated/BooleanOperations.html +0 -115
- package/examples/Animated/CandyCrash.html +0 -151
- package/examples/Animated/Extruded.html +0 -50
- package/examples/Animated/Lines.html +0 -53
- package/examples/Animated/Smoothing.html +0 -70
- package/examples/Animated/Space.html +0 -86
- package/examples/Animated/SpaceUsingShapes.html +0 -79
- package/examples/Games/Paperoids.html +0 -569
- package/examples/JSON/Circle Testing.html +0 -34
- package/examples/JSON/Compound Path.html +0 -25
- package/examples/JSON/Empty Path Testing.html +0 -31
- package/examples/JSON/Gradients.html +0 -34
- package/examples/JSON/Group Transform.html +0 -28
- package/examples/JSON/Line Testing.html +0 -44
- package/examples/JSON/Random Path Testing.html +0 -42
- package/examples/JSON/Raster.html +0 -29
- package/examples/JSON/Rect and Attribute Testing.html +0 -56
- package/examples/JSON/Rotated Primitives.html +0 -55
- package/examples/JSON/Selection.html +0 -43
- package/examples/JSON/Shapes.html +0 -54
- package/examples/JSON/Symbols.html +0 -30
- package/examples/JSON/Text Testing.html +0 -38
- package/examples/JSON/Tiger.html +0 -19
- package/examples/JSON/Transform Test 1.html +0 -32
- package/examples/JSON/Transform Test 2.html +0 -30
- package/examples/Node.js/AnimatedStar.js +0 -52
- package/examples/Node.js/BooleanOperations.js +0 -36
- package/examples/Node.js/JSONtoPDF.js +0 -20
- package/examples/Node.js/Raster.js +0 -32
- package/examples/Node.js/RasterRemote.js +0 -33
- package/examples/Node.js/SvgExport.js +0 -52
- package/examples/Node.js/SvgImport.js +0 -23
- package/examples/Node.js/Tadpoles.js +0 -16
- package/examples/Node.js/Tadpoles.pjs +0 -278
- package/examples/Node.js/in.json +0 -1
- package/examples/Node.js/in.svg +0 -16
- package/examples/Paperjs.org/BooleanOperattions.html +0 -115
- package/examples/Paperjs.org/BouncingBalls.html +0 -103
- package/examples/Paperjs.org/Chain.html +0 -54
- package/examples/Paperjs.org/DivisionRaster.html +0 -72
- package/examples/Paperjs.org/FutureSplash.html +0 -122
- package/examples/Paperjs.org/HitTesting.html +0 -103
- package/examples/Paperjs.org/InteractiveTiger.html +0 -777
- package/examples/Paperjs.org/LiveEffects.html +0 -366
- package/examples/Paperjs.org/MetaBalls.html +0 -132
- package/examples/Paperjs.org/NyanRainbow.html +0 -202
- package/examples/Paperjs.org/Offsetting.html +0 -379
- package/examples/Paperjs.org/PathIntersections.html +0 -76
- package/examples/Paperjs.org/Qbertify.html +0 -146
- package/examples/Paperjs.org/RadialRainbows.html +0 -80
- package/examples/Paperjs.org/RoundedRectangles.html +0 -41
- package/examples/Paperjs.org/SatieLikedToDraw.html +0 -140
- package/examples/Paperjs.org/Simplify.html +0 -63
- package/examples/Paperjs.org/SpiralRaster.html +0 -120
- package/examples/Paperjs.org/StrokeProfiles.html +0 -706
- package/examples/Paperjs.org/Tadpoles.html +0 -283
- package/examples/Paperjs.org/Voronoi.html +0 -134
- package/examples/Rasters/PhyllotaxisRaster.html +0 -96
- package/examples/Rasters/Raster.html +0 -34
- package/examples/Rasters/RotationRaster.html +0 -44
- package/examples/Rasters/Smoothing.html +0 -36
- package/examples/SVG Export/Circle Testing.html +0 -32
- package/examples/SVG Export/Clipping.html +0 -17
- package/examples/SVG Export/Compound Path.html +0 -22
- package/examples/SVG Export/Empty Path Testing.html +0 -28
- package/examples/SVG Export/Gradients.html +0 -52
- package/examples/SVG Export/Group Transform.html +0 -25
- package/examples/SVG Export/Line Testing.html +0 -41
- package/examples/SVG Export/Random Path Testing.html +0 -39
- package/examples/SVG Export/Raster.html +0 -21
- package/examples/SVG Export/Rect and Attribute Testing.html +0 -53
- package/examples/SVG Export/Rotated Primitives.html +0 -80
- package/examples/SVG Export/Shapes.html +0 -58
- package/examples/SVG Export/Symbols.html +0 -27
- package/examples/SVG Export/Text Testing.html +0 -45
- package/examples/SVG Export/Tiger.html +0 -23
- package/examples/SVG Export/Transform Test 1.html +0 -29
- package/examples/SVG Export/Transform Test 2.html +0 -27
- package/examples/SVG Import/Arcs.html +0 -78
- package/examples/SVG Import/Butterfly.html +0 -223
- package/examples/SVG Import/Circle and Ellipse Testing.html +0 -26
- package/examples/SVG Import/Clipping.html +0 -100
- package/examples/SVG Import/From File.html +0 -30
- package/examples/SVG Import/Gradient.html +0 -138
- package/examples/SVG Import/Gradients.html +0 -30
- package/examples/SVG Import/Inkscape Pivot.html +0 -52
- package/examples/SVG Import/Inkscape.html +0 -88
- package/examples/SVG Import/Line Testing.html +0 -24
- package/examples/SVG Import/MoreGradients.html +0 -107
- package/examples/SVG Import/Multiple Paths Test 1.html +0 -42
- package/examples/SVG Import/Multiple Paths Test 2.html +0 -33
- package/examples/SVG Import/Nested Groups Test.html +0 -78
- package/examples/SVG Import/Polybezier.html +0 -43
- package/examples/SVG Import/Rect Testing.html +0 -25
- package/examples/SVG Import/Symbols.html +0 -24
- package/examples/SVG Import/Testing.html +0 -40
- package/examples/SVG Import/Text Testing.html +0 -19
- package/examples/SVG Import/Tiger.html +0 -742
- package/examples/SVG Import/Transform Testing.html +0 -22
- package/examples/SVG Import/Viewbox.html +0 -38
- package/examples/Scripts/Arcs.html +0 -39
- package/examples/Scripts/AreaText.html +0 -65
- package/examples/Scripts/BlendModes.html +0 -77
- package/examples/Scripts/BooleanOperations.html +0 -937
- package/examples/Scripts/CompoundPath.html +0 -19
- package/examples/Scripts/CurveTimeParameterization.html +0 -61
- package/examples/Scripts/HslColor.html +0 -53
- package/examples/Scripts/PathStructure.html +0 -82
- package/examples/Scripts/PathTangents.html +0 -73
- package/examples/Scripts/PathText.html +0 -48
- package/examples/Scripts/Patterns.html +0 -57
- package/examples/Scripts/Resize.html +0 -42
- package/examples/Scripts/RoundRectangle.html +0 -28
- package/examples/Scripts/Shapes.html +0 -54
- package/examples/Scripts/StrokeBounds.html +0 -101
- package/examples/Scripts/StrokeScaling.html +0 -65
- package/examples/Scripts/TextRanges.html +0 -51
- package/examples/Tools/BezierTool.html +0 -90
- package/examples/Tools/Circles.html +0 -28
- package/examples/Tools/Clouds.html +0 -35
- package/examples/Tools/DrippingBrush.html +0 -73
- package/examples/Tools/FancyBrush.html +0 -82
- package/examples/Tools/Grid.html +0 -44
- package/examples/Tools/MultiLines.html +0 -44
- package/examples/Tools/MultipleTools.html +0 -44
- package/examples/Tools/PathEditing.html +0 -95
- package/examples/Tools/SquareRounded.html +0 -76
- package/examples/Tools/Stars.html +0 -38
- package/examples/Tools/Vektor.html +0 -200
- package/examples/Tools/Wave.html +0 -50
- package/examples/Tools/WormFarm.html +0 -88
- package/examples/Worker/Main.html +0 -53
- package/examples/Worker/Worker.js +0 -14
- package/examples/css/style.css +0 -12
|
@@ -0,0 +1,738 @@
|
|
|
1
|
+
/*
|
|
2
|
+
* Paper.js - The Swiss Army Knife of Vector Graphics Scripting.
|
|
3
|
+
* http://paperjs.org/
|
|
4
|
+
*
|
|
5
|
+
* Copyright (c) 2011 - 2026, Jürg Lehni & Jonathan Puckey
|
|
6
|
+
* http://juerglehni.com/ & https://puckey.studio/
|
|
7
|
+
*
|
|
8
|
+
* Distributed under the MIT license. See LICENSE file for details.
|
|
9
|
+
*
|
|
10
|
+
* All rights reserved.
|
|
11
|
+
*/
|
|
12
|
+
import { ItemSelection } from "../constants.js";
|
|
13
|
+
import { TRIGONOMETRIC_EPSILON, clamp, isZero } from "../util/numerical.js";
|
|
14
|
+
import { Formatter } from "../util/Formatter.js";
|
|
15
|
+
import { Base } from "../core/Base.js";
|
|
16
|
+
import { registerClasses } from "../core/serialization.js";
|
|
17
|
+
import { Rectangle } from "./Rectangle.js";
|
|
18
|
+
/**
|
|
19
|
+
* The Point object represents a point in the two dimensional space
|
|
20
|
+
* of the Paper.js project. It is also used to represent two dimensional
|
|
21
|
+
* vector objects.
|
|
22
|
+
*
|
|
23
|
+
* Wherever a point is the only argument of a function, it can also be passed
|
|
24
|
+
* as two numbers, e.g. `point.add(10, 20)` or `item.translate(10, 20)`.
|
|
25
|
+
*
|
|
26
|
+
* @classexample
|
|
27
|
+
* // Create a point at x: 10, y: 5
|
|
28
|
+
* var point = new Point(10, 5);
|
|
29
|
+
* console.log(point.x); // 10
|
|
30
|
+
* console.log(point.y); // 5
|
|
31
|
+
*/
|
|
32
|
+
export class Point extends Base {
|
|
33
|
+
// The angle that the vector keeps when its length is set to 0:
|
|
34
|
+
#angle;
|
|
35
|
+
constructor(x, y) {
|
|
36
|
+
super();
|
|
37
|
+
this.set(x, y);
|
|
38
|
+
}
|
|
39
|
+
/**
|
|
40
|
+
* Sets the point to the passed values. Note that any sequence of parameters
|
|
41
|
+
* that is supported by the various {@link Point()} constructors also work
|
|
42
|
+
* for calls of `set()`.
|
|
43
|
+
*
|
|
44
|
+
* @param point the point, or its x-coordinate
|
|
45
|
+
* @param y the y-coordinate, with a number as the first argument
|
|
46
|
+
*/
|
|
47
|
+
set(point, y) {
|
|
48
|
+
if (typeof point === 'number') {
|
|
49
|
+
this._set(point, typeof y === 'number' ? y : point);
|
|
50
|
+
}
|
|
51
|
+
else if (point === undefined || point === null) {
|
|
52
|
+
this._set(0, 0);
|
|
53
|
+
}
|
|
54
|
+
else {
|
|
55
|
+
const obj = point;
|
|
56
|
+
if (Array.isArray(obj)) {
|
|
57
|
+
this._set(+obj[0], +(obj.length > 1 ? obj[1] : obj[0]));
|
|
58
|
+
}
|
|
59
|
+
else if ('x' in obj) {
|
|
60
|
+
this._set(obj.x || 0, obj.y || 0);
|
|
61
|
+
}
|
|
62
|
+
else if ('width' in obj) {
|
|
63
|
+
this._set(obj.width || 0, obj.height || 0);
|
|
64
|
+
}
|
|
65
|
+
else if ('angle' in obj) {
|
|
66
|
+
this._set(obj.length || 0, 0);
|
|
67
|
+
this.angle = obj.angle || 0;
|
|
68
|
+
}
|
|
69
|
+
else if ('angleInRadians' in obj) {
|
|
70
|
+
this._set(obj.length || 0, 0);
|
|
71
|
+
this.angleInRadians = obj.angleInRadians || 0;
|
|
72
|
+
}
|
|
73
|
+
else {
|
|
74
|
+
this._set(0, 0);
|
|
75
|
+
}
|
|
76
|
+
}
|
|
77
|
+
return this;
|
|
78
|
+
}
|
|
79
|
+
/**
|
|
80
|
+
* Internal helper function to directly set the underlying properties.
|
|
81
|
+
*
|
|
82
|
+
* Convention regarding {@link #set()} VS {@link #_set()}:
|
|
83
|
+
*
|
|
84
|
+
* - {@link #_set()} is for actually setting properties, e.g. on Point,
|
|
85
|
+
* Size, so that derived classes can reuse other parts (e.g. SegmentPoint)
|
|
86
|
+
* - {@link #set()} takes the same arguments as the constructor on all
|
|
87
|
+
* basic types, to offer the same amount of flexibility when setting
|
|
88
|
+
* values.
|
|
89
|
+
*/
|
|
90
|
+
_set(x, y) {
|
|
91
|
+
this.x = x;
|
|
92
|
+
this.y = y;
|
|
93
|
+
return this;
|
|
94
|
+
}
|
|
95
|
+
equals(point) {
|
|
96
|
+
return (this === point || (point && (this.x === point.x && this.y === point.y || (Array.isArray(point) &&
|
|
97
|
+
this.x === point[0] &&
|
|
98
|
+
this.y === point[1]))) ||
|
|
99
|
+
false);
|
|
100
|
+
}
|
|
101
|
+
/**
|
|
102
|
+
* Returns a copy of the point.
|
|
103
|
+
*
|
|
104
|
+
* @example
|
|
105
|
+
* var point1 = new Point();
|
|
106
|
+
* var point2 = point1;
|
|
107
|
+
* point2.x = 1; // also changes point1.x
|
|
108
|
+
*
|
|
109
|
+
* var point2 = point1.clone();
|
|
110
|
+
* point2.x = 1; // doesn't change point1.x
|
|
111
|
+
*
|
|
112
|
+
* @return the cloned point
|
|
113
|
+
*/
|
|
114
|
+
clone() {
|
|
115
|
+
return new Point(this.x, this.y);
|
|
116
|
+
}
|
|
117
|
+
/**
|
|
118
|
+
* @return a string representation of the point
|
|
119
|
+
*/
|
|
120
|
+
toString() {
|
|
121
|
+
const { instance } = Formatter;
|
|
122
|
+
return `{ x: ${instance.number(this.x)}, y: ${instance.number(this.y)} }`;
|
|
123
|
+
}
|
|
124
|
+
_serialize(options) {
|
|
125
|
+
const { formatter } = options;
|
|
126
|
+
// For speed reasons, we directly call formatter.number() here, instead
|
|
127
|
+
// of converting array through serialize() which makes a copy.
|
|
128
|
+
return [formatter.number(this.x), formatter.number(this.y)];
|
|
129
|
+
}
|
|
130
|
+
/**
|
|
131
|
+
* The point's coordinates as an array, `[x, y]`, as
|
|
132
|
+
* {@link Matrix#values} gives those of a matrix.
|
|
133
|
+
*/
|
|
134
|
+
get values() {
|
|
135
|
+
return [this.x, this.y];
|
|
136
|
+
}
|
|
137
|
+
/**
|
|
138
|
+
* The length of the vector that is represented by this point's coordinates.
|
|
139
|
+
* Each point can be interpreted as a vector that points from the origin (`x
|
|
140
|
+
* = 0`, `y = 0`) to the point's location. Setting the length changes the
|
|
141
|
+
* location but keeps the vector's angle.
|
|
142
|
+
*/
|
|
143
|
+
get length() {
|
|
144
|
+
return Math.sqrt(this.x * this.x + this.y * this.y);
|
|
145
|
+
}
|
|
146
|
+
set length(length) {
|
|
147
|
+
// Whenever chaining both x & y, use #_set() instead of direct
|
|
148
|
+
// assignment, so LinkedPoint does not report changes twice.
|
|
149
|
+
if (this.isZero()) {
|
|
150
|
+
const angle = this.#angle || 0;
|
|
151
|
+
this._set(Math.cos(angle) * length, Math.sin(angle) * length);
|
|
152
|
+
}
|
|
153
|
+
else {
|
|
154
|
+
const scale = length / this.length;
|
|
155
|
+
// Force calculation of angle now, so it will be preserved even when
|
|
156
|
+
// x and y are 0
|
|
157
|
+
if (isZero(scale)) {
|
|
158
|
+
this.angle;
|
|
159
|
+
}
|
|
160
|
+
this._set(this.x * scale, this.y * scale);
|
|
161
|
+
}
|
|
162
|
+
}
|
|
163
|
+
/**
|
|
164
|
+
* The vector's angle in degrees, measured from the x-axis to the vector.
|
|
165
|
+
*/
|
|
166
|
+
get angle() {
|
|
167
|
+
return this.angleInRadians * 180 / Math.PI;
|
|
168
|
+
}
|
|
169
|
+
set angle(angle) {
|
|
170
|
+
this.angleInRadians = angle * Math.PI / 180;
|
|
171
|
+
}
|
|
172
|
+
/**
|
|
173
|
+
* The vector's angle in radians, measured from the x-axis to the vector.
|
|
174
|
+
*/
|
|
175
|
+
get angleInRadians() {
|
|
176
|
+
// Return the preserved angle in case the vector has no length, and
|
|
177
|
+
// update the internal #angle in case the vector has a length, see the
|
|
178
|
+
// setter:
|
|
179
|
+
return this.isZero()
|
|
180
|
+
? this.#angle || 0
|
|
181
|
+
: (this.#angle = Math.atan2(this.y, this.x));
|
|
182
|
+
}
|
|
183
|
+
set angleInRadians(angle) {
|
|
184
|
+
// We store a reference to #angle internally so we still preserve it
|
|
185
|
+
// when the vector's length is set to zero, and then anything else.
|
|
186
|
+
// Note that we cannot rely on it if x and y are something else than 0,
|
|
187
|
+
// since updating x / y does not automatically change #angle!
|
|
188
|
+
this.#angle = angle;
|
|
189
|
+
if (!this.isZero()) {
|
|
190
|
+
const { length } = this;
|
|
191
|
+
// Use #_set() instead of direct assignment of x/y, so LinkedPoint
|
|
192
|
+
// does not report changes twice.
|
|
193
|
+
this._set(Math.cos(angle) * length, Math.sin(angle) * length);
|
|
194
|
+
}
|
|
195
|
+
}
|
|
196
|
+
/**
|
|
197
|
+
* Returns the smaller angle between two vectors. The angle is unsigned, no
|
|
198
|
+
* information about rotational direction is given.
|
|
199
|
+
*
|
|
200
|
+
* @param point
|
|
201
|
+
* @return the angle in degrees
|
|
202
|
+
*/
|
|
203
|
+
getAngle(point, y) {
|
|
204
|
+
return this.getAngleInRadians(point, y) * 180 / Math.PI;
|
|
205
|
+
}
|
|
206
|
+
/**
|
|
207
|
+
* Returns the smaller angle between two vectors in radians. The angle is
|
|
208
|
+
* unsigned, no information about rotational direction is given.
|
|
209
|
+
*
|
|
210
|
+
* @param point
|
|
211
|
+
* @return the angle in radians
|
|
212
|
+
*/
|
|
213
|
+
getAngleInRadians(point, y) {
|
|
214
|
+
const other = Point.from(point, y);
|
|
215
|
+
const div = this.length * other.length;
|
|
216
|
+
if (isZero(div)) {
|
|
217
|
+
return NaN;
|
|
218
|
+
}
|
|
219
|
+
else {
|
|
220
|
+
const a = this.dot(other) / div;
|
|
221
|
+
return Math.acos(a < -1 ? -1 : a > 1 ? 1 : a);
|
|
222
|
+
}
|
|
223
|
+
}
|
|
224
|
+
/**
|
|
225
|
+
* The quadrant of the {@link #angle} of the point.
|
|
226
|
+
*
|
|
227
|
+
* Angles between 0 and 90 degrees are in quadrant `1`. Angles between 90
|
|
228
|
+
* and 180 degrees are in quadrant `2`, angles between 180 and 270 degrees
|
|
229
|
+
* are in quadrant `3` and angles between 270 and 360 degrees are in
|
|
230
|
+
* quadrant `4`.
|
|
231
|
+
*
|
|
232
|
+
*
|
|
233
|
+
* @example
|
|
234
|
+
* var point = new Point({
|
|
235
|
+
* angle: 10,
|
|
236
|
+
* length: 20
|
|
237
|
+
* });
|
|
238
|
+
* console.log(point.quadrant); // 1
|
|
239
|
+
*
|
|
240
|
+
* point.angle = 100;
|
|
241
|
+
* console.log(point.quadrant); // 2
|
|
242
|
+
*
|
|
243
|
+
* point.angle = 190;
|
|
244
|
+
* console.log(point.quadrant); // 3
|
|
245
|
+
*
|
|
246
|
+
* point.angle = 280;
|
|
247
|
+
* console.log(point.quadrant); // 4
|
|
248
|
+
*/
|
|
249
|
+
get quadrant() {
|
|
250
|
+
return this.x >= 0 ? (this.y >= 0 ? 1 : 4) : this.y >= 0 ? 2 : 3;
|
|
251
|
+
}
|
|
252
|
+
/**
|
|
253
|
+
* Returns the angle between two vectors. The angle is directional and
|
|
254
|
+
* signed, giving information about the rotational direction.
|
|
255
|
+
*
|
|
256
|
+
* Read more about angle units and orientation in the description of the
|
|
257
|
+
* {@link #angle} property.
|
|
258
|
+
*
|
|
259
|
+
* @param point
|
|
260
|
+
* @return the angle between the two vectors
|
|
261
|
+
*/
|
|
262
|
+
getDirectedAngle(point, y) {
|
|
263
|
+
const other = Point.from(point, y);
|
|
264
|
+
return Math.atan2(this.cross(other), this.dot(other)) * 180 / Math.PI;
|
|
265
|
+
}
|
|
266
|
+
/**
|
|
267
|
+
* Returns the distance between the point and another point.
|
|
268
|
+
*
|
|
269
|
+
* @param point
|
|
270
|
+
* @param [squared=false] controls whether the distance should remain
|
|
271
|
+
* squared, or its square root should be calculated
|
|
272
|
+
*/
|
|
273
|
+
getDistance(point, squared) {
|
|
274
|
+
const other = Point.from(point);
|
|
275
|
+
const x = other.x - this.x;
|
|
276
|
+
const y = other.y - this.y;
|
|
277
|
+
const d = x * x + y * y;
|
|
278
|
+
return squared ? d : Math.sqrt(d);
|
|
279
|
+
}
|
|
280
|
+
/**
|
|
281
|
+
* Normalize modifies the {@link #length} of the vector to `1` without
|
|
282
|
+
* changing its angle and returns it as a new point. The optional `length`
|
|
283
|
+
* parameter defines the length to normalize to. The object itself is not
|
|
284
|
+
* modified!
|
|
285
|
+
*
|
|
286
|
+
* @param length The length of the normalized vector
|
|
287
|
+
* @return the normalized vector of the vector that is represented
|
|
288
|
+
* by this point's coordinates
|
|
289
|
+
*/
|
|
290
|
+
normalize(length = 1) {
|
|
291
|
+
const current = this.length;
|
|
292
|
+
const scale = current !== 0 ? length / current : 0;
|
|
293
|
+
const point = new Point(this.x * scale, this.y * scale);
|
|
294
|
+
// Preserve angle.
|
|
295
|
+
if (scale >= 0) {
|
|
296
|
+
point.#angle = this.#angle;
|
|
297
|
+
}
|
|
298
|
+
return point;
|
|
299
|
+
}
|
|
300
|
+
/**
|
|
301
|
+
* Rotates the point by the given angle around an optional center point.
|
|
302
|
+
* The object itself is not modified.
|
|
303
|
+
*
|
|
304
|
+
* Read more about angle units and orientation in the description of the
|
|
305
|
+
* {@link #angle} property.
|
|
306
|
+
*
|
|
307
|
+
* @param angle the rotation angle
|
|
308
|
+
* @param center the center point of the rotation
|
|
309
|
+
* @return the rotated point
|
|
310
|
+
*/
|
|
311
|
+
rotate(angle, center) {
|
|
312
|
+
if (angle === 0)
|
|
313
|
+
return this.clone();
|
|
314
|
+
angle = angle * Math.PI / 180;
|
|
315
|
+
let point = center ? this.subtract(center) : this;
|
|
316
|
+
const sin = Math.sin(angle);
|
|
317
|
+
const cos = Math.cos(angle);
|
|
318
|
+
point = new Point(point.x * cos - point.y * sin, point.x * sin + point.y * cos);
|
|
319
|
+
return center ? point.add(center) : point;
|
|
320
|
+
}
|
|
321
|
+
/**
|
|
322
|
+
* Transforms the point by the matrix as a new point. The object itself is
|
|
323
|
+
* not modified!
|
|
324
|
+
*
|
|
325
|
+
* @param matrix
|
|
326
|
+
* @return the transformed point
|
|
327
|
+
*/
|
|
328
|
+
transform(matrix) {
|
|
329
|
+
return matrix ? matrix._transformPoint(this) : this;
|
|
330
|
+
}
|
|
331
|
+
add(point, y) {
|
|
332
|
+
const other = Point.coerce(point, y);
|
|
333
|
+
return new Point(this.x + other.x, this.y + other.y);
|
|
334
|
+
}
|
|
335
|
+
subtract(point, y) {
|
|
336
|
+
const other = Point.coerce(point, y);
|
|
337
|
+
return new Point(this.x - other.x, this.y - other.y);
|
|
338
|
+
}
|
|
339
|
+
multiply(point, y) {
|
|
340
|
+
const other = Point.coerce(point, y);
|
|
341
|
+
return new Point(this.x * other.x, this.y * other.y);
|
|
342
|
+
}
|
|
343
|
+
divide(point, y) {
|
|
344
|
+
const other = Point.coerce(point, y);
|
|
345
|
+
return new Point(this.x / other.x, this.y / other.y);
|
|
346
|
+
}
|
|
347
|
+
modulo(point, y) {
|
|
348
|
+
const other = Point.coerce(point, y);
|
|
349
|
+
return new Point(this.x % other.x, this.y % other.y);
|
|
350
|
+
}
|
|
351
|
+
/**
|
|
352
|
+
* Returns a new point with both coordinates negated.
|
|
353
|
+
* PaperScript uses it for the unary minus operator.
|
|
354
|
+
* The object itself is not modified!
|
|
355
|
+
*
|
|
356
|
+
* @return the negation of the point as a new point
|
|
357
|
+
*
|
|
358
|
+
* @example
|
|
359
|
+
* var point = new Point(12, -6);
|
|
360
|
+
* var result = -point; // PaperScript
|
|
361
|
+
* var result = point.negate(); // JavaScript
|
|
362
|
+
* console.log(result); // {x: -12, y: 6}
|
|
363
|
+
*/
|
|
364
|
+
negate() {
|
|
365
|
+
return new Point(-this.x, -this.y);
|
|
366
|
+
}
|
|
367
|
+
/**
|
|
368
|
+
* {@grouptitle Tests}
|
|
369
|
+
*
|
|
370
|
+
* Checks whether the point is inside the boundaries of the rectangle.
|
|
371
|
+
*
|
|
372
|
+
* @param rect the rectangle to check against
|
|
373
|
+
* @return {@true if the point is inside the rectangle}
|
|
374
|
+
*/
|
|
375
|
+
isInside(rect) {
|
|
376
|
+
return Rectangle.from(rect).contains(this);
|
|
377
|
+
}
|
|
378
|
+
/**
|
|
379
|
+
* Checks if the point is within a given distance of another point.
|
|
380
|
+
*
|
|
381
|
+
* @param point the point to check against
|
|
382
|
+
* @param tolerance the maximum distance allowed
|
|
383
|
+
* @return {@true if it is within the given distance}
|
|
384
|
+
*/
|
|
385
|
+
isClose(point, tolerance) {
|
|
386
|
+
return this.getDistance(point) <= tolerance;
|
|
387
|
+
}
|
|
388
|
+
/**
|
|
389
|
+
* Checks if the vector represented by this point is collinear (parallel) to
|
|
390
|
+
* another vector, within a tolerance of 1e-8 for the sine of the angle
|
|
391
|
+
* between them.
|
|
392
|
+
*
|
|
393
|
+
* @param point the vector to check against
|
|
394
|
+
* @return {@true if it is collinear}
|
|
395
|
+
*/
|
|
396
|
+
isCollinear(point, y) {
|
|
397
|
+
const other = Point.from(point, y);
|
|
398
|
+
return Point.isCollinear(this.x, this.y, other.x, other.y);
|
|
399
|
+
}
|
|
400
|
+
/**
|
|
401
|
+
* Checks if the vector represented by this point is orthogonal
|
|
402
|
+
* (perpendicular) to another vector, within a tolerance of 1e-8 for the
|
|
403
|
+
* cosine of the angle between them.
|
|
404
|
+
*
|
|
405
|
+
* @param point the vector to check against
|
|
406
|
+
* @return {@true if it is orthogonal}
|
|
407
|
+
*/
|
|
408
|
+
isOrthogonal(point, y) {
|
|
409
|
+
const other = Point.from(point, y);
|
|
410
|
+
return Point.isOrthogonal(this.x, this.y, other.x, other.y);
|
|
411
|
+
}
|
|
412
|
+
/**
|
|
413
|
+
* Checks if this point has both the x and y coordinate set to 0, within
|
|
414
|
+
* a tolerance of 1e-12, unlike {@link #equals(point)}, which compares
|
|
415
|
+
* exactly.
|
|
416
|
+
*
|
|
417
|
+
* @return {@true if both x and y are 0, within the tolerance}
|
|
418
|
+
*/
|
|
419
|
+
isZero() {
|
|
420
|
+
return isZero(this.x) && isZero(this.y);
|
|
421
|
+
}
|
|
422
|
+
/**
|
|
423
|
+
* Checks if this point has an undefined value for at least one of its
|
|
424
|
+
* coordinates.
|
|
425
|
+
*
|
|
426
|
+
* @return {@true if either x or y are not a number}
|
|
427
|
+
*/
|
|
428
|
+
isNaN() {
|
|
429
|
+
return isNaN(this.x) || isNaN(this.y);
|
|
430
|
+
}
|
|
431
|
+
/**
|
|
432
|
+
* Checks if the vector is within the specified quadrant. Note that if the
|
|
433
|
+
* vector lies on the boundary between two quadrants, `true` will be
|
|
434
|
+
* returned for both quadrants.
|
|
435
|
+
*
|
|
436
|
+
* @param quadrant the quadrant to check against
|
|
437
|
+
* @return {@true if the vector is within the quadrant}
|
|
438
|
+
* @see #quadrant
|
|
439
|
+
*/
|
|
440
|
+
isInQuadrant(quadrant) {
|
|
441
|
+
// Map quadrant to x & y coordinate pairs and multiply with coordinates,
|
|
442
|
+
// then check sign:
|
|
443
|
+
// 1: [ 1, 1]
|
|
444
|
+
// 2: [-1, 1]
|
|
445
|
+
// 3: [-1, -1]
|
|
446
|
+
// 4: [ 1, -1]
|
|
447
|
+
return (this.x * (quadrant > 1 && quadrant < 4 ? -1 : 1) >= 0 &&
|
|
448
|
+
this.y * (quadrant > 2 ? -1 : 1) >= 0);
|
|
449
|
+
}
|
|
450
|
+
/**
|
|
451
|
+
* {@grouptitle Vector Math Functions}
|
|
452
|
+
* Returns the dot product of the point and another point.
|
|
453
|
+
*
|
|
454
|
+
* @param point
|
|
455
|
+
* @return the dot product of the two points
|
|
456
|
+
*/
|
|
457
|
+
dot(point, y) {
|
|
458
|
+
const other = Point.from(point, y);
|
|
459
|
+
return this.x * other.x + this.y * other.y;
|
|
460
|
+
}
|
|
461
|
+
/**
|
|
462
|
+
* Returns the cross product of the point and another point.
|
|
463
|
+
*
|
|
464
|
+
* @param point
|
|
465
|
+
* @return the cross product of the two points
|
|
466
|
+
*/
|
|
467
|
+
cross(point, y) {
|
|
468
|
+
const other = Point.from(point, y);
|
|
469
|
+
return this.x * other.y - this.y * other.x;
|
|
470
|
+
}
|
|
471
|
+
/**
|
|
472
|
+
* Returns the projection of the point onto another point.
|
|
473
|
+
* Both points are interpreted as vectors.
|
|
474
|
+
*
|
|
475
|
+
* @param point
|
|
476
|
+
* @return the projection of the point onto another point
|
|
477
|
+
*/
|
|
478
|
+
project(point, y) {
|
|
479
|
+
const other = Point.from(point, y);
|
|
480
|
+
const scale = other.isZero() ? 0 : this.dot(other) / other.dot(other);
|
|
481
|
+
return new Point(other.x * scale, other.y * scale);
|
|
482
|
+
}
|
|
483
|
+
/**
|
|
484
|
+
* Returns a new point with the {@link #x} and {@link #y} values clamped to
|
|
485
|
+
* the range between the given minimum and maximum points. The object
|
|
486
|
+
* itself is not modified!
|
|
487
|
+
*
|
|
488
|
+
* @param min the point with the smallest values
|
|
489
|
+
* @param max the point with the largest values
|
|
490
|
+
* @return the clamped point as a new point
|
|
491
|
+
*
|
|
492
|
+
* @example
|
|
493
|
+
* var point = new Point(-5, 150);
|
|
494
|
+
* var clampPoint = point.clamp(new Point(0, 0), new Point(100, 100));
|
|
495
|
+
* console.log(clampPoint); // {x: 0, y: 100}
|
|
496
|
+
*
|
|
497
|
+
* @example
|
|
498
|
+
* // Keep a point inside a rectangle:
|
|
499
|
+
* var rect = new Rectangle(10, 20, 100, 50);
|
|
500
|
+
* var point = new Point(200, 40);
|
|
501
|
+
* var clampPoint = point.clamp(rect.topLeft, rect.bottomRight);
|
|
502
|
+
* console.log(clampPoint); // {x: 110, y: 40}
|
|
503
|
+
*/
|
|
504
|
+
clamp(min, max) {
|
|
505
|
+
const { x: minX, y: minY } = Point.from(min);
|
|
506
|
+
const { x: maxX, y: maxY } = Point.from(max);
|
|
507
|
+
return new Point(clamp(this.x, minX, maxX), clamp(this.y, minY, maxY));
|
|
508
|
+
}
|
|
509
|
+
/**
|
|
510
|
+
* Returns the passed point if it is one already, or else a new point
|
|
511
|
+
* created from the passed values, as {@link Point()} reads them. A number
|
|
512
|
+
* makes a point only together with its y-coordinate.
|
|
513
|
+
*
|
|
514
|
+
* @param point
|
|
515
|
+
* @param y
|
|
516
|
+
*/
|
|
517
|
+
static from(point, y) {
|
|
518
|
+
if (point instanceof Point) {
|
|
519
|
+
return point;
|
|
520
|
+
}
|
|
521
|
+
else if (typeof point === 'number' && typeof y !== 'number') {
|
|
522
|
+
throw new TypeError(`Invalid point: ${point}. Pass [x, y].`);
|
|
523
|
+
}
|
|
524
|
+
else {
|
|
525
|
+
return new Point(point, y);
|
|
526
|
+
}
|
|
527
|
+
}
|
|
528
|
+
/**
|
|
529
|
+
* Returns the passed point if it is one already, or else a new point
|
|
530
|
+
* created from the passed values, where a single number stands for both
|
|
531
|
+
* coordinates, as in `point.multiply(2)`, translations and scale factors.
|
|
532
|
+
*
|
|
533
|
+
* @param point
|
|
534
|
+
* @param y
|
|
535
|
+
*/
|
|
536
|
+
static coerce(point, y) {
|
|
537
|
+
return typeof point === 'number' && y === undefined
|
|
538
|
+
? new Point(point, point)
|
|
539
|
+
: Point.from(point, y);
|
|
540
|
+
}
|
|
541
|
+
/**
|
|
542
|
+
* Returns a new point object with the smallest {@link #x} and
|
|
543
|
+
* {@link #y} of the supplied points.
|
|
544
|
+
*
|
|
545
|
+
* @param point1
|
|
546
|
+
* @param point2
|
|
547
|
+
* @return the newly created point object
|
|
548
|
+
*
|
|
549
|
+
* @example
|
|
550
|
+
* var point1 = new Point(10, 100);
|
|
551
|
+
* var point2 = new Point(200, 5);
|
|
552
|
+
* var minPoint = Point.min(point1, point2);
|
|
553
|
+
* console.log(minPoint); // {x: 10, y: 5}
|
|
554
|
+
*
|
|
555
|
+
* @example
|
|
556
|
+
* // Find the minimum of multiple points:
|
|
557
|
+
* var point1 = new Point(60, 100);
|
|
558
|
+
* var point2 = new Point(200, 5);
|
|
559
|
+
* var point3 = new Point(250, 35);
|
|
560
|
+
* [point1, point2, point3].reduce(Point.min) // {x: 60, y: 5}
|
|
561
|
+
*/
|
|
562
|
+
static min(point1, point2) {
|
|
563
|
+
const first = Point.from(point1);
|
|
564
|
+
const second = Point.from(point2);
|
|
565
|
+
return new Point(Math.min(first.x, second.x), Math.min(first.y, second.y));
|
|
566
|
+
}
|
|
567
|
+
/**
|
|
568
|
+
* Returns a new point object with the largest {@link #x} and
|
|
569
|
+
* {@link #y} of the supplied points.
|
|
570
|
+
*
|
|
571
|
+
* @param point1
|
|
572
|
+
* @param point2
|
|
573
|
+
* @return the newly created point object
|
|
574
|
+
*
|
|
575
|
+
* @example
|
|
576
|
+
* var point1 = new Point(10, 100);
|
|
577
|
+
* var point2 = new Point(200, 5);
|
|
578
|
+
* var maxPoint = Point.max(point1, point2);
|
|
579
|
+
* console.log(maxPoint); // {x: 200, y: 100}
|
|
580
|
+
*
|
|
581
|
+
* @example
|
|
582
|
+
* // Find the maximum of multiple points:
|
|
583
|
+
* var point1 = new Point(60, 100);
|
|
584
|
+
* var point2 = new Point(200, 5);
|
|
585
|
+
* var point3 = new Point(250, 35);
|
|
586
|
+
* [point1, point2, point3].reduce(Point.max) // {x: 250, y: 100}
|
|
587
|
+
*/
|
|
588
|
+
static max(point1, point2) {
|
|
589
|
+
const first = Point.from(point1);
|
|
590
|
+
const second = Point.from(point2);
|
|
591
|
+
return new Point(Math.max(first.x, second.x), Math.max(first.y, second.y));
|
|
592
|
+
}
|
|
593
|
+
/**
|
|
594
|
+
* Returns a point object with random {@link #x} and {@link #y} values
|
|
595
|
+
* between `0` and `1`.
|
|
596
|
+
*
|
|
597
|
+
* @return the newly created point object
|
|
598
|
+
*
|
|
599
|
+
* @example
|
|
600
|
+
* var maxPoint = new Point(100, 100);
|
|
601
|
+
* var randomPoint = Point.random();
|
|
602
|
+
*
|
|
603
|
+
* // A point between {x:0, y:0} and {x:100, y:100}:
|
|
604
|
+
* var point = maxPoint * randomPoint;
|
|
605
|
+
*/
|
|
606
|
+
static random() {
|
|
607
|
+
return new Point(Math.random(), Math.random());
|
|
608
|
+
}
|
|
609
|
+
static isCollinear(x1, y1, x2, y2) {
|
|
610
|
+
// NOTE: We use normalized vectors so that the epsilon comparison is
|
|
611
|
+
// reliable. We could instead scale the epsilon based on the vector
|
|
612
|
+
// length. But instead of normalizing the vectors before calculating
|
|
613
|
+
// the cross product, we can scale the epsilon accordingly.
|
|
614
|
+
return (Math.abs(x1 * y2 - y1 * x2) <=
|
|
615
|
+
Math.sqrt((x1 * x1 + y1 * y1) * (x2 * x2 + y2 * y2)) *
|
|
616
|
+
TRIGONOMETRIC_EPSILON);
|
|
617
|
+
}
|
|
618
|
+
static isOrthogonal(x1, y1, x2, y2) {
|
|
619
|
+
// See Point.isCollinear()
|
|
620
|
+
return (Math.abs(x1 * x2 + y1 * y2) <=
|
|
621
|
+
Math.sqrt((x1 * x1 + y1 * y1) * (x2 * x2 + y2 * y2)) *
|
|
622
|
+
TRIGONOMETRIC_EPSILON);
|
|
623
|
+
}
|
|
624
|
+
/**
|
|
625
|
+
* {@grouptitle Math Functions}
|
|
626
|
+
*
|
|
627
|
+
* Returns a new point with rounded {@link #x} and {@link #y} values. The
|
|
628
|
+
* object itself is not modified!
|
|
629
|
+
*
|
|
630
|
+
*
|
|
631
|
+
* @example
|
|
632
|
+
* var point = new Point(10.2, 10.9);
|
|
633
|
+
* var roundPoint = point.round();
|
|
634
|
+
* console.log(roundPoint); // {x: 10, y: 11}
|
|
635
|
+
*/
|
|
636
|
+
round() {
|
|
637
|
+
return new Point(Math.round(this.x), Math.round(this.y));
|
|
638
|
+
}
|
|
639
|
+
/**
|
|
640
|
+
* Returns a new point with the nearest greater non-fractional values to the
|
|
641
|
+
* specified {@link #x} and {@link #y} values. The object itself is not
|
|
642
|
+
* modified!
|
|
643
|
+
*
|
|
644
|
+
*
|
|
645
|
+
* @example
|
|
646
|
+
* var point = new Point(10.2, 10.9);
|
|
647
|
+
* var ceilPoint = point.ceil();
|
|
648
|
+
* console.log(ceilPoint); // {x: 11, y: 11}
|
|
649
|
+
*/
|
|
650
|
+
ceil() {
|
|
651
|
+
return new Point(Math.ceil(this.x), Math.ceil(this.y));
|
|
652
|
+
}
|
|
653
|
+
/**
|
|
654
|
+
* Returns a new point with the nearest smaller non-fractional values to the
|
|
655
|
+
* specified {@link #x} and {@link #y} values. The object itself is not
|
|
656
|
+
* modified!
|
|
657
|
+
*
|
|
658
|
+
*
|
|
659
|
+
* @example
|
|
660
|
+
* var point = new Point(10.2, 10.9);
|
|
661
|
+
* var floorPoint = point.floor();
|
|
662
|
+
* console.log(floorPoint); // {x: 10, y: 10}
|
|
663
|
+
*/
|
|
664
|
+
floor() {
|
|
665
|
+
return new Point(Math.floor(this.x), Math.floor(this.y));
|
|
666
|
+
}
|
|
667
|
+
/**
|
|
668
|
+
* Returns a new point with the absolute values of the specified {@link #x}
|
|
669
|
+
* and {@link #y} values. The object itself is not modified!
|
|
670
|
+
*
|
|
671
|
+
*
|
|
672
|
+
* @example
|
|
673
|
+
* var point = new Point(-5, 10);
|
|
674
|
+
* var absPoint = point.abs();
|
|
675
|
+
* console.log(absPoint); // {x: 5, y: 10}
|
|
676
|
+
*/
|
|
677
|
+
abs() {
|
|
678
|
+
return new Point(Math.abs(this.x), Math.abs(this.y));
|
|
679
|
+
}
|
|
680
|
+
static {
|
|
681
|
+
registerClasses({ Point: this });
|
|
682
|
+
}
|
|
683
|
+
}
|
|
684
|
+
/**
|
|
685
|
+
* An internal version of Point that notifies its owner of each change
|
|
686
|
+
* through setting itself again on the property that produced it.
|
|
687
|
+
*
|
|
688
|
+
* @private
|
|
689
|
+
* @internal
|
|
690
|
+
*/
|
|
691
|
+
export class LinkedPoint extends Point {
|
|
692
|
+
#x;
|
|
693
|
+
#y;
|
|
694
|
+
#owner;
|
|
695
|
+
#key;
|
|
696
|
+
constructor(x, y, owner, key) {
|
|
697
|
+
super();
|
|
698
|
+
this.#x = x;
|
|
699
|
+
this.#y = y;
|
|
700
|
+
this.#owner = owner;
|
|
701
|
+
this.#key = key;
|
|
702
|
+
}
|
|
703
|
+
// See Point#_set() for an explanation of _set():
|
|
704
|
+
_set(x, y) {
|
|
705
|
+
// Point's constructor calls this before the private fields exist:
|
|
706
|
+
if (#x in this) {
|
|
707
|
+
this.#x = x;
|
|
708
|
+
this.#y = y;
|
|
709
|
+
this.#owner[this.#key] = this;
|
|
710
|
+
}
|
|
711
|
+
return this;
|
|
712
|
+
}
|
|
713
|
+
// @ts-expect-error: Point declares x as a field, LinkedPoint reads #x
|
|
714
|
+
get x() {
|
|
715
|
+
return this.#x;
|
|
716
|
+
}
|
|
717
|
+
set x(x) {
|
|
718
|
+
this.#x = x;
|
|
719
|
+
this.#owner[this.#key] = this;
|
|
720
|
+
}
|
|
721
|
+
// @ts-expect-error: See x
|
|
722
|
+
get y() {
|
|
723
|
+
return this.#y;
|
|
724
|
+
}
|
|
725
|
+
set y(y) {
|
|
726
|
+
this.#y = y;
|
|
727
|
+
this.#owner[this.#key] = this;
|
|
728
|
+
}
|
|
729
|
+
get selected() {
|
|
730
|
+
return !!(this.#owner._selection & this.#getSelection());
|
|
731
|
+
}
|
|
732
|
+
set selected(selected) {
|
|
733
|
+
this.#owner._changeSelection(this.#getSelection(), selected);
|
|
734
|
+
}
|
|
735
|
+
#getSelection() {
|
|
736
|
+
return this.#key === 'position' ? ItemSelection.POSITION : 0;
|
|
737
|
+
}
|
|
738
|
+
}
|