diff --git a/core/src/main/kotlin/org/polyfrost/compose/backend/PolyPathOps.kt b/core/src/main/kotlin/org/polyfrost/compose/backend/PolyPathOps.kt index d305b65..779eab2 100644 --- a/core/src/main/kotlin/org/polyfrost/compose/backend/PolyPathOps.kt +++ b/core/src/main/kotlin/org/polyfrost/compose/backend/PolyPathOps.kt @@ -36,12 +36,12 @@ private fun oriented(contours: List, sign: Float): List // Twice the signed area private fun area(c: FloatArray): Float { - var sum = 0f + var sum = 0.0 for (k in c.indices step 2) { val j = (k + 2) % c.size - sum += c[k] * c[j + 1] - c[j] * c[k + 1] + sum += c[k].toDouble() * c[j + 1] - c[j].toDouble() * c[k + 1] } - return sum + return sum.toFloat() } private fun convex(contours: List): FloatArray? { diff --git a/core/src/test/kotlin/org/polyfrost/compose/backend/PolyPathOpsTest.kt b/core/src/test/kotlin/org/polyfrost/compose/backend/PolyPathOpsTest.kt index 15bb723..d91fe47 100644 --- a/core/src/test/kotlin/org/polyfrost/compose/backend/PolyPathOpsTest.kt +++ b/core/src/test/kotlin/org/polyfrost/compose/backend/PolyPathOpsTest.kt @@ -86,6 +86,19 @@ class PolyPathOpsTest { assertEquals(listOf(true, false, false), clipped.hits(7f, 7f, 12f, 12f, 2f, 2f)) } + @Test + fun intersectKeepsTinyBoxFarFromOrigin() { + val box = rect(1299.995f, 305.995f, 1300.005f, 306.005f) + assertFalse(op(rect(1100f, 286f, 1500f, 326f), box, PathOperation.Intersect).isEmpty) + assertTrue(op(rect(1100f, 286f, 1290f, 326f), box, PathOperation.Intersect).isEmpty) + } + + @Test + fun intersectKeepsStretchedTriangle() { + val triangle = Path().apply { moveTo(-1e8f, -1e8f); lineTo(0f, 0f); lineTo(0f, 1f); close() } + assertFalse(op(triangle, triangle, PathOperation.Intersect).isEmpty) + } + @Test fun nonUniformRoundedBorderRenders() { val rec = FrameRecomposer(Dispatchers.Unconfined) {}