All Downloads are FREE. Search and download functionalities are using the official Maven repository.

commonMain.utilities.SplitAt.kt Maven / Gradle / Ivy

The newest version!
package org.openrndr.extra.shapes.utilities

import org.openrndr.math.EuclideanVector
import org.openrndr.shape.*

fun ShapeContour.splitAt(segmentIndex: Double, segmentT: Double): List {
    val t = (1.0 / segments.size) * (segmentIndex + segmentT)
    return splitAt(listOf(t))
}

fun Path3D.splitAt(segmentIndex: Double, segmentT: Double): List {
    val t = (1.0 / segments.size) * (segmentIndex + segmentT)
    return splitAt(listOf(t))
}


fun > Path.splitAtBase(ascendingTs: List, weldEpsilon: Double = 1E-6): List> {
    if (empty || ascendingTs.isEmpty()) {
        return listOf(this)
    }
    @Suppress("NAME_SHADOWING") val ascendingTs = (listOf(0.0) + ascendingTs + listOf(1.0)).weldAscending(weldEpsilon)
    return ascendingTs.windowed(2, 1).map {
        sub(it[0], it[1])
    }
}

fun ShapeContour.splitAt(ascendingTs: List, weldEpsilon: Double = 1E-6): List {
    @Suppress("UNCHECKED_CAST")
    return splitAtBase(ascendingTs, weldEpsilon) as List
}

fun Path3D.splitAt(ascendingTs: List, weldEpsilon: Double = 1E-6): List {
    @Suppress("UNCHECKED_CAST")
    return splitAtBase(ascendingTs, weldEpsilon) as List
}

fun > BezierSegment.splitAtBase(
    ascendingTs: List,
    weldEpsilon: Double = 1E-6
): List> {
    if (ascendingTs.isEmpty()) {
        return listOf(this)
    }

    @Suppress("NAME_SHADOWING") val ascendingTs = (listOf(0.0) + ascendingTs + listOf(1.0)).weldAscending(weldEpsilon)
    return ascendingTs.windowed(2, 1).map {
        sub(it[0], it[1])
    }
}

fun Segment2D.splitAt(ascendingTs: List,
                      weldEpsilon: Double = 1E-6) : List {
    @Suppress("UNCHECKED_CAST")
    return splitAtBase(ascendingTs, weldEpsilon) as List
}

fun Segment3D.splitAt(ascendingTs: List,
                      weldEpsilon: Double = 1E-6) : List {
    @Suppress("UNCHECKED_CAST")
    return splitAtBase(ascendingTs, weldEpsilon) as List
}




© 2015 - 2025 Weber Informatics LLC | Privacy Policy