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

com.primogemstudio.advancedfmk.fontengine.gen.Polygon.kt Maven / Gradle / Ivy

package com.primogemstudio.advancedfmk.fontengine.gen

import org.joml.Vector2f
import kotlin.math.abs

data class Polygon(
    val vertices: MutableList, val holes: MutableList = mutableListOf()
) {
    fun toTriangles(): List {
        val r = mutableListOf()

        var holeSize = holes.sumOf { it.vertices.size }
        val base = vertices.size - holeSize
        val arr = mutableListOf(base)
        for (i in 0 ..< holes.size - 1) {
            holeSize -= holes[i].vertices.size
            arr.add(vertices.size - holeSize - 0)
        }

        val re = EarCutTriangulation.earcut(
            vertices.flatMap { listOf(it.x.toDouble(), it.y.toDouble()) }.toDoubleArray(),
            if (holes.isNotEmpty()) arr.toIntArray() else IntArray(0),
            2
        )
        for (i in 0.. point.y) != (p2.y > point.y) && (point.x < (p2.x - p1.x) * (point.y - p1.y) / (p2.y - p1.y) + p1.x)) count++
        }

        return count % 2 == 1
    }
}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy