Close fully visible geohash outlines

This commit is contained in:
a1denvalu3 2026-07-30 14:29:22 +02:00
parent 2a43265e12
commit 5bde4e0b4a
2 changed files with 42 additions and 2 deletions

View File

@ -421,7 +421,7 @@ private fun DrawScope.drawGraticule(
drawPath(path, color, style = Stroke(width = 1f))
}
private data class DiscPt(val x: Float, val y: Float, val front: Boolean)
internal data class DiscPt(val x: Float, val y: Float, val front: Boolean)
private fun limbPoint(behind: DiscPt, front: DiscPt): Pair<Float, Float> {
var lo = 0f; var hi = 1f
@ -440,7 +440,10 @@ private fun limbPoint(behind: DiscPt, front: DiscPt): Pair<Float, Float> {
* padded with the horizon intersection point so they can be closed along the horizon.
* Pass [closed] = false for open polylines (border lines).
*/
private fun buildFrontRuns(pts: List<DiscPt>, closed: Boolean = true): List<MutableList<Pair<Float, Float>>> {
internal fun buildFrontRuns(
pts: List<DiscPt>,
closed: Boolean = true
): List<MutableList<Pair<Float, Float>>> {
if (pts.isEmpty()) return emptyList()
val n = pts.size
val runs = mutableListOf<MutableList<Pair<Float, Float>>>()
@ -477,6 +480,12 @@ private fun buildFrontRuns(pts: List<DiscPt>, closed: Boolean = true): List<Muta
if (closed && runs.isNotEmpty() && pts[0].front && pts[n - 1].front) {
runs[0] = (run + runs[0]).toMutableList()
} else {
// A fully front-facing ring has no limb transition to terminate its run.
// Close it explicitly; cell boundary sampling intentionally omits the
// duplicated final corner.
if (closed && runs.isEmpty() && pts[0].front && pts[n - 1].front) {
run.add(run.first())
}
runs.add(run)
}
}

View File

@ -0,0 +1,31 @@
package com.bitchat.android.ui.globe
import org.junit.Assert.assertEquals
import org.junit.Assert.assertNotEquals
import org.junit.Test
class GlobeGeometryTest {
private val square = listOf(
DiscPt(-0.5f, -0.5f, front = true),
DiscPt(0.5f, -0.5f, front = true),
DiscPt(0.5f, 0.5f, front = true),
DiscPt(-0.5f, 0.5f, front = true)
)
@Test
fun closedFullyVisibleRing_connectsLastPointToFirst() {
val run = buildFrontRuns(square, closed = true).single()
assertEquals(square.size + 1, run.size)
assertEquals(run.first(), run.last())
}
@Test
fun openFullyVisibleLine_doesNotConnectLastPointToFirst() {
val run = buildFrontRuns(square, closed = false).single()
assertEquals(square.size, run.size)
assertNotEquals(run.first(), run.last())
}
}