Skip to content

Commit

Permalink
Update api
Browse files Browse the repository at this point in the history
  • Loading branch information
jzbrooks committed Nov 27, 2024
1 parent 0d1e390 commit 2e0e758
Show file tree
Hide file tree
Showing 2 changed files with 61 additions and 19 deletions.
64 changes: 57 additions & 7 deletions vgo-core/api/vgo-core.api
Original file line number Diff line number Diff line change
Expand Up @@ -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 <init> (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 <init> (Lcom/jzbrooks/vgo/core/util/math/Point;F)V
public final fun component1 ()Lcom/jzbrooks/vgo/core/util/math/Point;
Expand All @@ -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;
}

Expand Down Expand Up @@ -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 <init> (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 <init> ()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 <init> (FFF)V
public fun <init> (Lcom/jzbrooks/vgo/core/util/math/Point;)V
Expand Down
16 changes: 4 additions & 12 deletions vgo-core/src/main/kotlin/com/jzbrooks/vgo/core/util/math/Curves.kt
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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
*/
Expand Down Expand Up @@ -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) ->
Expand Down Expand Up @@ -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
}
}

Expand Down

0 comments on commit 2e0e758

Please sign in to comment.