From 7ff626fa8ab6decf3e799c60226ad61d2e69362a Mon Sep 17 00:00:00 2001 From: Edwin Jakobs Date: Sat, 20 Nov 2021 23:54:21 +0100 Subject: [PATCH] [orx-shapes] Add simple hobbyCurve interfaces --- orx-shapes/src/commonMain/kotlin/HobbyCurve.kt | 14 ++++++++++++++ 1 file changed, 14 insertions(+) diff --git a/orx-shapes/src/commonMain/kotlin/HobbyCurve.kt b/orx-shapes/src/commonMain/kotlin/HobbyCurve.kt index ce4f95a1..ac4b7f5a 100644 --- a/orx-shapes/src/commonMain/kotlin/HobbyCurve.kt +++ b/orx-shapes/src/commonMain/kotlin/HobbyCurve.kt @@ -3,12 +3,25 @@ package org.openrndr.extra.shapes import org.openrndr.math.Vector2 import org.openrndr.shape.Segment +import org.openrndr.shape.Shape import org.openrndr.shape.ShapeContour import kotlin.math.atan2 import kotlin.math.cos import kotlin.math.sin 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. * @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 rotateAngle(v: Vector2, alpha: Double) = rotate(v, sin(alpha), cos(alpha)) +