[orx-shapes] Add simple hobbyCurve interfaces
This commit is contained in:
@@ -3,12 +3,25 @@ package org.openrndr.extra.shapes
|
|||||||
|
|
||||||
import org.openrndr.math.Vector2
|
import org.openrndr.math.Vector2
|
||||||
import org.openrndr.shape.Segment
|
import org.openrndr.shape.Segment
|
||||||
|
import org.openrndr.shape.Shape
|
||||||
import org.openrndr.shape.ShapeContour
|
import org.openrndr.shape.ShapeContour
|
||||||
import kotlin.math.atan2
|
import kotlin.math.atan2
|
||||||
import kotlin.math.cos
|
import kotlin.math.cos
|
||||||
import kotlin.math.sin
|
import kotlin.math.sin
|
||||||
import kotlin.math.sqrt
|
import kotlin.math.sqrt
|
||||||
|
|
||||||
|
|
||||||
|
fun ShapeContour.hobbyCurve() : ShapeContour {
|
||||||
|
val vertices = segments.map { it.start }
|
||||||
|
return hobbyCurve(vertices, closed)
|
||||||
|
}
|
||||||
|
|
||||||
|
fun Shape.hobbyCurve() : Shape {
|
||||||
|
return Shape(contours.map {
|
||||||
|
it.hobbyCurve()
|
||||||
|
})
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Uses Hobby's algorithm to construct a [ShapeContour] through a given list of points.
|
* Uses Hobby's algorithm to construct a [ShapeContour] through a given list of points.
|
||||||
* @param points The list of points through which the curve should go.
|
* @param points The list of points through which the curve should go.
|
||||||
@@ -142,3 +155,4 @@ private fun rho(a: Double, b: Double): Double {
|
|||||||
|
|
||||||
private fun rotate(v: Vector2, s: Double, c: Double) = Vector2(v.x * c - v.y * s, v.x * s + v.y * c)
|
private fun rotate(v: Vector2, s: Double, c: Double) = Vector2(v.x * c - v.y * s, v.x * s + v.y * c)
|
||||||
private fun rotateAngle(v: Vector2, alpha: Double) = rotate(v, sin(alpha), cos(alpha))
|
private fun rotateAngle(v: Vector2, alpha: Double) = rotate(v, sin(alpha), cos(alpha))
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user