laymur 0.16.0 → 0.17.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/.claude/settings.local.json +9 -0
- package/.editorconfig +14 -0
- package/CLAUDE.md +181 -0
- package/README.md +84 -208
- package/assets/logotype.png +0 -0
- package/eslint.config.js +111 -0
- package/package.json +20 -36
- package/rollup.config.js +52 -0
- package/{dist/constraints/UIAspectConstraint/UIAspectConstraint.Internal.d.ts → src/core/constraints/UIAspectConstraint/UIAspectConstraint.Internal.ts} +3 -2
- package/src/core/constraints/UIAspectConstraint/UIAspectConstraint.ts +60 -0
- package/src/core/constraints/UIConstraint.ts +20 -0
- package/src/core/constraints/UICustomConstraint.ts +62 -0
- package/{dist/constraints/UIHeightConstraint/UIHeightConstraint.Internal.d.ts → src/core/constraints/UIHeightConstraint/UIHeightConstraint.Internal.ts} +3 -2
- package/src/core/constraints/UIHeightConstraint/UIHeightConstraint.ts +52 -0
- package/src/core/constraints/UIHorizontalDistanceConstraint/UIHorizontalDistanceConstraint.Internal.ts +13 -0
- package/src/core/constraints/UIHorizontalDistanceConstraint/UIHorizontalDistanceConstraint.ts +139 -0
- package/src/core/constraints/UIHorizontalInterpolationConstraint/UIHorizontalInterpolationConstraint.Internal.ts +16 -0
- package/src/core/constraints/UIHorizontalInterpolationConstraint/UIHorizontalInterpolationConstraint.ts +189 -0
- package/{dist/constraints/UIHorizontalProportionConstraint/UIHorizontalProportionConstraint.Internal.d.ts → src/core/constraints/UIHorizontalProportionConstraint/UIHorizontalProportionConstraint.Internal.ts} +3 -2
- package/src/core/constraints/UIHorizontalProportionConstraint/UIHorizontalProportionConstraint.ts +68 -0
- package/{dist/constraints/UISingleParameterConstraint/UISingleParameterConstraint.Internal.d.ts → src/core/constraints/UISingleParameterConstraint/UISingleParameterConstraint.Internal.ts} +9 -8
- package/src/core/constraints/UISingleParameterConstraint/UISingleParameterConstraint.ts +94 -0
- package/src/core/constraints/UIVerticalDistanceConstraint/UIVerticalDistanceConstraint.Internal.ts +13 -0
- package/src/core/constraints/UIVerticalDistanceConstraint/UIVerticalDistanceConstraint.ts +135 -0
- package/src/core/constraints/UIVerticalInterpolationConstraint/UIVerticalInterpolationConstraint.Internal.ts +16 -0
- package/src/core/constraints/UIVerticalInterpolationConstraint/UIVerticalInterpolationConstraint.ts +189 -0
- package/{dist/constraints/UIVerticalProportionConstraint/UIVerticalProportionConstraint.Internal.d.ts → src/core/constraints/UIVerticalProportionConstraint/UIVerticalProportionConstraint.Internal.ts} +3 -2
- package/src/core/constraints/UIVerticalProportionConstraint/UIVerticalProportionConstraint.ts +68 -0
- package/{dist/constraints/UIWidthConstraint/UIWidthConstraint.Internal.d.ts → src/core/constraints/UIWidthConstraint/UIWidthConstraint.Internal.ts} +3 -2
- package/src/core/constraints/UIWidthConstraint/UIWidthConstraint.ts +52 -0
- package/src/core/constraints/builders/UIConstraint2DBuilder.Internal.ts +84 -0
- package/src/core/constraints/builders/UIConstraint2DBuilder.ts +168 -0
- package/src/core/constraints/builders/UICoverConstraintBuilder.Internal.ts +15 -0
- package/src/core/constraints/builders/UICoverConstraintBuilder.ts +84 -0
- package/src/core/constraints/builders/UIFitConstraintBuilder.Internal.ts +15 -0
- package/src/core/constraints/builders/UIFitConstraintBuilder.ts +84 -0
- package/src/core/elements/UIAnchor/UIAnchor.Internal.ts +13 -0
- package/src/core/elements/UIAnchor/UIAnchor.ts +70 -0
- package/src/core/elements/UIAnimatedImage/UIAnimatedImage.Internal.ts +30 -0
- package/src/core/elements/UIAnimatedImage/UIAnimatedImage.ts +355 -0
- package/src/core/elements/UIDummy/UIDummy.Internal.ts +33 -0
- package/src/core/elements/UIDummy/UIDummy.ts +244 -0
- package/{dist/elements/UIElement/UIElement.Internal.d.ts → src/core/elements/UIElement/UIElement.Internal.ts} +7 -5
- package/src/core/elements/UIElement/UIElement.ts +127 -0
- package/{dist/elements/UIGraphics/UIGraphics.Internal.d.ts → src/core/elements/UIGraphics/UIGraphics.Internal.ts} +7 -5
- package/src/core/elements/UIGraphics/UIGraphics.ts +168 -0
- package/{dist/elements/UIImage/UIImage.Internal.d.ts → src/core/elements/UIImage/UIImage.Internal.ts} +3 -2
- package/src/core/elements/UIImage/UIImage.ts +138 -0
- package/src/core/elements/UINineSlice/UINineSlice.Internal.ts +26 -0
- package/src/core/elements/UINineSlice/UINineSlice.ts +296 -0
- package/src/core/elements/UIProgress/UIProgress.Internal.ts +24 -0
- package/src/core/elements/UIProgress/UIProgress.ts +259 -0
- package/src/core/elements/UIScene/UIScene.Internal.ts +46 -0
- package/src/core/elements/UIScene/UIScene.ts +259 -0
- package/{dist/elements/UIText/UIText.Interfaces.d.ts → src/core/elements/UIText/UIText.Interfaces.ts} +21 -16
- package/src/core/elements/UIText/UIText.Internal.ts +29 -0
- package/src/core/elements/UIText/UIText.Measuring.ts +183 -0
- package/src/core/elements/UIText/UIText.Rendering.ts +83 -0
- package/src/core/elements/UIText/UIText.ts +376 -0
- package/{dist/layers/UIFullscreenLayer/UIFullscreenLayer.Internal.d.ts → src/core/layers/UIFullscreenLayer/UIFullscreenLayer.Internal.ts} +14 -11
- package/src/core/layers/UIFullscreenLayer/UIFullscreenLayer.ts +233 -0
- package/{dist/layers/UILayer/UILayer.Internal.d.ts → src/core/layers/UILayer/UILayer.Internal.ts} +15 -11
- package/src/core/layers/UILayer/UILayer.ts +156 -0
- package/src/core/miscellaneous/UIExpression.ts +142 -0
- package/src/core/miscellaneous/UIMode.ts +29 -0
- package/src/core/miscellaneous/UIOrientation.ts +18 -0
- package/src/core/miscellaneous/UIPriority.ts +63 -0
- package/src/core/miscellaneous/UIRelation.ts +39 -0
- package/src/core/miscellaneous/UITransparencyMode.ts +9 -0
- package/src/core/miscellaneous/area/UIArea.ts +5 -0
- package/src/core/miscellaneous/area/UIAreaCircle.ts +32 -0
- package/src/core/miscellaneous/area/UIAreaPolygon.ts +50 -0
- package/src/core/miscellaneous/area/UIAreaRectangle.ts +38 -0
- package/src/core/miscellaneous/area/UIAreaRoundedRectangle.ts +78 -0
- package/src/core/miscellaneous/asserts.ts +187 -0
- package/src/core/miscellaneous/canvas.ts +73 -0
- package/src/core/miscellaneous/color/UIColor.Internal.ts +89 -0
- package/src/core/miscellaneous/color/UIColor.ts +844 -0
- package/src/core/miscellaneous/computeTransform.ts +127 -0
- package/src/core/miscellaneous/generic-plane/UIGenericInstancedPlane/UIGenericInstancedPlane.Internal.ts +235 -0
- package/src/core/miscellaneous/generic-plane/UIGenericInstancedPlane/UIGenericInstancedPlane.ts +524 -0
- package/{dist/miscellaneous/generic-plane/UIGenericPlaneRegistry/UIGenericPlaneRegistry.Internal.d.ts → src/core/miscellaneous/generic-plane/UIGenericPlaneRegistry/UIGenericPlaneRegistry.Internal.ts} +10 -8
- package/src/core/miscellaneous/generic-plane/UIGenericPlaneRegistry/UIGenericPlaneRegistry.ts +448 -0
- package/src/core/miscellaneous/generic-plane/shared.ts +323 -0
- package/src/core/miscellaneous/insets/UIInsets.Internal.ts +9 -0
- package/src/core/miscellaneous/insets/UIInsets.ts +248 -0
- package/src/core/miscellaneous/mask-function/UIProgressMaskFunction.ts +24 -0
- package/src/core/miscellaneous/mask-function/UIProgressMaskFunctionCircular.ts +58 -0
- package/src/core/miscellaneous/mask-function/UIProgressMaskFunctionDirectional.ts +52 -0
- package/src/core/miscellaneous/math.ts +16 -0
- package/src/core/miscellaneous/micro/UIMicro.Internal.ts +33 -0
- package/src/core/miscellaneous/micro/UIMicro.ts +222 -0
- package/src/core/miscellaneous/resize-policy/UIResizePolicy.ts +8 -0
- package/src/core/miscellaneous/resize-policy/UIResizePolicyCover.ts +57 -0
- package/src/core/miscellaneous/resize-policy/UIResizePolicyCross.ts +65 -0
- package/src/core/miscellaneous/resize-policy/UIResizePolicyCrossInverted.ts +65 -0
- package/src/core/miscellaneous/resize-policy/UIResizePolicyFit.ts +57 -0
- package/src/core/miscellaneous/resize-policy/UIResizePolicyFixedHeight.ts +65 -0
- package/src/core/miscellaneous/resize-policy/UIResizePolicyFixedWidth.ts +65 -0
- package/src/core/miscellaneous/resize-policy/UIResizePolicyNone.ts +11 -0
- package/src/core/miscellaneous/shared.ts +73 -0
- package/{dist/miscellaneous/text-span/UITextSpan.Internal.d.ts → src/core/miscellaneous/text-span/UITextSpan.Internal.ts} +5 -4
- package/src/core/miscellaneous/text-span/UITextSpan.ts +43 -0
- package/src/core/miscellaneous/text-style/UITextStyle.Internal.ts +52 -0
- package/src/core/miscellaneous/text-style/UITextStyle.ts +479 -0
- package/src/core/miscellaneous/texture/UITextureView.Internal.ts +55 -0
- package/src/core/miscellaneous/texture/UITextureView.ts +308 -0
- package/src/core/miscellaneous/webglCapabilities.ts +129 -0
- package/src/core/shaders/UIImage.glsl +10 -0
- package/src/core/shaders/UINineSlice.glsl +53 -0
- package/src/core/shaders/UIProgress.glsl +15 -0
- package/src/core/shaders/UIProgressMaskFunctionCircular.glsl +13 -0
- package/src/core/shaders/UIProgressMaskFunctionDirectional.glsl +12 -0
- package/src/core/shaders/glsl.d.ts +27 -0
- package/src/core/wrappers/UIInputWrapper/UIInputWrapper.Internal.ts +23 -0
- package/src/core/wrappers/UIInputWrapper/UIInputWrapper.ts +124 -0
- package/src/core/wrappers/UISceneWrapper/UISceneWrapper.Internal.ts +22 -0
- package/src/core/wrappers/UISceneWrapper/UISceneWrapper.ts +101 -0
- package/src/core/wrappers/UISolverWrapper/UISolverWrapper.Internal.ts +58 -0
- package/src/core/wrappers/UISolverWrapper/UISolverWrapper.ts +605 -0
- package/src/particles/behaviorModules/UIBehaviorDirectionalGravity.ts +70 -0
- package/src/particles/behaviorModules/UIBehaviorModule.ts +20 -0
- package/src/particles/behaviorModules/UIBehaviorPointGravity.ts +173 -0
- package/src/particles/behaviorModules/UIBehaviorScaleOverLife.ts +104 -0
- package/src/particles/behaviorModules/UIBehaviorTorqueDamping.ts +75 -0
- package/src/particles/behaviorModules/UIBehaviorTorqueNoise.ts +115 -0
- package/src/particles/behaviorModules/UIBehaviorVelocityDamping.ts +77 -0
- package/src/particles/behaviorModules/UIBehaviorVelocityNoise.ts +118 -0
- package/src/particles/elements/UIEmitter.Internal.ts +22 -0
- package/src/particles/elements/UIEmitter.ts +313 -0
- package/src/particles/index.ts +18 -0
- package/src/particles/instancedParticle/UIInstancedParticle.Internal.ts +263 -0
- package/src/particles/instancedParticle/UIInstancedParticle.ts +138 -0
- package/src/particles/miscellaneous/miscellaneous.ts +115 -0
- package/src/particles/renderingModules/UIRenderingColorOverLife.ts +39 -0
- package/src/particles/renderingModules/UIRenderingColorOverVelocity.ts +49 -0
- package/src/particles/renderingModules/UIRenderingModule.ts +17 -0
- package/src/particles/renderingModules/UIRenderingTexture.ts +30 -0
- package/src/particles/shaders/UIRenderingColorOverLife.glsl +4 -0
- package/src/particles/shaders/UIRenderingColorOverVelocity.glsl +6 -0
- package/src/particles/shaders/UIRenderingTexture.glsl +4 -0
- package/src/particles/spawnModules/UISpawnModule.ts +22 -0
- package/src/particles/spawnModules/UISpawnOffset.ts +62 -0
- package/src/particles/spawnModules/UISpawnRandomLifetime.ts +68 -0
- package/src/particles/spawnModules/UISpawnRandomRotation.ts +60 -0
- package/src/particles/spawnModules/UISpawnRandomScale.ts +81 -0
- package/src/particles/spawnModules/UISpawnRandomTorque.ts +62 -0
- package/src/particles/spawnModules/UISpawnRandomVelocity.ts +92 -0
- package/src/particles/spawnModules/UISpawnRectangle.ts +81 -0
- package/tsconfig.json +29 -0
- package/dist/constraints/UIAspectConstraint/UIAspectConstraint.d.ts +0 -22
- package/dist/constraints/UIConstraint.d.ts +0 -12
- package/dist/constraints/UICustomConstraint.d.ts +0 -28
- package/dist/constraints/UIHeightConstraint/UIHeightConstraint.d.ts +0 -20
- package/dist/constraints/UIHorizontalDistanceConstraint/UIHorizontalDistanceConstraint.Internal.d.ts +0 -11
- package/dist/constraints/UIHorizontalDistanceConstraint/UIHorizontalDistanceConstraint.d.ts +0 -36
- package/dist/constraints/UIHorizontalInterpolationConstraint/UIHorizontalInterpolationConstraint.Internal.d.ts +0 -14
- package/dist/constraints/UIHorizontalInterpolationConstraint/UIHorizontalInterpolationConstraint.d.ts +0 -44
- package/dist/constraints/UIHorizontalProportionConstraint/UIHorizontalProportionConstraint.d.ts +0 -22
- package/dist/constraints/UISingleParameterConstraint/UISingleParameterConstraint.d.ts +0 -43
- package/dist/constraints/UIVerticalDistanceConstraint/UIVerticalDistanceConstraint.Internal.d.ts +0 -11
- package/dist/constraints/UIVerticalDistanceConstraint/UIVerticalDistanceConstraint.d.ts +0 -32
- package/dist/constraints/UIVerticalInterpolationConstraint/UIVerticalInterpolationConstraint.Internal.d.ts +0 -14
- package/dist/constraints/UIVerticalInterpolationConstraint/UIVerticalInterpolationConstraint.d.ts +0 -44
- package/dist/constraints/UIVerticalProportionConstraint/UIVerticalProportionConstraint.d.ts +0 -22
- package/dist/constraints/UIWidthConstraint/UIWidthConstraint.d.ts +0 -20
- package/dist/constraints/builders/UIConstraint2DBuilder.Internal.d.ts +0 -64
- package/dist/constraints/builders/UIConstraint2DBuilder.d.ts +0 -46
- package/dist/constraints/builders/UICoverConstraintBuilder.Internal.d.ts +0 -13
- package/dist/constraints/builders/UICoverConstraintBuilder.d.ts +0 -29
- package/dist/constraints/builders/UIFitConstraintBuilder.Internal.d.ts +0 -13
- package/dist/constraints/builders/UIFitConstraintBuilder.d.ts +0 -29
- package/dist/elements/UIAnchor/UIAnchor.Internal.d.ts +0 -9
- package/dist/elements/UIAnchor/UIAnchor.d.ts +0 -32
- package/dist/elements/UIAnimatedImage/UIAnimatedImage.Internal.d.ts +0 -27
- package/dist/elements/UIAnimatedImage/UIAnimatedImage.d.ts +0 -77
- package/dist/elements/UIDummy/UIDummy.Internal.d.ts +0 -30
- package/dist/elements/UIDummy/UIDummy.d.ts +0 -82
- package/dist/elements/UIElement/UIElement.d.ts +0 -38
- package/dist/elements/UIGraphics/UIGraphics.d.ts +0 -51
- package/dist/elements/UIImage/UIImage.d.ts +0 -32
- package/dist/elements/UINineSlice/UINineSlice.Internal.d.ts +0 -23
- package/dist/elements/UINineSlice/UINineSlice.d.ts +0 -60
- package/dist/elements/UIProgress/UIProgress.Internal.d.ts +0 -14
- package/dist/elements/UIProgress/UIProgress.d.ts +0 -45
- package/dist/elements/UIScene/UIScene.Internal.d.ts +0 -43
- package/dist/elements/UIScene/UIScene.d.ts +0 -59
- package/dist/elements/UIText/UIText.Internal.d.ts +0 -26
- package/dist/elements/UIText/UIText.Measuring.d.ts +0 -50
- package/dist/elements/UIText/UIText.Rendering.d.ts +0 -20
- package/dist/elements/UIText/UIText.d.ts +0 -71
- package/dist/index.js +0 -9246
- package/dist/index.js.map +0 -1
- package/dist/index.min.js +0 -2
- package/dist/index.min.js.map +0 -1
- package/dist/layers/UIFullscreenLayer/UIFullscreenLayer.d.ts +0 -63
- package/dist/layers/UILayer/UILayer.d.ts +0 -49
- package/dist/miscellaneous/UIExpression.d.ts +0 -69
- package/dist/miscellaneous/UIMode.d.ts +0 -23
- package/dist/miscellaneous/UIOrientation.d.ts +0 -15
- package/dist/miscellaneous/UIPriority.d.ts +0 -32
- package/dist/miscellaneous/UIRelation.d.ts +0 -23
- package/dist/miscellaneous/UITransparencyMode.d.ts +0 -9
- package/dist/miscellaneous/area/UIArea.d.ts +0 -3
- package/dist/miscellaneous/area/UIAreaCircle.d.ts +0 -15
- package/dist/miscellaneous/area/UIAreaPolygon.d.ts +0 -12
- package/dist/miscellaneous/area/UIAreaRectangle.d.ts +0 -17
- package/dist/miscellaneous/area/UIAreaRoundedRectangle.d.ts +0 -21
- package/dist/miscellaneous/asserts.d.ts +0 -43
- package/dist/miscellaneous/canvas.d.ts +0 -31
- package/dist/miscellaneous/color/UIColor.Internal.d.ts +0 -7
- package/dist/miscellaneous/color/UIColor.d.ts +0 -234
- package/dist/miscellaneous/computeTransform.d.ts +0 -18
- package/dist/miscellaneous/generic-plane/UIGenericInstancedPlane/UIGenericInstancedPlane.Internal.d.ts +0 -19
- package/dist/miscellaneous/generic-plane/UIGenericInstancedPlane/UIGenericInstancedPlane.d.ts +0 -1
- package/dist/miscellaneous/generic-plane/UIGenericPlaneRegistry/UIGenericPlaneRegistry.d.ts +0 -1
- package/dist/miscellaneous/generic-plane/shared.d.ts +0 -38
- package/dist/miscellaneous/insets/UIInsets.Internal.d.ts +0 -11
- package/dist/miscellaneous/insets/UIInsets.d.ts +0 -48
- package/dist/miscellaneous/mask-function/UIProgressMaskFunction.d.ts +0 -9
- package/dist/miscellaneous/mask-function/UIProgressMaskFunctionCircular.d.ts +0 -21
- package/dist/miscellaneous/mask-function/UIProgressMaskFunctionDirectional.d.ts +0 -16
- package/dist/miscellaneous/math.d.ts +0 -5
- package/dist/miscellaneous/micro/UIMicro.Internal.d.ts +0 -31
- package/dist/miscellaneous/micro/UIMicro.d.ts +0 -59
- package/dist/miscellaneous/resize-policy/UIResizePolicy.d.ts +0 -3
- package/dist/miscellaneous/resize-policy/UIResizePolicyCover.d.ts +0 -22
- package/dist/miscellaneous/resize-policy/UIResizePolicyCross.d.ts +0 -22
- package/dist/miscellaneous/resize-policy/UIResizePolicyCrossInverted.d.ts +0 -22
- package/dist/miscellaneous/resize-policy/UIResizePolicyFit.d.ts +0 -22
- package/dist/miscellaneous/resize-policy/UIResizePolicyFixedHeight.d.ts +0 -22
- package/dist/miscellaneous/resize-policy/UIResizePolicyFixedWidth.d.ts +0 -22
- package/dist/miscellaneous/resize-policy/UIResizePolicyNone.d.ts +0 -5
- package/dist/miscellaneous/shared.d.ts +0 -46
- package/dist/miscellaneous/text-span/UITextSpan.d.ts +0 -14
- package/dist/miscellaneous/text-style/UITextStyle.Internal.d.ts +0 -48
- package/dist/miscellaneous/text-style/UITextStyle.d.ts +0 -85
- package/dist/miscellaneous/texture/UITextureView.Internal.d.ts +0 -49
- package/dist/miscellaneous/texture/UITextureView.d.ts +0 -67
- package/dist/miscellaneous/webglCapabilities.d.ts +0 -2
- package/dist/wrappers/UIInputWrapper/UIInputWrapper.Internal.d.ts +0 -17
- package/dist/wrappers/UIInputWrapper/UIInputWrapper.d.ts +0 -13
- package/dist/wrappers/UISceneWrapper/UISceneWrapper.Internal.d.ts +0 -13
- package/dist/wrappers/UISceneWrapper/UISceneWrapper.d.ts +0 -20
- package/dist/wrappers/UISolverWrapper/UISolverWrapper.Internal.d.ts +0 -49
- package/dist/wrappers/UISolverWrapper/UISolverWrapper.d.ts +0 -215
- /package/{dist/index.d.ts → src/core/index.ts} +0 -0
|
@@ -0,0 +1,189 @@
|
|
|
1
|
+
import {
|
|
2
|
+
assertValidInterpolationConstraintArguments,
|
|
3
|
+
assertValidNumber,
|
|
4
|
+
} from "../../miscellaneous/asserts";
|
|
5
|
+
import type { UIPlaneElement, UIPointElement } from "../../miscellaneous/shared";
|
|
6
|
+
import { isUIPlaneElement, isUIPointElement } from "../../miscellaneous/shared";
|
|
7
|
+
import { UIExpression } from "../../miscellaneous/UIExpression";
|
|
8
|
+
import { UISingleParameterConstraint } from "../UISingleParameterConstraint/UISingleParameterConstraint";
|
|
9
|
+
import type { UIHorizontalInterpolationConstraintOptions } from "./UIHorizontalInterpolationConstraint.Internal";
|
|
10
|
+
import { DEFAULT_ANCHOR, DEFAULT_T } from "./UIHorizontalInterpolationConstraint.Internal";
|
|
11
|
+
|
|
12
|
+
/** Positions element C horizontally between A and B based on interpolation factor */
|
|
13
|
+
export class UIHorizontalInterpolationConstraint extends UISingleParameterConstraint {
|
|
14
|
+
/** Solver constraint descriptor */
|
|
15
|
+
protected override readonly constraint: number;
|
|
16
|
+
|
|
17
|
+
/** Anchor on element A */
|
|
18
|
+
private anchorAInternal: number;
|
|
19
|
+
/** Anchor on element B */
|
|
20
|
+
private anchorBInternal: number;
|
|
21
|
+
/** Anchor on element C */
|
|
22
|
+
private anchorCInternal: number;
|
|
23
|
+
/** Interpolation factor */
|
|
24
|
+
private tInternal: number;
|
|
25
|
+
|
|
26
|
+
/**
|
|
27
|
+
* @param a First element
|
|
28
|
+
* @param b Second element
|
|
29
|
+
* @param c Element to position between A and B
|
|
30
|
+
* @param options Interpolation configuration
|
|
31
|
+
*/
|
|
32
|
+
constructor(
|
|
33
|
+
private readonly a: UIPointElement | UIPlaneElement,
|
|
34
|
+
private readonly b: UIPointElement | UIPlaneElement,
|
|
35
|
+
private readonly c: UIPointElement | UIPlaneElement,
|
|
36
|
+
options: Partial<UIHorizontalInterpolationConstraintOptions> = {},
|
|
37
|
+
) {
|
|
38
|
+
if (options.anchorA !== undefined) {
|
|
39
|
+
assertValidNumber(
|
|
40
|
+
options.anchorA,
|
|
41
|
+
"UIHorizontalInterpolationConstraint.constructor.options.anchorA",
|
|
42
|
+
);
|
|
43
|
+
}
|
|
44
|
+
if (options.anchorB !== undefined) {
|
|
45
|
+
assertValidNumber(
|
|
46
|
+
options.anchorB,
|
|
47
|
+
"UIHorizontalInterpolationConstraint.constructor.options.anchorB",
|
|
48
|
+
);
|
|
49
|
+
}
|
|
50
|
+
if (options.anchorC !== undefined) {
|
|
51
|
+
assertValidNumber(
|
|
52
|
+
options.anchorC,
|
|
53
|
+
"UIHorizontalInterpolationConstraint.constructor.options.anchorC",
|
|
54
|
+
);
|
|
55
|
+
}
|
|
56
|
+
if (options.t !== undefined) {
|
|
57
|
+
assertValidNumber(options.t, "UIHorizontalInterpolationConstraint.constructor.options.t");
|
|
58
|
+
}
|
|
59
|
+
|
|
60
|
+
const anchorA = options.anchorA ?? DEFAULT_ANCHOR;
|
|
61
|
+
const anchorB = options.anchorB ?? DEFAULT_ANCHOR;
|
|
62
|
+
|
|
63
|
+
super(
|
|
64
|
+
assertValidInterpolationConstraintArguments(
|
|
65
|
+
"UIHorizontalInterpolationConstraint.constructor",
|
|
66
|
+
a,
|
|
67
|
+
b,
|
|
68
|
+
c,
|
|
69
|
+
anchorA,
|
|
70
|
+
anchorB,
|
|
71
|
+
),
|
|
72
|
+
options,
|
|
73
|
+
);
|
|
74
|
+
|
|
75
|
+
this.anchorAInternal = anchorA;
|
|
76
|
+
this.anchorBInternal = anchorA;
|
|
77
|
+
this.anchorCInternal = options.anchorC ?? DEFAULT_ANCHOR;
|
|
78
|
+
this.tInternal = options.t ?? DEFAULT_T;
|
|
79
|
+
|
|
80
|
+
this.constraint = this.solverWrapper.createConstraint(
|
|
81
|
+
this.buildLHS(),
|
|
82
|
+
new UIExpression(0),
|
|
83
|
+
this.relation,
|
|
84
|
+
this.priority,
|
|
85
|
+
this.isConstraintEnabled(),
|
|
86
|
+
);
|
|
87
|
+
}
|
|
88
|
+
|
|
89
|
+
/** Interpolation factor (0 = A position, 1 = B position) */
|
|
90
|
+
public get t(): number {
|
|
91
|
+
return this.tInternal;
|
|
92
|
+
}
|
|
93
|
+
|
|
94
|
+
/** Anchor on element A (0 = left, 0.5 = center, 1 = right) */
|
|
95
|
+
public get anchorA(): number {
|
|
96
|
+
return this.anchorAInternal;
|
|
97
|
+
}
|
|
98
|
+
|
|
99
|
+
/** Anchor on element B (0 = left, 0.5 = center, 1 = right) */
|
|
100
|
+
public get anchorB(): number {
|
|
101
|
+
return this.anchorBInternal;
|
|
102
|
+
}
|
|
103
|
+
|
|
104
|
+
/** Anchor on element C (0 = left, 0.5 = center, 1 = right) */
|
|
105
|
+
public get anchorC(): number {
|
|
106
|
+
return this.anchorCInternal;
|
|
107
|
+
}
|
|
108
|
+
|
|
109
|
+
/** Updates interpolation factor */
|
|
110
|
+
public set t(value: number) {
|
|
111
|
+
assertValidNumber(value, "UIHorizontalInterpolationConstraint.t");
|
|
112
|
+
if (this.tInternal !== value) {
|
|
113
|
+
this.tInternal = value;
|
|
114
|
+
this.solverWrapper.setConstraintLHS(this.constraint, this.buildLHS());
|
|
115
|
+
}
|
|
116
|
+
}
|
|
117
|
+
|
|
118
|
+
/** Updates anchor on element A */
|
|
119
|
+
public set anchorA(value: number) {
|
|
120
|
+
assertValidNumber(value, "UIHorizontalInterpolationConstraint.anchorA");
|
|
121
|
+
if (this.anchorAInternal !== value) {
|
|
122
|
+
this.anchorAInternal = value;
|
|
123
|
+
this.solverWrapper.setConstraintLHS(this.constraint, this.buildLHS());
|
|
124
|
+
}
|
|
125
|
+
}
|
|
126
|
+
|
|
127
|
+
/** Updates anchor on element B */
|
|
128
|
+
public set anchorB(value: number) {
|
|
129
|
+
assertValidNumber(value, "UIHorizontalInterpolationConstraint.anchorB");
|
|
130
|
+
if (this.anchorBInternal !== value) {
|
|
131
|
+
this.anchorBInternal = value;
|
|
132
|
+
this.solverWrapper.setConstraintLHS(this.constraint, this.buildLHS());
|
|
133
|
+
}
|
|
134
|
+
}
|
|
135
|
+
|
|
136
|
+
/** Updates anchor on element C */
|
|
137
|
+
public set anchorC(value: number) {
|
|
138
|
+
assertValidNumber(value, "UIHorizontalInterpolationConstraint.anchorC");
|
|
139
|
+
if (this.anchorCInternal !== value) {
|
|
140
|
+
this.anchorCInternal = value;
|
|
141
|
+
this.solverWrapper.setConstraintLHS(this.constraint, this.buildLHS());
|
|
142
|
+
}
|
|
143
|
+
}
|
|
144
|
+
|
|
145
|
+
/** Builds constraint expression: C - A*(1-t) - B*t = 0 */
|
|
146
|
+
private buildLHS(): UIExpression {
|
|
147
|
+
let aExpression: UIExpression;
|
|
148
|
+
let bExpression: UIExpression;
|
|
149
|
+
let cExpression: UIExpression;
|
|
150
|
+
|
|
151
|
+
if (isUIPlaneElement(this.a)) {
|
|
152
|
+
aExpression = new UIExpression(0, [
|
|
153
|
+
[this.a.xVariable, 1],
|
|
154
|
+
[this.a.wVariable, this.anchorAInternal],
|
|
155
|
+
]);
|
|
156
|
+
} else if (isUIPointElement(this.a)) {
|
|
157
|
+
aExpression = new UIExpression().plus(this.a.xVariable, 1);
|
|
158
|
+
} else {
|
|
159
|
+
throw new Error("UIHorizontalInterpolationConstraint.buildLHS.a: invalid element type");
|
|
160
|
+
}
|
|
161
|
+
|
|
162
|
+
if (isUIPlaneElement(this.b)) {
|
|
163
|
+
bExpression = new UIExpression(0, [
|
|
164
|
+
[this.b.xVariable, 1],
|
|
165
|
+
[this.b.wVariable, this.anchorBInternal],
|
|
166
|
+
]);
|
|
167
|
+
} else if (isUIPointElement(this.b)) {
|
|
168
|
+
bExpression = new UIExpression().plus(this.b.xVariable, 1);
|
|
169
|
+
} else {
|
|
170
|
+
throw new Error("UIHorizontalInterpolationConstraint.buildLHS.b: invalid element type");
|
|
171
|
+
}
|
|
172
|
+
|
|
173
|
+
if (isUIPlaneElement(this.c)) {
|
|
174
|
+
cExpression = new UIExpression(0, [
|
|
175
|
+
[this.c.xVariable, 1],
|
|
176
|
+
[this.c.wVariable, this.anchorCInternal],
|
|
177
|
+
]);
|
|
178
|
+
} else if (isUIPointElement(this.c)) {
|
|
179
|
+
cExpression = new UIExpression().plus(this.c.xVariable, 1);
|
|
180
|
+
} else {
|
|
181
|
+
throw new Error("UIHorizontalInterpolationConstraint.buildLHS.c: invalid element type");
|
|
182
|
+
}
|
|
183
|
+
|
|
184
|
+
// C - A*(1-t) - B*t = 0
|
|
185
|
+
const aScaled = aExpression.clone().multiply(1 - this.tInternal);
|
|
186
|
+
const bScaled = bExpression.clone().multiply(this.tInternal);
|
|
187
|
+
return UIExpression.minus(UIExpression.minus(cExpression, aScaled), bScaled);
|
|
188
|
+
}
|
|
189
|
+
}
|
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
import type { UISingleParameterConstraintOptions } from "../UISingleParameterConstraint/UISingleParameterConstraint.Internal";
|
|
2
|
+
|
|
2
3
|
/** Horizontal proportion constraint options */
|
|
3
4
|
export interface UIHorizontalProportionConstraintOptions extends UISingleParameterConstraintOptions {
|
|
4
|
-
|
|
5
|
-
|
|
5
|
+
/** Proportion multiplier (A.width * proportion = B.width) */
|
|
6
|
+
proportion: number;
|
|
6
7
|
}
|
package/src/core/constraints/UIHorizontalProportionConstraint/UIHorizontalProportionConstraint.ts
ADDED
|
@@ -0,0 +1,68 @@
|
|
|
1
|
+
import {
|
|
2
|
+
assertValidConstraintArguments,
|
|
3
|
+
assertValidPositiveNumber,
|
|
4
|
+
} from "../../miscellaneous/asserts";
|
|
5
|
+
import type { UIPlaneElement } from "../../miscellaneous/shared";
|
|
6
|
+
import { UIExpression } from "../../miscellaneous/UIExpression";
|
|
7
|
+
import { UISingleParameterConstraint } from "../UISingleParameterConstraint/UISingleParameterConstraint";
|
|
8
|
+
import type { UIHorizontalProportionConstraintOptions } from "./UIHorizontalProportionConstraint.Internal";
|
|
9
|
+
|
|
10
|
+
/** Maintains proportional width relationship (A.width * proportion = B.width) */
|
|
11
|
+
export class UIHorizontalProportionConstraint extends UISingleParameterConstraint {
|
|
12
|
+
protected override readonly constraint: number;
|
|
13
|
+
private proportionInternal: number;
|
|
14
|
+
|
|
15
|
+
/**
|
|
16
|
+
* @param a First element
|
|
17
|
+
* @param b Second element
|
|
18
|
+
* @param options Proportion configuration
|
|
19
|
+
*/
|
|
20
|
+
constructor(
|
|
21
|
+
private readonly a: UIPlaneElement,
|
|
22
|
+
private readonly b: UIPlaneElement,
|
|
23
|
+
options: Partial<UIHorizontalProportionConstraintOptions> = {},
|
|
24
|
+
) {
|
|
25
|
+
if (options.proportion !== undefined) {
|
|
26
|
+
assertValidPositiveNumber(
|
|
27
|
+
options.proportion,
|
|
28
|
+
"UIHorizontalProportionConstraint.constructor.options.proportion",
|
|
29
|
+
);
|
|
30
|
+
}
|
|
31
|
+
|
|
32
|
+
super(
|
|
33
|
+
assertValidConstraintArguments(a, b, "UIHorizontalProportionConstraint.constructor"),
|
|
34
|
+
options,
|
|
35
|
+
);
|
|
36
|
+
|
|
37
|
+
this.proportionInternal = options.proportion ?? 1;
|
|
38
|
+
this.constraint = this.solverWrapper.createConstraint(
|
|
39
|
+
new UIExpression(0),
|
|
40
|
+
this.buildRHS(),
|
|
41
|
+
this.relation,
|
|
42
|
+
this.priority,
|
|
43
|
+
this.isConstraintEnabled(),
|
|
44
|
+
);
|
|
45
|
+
}
|
|
46
|
+
|
|
47
|
+
/** Current proportion multiplier */
|
|
48
|
+
public get proportion(): number {
|
|
49
|
+
return this.proportionInternal;
|
|
50
|
+
}
|
|
51
|
+
|
|
52
|
+
/** Updates proportion multiplier */
|
|
53
|
+
public set proportion(value: number) {
|
|
54
|
+
assertValidPositiveNumber(value, "UIHorizontalProportionConstraint.proportion");
|
|
55
|
+
if (this.proportionInternal !== value) {
|
|
56
|
+
this.proportionInternal = value;
|
|
57
|
+
this.solverWrapper.setConstraintRHS(this.constraint, this.buildRHS());
|
|
58
|
+
}
|
|
59
|
+
}
|
|
60
|
+
|
|
61
|
+
/** Builds constraint expression for proportional relationship */
|
|
62
|
+
private buildRHS(): UIExpression {
|
|
63
|
+
return UIExpression.minus(
|
|
64
|
+
new UIExpression(0, [[this.a.wVariable, this.proportionInternal]]),
|
|
65
|
+
new UIExpression(0, [[this.b.wVariable, 1]]),
|
|
66
|
+
);
|
|
67
|
+
}
|
|
68
|
+
}
|
|
@@ -1,14 +1,15 @@
|
|
|
1
1
|
import type { UIOrientation } from "../../miscellaneous/UIOrientation";
|
|
2
2
|
import type { UIPriority } from "../../miscellaneous/UIPriority";
|
|
3
3
|
import type { UIRelation } from "../../miscellaneous/UIRelation";
|
|
4
|
+
|
|
4
5
|
/** Single parameter constraint options */
|
|
5
6
|
export interface UISingleParameterConstraintOptions {
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
7
|
+
/** Constraint name */
|
|
8
|
+
name: string;
|
|
9
|
+
/** Constraint priority */
|
|
10
|
+
priority: UIPriority;
|
|
11
|
+
/** Constraint relation */
|
|
12
|
+
relation: UIRelation;
|
|
13
|
+
/** When constraint is active */
|
|
14
|
+
orientation: UIOrientation;
|
|
14
15
|
}
|
|
@@ -0,0 +1,94 @@
|
|
|
1
|
+
import type { UILayer } from "../../layers/UILayer/UILayer";
|
|
2
|
+
import { resolveOrientation, UIOrientation } from "../../miscellaneous/UIOrientation";
|
|
3
|
+
import type { UIPriority } from "../../miscellaneous/UIPriority";
|
|
4
|
+
import { resolvePriority } from "../../miscellaneous/UIPriority";
|
|
5
|
+
import type { UIRelation } from "../../miscellaneous/UIRelation";
|
|
6
|
+
import { resolveRelation } from "../../miscellaneous/UIRelation";
|
|
7
|
+
import { UIConstraint } from "../UIConstraint";
|
|
8
|
+
import type { UISingleParameterConstraintOptions } from "./UISingleParameterConstraint.Internal";
|
|
9
|
+
|
|
10
|
+
/** Base class for constraints with priority, relation, and orientation */
|
|
11
|
+
export abstract class UISingleParameterConstraint extends UIConstraint {
|
|
12
|
+
/** Constraint priority */
|
|
13
|
+
private priorityInternal: UIPriority;
|
|
14
|
+
/** Constraint relation */
|
|
15
|
+
private relationInternal: UIRelation;
|
|
16
|
+
/** Constraint orientation */
|
|
17
|
+
private orientationInternal: UIOrientation;
|
|
18
|
+
|
|
19
|
+
/** Solver constraint descriptor */
|
|
20
|
+
protected abstract readonly constraint: number;
|
|
21
|
+
|
|
22
|
+
/**
|
|
23
|
+
* @param layer Layer containing this constraint
|
|
24
|
+
* @param options Constraint configuration
|
|
25
|
+
*/
|
|
26
|
+
constructor(layer: UILayer, options?: Partial<UISingleParameterConstraintOptions>) {
|
|
27
|
+
super(layer, options?.name);
|
|
28
|
+
this.priorityInternal = resolvePriority(options?.priority);
|
|
29
|
+
this.relationInternal = resolveRelation(options?.relation);
|
|
30
|
+
this.orientationInternal = resolveOrientation(options?.orientation);
|
|
31
|
+
this.layer.signalOrientationChanged.on(this.onOrientationChange);
|
|
32
|
+
}
|
|
33
|
+
|
|
34
|
+
/** Constraint priority */
|
|
35
|
+
public get priority(): UIPriority {
|
|
36
|
+
return this.priorityInternal;
|
|
37
|
+
}
|
|
38
|
+
|
|
39
|
+
/** Constraint relation */
|
|
40
|
+
public get relation(): UIRelation {
|
|
41
|
+
return this.relationInternal;
|
|
42
|
+
}
|
|
43
|
+
|
|
44
|
+
/** When constraint is active */
|
|
45
|
+
public get orientation(): UIOrientation {
|
|
46
|
+
return this.orientationInternal;
|
|
47
|
+
}
|
|
48
|
+
|
|
49
|
+
/** Updates constraint priority */
|
|
50
|
+
public set priority(value: UIPriority) {
|
|
51
|
+
if (value !== this.priorityInternal) {
|
|
52
|
+
this.priorityInternal = value;
|
|
53
|
+
this.solverWrapper.setConstraintPriority(this.constraint, this.priorityInternal);
|
|
54
|
+
}
|
|
55
|
+
}
|
|
56
|
+
|
|
57
|
+
/** Updates constraint relation */
|
|
58
|
+
public set relation(value: UIRelation) {
|
|
59
|
+
if (value !== this.relationInternal) {
|
|
60
|
+
this.relationInternal = value;
|
|
61
|
+
this.solverWrapper.setConstraintRelation(this.constraint, this.relationInternal);
|
|
62
|
+
}
|
|
63
|
+
}
|
|
64
|
+
|
|
65
|
+
/** Updates when constraint is active */
|
|
66
|
+
public set orientation(value: UIOrientation) {
|
|
67
|
+
if (value !== this.orientationInternal) {
|
|
68
|
+
this.orientationInternal = value;
|
|
69
|
+
this.onOrientationChange();
|
|
70
|
+
}
|
|
71
|
+
}
|
|
72
|
+
|
|
73
|
+
/** Removes constraint from solver and cleans up listeners */
|
|
74
|
+
public destroy(): void {
|
|
75
|
+
this.layer.signalOrientationChanged.off(this.onOrientationChange);
|
|
76
|
+
this.solverWrapper.removeConstraint(this.constraint);
|
|
77
|
+
}
|
|
78
|
+
|
|
79
|
+
/**
|
|
80
|
+
* Checks if constraint should be active for current orientation.
|
|
81
|
+
* @returns True if orientation is ALWAYS or matches layer orientation
|
|
82
|
+
*/
|
|
83
|
+
protected isConstraintEnabled(): boolean {
|
|
84
|
+
return (
|
|
85
|
+
this.orientationInternal === UIOrientation.ALWAYS ||
|
|
86
|
+
this.orientationInternal === this.layer.orientation
|
|
87
|
+
);
|
|
88
|
+
}
|
|
89
|
+
|
|
90
|
+
/** Updates constraint enabled state when layer orientation changes */
|
|
91
|
+
private readonly onOrientationChange = (): void => {
|
|
92
|
+
this.solverWrapper.setConstraintEnabled(this.constraint, this.isConstraintEnabled());
|
|
93
|
+
};
|
|
94
|
+
}
|
package/src/core/constraints/UIVerticalDistanceConstraint/UIVerticalDistanceConstraint.Internal.ts
ADDED
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
import type { UISingleParameterConstraintOptions } from "../UISingleParameterConstraint/UISingleParameterConstraint.Internal";
|
|
2
|
+
|
|
3
|
+
export const DEFAULT_ANCHOR = 0.5;
|
|
4
|
+
|
|
5
|
+
/** Vertical distance constraint options */
|
|
6
|
+
export interface UIVerticalDistanceConstraintOptions extends UISingleParameterConstraintOptions {
|
|
7
|
+
/** Anchor on element A (0 = bottom, 0.5 = center, 1 = top) */
|
|
8
|
+
anchorA: number;
|
|
9
|
+
/** Anchor on element B (0 = bottom, 0.5 = center, 1 = top) */
|
|
10
|
+
anchorB: number;
|
|
11
|
+
/** Distance in world units */
|
|
12
|
+
distance: number;
|
|
13
|
+
}
|
|
@@ -0,0 +1,135 @@
|
|
|
1
|
+
import { assertValidConstraintArguments, assertValidNumber } from "../../miscellaneous/asserts";
|
|
2
|
+
import type { UIPlaneElement, UIPointElement } from "../../miscellaneous/shared";
|
|
3
|
+
import { isUIPlaneElement, isUIPointElement } from "../../miscellaneous/shared";
|
|
4
|
+
import { UIExpression } from "../../miscellaneous/UIExpression";
|
|
5
|
+
import { UISingleParameterConstraint } from "../UISingleParameterConstraint/UISingleParameterConstraint";
|
|
6
|
+
import type { UIVerticalDistanceConstraintOptions } from "./UIVerticalDistanceConstraint.Internal";
|
|
7
|
+
import { DEFAULT_ANCHOR } from "./UIVerticalDistanceConstraint.Internal";
|
|
8
|
+
|
|
9
|
+
/** Maintains vertical distance between elements with configurable anchors */
|
|
10
|
+
export class UIVerticalDistanceConstraint extends UISingleParameterConstraint {
|
|
11
|
+
protected override readonly constraint: number;
|
|
12
|
+
|
|
13
|
+
private anchorAInternal: number;
|
|
14
|
+
private anchorBInternal: number;
|
|
15
|
+
private distanceInternal: number;
|
|
16
|
+
|
|
17
|
+
/**
|
|
18
|
+
* @param a First element
|
|
19
|
+
* @param b Second element
|
|
20
|
+
* @param options Distance configuration
|
|
21
|
+
*/
|
|
22
|
+
constructor(
|
|
23
|
+
private readonly a: UIPointElement | UIPlaneElement,
|
|
24
|
+
private readonly b: UIPointElement | UIPlaneElement,
|
|
25
|
+
options: Partial<UIVerticalDistanceConstraintOptions> = {},
|
|
26
|
+
) {
|
|
27
|
+
if (options.anchorA !== undefined) {
|
|
28
|
+
assertValidNumber(
|
|
29
|
+
options.anchorA,
|
|
30
|
+
"UIVerticalDistanceConstraint.constructor.options.anchorA",
|
|
31
|
+
);
|
|
32
|
+
}
|
|
33
|
+
if (options.anchorB !== undefined) {
|
|
34
|
+
assertValidNumber(
|
|
35
|
+
options.anchorB,
|
|
36
|
+
"UIVerticalDistanceConstraint.constructor.options.anchorB",
|
|
37
|
+
);
|
|
38
|
+
}
|
|
39
|
+
if (options.distance !== undefined) {
|
|
40
|
+
assertValidNumber(
|
|
41
|
+
options.distance,
|
|
42
|
+
"UIVerticalDistanceConstraint.constructor.options.distance",
|
|
43
|
+
);
|
|
44
|
+
}
|
|
45
|
+
|
|
46
|
+
super(
|
|
47
|
+
assertValidConstraintArguments(a, b, "UIVerticalDistanceConstraint.constructor"),
|
|
48
|
+
options,
|
|
49
|
+
);
|
|
50
|
+
|
|
51
|
+
this.anchorAInternal = options.anchorA ?? DEFAULT_ANCHOR;
|
|
52
|
+
this.anchorBInternal = options.anchorB ?? DEFAULT_ANCHOR;
|
|
53
|
+
this.distanceInternal = options.distance ?? 0;
|
|
54
|
+
|
|
55
|
+
this.constraint = this.solverWrapper.createConstraint(
|
|
56
|
+
this.buildLHS(),
|
|
57
|
+
new UIExpression(this.distanceInternal),
|
|
58
|
+
this.relation,
|
|
59
|
+
this.priority,
|
|
60
|
+
this.isConstraintEnabled(),
|
|
61
|
+
);
|
|
62
|
+
}
|
|
63
|
+
|
|
64
|
+
/** Current distance in world units */
|
|
65
|
+
public get distance(): number {
|
|
66
|
+
return this.distanceInternal;
|
|
67
|
+
}
|
|
68
|
+
|
|
69
|
+
/** Anchor on element A (0 = bottom, 0.5 = center, 1 = top) */
|
|
70
|
+
public get anchorA(): number {
|
|
71
|
+
return this.anchorAInternal;
|
|
72
|
+
}
|
|
73
|
+
|
|
74
|
+
/** Anchor on element B (0 = bottom, 0.5 = center, 1 = top) */
|
|
75
|
+
public get anchorB(): number {
|
|
76
|
+
return this.anchorBInternal;
|
|
77
|
+
}
|
|
78
|
+
|
|
79
|
+
/** Updates distance */
|
|
80
|
+
public set distance(value: number) {
|
|
81
|
+
assertValidNumber(value, "UIVerticalDistanceConstraint.distance");
|
|
82
|
+
if (this.distanceInternal !== value) {
|
|
83
|
+
this.distanceInternal = value;
|
|
84
|
+
this.solverWrapper.setConstraintRHS(this.constraint, new UIExpression(this.distanceInternal));
|
|
85
|
+
}
|
|
86
|
+
}
|
|
87
|
+
|
|
88
|
+
/** Updates anchor on element A */
|
|
89
|
+
public set anchorA(value: number) {
|
|
90
|
+
assertValidNumber(value, "UIVerticalDistanceConstraint.anchorA");
|
|
91
|
+
if (this.anchorAInternal !== value) {
|
|
92
|
+
this.anchorAInternal = value;
|
|
93
|
+
this.solverWrapper.setConstraintLHS(this.constraint, this.buildLHS());
|
|
94
|
+
}
|
|
95
|
+
}
|
|
96
|
+
|
|
97
|
+
/** Updates anchor on element B */
|
|
98
|
+
public set anchorB(value: number) {
|
|
99
|
+
assertValidNumber(value, "UIVerticalDistanceConstraint.anchorB");
|
|
100
|
+
if (this.anchorBInternal !== value) {
|
|
101
|
+
this.anchorBInternal = value;
|
|
102
|
+
this.solverWrapper.setConstraintLHS(this.constraint, this.buildLHS());
|
|
103
|
+
}
|
|
104
|
+
}
|
|
105
|
+
|
|
106
|
+
/** Builds constraint expression for distance between anchored positions */
|
|
107
|
+
private buildLHS(): UIExpression {
|
|
108
|
+
let aExpression: UIExpression;
|
|
109
|
+
let bExpression: UIExpression;
|
|
110
|
+
|
|
111
|
+
if (isUIPlaneElement(this.a)) {
|
|
112
|
+
aExpression = new UIExpression(0, [
|
|
113
|
+
[this.a.yVariable, 1],
|
|
114
|
+
[this.a.hVariable, this.anchorAInternal],
|
|
115
|
+
]);
|
|
116
|
+
} else if (isUIPointElement(this.a)) {
|
|
117
|
+
aExpression = new UIExpression().plus(this.a.yVariable, 1);
|
|
118
|
+
} else {
|
|
119
|
+
throw new Error("UIVerticalDistanceConstraint.buildLHS.a: invalid element type");
|
|
120
|
+
}
|
|
121
|
+
|
|
122
|
+
if (isUIPlaneElement(this.b)) {
|
|
123
|
+
bExpression = new UIExpression(0, [
|
|
124
|
+
[this.b.yVariable, 1],
|
|
125
|
+
[this.b.hVariable, this.anchorBInternal],
|
|
126
|
+
]);
|
|
127
|
+
} else if (isUIPointElement(this.b)) {
|
|
128
|
+
bExpression = new UIExpression().plus(this.b.yVariable, 1);
|
|
129
|
+
} else {
|
|
130
|
+
throw new Error("UIVerticalDistanceConstraint.buildLHS.b: invalid element type");
|
|
131
|
+
}
|
|
132
|
+
|
|
133
|
+
return UIExpression.minus(bExpression, aExpression);
|
|
134
|
+
}
|
|
135
|
+
}
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
import type { UISingleParameterConstraintOptions } from "../UISingleParameterConstraint/UISingleParameterConstraint.Internal";
|
|
2
|
+
|
|
3
|
+
export const DEFAULT_ANCHOR = 0.5;
|
|
4
|
+
export const DEFAULT_T = 0.5;
|
|
5
|
+
|
|
6
|
+
/** Vertical interpolation constraint options */
|
|
7
|
+
export interface UIVerticalInterpolationConstraintOptions extends UISingleParameterConstraintOptions {
|
|
8
|
+
/** Anchor on element A (0 = bottom, 0.5 = center, 1 = top) */
|
|
9
|
+
anchorA: number;
|
|
10
|
+
/** Anchor on element B (0 = bottom, 0.5 = center, 1 = top) */
|
|
11
|
+
anchorB: number;
|
|
12
|
+
/** Anchor on element C (0 = bottom, 0.5 = center, 1 = top) */
|
|
13
|
+
anchorC: number;
|
|
14
|
+
/** Interpolation factor (0 = A position, 1 = B position) */
|
|
15
|
+
t: number;
|
|
16
|
+
}
|