Skip to content

Commit e0f72d4

Browse files
committed
Fixes pointsRoughlySquare
1 parent 72c7129 commit e0f72d4

2 files changed

Lines changed: 31 additions & 16 deletions

File tree

app/build.gradle

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -48,8 +48,8 @@ android {
4848
applicationId "app.jerboa.spp"
4949
minSdk 23
5050
targetSdk 35
51-
versionCode 48
52-
versionName "0.7.0"
51+
versionCode 49
52+
versionName "0.7.1"
5353

5454
testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner"
5555
vectorDrawables {

app/src/main/java/app/jerboa/spp/ui/view/SPPRenderer.kt

Lines changed: 29 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1705,27 +1705,42 @@ class SPPRenderer(
17051705

17061706
}
17071707

1708-
private fun pointsRoughlySquare(points: List<Pair<Float,Float>>, tolerance: Float = 160f*160f): Boolean{
1708+
private fun pointsRoughlySquare(points: List<Pair<Float,Float>>, alignmentTolerance: Float = 50f, sideTolerance: Float = 160f*160f): Boolean{
17091709
if (points.size != 4){ return false }
1710-
val dists = mutableListOf<Float>()
1710+
val smallestDists = mutableListOf<Float>()
17111711
for (i in points.indices){
1712+
var k = 0
1713+
val dists = mutableListOf<Float>(0.0f,0.0f,0.0f)
1714+
var smallDistX = Float.POSITIVE_INFINITY
1715+
var smallDistY = Float.POSITIVE_INFINITY
17121716
for (j in points.indices){
17131717
if (i != j){
17141718
val rx = points[i].first-points[j].first
17151719
val ry = points[i].second-points[j].second
1716-
val d2 = rx*rx+ry*ry
1720+
dists[k] = rx*rx+ry*ry
1721+
k += 1
1722+
if (abs(rx) < smallDistX) { smallDistX = abs(rx) }
1723+
if (abs(ry) < smallDistY) { smallDistY = abs(ry) }
1724+
}
1725+
}
1726+
dists.sort()
1727+
if (abs(dists[0]-dists[1]) > sideTolerance) {
1728+
return false
1729+
}
1730+
if (smallDistX > alignmentTolerance || smallDistY > alignmentTolerance)
1731+
{
1732+
return false
1733+
}
1734+
smallestDists.add(dists[0])
1735+
}
17171736

1718-
if (dists.size == 0) { dists.add(d2) }
1719-
if (dists.size == 1){
1720-
if (abs(dists[0] - d2 ) > tolerance){
1721-
dists.add(d2)
1722-
}
1723-
}
1724-
if (dists.size == 2){
1725-
if (abs(dists[0] - d2 ) > tolerance && abs(dists[1] - d2 ) > tolerance){
1726-
return false
1727-
}
1728-
}
1737+
for (i in smallestDists.indices)
1738+
{
1739+
for (j in smallestDists.indices)
1740+
{
1741+
if (abs(smallestDists[i]-smallestDists[j]) > sideTolerance)
1742+
{
1743+
return false
17291744
}
17301745
}
17311746
}

0 commit comments

Comments
 (0)