@@ -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