@antv/g 3.5.0-beta.3 → 5.0.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/README.md +0 -546
- package/dist/index.umd.js +15 -0
- package/es/AbstractRenderer.d.ts +26 -0
- package/es/AbstractRenderer.js +42 -0
- package/es/Canvas.d.ts +97 -0
- package/es/Canvas.js +406 -0
- package/es/DisplayObjectPool.d.ts +7 -0
- package/es/DisplayObjectPool.js +27 -0
- package/es/camera/Camera.d.ts +279 -0
- package/es/camera/Camera.js +975 -0
- package/es/camera/Landmark.d.ts +28 -0
- package/es/camera/Landmark.js +68 -0
- package/es/camera/index.d.ts +2 -0
- package/es/camera/index.js +2 -0
- package/es/canvas-module.d.ts +1 -0
- package/es/canvas-module.js +33 -0
- package/es/components/Cullable.d.ts +14 -0
- package/es/components/Cullable.js +28 -0
- package/es/components/Geometry.d.ts +12 -0
- package/es/components/Geometry.js +10 -0
- package/es/components/Renderable.d.ts +24 -0
- package/es/components/Renderable.js +18 -0
- package/es/components/Sortable.d.ts +16 -0
- package/es/components/Sortable.js +15 -0
- package/es/components/Transform.d.ts +29 -0
- package/es/components/Transform.js +65 -0
- package/es/components/index.d.ts +5 -0
- package/es/components/index.js +5 -0
- package/es/display-objects/Circle.d.ts +12 -0
- package/es/display-objects/Circle.js +26 -0
- package/es/display-objects/CustomElement.d.ts +22 -0
- package/es/display-objects/CustomElement.js +76 -0
- package/es/display-objects/DisplayObject.d.ts +258 -0
- package/es/display-objects/DisplayObject.js +854 -0
- package/es/display-objects/Ellipse.d.ts +14 -0
- package/es/display-objects/Ellipse.js +27 -0
- package/es/display-objects/Group.d.ts +6 -0
- package/es/display-objects/Group.js +27 -0
- package/es/display-objects/HTML.d.ts +36 -0
- package/es/display-objects/HTML.js +93 -0
- package/es/display-objects/Image.d.ts +16 -0
- package/es/display-objects/Image.js +25 -0
- package/es/display-objects/Line.d.ts +23 -0
- package/es/display-objects/Line.js +56 -0
- package/es/display-objects/Path.d.ts +47 -0
- package/es/display-objects/Path.js +132 -0
- package/es/display-objects/Polygon.d.ts +12 -0
- package/es/display-objects/Polygon.js +25 -0
- package/es/display-objects/Polyline.d.ts +23 -0
- package/es/display-objects/Polyline.js +75 -0
- package/es/display-objects/Rect.d.ts +16 -0
- package/es/display-objects/Rect.js +26 -0
- package/es/display-objects/Text.d.ts +65 -0
- package/es/display-objects/Text.js +61 -0
- package/es/display-objects/index.d.ts +13 -0
- package/es/display-objects/index.js +13 -0
- package/es/dom/Animation.d.ts +132 -0
- package/es/dom/Animation.js +498 -0
- package/es/dom/AnimationEffectTiming.d.ts +59 -0
- package/es/dom/AnimationEffectTiming.js +68 -0
- package/es/dom/AnimationEvent.d.ts +11 -0
- package/es/dom/AnimationEvent.js +34 -0
- package/es/dom/AnimationTimeline.d.ts +37 -0
- package/es/dom/AnimationTimeline.js +217 -0
- package/es/dom/CustomElementRegistry.d.ts +15 -0
- package/es/dom/CustomElementRegistry.js +42 -0
- package/es/dom/CustomEvent.d.ts +16 -0
- package/es/dom/CustomEvent.js +34 -0
- package/es/dom/Document.d.ts +59 -0
- package/es/dom/Document.js +167 -0
- package/es/dom/Element.d.ts +150 -0
- package/es/dom/Element.js +490 -0
- package/es/dom/EventTarget.d.ts +40 -0
- package/es/dom/EventTarget.js +155 -0
- package/es/dom/FederatedEvent.d.ts +146 -0
- package/es/dom/FederatedEvent.js +232 -0
- package/es/dom/FederatedMouseEvent.d.ts +52 -0
- package/es/dom/FederatedMouseEvent.js +124 -0
- package/es/dom/FederatedPointerEvent.d.ts +69 -0
- package/es/dom/FederatedPointerEvent.js +53 -0
- package/es/dom/FederatedWheelEvent.d.ts +20 -0
- package/es/dom/FederatedWheelEvent.js +27 -0
- package/es/dom/KeyframeEffect.d.ts +47 -0
- package/es/dom/KeyframeEffect.js +174 -0
- package/es/dom/KeyframeList.d.ts +2 -0
- package/es/dom/KeyframeList.js +176 -0
- package/es/dom/Node.d.ts +106 -0
- package/es/dom/Node.js +214 -0
- package/es/dom/index.d.ts +17 -0
- package/es/dom/index.js +17 -0
- package/es/dom/interfaces.d.ts +324 -0
- package/es/dom/interfaces.js +32 -0
- package/es/global-module.d.ts +2 -0
- package/es/global-module.js +173 -0
- package/es/index.d.ts +15 -0
- package/es/index.js +18 -0
- package/es/plugins/CullingPlugin.d.ts +19 -0
- package/es/plugins/CullingPlugin.js +79 -0
- package/es/plugins/DirtyCheckPlugin.d.ts +10 -0
- package/es/plugins/DirtyCheckPlugin.js +52 -0
- package/es/plugins/EventPlugin.d.ts +26 -0
- package/es/plugins/EventPlugin.js +288 -0
- package/es/plugins/FrustumCullingStrategy.d.ts +21 -0
- package/es/plugins/FrustumCullingStrategy.js +101 -0
- package/es/plugins/PrepareRendererPlugin.d.ts +6 -0
- package/es/plugins/PrepareRendererPlugin.js +78 -0
- package/es/property-handlers/aabb.d.ts +2 -0
- package/es/property-handlers/aabb.js +135 -0
- package/es/property-handlers/anchor.d.ts +3 -0
- package/es/property-handlers/anchor.js +20 -0
- package/es/property-handlers/clipPath.d.ts +19 -0
- package/es/property-handlers/clipPath.js +36 -0
- package/es/property-handlers/color.d.ts +35 -0
- package/es/property-handlers/color.js +253 -0
- package/es/property-handlers/dimension.d.ts +18 -0
- package/es/property-handlers/dimension.js +123 -0
- package/es/property-handlers/filter.d.ts +9 -0
- package/es/property-handlers/filter.js +43 -0
- package/es/property-handlers/index.d.ts +18 -0
- package/es/property-handlers/index.js +18 -0
- package/es/property-handlers/interfaces.d.ts +20 -0
- package/es/property-handlers/interfaces.js +6 -0
- package/es/property-handlers/lineDash.d.ts +2 -0
- package/es/property-handlers/lineDash.js +8 -0
- package/es/property-handlers/localPosition.d.ts +2 -0
- package/es/property-handlers/localPosition.js +9 -0
- package/es/property-handlers/numeric.d.ts +5 -0
- package/es/property-handlers/numeric.js +34 -0
- package/es/property-handlers/offsetDistance.d.ts +5 -0
- package/es/property-handlers/offsetDistance.js +20 -0
- package/es/property-handlers/offsetPath.d.ts +5 -0
- package/es/property-handlers/offsetPath.js +18 -0
- package/es/property-handlers/origin.d.ts +11 -0
- package/es/property-handlers/origin.js +68 -0
- package/es/property-handlers/path.d.ts +5 -0
- package/es/property-handlers/path.js +200 -0
- package/es/property-handlers/points.d.ts +6 -0
- package/es/property-handlers/points.js +23 -0
- package/es/property-handlers/transform.d.ts +45 -0
- package/es/property-handlers/transform.js +416 -0
- package/es/property-handlers/zIndex.d.ts +2 -0
- package/es/property-handlers/zIndex.js +16 -0
- package/es/services/ContextService.d.ts +12 -0
- package/es/services/ContextService.js +5 -0
- package/es/services/EventService.d.ts +64 -0
- package/es/services/EventService.js +936 -0
- package/es/services/RenderingContext.d.ts +28 -0
- package/es/services/RenderingContext.js +13 -0
- package/es/services/RenderingService.d.ts +52 -0
- package/es/services/RenderingService.js +147 -0
- package/es/services/SceneGraphSelector.d.ts +20 -0
- package/es/services/SceneGraphSelector.js +64 -0
- package/es/services/SceneGraphService.d.ts +148 -0
- package/es/services/SceneGraphService.js +824 -0
- package/es/services/aabb/CircleUpdater.d.ts +10 -0
- package/es/services/aabb/CircleUpdater.js +35 -0
- package/es/services/aabb/EllipseUpdater.d.ts +10 -0
- package/es/services/aabb/EllipseUpdater.js +37 -0
- package/es/services/aabb/LineUpdater.d.ts +10 -0
- package/es/services/aabb/LineUpdater.js +39 -0
- package/es/services/aabb/PathUpdater.d.ts +11 -0
- package/es/services/aabb/PathUpdater.js +172 -0
- package/es/services/aabb/PolylineUpdater.d.ts +10 -0
- package/es/services/aabb/PolylineUpdater.js +48 -0
- package/es/services/aabb/RectUpdater.d.ts +10 -0
- package/es/services/aabb/RectUpdater.js +55 -0
- package/es/services/aabb/TextUpdater.d.ts +13 -0
- package/es/services/aabb/TextUpdater.js +81 -0
- package/es/services/aabb/index.d.ts +8 -0
- package/es/services/aabb/index.js +8 -0
- package/es/services/aabb/interfaces.d.ts +16 -0
- package/es/services/aabb/interfaces.js +2 -0
- package/es/services/index.d.ts +10 -0
- package/es/services/index.js +10 -0
- package/es/services/text/OffscreenCanvasCreator.d.ts +6 -0
- package/es/services/text/OffscreenCanvasCreator.js +47 -0
- package/es/services/text/index.d.ts +35 -0
- package/es/services/text/index.js +355 -0
- package/es/shapes/AABB.d.ts +33 -0
- package/es/shapes/AABB.js +217 -0
- package/es/shapes/BoundingSphere.d.ts +8 -0
- package/es/shapes/BoundingSphere.js +31 -0
- package/es/shapes/Frustum.d.ts +16 -0
- package/es/shapes/Frustum.js +79 -0
- package/es/shapes/Plane.d.ts +14 -0
- package/es/shapes/Plane.js +42 -0
- package/es/shapes/Point.d.ts +11 -0
- package/es/shapes/Point.js +31 -0
- package/es/shapes/Polygon.d.ts +9 -0
- package/es/shapes/Polygon.js +64 -0
- package/es/shapes/Ray.d.ts +24 -0
- package/es/shapes/Ray.js +138 -0
- package/es/shapes/Rect.d.ts +12 -0
- package/es/shapes/Rect.js +24 -0
- package/es/shapes/Rectangle.d.ts +12 -0
- package/es/shapes/Rectangle.js +20 -0
- package/es/shapes/index.d.ts +8 -0
- package/es/shapes/index.js +8 -0
- package/es/types.d.ts +220 -0
- package/es/types.js +17 -0
- package/es/utils/animation.d.ts +15 -0
- package/es/utils/animation.js +251 -0
- package/es/utils/bezier-easing.d.ts +20 -0
- package/es/utils/bezier-easing.js +90 -0
- package/es/utils/canvas.d.ts +5 -0
- package/es/utils/canvas.js +15 -0
- package/es/utils/custom-easing.d.ts +75 -0
- package/es/utils/custom-easing.js +332 -0
- package/es/utils/event.d.ts +11 -0
- package/es/utils/event.js +69 -0
- package/es/utils/index.d.ts +5 -0
- package/es/utils/index.js +5 -0
- package/es/utils/interpolation.d.ts +3 -0
- package/es/utils/interpolation.js +182 -0
- package/es/utils/math.d.ts +23 -0
- package/es/utils/math.js +166 -0
- package/es/utils/path.d.ts +15 -0
- package/es/utils/path.js +333 -0
- package/es/utils/raf.d.ts +3 -0
- package/es/utils/raf.js +15 -0
- package/es/utils/text.d.ts +2 -0
- package/es/utils/text.js +32 -0
- package/lib/AbstractRenderer.d.ts +26 -0
- package/lib/AbstractRenderer.js +49 -0
- package/lib/Canvas.d.ts +97 -0
- package/lib/Canvas.js +427 -0
- package/lib/DisplayObjectPool.d.ts +7 -0
- package/lib/DisplayObjectPool.js +35 -0
- package/lib/camera/Camera.d.ts +279 -0
- package/lib/camera/Camera.js +1047 -0
- package/lib/camera/Landmark.d.ts +28 -0
- package/lib/camera/Landmark.js +75 -0
- package/lib/camera/index.d.ts +2 -0
- package/lib/camera/index.js +31 -0
- package/lib/canvas-module.d.ts +1 -0
- package/lib/canvas-module.js +48 -0
- package/lib/components/Cullable.d.ts +14 -0
- package/lib/components/Cullable.js +36 -0
- package/lib/components/Geometry.d.ts +12 -0
- package/lib/components/Geometry.js +17 -0
- package/lib/components/Renderable.d.ts +24 -0
- package/lib/components/Renderable.js +25 -0
- package/lib/components/Sortable.d.ts +16 -0
- package/lib/components/Sortable.js +22 -0
- package/lib/components/Transform.d.ts +29 -0
- package/lib/components/Transform.js +72 -0
- package/lib/components/index.d.ts +5 -0
- package/lib/components/index.js +70 -0
- package/lib/display-objects/Circle.d.ts +12 -0
- package/lib/display-objects/Circle.js +34 -0
- package/lib/display-objects/CustomElement.d.ts +22 -0
- package/lib/display-objects/CustomElement.js +84 -0
- package/lib/display-objects/DisplayObject.d.ts +258 -0
- package/lib/display-objects/DisplayObject.js +874 -0
- package/lib/display-objects/Ellipse.d.ts +14 -0
- package/lib/display-objects/Ellipse.js +35 -0
- package/lib/display-objects/Group.d.ts +6 -0
- package/lib/display-objects/Group.js +36 -0
- package/lib/display-objects/HTML.d.ts +36 -0
- package/lib/display-objects/HTML.js +105 -0
- package/lib/display-objects/Image.d.ts +16 -0
- package/lib/display-objects/Image.js +33 -0
- package/lib/display-objects/Line.d.ts +23 -0
- package/lib/display-objects/Line.js +68 -0
- package/lib/display-objects/Path.d.ts +47 -0
- package/lib/display-objects/Path.js +143 -0
- package/lib/display-objects/Polygon.d.ts +12 -0
- package/lib/display-objects/Polygon.js +33 -0
- package/lib/display-objects/Polyline.d.ts +23 -0
- package/lib/display-objects/Polyline.js +85 -0
- package/lib/display-objects/Rect.d.ts +16 -0
- package/lib/display-objects/Rect.js +34 -0
- package/lib/display-objects/Text.d.ts +65 -0
- package/lib/display-objects/Text.js +69 -0
- package/lib/display-objects/index.d.ts +13 -0
- package/lib/display-objects/index.js +174 -0
- package/lib/dom/Animation.d.ts +132 -0
- package/lib/dom/Animation.js +506 -0
- package/lib/dom/AnimationEffectTiming.d.ts +59 -0
- package/lib/dom/AnimationEffectTiming.js +75 -0
- package/lib/dom/AnimationEvent.d.ts +11 -0
- package/lib/dom/AnimationEvent.js +42 -0
- package/lib/dom/AnimationTimeline.d.ts +37 -0
- package/lib/dom/AnimationTimeline.js +229 -0
- package/lib/dom/CustomElementRegistry.d.ts +15 -0
- package/lib/dom/CustomElementRegistry.js +50 -0
- package/lib/dom/CustomEvent.d.ts +16 -0
- package/lib/dom/CustomEvent.js +42 -0
- package/lib/dom/Document.d.ts +59 -0
- package/lib/dom/Document.js +177 -0
- package/lib/dom/Element.d.ts +150 -0
- package/lib/dom/Element.js +504 -0
- package/lib/dom/EventTarget.d.ts +40 -0
- package/lib/dom/EventTarget.js +169 -0
- package/lib/dom/FederatedEvent.d.ts +146 -0
- package/lib/dom/FederatedEvent.js +239 -0
- package/lib/dom/FederatedMouseEvent.d.ts +52 -0
- package/lib/dom/FederatedMouseEvent.js +133 -0
- package/lib/dom/FederatedPointerEvent.d.ts +69 -0
- package/lib/dom/FederatedPointerEvent.js +61 -0
- package/lib/dom/FederatedWheelEvent.d.ts +20 -0
- package/lib/dom/FederatedWheelEvent.js +35 -0
- package/lib/dom/KeyframeEffect.d.ts +47 -0
- package/lib/dom/KeyframeEffect.js +192 -0
- package/lib/dom/KeyframeList.d.ts +2 -0
- package/lib/dom/KeyframeList.js +183 -0
- package/lib/dom/Node.d.ts +106 -0
- package/lib/dom/Node.js +222 -0
- package/lib/dom/__tests__/utils/easing.d.ts +14 -0
- package/lib/dom/__tests__/utils/keyframe.d.ts +38 -0
- package/lib/dom/index.d.ts +17 -0
- package/lib/dom/index.js +226 -0
- package/lib/dom/interfaces.d.ts +324 -0
- package/lib/dom/interfaces.js +40 -0
- package/lib/global-module.d.ts +2 -0
- package/lib/global-module.js +192 -0
- package/lib/index.d.ts +14 -12
- package/lib/index.js +203 -24
- package/lib/plugins/CullingPlugin.d.ts +19 -0
- package/lib/plugins/CullingPlugin.js +90 -0
- package/lib/plugins/DirtyCheckPlugin.d.ts +10 -0
- package/lib/plugins/DirtyCheckPlugin.js +60 -0
- package/lib/plugins/EventPlugin.d.ts +26 -0
- package/lib/plugins/EventPlugin.js +297 -0
- package/lib/plugins/FrustumCullingStrategy.d.ts +21 -0
- package/lib/plugins/FrustumCullingStrategy.js +114 -0
- package/lib/plugins/PrepareRendererPlugin.d.ts +6 -0
- package/lib/plugins/PrepareRendererPlugin.js +86 -0
- package/lib/property-handlers/aabb.d.ts +2 -0
- package/lib/property-handlers/aabb.js +152 -0
- package/lib/property-handlers/anchor.d.ts +3 -0
- package/lib/property-handlers/anchor.js +32 -0
- package/lib/property-handlers/clipPath.d.ts +19 -0
- package/lib/property-handlers/clipPath.js +43 -0
- package/lib/property-handlers/color.d.ts +35 -0
- package/lib/property-handlers/color.js +274 -0
- package/lib/property-handlers/dimension.d.ts +18 -0
- package/lib/property-handlers/dimension.js +144 -0
- package/lib/property-handlers/filter.d.ts +9 -0
- package/lib/property-handlers/filter.js +56 -0
- package/lib/property-handlers/index.d.ts +18 -0
- package/lib/property-handlers/index.js +226 -0
- package/lib/property-handlers/interfaces.d.ts +20 -0
- package/lib/property-handlers/interfaces.js +18 -0
- package/lib/property-handlers/lineDash.d.ts +2 -0
- package/lib/property-handlers/lineDash.js +15 -0
- package/lib/property-handlers/localPosition.d.ts +2 -0
- package/lib/property-handlers/localPosition.js +16 -0
- package/lib/property-handlers/numeric.d.ts +5 -0
- package/lib/property-handlers/numeric.js +50 -0
- package/lib/property-handlers/offsetDistance.d.ts +5 -0
- package/lib/property-handlers/offsetDistance.js +27 -0
- package/lib/property-handlers/offsetPath.d.ts +5 -0
- package/lib/property-handlers/offsetPath.js +25 -0
- package/lib/property-handlers/origin.d.ts +11 -0
- package/lib/property-handlers/origin.js +79 -0
- package/lib/property-handlers/path.d.ts +5 -0
- package/lib/property-handlers/path.js +214 -0
- package/lib/property-handlers/points.d.ts +6 -0
- package/lib/property-handlers/points.js +33 -0
- package/lib/property-handlers/transform.d.ts +45 -0
- package/lib/property-handlers/transform.js +430 -0
- package/lib/property-handlers/zIndex.d.ts +2 -0
- package/lib/property-handlers/zIndex.js +23 -0
- package/lib/services/ContextService.d.ts +12 -0
- package/lib/services/ContextService.js +15 -0
- package/lib/services/EventService.d.ts +64 -0
- package/lib/services/EventService.js +960 -0
- package/lib/services/RenderingContext.d.ts +28 -0
- package/lib/services/RenderingContext.js +22 -0
- package/lib/services/RenderingService.d.ts +52 -0
- package/lib/services/RenderingService.js +159 -0
- package/lib/services/SceneGraphSelector.d.ts +20 -0
- package/lib/services/SceneGraphSelector.js +76 -0
- package/lib/services/SceneGraphService.d.ts +148 -0
- package/lib/services/SceneGraphService.js +871 -0
- package/lib/services/aabb/CircleUpdater.d.ts +10 -0
- package/lib/services/aabb/CircleUpdater.js +45 -0
- package/lib/services/aabb/EllipseUpdater.d.ts +10 -0
- package/lib/services/aabb/EllipseUpdater.js +47 -0
- package/lib/services/aabb/LineUpdater.d.ts +10 -0
- package/lib/services/aabb/LineUpdater.js +49 -0
- package/lib/services/aabb/PathUpdater.d.ts +11 -0
- package/lib/services/aabb/PathUpdater.js +183 -0
- package/lib/services/aabb/PolylineUpdater.d.ts +10 -0
- package/lib/services/aabb/PolylineUpdater.js +58 -0
- package/lib/services/aabb/RectUpdater.d.ts +10 -0
- package/lib/services/aabb/RectUpdater.js +66 -0
- package/lib/services/aabb/TextUpdater.d.ts +13 -0
- package/lib/services/aabb/TextUpdater.js +93 -0
- package/lib/services/aabb/index.d.ts +8 -0
- package/lib/services/aabb/index.js +84 -0
- package/lib/services/aabb/interfaces.d.ts +16 -0
- package/lib/services/aabb/interfaces.js +10 -0
- package/lib/services/index.d.ts +10 -0
- package/lib/services/index.js +122 -0
- package/lib/services/text/OffscreenCanvasCreator.d.ts +6 -0
- package/lib/services/text/OffscreenCanvasCreator.js +55 -0
- package/lib/services/text/index.d.ts +35 -0
- package/lib/services/text/index.js +364 -0
- package/lib/shapes/AABB.d.ts +33 -0
- package/lib/shapes/AABB.js +235 -0
- package/lib/shapes/BoundingSphere.d.ts +8 -0
- package/lib/shapes/BoundingSphere.js +41 -0
- package/lib/shapes/Frustum.d.ts +16 -0
- package/lib/shapes/Frustum.js +96 -0
- package/lib/shapes/Plane.d.ts +14 -0
- package/lib/shapes/Plane.js +51 -0
- package/lib/shapes/Point.d.ts +11 -0
- package/lib/shapes/Point.js +38 -0
- package/lib/shapes/Polygon.d.ts +9 -0
- package/lib/shapes/Polygon.js +71 -0
- package/lib/shapes/Ray.d.ts +24 -0
- package/lib/shapes/Ray.js +169 -0
- package/lib/shapes/Rect.d.ts +12 -0
- package/lib/shapes/Rect.js +31 -0
- package/lib/shapes/Rectangle.d.ts +12 -0
- package/lib/shapes/Rectangle.js +27 -0
- package/lib/shapes/index.d.ts +8 -13
- package/lib/shapes/index.js +108 -28
- package/lib/types.d.ts +220 -0
- package/lib/types.js +25 -0
- package/lib/utils/animation.d.ts +15 -0
- package/lib/utils/animation.js +275 -0
- package/lib/utils/bezier-easing.d.ts +20 -0
- package/lib/utils/bezier-easing.js +128 -0
- package/lib/utils/canvas.d.ts +5 -0
- package/lib/utils/canvas.js +21 -0
- package/lib/utils/custom-easing.d.ts +75 -0
- package/lib/utils/custom-easing.js +415 -0
- package/lib/utils/event.d.ts +11 -0
- package/lib/utils/event.js +88 -0
- package/lib/utils/index.d.ts +5 -0
- package/lib/utils/index.js +70 -0
- package/lib/utils/interpolation.d.ts +3 -0
- package/lib/utils/interpolation.js +197 -0
- package/lib/utils/math.d.ts +23 -0
- package/lib/utils/math.js +193 -0
- package/lib/utils/path.d.ts +15 -0
- package/lib/utils/path.js +359 -0
- package/lib/utils/raf.d.ts +3 -0
- package/lib/utils/raf.js +21 -0
- package/lib/utils/text.d.ts +2 -0
- package/lib/utils/text.js +41 -0
- package/package.json +35 -92
- package/dist/g.min.js +0 -17
- package/dist/g.min.js.map +0 -1
- package/esm/canvas.d.ts +0 -39
- package/esm/canvas.js +0 -378
- package/esm/canvas.js.map +0 -1
- package/esm/core/attribute.d.ts +0 -49
- package/esm/core/attribute.js +0 -277
- package/esm/core/attribute.js.map +0 -1
- package/esm/core/base.d.ts +0 -32
- package/esm/core/base.js +0 -190
- package/esm/core/base.js.map +0 -1
- package/esm/core/bbox.d.ts +0 -22
- package/esm/core/bbox.js +0 -34
- package/esm/core/bbox.js.map +0 -1
- package/esm/core/element.d.ts +0 -19
- package/esm/core/element.js +0 -203
- package/esm/core/element.js.map +0 -1
- package/esm/core/group.d.ts +0 -72
- package/esm/core/group.js +0 -437
- package/esm/core/group.js.map +0 -1
- package/esm/core/shape.d.ts +0 -35
- package/esm/core/shape.js +0 -158
- package/esm/core/shape.js.map +0 -1
- package/esm/core/timeline.d.ts +0 -15
- package/esm/core/timeline.js +0 -179
- package/esm/core/timeline.js.map +0 -1
- package/esm/event.d.ts +0 -25
- package/esm/event.js +0 -37
- package/esm/event.js.map +0 -1
- package/esm/index.d.ts +0 -13
- package/esm/index.js +0 -14
- package/esm/index.js.map +0 -1
- package/esm/interface.d.ts +0 -18
- package/esm/interface.js +0 -1
- package/esm/interface.js.map +0 -1
- package/esm/renderers/canvas/index.d.ts +0 -1
- package/esm/renderers/canvas/index.js +0 -2
- package/esm/renderers/canvas/index.js.map +0 -1
- package/esm/renderers/canvas/painter.d.ts +0 -17
- package/esm/renderers/canvas/painter.js +0 -152
- package/esm/renderers/canvas/painter.js.map +0 -1
- package/esm/renderers/canvas/util.d.ts +0 -2
- package/esm/renderers/canvas/util.js +0 -187
- package/esm/renderers/canvas/util.js.map +0 -1
- package/esm/renderers/index.d.ts +0 -3
- package/esm/renderers/index.js +0 -4
- package/esm/renderers/index.js.map +0 -1
- package/esm/renderers/svg/defs/arrow.d.ts +0 -15
- package/esm/renderers/svg/defs/arrow.js +0 -68
- package/esm/renderers/svg/defs/arrow.js.map +0 -1
- package/esm/renderers/svg/defs/clip.d.ts +0 -12
- package/esm/renderers/svg/defs/clip.js +0 -29
- package/esm/renderers/svg/defs/clip.js.map +0 -1
- package/esm/renderers/svg/defs/gradient.d.ts +0 -10
- package/esm/renderers/svg/defs/gradient.js +0 -117
- package/esm/renderers/svg/defs/gradient.js.map +0 -1
- package/esm/renderers/svg/defs/pattern.d.ts +0 -10
- package/esm/renderers/svg/defs/pattern.js +0 -46
- package/esm/renderers/svg/defs/pattern.js.map +0 -1
- package/esm/renderers/svg/defs/shadow.d.ts +0 -13
- package/esm/renderers/svg/defs/shadow.js +0 -62
- package/esm/renderers/svg/defs/shadow.js.map +0 -1
- package/esm/renderers/svg/defs.d.ts +0 -18
- package/esm/renderers/svg/defs.js +0 -90
- package/esm/renderers/svg/defs.js.map +0 -1
- package/esm/renderers/svg/get-shape.d.ts +0 -1
- package/esm/renderers/svg/get-shape.js +0 -28
- package/esm/renderers/svg/get-shape.js.map +0 -1
- package/esm/renderers/svg/index.d.ts +0 -2
- package/esm/renderers/svg/index.js +0 -3
- package/esm/renderers/svg/index.js.map +0 -1
- package/esm/renderers/svg/painter.d.ts +0 -32
- package/esm/renderers/svg/painter.js +0 -695
- package/esm/renderers/svg/painter.js.map +0 -1
- package/esm/shapes/arc.d.ts +0 -25
- package/esm/shapes/arc.js +0 -107
- package/esm/shapes/arc.js.map +0 -1
- package/esm/shapes/circle.d.ts +0 -17
- package/esm/shapes/circle.js +0 -62
- package/esm/shapes/circle.js.map +0 -1
- package/esm/shapes/dom.d.ts +0 -10
- package/esm/shapes/dom.js +0 -35
- package/esm/shapes/dom.js.map +0 -1
- package/esm/shapes/ellipse.d.ts +0 -18
- package/esm/shapes/ellipse.js +0 -88
- package/esm/shapes/ellipse.js.map +0 -1
- package/esm/shapes/fan.d.ts +0 -21
- package/esm/shapes/fan.js +0 -151
- package/esm/shapes/fan.js.map +0 -1
- package/esm/shapes/image.d.ts +0 -24
- package/esm/shapes/image.js +0 -154
- package/esm/shapes/image.js.map +0 -1
- package/esm/shapes/index.d.ts +0 -13
- package/esm/shapes/index.js +0 -14
- package/esm/shapes/index.js.map +0 -1
- package/esm/shapes/interface.d.ts +0 -3
- package/esm/shapes/interface.js +0 -1
- package/esm/shapes/interface.js.map +0 -1
- package/esm/shapes/line.d.ts +0 -22
- package/esm/shapes/line.js +0 -70
- package/esm/shapes/line.js.map +0 -1
- package/esm/shapes/marker/index.d.ts +0 -30
- package/esm/shapes/marker/index.js +0 -90
- package/esm/shapes/marker/index.js.map +0 -1
- package/esm/shapes/marker/symbols.d.ts +0 -14
- package/esm/shapes/marker/symbols.js +0 -39
- package/esm/shapes/marker/symbols.js.map +0 -1
- package/esm/shapes/math/arc.d.ts +0 -6
- package/esm/shapes/math/arc.js +0 -113
- package/esm/shapes/math/arc.js.map +0 -1
- package/esm/shapes/math/cubic.d.ts +0 -7
- package/esm/shapes/math/cubic.js +0 -141
- package/esm/shapes/math/cubic.js.map +0 -1
- package/esm/shapes/math/ellipse.d.ts +0 -4
- package/esm/shapes/math/ellipse.js +0 -13
- package/esm/shapes/math/ellipse.js.map +0 -1
- package/esm/shapes/math/line.d.ts +0 -5
- package/esm/shapes/math/line.js +0 -23
- package/esm/shapes/math/line.js.map +0 -1
- package/esm/shapes/math/quadratic.d.ts +0 -5
- package/esm/shapes/math/quadratic.js +0 -74
- package/esm/shapes/math/quadratic.js.map +0 -1
- package/esm/shapes/path.d.ts +0 -25
- package/esm/shapes/path.js +0 -270
- package/esm/shapes/path.js.map +0 -1
- package/esm/shapes/polygon.d.ts +0 -15
- package/esm/shapes/polygon.js +0 -103
- package/esm/shapes/polygon.js.map +0 -1
- package/esm/shapes/polyline.d.ts +0 -24
- package/esm/shapes/polyline.js +0 -171
- package/esm/shapes/polyline.js.map +0 -1
- package/esm/shapes/rect.d.ts +0 -19
- package/esm/shapes/rect.js +0 -107
- package/esm/shapes/rect.js.map +0 -1
- package/esm/shapes/text.d.ts +0 -35
- package/esm/shapes/text.js +0 -242
- package/esm/shapes/text.js.map +0 -1
- package/esm/shapes/util/arrow.d.ts +0 -3
- package/esm/shapes/util/arrow.js +0 -131
- package/esm/shapes/util/arrow.js.map +0 -1
- package/esm/shapes/util/inside.d.ts +0 -9
- package/esm/shapes/util/inside.js +0 -50
- package/esm/shapes/util/inside.js.map +0 -1
- package/esm/shapes/util/is-point-in-path-by-ctx.d.ts +0 -2
- package/esm/shapes/util/is-point-in-path-by-ctx.js +0 -8
- package/esm/shapes/util/is-point-in-path-by-ctx.js.map +0 -1
- package/esm/shapes/util/path-segment.d.ts +0 -18
- package/esm/shapes/util/path-segment.js +0 -594
- package/esm/shapes/util/path-segment.js.map +0 -1
- package/esm/util/format.d.ts +0 -7
- package/esm/util/format.js +0 -60
- package/esm/util/format.js.map +0 -1
- package/esm/util/path.d.ts +0 -11
- package/esm/util/path.js +0 -1327
- package/esm/util/path.js.map +0 -1
- package/lib/canvas.d.ts +0 -39
- package/lib/canvas.js +0 -380
- package/lib/canvas.js.map +0 -1
- package/lib/core/attribute.d.ts +0 -49
- package/lib/core/attribute.js +0 -279
- package/lib/core/attribute.js.map +0 -1
- package/lib/core/base.d.ts +0 -32
- package/lib/core/base.js +0 -192
- package/lib/core/base.js.map +0 -1
- package/lib/core/bbox.d.ts +0 -22
- package/lib/core/bbox.js +0 -36
- package/lib/core/bbox.js.map +0 -1
- package/lib/core/element.d.ts +0 -19
- package/lib/core/element.js +0 -205
- package/lib/core/element.js.map +0 -1
- package/lib/core/group.d.ts +0 -72
- package/lib/core/group.js +0 -439
- package/lib/core/group.js.map +0 -1
- package/lib/core/shape.d.ts +0 -35
- package/lib/core/shape.js +0 -160
- package/lib/core/shape.js.map +0 -1
- package/lib/core/timeline.d.ts +0 -15
- package/lib/core/timeline.js +0 -181
- package/lib/core/timeline.js.map +0 -1
- package/lib/event.d.ts +0 -25
- package/lib/event.js +0 -39
- package/lib/event.js.map +0 -1
- package/lib/index.js.map +0 -1
- package/lib/interface.d.ts +0 -18
- package/lib/interface.js +0 -3
- package/lib/interface.js.map +0 -1
- package/lib/renderers/canvas/index.d.ts +0 -1
- package/lib/renderers/canvas/index.js +0 -5
- package/lib/renderers/canvas/index.js.map +0 -1
- package/lib/renderers/canvas/painter.d.ts +0 -17
- package/lib/renderers/canvas/painter.js +0 -154
- package/lib/renderers/canvas/painter.js.map +0 -1
- package/lib/renderers/canvas/util.d.ts +0 -2
- package/lib/renderers/canvas/util.js +0 -191
- package/lib/renderers/canvas/util.js.map +0 -1
- package/lib/renderers/index.d.ts +0 -3
- package/lib/renderers/index.js +0 -7
- package/lib/renderers/index.js.map +0 -1
- package/lib/renderers/svg/defs/arrow.d.ts +0 -15
- package/lib/renderers/svg/defs/arrow.js +0 -70
- package/lib/renderers/svg/defs/arrow.js.map +0 -1
- package/lib/renderers/svg/defs/clip.d.ts +0 -12
- package/lib/renderers/svg/defs/clip.js +0 -31
- package/lib/renderers/svg/defs/clip.js.map +0 -1
- package/lib/renderers/svg/defs/gradient.d.ts +0 -10
- package/lib/renderers/svg/defs/gradient.js +0 -119
- package/lib/renderers/svg/defs/gradient.js.map +0 -1
- package/lib/renderers/svg/defs/pattern.d.ts +0 -10
- package/lib/renderers/svg/defs/pattern.js +0 -48
- package/lib/renderers/svg/defs/pattern.js.map +0 -1
- package/lib/renderers/svg/defs/shadow.d.ts +0 -13
- package/lib/renderers/svg/defs/shadow.js +0 -64
- package/lib/renderers/svg/defs/shadow.js.map +0 -1
- package/lib/renderers/svg/defs.d.ts +0 -18
- package/lib/renderers/svg/defs.js +0 -92
- package/lib/renderers/svg/defs.js.map +0 -1
- package/lib/renderers/svg/get-shape.d.ts +0 -1
- package/lib/renderers/svg/get-shape.js +0 -31
- package/lib/renderers/svg/get-shape.js.map +0 -1
- package/lib/renderers/svg/index.d.ts +0 -2
- package/lib/renderers/svg/index.js +0 -7
- package/lib/renderers/svg/index.js.map +0 -1
- package/lib/renderers/svg/painter.d.ts +0 -32
- package/lib/renderers/svg/painter.js +0 -697
- package/lib/renderers/svg/painter.js.map +0 -1
- package/lib/shapes/arc.d.ts +0 -25
- package/lib/shapes/arc.js +0 -109
- package/lib/shapes/arc.js.map +0 -1
- package/lib/shapes/circle.d.ts +0 -17
- package/lib/shapes/circle.js +0 -64
- package/lib/shapes/circle.js.map +0 -1
- package/lib/shapes/dom.d.ts +0 -10
- package/lib/shapes/dom.js +0 -37
- package/lib/shapes/dom.js.map +0 -1
- package/lib/shapes/ellipse.d.ts +0 -18
- package/lib/shapes/ellipse.js +0 -90
- package/lib/shapes/ellipse.js.map +0 -1
- package/lib/shapes/fan.d.ts +0 -21
- package/lib/shapes/fan.js +0 -153
- package/lib/shapes/fan.js.map +0 -1
- package/lib/shapes/image.d.ts +0 -24
- package/lib/shapes/image.js +0 -156
- package/lib/shapes/image.js.map +0 -1
- package/lib/shapes/index.js.map +0 -1
- package/lib/shapes/interface.d.ts +0 -3
- package/lib/shapes/interface.js +0 -3
- package/lib/shapes/interface.js.map +0 -1
- package/lib/shapes/line.d.ts +0 -22
- package/lib/shapes/line.js +0 -72
- package/lib/shapes/line.js.map +0 -1
- package/lib/shapes/marker/index.d.ts +0 -30
- package/lib/shapes/marker/index.js +0 -92
- package/lib/shapes/marker/index.js.map +0 -1
- package/lib/shapes/marker/symbols.d.ts +0 -14
- package/lib/shapes/marker/symbols.js +0 -41
- package/lib/shapes/marker/symbols.js.map +0 -1
- package/lib/shapes/math/arc.d.ts +0 -6
- package/lib/shapes/math/arc.js +0 -115
- package/lib/shapes/math/arc.js.map +0 -1
- package/lib/shapes/math/cubic.d.ts +0 -7
- package/lib/shapes/math/cubic.js +0 -148
- package/lib/shapes/math/cubic.js.map +0 -1
- package/lib/shapes/math/ellipse.d.ts +0 -4
- package/lib/shapes/math/ellipse.js +0 -19
- package/lib/shapes/math/ellipse.js.map +0 -1
- package/lib/shapes/math/line.d.ts +0 -5
- package/lib/shapes/math/line.js +0 -29
- package/lib/shapes/math/line.js.map +0 -1
- package/lib/shapes/math/quadratic.d.ts +0 -5
- package/lib/shapes/math/quadratic.js +0 -80
- package/lib/shapes/math/quadratic.js.map +0 -1
- package/lib/shapes/path.d.ts +0 -25
- package/lib/shapes/path.js +0 -272
- package/lib/shapes/path.js.map +0 -1
- package/lib/shapes/polygon.d.ts +0 -15
- package/lib/shapes/polygon.js +0 -105
- package/lib/shapes/polygon.js.map +0 -1
- package/lib/shapes/polyline.d.ts +0 -24
- package/lib/shapes/polyline.js +0 -173
- package/lib/shapes/polyline.js.map +0 -1
- package/lib/shapes/rect.d.ts +0 -19
- package/lib/shapes/rect.js +0 -109
- package/lib/shapes/rect.js.map +0 -1
- package/lib/shapes/text.d.ts +0 -35
- package/lib/shapes/text.js +0 -244
- package/lib/shapes/text.js.map +0 -1
- package/lib/shapes/util/arrow.d.ts +0 -3
- package/lib/shapes/util/arrow.js +0 -135
- package/lib/shapes/util/arrow.js.map +0 -1
- package/lib/shapes/util/inside.d.ts +0 -9
- package/lib/shapes/util/inside.js +0 -60
- package/lib/shapes/util/inside.js.map +0 -1
- package/lib/shapes/util/is-point-in-path-by-ctx.d.ts +0 -2
- package/lib/shapes/util/is-point-in-path-by-ctx.js +0 -11
- package/lib/shapes/util/is-point-in-path-by-ctx.js.map +0 -1
- package/lib/shapes/util/path-segment.d.ts +0 -18
- package/lib/shapes/util/path-segment.js +0 -596
- package/lib/shapes/util/path-segment.js.map +0 -1
- package/lib/util/format.d.ts +0 -7
- package/lib/util/format.js +0 -64
- package/lib/util/format.js.map +0 -1
- package/lib/util/path.d.ts +0 -11
- package/lib/util/path.js +0 -1338
- package/lib/util/path.js.map +0 -1
|
@@ -0,0 +1,364 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
Object.defineProperty(exports, "__esModule", {
|
|
4
|
+
value: true
|
|
5
|
+
});
|
|
6
|
+
exports.TextService = void 0;
|
|
7
|
+
|
|
8
|
+
var _tslib = require("tslib");
|
|
9
|
+
|
|
10
|
+
var _manaSyringe = require("mana-syringe");
|
|
11
|
+
|
|
12
|
+
var _shapes = require("../../shapes");
|
|
13
|
+
|
|
14
|
+
var _text = require("../../utils/text");
|
|
15
|
+
|
|
16
|
+
var _OffscreenCanvasCreator = require("./OffscreenCanvasCreator");
|
|
17
|
+
|
|
18
|
+
var TEXT_METRICS = {
|
|
19
|
+
MetricsString: '|ÉqÅ',
|
|
20
|
+
BaselineSymbol: 'M',
|
|
21
|
+
BaselineMultiplier: 1.4,
|
|
22
|
+
HeightMultiplier: 2,
|
|
23
|
+
Newlines: [0x000a, 0x000d // carriage return
|
|
24
|
+
],
|
|
25
|
+
BreakingSpaces: [0x0009, 0x0020, 0x2000, 0x2001, 0x2002, 0x2003, 0x2004, 0x2005, 0x2006, 0x2008, 0x2009, 0x200a, 0x205f, 0x3000 // ideographic space
|
|
26
|
+
]
|
|
27
|
+
};
|
|
28
|
+
var LATIN_REGEX = /[a-zA-Z0-9\u00C0-\u00D6\u00D8-\u00f6\u00f8-\u00ff!"#$%&'()*+,-./:;]/; // Line breaking rules in CJK (Kinsoku Shori)
|
|
29
|
+
// Refer from https://en.wikipedia.org/wiki/Line_breaking_rules_in_East_Asian_languages
|
|
30
|
+
|
|
31
|
+
var regexCannotStartZhCn = /[!%),.:;?\]}¢°·'""†‡›℃∶、。〃〆〕〗〞﹚﹜!"%'),.:;?!]}~]/;
|
|
32
|
+
var regexCannotEndZhCn = /[$(£¥·'"〈《「『【〔〖〝﹙﹛$(.[{£¥]/;
|
|
33
|
+
var regexCannotStartZhTw = /[!),.:;?\]}¢·–—'"•"、。〆〞〕〉》」︰︱︲︳﹐﹑﹒﹔﹕﹖﹘﹚﹜!),.:;?︶︸︺︼︾﹀﹂﹗]|}、]/;
|
|
34
|
+
var regexCannotEndZhTw = /[([{£¥'"‵〈《「『〔〝︴﹙﹛({︵︷︹︻︽︿﹁﹃﹏]/;
|
|
35
|
+
var regexCannotStartJaJp = /[)\]}〕〉》」』】〙〗〟'"⦆»ヽヾーァィゥェォッャュョヮヵヶぁぃぅぇぉっゃゅょゎゕゖㇰㇱㇲㇳㇴㇵㇶㇷㇸㇹㇺㇻㇼㇽㇾㇿ々〻‐゠–〜?!‼⁇⁈⁉・、:;,。.]/;
|
|
36
|
+
var regexCannotEndJaJp = /[([{〔〈《「『【〘〖〝'"⦅«—...‥〳〴〵]/;
|
|
37
|
+
var regexCannotStartKoKr = /[!%),.:;?\]}¢°'"†‡℃〆〈《「『〕!%),.:;?]}]/;
|
|
38
|
+
var regexCannotEndKoKr = /[$([{£¥'"々〇〉》」〔$([{⦆¥₩#]/;
|
|
39
|
+
var regexCannotStart = new RegExp(regexCannotStartZhCn.source + "|" + regexCannotStartZhTw.source + "|" + regexCannotStartJaJp.source + "|" + regexCannotStartKoKr.source);
|
|
40
|
+
var regexCannotEnd = new RegExp(regexCannotEndZhCn.source + "|" + regexCannotEndZhTw.source + "|" + regexCannotEndJaJp.source + "|" + regexCannotEndKoKr.source);
|
|
41
|
+
|
|
42
|
+
var TextService =
|
|
43
|
+
/** @class */
|
|
44
|
+
function () {
|
|
45
|
+
function TextService() {
|
|
46
|
+
var _this = this;
|
|
47
|
+
|
|
48
|
+
this.cache = {};
|
|
49
|
+
|
|
50
|
+
this.shouldBreakByKinsokuShorui = function (char, nextChar) {
|
|
51
|
+
if (_this.isBreakingSpace(nextChar)) return false;
|
|
52
|
+
|
|
53
|
+
if (char) {
|
|
54
|
+
// Line breaking rules in CJK (Kinsoku Shori)
|
|
55
|
+
if (regexCannotEnd.exec(nextChar) || regexCannotStart.exec(char)) {
|
|
56
|
+
return true;
|
|
57
|
+
}
|
|
58
|
+
}
|
|
59
|
+
|
|
60
|
+
return false;
|
|
61
|
+
};
|
|
62
|
+
|
|
63
|
+
this.trimByKinsokuShorui = function (prev) {
|
|
64
|
+
var next = (0, _tslib.__spreadArray)([], (0, _tslib.__read)(prev), false);
|
|
65
|
+
var prevLine = next[next.length - 2];
|
|
66
|
+
|
|
67
|
+
if (!prevLine) {
|
|
68
|
+
return prev;
|
|
69
|
+
}
|
|
70
|
+
|
|
71
|
+
var lastChar = prevLine[prevLine.length - 1];
|
|
72
|
+
next[next.length - 2] = prevLine.slice(0, -1);
|
|
73
|
+
next[next.length - 1] = lastChar + next[next.length - 1];
|
|
74
|
+
return next;
|
|
75
|
+
};
|
|
76
|
+
}
|
|
77
|
+
|
|
78
|
+
TextService.prototype.measureFont = function (font) {
|
|
79
|
+
// as this method is used for preparing assets, don't recalculate things if we don't need to
|
|
80
|
+
if (this.cache[font]) {
|
|
81
|
+
return this.cache[font];
|
|
82
|
+
}
|
|
83
|
+
|
|
84
|
+
var properties = {
|
|
85
|
+
ascent: 0,
|
|
86
|
+
descent: 0,
|
|
87
|
+
fontSize: 0
|
|
88
|
+
};
|
|
89
|
+
var canvas = this.offscreenCanvas.getOrCreateCanvas();
|
|
90
|
+
var context = this.offscreenCanvas.getOrCreateContext();
|
|
91
|
+
context.font = font;
|
|
92
|
+
var metricsString = TEXT_METRICS.MetricsString + TEXT_METRICS.BaselineSymbol;
|
|
93
|
+
var width = Math.ceil(context.measureText(metricsString).width);
|
|
94
|
+
var baseline = Math.ceil(context.measureText(TEXT_METRICS.BaselineSymbol).width);
|
|
95
|
+
var height = TEXT_METRICS.HeightMultiplier * baseline;
|
|
96
|
+
baseline = baseline * TEXT_METRICS.BaselineMultiplier | 0; // @ts-ignore
|
|
97
|
+
|
|
98
|
+
canvas.width = width; // @ts-ignore
|
|
99
|
+
|
|
100
|
+
canvas.height = height;
|
|
101
|
+
context.fillStyle = '#f00';
|
|
102
|
+
context.fillRect(0, 0, width, height);
|
|
103
|
+
context.font = font;
|
|
104
|
+
context.textBaseline = 'alphabetic';
|
|
105
|
+
context.fillStyle = '#000';
|
|
106
|
+
context.fillText(metricsString, 0, baseline);
|
|
107
|
+
var imagedata = context.getImageData(0, 0, width, height).data;
|
|
108
|
+
var pixels = imagedata.length;
|
|
109
|
+
var line = width * 4;
|
|
110
|
+
var i = 0;
|
|
111
|
+
var idx = 0;
|
|
112
|
+
var stop = false; // ascent. scan from top to bottom until we find a non red pixel
|
|
113
|
+
|
|
114
|
+
for (i = 0; i < baseline; ++i) {
|
|
115
|
+
for (var j = 0; j < line; j += 4) {
|
|
116
|
+
if (imagedata[idx + j] !== 255) {
|
|
117
|
+
stop = true;
|
|
118
|
+
break;
|
|
119
|
+
}
|
|
120
|
+
}
|
|
121
|
+
|
|
122
|
+
if (!stop) {
|
|
123
|
+
idx += line;
|
|
124
|
+
} else {
|
|
125
|
+
break;
|
|
126
|
+
}
|
|
127
|
+
}
|
|
128
|
+
|
|
129
|
+
properties.ascent = baseline - i;
|
|
130
|
+
idx = pixels - line;
|
|
131
|
+
stop = false; // descent. scan from bottom to top until we find a non red pixel
|
|
132
|
+
|
|
133
|
+
for (i = height; i > baseline; --i) {
|
|
134
|
+
for (var j = 0; j < line; j += 4) {
|
|
135
|
+
if (imagedata[idx + j] !== 255) {
|
|
136
|
+
stop = true;
|
|
137
|
+
break;
|
|
138
|
+
}
|
|
139
|
+
}
|
|
140
|
+
|
|
141
|
+
if (!stop) {
|
|
142
|
+
idx -= line;
|
|
143
|
+
} else {
|
|
144
|
+
break;
|
|
145
|
+
}
|
|
146
|
+
}
|
|
147
|
+
|
|
148
|
+
properties.descent = i - baseline;
|
|
149
|
+
properties.fontSize = properties.ascent + properties.descent;
|
|
150
|
+
this.cache[font] = properties;
|
|
151
|
+
return properties;
|
|
152
|
+
};
|
|
153
|
+
|
|
154
|
+
TextService.prototype.measureText = function (text, attributes) {
|
|
155
|
+
var _a = attributes.fontSize,
|
|
156
|
+
fontSize = _a === void 0 ? 0 : _a,
|
|
157
|
+
wordWrap = attributes.wordWrap,
|
|
158
|
+
_b = attributes.lineHeight,
|
|
159
|
+
strokeHeight = _b === void 0 ? 0 : _b,
|
|
160
|
+
_c = attributes.lineWidth,
|
|
161
|
+
lineWidth = _c === void 0 ? 0 : _c,
|
|
162
|
+
textBaseline = attributes.textBaseline,
|
|
163
|
+
textAlign = attributes.textAlign,
|
|
164
|
+
_d = attributes.letterSpacing,
|
|
165
|
+
letterSpacing = _d === void 0 ? 0 : _d,
|
|
166
|
+
dropShadow = attributes.dropShadow,
|
|
167
|
+
_e = attributes.dropShadowDistance,
|
|
168
|
+
dropShadowDistance = _e === void 0 ? 0 : _e,
|
|
169
|
+
_f = attributes.leading,
|
|
170
|
+
leading = _f === void 0 ? 0 : _f;
|
|
171
|
+
var font = (0, _text.toFontString)(attributes);
|
|
172
|
+
var fontProperties = this.measureFont(font); // fallback in case UA disallow canvas data extraction
|
|
173
|
+
// (toDataURI, getImageData functions)
|
|
174
|
+
|
|
175
|
+
if (fontProperties.fontSize === 0) {
|
|
176
|
+
fontProperties.fontSize = fontSize;
|
|
177
|
+
fontProperties.ascent = fontSize;
|
|
178
|
+
}
|
|
179
|
+
|
|
180
|
+
var context = this.offscreenCanvas.getOrCreateContext();
|
|
181
|
+
context.font = font;
|
|
182
|
+
var outputText = wordWrap ? this.wordWrap(text, attributes) : text;
|
|
183
|
+
var lines = outputText.split(/(?:\r\n|\r|\n)/);
|
|
184
|
+
var lineWidths = new Array(lines.length);
|
|
185
|
+
var maxLineWidth = 0;
|
|
186
|
+
|
|
187
|
+
for (var i = 0; i < lines.length; i++) {
|
|
188
|
+
var lineWidth_1 = context.measureText(lines[i]).width + (lines[i].length - 1) * letterSpacing;
|
|
189
|
+
lineWidths[i] = lineWidth_1;
|
|
190
|
+
maxLineWidth = Math.max(maxLineWidth, lineWidth_1);
|
|
191
|
+
}
|
|
192
|
+
|
|
193
|
+
var width = maxLineWidth + lineWidth;
|
|
194
|
+
|
|
195
|
+
if (dropShadow) {
|
|
196
|
+
width += dropShadowDistance;
|
|
197
|
+
}
|
|
198
|
+
|
|
199
|
+
var lineHeight = strokeHeight || fontProperties.fontSize + lineWidth;
|
|
200
|
+
var height = Math.max(lineHeight, fontProperties.fontSize + lineWidth) + (lines.length - 1) * (lineHeight + leading);
|
|
201
|
+
|
|
202
|
+
if (dropShadow) {
|
|
203
|
+
height += dropShadowDistance;
|
|
204
|
+
}
|
|
205
|
+
|
|
206
|
+
lineHeight += leading; // handle vertical text baseline
|
|
207
|
+
|
|
208
|
+
var offsetY = 0;
|
|
209
|
+
|
|
210
|
+
if (textBaseline === 'middle') {
|
|
211
|
+
offsetY = -height / 2;
|
|
212
|
+
} else if (textBaseline === 'bottom' || textBaseline === 'alphabetic' || textBaseline === 'ideographic') {
|
|
213
|
+
offsetY = -height;
|
|
214
|
+
} else if (textBaseline === 'top' || textBaseline === 'hanging') {
|
|
215
|
+
offsetY = 0;
|
|
216
|
+
}
|
|
217
|
+
|
|
218
|
+
return {
|
|
219
|
+
font: font,
|
|
220
|
+
width: width,
|
|
221
|
+
height: height,
|
|
222
|
+
lines: lines,
|
|
223
|
+
lineWidths: lineWidths,
|
|
224
|
+
lineHeight: lineHeight,
|
|
225
|
+
maxLineWidth: maxLineWidth,
|
|
226
|
+
fontProperties: fontProperties,
|
|
227
|
+
lineMetrics: lineWidths.map(function (width, i) {
|
|
228
|
+
var offsetX = 0; // handle horizontal text align
|
|
229
|
+
|
|
230
|
+
if (textAlign === 'center') {
|
|
231
|
+
offsetX -= width / 2;
|
|
232
|
+
} else if (textAlign === 'right' || textAlign === 'end') {
|
|
233
|
+
offsetX -= width;
|
|
234
|
+
}
|
|
235
|
+
|
|
236
|
+
return new _shapes.Rectangle(offsetX - lineWidth / 2, offsetY + i * lineHeight, width + lineWidth, lineHeight);
|
|
237
|
+
})
|
|
238
|
+
};
|
|
239
|
+
};
|
|
240
|
+
|
|
241
|
+
TextService.prototype.wordWrap = function (text, _a) {
|
|
242
|
+
var _this = this;
|
|
243
|
+
|
|
244
|
+
var _b = _a.wordWrapWidth,
|
|
245
|
+
wordWrapWidth = _b === void 0 ? 0 : _b,
|
|
246
|
+
_c = _a.letterSpacing,
|
|
247
|
+
letterSpacing = _c === void 0 ? 0 : _c;
|
|
248
|
+
var context = this.offscreenCanvas.getOrCreateContext();
|
|
249
|
+
var maxWidth = wordWrapWidth + letterSpacing;
|
|
250
|
+
var lines = [];
|
|
251
|
+
var currentIndex = 0;
|
|
252
|
+
var currentWidth = 0;
|
|
253
|
+
var cache = {};
|
|
254
|
+
|
|
255
|
+
var calcWidth = function calcWidth(char) {
|
|
256
|
+
return _this.getFromCache(char, letterSpacing, cache, context);
|
|
257
|
+
};
|
|
258
|
+
|
|
259
|
+
Array.from(text).forEach(function (char, i) {
|
|
260
|
+
var prevChar = text[i - 1];
|
|
261
|
+
var nextChar = text[i + 1];
|
|
262
|
+
var width = calcWidth(char);
|
|
263
|
+
|
|
264
|
+
if (_this.isNewline(char)) {
|
|
265
|
+
currentIndex++;
|
|
266
|
+
currentWidth = 0;
|
|
267
|
+
lines[currentIndex] = '';
|
|
268
|
+
return;
|
|
269
|
+
}
|
|
270
|
+
|
|
271
|
+
if (currentWidth > 0 && currentWidth + width > maxWidth) {
|
|
272
|
+
currentIndex++;
|
|
273
|
+
currentWidth = 0;
|
|
274
|
+
lines[currentIndex] = '';
|
|
275
|
+
|
|
276
|
+
if (_this.isBreakingSpace(char)) {
|
|
277
|
+
return;
|
|
278
|
+
}
|
|
279
|
+
|
|
280
|
+
if (!_this.canBreakInLastChar(char)) {
|
|
281
|
+
lines = _this.trimToBreakable(lines);
|
|
282
|
+
currentWidth = _this.sumTextWidthByCache(lines[currentIndex] || '', cache);
|
|
283
|
+
}
|
|
284
|
+
|
|
285
|
+
if (_this.shouldBreakByKinsokuShorui(char, nextChar)) {
|
|
286
|
+
lines = _this.trimByKinsokuShorui(lines);
|
|
287
|
+
currentWidth += calcWidth(prevChar || '');
|
|
288
|
+
}
|
|
289
|
+
}
|
|
290
|
+
|
|
291
|
+
currentWidth += width;
|
|
292
|
+
lines[currentIndex] = (lines[currentIndex] || '') + char;
|
|
293
|
+
});
|
|
294
|
+
return lines.join('\n');
|
|
295
|
+
};
|
|
296
|
+
|
|
297
|
+
TextService.prototype.isBreakingSpace = function (char, _nextChar) {
|
|
298
|
+
if (typeof char !== 'string') {
|
|
299
|
+
return false;
|
|
300
|
+
}
|
|
301
|
+
|
|
302
|
+
return TEXT_METRICS.BreakingSpaces.indexOf(char.charCodeAt(0)) >= 0;
|
|
303
|
+
};
|
|
304
|
+
|
|
305
|
+
TextService.prototype.isNewline = function (char) {
|
|
306
|
+
if (typeof char !== 'string') {
|
|
307
|
+
return false;
|
|
308
|
+
}
|
|
309
|
+
|
|
310
|
+
return TEXT_METRICS.Newlines.indexOf(char.charCodeAt(0)) >= 0;
|
|
311
|
+
};
|
|
312
|
+
|
|
313
|
+
TextService.prototype.trimToBreakable = function (prev) {
|
|
314
|
+
var next = (0, _tslib.__spreadArray)([], (0, _tslib.__read)(prev), false);
|
|
315
|
+
var prevLine = next[next.length - 2];
|
|
316
|
+
var index = this.findBreakableIndex(prevLine);
|
|
317
|
+
if (index === -1 || !prevLine) return next;
|
|
318
|
+
var trimmedChar = prevLine.slice(index, index + 1);
|
|
319
|
+
var isTrimmedWithSpace = this.isBreakingSpace(trimmedChar);
|
|
320
|
+
var trimFrom = index + 1;
|
|
321
|
+
var trimTo = index + (isTrimmedWithSpace ? 0 : 1);
|
|
322
|
+
next[next.length - 1] += prevLine.slice(trimFrom, prevLine.length);
|
|
323
|
+
next[next.length - 2] = prevLine.slice(0, trimTo);
|
|
324
|
+
return next;
|
|
325
|
+
};
|
|
326
|
+
|
|
327
|
+
TextService.prototype.canBreakInLastChar = function (char) {
|
|
328
|
+
if (char && LATIN_REGEX.test(char)) return false;
|
|
329
|
+
return true;
|
|
330
|
+
};
|
|
331
|
+
|
|
332
|
+
TextService.prototype.sumTextWidthByCache = function (text, cache) {
|
|
333
|
+
return text.split('').reduce(function (sum, c) {
|
|
334
|
+
if (!cache[c]) throw Error('cannot count the word without cache');
|
|
335
|
+
return sum + cache[c];
|
|
336
|
+
}, 0);
|
|
337
|
+
};
|
|
338
|
+
|
|
339
|
+
TextService.prototype.findBreakableIndex = function (line) {
|
|
340
|
+
for (var i = line.length - 1; i >= 0; i--) {
|
|
341
|
+
if (!LATIN_REGEX.test(line[i])) return i;
|
|
342
|
+
}
|
|
343
|
+
|
|
344
|
+
return -1;
|
|
345
|
+
};
|
|
346
|
+
|
|
347
|
+
TextService.prototype.getFromCache = function (key, letterSpacing, cache, context) {
|
|
348
|
+
var width = cache[key];
|
|
349
|
+
|
|
350
|
+
if (typeof width !== 'number') {
|
|
351
|
+
var spacing = key.length * letterSpacing;
|
|
352
|
+
width = context.measureText(key).width + spacing;
|
|
353
|
+
cache[key] = width;
|
|
354
|
+
}
|
|
355
|
+
|
|
356
|
+
return width;
|
|
357
|
+
};
|
|
358
|
+
|
|
359
|
+
(0, _tslib.__decorate)([(0, _manaSyringe.inject)(_OffscreenCanvasCreator.OffscreenCanvasCreator), (0, _tslib.__metadata)("design:type", _OffscreenCanvasCreator.OffscreenCanvasCreator)], TextService.prototype, "offscreenCanvas", void 0);
|
|
360
|
+
TextService = (0, _tslib.__decorate)([(0, _manaSyringe.singleton)()], TextService);
|
|
361
|
+
return TextService;
|
|
362
|
+
}();
|
|
363
|
+
|
|
364
|
+
exports.TextService = TextService;
|
|
@@ -0,0 +1,33 @@
|
|
|
1
|
+
import { mat4, vec3 } from 'gl-matrix';
|
|
2
|
+
import { Plane } from './Plane';
|
|
3
|
+
/**
|
|
4
|
+
* Axis-Aligned Bounding Box
|
|
5
|
+
* 为了便于后续 Frustum Culling,通过查找表定义 p-vertex 和 n-vertex
|
|
6
|
+
* @see https://github.com/antvis/GWebGPUEngine/issues/3
|
|
7
|
+
*/
|
|
8
|
+
export declare class AABB {
|
|
9
|
+
center: vec3;
|
|
10
|
+
halfExtents: vec3;
|
|
11
|
+
min: vec3;
|
|
12
|
+
max: vec3;
|
|
13
|
+
constructor(center?: vec3, halfExtents?: vec3);
|
|
14
|
+
update(center?: vec3, halfExtents?: vec3): void;
|
|
15
|
+
setMinMax(min: vec3, max: vec3): void;
|
|
16
|
+
getMin(): vec3;
|
|
17
|
+
getMax(): vec3;
|
|
18
|
+
add(aabb: AABB): void;
|
|
19
|
+
setFromTransformedAABB(aabb: AABB, m: mat4): void;
|
|
20
|
+
intersects(aabb: AABB): boolean;
|
|
21
|
+
intersection(aabb: AABB): AABB | null;
|
|
22
|
+
containsPoint(point: vec3): boolean;
|
|
23
|
+
/**
|
|
24
|
+
* get n-vertex
|
|
25
|
+
* @param plane plane of CullingVolume
|
|
26
|
+
*/
|
|
27
|
+
getNegativeFarPoint(plane: Plane): vec3;
|
|
28
|
+
/**
|
|
29
|
+
* get p-vertex
|
|
30
|
+
* @param plane plane of CullingVolume
|
|
31
|
+
*/
|
|
32
|
+
getPositiveFarPoint(plane: Plane): vec3;
|
|
33
|
+
}
|
|
@@ -0,0 +1,235 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
Object.defineProperty(exports, "__esModule", {
|
|
4
|
+
value: true
|
|
5
|
+
});
|
|
6
|
+
exports.AABB = void 0;
|
|
7
|
+
|
|
8
|
+
var _glMatrix = require("gl-matrix");
|
|
9
|
+
|
|
10
|
+
/**
|
|
11
|
+
* Axis-Aligned Bounding Box
|
|
12
|
+
* 为了便于后续 Frustum Culling,通过查找表定义 p-vertex 和 n-vertex
|
|
13
|
+
* @see https://github.com/antvis/GWebGPUEngine/issues/3
|
|
14
|
+
*/
|
|
15
|
+
var AABB =
|
|
16
|
+
/** @class */
|
|
17
|
+
function () {
|
|
18
|
+
function AABB(center, halfExtents) {
|
|
19
|
+
this.min = _glMatrix.vec3.create();
|
|
20
|
+
this.max = _glMatrix.vec3.create();
|
|
21
|
+
this.update(center, halfExtents);
|
|
22
|
+
}
|
|
23
|
+
|
|
24
|
+
AABB.prototype.update = function (center, halfExtents) {
|
|
25
|
+
this.center = _glMatrix.vec3.copy(_glMatrix.vec3.create(), center || _glMatrix.vec3.create());
|
|
26
|
+
this.halfExtents = _glMatrix.vec3.copy(_glMatrix.vec3.create(), halfExtents || _glMatrix.vec3.fromValues(0, 0, 0));
|
|
27
|
+
this.min = _glMatrix.vec3.sub(this.min, this.center, this.halfExtents);
|
|
28
|
+
this.max = _glMatrix.vec3.add(this.max, this.center, this.halfExtents);
|
|
29
|
+
};
|
|
30
|
+
|
|
31
|
+
AABB.prototype.setMinMax = function (min, max) {
|
|
32
|
+
_glMatrix.vec3.add(this.center, max, min);
|
|
33
|
+
|
|
34
|
+
_glMatrix.vec3.scale(this.center, this.center, 0.5);
|
|
35
|
+
|
|
36
|
+
_glMatrix.vec3.sub(this.halfExtents, max, min);
|
|
37
|
+
|
|
38
|
+
_glMatrix.vec3.scale(this.halfExtents, this.halfExtents, 0.5);
|
|
39
|
+
|
|
40
|
+
_glMatrix.vec3.copy(this.min, min);
|
|
41
|
+
|
|
42
|
+
_glMatrix.vec3.copy(this.max, max);
|
|
43
|
+
};
|
|
44
|
+
|
|
45
|
+
AABB.prototype.getMin = function () {
|
|
46
|
+
return this.min;
|
|
47
|
+
};
|
|
48
|
+
|
|
49
|
+
AABB.prototype.getMax = function () {
|
|
50
|
+
return this.max;
|
|
51
|
+
};
|
|
52
|
+
|
|
53
|
+
AABB.prototype.add = function (aabb) {
|
|
54
|
+
var tc = this.center;
|
|
55
|
+
var tcx = tc[0];
|
|
56
|
+
var tcy = tc[1];
|
|
57
|
+
var tcz = tc[2];
|
|
58
|
+
var th = this.halfExtents;
|
|
59
|
+
var thx = th[0];
|
|
60
|
+
var thy = th[1];
|
|
61
|
+
var thz = th[2];
|
|
62
|
+
var tminx = tcx - thx;
|
|
63
|
+
var tmaxx = tcx + thx;
|
|
64
|
+
var tminy = tcy - thy;
|
|
65
|
+
var tmaxy = tcy + thy;
|
|
66
|
+
var tminz = tcz - thz;
|
|
67
|
+
var tmaxz = tcz + thz;
|
|
68
|
+
var oc = aabb.center;
|
|
69
|
+
var ocx = oc[0];
|
|
70
|
+
var ocy = oc[1];
|
|
71
|
+
var ocz = oc[2];
|
|
72
|
+
var oh = aabb.halfExtents;
|
|
73
|
+
var ohx = oh[0];
|
|
74
|
+
var ohy = oh[1];
|
|
75
|
+
var ohz = oh[2];
|
|
76
|
+
var ominx = ocx - ohx;
|
|
77
|
+
var omaxx = ocx + ohx;
|
|
78
|
+
var ominy = ocy - ohy;
|
|
79
|
+
var omaxy = ocy + ohy;
|
|
80
|
+
var ominz = ocz - ohz;
|
|
81
|
+
var omaxz = ocz + ohz;
|
|
82
|
+
|
|
83
|
+
if (ominx < tminx) {
|
|
84
|
+
tminx = ominx;
|
|
85
|
+
}
|
|
86
|
+
|
|
87
|
+
if (omaxx > tmaxx) {
|
|
88
|
+
tmaxx = omaxx;
|
|
89
|
+
}
|
|
90
|
+
|
|
91
|
+
if (ominy < tminy) {
|
|
92
|
+
tminy = ominy;
|
|
93
|
+
}
|
|
94
|
+
|
|
95
|
+
if (omaxy > tmaxy) {
|
|
96
|
+
tmaxy = omaxy;
|
|
97
|
+
}
|
|
98
|
+
|
|
99
|
+
if (ominz < tminz) {
|
|
100
|
+
tminz = ominz;
|
|
101
|
+
}
|
|
102
|
+
|
|
103
|
+
if (omaxz > tmaxz) {
|
|
104
|
+
tmaxz = omaxz;
|
|
105
|
+
}
|
|
106
|
+
|
|
107
|
+
tc[0] = (tminx + tmaxx) * 0.5;
|
|
108
|
+
tc[1] = (tminy + tmaxy) * 0.5;
|
|
109
|
+
tc[2] = (tminz + tmaxz) * 0.5;
|
|
110
|
+
th[0] = (tmaxx - tminx) * 0.5;
|
|
111
|
+
th[1] = (tmaxy - tminy) * 0.5;
|
|
112
|
+
th[2] = (tmaxz - tminz) * 0.5;
|
|
113
|
+
this.min[0] = tminx;
|
|
114
|
+
this.min[1] = tminy;
|
|
115
|
+
this.min[2] = tminz;
|
|
116
|
+
this.max[0] = tmaxx;
|
|
117
|
+
this.max[1] = tmaxy;
|
|
118
|
+
this.max[2] = tmaxz;
|
|
119
|
+
};
|
|
120
|
+
|
|
121
|
+
AABB.prototype.setFromTransformedAABB = function (aabb, m) {
|
|
122
|
+
var bc = this.center;
|
|
123
|
+
var br = this.halfExtents;
|
|
124
|
+
var ac = aabb.center;
|
|
125
|
+
var ar = aabb.halfExtents;
|
|
126
|
+
var mx0 = m[0];
|
|
127
|
+
var mx1 = m[4];
|
|
128
|
+
var mx2 = m[8];
|
|
129
|
+
var my0 = m[1];
|
|
130
|
+
var my1 = m[5];
|
|
131
|
+
var my2 = m[9];
|
|
132
|
+
var mz0 = m[2];
|
|
133
|
+
var mz1 = m[6];
|
|
134
|
+
var mz2 = m[10];
|
|
135
|
+
var mx0a = Math.abs(mx0);
|
|
136
|
+
var mx1a = Math.abs(mx1);
|
|
137
|
+
var mx2a = Math.abs(mx2);
|
|
138
|
+
var my0a = Math.abs(my0);
|
|
139
|
+
var my1a = Math.abs(my1);
|
|
140
|
+
var my2a = Math.abs(my2);
|
|
141
|
+
var mz0a = Math.abs(mz0);
|
|
142
|
+
var mz1a = Math.abs(mz1);
|
|
143
|
+
var mz2a = Math.abs(mz2);
|
|
144
|
+
|
|
145
|
+
_glMatrix.vec3.set(bc, m[12] + mx0 * ac[0] + mx1 * ac[1] + mx2 * ac[2], m[13] + my0 * ac[0] + my1 * ac[1] + my2 * ac[2], m[14] + mz0 * ac[0] + mz1 * ac[1] + mz2 * ac[2]);
|
|
146
|
+
|
|
147
|
+
_glMatrix.vec3.set(br, mx0a * ar[0] + mx1a * ar[1] + mx2a * ar[2], my0a * ar[0] + my1a * ar[1] + my2a * ar[2], mz0a * ar[0] + mz1a * ar[1] + mz2a * ar[2]);
|
|
148
|
+
|
|
149
|
+
this.min = _glMatrix.vec3.sub(this.min, bc, br);
|
|
150
|
+
this.max = _glMatrix.vec3.add(this.max, bc, br);
|
|
151
|
+
};
|
|
152
|
+
|
|
153
|
+
AABB.prototype.intersects = function (aabb) {
|
|
154
|
+
var aMax = this.getMax();
|
|
155
|
+
var aMin = this.getMin();
|
|
156
|
+
var bMax = aabb.getMax();
|
|
157
|
+
var bMin = aabb.getMin();
|
|
158
|
+
return aMin[0] <= bMax[0] && aMax[0] >= bMin[0] && aMin[1] <= bMax[1] && aMax[1] >= bMin[1] && aMin[2] <= bMax[2] && aMax[2] >= bMin[2];
|
|
159
|
+
};
|
|
160
|
+
|
|
161
|
+
AABB.prototype.intersection = function (aabb) {
|
|
162
|
+
if (!this.intersects(aabb)) {
|
|
163
|
+
return null;
|
|
164
|
+
}
|
|
165
|
+
|
|
166
|
+
var intersection = new AABB();
|
|
167
|
+
|
|
168
|
+
var min = _glMatrix.vec3.max(_glMatrix.vec3.create(), this.getMin(), aabb.getMin());
|
|
169
|
+
|
|
170
|
+
var max = _glMatrix.vec3.min(_glMatrix.vec3.create(), this.getMax(), aabb.getMax());
|
|
171
|
+
|
|
172
|
+
intersection.setMinMax(min, max);
|
|
173
|
+
return intersection;
|
|
174
|
+
};
|
|
175
|
+
|
|
176
|
+
AABB.prototype.containsPoint = function (point) {
|
|
177
|
+
var min = this.getMin();
|
|
178
|
+
var max = this.getMax();
|
|
179
|
+
return !(point[0] < min[0] || point[0] > max[0] || point[1] < min[1] || point[1] > max[1] || point[2] < min[2] || point[2] > max[2]);
|
|
180
|
+
};
|
|
181
|
+
/**
|
|
182
|
+
* get n-vertex
|
|
183
|
+
* @param plane plane of CullingVolume
|
|
184
|
+
*/
|
|
185
|
+
|
|
186
|
+
|
|
187
|
+
AABB.prototype.getNegativeFarPoint = function (plane) {
|
|
188
|
+
if (plane.pnVertexFlag === 0x111) {
|
|
189
|
+
return _glMatrix.vec3.copy(_glMatrix.vec3.create(), this.min);
|
|
190
|
+
} else if (plane.pnVertexFlag === 0x110) {
|
|
191
|
+
return _glMatrix.vec3.fromValues(this.min[0], this.min[1], this.max[2]);
|
|
192
|
+
} else if (plane.pnVertexFlag === 0x101) {
|
|
193
|
+
return _glMatrix.vec3.fromValues(this.min[0], this.max[1], this.min[2]);
|
|
194
|
+
} else if (plane.pnVertexFlag === 0x100) {
|
|
195
|
+
return _glMatrix.vec3.fromValues(this.min[0], this.max[1], this.max[2]);
|
|
196
|
+
} else if (plane.pnVertexFlag === 0x011) {
|
|
197
|
+
return _glMatrix.vec3.fromValues(this.max[0], this.min[1], this.min[2]);
|
|
198
|
+
} else if (plane.pnVertexFlag === 0x010) {
|
|
199
|
+
return _glMatrix.vec3.fromValues(this.max[0], this.min[1], this.max[2]);
|
|
200
|
+
} else if (plane.pnVertexFlag === 0x001) {
|
|
201
|
+
return _glMatrix.vec3.fromValues(this.max[0], this.max[1], this.min[2]);
|
|
202
|
+
} else {
|
|
203
|
+
return _glMatrix.vec3.fromValues(this.max[0], this.max[1], this.max[2]);
|
|
204
|
+
}
|
|
205
|
+
};
|
|
206
|
+
/**
|
|
207
|
+
* get p-vertex
|
|
208
|
+
* @param plane plane of CullingVolume
|
|
209
|
+
*/
|
|
210
|
+
|
|
211
|
+
|
|
212
|
+
AABB.prototype.getPositiveFarPoint = function (plane) {
|
|
213
|
+
if (plane.pnVertexFlag === 0x111) {
|
|
214
|
+
return _glMatrix.vec3.copy(_glMatrix.vec3.create(), this.max);
|
|
215
|
+
} else if (plane.pnVertexFlag === 0x110) {
|
|
216
|
+
return _glMatrix.vec3.fromValues(this.max[0], this.max[1], this.min[2]);
|
|
217
|
+
} else if (plane.pnVertexFlag === 0x101) {
|
|
218
|
+
return _glMatrix.vec3.fromValues(this.max[0], this.min[1], this.max[2]);
|
|
219
|
+
} else if (plane.pnVertexFlag === 0x100) {
|
|
220
|
+
return _glMatrix.vec3.fromValues(this.max[0], this.min[1], this.min[2]);
|
|
221
|
+
} else if (plane.pnVertexFlag === 0x011) {
|
|
222
|
+
return _glMatrix.vec3.fromValues(this.min[0], this.max[1], this.max[2]);
|
|
223
|
+
} else if (plane.pnVertexFlag === 0x010) {
|
|
224
|
+
return _glMatrix.vec3.fromValues(this.min[0], this.max[1], this.min[2]);
|
|
225
|
+
} else if (plane.pnVertexFlag === 0x001) {
|
|
226
|
+
return _glMatrix.vec3.fromValues(this.min[0], this.min[1], this.max[2]);
|
|
227
|
+
} else {
|
|
228
|
+
return _glMatrix.vec3.fromValues(this.min[0], this.min[1], this.min[2]);
|
|
229
|
+
}
|
|
230
|
+
};
|
|
231
|
+
|
|
232
|
+
return AABB;
|
|
233
|
+
}();
|
|
234
|
+
|
|
235
|
+
exports.AABB = AABB;
|
|
@@ -0,0 +1,41 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
Object.defineProperty(exports, "__esModule", {
|
|
4
|
+
value: true
|
|
5
|
+
});
|
|
6
|
+
exports.BoundingSphere = void 0;
|
|
7
|
+
|
|
8
|
+
var _glMatrix = require("gl-matrix");
|
|
9
|
+
|
|
10
|
+
var tmpVecA = _glMatrix.vec3.create();
|
|
11
|
+
|
|
12
|
+
var BoundingSphere =
|
|
13
|
+
/** @class */
|
|
14
|
+
function () {
|
|
15
|
+
function BoundingSphere(center, radius) {
|
|
16
|
+
this.center = center || _glMatrix.vec3.create();
|
|
17
|
+
this.radius = radius || 0.5;
|
|
18
|
+
}
|
|
19
|
+
|
|
20
|
+
BoundingSphere.prototype.containsPoint = function (point) {
|
|
21
|
+
_glMatrix.vec3.sub(tmpVecA, point, this.center);
|
|
22
|
+
|
|
23
|
+
return _glMatrix.vec3.length(tmpVecA) < this.radius * this.radius;
|
|
24
|
+
};
|
|
25
|
+
|
|
26
|
+
BoundingSphere.prototype.intersects = function (sphere) {
|
|
27
|
+
_glMatrix.vec3.sub(tmpVecA, sphere.center, this.center);
|
|
28
|
+
|
|
29
|
+
var totalRadius = sphere.radius + this.radius;
|
|
30
|
+
|
|
31
|
+
if (_glMatrix.vec3.length(tmpVecA) <= totalRadius * totalRadius) {
|
|
32
|
+
return true;
|
|
33
|
+
}
|
|
34
|
+
|
|
35
|
+
return false;
|
|
36
|
+
};
|
|
37
|
+
|
|
38
|
+
return BoundingSphere;
|
|
39
|
+
}();
|
|
40
|
+
|
|
41
|
+
exports.BoundingSphere = BoundingSphere;
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
import { mat4 } from 'gl-matrix';
|
|
2
|
+
import { Plane } from './Plane';
|
|
3
|
+
export declare enum Mask {
|
|
4
|
+
OUTSIDE = 4294967295,
|
|
5
|
+
INSIDE = 0,
|
|
6
|
+
INDETERMINATE = 2147483647
|
|
7
|
+
}
|
|
8
|
+
export declare class Frustum {
|
|
9
|
+
planes: Plane[];
|
|
10
|
+
constructor(planes?: Plane[]);
|
|
11
|
+
/**
|
|
12
|
+
* extract 6 planes from projectionMatrix
|
|
13
|
+
* @see http://www8.cs.umu.se/kurser/5DV051/HT12/lab/plane_extraction.pdf
|
|
14
|
+
*/
|
|
15
|
+
extractFromVPMatrix(projectionMatrix: mat4): void;
|
|
16
|
+
}
|