openrndr / orx

A growing library of assorted data structures, algorithms and utilities for OPENRNDR
https://openrndr.org
BSD 2-Clause "Simplified" License
121 stars 37 forks source link

[orx-shapes] rectified t values produce normals and positions with unexpected gap near t=1.0 value #334

Closed hamoid closed 4 months ago

hamoid commented 4 months ago

Operating System

Linux

OPENRNDR version

0.4.5-SNAPSHOT

ORX version

0.4.5-SNAPSHOT

Java version (if applicable)

No response

Describe the bug

Discussed in https://openrndr.slack.com/archives/CARDHCRLG/p1715349495895799

Passing a t value with regular increments produces results which are not regular around 1.0 boundary both for .normal() and .position().

Steps to reproduce the bug

import org.openrndr.application
import org.openrndr.color.ColorRGBa
import org.openrndr.extra.shapes.rectify.rectified
import org.openrndr.shape.Circle
import org.openrndr.shape.Segment2D

fun main() = application {
    program {
        val c = Circle(drawer.bounds.center, 50.0).contour
        val rc = c.rectified()
        val normals = List(100) {
            val t = it / 100.0
            val p = rc.position(t)
            val n = rc.normal(t)
            Segment2D(p, p + n * 500.0)
        }
        (normals + normals.first()).zipWithNext { a, b ->
            println(a.end.distanceTo(b.end).toInt())
        }
        extend {
            drawer.clear(ColorRGBa.WHITE)
            drawer.stroke = ColorRGBa.WHITE.shade(0.8)
            drawer.segments(normals)
            drawer.stroke = ColorRGBa.GREEN
            drawer.segment(normals[normals.size - 2])
            drawer.stroke = ColorRGBa.RED
            drawer.segment(normals[normals.size - 1])
            drawer.stroke = ColorRGBa.BLUE
            drawer.segment(normals.first())
        }
    }
}

image

hamoid commented 4 months ago

A workaround is to use .contour.open instead of .contour.