excalibur 0.28.3 → 0.28.4
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/.gitattributes +63 -63
- package/CHANGELOG.md +2003 -1955
- package/LICENSE.md +25 -25
- package/README.md +134 -134
- package/STYLEGUIDE.md +136 -136
- package/build/dist/Actions/Action/ActionSequence.js +31 -0
- package/build/dist/Actions/Action/ActionSequence.js.map +1 -0
- package/build/dist/Actions/Action/Blink.js +54 -0
- package/build/dist/Actions/Action/Blink.js.map +1 -0
- package/build/dist/Actions/Action/CallMethod.js +21 -0
- package/build/dist/Actions/Action/CallMethod.js.map +1 -0
- package/build/dist/Actions/Action/Delay.js +26 -0
- package/build/dist/Actions/Action/Delay.js.map +1 -0
- package/build/dist/Actions/Action/Die.js +22 -0
- package/build/dist/Actions/Action/Die.js.map +1 -0
- package/build/dist/Actions/Action/EaseBy.js +70 -0
- package/build/dist/Actions/Action/EaseBy.js.map +1 -0
- package/build/dist/Actions/Action/EaseTo.js +69 -0
- package/build/dist/Actions/Action/EaseTo.js.map +1 -0
- package/build/dist/Actions/Action/Fade.js +48 -0
- package/build/dist/Actions/Action/Fade.js.map +1 -0
- package/build/dist/Actions/Action/Follow.js +56 -0
- package/build/dist/Actions/Action/Follow.js.map +1 -0
- package/build/dist/Actions/Action/Meet.js +54 -0
- package/build/dist/Actions/Action/Meet.js.map +1 -0
- package/build/dist/Actions/Action/MoveBy.js +48 -0
- package/build/dist/Actions/Action/MoveBy.js.map +1 -0
- package/build/dist/Actions/Action/MoveTo.js +41 -0
- package/build/dist/Actions/Action/MoveTo.js.map +1 -0
- package/build/dist/Actions/Action/ParallelActions.js +23 -0
- package/build/dist/Actions/Action/ParallelActions.js.map +1 -0
- package/build/dist/Actions/Action/Repeat.js +31 -0
- package/build/dist/Actions/Action/Repeat.js.map +1 -0
- package/build/dist/Actions/Action/RepeatForever.js +37 -0
- package/build/dist/Actions/Action/RepeatForever.js.map +1 -0
- package/build/dist/Actions/Action/RotateBy.js +95 -0
- package/build/dist/Actions/Action/RotateBy.js.map +1 -0
- package/build/dist/Actions/Action/RotateTo.js +91 -0
- package/build/dist/Actions/Action/RotateTo.js.map +1 -0
- package/build/dist/Actions/Action/ScaleBy.js +46 -0
- package/build/dist/Actions/Action/ScaleBy.js.map +1 -0
- package/build/dist/Actions/Action/ScaleTo.js +58 -0
- package/build/dist/Actions/Action/ScaleTo.js.map +1 -0
- package/build/dist/Actions/Action.js +2 -0
- package/build/dist/Actions/Action.js.map +1 -0
- package/build/dist/Actions/ActionContext.js +322 -0
- package/build/dist/Actions/ActionContext.js.map +1 -0
- package/build/dist/Actions/ActionQueue.js +87 -0
- package/build/dist/Actions/ActionQueue.js.map +1 -0
- package/build/dist/Actions/Actionable.js +2 -0
- package/build/dist/Actions/Actionable.js.map +1 -0
- package/build/dist/Actions/ActionsComponent.js +195 -0
- package/build/dist/Actions/ActionsComponent.js.map +1 -0
- package/build/dist/Actions/ActionsSystem.js +30 -0
- package/build/dist/Actions/ActionsSystem.js.map +1 -0
- package/build/dist/Actions/Index.js +26 -0
- package/build/dist/Actions/Index.js.map +1 -0
- package/build/dist/Actions/RotationType.js +27 -0
- package/build/dist/Actions/RotationType.js.map +1 -0
- package/build/dist/Actor.js +629 -0
- package/build/dist/Actor.js.map +1 -0
- package/build/dist/Camera.js +660 -0
- package/build/dist/Camera.js.map +1 -0
- package/build/dist/Collision/BoundingBox.js +415 -0
- package/build/dist/Collision/BoundingBox.js.map +1 -0
- package/build/dist/Collision/ColliderComponent.js +202 -0
- package/build/dist/Collision/ColliderComponent.js.map +1 -0
- package/build/dist/Collision/Colliders/CircleCollider.js +226 -0
- package/build/dist/Collision/Colliders/CircleCollider.js.map +1 -0
- package/build/dist/Collision/Colliders/ClosestLineJumpTable.js +211 -0
- package/build/dist/Collision/Colliders/ClosestLineJumpTable.js.map +1 -0
- package/build/dist/Collision/Colliders/Collider.js +32 -0
- package/build/dist/Collision/Colliders/Collider.js.map +1 -0
- package/build/dist/Collision/Colliders/CollisionJumpTable.js +300 -0
- package/build/dist/Collision/Colliders/CollisionJumpTable.js.map +1 -0
- package/build/dist/Collision/Colliders/EdgeCollider.js +229 -0
- package/build/dist/Collision/Colliders/EdgeCollider.js.map +1 -0
- package/build/dist/Collision/Colliders/PolygonCollider.js +556 -0
- package/build/dist/Collision/Colliders/PolygonCollider.js.map +1 -0
- package/build/dist/Collision/Colliders/SeparatingAxis.js +67 -0
- package/build/dist/Collision/Colliders/SeparatingAxis.js.map +1 -0
- package/build/dist/Collision/Colliders/Shape.js +99 -0
- package/build/dist/Collision/Colliders/Shape.js.map +1 -0
- package/build/dist/Collision/CollisionType.js +33 -0
- package/build/dist/Collision/CollisionType.js.map +1 -0
- package/build/dist/Collision/Detection/CollisionContact.js +51 -0
- package/build/dist/Collision/Detection/CollisionContact.js.map +1 -0
- package/build/dist/Collision/Detection/CollisionProcessor.js +2 -0
- package/build/dist/Collision/Detection/CollisionProcessor.js.map +1 -0
- package/build/dist/Collision/Detection/DynamicTree.js +442 -0
- package/build/dist/Collision/Detection/DynamicTree.js.map +1 -0
- package/build/dist/Collision/Detection/Pair.js +92 -0
- package/build/dist/Collision/Detection/Pair.js.map +1 -0
- package/build/dist/Collision/Detection/QuadTree.js +193 -0
- package/build/dist/Collision/Detection/QuadTree.js.map +1 -0
- package/build/dist/Collision/Group/CollisionGroup.js +3 -3
- package/build/dist/Collision/Integrator.js +25 -0
- package/build/dist/Collision/Integrator.js.map +1 -0
- package/build/dist/Collision/MotionSystem.js +35 -0
- package/build/dist/Collision/MotionSystem.js.map +1 -0
- package/build/dist/Collision/Physics.js +163 -0
- package/build/dist/Collision/Physics.js.map +1 -0
- package/build/dist/Collision/PhysicsWorld.js +10 -0
- package/build/dist/Collision/PhysicsWorld.js.map +1 -0
- package/build/dist/Collision/Side.js +51 -0
- package/build/dist/Collision/Side.js.map +1 -0
- package/build/dist/Collision/Solver/ArcadeSolver.js +154 -0
- package/build/dist/Collision/Solver/ArcadeSolver.js.map +1 -0
- package/build/dist/Collision/Solver/ContactConstraintPoint.js +87 -0
- package/build/dist/Collision/Solver/ContactConstraintPoint.js.map +1 -0
- package/build/dist/Collision/Solver/RealisticSolver.js +293 -0
- package/build/dist/Collision/Solver/RealisticSolver.js.map +1 -0
- package/build/dist/Collision/Solver/Solver.js +2 -0
- package/build/dist/Collision/Solver/Solver.js.map +1 -0
- package/build/dist/Color.js +417 -0
- package/build/dist/Color.js.map +1 -0
- package/build/dist/Configurable.js +32 -0
- package/build/dist/Configurable.js.map +1 -0
- package/build/dist/Debug/Debug.d.ts +11 -0
- package/build/dist/Debug/Debug.js +385 -0
- package/build/dist/Debug/Debug.js.map +1 -0
- package/build/dist/Debug/DebugFlags.js +40 -0
- package/build/dist/Debug/DebugFlags.js.map +1 -0
- package/build/dist/Debug/DebugSystem.js +263 -0
- package/build/dist/Debug/DebugSystem.js.map +1 -0
- package/build/dist/Debug/index.js +4 -0
- package/build/dist/Debug/index.js.map +1 -0
- package/build/dist/Deprecated.js +2 -0
- package/build/dist/Deprecated.js.map +1 -0
- package/build/dist/Engine.js +986 -0
- package/build/dist/Engine.js.map +1 -0
- package/build/dist/EntityComponentSystem/Component.js +65 -0
- package/build/dist/EntityComponentSystem/Component.js.map +1 -0
- package/build/dist/EntityComponentSystem/Components/MotionComponent.js +33 -0
- package/build/dist/EntityComponentSystem/Components/MotionComponent.js.map +1 -0
- package/build/dist/EntityComponentSystem/Components/TransformComponent.js +107 -0
- package/build/dist/EntityComponentSystem/Components/TransformComponent.js.map +1 -0
- package/build/dist/EntityComponentSystem/Entity.js +487 -0
- package/build/dist/EntityComponentSystem/Entity.js.map +1 -0
- package/build/dist/EntityComponentSystem/EntityManager.js +137 -0
- package/build/dist/EntityComponentSystem/EntityManager.js.map +1 -0
- package/build/dist/EntityComponentSystem/Query.js +90 -0
- package/build/dist/EntityComponentSystem/Query.js.map +1 -0
- package/build/dist/EntityComponentSystem/QueryManager.js +90 -0
- package/build/dist/EntityComponentSystem/QueryManager.js.map +1 -0
- package/build/dist/EntityComponentSystem/System.js +76 -0
- package/build/dist/EntityComponentSystem/System.js.map +1 -0
- package/build/dist/EntityComponentSystem/SystemManager.js +104 -0
- package/build/dist/EntityComponentSystem/SystemManager.js.map +1 -0
- package/build/dist/EntityComponentSystem/Util.js +5 -0
- package/build/dist/EntityComponentSystem/Util.js.map +1 -0
- package/build/dist/EntityComponentSystem/World.js +55 -0
- package/build/dist/EntityComponentSystem/World.js.map +1 -0
- package/build/dist/EntityComponentSystem/index.js +11 -0
- package/build/dist/EntityComponentSystem/index.js.map +1 -0
- package/build/dist/EventDispatcher.js +122 -0
- package/build/dist/EventDispatcher.js.map +1 -0
- package/build/dist/EventEmitter.js +86 -0
- package/build/dist/EventEmitter.js.map +1 -0
- package/build/dist/Events/ExEvent.js +12 -0
- package/build/dist/Events/ExEvent.js.map +1 -0
- package/build/dist/Events/MediaEvents.js +75 -0
- package/build/dist/Events/MediaEvents.js.map +1 -0
- package/build/dist/Events/PointerEvents.js +52 -0
- package/build/dist/Events/PointerEvents.js.map +1 -0
- package/build/dist/Events.js +473 -0
- package/build/dist/Events.js.map +1 -0
- package/build/dist/Flags.js +67 -0
- package/build/dist/Flags.js.map +1 -0
- package/build/dist/Graphics/Animation.js +344 -0
- package/build/dist/Graphics/Animation.js.map +1 -0
- package/build/dist/Graphics/Canvas.js +38 -0
- package/build/dist/Graphics/Canvas.js.map +1 -0
- package/build/dist/Graphics/Circle.js +48 -0
- package/build/dist/Graphics/Circle.js.map +1 -0
- package/build/dist/Graphics/Context/ExcaliburGraphicsContext.js +2 -0
- package/build/dist/Graphics/Context/ExcaliburGraphicsContext.js.map +1 -0
- package/build/dist/Graphics/Context/ExcaliburGraphicsContext2DCanvas.js +237 -0
- package/build/dist/Graphics/Context/ExcaliburGraphicsContext2DCanvas.js.map +1 -0
- package/build/dist/Graphics/Context/ExcaliburGraphicsContextWebGL.d.ts +1 -0
- package/build/dist/Graphics/Context/ExcaliburGraphicsContextWebGL.js +481 -0
- package/build/dist/Graphics/Context/ExcaliburGraphicsContextWebGL.js.map +1 -0
- package/build/dist/Graphics/Context/circle-renderer/circle-renderer.frag.glsl +52 -52
- package/build/dist/Graphics/Context/circle-renderer/circle-renderer.js +174 -0
- package/build/dist/Graphics/Context/circle-renderer/circle-renderer.js.map +1 -0
- package/build/dist/Graphics/Context/circle-renderer/circle-renderer.vert.glsl +37 -37
- package/build/dist/Graphics/Context/debug-text.js +47 -0
- package/build/dist/Graphics/Context/debug-text.js.map +1 -0
- package/build/dist/Graphics/Context/draw-call.js +16 -0
- package/build/dist/Graphics/Context/draw-call.js.map +1 -0
- package/build/dist/Graphics/Context/image-renderer/image-renderer.frag.glsl +32 -32
- package/build/dist/Graphics/Context/image-renderer/image-renderer.js +246 -0
- package/build/dist/Graphics/Context/image-renderer/image-renderer.js.map +1 -0
- package/build/dist/Graphics/Context/image-renderer/image-renderer.vert.glsl +32 -32
- package/build/dist/Graphics/Context/line-renderer/line-fragment.glsl +10 -10
- package/build/dist/Graphics/Context/line-renderer/line-renderer.js +90 -0
- package/build/dist/Graphics/Context/line-renderer/line-renderer.js.map +1 -0
- package/build/dist/Graphics/Context/line-renderer/line-vertex.glsl +14 -14
- package/build/dist/Graphics/Context/material-renderer/material-renderer.js +23 -2
- package/build/dist/Graphics/Context/material-renderer/material-renderer.js.map +1 -1
- package/build/dist/Graphics/Context/material.d.ts +2 -0
- package/build/dist/Graphics/Context/material.js +72 -0
- package/build/dist/Graphics/Context/material.js.map +1 -0
- package/build/dist/Graphics/Context/point-renderer/point-fragment.glsl +19 -19
- package/build/dist/Graphics/Context/point-renderer/point-renderer.js +91 -0
- package/build/dist/Graphics/Context/point-renderer/point-renderer.js.map +1 -0
- package/build/dist/Graphics/Context/point-renderer/point-vertex.glsl +11 -11
- package/build/dist/Graphics/Context/quad-index-buffer.js +67 -0
- package/build/dist/Graphics/Context/quad-index-buffer.js.map +1 -0
- package/build/dist/Graphics/Context/rectangle-renderer/rectangle-renderer.frag.glsl +85 -85
- package/build/dist/Graphics/Context/rectangle-renderer/rectangle-renderer.js +305 -0
- package/build/dist/Graphics/Context/rectangle-renderer/rectangle-renderer.js.map +1 -0
- package/build/dist/Graphics/Context/rectangle-renderer/rectangle-renderer.vert.glsl +42 -42
- package/build/dist/Graphics/Context/render-source.js +16 -0
- package/build/dist/Graphics/Context/render-source.js.map +1 -0
- package/build/dist/Graphics/Context/render-target.js +65 -0
- package/build/dist/Graphics/Context/render-target.js.map +1 -0
- package/build/dist/Graphics/Context/renderer.js +2 -0
- package/build/dist/Graphics/Context/renderer.js.map +1 -0
- package/build/dist/Graphics/Context/screen-pass-painter/screen-fragment.glsl +13 -13
- package/build/dist/Graphics/Context/screen-pass-painter/screen-pass-painter.js +56 -0
- package/build/dist/Graphics/Context/screen-pass-painter/screen-pass-painter.js.map +1 -0
- package/build/dist/Graphics/Context/screen-pass-painter/screen-vertex.glsl +11 -11
- package/build/dist/Graphics/Context/state-stack.js +37 -0
- package/build/dist/Graphics/Context/state-stack.js.map +1 -0
- package/build/dist/Graphics/Context/texture-loader.js +109 -0
- package/build/dist/Graphics/Context/texture-loader.js.map +1 -0
- package/build/dist/Graphics/Context/transform-stack.js +30 -0
- package/build/dist/Graphics/Context/transform-stack.js.map +1 -0
- package/build/dist/Graphics/Context/vertex-buffer.js +53 -0
- package/build/dist/Graphics/Context/vertex-buffer.js.map +1 -0
- package/build/dist/Graphics/Context/webgl-util.js +79 -0
- package/build/dist/Graphics/Context/webgl-util.js.map +1 -0
- package/build/dist/Graphics/DebugGraphicsComponent.d.ts +3 -2
- package/build/dist/Graphics/DebugGraphicsComponent.js +16 -0
- package/build/dist/Graphics/DebugGraphicsComponent.js.map +1 -0
- package/build/dist/Graphics/Filtering.js +17 -0
- package/build/dist/Graphics/Filtering.js.map +1 -0
- package/build/dist/Graphics/Font.js +148 -0
- package/build/dist/Graphics/Font.js.map +1 -0
- package/build/dist/Graphics/FontCache.d.ts +1 -0
- package/build/dist/Graphics/FontCache.js +80 -0
- package/build/dist/Graphics/FontCache.js.map +1 -0
- package/build/dist/Graphics/FontCommon.js +109 -0
- package/build/dist/Graphics/FontCommon.js.map +1 -0
- package/build/dist/Graphics/FontTextInstance.js +230 -0
- package/build/dist/Graphics/FontTextInstance.js.map +1 -0
- package/build/dist/Graphics/Graphic.js +208 -0
- package/build/dist/Graphics/Graphic.js.map +1 -0
- package/build/dist/Graphics/GraphicsComponent.js +336 -0
- package/build/dist/Graphics/GraphicsComponent.js.map +1 -0
- package/build/dist/Graphics/GraphicsDiagnostics.js +9 -0
- package/build/dist/Graphics/GraphicsDiagnostics.js.map +1 -0
- package/build/dist/Graphics/GraphicsGroup.js +69 -0
- package/build/dist/Graphics/GraphicsGroup.js.map +1 -0
- package/build/dist/Graphics/GraphicsSystem.js +210 -0
- package/build/dist/Graphics/GraphicsSystem.js.map +1 -0
- package/build/dist/Graphics/ImageSource.js +124 -0
- package/build/dist/Graphics/ImageSource.js.map +1 -0
- package/build/dist/Graphics/Line.js +45 -0
- package/build/dist/Graphics/Line.js.map +1 -0
- package/build/dist/Graphics/OffscreenSystem.js +64 -0
- package/build/dist/Graphics/OffscreenSystem.js.map +1 -0
- package/build/dist/Graphics/ParallaxComponent.js +11 -0
- package/build/dist/Graphics/ParallaxComponent.js.map +1 -0
- package/build/dist/Graphics/Polygon.js +59 -0
- package/build/dist/Graphics/Polygon.js.map +1 -0
- package/build/dist/Graphics/PostProcessor/ColorBlindnessMode.js +7 -0
- package/build/dist/Graphics/PostProcessor/ColorBlindnessMode.js.map +1 -0
- package/build/dist/Graphics/PostProcessor/ColorBlindnessPostProcessor.js +52 -0
- package/build/dist/Graphics/PostProcessor/ColorBlindnessPostProcessor.js.map +1 -0
- package/build/dist/Graphics/PostProcessor/PostProcessor.js +2 -0
- package/build/dist/Graphics/PostProcessor/PostProcessor.js.map +1 -0
- package/build/dist/Graphics/PostProcessor/ScreenShader.js +59 -0
- package/build/dist/Graphics/PostProcessor/ScreenShader.js.map +1 -0
- package/build/dist/Graphics/PostProcessor/color-blind-fragment.glsl +64 -64
- package/build/dist/Graphics/Raster.js +215 -0
- package/build/dist/Graphics/Raster.js.map +1 -0
- package/build/dist/Graphics/Rectangle.js +29 -0
- package/build/dist/Graphics/Rectangle.js.map +1 -0
- package/build/dist/Graphics/Sprite.js +82 -0
- package/build/dist/Graphics/Sprite.js.map +1 -0
- package/build/dist/Graphics/SpriteFont.js +139 -0
- package/build/dist/Graphics/SpriteFont.js.map +1 -0
- package/build/dist/Graphics/SpriteSheet.js +116 -0
- package/build/dist/Graphics/SpriteSheet.js.map +1 -0
- package/build/dist/Graphics/Text.js +103 -0
- package/build/dist/Graphics/Text.js.map +1 -0
- package/build/dist/Graphics/index.js +46 -0
- package/build/dist/Graphics/index.js.map +1 -0
- package/build/dist/Id.js +8 -0
- package/build/dist/Id.js.map +1 -0
- package/build/dist/Input/CapturePointerConfig.js +5 -0
- package/build/dist/Input/CapturePointerConfig.js.map +1 -0
- package/build/dist/Input/EngineInput.js +2 -0
- package/build/dist/Input/EngineInput.js.map +1 -0
- package/build/dist/Input/Gamepad.js +422 -0
- package/build/dist/Input/Gamepad.js.map +1 -0
- package/build/dist/Input/Index.js +88 -0
- package/build/dist/Input/Index.js.map +1 -0
- package/build/dist/Input/InputMapper.js +45 -0
- package/build/dist/Input/InputMapper.js.map +1 -0
- package/build/dist/Input/Keyboard.js +348 -0
- package/build/dist/Input/Keyboard.js.map +1 -0
- package/build/dist/Input/NativePointerButton.js +12 -0
- package/build/dist/Input/NativePointerButton.js.map +1 -0
- package/build/dist/Input/PointerAbstraction.js +44 -0
- package/build/dist/Input/PointerAbstraction.js.map +1 -0
- package/build/dist/Input/PointerButton.js +12 -0
- package/build/dist/Input/PointerButton.js.map +1 -0
- package/build/dist/Input/PointerComponent.js +28 -0
- package/build/dist/Input/PointerComponent.js.map +1 -0
- package/build/dist/Input/PointerEvent.js +25 -0
- package/build/dist/Input/PointerEvent.js.map +1 -0
- package/build/dist/Input/PointerEventReceiver.js +456 -0
- package/build/dist/Input/PointerEventReceiver.js.map +1 -0
- package/build/dist/Input/PointerScope.js +16 -0
- package/build/dist/Input/PointerScope.js.map +1 -0
- package/build/dist/Input/PointerSystem.js +249 -0
- package/build/dist/Input/PointerSystem.js.map +1 -0
- package/build/dist/Input/PointerType.js +11 -0
- package/build/dist/Input/PointerType.js.map +1 -0
- package/build/dist/Input/WheelDeltaMode.js +7 -0
- package/build/dist/Input/WheelDeltaMode.js.map +1 -0
- package/build/dist/Input/WheelEvent.js +21 -0
- package/build/dist/Input/WheelEvent.js.map +1 -0
- package/build/dist/Interfaces/Audio.js +2 -0
- package/build/dist/Interfaces/Audio.js.map +1 -0
- package/build/dist/Interfaces/AudioImplementation.js +11 -0
- package/build/dist/Interfaces/AudioImplementation.js.map +1 -0
- package/build/dist/Interfaces/Clonable.js +2 -0
- package/build/dist/Interfaces/Clonable.js.map +1 -0
- package/build/dist/Interfaces/Evented.js +2 -0
- package/build/dist/Interfaces/Evented.js.map +1 -0
- package/build/dist/Interfaces/Index.js +8 -0
- package/build/dist/Interfaces/Index.js.map +1 -0
- package/build/dist/Interfaces/LifecycleEvents.js +51 -0
- package/build/dist/Interfaces/LifecycleEvents.js.map +1 -0
- package/build/dist/Interfaces/Loadable.js +2 -0
- package/build/dist/Interfaces/Loadable.js.map +1 -0
- package/build/dist/Interfaces/PointerEventHandlers.js +2 -0
- package/build/dist/Interfaces/PointerEventHandlers.js.map +1 -0
- package/build/dist/Label.js +81 -0
- package/build/dist/Label.js.map +1 -0
- package/build/dist/Loader.js +416 -0
- package/build/dist/Loader.js.map +1 -0
- package/build/dist/Math/Index.js +13 -0
- package/build/dist/Math/Index.js.map +1 -0
- package/build/dist/Math/Random.js +239 -0
- package/build/dist/Math/Random.js.map +1 -0
- package/build/dist/Math/affine-matrix.js +331 -0
- package/build/dist/Math/affine-matrix.js.map +1 -0
- package/build/dist/Math/coord-plane.js +17 -0
- package/build/dist/Math/coord-plane.js.map +1 -0
- package/build/dist/Math/global-coordinates.js +30 -0
- package/build/dist/Math/global-coordinates.js.map +1 -0
- package/build/dist/Math/line-segment.js +205 -0
- package/build/dist/Math/line-segment.js.map +1 -0
- package/build/dist/Math/matrix.js +457 -0
- package/build/dist/Math/matrix.js.map +1 -0
- package/build/dist/Math/projection.js +24 -0
- package/build/dist/Math/projection.js.map +1 -0
- package/build/dist/Math/ray.js +52 -0
- package/build/dist/Math/ray.js.map +1 -0
- package/build/dist/Math/transform.js +219 -0
- package/build/dist/Math/transform.js.map +1 -0
- package/build/dist/Math/util.js +82 -0
- package/build/dist/Math/util.js.map +1 -0
- package/build/dist/Math/vector-view.js +25 -0
- package/build/dist/Math/vector-view.js.map +1 -0
- package/build/dist/Math/vector.js +340 -0
- package/build/dist/Math/vector.js.map +1 -0
- package/build/dist/Math/watch-vector.js +26 -0
- package/build/dist/Math/watch-vector.js.map +1 -0
- package/build/dist/Particles.js +430 -0
- package/build/dist/Particles.js.map +1 -0
- package/build/dist/Polyfill.js +56 -0
- package/build/dist/Polyfill.js.map +1 -0
- package/build/dist/Resources/Gif.js +464 -0
- package/build/dist/Resources/Gif.js.map +1 -0
- package/build/dist/Resources/Index.js +4 -0
- package/build/dist/Resources/Index.js.map +1 -0
- package/build/dist/Resources/Resource.js +81 -0
- package/build/dist/Resources/Resource.js.map +1 -0
- package/build/dist/Resources/Sound/AudioContext.js +16 -0
- package/build/dist/Resources/Sound/AudioContext.js.map +1 -0
- package/build/dist/Resources/Sound/Index.js +4 -0
- package/build/dist/Resources/Sound/Index.js.map +1 -0
- package/build/dist/Resources/Sound/Sound.js +326 -0
- package/build/dist/Resources/Sound/Sound.js.map +1 -0
- package/build/dist/Resources/Sound/WebAudioInstance.js +190 -0
- package/build/dist/Resources/Sound/WebAudioInstance.js.map +1 -0
- package/build/dist/Scene.js +444 -0
- package/build/dist/Scene.js.map +1 -0
- package/build/dist/Screen.js +782 -0
- package/build/dist/Screen.js.map +1 -0
- package/build/dist/ScreenElement.js +43 -0
- package/build/dist/ScreenElement.js.map +1 -0
- package/build/dist/TileMap/IsometricEntityComponent.js +17 -0
- package/build/dist/TileMap/IsometricEntityComponent.js.map +1 -0
- package/build/dist/TileMap/IsometricEntitySystem.js +23 -0
- package/build/dist/TileMap/IsometricEntitySystem.js.map +1 -0
- package/build/dist/TileMap/IsometricMap.js +311 -0
- package/build/dist/TileMap/IsometricMap.js.map +1 -0
- package/build/dist/TileMap/TileMap.d.ts +2 -1
- package/build/dist/TileMap/TileMap.js +630 -0
- package/build/dist/TileMap/TileMap.js.map +1 -0
- package/build/dist/TileMap/index.js +5 -0
- package/build/dist/TileMap/index.js.map +1 -0
- package/build/dist/Timer.js +202 -0
- package/build/dist/Timer.js.map +1 -0
- package/build/dist/Trigger.js +94 -0
- package/build/dist/Trigger.js.map +1 -0
- package/build/dist/Util/Browser.js +66 -0
- package/build/dist/Util/Browser.js.map +1 -0
- package/build/dist/Util/Clock.js +219 -0
- package/build/dist/Util/Clock.js.map +1 -0
- package/build/dist/Util/Decorators.js +78 -0
- package/build/dist/Util/Decorators.js.map +1 -0
- package/build/dist/Util/Detector.js +167 -0
- package/build/dist/Util/Detector.js.map +1 -0
- package/build/dist/Util/DrawUtil.js +115 -0
- package/build/dist/Util/DrawUtil.js.map +1 -0
- package/build/dist/Util/EasingFunctions.js +102 -0
- package/build/dist/Util/EasingFunctions.js.map +1 -0
- package/build/dist/Util/Fps.js +47 -0
- package/build/dist/Util/Fps.js.map +1 -0
- package/build/dist/Util/Future.js +30 -0
- package/build/dist/Util/Future.js.map +1 -0
- package/build/dist/Util/IFrame.js +23 -0
- package/build/dist/Util/IFrame.js.map +1 -0
- package/build/dist/Util/Index.js +7 -0
- package/build/dist/Util/Index.js.map +1 -0
- package/build/dist/Util/Log.js +195 -0
- package/build/dist/Util/Log.js.map +1 -0
- package/build/dist/Util/Observable.js +66 -0
- package/build/dist/Util/Observable.js.map +1 -0
- package/build/dist/Util/Pool.js +74 -0
- package/build/dist/Util/Pool.js.map +1 -0
- package/build/dist/Util/Semaphore.js +55 -0
- package/build/dist/Util/Semaphore.js.map +1 -0
- package/build/dist/Util/Sound.js +22 -0
- package/build/dist/Util/Sound.js.map +1 -0
- package/build/dist/Util/StateMachine.js +79 -0
- package/build/dist/Util/StateMachine.js.map +1 -0
- package/build/dist/Util/Toaster.css +28 -28
- package/build/dist/Util/Toaster.js +84 -0
- package/build/dist/Util/Toaster.js.map +1 -0
- package/build/dist/Util/Util.d.ts +6 -0
- package/build/dist/Util/Util.js +95 -0
- package/build/dist/Util/Util.js.map +1 -0
- package/build/dist/Util/Watch.js +67 -0
- package/build/dist/Util/Watch.js.map +1 -0
- package/build/dist/Util/WebAudio.js +62 -0
- package/build/dist/Util/WebAudio.js.map +1 -0
- package/build/dist/excalibur.d.ts +2 -2
- package/build/dist/excalibur.js +389 -258
- package/build/dist/excalibur.js.map +1 -1
- package/build/dist/excalibur.min.js +1 -1
- package/build/dist/excalibur.min.js.LICENSE.txt +1 -1
- package/build/dist/excalibur.min.js.map +1 -1
- package/build/dist/index.js +81 -0
- package/build/dist/index.js.map +1 -0
- package/build/esm/Debug/Debug.d.ts +11 -0
- package/build/esm/Graphics/Context/ExcaliburGraphicsContextWebGL.d.ts +1 -0
- package/build/esm/Graphics/Context/material.d.ts +2 -0
- package/build/esm/Graphics/DebugGraphicsComponent.d.ts +3 -2
- package/build/esm/Graphics/FontCache.d.ts +1 -0
- package/build/esm/TileMap/TileMap.d.ts +2 -1
- package/build/esm/Util/Util.d.ts +6 -0
- package/build/esm/excalibur.d.ts +2 -2
- package/build/esm/excalibur.js +389 -258
- package/build/esm/excalibur.js.map +1 -1
- package/build/esm/excalibur.min.js +1 -1
- package/build/esm/excalibur.min.js.LICENSE.txt +1 -1
- package/build/esm/excalibur.min.js.map +1 -1
- package/docker-compose.yml +11 -11
- package/package.json +131 -131
- package/build/dist/Loader.css +0 -122
- package/build/nuget/Excalibur.0.28.3.nupkg +0 -0
- package/build/v0.28.3.zip +0 -0
- package/excalibur-0.28.3.tgz +0 -0
|
@@ -0,0 +1,202 @@
|
|
|
1
|
+
import { Vector } from '../Math/vector';
|
|
2
|
+
import { TransformComponent } from '../EntityComponentSystem';
|
|
3
|
+
import { Component } from '../EntityComponentSystem/Component';
|
|
4
|
+
import { CollisionEndEvent, CollisionStartEvent, PostCollisionEvent, PreCollisionEvent } from '../Events';
|
|
5
|
+
import { Observable } from '../Util/Observable';
|
|
6
|
+
import { BoundingBox } from './BoundingBox';
|
|
7
|
+
import { CompositeCollider } from './Colliders/CompositeCollider';
|
|
8
|
+
import { Shape } from './Colliders/Shape';
|
|
9
|
+
import { EventEmitter } from '../EventEmitter';
|
|
10
|
+
export class ColliderComponent extends Component {
|
|
11
|
+
constructor(collider) {
|
|
12
|
+
super();
|
|
13
|
+
this.type = 'ex.collider';
|
|
14
|
+
this.events = new EventEmitter();
|
|
15
|
+
/**
|
|
16
|
+
* Observable that notifies when a collider is added to the body
|
|
17
|
+
*/
|
|
18
|
+
this.$colliderAdded = new Observable();
|
|
19
|
+
/**
|
|
20
|
+
* Observable that notifies when a collider is removed from the body
|
|
21
|
+
*/
|
|
22
|
+
this.$colliderRemoved = new Observable();
|
|
23
|
+
this.set(collider);
|
|
24
|
+
}
|
|
25
|
+
/**
|
|
26
|
+
* Get the current collider geometry
|
|
27
|
+
*/
|
|
28
|
+
get() {
|
|
29
|
+
return this._collider;
|
|
30
|
+
}
|
|
31
|
+
/**
|
|
32
|
+
* Set the collider geometry
|
|
33
|
+
* @param collider
|
|
34
|
+
* @returns the collider you set
|
|
35
|
+
*/
|
|
36
|
+
set(collider) {
|
|
37
|
+
this.clear();
|
|
38
|
+
if (collider) {
|
|
39
|
+
this._collider = collider;
|
|
40
|
+
this._collider.owner = this.owner;
|
|
41
|
+
collider.events.pipe(this.events);
|
|
42
|
+
this.$colliderAdded.notifyAll(collider);
|
|
43
|
+
this.update();
|
|
44
|
+
}
|
|
45
|
+
return collider;
|
|
46
|
+
}
|
|
47
|
+
/**
|
|
48
|
+
* Remove collider geometry from collider component
|
|
49
|
+
*/
|
|
50
|
+
clear() {
|
|
51
|
+
if (this._collider) {
|
|
52
|
+
this._collider.events.unpipe(this.events);
|
|
53
|
+
this.$colliderRemoved.notifyAll(this._collider);
|
|
54
|
+
this._collider.owner = null;
|
|
55
|
+
this._collider = null;
|
|
56
|
+
}
|
|
57
|
+
}
|
|
58
|
+
clone() {
|
|
59
|
+
const clone = new ColliderComponent(this._collider.clone());
|
|
60
|
+
return clone;
|
|
61
|
+
}
|
|
62
|
+
/**
|
|
63
|
+
* Return world space bounds
|
|
64
|
+
*/
|
|
65
|
+
get bounds() {
|
|
66
|
+
var _a, _b;
|
|
67
|
+
return (_b = (_a = this._collider) === null || _a === void 0 ? void 0 : _a.bounds) !== null && _b !== void 0 ? _b : new BoundingBox();
|
|
68
|
+
}
|
|
69
|
+
/**
|
|
70
|
+
* Return local space bounds
|
|
71
|
+
*/
|
|
72
|
+
get localBounds() {
|
|
73
|
+
var _a, _b;
|
|
74
|
+
return (_b = (_a = this._collider) === null || _a === void 0 ? void 0 : _a.localBounds) !== null && _b !== void 0 ? _b : new BoundingBox();
|
|
75
|
+
}
|
|
76
|
+
/**
|
|
77
|
+
* Update the collider's transformed geometry
|
|
78
|
+
*/
|
|
79
|
+
update() {
|
|
80
|
+
var _a;
|
|
81
|
+
const tx = (_a = this.owner) === null || _a === void 0 ? void 0 : _a.get(TransformComponent);
|
|
82
|
+
if (this._collider) {
|
|
83
|
+
this._collider.owner = this.owner;
|
|
84
|
+
if (tx) {
|
|
85
|
+
this._collider.update(tx.get());
|
|
86
|
+
}
|
|
87
|
+
}
|
|
88
|
+
}
|
|
89
|
+
/**
|
|
90
|
+
* Collide component with another
|
|
91
|
+
* @param other
|
|
92
|
+
*/
|
|
93
|
+
collide(other) {
|
|
94
|
+
let colliderA = this._collider;
|
|
95
|
+
let colliderB = other._collider;
|
|
96
|
+
if (!colliderA || !colliderB) {
|
|
97
|
+
return [];
|
|
98
|
+
}
|
|
99
|
+
// If we have a composite lefthand side :(
|
|
100
|
+
// Might bite us, but to avoid updating all the handlers make composite always left side
|
|
101
|
+
let flipped = false;
|
|
102
|
+
if (colliderB instanceof CompositeCollider) {
|
|
103
|
+
colliderA = colliderB;
|
|
104
|
+
colliderB = this._collider;
|
|
105
|
+
flipped = true;
|
|
106
|
+
}
|
|
107
|
+
if (this._collider) {
|
|
108
|
+
const contacts = colliderA.collide(colliderB);
|
|
109
|
+
if (contacts) {
|
|
110
|
+
if (flipped) {
|
|
111
|
+
contacts.forEach((contact) => {
|
|
112
|
+
contact.mtv = contact.mtv.negate();
|
|
113
|
+
contact.normal = contact.normal.negate();
|
|
114
|
+
contact.tangent = contact.normal.perpendicular();
|
|
115
|
+
contact.colliderA = this._collider;
|
|
116
|
+
contact.colliderB = other._collider;
|
|
117
|
+
});
|
|
118
|
+
}
|
|
119
|
+
return contacts;
|
|
120
|
+
}
|
|
121
|
+
return [];
|
|
122
|
+
}
|
|
123
|
+
return [];
|
|
124
|
+
}
|
|
125
|
+
onAdd(entity) {
|
|
126
|
+
if (this._collider) {
|
|
127
|
+
this.update();
|
|
128
|
+
}
|
|
129
|
+
// Wire up the collider events to the owning entity
|
|
130
|
+
this.events.on('precollision', (evt) => {
|
|
131
|
+
const precollision = evt;
|
|
132
|
+
entity.events.emit('precollision', new PreCollisionEvent(precollision.target.owner, precollision.other.owner, precollision.side, precollision.intersection));
|
|
133
|
+
});
|
|
134
|
+
this.events.on('postcollision', (evt) => {
|
|
135
|
+
const postcollision = evt;
|
|
136
|
+
entity.events.emit('postcollision', new PostCollisionEvent(postcollision.target.owner, postcollision.other.owner, postcollision.side, postcollision.intersection));
|
|
137
|
+
});
|
|
138
|
+
this.events.on('collisionstart', (evt) => {
|
|
139
|
+
const start = evt;
|
|
140
|
+
entity.events.emit('collisionstart', new CollisionStartEvent(start.target.owner, start.other.owner, start.contact));
|
|
141
|
+
});
|
|
142
|
+
this.events.on('collisionend', (evt) => {
|
|
143
|
+
const end = evt;
|
|
144
|
+
entity.events.emit('collisionend', new CollisionEndEvent(end.target.owner, end.other.owner));
|
|
145
|
+
});
|
|
146
|
+
}
|
|
147
|
+
onRemove() {
|
|
148
|
+
this.events.clear();
|
|
149
|
+
this.$colliderRemoved.notifyAll(this._collider);
|
|
150
|
+
}
|
|
151
|
+
/**
|
|
152
|
+
* Sets up a box geometry based on the current bounds of the associated actor of this physics body.
|
|
153
|
+
*
|
|
154
|
+
* If no width/height are specified the body will attempt to use the associated actor's width/height.
|
|
155
|
+
*
|
|
156
|
+
* By default, the box is center is at (0, 0) which means it is centered around the actors anchor.
|
|
157
|
+
*/
|
|
158
|
+
useBoxCollider(width, height, anchor = Vector.Half, center = Vector.Zero) {
|
|
159
|
+
const collider = Shape.Box(width, height, anchor, center);
|
|
160
|
+
return (this.set(collider));
|
|
161
|
+
}
|
|
162
|
+
/**
|
|
163
|
+
* Sets up a [[PolygonCollider|polygon]] collision geometry based on a list of of points relative
|
|
164
|
+
* to the anchor of the associated actor
|
|
165
|
+
* of this physics body.
|
|
166
|
+
*
|
|
167
|
+
* Only [convex polygon](https://en.wikipedia.org/wiki/Convex_polygon) definitions are supported.
|
|
168
|
+
*
|
|
169
|
+
* By default, the box is center is at (0, 0) which means it is centered around the actors anchor.
|
|
170
|
+
*/
|
|
171
|
+
usePolygonCollider(points, center = Vector.Zero) {
|
|
172
|
+
const poly = Shape.Polygon(points, center);
|
|
173
|
+
return (this.set(poly));
|
|
174
|
+
}
|
|
175
|
+
/**
|
|
176
|
+
* Sets up a [[Circle|circle collision geometry]] as the only collider with a specified radius in pixels.
|
|
177
|
+
*
|
|
178
|
+
* By default, the box is center is at (0, 0) which means it is centered around the actors anchor.
|
|
179
|
+
*/
|
|
180
|
+
useCircleCollider(radius, center = Vector.Zero) {
|
|
181
|
+
const collider = Shape.Circle(radius, center);
|
|
182
|
+
return (this.set(collider));
|
|
183
|
+
}
|
|
184
|
+
/**
|
|
185
|
+
* Sets up an [[Edge|edge collision geometry]] with a start point and an end point relative to the anchor of the associated actor
|
|
186
|
+
* of this physics body.
|
|
187
|
+
*
|
|
188
|
+
* By default, the box is center is at (0, 0) which means it is centered around the actors anchor.
|
|
189
|
+
*/
|
|
190
|
+
useEdgeCollider(begin, end) {
|
|
191
|
+
const collider = Shape.Edge(begin, end);
|
|
192
|
+
return (this.set(collider));
|
|
193
|
+
}
|
|
194
|
+
/**
|
|
195
|
+
* Setups up a [[CompositeCollider]] which can define any arbitrary set of excalibur colliders
|
|
196
|
+
* @param colliders
|
|
197
|
+
*/
|
|
198
|
+
useCompositeCollider(colliders) {
|
|
199
|
+
return (this.set(new CompositeCollider(colliders)));
|
|
200
|
+
}
|
|
201
|
+
}
|
|
202
|
+
//# sourceMappingURL=ColliderComponent.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"ColliderComponent.js","sourceRoot":"","sources":["../../../src/engine/Collision/ColliderComponent.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,MAAM,EAAE,MAAM,gBAAgB,CAAC;AACxC,OAAO,EAAE,kBAAkB,EAAE,MAAM,0BAA0B,CAAC;AAC9D,OAAO,EAAE,SAAS,EAAE,MAAM,oCAAoC,CAAC;AAE/D,OAAO,EAAE,iBAAiB,EAAE,mBAAmB,EAAE,kBAAkB,EAAE,iBAAiB,EAAE,MAAM,WAAW,CAAC;AAC1G,OAAO,EAAE,UAAU,EAAE,MAAM,oBAAoB,CAAC;AAChD,OAAO,EAAE,WAAW,EAAE,MAAM,eAAe,CAAC;AAI5C,OAAO,EAAE,iBAAiB,EAAE,MAAM,+BAA+B,CAAC;AAGlE,OAAO,EAAE,KAAK,EAAE,MAAM,mBAAmB,CAAC;AAC1C,OAAO,EAAE,YAAY,EAAE,MAAM,iBAAiB,CAAC;AAE/C,MAAM,OAAO,iBAAkB,SAAQ,SAAwB;IAc7D,YAAY,QAAmB;QAC7B,KAAK,EAAE,CAAC;QAdM,SAAI,GAAG,aAAa,CAAC;QAE9B,WAAM,GAAG,IAAI,YA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,CAAC,IAAI;QAC/D,MAAM,IAAI,GAAG,KAAK,CAAC,OAAO,CAAC,MAAM,EAAE,MAAM,CAAC,CAAC;QAC3C,OAAO,CAAC,IAAI,CAAC,GAAG,CAAC,IAAI,CAAC,CAAC,CAAC;IAC1B,CAAC;IAED;;;;OAIG;IACH,iBAAiB,CAAC,MAAc,EAAE,SAAiB,MAAM,CAAC,IAAI;QAC5D,MAAM,QAAQ,GAAG,KAAK,CAAC,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,CAAC;QAC9C,OAAO,CAAC,IAAI,CAAC,GAAG,CAAC,QAAQ,CAAC,CAAC,CAAC;IAC9B,CAAC;IAED;;;;;OAKG;IACH,eAAe,CAAC,KAAa,EAAE,GAAW;QACxC,MAAM,QAAQ,GAAG,KAAK,CAAC,IAAI,CAAC,KAAK,EAAE,GAAG,CAAC,CAAC;QACxC,OAAO,CAAC,IAAI,CAAC,GAAG,CAAC,QAAQ,CAAC,CAAC,CAAC;IAC9B,CAAC;IAED;;;OAGG;IACH,oBAAoB,CAAC,SAAqB;QACxC,OAAO,CAAC,IAAI,CAAC,GAAG,CAAC,IAAI,iBAAiB,CAAC,SAAS,CAAC,CAAC,CAAC,CAAC;IACtD,CAAC;CACF"}
|
|
@@ -0,0 +1,226 @@
|
|
|
1
|
+
import { BoundingBox } from '../BoundingBox';
|
|
2
|
+
import { CollisionJumpTable } from './CollisionJumpTable';
|
|
3
|
+
import { PolygonCollider } from './PolygonCollider';
|
|
4
|
+
import { EdgeCollider } from './EdgeCollider';
|
|
5
|
+
import { Projection } from '../../Math/projection';
|
|
6
|
+
import { Vector } from '../../Math/vector';
|
|
7
|
+
import { Color } from '../../Color';
|
|
8
|
+
import { Collider } from './Collider';
|
|
9
|
+
import { ClosestLineJumpTable } from './ClosestLineJumpTable';
|
|
10
|
+
import { AffineMatrix } from '../../Math/affine-matrix';
|
|
11
|
+
/**
|
|
12
|
+
* This is a circle collider for the excalibur rigid body physics simulation
|
|
13
|
+
*/
|
|
14
|
+
export class CircleCollider extends Collider {
|
|
15
|
+
get worldPos() {
|
|
16
|
+
return this._globalMatrix.getPosition();
|
|
17
|
+
}
|
|
18
|
+
/**
|
|
19
|
+
* Get the radius of the circle
|
|
20
|
+
*/
|
|
21
|
+
get radius() {
|
|
22
|
+
var _a;
|
|
23
|
+
const tx = this._transform;
|
|
24
|
+
const scale = (_a = tx === null || tx === void 0 ? void 0 : tx.globalScale) !== null && _a !== void 0 ? _a : Vector.One;
|
|
25
|
+
// This is a trade off, the alternative is retooling circles to support ellipse collisions
|
|
26
|
+
return this._naturalRadius * Math.min(scale.x, scale.y);
|
|
27
|
+
}
|
|
28
|
+
/**
|
|
29
|
+
* Set the radius of the circle
|
|
30
|
+
*/
|
|
31
|
+
set radius(val) {
|
|
32
|
+
var _a;
|
|
33
|
+
const tx = this._transform;
|
|
34
|
+
const scale = (_a = tx === null || tx === void 0 ? void 0 : tx.globalScale) !== null && _a !== void 0 ? _a : Vector.One;
|
|
35
|
+
// This is a trade off, the alternative is retooling circles to support ellipse collisions
|
|
36
|
+
this._naturalRadius = val / Math.min(scale.x, scale.y);
|
|
37
|
+
}
|
|
38
|
+
constructor(options) {
|
|
39
|
+
super();
|
|
40
|
+
/**
|
|
41
|
+
* Position of the circle relative to the collider, by default (0, 0).
|
|
42
|
+
*/
|
|
43
|
+
this.offset = Vector.Zero;
|
|
44
|
+
this._globalMatrix = AffineMatrix.identity();
|
|
45
|
+
this.offset = options.offset || Vector.Zero;
|
|
46
|
+
this.radius = options.radius || 0;
|
|
47
|
+
this._globalMatrix.translate(this.offset.x, this.offset.y);
|
|
48
|
+
}
|
|
49
|
+
/**
|
|
50
|
+
* Returns a clone of this shape, not associated with any collider
|
|
51
|
+
*/
|
|
52
|
+
clone() {
|
|
53
|
+
return new CircleCollider({
|
|
54
|
+
offset: this.offset.clone(),
|
|
55
|
+
radius: this.radius
|
|
56
|
+
});
|
|
57
|
+
}
|
|
58
|
+
/**
|
|
59
|
+
* Get the center of the collider in world coordinates
|
|
60
|
+
*/
|
|
61
|
+
get center() {
|
|
62
|
+
return this._globalMatrix.getPosition();
|
|
63
|
+
}
|
|
64
|
+
/**
|
|
65
|
+
* Tests if a point is contained in this collider
|
|
66
|
+
*/
|
|
67
|
+
contains(point) {
|
|
68
|
+
var _a, _b;
|
|
69
|
+
const pos = (_b = (_a = this._transform) === null || _a === void 0 ? void 0 : _a.pos) !== null && _b !== void 0 ? _b : this.offset;
|
|
70
|
+
const distance = pos.distance(point);
|
|
71
|
+
if (distance <= this.radius) {
|
|
72
|
+
return true;
|
|
73
|
+
}
|
|
74
|
+
return false;
|
|
75
|
+
}
|
|
76
|
+
/**
|
|
77
|
+
* Casts a ray at the Circle collider and returns the nearest point of collision
|
|
78
|
+
* @param ray
|
|
79
|
+
*/
|
|
80
|
+
rayCast(ray, max = Infinity) {
|
|
81
|
+
//https://en.wikipedia.org/wiki/Line%E2%80%93sphere_intersection
|
|
82
|
+
const c = this.center;
|
|
83
|
+
const dir = ray.dir;
|
|
84
|
+
const orig = ray.pos;
|
|
85
|
+
const discriminant = Math.sqrt(Math.pow(dir.dot(orig.sub(c)), 2) - Math.pow(orig.sub(c).distance(), 2) + Math.pow(this.radius, 2));
|
|
86
|
+
if (discriminant < 0) {
|
|
87
|
+
// no intersection
|
|
88
|
+
return null;
|
|
89
|
+
}
|
|
90
|
+
else {
|
|
91
|
+
let toi = 0;
|
|
92
|
+
if (discriminant === 0) {
|
|
93
|
+
toi = -dir.dot(orig.sub(c));
|
|
94
|
+
if (toi > 0 && toi < max) {
|
|
95
|
+
return ray.getPoint(toi);
|
|
96
|
+
}
|
|
97
|
+
return null;
|
|
98
|
+
}
|
|
99
|
+
else {
|
|
100
|
+
const toi1 = -dir.dot(orig.sub(c)) + discriminant;
|
|
101
|
+
const toi2 = -dir.dot(orig.sub(c)) - discriminant;
|
|
102
|
+
const positiveToi = [];
|
|
103
|
+
if (toi1 >= 0) {
|
|
104
|
+
positiveToi.push(toi1);
|
|
105
|
+
}
|
|
106
|
+
if (toi2 >= 0) {
|
|
107
|
+
positiveToi.push(toi2);
|
|
108
|
+
}
|
|
109
|
+
const mintoi = Math.min(...positiveToi);
|
|
110
|
+
if (mintoi <= max) {
|
|
111
|
+
return ray.getPoint(mintoi);
|
|
112
|
+
}
|
|
113
|
+
return null;
|
|
114
|
+
}
|
|
115
|
+
}
|
|
116
|
+
}
|
|
117
|
+
getClosestLineBetween(shape) {
|
|
118
|
+
if (shape instanceof CircleCollider) {
|
|
119
|
+
return ClosestLineJumpTable.CircleCircleClosestLine(this, shape);
|
|
120
|
+
}
|
|
121
|
+
else if (shape instanceof PolygonCollider) {
|
|
122
|
+
return ClosestLineJumpTable.PolygonCircleClosestLine(shape, this).flip();
|
|
123
|
+
}
|
|
124
|
+
else if (shape instanceof EdgeCollider) {
|
|
125
|
+
return ClosestLineJumpTable.CircleEdgeClosestLine(this, shape).flip();
|
|
126
|
+
}
|
|
127
|
+
else {
|
|
128
|
+
throw new Error(`Polygon could not collide with unknown CollisionShape ${typeof shape}`);
|
|
129
|
+
}
|
|
130
|
+
}
|
|
131
|
+
/**
|
|
132
|
+
* @inheritdoc
|
|
133
|
+
*/
|
|
134
|
+
collide(collider) {
|
|
135
|
+
if (collider instanceof CircleCollider) {
|
|
136
|
+
return CollisionJumpTable.CollideCircleCircle(this, collider);
|
|
137
|
+
}
|
|
138
|
+
else if (collider instanceof PolygonCollider) {
|
|
139
|
+
return CollisionJumpTable.CollideCirclePolygon(this, collider);
|
|
140
|
+
}
|
|
141
|
+
else if (collider instanceof EdgeCollider) {
|
|
142
|
+
return CollisionJumpTable.CollideCircleEdge(this, collider);
|
|
143
|
+
}
|
|
144
|
+
else {
|
|
145
|
+
throw new Error(`Circle could not collide with unknown CollisionShape ${typeof collider}`);
|
|
146
|
+
}
|
|
147
|
+
}
|
|
148
|
+
/**
|
|
149
|
+
* Find the point on the collider furthest in the direction specified
|
|
150
|
+
*/
|
|
151
|
+
getFurthestPoint(direction) {
|
|
152
|
+
return this.center.add(direction.normalize().scale(this.radius));
|
|
153
|
+
}
|
|
154
|
+
/**
|
|
155
|
+
* Find the local point on the shape in the direction specified
|
|
156
|
+
* @param direction
|
|
157
|
+
*/
|
|
158
|
+
getFurthestLocalPoint(direction) {
|
|
159
|
+
const dir = direction.normalize();
|
|
160
|
+
return dir.scale(this.radius);
|
|
161
|
+
}
|
|
162
|
+
/**
|
|
163
|
+
* Get the axis aligned bounding box for the circle collider in world coordinates
|
|
164
|
+
*/
|
|
165
|
+
get bounds() {
|
|
166
|
+
var _a, _b, _c;
|
|
167
|
+
const tx = this._transform;
|
|
168
|
+
const scale = (_a = tx === null || tx === void 0 ? void 0 : tx.globalScale) !== null && _a !== void 0 ? _a : Vector.One;
|
|
169
|
+
const rotation = (_b = tx === null || tx === void 0 ? void 0 : tx.globalRotation) !== null && _b !== void 0 ? _b : 0;
|
|
170
|
+
const pos = ((_c = tx === null || tx === void 0 ? void 0 : tx.globalPos) !== null && _c !== void 0 ? _c : Vector.Zero);
|
|
171
|
+
return new BoundingBox(this.offset.x - this._naturalRadius, this.offset.y - this._naturalRadius, this.offset.x + this._naturalRadius, this.offset.y + this._naturalRadius).rotate(rotation).scale(scale).translate(pos);
|
|
172
|
+
}
|
|
173
|
+
/**
|
|
174
|
+
* Get the axis aligned bounding box for the circle collider in local coordinates
|
|
175
|
+
*/
|
|
176
|
+
get localBounds() {
|
|
177
|
+
return new BoundingBox(this.offset.x - this._naturalRadius, this.offset.y - this._naturalRadius, this.offset.x + this._naturalRadius, this.offset.y + this._naturalRadius);
|
|
178
|
+
}
|
|
179
|
+
/**
|
|
180
|
+
* Get axis not implemented on circles, since there are infinite axis in a circle
|
|
181
|
+
*/
|
|
182
|
+
get axes() {
|
|
183
|
+
return [];
|
|
184
|
+
}
|
|
185
|
+
/**
|
|
186
|
+
* Returns the moment of inertia of a circle given it's mass
|
|
187
|
+
* https://en.wikipedia.org/wiki/List_of_moments_of_inertia
|
|
188
|
+
*/
|
|
189
|
+
getInertia(mass) {
|
|
190
|
+
return (mass * this.radius * this.radius) / 2;
|
|
191
|
+
}
|
|
192
|
+
/* istanbul ignore next */
|
|
193
|
+
update(transform) {
|
|
194
|
+
var _a;
|
|
195
|
+
this._transform = transform;
|
|
196
|
+
const globalMat = (_a = transform.matrix) !== null && _a !== void 0 ? _a : this._globalMatrix;
|
|
197
|
+
globalMat.clone(this._globalMatrix);
|
|
198
|
+
this._globalMatrix.translate(this.offset.x, this.offset.y);
|
|
199
|
+
}
|
|
200
|
+
/**
|
|
201
|
+
* Project the circle along a specified axis
|
|
202
|
+
*/
|
|
203
|
+
project(axis) {
|
|
204
|
+
const scalars = [];
|
|
205
|
+
const point = this.center;
|
|
206
|
+
const dotProduct = point.dot(axis);
|
|
207
|
+
scalars.push(dotProduct);
|
|
208
|
+
scalars.push(dotProduct + this.radius);
|
|
209
|
+
scalars.push(dotProduct - this.radius);
|
|
210
|
+
return new Projection(Math.min.apply(Math, scalars), Math.max.apply(Math, scalars));
|
|
211
|
+
}
|
|
212
|
+
debug(ex, color) {
|
|
213
|
+
var _a, _b, _c, _d;
|
|
214
|
+
const tx = this._transform;
|
|
215
|
+
const scale = (_a = tx === null || tx === void 0 ? void 0 : tx.globalScale) !== null && _a !== void 0 ? _a : Vector.One;
|
|
216
|
+
const rotation = (_b = tx === null || tx === void 0 ? void 0 : tx.globalRotation) !== null && _b !== void 0 ? _b : 0;
|
|
217
|
+
const pos = ((_c = tx === null || tx === void 0 ? void 0 : tx.globalPos) !== null && _c !== void 0 ? _c : Vector.Zero);
|
|
218
|
+
ex.save();
|
|
219
|
+
ex.translate(pos.x, pos.y);
|
|
220
|
+
ex.rotate(rotation);
|
|
221
|
+
ex.scale(scale.x, scale.y);
|
|
222
|
+
ex.drawCircle(((_d = this.offset) !== null && _d !== void 0 ? _d : Vector.Zero), this._naturalRadius, Color.Transparent, color, 2);
|
|
223
|
+
ex.restore();
|
|
224
|
+
}
|
|
225
|
+
}
|
|
226
|
+
//# sourceMappingURL=Circ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AC,EAAE,IAAI,CAAC,cAAc,EAAE,KAAK,CAAC,WAAW,EAAE,KAAK,EAAE,CAAC,CAAC,CAAC;QAC9F,EAAE,CAAC,OAAO,EAAE,CAAC;IACf,CAAC;CACF"}
|
|
@@ -0,0 +1,211 @@
|
|
|
1
|
+
import { LineSegment } from '../../Math/line-segment';
|
|
2
|
+
import { Vector } from '../../Math/vector';
|
|
3
|
+
import { Ray } from '../../Math/ray';
|
|
4
|
+
/**
|
|
5
|
+
* Finds the closes line between 2 line segments, were the magnitude of u, v are the lengths of each segment
|
|
6
|
+
* L1 = P(s) = p0 + s * u, where s is time and p0 is the start of the line
|
|
7
|
+
* L2 = Q(t) = q0 + t * v, where t is time and q0 is the start of the line
|
|
8
|
+
* @param p0 Point where L1 begins
|
|
9
|
+
* @param u Direction and length of L1
|
|
10
|
+
* @param q0 Point were L2 begins
|
|
11
|
+
* @param v Direction and length of L2
|
|
12
|
+
*/
|
|
13
|
+
export function ClosestLine(p0, u, q0, v) {
|
|
14
|
+
// Distance between 2 lines http://geomalgorithms.com/a07-_distance.html
|
|
15
|
+
// w(s, t) = P(s) - Q(t)
|
|
16
|
+
// The w(s, t) that has the minimum distance we will say is w(sClosest, tClosest) = wClosest
|
|
17
|
+
//
|
|
18
|
+
// wClosest is the vector that is uniquely perpendicular to the 2 line directions u & v.
|
|
19
|
+
// wClosest = w0 + sClosest * u - tClosest * v, where w0 is p0 - q0
|
|
20
|
+
//
|
|
21
|
+
// The closest point between 2 lines then satisfies this pair of equations
|
|
22
|
+
// 1: u * wClosest = 0
|
|
23
|
+
// 2: v * wClosest = 0
|
|
24
|
+
//
|
|
25
|
+
// Substituting wClosest into the equations we get
|
|
26
|
+
//
|
|
27
|
+
// 1: (u * u) * sClosest - (u * v) tClosest = -u * w0
|
|
28
|
+
// 2: (v * u) * sClosest - (v * v) tClosest = -v * w0
|
|
29
|
+
// simplify w0
|
|
30
|
+
const w0 = p0.sub(q0);
|
|
31
|
+
// simplify (u * u);
|
|
32
|
+
const a = u.dot(u);
|
|
33
|
+
// simplify (u * v);
|
|
34
|
+
const b = u.dot(v);
|
|
35
|
+
// simplify (v * v)
|
|
36
|
+
const c = v.dot(v);
|
|
37
|
+
// simplify (u * w0)
|
|
38
|
+
const d = u.dot(w0);
|
|
39
|
+
// simplify (v * w0)
|
|
40
|
+
const e = v.dot(w0);
|
|
41
|
+
// denominator ac - b^2
|
|
42
|
+
const denom = a * c - b * b;
|
|
43
|
+
let sDenom = denom;
|
|
44
|
+
let tDenom = denom;
|
|
45
|
+
// if denom is 0 they are parallel, use any point from either as the start in this case p0
|
|
46
|
+
if (denom === 0 || denom <= 0.01) {
|
|
47
|
+
const tClosestParallel = d / b;
|
|
48
|
+
return new LineSegment(p0, q0.add(v.scale(tClosestParallel)));
|
|
49
|
+
}
|
|
50
|
+
// Solve for sClosest for infinite line
|
|
51
|
+
let sClosest = b * e - c * d; // / denom;
|
|
52
|
+
// Solve for tClosest for infinite line
|
|
53
|
+
let tClosest = a * e - b * d; // / denom;
|
|
54
|
+
// Solve for segments candidate edges, if sClosest and tClosest are outside their segments
|
|
55
|
+
if (sClosest < 0) {
|
|
56
|
+
sClosest = 0;
|
|
57
|
+
tClosest = e;
|
|
58
|
+
tDenom = c;
|
|
59
|
+
}
|
|
60
|
+
else if (sClosest > sDenom) {
|
|
61
|
+
sClosest = sDenom;
|
|
62
|
+
tClosest = e + b;
|
|
63
|
+
tDenom = c;
|
|
64
|
+
}
|
|
65
|
+
if (tClosest < 0) {
|
|
66
|
+
tClosest = 0;
|
|
67
|
+
if (-d < 0) {
|
|
68
|
+
sClosest = 0;
|
|
69
|
+
}
|
|
70
|
+
else if (-d > a) {
|
|
71
|
+
sClosest = sDenom;
|
|
72
|
+
}
|
|
73
|
+
else {
|
|
74
|
+
sClosest = -d;
|
|
75
|
+
sDenom = a;
|
|
76
|
+
}
|
|
77
|
+
}
|
|
78
|
+
else if (tClosest > tDenom) {
|
|
79
|
+
tClosest = tDenom;
|
|
80
|
+
if (-d + b < 0) {
|
|
81
|
+
sClosest = 0;
|
|
82
|
+
}
|
|
83
|
+
else if (-d + b > a) {
|
|
84
|
+
sClosest = sDenom;
|
|
85
|
+
}
|
|
86
|
+
else {
|
|
87
|
+
sClosest = -d + b;
|
|
88
|
+
sDenom = a;
|
|
89
|
+
}
|
|
90
|
+
}
|
|
91
|
+
sClosest = Math.abs(sClosest) < 0.001 ? 0 : sClosest / sDenom;
|
|
92
|
+
tClosest = Math.abs(tClosest) < 0.001 ? 0 : tClosest / tDenom;
|
|
93
|
+
return new LineSegment(p0.add(u.scale(sClosest)), q0.add(v.scale(tClosest)));
|
|
94
|
+
}
|
|
95
|
+
export const ClosestLineJumpTable = {
|
|
96
|
+
PolygonPolygonClosestLine(polygonA, polygonB) {
|
|
97
|
+
// Find the 2 closest faces on each polygon
|
|
98
|
+
const otherWorldPos = polygonB.worldPos;
|
|
99
|
+
const otherDirection = otherWorldPos.sub(polygonA.worldPos);
|
|
100
|
+
const thisDirection = otherDirection.negate();
|
|
101
|
+
const rayTowardsOther = new Ray(polygonA.worldPos, otherDirection);
|
|
102
|
+
const rayTowardsThis = new Ray(otherWorldPos, thisDirection);
|
|
103
|
+
const thisPoint = polygonA.rayCast(rayTowardsOther).add(rayTowardsOther.dir.scale(0.1));
|
|
104
|
+
const otherPoint = polygonB.rayCast(rayTowardsThis).add(rayTowardsThis.dir.scale(0.1));
|
|
105
|
+
const thisFace = polygonA.getClosestFace(thisPoint);
|
|
106
|
+
const otherFace = polygonB.getClosestFace(otherPoint);
|
|
107
|
+
// L1 = P(s) = p0 + s * u, where s is time and p0 is the start of the line
|
|
108
|
+
const p0 = thisFace.face.begin;
|
|
109
|
+
const u = thisFace.face.getEdge();
|
|
110
|
+
// L2 = Q(t) = q0 + t * v, where t is time and q0 is the start of the line
|
|
111
|
+
const q0 = otherFace.face.begin;
|
|
112
|
+
const v = otherFace.face.getEdge();
|
|
113
|
+
return ClosestLine(p0, u, q0, v);
|
|
114
|
+
},
|
|
115
|
+
PolygonEdgeClosestLine(polygon, edge) {
|
|
116
|
+
// Find the 2 closest faces on each polygon
|
|
117
|
+
const otherWorldPos = edge.worldPos;
|
|
118
|
+
const otherDirection = otherWorldPos.sub(polygon.worldPos);
|
|
119
|
+
const rayTowardsOther = new Ray(polygon.worldPos, otherDirection);
|
|
120
|
+
const thisPoint = polygon.rayCast(rayTowardsOther).add(rayTowardsOther.dir.scale(0.1));
|
|
121
|
+
const thisFace = polygon.getClosestFace(thisPoint);
|
|
122
|
+
// L1 = P(s) = p0 + s * u, where s is time and p0 is the start of the line
|
|
123
|
+
const p0 = thisFace.face.begin;
|
|
124
|
+
const u = thisFace.face.getEdge();
|
|
125
|
+
// L2 = Q(t) = q0 + t * v, where t is time and q0 is the start of the line
|
|
126
|
+
const edgeLine = edge.asLine();
|
|
127
|
+
const edgeStart = edgeLine.begin;
|
|
128
|
+
const edgeVector = edgeLine.getEdge();
|
|
129
|
+
const q0 = edgeStart;
|
|
130
|
+
const v = edgeVector;
|
|
131
|
+
return ClosestLine(p0, u, q0, v);
|
|
132
|
+
},
|
|
133
|
+
PolygonCircleClosestLine(polygon, circle) {
|
|
134
|
+
// https://math.stackexchange.com/questions/1919177/how-to-find-point-on-line-closest-to-sphere
|
|
135
|
+
// Find the 2 closest faces on each polygon
|
|
136
|
+
const otherWorldPos = circle.worldPos;
|
|
137
|
+
const otherDirection = otherWorldPos.sub(polygon.worldPos);
|
|
138
|
+
const rayTowardsOther = new Ray(polygon.worldPos, otherDirection.normalize());
|
|
139
|
+
const thisPoint = polygon.rayCast(rayTowardsOther).add(rayTowardsOther.dir.scale(0.1));
|
|
140
|
+
const thisFace = polygon.getClosestFace(thisPoint);
|
|
141
|
+
// L1 = P(s) = p0 + s * u, where s is time and p0 is the start of the line
|
|
142
|
+
const p0 = thisFace.face.begin;
|
|
143
|
+
const u = thisFace.face.getEdge();
|
|
144
|
+
// Time of minimum distance
|
|
145
|
+
let t = (u.x * (otherWorldPos.x - p0.x) + u.y * (otherWorldPos.y - p0.y)) / (u.x * u.x + u.y * u.y);
|
|
146
|
+
// If time of minimum is past the edge clamp
|
|
147
|
+
if (t > 1) {
|
|
148
|
+
t = 1;
|
|
149
|
+
}
|
|
150
|
+
else if (t < 0) {
|
|
151
|
+
t = 0;
|
|
152
|
+
}
|
|
153
|
+
// Minimum distance
|
|
154
|
+
const d = Math.sqrt(Math.pow(p0.x + u.x * t - otherWorldPos.x, 2) + Math.pow(p0.y + u.y * t - otherWorldPos.y, 2)) - circle.radius;
|
|
155
|
+
const circlex = ((p0.x + u.x * t - otherWorldPos.x) * circle.radius) / (circle.radius + d);
|
|
156
|
+
const circley = ((p0.y + u.y * t - otherWorldPos.y) * circle.radius) / (circle.radius + d);
|
|
157
|
+
return new LineSegment(u.scale(t).add(p0), new Vector(otherWorldPos.x + circlex, otherWorldPos.y + circley));
|
|
158
|
+
},
|
|
159
|
+
CircleCircleClosestLine(circleA, circleB) {
|
|
160
|
+
// Find the 2 closest faces on each polygon
|
|
161
|
+
const otherWorldPos = circleB.worldPos;
|
|
162
|
+
const otherDirection = otherWorldPos.sub(circleA.worldPos);
|
|
163
|
+
const thisWorldPos = circleA.worldPos;
|
|
164
|
+
const thisDirection = thisWorldPos.sub(circleB.worldPos);
|
|
165
|
+
const rayTowardsOther = new Ray(circleA.worldPos, otherDirection);
|
|
166
|
+
const rayTowardsThis = new Ray(circleB.worldPos, thisDirection);
|
|
167
|
+
const thisPoint = circleA.rayCast(rayTowardsOther);
|
|
168
|
+
const otherPoint = circleB.rayCast(rayTowardsThis);
|
|
169
|
+
return new LineSegment(thisPoint, otherPoint);
|
|
170
|
+
},
|
|
171
|
+
CircleEdgeClosestLine(circle, edge) {
|
|
172
|
+
// https://math.stackexchange.com/questions/1919177/how-to-find-point-on-line-closest-to-sphere
|
|
173
|
+
const circleWorlPos = circle.worldPos;
|
|
174
|
+
// L1 = P(s) = p0 + s * u, where s is time and p0 is the start of the line
|
|
175
|
+
const edgeLine = edge.asLine();
|
|
176
|
+
const edgeStart = edgeLine.begin;
|
|
177
|
+
const edgeVector = edgeLine.getEdge();
|
|
178
|
+
const p0 = edgeStart;
|
|
179
|
+
const u = edgeVector;
|
|
180
|
+
// Time of minimum distance
|
|
181
|
+
let t = (u.x * (circleWorlPos.x - p0.x) + u.y * (circleWorlPos.y - p0.y)) / (u.x * u.x + u.y * u.y);
|
|
182
|
+
// If time of minimum is past the edge clamp to edge
|
|
183
|
+
if (t > 1) {
|
|
184
|
+
t = 1;
|
|
185
|
+
}
|
|
186
|
+
else if (t < 0) {
|
|
187
|
+
t = 0;
|
|
188
|
+
}
|
|
189
|
+
// Minimum distance
|
|
190
|
+
const d = Math.sqrt(Math.pow(p0.x + u.x * t - circleWorlPos.x, 2) + Math.pow(p0.y + u.y * t - circleWorlPos.y, 2)) - circle.radius;
|
|
191
|
+
const circlex = ((p0.x + u.x * t - circleWorlPos.x) * circle.radius) / (circle.radius + d);
|
|
192
|
+
const circley = ((p0.y + u.y * t - circleWorlPos.y) * circle.radius) / (circle.radius + d);
|
|
193
|
+
return new LineSegment(u.scale(t).add(p0), new Vector(circleWorlPos.x + circlex, circleWorlPos.y + circley));
|
|
194
|
+
},
|
|
195
|
+
EdgeEdgeClosestLine(edgeA, edgeB) {
|
|
196
|
+
// L1 = P(s) = p0 + s * u, where s is time and p0 is the start of the line
|
|
197
|
+
const edgeLineA = edgeA.asLine();
|
|
198
|
+
const edgeStartA = edgeLineA.begin;
|
|
199
|
+
const edgeVectorA = edgeLineA.getEdge();
|
|
200
|
+
const p0 = edgeStartA;
|
|
201
|
+
const u = edgeVectorA;
|
|
202
|
+
// L2 = Q(t) = q0 + t * v, where t is time and q0 is the start of the line
|
|
203
|
+
const edgeLineB = edgeB.asLine();
|
|
204
|
+
const edgeStartB = edgeLineB.begin;
|
|
205
|
+
const edgeVectorB = edgeLineB.getEdge();
|
|
206
|
+
const q0 = edgeStartB;
|
|
207
|
+
const v = edgeVectorB;
|
|
208
|
+
return ClosestLine(p0, u, q0, v);
|
|
209
|
+
}
|
|
210
|
+
};
|
|
211
|
+
//# sourceMappingURL=ClosestLineJumpTable.js.map
|