paper 0.16.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 +294 -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 +33083 -22681
- package/dist/paper-full.min.js +36 -31
- package/dist/paper-hosted.js +33898 -23223
- 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 +90 -58
- 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 -23759
- package/dist/docs/classes/AreaText.html +0 -8708
- package/dist/docs/classes/ChangeFlag.html +0 -385
- package/dist/docs/classes/Color.html +0 -2205
- package/dist/docs/classes/CompoundPath.html +0 -9168
- package/dist/docs/classes/Curve.html +0 -2326
- package/dist/docs/classes/CurveLocation.html +0 -673
- 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 -7139
- package/dist/docs/classes/HitResult.html +0 -241
- package/dist/docs/classes/HostItem.html +0 -6836
- package/dist/docs/classes/Item.html +0 -6892
- package/dist/docs/classes/Key.html +0 -140
- package/dist/docs/classes/KeyEvent.html +0 -309
- package/dist/docs/classes/Layer.html +0 -7122
- 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 -202
- package/dist/docs/classes/Path.html +0 -12064
- package/dist/docs/classes/PathItem.html +0 -8930
- package/dist/docs/classes/PathText.html +0 -8578
- package/dist/docs/classes/Point.html +0 -2860
- package/dist/docs/classes/PointText.html +0 -8489
- package/dist/docs/classes/Project.html +0 -1604
- package/dist/docs/classes/Raster.html +0 -8069
- package/dist/docs/classes/Rectangle.html +0 -1698
- package/dist/docs/classes/Segment.html +0 -1017
- package/dist/docs/classes/Shape.html +0 -7570
- package/dist/docs/classes/Size.html +0 -1915
- package/dist/docs/classes/Style.html +0 -1765
- package/dist/docs/classes/SymbolDefinition.html +0 -312
- package/dist/docs/classes/SymbolItem.html +0 -6999
- package/dist/docs/classes/TextItem.html +0 -8332
- 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/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 -21834
- package/dist/paper-core.min.js +0 -32
- package/dist/paper.d.ts +0 -9630
- 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/MetaBalls.html +0 -132
- package/examples/Paperjs.org/NyanRainbow.html +0 -202
- 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/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/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,996 @@
|
|
|
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 { Base, CURVETIME_EPSILON, CurveLocation, GEOMETRIC_EPSILON, Line, Path, Point, Rectangle, Segment, TRIGONOMETRIC_EPSILON, classifyCurve, findCurveBoundsCollisions, getCurvature, getCurveArea, getCurveIntersections, getCurveLength, getCurveNormal, getCurvePart, getCurvePeaks, getCurvePoint, getCurveSelfIntersection, getCurveTangent, getCurveTimeAt, getCurveTimeOf, getCurveTimesWithTangent, getNearestCurveTime, getSegmentBounds, getSegmentStrokeBounds, getWeightedCurveNormal, getWeightedCurveTangent, hasLinearHandles, hasStraightHandles, registerClasses, serialize, subdivideCurve } from "../internal.js";
|
|
13
|
+
/**
|
|
14
|
+
* The Curve object represents the parts of a path that are connected by
|
|
15
|
+
* two following {@link Segment} objects. The curves of a path can be accessed
|
|
16
|
+
* through its {@link Path#curves} array.
|
|
17
|
+
*
|
|
18
|
+
* While a segment describe the anchor point and its incoming and outgoing
|
|
19
|
+
* handles, a Curve object describes the curve passing between two such
|
|
20
|
+
* segments. Curves and segments represent two different ways of looking at the
|
|
21
|
+
* same thing, but focusing on different aspects. Curves for example offer many
|
|
22
|
+
* convenient ways to work with parts of the path, finding lengths, positions or
|
|
23
|
+
* tangents at given offsets.
|
|
24
|
+
*/
|
|
25
|
+
export class Curve extends Base {
|
|
26
|
+
_path = null;
|
|
27
|
+
_segment1;
|
|
28
|
+
_segment2;
|
|
29
|
+
#length;
|
|
30
|
+
#bounds;
|
|
31
|
+
constructor(arg0, arg1, arg2, arg3) {
|
|
32
|
+
super();
|
|
33
|
+
const count = arguments.length;
|
|
34
|
+
let segment1;
|
|
35
|
+
let segment2;
|
|
36
|
+
let point1;
|
|
37
|
+
let point2;
|
|
38
|
+
let handle1;
|
|
39
|
+
let handle2;
|
|
40
|
+
// The following code has to either set segment1 & segment2,
|
|
41
|
+
// or point1, point2, handle1 & handle2. At the end, the internal
|
|
42
|
+
// segments are created accordingly.
|
|
43
|
+
if (count === 3) {
|
|
44
|
+
// Undocumented internal constructor, used by Path#curves
|
|
45
|
+
// new Curve(path, segment1, segment2);
|
|
46
|
+
this._path = arg0;
|
|
47
|
+
segment1 = arg1;
|
|
48
|
+
segment2 = arg2;
|
|
49
|
+
}
|
|
50
|
+
else if (!count) {
|
|
51
|
+
segment1 = new Segment();
|
|
52
|
+
segment2 = new Segment();
|
|
53
|
+
}
|
|
54
|
+
else if (count === 1) {
|
|
55
|
+
// new Curve(object);
|
|
56
|
+
// NOTE: This copies from existing segments through their accessors
|
|
57
|
+
if ('segment1' in arg0) {
|
|
58
|
+
segment1 = new Segment(arg0.segment1);
|
|
59
|
+
segment2 = new Segment(arg0.segment2);
|
|
60
|
+
}
|
|
61
|
+
else if ('point1' in arg0) {
|
|
62
|
+
// As printed by #toString()
|
|
63
|
+
point1 = arg0.point1;
|
|
64
|
+
handle1 = arg0.handle1;
|
|
65
|
+
handle2 = arg0.handle2;
|
|
66
|
+
point2 = arg0.point2;
|
|
67
|
+
}
|
|
68
|
+
else if (Array.isArray(arg0)) {
|
|
69
|
+
// Convert the #values array back to points and handles so we
|
|
70
|
+
// can create segments for those.
|
|
71
|
+
point1 = [arg0[0], arg0[1]];
|
|
72
|
+
point2 = [arg0[6], arg0[7]];
|
|
73
|
+
handle1 = [arg0[2] - arg0[0], arg0[3] - arg0[1]];
|
|
74
|
+
handle2 = [arg0[4] - arg0[6], arg0[5] - arg0[7]];
|
|
75
|
+
}
|
|
76
|
+
}
|
|
77
|
+
else if (count === 2) {
|
|
78
|
+
// new Curve(segment1, segment2);
|
|
79
|
+
segment1 = new Segment(arg0);
|
|
80
|
+
segment2 = new Segment(arg1);
|
|
81
|
+
}
|
|
82
|
+
else if (count === 4) {
|
|
83
|
+
point1 = arg0;
|
|
84
|
+
handle1 = arg1;
|
|
85
|
+
handle2 = arg2;
|
|
86
|
+
point2 = arg3;
|
|
87
|
+
}
|
|
88
|
+
this._segment1 = segment1 ?? new Segment(point1, null, handle1);
|
|
89
|
+
this._segment2 = segment2 ?? new Segment(point2, handle2, null);
|
|
90
|
+
}
|
|
91
|
+
_serialize(options, dictionary) {
|
|
92
|
+
// If it has no handles, only serialize points, otherwise handles too.
|
|
93
|
+
return serialize(this.hasHandles()
|
|
94
|
+
? [this.point1, this.handle1, this.handle2, this.point2]
|
|
95
|
+
: [this.point1, this.point2], options, true, dictionary);
|
|
96
|
+
}
|
|
97
|
+
_changed() {
|
|
98
|
+
// Clear cached values.
|
|
99
|
+
this.#length = this.#bounds = undefined;
|
|
100
|
+
}
|
|
101
|
+
/**
|
|
102
|
+
* Returns a copy of the curve.
|
|
103
|
+
*/
|
|
104
|
+
clone() {
|
|
105
|
+
return new Curve(this._segment1, this._segment2);
|
|
106
|
+
}
|
|
107
|
+
/**
|
|
108
|
+
* Returns a string representation of the curve.
|
|
109
|
+
*
|
|
110
|
+
* @return a string representation of the curve
|
|
111
|
+
*/
|
|
112
|
+
toString() {
|
|
113
|
+
const parts = [`point1: ${this._segment1._point}`];
|
|
114
|
+
if (!this._segment1._handleOut.isZero()) {
|
|
115
|
+
parts.push(`handle1: ${this._segment1._handleOut}`);
|
|
116
|
+
}
|
|
117
|
+
if (!this._segment2._handleIn.isZero()) {
|
|
118
|
+
parts.push(`handle2: ${this._segment2._handleIn}`);
|
|
119
|
+
}
|
|
120
|
+
parts.push(`point2: ${this._segment2._point}`);
|
|
121
|
+
return `{ ${parts.join(', ')} }`;
|
|
122
|
+
}
|
|
123
|
+
/**
|
|
124
|
+
* Determines the type of cubic Bézier curve via discriminant
|
|
125
|
+
* classification, as well as the curve-time parameters of the associated
|
|
126
|
+
* points of inflection, loops, cusps, etc.
|
|
127
|
+
*
|
|
128
|
+
* @return the curve classification information as an object, see
|
|
129
|
+
* options
|
|
130
|
+
* @result info.type {String} the type of Bézier curve, possible values are:
|
|
131
|
+
* {@values 'line', 'quadratic', 'serpentine', 'cusp', 'loop', 'arch'}
|
|
132
|
+
* @result info.roots {Number[]} the curve-time parameters of the
|
|
133
|
+
* associated points of inflection for serpentine curves, loops, cusps,
|
|
134
|
+
etc
|
|
135
|
+
*/
|
|
136
|
+
classify() {
|
|
137
|
+
return classifyCurve(this.values);
|
|
138
|
+
}
|
|
139
|
+
/**
|
|
140
|
+
* Removes the curve from the path that it belongs to, by removing its
|
|
141
|
+
* second segment and merging its handle with the first segment.
|
|
142
|
+
* @return {@true if the curve was removed}
|
|
143
|
+
*/
|
|
144
|
+
remove() {
|
|
145
|
+
let removed = false;
|
|
146
|
+
if (this._path) {
|
|
147
|
+
const segment2 = this._segment2;
|
|
148
|
+
const handleOut = segment2._handleOut;
|
|
149
|
+
removed = segment2.remove();
|
|
150
|
+
if (removed) {
|
|
151
|
+
this._segment1._handleOut.set(handleOut);
|
|
152
|
+
}
|
|
153
|
+
}
|
|
154
|
+
return removed;
|
|
155
|
+
}
|
|
156
|
+
/**
|
|
157
|
+
* The first anchor point of the curve.
|
|
158
|
+
*/
|
|
159
|
+
get point1() {
|
|
160
|
+
return this._segment1._point;
|
|
161
|
+
}
|
|
162
|
+
set point1(point) {
|
|
163
|
+
this._segment1._point.set(point);
|
|
164
|
+
}
|
|
165
|
+
/**
|
|
166
|
+
* The second anchor point of the curve.
|
|
167
|
+
*/
|
|
168
|
+
get point2() {
|
|
169
|
+
return this._segment2._point;
|
|
170
|
+
}
|
|
171
|
+
set point2(point) {
|
|
172
|
+
this._segment2._point.set(point);
|
|
173
|
+
}
|
|
174
|
+
/**
|
|
175
|
+
* The handle point that describes the tangent in the first anchor point.
|
|
176
|
+
*/
|
|
177
|
+
get handle1() {
|
|
178
|
+
return this._segment1._handleOut;
|
|
179
|
+
}
|
|
180
|
+
set handle1(point) {
|
|
181
|
+
this._segment1._handleOut.set(point);
|
|
182
|
+
}
|
|
183
|
+
/**
|
|
184
|
+
* The handle point that describes the tangent in the second anchor point.
|
|
185
|
+
*/
|
|
186
|
+
get handle2() {
|
|
187
|
+
return this._segment2._handleIn;
|
|
188
|
+
}
|
|
189
|
+
set handle2(point) {
|
|
190
|
+
this._segment2._handleIn.set(point);
|
|
191
|
+
}
|
|
192
|
+
/**
|
|
193
|
+
* The first segment of the curve.
|
|
194
|
+
*/
|
|
195
|
+
get segment1() {
|
|
196
|
+
return this._segment1;
|
|
197
|
+
}
|
|
198
|
+
/**
|
|
199
|
+
* The second segment of the curve.
|
|
200
|
+
*/
|
|
201
|
+
get segment2() {
|
|
202
|
+
return this._segment2;
|
|
203
|
+
}
|
|
204
|
+
/**
|
|
205
|
+
* The path that the curve belongs to.
|
|
206
|
+
*/
|
|
207
|
+
get path() {
|
|
208
|
+
return this._path;
|
|
209
|
+
}
|
|
210
|
+
/**
|
|
211
|
+
* The index of the curve in the {@link Path#curves} array.
|
|
212
|
+
*/
|
|
213
|
+
get index() {
|
|
214
|
+
return this._segment1._index;
|
|
215
|
+
}
|
|
216
|
+
/**
|
|
217
|
+
* The next curve in the {@link Path#curves} array that the curve
|
|
218
|
+
* belongs to.
|
|
219
|
+
*/
|
|
220
|
+
get next() {
|
|
221
|
+
const path = this._path;
|
|
222
|
+
const curves = path?._curves;
|
|
223
|
+
return (curves && (curves[this._segment1._index + 1] ||
|
|
224
|
+
path._closed && curves[0]) ||
|
|
225
|
+
null);
|
|
226
|
+
}
|
|
227
|
+
/**
|
|
228
|
+
* The previous curve in the {@link Path#curves} array that the curve
|
|
229
|
+
* belongs to.
|
|
230
|
+
*/
|
|
231
|
+
get previous() {
|
|
232
|
+
const path = this._path;
|
|
233
|
+
const curves = path?._curves;
|
|
234
|
+
return (curves && (curves[this._segment1._index - 1] ||
|
|
235
|
+
path._closed && curves.at(-1)) ||
|
|
236
|
+
null);
|
|
237
|
+
}
|
|
238
|
+
/**
|
|
239
|
+
* Checks if this is the first curve in the {@link Path#curves} array.
|
|
240
|
+
*
|
|
241
|
+
* @return {@true if this is the first curve}
|
|
242
|
+
*/
|
|
243
|
+
isFirst() {
|
|
244
|
+
return !this._segment1._index;
|
|
245
|
+
}
|
|
246
|
+
/**
|
|
247
|
+
* Checks if this is the last curve in the {@link Path#curves} array.
|
|
248
|
+
*
|
|
249
|
+
* @return {@true if this is the last curve}
|
|
250
|
+
*/
|
|
251
|
+
isLast() {
|
|
252
|
+
const path = this._path;
|
|
253
|
+
return (path && this._segment1._index === path._curves.length - 1 ||
|
|
254
|
+
false);
|
|
255
|
+
}
|
|
256
|
+
/**
|
|
257
|
+
* Specifies whether the points and handles of the curve are selected.
|
|
258
|
+
*/
|
|
259
|
+
get selected() {
|
|
260
|
+
return (this.point1.selected &&
|
|
261
|
+
this.handle1.selected &&
|
|
262
|
+
this.handle2.selected &&
|
|
263
|
+
this.point2.selected);
|
|
264
|
+
}
|
|
265
|
+
set selected(selected) {
|
|
266
|
+
this.point1.selected = selected;
|
|
267
|
+
this.handle1.selected = selected;
|
|
268
|
+
this.handle2.selected = selected;
|
|
269
|
+
this.point2.selected = selected;
|
|
270
|
+
}
|
|
271
|
+
/**
|
|
272
|
+
* An array of 8 float values, describing this curve's geometry in four
|
|
273
|
+
* absolute x/y pairs (point1, handle1, handle2, point2), as a new array on
|
|
274
|
+
* each read. This format is used internally for efficient processing of
|
|
275
|
+
* curve geometries, e.g. when calculating intersections or bounds.
|
|
276
|
+
*
|
|
277
|
+
* Note that the handles are converted to absolute coordinates.
|
|
278
|
+
*/
|
|
279
|
+
get values() {
|
|
280
|
+
return getCurveValues(this._segment1, this._segment2);
|
|
281
|
+
}
|
|
282
|
+
/**
|
|
283
|
+
* An array of 4 point objects, describing this curve's geometry in absolute
|
|
284
|
+
* coordinates (point1, handle1, handle2, point2).
|
|
285
|
+
*
|
|
286
|
+
* Note that the handles are converted to absolute coordinates.
|
|
287
|
+
*/
|
|
288
|
+
get points() {
|
|
289
|
+
// Convert to array of absolute points
|
|
290
|
+
const coords = this.values;
|
|
291
|
+
const points = [];
|
|
292
|
+
for (let i = 0; i < 8; i += 2) {
|
|
293
|
+
points.push(new Point(coords[i], coords[i + 1]));
|
|
294
|
+
}
|
|
295
|
+
return points;
|
|
296
|
+
}
|
|
297
|
+
/**
|
|
298
|
+
* The approximated length of the curve.
|
|
299
|
+
*/
|
|
300
|
+
get length() {
|
|
301
|
+
this.#length ??= getCurveLength(this.values, 0, 1);
|
|
302
|
+
return this.#length;
|
|
303
|
+
}
|
|
304
|
+
/**
|
|
305
|
+
* The area that the curve's geometry is covering.
|
|
306
|
+
*/
|
|
307
|
+
get area() {
|
|
308
|
+
return getCurveArea(this.values);
|
|
309
|
+
}
|
|
310
|
+
/**
|
|
311
|
+
* @private
|
|
312
|
+
*/
|
|
313
|
+
get line() {
|
|
314
|
+
return new Line(this._segment1._point, this._segment2._point);
|
|
315
|
+
}
|
|
316
|
+
/**
|
|
317
|
+
* Creates a new curve as a sub-curve from this curve, its range defined by
|
|
318
|
+
* the given curve-time parameters. If `from` is larger than `to`, then
|
|
319
|
+
* the resulting curve will have its direction reversed.
|
|
320
|
+
*
|
|
321
|
+
* @param from the curve-time parameter at which the sub-curve
|
|
322
|
+
* starts
|
|
323
|
+
* @param to the curve-time parameter at which the sub-curve
|
|
324
|
+
* ends
|
|
325
|
+
* @return the newly created sub-curve
|
|
326
|
+
*/
|
|
327
|
+
getPart(from, to) {
|
|
328
|
+
return new Curve(getCurvePart(this.values, from, to));
|
|
329
|
+
}
|
|
330
|
+
/**
|
|
331
|
+
* Returns the length of the part of the curve between the given
|
|
332
|
+
* curve-time parameters.
|
|
333
|
+
*
|
|
334
|
+
* @param from the curve-time parameter at which the part starts
|
|
335
|
+
* @param to the curve-time parameter at which the part ends
|
|
336
|
+
* @return the length of the part
|
|
337
|
+
*/
|
|
338
|
+
getPartLength(from, to) {
|
|
339
|
+
return getCurveLength(this.values, from, to);
|
|
340
|
+
}
|
|
341
|
+
/**
|
|
342
|
+
* Divides the curve into two curves at the given offset or location. The
|
|
343
|
+
* curve itself is modified and becomes the first part, the second part is
|
|
344
|
+
* returned as a new curve. If the curve belongs to a path item, a new
|
|
345
|
+
* segment is inserted into the path at the given location, and the second
|
|
346
|
+
* part becomes a part of the path as well.
|
|
347
|
+
*
|
|
348
|
+
* @param location the offset or location on the
|
|
349
|
+
* curve at which to divide
|
|
350
|
+
* @return the second part of the divided curve if the location is
|
|
351
|
+
* valid, `null` otherwise
|
|
352
|
+
* @see #divideAtTime(time)
|
|
353
|
+
*/
|
|
354
|
+
divideAt(location) {
|
|
355
|
+
const time = getLocationTime(this, location);
|
|
356
|
+
return time == null ? null : this.divideAtTime(time);
|
|
357
|
+
}
|
|
358
|
+
/**
|
|
359
|
+
* Divides the curve into two curves at the given curve-time parameter. The
|
|
360
|
+
* curve itself is modified and becomes the first part, the second part is
|
|
361
|
+
* returned as a new curve. If the modified curve belongs to a path item,
|
|
362
|
+
* the second part is also added to the path.
|
|
363
|
+
*
|
|
364
|
+
* @param time the curve-time parameter on the curve at which to
|
|
365
|
+
* divide
|
|
366
|
+
* @return the second part of the divided curve, if the offset is
|
|
367
|
+
* within the valid range, `null` otherwise.
|
|
368
|
+
* @see #divideAt(location)
|
|
369
|
+
*/
|
|
370
|
+
divideAtTime(time) {
|
|
371
|
+
// Only divide if not at the beginning or end.
|
|
372
|
+
const tMin = CURVETIME_EPSILON;
|
|
373
|
+
const tMax = 1 - tMin;
|
|
374
|
+
let res = null;
|
|
375
|
+
if (time >= tMin && time <= tMax) {
|
|
376
|
+
const [left, right] = subdivideCurve(this.values, time);
|
|
377
|
+
const setHandles = this.hasHandles();
|
|
378
|
+
const segment1 = this._segment1;
|
|
379
|
+
const segment2 = this._segment2;
|
|
380
|
+
const path = this._path;
|
|
381
|
+
if (setHandles) {
|
|
382
|
+
// Adjust the handles on the existing segments. The new segment
|
|
383
|
+
// will be inserted between the existing segment1 and segment2:
|
|
384
|
+
// Convert absolute -> relative
|
|
385
|
+
segment1._handleOut._set(left[2] - left[0], left[3] - left[1]);
|
|
386
|
+
segment2._handleIn._set(right[4] - right[6], right[5] - right[7]);
|
|
387
|
+
}
|
|
388
|
+
// Create the new segment:
|
|
389
|
+
const x = left[6];
|
|
390
|
+
const y = left[7];
|
|
391
|
+
const segment = new Segment(new Point(x, y), setHandles ? new Point(left[4] - x, left[5] - y) : null, setHandles ? new Point(right[2] - x, right[3] - y) : null);
|
|
392
|
+
// Insert it in the segments list, if needed:
|
|
393
|
+
if (path) {
|
|
394
|
+
// By inserting at segment1.index + 1, we make sure to insert at
|
|
395
|
+
// the end if this curve is a closing curve of a closed path,
|
|
396
|
+
// as with segment2.index it would be inserted at 0.
|
|
397
|
+
path.insert(segment1._index + 1, segment);
|
|
398
|
+
// The newly inserted segment is the start of the next curve:
|
|
399
|
+
res = this.next;
|
|
400
|
+
}
|
|
401
|
+
else {
|
|
402
|
+
// otherwise create it from the result of split
|
|
403
|
+
this._segment2 = segment;
|
|
404
|
+
this._changed();
|
|
405
|
+
res = new Curve(segment, segment2);
|
|
406
|
+
}
|
|
407
|
+
}
|
|
408
|
+
return res;
|
|
409
|
+
}
|
|
410
|
+
/**
|
|
411
|
+
* Splits the path this curve belongs to at the given offset. After
|
|
412
|
+
* splitting, the path will be open. If the path was open already, splitting
|
|
413
|
+
* will result in two paths.
|
|
414
|
+
*
|
|
415
|
+
* @param location the offset or location on the
|
|
416
|
+
* curve at which to split
|
|
417
|
+
* @return the newly created path after splitting, if any
|
|
418
|
+
* @see Path#splitAt(location)
|
|
419
|
+
*/
|
|
420
|
+
splitAt(location) {
|
|
421
|
+
const path = this._path;
|
|
422
|
+
return path?.splitAt(location) ?? null;
|
|
423
|
+
}
|
|
424
|
+
/**
|
|
425
|
+
* Splits the path this curve belongs to at the given curve-time parameter.
|
|
426
|
+
* After splitting, the path will be open. If the path was open already,
|
|
427
|
+
* splitting will result in two paths.
|
|
428
|
+
*
|
|
429
|
+
* @param time the curve-time parameter on the curve at which to
|
|
430
|
+
* split
|
|
431
|
+
* @return the newly created path after splitting, if any
|
|
432
|
+
* @see Path#splitAt(location)
|
|
433
|
+
*/
|
|
434
|
+
splitAtTime(time) {
|
|
435
|
+
const location = this.getLocationAtTime(time);
|
|
436
|
+
return location && this.splitAt(location);
|
|
437
|
+
}
|
|
438
|
+
/**
|
|
439
|
+
* Returns a reversed version of the curve, without modifying the curve
|
|
440
|
+
* itself.
|
|
441
|
+
*
|
|
442
|
+
* @return a reversed version of the curve
|
|
443
|
+
*/
|
|
444
|
+
reversed() {
|
|
445
|
+
return new Curve(this._segment2.reversed(), this._segment1.reversed());
|
|
446
|
+
}
|
|
447
|
+
/**
|
|
448
|
+
* Clears the curve's handles by setting their coordinates to zero,
|
|
449
|
+
* turning the curve into a straight line.
|
|
450
|
+
*/
|
|
451
|
+
clearHandles() {
|
|
452
|
+
this._segment1._handleOut._set(0, 0);
|
|
453
|
+
this._segment2._handleIn._set(0, 0);
|
|
454
|
+
}
|
|
455
|
+
/**
|
|
456
|
+
* {@grouptitle Bounding Boxes}
|
|
457
|
+
*
|
|
458
|
+
* The bounding rectangle of the curve excluding stroke width.
|
|
459
|
+
*/
|
|
460
|
+
get bounds() {
|
|
461
|
+
return this.#getBounds(false);
|
|
462
|
+
}
|
|
463
|
+
/**
|
|
464
|
+
* The bounding rectangle of the curve including stroke width.
|
|
465
|
+
*/
|
|
466
|
+
get strokeBounds() {
|
|
467
|
+
return this.#getBounds(true);
|
|
468
|
+
}
|
|
469
|
+
#getBounds(stroke) {
|
|
470
|
+
this.#bounds ??= {};
|
|
471
|
+
const key = stroke ? 'strokeBounds' : 'bounds';
|
|
472
|
+
let bounds = this.#bounds[key];
|
|
473
|
+
if (!bounds) {
|
|
474
|
+
// Calculate the curve bounds by passing a segment list for the
|
|
475
|
+
// curve to the getSegment*Bounds() functions. Without a path,
|
|
476
|
+
// there is no stroke, so the stroke bounds are the bounds.
|
|
477
|
+
const path = this._path;
|
|
478
|
+
const segments = [this._segment1, this._segment2];
|
|
479
|
+
bounds = this.#bounds[key] =
|
|
480
|
+
path && stroke
|
|
481
|
+
? getSegmentStrokeBounds(segments, false, path)
|
|
482
|
+
: getSegmentBounds(segments, false, path);
|
|
483
|
+
}
|
|
484
|
+
return bounds.clone();
|
|
485
|
+
}
|
|
486
|
+
/**
|
|
487
|
+
* The bounding rectangle of the curve including handles.
|
|
488
|
+
*/
|
|
489
|
+
get handleBounds() {
|
|
490
|
+
// Unlike getSegmentHandleBounds(), only include the curve's own handles,
|
|
491
|
+
// not the outer handles of its two segments.
|
|
492
|
+
const v = this.values;
|
|
493
|
+
const x1 = Math.min(v[0], v[2], v[4], v[6]);
|
|
494
|
+
const y1 = Math.min(v[1], v[3], v[5], v[7]);
|
|
495
|
+
const x2 = Math.max(v[0], v[2], v[4], v[6]);
|
|
496
|
+
const y2 = Math.max(v[1], v[3], v[5], v[7]);
|
|
497
|
+
return new Rectangle(x1, y1, x2 - x1, y2 - y1);
|
|
498
|
+
}
|
|
499
|
+
/**
|
|
500
|
+
* {@grouptitle Curve Tests}
|
|
501
|
+
*
|
|
502
|
+
* Checks if this curve has any curve handles set. Handles of which both
|
|
503
|
+
* coordinates are 0 within a tolerance of 1e-12 count as not set, see
|
|
504
|
+
* {@link Point#isZero()}.
|
|
505
|
+
*
|
|
506
|
+
* @return {@true if the curve has handles set}
|
|
507
|
+
* @see Curve#handle1
|
|
508
|
+
* @see Curve#handle2
|
|
509
|
+
* @see Segment#hasHandles()
|
|
510
|
+
* @see Path#hasHandles()
|
|
511
|
+
*/
|
|
512
|
+
hasHandles() {
|
|
513
|
+
return (!this._segment1._handleOut.isZero() ||
|
|
514
|
+
!this._segment2._handleIn.isZero());
|
|
515
|
+
}
|
|
516
|
+
/**
|
|
517
|
+
* Checks if this curve has any length.
|
|
518
|
+
*
|
|
519
|
+
* @param [epsilon=0] the epsilon against which to compare the
|
|
520
|
+
* curve's length
|
|
521
|
+
* @return {@true if the curve is longer than the given epsilon}
|
|
522
|
+
*/
|
|
523
|
+
hasLength(epsilon) {
|
|
524
|
+
return ((!this.point1.equals(this.point2) || this.hasHandles()) &&
|
|
525
|
+
this.length > (epsilon || 0));
|
|
526
|
+
}
|
|
527
|
+
/**
|
|
528
|
+
* Checks if the two curves describe straight lines that are
|
|
529
|
+
* collinear, meaning they run in parallel.
|
|
530
|
+
*
|
|
531
|
+
* @param curve the other curve to check against
|
|
532
|
+
* @return {@true if the two lines are collinear}
|
|
533
|
+
*/
|
|
534
|
+
isCollinear(curve) {
|
|
535
|
+
return (!!curve &&
|
|
536
|
+
this.isStraight() &&
|
|
537
|
+
curve.isStraight() &&
|
|
538
|
+
this.line.isCollinear(curve.line));
|
|
539
|
+
}
|
|
540
|
+
/**
|
|
541
|
+
* Checks if the curve is a straight horizontal line.
|
|
542
|
+
*
|
|
543
|
+
* @return {@true if the line is horizontal}
|
|
544
|
+
*/
|
|
545
|
+
isHorizontal() {
|
|
546
|
+
return (this.isStraight() &&
|
|
547
|
+
Math.abs(getCurveTangent(this.values, 0.5).y) < TRIGONOMETRIC_EPSILON);
|
|
548
|
+
}
|
|
549
|
+
/**
|
|
550
|
+
* Checks if the curve is a straight vertical line.
|
|
551
|
+
*
|
|
552
|
+
* @return {@true if the line is vertical}
|
|
553
|
+
*/
|
|
554
|
+
isVertical() {
|
|
555
|
+
return (this.isStraight() &&
|
|
556
|
+
Math.abs(getCurveTangent(this.values, 0.5).x) < TRIGONOMETRIC_EPSILON);
|
|
557
|
+
}
|
|
558
|
+
/**
|
|
559
|
+
* {@grouptitle Positions on Curves}
|
|
560
|
+
*
|
|
561
|
+
* Calculates the curve location at the specified offset on the curve, or
|
|
562
|
+
* `null` if the offset exceeds the length of the curve.
|
|
563
|
+
*
|
|
564
|
+
* @param offset the offset on the curve
|
|
565
|
+
* @return the curve location at the specified offset
|
|
566
|
+
*/
|
|
567
|
+
getLocationAt(offset) {
|
|
568
|
+
return this.getLocationAtTime(this.getTimeAt(offset));
|
|
569
|
+
}
|
|
570
|
+
/**
|
|
571
|
+
* Calculates the curve location at the specified curve-time parameter on
|
|
572
|
+
* the curve, or `null` if the parameter lies outside of `0..1`.
|
|
573
|
+
*
|
|
574
|
+
* @param time the curve-time parameter on the curve
|
|
575
|
+
* @return the curve location at the specified curve-time parameter
|
|
576
|
+
*/
|
|
577
|
+
getLocationAtTime(time) {
|
|
578
|
+
return time != null && time >= 0 && time <= 1
|
|
579
|
+
? new CurveLocation(this, time)
|
|
580
|
+
: null;
|
|
581
|
+
}
|
|
582
|
+
/**
|
|
583
|
+
* Calculates the curve-time parameter of the specified offset on the path,
|
|
584
|
+
* relative to the provided start parameter. If offset is a negative value,
|
|
585
|
+
* the parameter is searched to the left of the start parameter. If no start
|
|
586
|
+
* parameter is provided, a default of `0` for positive values of `offset`
|
|
587
|
+
* and `1` for negative values of `offset`.
|
|
588
|
+
*
|
|
589
|
+
* @param offset the offset at which to find the curve-time, in
|
|
590
|
+
* curve length units
|
|
591
|
+
* @param [start] the curve-time in relation to which the offset is
|
|
592
|
+
* determined
|
|
593
|
+
* @return the curve-time parameter at the specified location, or
|
|
594
|
+
* `null` if the offset exceeds the length of the curve
|
|
595
|
+
*/
|
|
596
|
+
getTimeAt(offset, start) {
|
|
597
|
+
return getCurveTimeAt(this.values, offset, start);
|
|
598
|
+
}
|
|
599
|
+
/**
|
|
600
|
+
* Calculates the curve-time parameters where the curve is tangential to
|
|
601
|
+
* provided tangent. Note that tangents at the start or end are included.
|
|
602
|
+
*
|
|
603
|
+
* @param tangent the tangent to which the curve must be tangential
|
|
604
|
+
* @return at most two curve-time parameters, where the curve is
|
|
605
|
+
* tangential to the given tangent
|
|
606
|
+
*/
|
|
607
|
+
getTimesWithTangent(tangent, y) {
|
|
608
|
+
const vector = Point.from(tangent, y);
|
|
609
|
+
return vector.isZero()
|
|
610
|
+
? []
|
|
611
|
+
: getCurveTimesWithTangent(this.values, vector);
|
|
612
|
+
}
|
|
613
|
+
/**
|
|
614
|
+
* Returns the curve-time parameters of the peaks of the curve: where its
|
|
615
|
+
* first derivative is perpendicular to its second, so that its speed is
|
|
616
|
+
* the least or the most. They are similar to the extrema of its curvature,
|
|
617
|
+
* and cheaper to find.
|
|
618
|
+
*
|
|
619
|
+
* @return the curve-time parameters of the peaks
|
|
620
|
+
*/
|
|
621
|
+
getPeaks() {
|
|
622
|
+
return getCurvePeaks(this.values);
|
|
623
|
+
}
|
|
624
|
+
/**
|
|
625
|
+
* Calculates the curve offset at the specified curve-time parameter on
|
|
626
|
+
* the curve.
|
|
627
|
+
*
|
|
628
|
+
* @param time the curve-time parameter on the curve
|
|
629
|
+
* @return the curve offset at the specified curve-time parameter
|
|
630
|
+
*/
|
|
631
|
+
getOffsetAtTime(time) {
|
|
632
|
+
return this.getPartLength(0, time);
|
|
633
|
+
}
|
|
634
|
+
/**
|
|
635
|
+
* Returns the curve location of the specified point if it lies on the
|
|
636
|
+
* curve, `null` otherwise.
|
|
637
|
+
*
|
|
638
|
+
* @param point the point on the curve
|
|
639
|
+
* @return the curve location of the specified point
|
|
640
|
+
*/
|
|
641
|
+
getLocationOf(point, y) {
|
|
642
|
+
return this.getLocationAtTime(this.getTimeOf(point, y));
|
|
643
|
+
}
|
|
644
|
+
/**
|
|
645
|
+
* Returns the length of the path from its beginning up to the
|
|
646
|
+
* specified point if it lies on the path, `null` otherwise.
|
|
647
|
+
*
|
|
648
|
+
* @param point the point on the path
|
|
649
|
+
* @return the length of the path up to the specified point
|
|
650
|
+
*/
|
|
651
|
+
getOffsetOf(point, y) {
|
|
652
|
+
const location = this.getLocationOf(point, y);
|
|
653
|
+
return location?.offset ?? null;
|
|
654
|
+
}
|
|
655
|
+
/**
|
|
656
|
+
* Returns the curve-time parameter of the specified point if it lies on the
|
|
657
|
+
* curve, `null` otherwise.
|
|
658
|
+
* Note that if there is more than one possible solution in a
|
|
659
|
+
* self-intersecting curve, the first found result is returned.
|
|
660
|
+
*
|
|
661
|
+
* @param point the point on the curve
|
|
662
|
+
* @return the curve-time parameter of the specified point
|
|
663
|
+
*/
|
|
664
|
+
getTimeOf(point, y) {
|
|
665
|
+
return getCurveTimeOf(this.values, Point.from(point, y));
|
|
666
|
+
}
|
|
667
|
+
/**
|
|
668
|
+
* Returns the nearest location on the curve to the specified point.
|
|
669
|
+
*
|
|
670
|
+
* @param point the point for which we search the nearest location
|
|
671
|
+
* @return the location on the curve that's the closest to
|
|
672
|
+
* the specified point
|
|
673
|
+
*/
|
|
674
|
+
getNearestLocation(point, y) {
|
|
675
|
+
const target = Point.from(point, y);
|
|
676
|
+
const { values } = this;
|
|
677
|
+
const t = getNearestCurveTime(values, target);
|
|
678
|
+
const pt = getCurvePoint(values, t);
|
|
679
|
+
return new CurveLocation(this, t, pt, undefined, target.getDistance(pt));
|
|
680
|
+
}
|
|
681
|
+
/**
|
|
682
|
+
* Returns the nearest point on the curve to the specified point.
|
|
683
|
+
*
|
|
684
|
+
* @param point the point for which we search the nearest point
|
|
685
|
+
* @return the point on the curve that's the closest to the
|
|
686
|
+
* specified point
|
|
687
|
+
*/
|
|
688
|
+
getNearestPoint(point, y) {
|
|
689
|
+
const location = this.getNearestLocation(point, y);
|
|
690
|
+
return location?.point ?? null;
|
|
691
|
+
}
|
|
692
|
+
static getIntersections(curves1, curves2, include, matrix1, matrix2, _returnFirst) {
|
|
693
|
+
const self = !curves2;
|
|
694
|
+
const others = curves2 ?? curves1;
|
|
695
|
+
const length1 = curves1.length;
|
|
696
|
+
const length2 = others.length;
|
|
697
|
+
const values1 = new Array(length1);
|
|
698
|
+
const values2 = self ? values1 : new Array(length2);
|
|
699
|
+
const locations = [];
|
|
700
|
+
for (let i = 0; i < length1; i++) {
|
|
701
|
+
values1[i] = getCurveValues(curves1[i]._segment1, curves1[i]._segment2, matrix1);
|
|
702
|
+
}
|
|
703
|
+
if (!self) {
|
|
704
|
+
for (let i = 0; i < length2; i++) {
|
|
705
|
+
values2[i] = getCurveValues(others[i]._segment1, others[i]._segment2, matrix2);
|
|
706
|
+
}
|
|
707
|
+
}
|
|
708
|
+
const boundsCollisions = findCurveBoundsCollisions(values1, values2, GEOMETRIC_EPSILON);
|
|
709
|
+
for (let index1 = 0; index1 < length1; index1++) {
|
|
710
|
+
const curve1 = curves1[index1];
|
|
711
|
+
const v1 = values1[index1];
|
|
712
|
+
if (self) {
|
|
713
|
+
// First check for self-intersections within the same curve.
|
|
714
|
+
addIntersections(locations, include, curve1, v1);
|
|
715
|
+
}
|
|
716
|
+
// Check for intersections with potentially intersecting curves.
|
|
717
|
+
const collisions1 = boundsCollisions[index1];
|
|
718
|
+
if (collisions1) {
|
|
719
|
+
for (let j = 0; j < collisions1.length; j++) {
|
|
720
|
+
// There might be already one location from the above
|
|
721
|
+
// self-intersection check:
|
|
722
|
+
if (_returnFirst && locations.length)
|
|
723
|
+
return locations;
|
|
724
|
+
const index2 = collisions1[j];
|
|
725
|
+
if (!self || index2 > index1) {
|
|
726
|
+
addIntersections(locations, include, curve1, v1, others[index2], values2[index2]);
|
|
727
|
+
}
|
|
728
|
+
}
|
|
729
|
+
}
|
|
730
|
+
}
|
|
731
|
+
return locations;
|
|
732
|
+
}
|
|
733
|
+
/**
|
|
734
|
+
* Returns all intersections between two {@link Curve} objects as an
|
|
735
|
+
* array of {@link CurveLocation} objects.
|
|
736
|
+
*
|
|
737
|
+
* @param curve the other curve to find the intersections with
|
|
738
|
+
* (if the curve itself or `null` is passed, the self intersection
|
|
739
|
+
* of the curve is returned, if it exists)
|
|
740
|
+
* @return the locations of all intersections between
|
|
741
|
+
* the curves
|
|
742
|
+
*/
|
|
743
|
+
getIntersections(curve) {
|
|
744
|
+
const locations = [];
|
|
745
|
+
if (curve && curve !== this) {
|
|
746
|
+
addIntersections(locations, null, this, this.values, curve, curve.values);
|
|
747
|
+
}
|
|
748
|
+
else {
|
|
749
|
+
addIntersections(locations, null, this, this.values);
|
|
750
|
+
}
|
|
751
|
+
return locations;
|
|
752
|
+
}
|
|
753
|
+
/**
|
|
754
|
+
* Checks if this curve appears as a straight line. This can mean that
|
|
755
|
+
* it has no handles defined, or that the handles run collinear with the
|
|
756
|
+
* line that connects the curve's start and end point, not falling
|
|
757
|
+
* outside of the line.
|
|
758
|
+
*
|
|
759
|
+
* @return {@true if the curve is straight}
|
|
760
|
+
*/
|
|
761
|
+
isStraight() {
|
|
762
|
+
return this.#testHandles(hasStraightHandles);
|
|
763
|
+
}
|
|
764
|
+
/**
|
|
765
|
+
* Checks if this curve is parametrically linear, meaning that it is
|
|
766
|
+
* straight and its handles are positioned at 1/3 and 2/3 of the total
|
|
767
|
+
* length of the curve.
|
|
768
|
+
*
|
|
769
|
+
* @return {@true if the curve is parametrically linear}
|
|
770
|
+
*/
|
|
771
|
+
isLinear() {
|
|
772
|
+
return this.#testHandles(hasLinearHandles);
|
|
773
|
+
}
|
|
774
|
+
// The tests on curve objects pass the coordinates without creating points
|
|
775
|
+
// or arrays, as they are called a lot:
|
|
776
|
+
#testHandles(test) {
|
|
777
|
+
const p1 = this._segment1._point;
|
|
778
|
+
const h1 = this._segment1._handleOut;
|
|
779
|
+
const h2 = this._segment2._handleIn;
|
|
780
|
+
const p2 = this._segment2._point;
|
|
781
|
+
return test(p1._x, p1._y, h1._x, h1._y, h2._x, h2._y, p2._x, p2._y);
|
|
782
|
+
}
|
|
783
|
+
/**
|
|
784
|
+
* Calculates the point on the curve at the given location.
|
|
785
|
+
*
|
|
786
|
+
* @param location the offset or location on the
|
|
787
|
+
* curve
|
|
788
|
+
* @return the point on the curve at the given location, or `null` if the
|
|
789
|
+
* location isn't on the curve
|
|
790
|
+
*/
|
|
791
|
+
getPointAt(location) {
|
|
792
|
+
return evaluateAt(this, location, getCurvePoint);
|
|
793
|
+
}
|
|
794
|
+
/**
|
|
795
|
+
* Calculates the point on the curve at the given curve-time parameter.
|
|
796
|
+
*
|
|
797
|
+
* @param time the curve-time parameter on the curve
|
|
798
|
+
* @return the point on the curve at the given curve-time parameter, or `null`
|
|
799
|
+
* for times outside 0 to 1
|
|
800
|
+
*/
|
|
801
|
+
getPointAtTime(time) {
|
|
802
|
+
return evaluateAtTime(this, time, getCurvePoint);
|
|
803
|
+
}
|
|
804
|
+
/**
|
|
805
|
+
* Calculates the normalized tangent vector of the curve at the given
|
|
806
|
+
* location.
|
|
807
|
+
*
|
|
808
|
+
* @param location the offset or location on the
|
|
809
|
+
* curve
|
|
810
|
+
* @return the normalized tangent of the curve at the given location, or
|
|
811
|
+
* `null` if the location isn't on the curve
|
|
812
|
+
*/
|
|
813
|
+
getTangentAt(location) {
|
|
814
|
+
return evaluateAt(this, location, getCurveTangent);
|
|
815
|
+
}
|
|
816
|
+
/**
|
|
817
|
+
* Calculates the normalized tangent vector of the curve at the given
|
|
818
|
+
* curve-time parameter.
|
|
819
|
+
*
|
|
820
|
+
* @param time the curve-time parameter on the curve
|
|
821
|
+
* @return the normalized tangent of the curve at the given curve-time
|
|
822
|
+
* parameter, or `null` for times outside 0 to 1
|
|
823
|
+
*/
|
|
824
|
+
getTangentAtTime(time) {
|
|
825
|
+
return evaluateAtTime(this, time, getCurveTangent);
|
|
826
|
+
}
|
|
827
|
+
/**
|
|
828
|
+
* Calculates the normal vector of the curve at the given location.
|
|
829
|
+
*
|
|
830
|
+
* @param location the offset or location on the
|
|
831
|
+
* curve
|
|
832
|
+
* @return the normal of the curve at the given location, or `null` if the
|
|
833
|
+
* location isn't on the curve
|
|
834
|
+
*/
|
|
835
|
+
getNormalAt(location) {
|
|
836
|
+
return evaluateAt(this, location, getCurveNormal);
|
|
837
|
+
}
|
|
838
|
+
/**
|
|
839
|
+
* Calculates the normal vector of the curve at the given curve-time
|
|
840
|
+
* parameter.
|
|
841
|
+
*
|
|
842
|
+
* @param time the curve-time parameter on the curve
|
|
843
|
+
* @return the normal of the curve at the given curve-time parameter, or
|
|
844
|
+
* `null` for times outside 0 to 1
|
|
845
|
+
*/
|
|
846
|
+
getNormalAtTime(time) {
|
|
847
|
+
return evaluateAtTime(this, time, getCurveNormal);
|
|
848
|
+
}
|
|
849
|
+
/**
|
|
850
|
+
* Calculates the weighted tangent vector of the curve at the given
|
|
851
|
+
* location, its length reflecting the curve velocity at that location.
|
|
852
|
+
*
|
|
853
|
+
* @param location the offset or location on the
|
|
854
|
+
* curve
|
|
855
|
+
* @return the weighted tangent of the curve at the given location, or `null`
|
|
856
|
+
* if the location isn't on the curve
|
|
857
|
+
*/
|
|
858
|
+
getWeightedTangentAt(location) {
|
|
859
|
+
return evaluateAt(this, location, getWeightedCurveTangent);
|
|
860
|
+
}
|
|
861
|
+
/**
|
|
862
|
+
* Calculates the weighted tangent vector of the curve at the given
|
|
863
|
+
* curve-time parameter, its length reflecting the curve velocity there.
|
|
864
|
+
*
|
|
865
|
+
* @param time the curve-time parameter on the curve
|
|
866
|
+
* @return the weighted tangent of the curve at the given curve-time
|
|
867
|
+
* parameter, or `null` for times outside 0 to 1
|
|
868
|
+
*/
|
|
869
|
+
getWeightedTangentAtTime(time) {
|
|
870
|
+
return evaluateAtTime(this, time, getWeightedCurveTangent);
|
|
871
|
+
}
|
|
872
|
+
/**
|
|
873
|
+
* Calculates the weighted normal vector of the curve at the given location,
|
|
874
|
+
* its length reflecting the curve velocity at that location.
|
|
875
|
+
*
|
|
876
|
+
* @param location the offset or location on the
|
|
877
|
+
* curve
|
|
878
|
+
* @return the weighted normal of the curve at the given location, or `null`
|
|
879
|
+
* if the location isn't on the curve
|
|
880
|
+
*/
|
|
881
|
+
getWeightedNormalAt(location) {
|
|
882
|
+
return evaluateAt(this, location, getWeightedCurveNormal);
|
|
883
|
+
}
|
|
884
|
+
/**
|
|
885
|
+
* Calculates the weighted normal vector of the curve at the given
|
|
886
|
+
* curve-time parameter, its length reflecting the curve velocity there.
|
|
887
|
+
*
|
|
888
|
+
* @param time the curve-time parameter on the curve
|
|
889
|
+
* @return the weighted normal of the curve at the given curve-time parameter,
|
|
890
|
+
* or `null` for times outside 0 to 1
|
|
891
|
+
*/
|
|
892
|
+
getWeightedNormalAtTime(time) {
|
|
893
|
+
return evaluateAtTime(this, time, getWeightedCurveNormal);
|
|
894
|
+
}
|
|
895
|
+
/**
|
|
896
|
+
* Calculates the curvature of the curve at the given location. Curvatures
|
|
897
|
+
* indicate how sharply a curve changes direction. A straight line has zero
|
|
898
|
+
* curvature, where as a circle has a constant curvature. The curve's radius
|
|
899
|
+
* at the given location is the reciprocal value of its curvature.
|
|
900
|
+
*
|
|
901
|
+
* @param location the offset or location on the
|
|
902
|
+
* curve
|
|
903
|
+
* @return the curvature of the curve at the given location, or `null` if the
|
|
904
|
+
* location isn't on the curve
|
|
905
|
+
*/
|
|
906
|
+
getCurvatureAt(location) {
|
|
907
|
+
return evaluateAt(this, location, getCurvature);
|
|
908
|
+
}
|
|
909
|
+
/**
|
|
910
|
+
* Calculates the curvature of the curve at the given curve-time
|
|
911
|
+
* parameter. Curvatures indicate how sharply a curve changes direction. A
|
|
912
|
+
* straight line has zero curvature, where as a circle has a constant
|
|
913
|
+
* curvature. The curve's radius at the given curve-time parameter is the
|
|
914
|
+
* reciprocal value of its curvature.
|
|
915
|
+
*
|
|
916
|
+
* @param time the curve-time parameter on the curve
|
|
917
|
+
* @return the curvature of the curve at the given curve-time parameter, or
|
|
918
|
+
* `null` for times outside 0 to 1
|
|
919
|
+
*/
|
|
920
|
+
getCurvatureAtTime(time) {
|
|
921
|
+
return evaluateAtTime(this, time, getCurvature);
|
|
922
|
+
}
|
|
923
|
+
static {
|
|
924
|
+
registerClasses({ Curve: this });
|
|
925
|
+
}
|
|
926
|
+
}
|
|
927
|
+
// Adds the intersections of the two curves with their values to the
|
|
928
|
+
// locations, or those of the first curve with itself: as two locations that
|
|
929
|
+
// are linked to each other, merged with the one that is there already at the
|
|
930
|
+
// same place. The filter leaves out the ones it rejects.
|
|
931
|
+
function addIntersections(locations, include, curve1, v1, curve2, v2) {
|
|
932
|
+
const intersections = curve2 && v2
|
|
933
|
+
? getCurveIntersections(v1, v2, {
|
|
934
|
+
sharesStart: curve1.previous === curve2,
|
|
935
|
+
sharesEnd: curve1.next === curve2
|
|
936
|
+
})
|
|
937
|
+
: getCurveSelfIntersection(v1, curve1.previous === curve1);
|
|
938
|
+
for (const [time1, time2, overlap] of intersections) {
|
|
939
|
+
// NOTE: We don't pass points, because the values may be transformed by
|
|
940
|
+
// the matrices of their paths, while the curves are not. CurveLocation
|
|
941
|
+
// gets the points from the curves then.
|
|
942
|
+
const location1 = new CurveLocation(curve1, time1, null, overlap);
|
|
943
|
+
const location2 = new CurveLocation(curve2 ?? curve1, time2, null, overlap);
|
|
944
|
+
location1._intersection = location2;
|
|
945
|
+
location2._intersection = location1;
|
|
946
|
+
if (!include || include(location1)) {
|
|
947
|
+
CurveLocation.insert(locations, location1, true);
|
|
948
|
+
}
|
|
949
|
+
}
|
|
950
|
+
}
|
|
951
|
+
// The values of the curve between two segments, transformed by the matrix
|
|
952
|
+
// if one is given, and without the handles if it is to be straight.
|
|
953
|
+
export function getCurveValues(segment1, segment2, matrix, straight) {
|
|
954
|
+
const p1 = segment1._point;
|
|
955
|
+
const h1 = segment1._handleOut;
|
|
956
|
+
const h2 = segment2._handleIn;
|
|
957
|
+
const p2 = segment2._point;
|
|
958
|
+
const x1 = p1.x;
|
|
959
|
+
const y1 = p1.y;
|
|
960
|
+
const x2 = p2.x;
|
|
961
|
+
const y2 = p2.y;
|
|
962
|
+
const values = straight
|
|
963
|
+
? [x1, y1, x1, y1, x2, y2, x2, y2]
|
|
964
|
+
: [
|
|
965
|
+
x1,
|
|
966
|
+
y1,
|
|
967
|
+
x1 + h1._x,
|
|
968
|
+
y1 + h1._y,
|
|
969
|
+
x2 + h2._x,
|
|
970
|
+
y2 + h2._y,
|
|
971
|
+
x2,
|
|
972
|
+
y2
|
|
973
|
+
];
|
|
974
|
+
if (matrix) {
|
|
975
|
+
matrix._transformCoordinates(values, values, 4);
|
|
976
|
+
}
|
|
977
|
+
return values;
|
|
978
|
+
}
|
|
979
|
+
// Returns the curve-time of an offset on the curve, or of a location on it, as
|
|
980
|
+
// well as of objects that act like locations:
|
|
981
|
+
function getLocationTime(curve, location) {
|
|
982
|
+
return location?.curve === curve
|
|
983
|
+
? location.time
|
|
984
|
+
: curve.getTimeAt(location);
|
|
985
|
+
}
|
|
986
|
+
// Evaluates the curve at the location, if it lies on the curve, see
|
|
987
|
+
// Curve#getPointAt():
|
|
988
|
+
function evaluateAt(curve, location, evaluate) {
|
|
989
|
+
const time = getLocationTime(curve, location);
|
|
990
|
+
return time == null ? null : evaluate(curve.values, time);
|
|
991
|
+
}
|
|
992
|
+
// Times outside the curve have nothing to evaluate, see
|
|
993
|
+
// Curve#getPointAtTime():
|
|
994
|
+
function evaluateAtTime(curve, time, evaluate) {
|
|
995
|
+
return time >= 0 && time <= 1 ? evaluate(curve.values, time) : null;
|
|
996
|
+
}
|