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

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

There is a newer version: 0.4.5-alpha6
Show newest version
package org.openrndr.extra.shapes.utilities

import org.openrndr.shape.ShapeContour
import org.openrndr.shape.contour

/**
 * Create a contour from a list of contours
 */
fun ShapeContour.Companion.fromContours(contours: List, closed: Boolean, connectEpsilon:Double=1E-6) : ShapeContour {
    @Suppress("NAME_SHADOWING") val contours = contours.filter { !it.empty }
    if (contours.isEmpty()) {
        return EMPTY
    }
    return contour {
        moveTo(contours.first().position(0.0))
        for (c in contours.windowed(2,1,true)) {
            copy(c[0])
            if (c.size == 2) {
                val d = c[0].position(1.0).distanceTo(c[1].position(0.0))
                if (d > connectEpsilon ) {
                    lineTo(c[1].position(0.0))
                }
            }
        }
        if (closed) {
            close()
        }
    }
}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy