[orx-shapes] Convert primitive classes to @JvmRecord and implement GeometricPrimitive2D where applicable

This commit is contained in:
Edwin Jakobs
2025-08-20 21:27:16 +02:00
parent af64323229
commit e17644a247
5 changed files with 22 additions and 6 deletions

View File

@@ -3,6 +3,7 @@ package org.openrndr.extra.shapes.primitives
import org.openrndr.math.*
import org.openrndr.shape.ShapeContour
import org.openrndr.shape.contour
import kotlin.jvm.JvmRecord
/**
* Represents an arc defined by a center point, a radius, and a range of angles.
@@ -15,7 +16,8 @@ import org.openrndr.shape.contour
* @property angle0 The starting angle of the arc, in degrees.
* @property angle1 The ending angle of the arc, in degrees.
*/
class Arc(val center: Vector2, val radius: Double, val angle0: Double, val angle1: Double) : LinearType<Arc> {
@JvmRecord
data class Arc(val center: Vector2, val radius: Double, val angle0: Double, val angle1: Double) : LinearType<Arc>, GeometricPrimitive2D {
/**
* Calculates the position of a point along the arc at a specified parameter `t`.
* The parameter `t` interpolates between the starting and ending angles of the arc.
@@ -29,6 +31,8 @@ class Arc(val center: Vector2, val radius: Double, val angle0: Double, val angle
return Polar(angle, radius).cartesian + center
}
fun conjugate() = Arc(center, radius, angle1-360.0, angle0)
/**
* A computed property that provides a [ShapeContour] representation of the arc.
* The contour is constructed by moving to the position at the start of the arc (t=0.0),

View File

@@ -1,11 +1,14 @@
package org.openrndr.extra.shapes.primitives
import org.openrndr.math.GeometricPrimitive2D
import org.openrndr.math.LinearType
import org.openrndr.math.Polar
import org.openrndr.math.Vector2
import org.openrndr.shape.Circle
import org.openrndr.shape.LineSegment
import org.openrndr.shape.ShapeContour
import kotlin.jvm.JvmInline
import kotlin.jvm.JvmRecord
/**
* Represents a net defined by two points and a circle. The net can be seen as a structure
@@ -18,8 +21,9 @@ import org.openrndr.shape.ShapeContour
* @property point1 The ending point of the net.
* @property circle The circle around which the net is constructed.
*/
class Net(val point0: Vector2, val point1: Vector2, val circle: Circle) :
LinearType<Net> {
@JvmRecord
data class Net(val point0: Vector2, val point1: Vector2, val circle: Circle) :
LinearType<Net>, GeometricPrimitive2D {
override fun div(scale: Double) =
Net(point0 / scale, point1 / scale, circle / scale)

View File

@@ -1,10 +1,12 @@
package org.openrndr.extra.shapes.primitives
import org.openrndr.math.GeometricPrimitive2D
import org.openrndr.math.LinearType
import org.openrndr.math.Polar
import org.openrndr.shape.Circle
import org.openrndr.shape.LineSegment
import org.openrndr.shape.ShapeContour
import kotlin.jvm.JvmRecord
/**
* Represents a pulley system defined by two circles.
@@ -17,7 +19,8 @@ import org.openrndr.shape.ShapeContour
* @property circle0 The first circle in the pulley system.
* @property circle1 The second circle in the pulley system.
*/
class Pulley(val circle0: Circle, val circle1: Circle) : LinearType<Pulley> {
@JvmRecord
data class Pulley(val circle0: Circle, val circle1: Circle) : LinearType<Pulley>, GeometricPrimitive2D {
override fun div(scale: Double): Pulley {
return Pulley(circle0 / scale, circle1 / scale)
}

View File

@@ -5,9 +5,11 @@ import org.openrndr.math.Vector2
import org.openrndr.shape.Rectangle
import org.openrndr.shape.contour
import org.openrndr.shape.ShapeContour
import kotlin.jvm.JvmRecord
import kotlin.math.min
class RoundedRectangle(val corner: Vector2, val width: Double, val height: Double, val radius: Double) {
@JvmRecord
data class RoundedRectangle(val corner: Vector2, val width: Double, val height: Double, val radius: Double) {
constructor(x: Double, y: Double, width: Double, height: Double, radius: Double) : this(
Vector2(x, y),
width,

View File

@@ -1,11 +1,13 @@
package org.openrndr.extra.shapes.primitives
import org.openrndr.math.GeometricPrimitive2D
import org.openrndr.math.LinearType
import org.openrndr.math.Polar
import org.openrndr.math.Vector2
import org.openrndr.shape.Circle
import org.openrndr.shape.LineSegment
import org.openrndr.shape.ShapeContour
import kotlin.jvm.JvmRecord
/**
* Represents a "Tear" consisting of a point and a circle.
@@ -18,7 +20,8 @@ import org.openrndr.shape.ShapeContour
* @property point The [Vector2] coordinate representing a point in the Tear.
* @property circle The [Circle] geometry associated with the Tear.
*/
class Tear(val point: Vector2, val circle: Circle) : LinearType<Tear> {
@JvmRecord
data class Tear(val point: Vector2, val circle: Circle) : LinearType<Tear>, GeometricPrimitive2D {
override fun div(scale: Double) = Tear(point / scale, circle / scale)
override fun times(scale: Double) = Tear(point * scale, circle * scale)