From 2e0e7589a638ea3203a9aee0893dcab9c4d253d1 Mon Sep 17 00:00:00 2001 From: Justin Brooks Date: Tue, 26 Nov 2024 23:09:06 -0600 Subject: [PATCH] Update api --- vgo-core/api/vgo-core.api | 64 +++++++++++++++++-- .../com/jzbrooks/vgo/core/util/math/Curves.kt | 16 ++--- 2 files changed, 61 insertions(+), 19 deletions(-) diff --git a/vgo-core/api/vgo-core.api b/vgo-core/api/vgo-core.api index 74ec0f43..f35a635d 100644 --- a/vgo-core/api/vgo-core.api +++ b/vgo-core/api/vgo-core.api @@ -626,6 +626,23 @@ public final class com/jzbrooks/vgo/core/util/element/TraverseKt { public static final fun traverseTopDown (Lcom/jzbrooks/vgo/core/graphic/Element;Lkotlin/jvm/functions/Function1;)Lcom/jzbrooks/vgo/core/graphic/Element; } +public final class com/jzbrooks/vgo/core/util/math/CenterParameterization { + public fun (Lcom/jzbrooks/vgo/core/util/math/Point;FFD)V + public final fun component1 ()Lcom/jzbrooks/vgo/core/util/math/Point; + public final fun component2 ()F + public final fun component3 ()F + public final fun component4 ()D + public final fun copy (Lcom/jzbrooks/vgo/core/util/math/Point;FFD)Lcom/jzbrooks/vgo/core/util/math/CenterParameterization; + public static synthetic fun copy$default (Lcom/jzbrooks/vgo/core/util/math/CenterParameterization;Lcom/jzbrooks/vgo/core/util/math/Point;FFDILjava/lang/Object;)Lcom/jzbrooks/vgo/core/util/math/CenterParameterization; + public fun equals (Ljava/lang/Object;)Z + public final fun getCenter ()Lcom/jzbrooks/vgo/core/util/math/Point; + public final fun getPhi ()D + public final fun getRadiusX ()F + public final fun getRadiusY ()F + public fun hashCode ()I + public fun toString ()Ljava/lang/String; +} + public final class com/jzbrooks/vgo/core/util/math/Circle { public fun (Lcom/jzbrooks/vgo/core/util/math/Point;F)V public final fun component1 ()Lcom/jzbrooks/vgo/core/util/math/Point; @@ -645,14 +662,20 @@ public final class com/jzbrooks/vgo/core/util/math/CommandsKt { } public final class com/jzbrooks/vgo/core/util/math/CurvesKt { + public static final fun computeBoundingBox (Lcom/jzbrooks/vgo/core/graphic/command/EllipticalArcCurve$Parameter;Lcom/jzbrooks/vgo/core/graphic/command/CommandVariant;Lcom/jzbrooks/vgo/core/util/math/Point;)Lcom/jzbrooks/vgo/core/util/math/Rectangle; + public static final fun computeCenterParameterization (Lcom/jzbrooks/vgo/core/graphic/command/EllipticalArcCurve$Parameter;Lcom/jzbrooks/vgo/core/graphic/command/CommandVariant;Lcom/jzbrooks/vgo/core/util/math/Point;)Lcom/jzbrooks/vgo/core/util/math/CenterParameterization; public static final fun findArcAngle (Lcom/jzbrooks/vgo/core/graphic/command/CubicBezierCurve;Lcom/jzbrooks/vgo/core/util/math/Circle;)F - public static final fun fitCircle (Lcom/jzbrooks/vgo/core/graphic/command/CubicCurve;F)Lcom/jzbrooks/vgo/core/util/math/Circle; - public static synthetic fun fitCircle$default (Lcom/jzbrooks/vgo/core/graphic/command/CubicCurve;FILjava/lang/Object;)Lcom/jzbrooks/vgo/core/util/math/Circle; - public static final fun interpolate (Lcom/jzbrooks/vgo/core/graphic/command/CubicCurve;F)Lcom/jzbrooks/vgo/core/util/math/Point; - public static final fun isConvex (Lcom/jzbrooks/vgo/core/graphic/command/CubicCurve;F)Z - public static synthetic fun isConvex$default (Lcom/jzbrooks/vgo/core/graphic/command/CubicCurve;FILjava/lang/Object;)Z - public static final fun liesOnCircle (Lcom/jzbrooks/vgo/core/graphic/command/CubicCurve;Lcom/jzbrooks/vgo/core/util/math/Circle;F)Z - public static synthetic fun liesOnCircle$default (Lcom/jzbrooks/vgo/core/graphic/command/CubicCurve;Lcom/jzbrooks/vgo/core/util/math/Circle;FILjava/lang/Object;)Z + public static final fun fitCircle (Lcom/jzbrooks/vgo/core/graphic/command/CubicBezierCurve;F)Lcom/jzbrooks/vgo/core/util/math/Circle; + public static synthetic fun fitCircle$default (Lcom/jzbrooks/vgo/core/graphic/command/CubicBezierCurve;FILjava/lang/Object;)Lcom/jzbrooks/vgo/core/util/math/Circle; + public static final fun interpolate (Lcom/jzbrooks/vgo/core/graphic/command/CubicBezierCurve$Parameter;Lcom/jzbrooks/vgo/core/util/math/Point;F)Lcom/jzbrooks/vgo/core/util/math/Point; + public static final fun interpolate (Lcom/jzbrooks/vgo/core/graphic/command/CubicBezierCurve;Lcom/jzbrooks/vgo/core/util/math/Point;F)Lcom/jzbrooks/vgo/core/util/math/Point; + public static final fun interpolate (Lcom/jzbrooks/vgo/core/graphic/command/QuadraticBezierCurve$Parameter;Lcom/jzbrooks/vgo/core/util/math/Point;F)Lcom/jzbrooks/vgo/core/util/math/Point; + public static final fun interpolate (Lcom/jzbrooks/vgo/core/graphic/command/SmoothCubicBezierCurve$Parameter;Lcom/jzbrooks/vgo/core/util/math/Point;Lcom/jzbrooks/vgo/core/util/math/Point;F)Lcom/jzbrooks/vgo/core/util/math/Point; + public static final fun interpolateSmoothQuadraticBezierCurve (Lcom/jzbrooks/vgo/core/util/math/Point;Lcom/jzbrooks/vgo/core/util/math/Point;Lcom/jzbrooks/vgo/core/util/math/Point;F)Lcom/jzbrooks/vgo/core/util/math/Point; + public static final fun isConvex (Lcom/jzbrooks/vgo/core/graphic/command/CubicBezierCurve;F)Z + public static synthetic fun isConvex$default (Lcom/jzbrooks/vgo/core/graphic/command/CubicBezierCurve;FILjava/lang/Object;)Z + public static final fun liesOnCircle (Lcom/jzbrooks/vgo/core/graphic/command/CubicBezierCurve;Lcom/jzbrooks/vgo/core/util/math/Circle;F)Z + public static synthetic fun liesOnCircle$default (Lcom/jzbrooks/vgo/core/graphic/command/CubicBezierCurve;Lcom/jzbrooks/vgo/core/util/math/Circle;FILjava/lang/Object;)Z public static final fun toCubicBezierCurve (Lcom/jzbrooks/vgo/core/graphic/command/SmoothCubicBezierCurve;Lcom/jzbrooks/vgo/core/graphic/command/CubicCurve;)Lcom/jzbrooks/vgo/core/graphic/command/CubicBezierCurve; } @@ -729,6 +752,33 @@ public final class com/jzbrooks/vgo/core/util/math/Point$Companion { public final fun getZERO ()Lcom/jzbrooks/vgo/core/util/math/Point; } +public final class com/jzbrooks/vgo/core/util/math/Rectangle { + public fun (FFFF)V + public final fun component1 ()F + public final fun component2 ()F + public final fun component3 ()F + public final fun component4 ()F + public final fun copy (FFFF)Lcom/jzbrooks/vgo/core/util/math/Rectangle; + public static synthetic fun copy$default (Lcom/jzbrooks/vgo/core/util/math/Rectangle;FFFFILjava/lang/Object;)Lcom/jzbrooks/vgo/core/util/math/Rectangle; + public fun equals (Ljava/lang/Object;)Z + public final fun getBottom ()F + public final fun getLeft ()F + public final fun getRight ()F + public final fun getTop ()F + public fun hashCode ()I + public fun toString ()Ljava/lang/String; +} + +public final class com/jzbrooks/vgo/core/util/math/RectangleKt { + public static final fun intersects (Lcom/jzbrooks/vgo/core/util/math/Rectangle;Lcom/jzbrooks/vgo/core/util/math/Rectangle;)Z +} + +public final class com/jzbrooks/vgo/core/util/math/Surveyor { + public static final field RESOLUTION I + public fun ()V + public final fun findBoundingBox (Ljava/util/List;)Lcom/jzbrooks/vgo/core/util/math/Rectangle; +} + public final class com/jzbrooks/vgo/core/util/math/Vector3 { public fun (FFF)V public fun (Lcom/jzbrooks/vgo/core/util/math/Point;)V diff --git a/vgo-core/src/main/kotlin/com/jzbrooks/vgo/core/util/math/Curves.kt b/vgo-core/src/main/kotlin/com/jzbrooks/vgo/core/util/math/Curves.kt index a36e8e9a..f6d13d33 100644 --- a/vgo-core/src/main/kotlin/com/jzbrooks/vgo/core/util/math/Curves.kt +++ b/vgo-core/src/main/kotlin/com/jzbrooks/vgo/core/util/math/Curves.kt @@ -25,7 +25,7 @@ fun CubicBezierCurve.fitCircle(tolerance: Float = 1e-3f): Circle? { assert(variant == CommandVariant.RELATIVE) assert(parameters.size == 1) - val mid = interpolateRelative(0.5f) + val mid = interpolate(Point.ZERO, 0.5f) val end = parameters[0].end val m1 = mid * 0.5f @@ -43,22 +43,13 @@ fun CubicBezierCurve.fitCircle(tolerance: Float = 1e-3f): Circle? { val withinTolerance = radius < 1e7 && floatArrayOf(0.25f, 0.75f).all { - val curveValue = interpolateRelative(it) + val curveValue = interpolate(Point.ZERO, it) abs(curveValue.distanceTo(center) - radius) <= tolerance } return if (withinTolerance) Circle(center, radius) else null } -/** - * Requires that the curve only has a single parameter - * Requires that the curve use relative coordinates - */ -fun CubicBezierCurve.interpolateRelative(t: Float): Point { - assert(variant == CommandVariant.RELATIVE) - return interpolate(Point.ZERO, t) -} - /** * Requires that the curve only has a single parameter */ @@ -128,6 +119,7 @@ fun SmoothCubicBezierCurve.toCubicBezierCurve(previous: CubicCurve<*>): CubicBez else -> throw IllegalStateException("A destructuring of control points is required for ${previous::class.simpleName}.") } + // todo: is this implied control point computed correctly? It doesn't look reflected return CubicBezierCurve( variant, parameters.map { (endControl, end) -> @@ -163,7 +155,7 @@ fun CubicBezierCurve.liesOnCircle( val tolerance = min(ARC_THRESHOLD * tolerance, ARC_TOLERANCE * circle.radius / 100) return floatArrayOf(0f, 0.25f, 0.5f, 0.75f, 1f).all { t -> - abs(interpolateRelative(t).distanceTo(circle.center) - circle.radius) <= tolerance + abs(interpolate(Point.ZERO, t).distanceTo(circle.center) - circle.radius) <= tolerance } }