From 03df4bafa66bad77d4616d6627cdd3e6a43e48d6 Mon Sep 17 00:00:00 2001
From: Michael Utama <michaelu670@gmail.com>
Date: Tue, 21 May 2024 10:37:23 +0700
Subject: [PATCH] fix: weird cropping behavior and centralize pattern
 coordinate

---
 app/src/main/java/com/k2_9/omrekap/utils/CropHelper.kt | 10 +++-------
 1 file changed, 3 insertions(+), 7 deletions(-)

diff --git a/app/src/main/java/com/k2_9/omrekap/utils/CropHelper.kt b/app/src/main/java/com/k2_9/omrekap/utils/CropHelper.kt
index 57b8e46..735408e 100644
--- a/app/src/main/java/com/k2_9/omrekap/utils/CropHelper.kt
+++ b/app/src/main/java/com/k2_9/omrekap/utils/CropHelper.kt
@@ -111,7 +111,7 @@ object CropHelper {
 		pointsList.forEach {
 			if (needChange == 0) return@forEach
 
-			val corner = nearWhichCorner(it.x, it.y, resultMatrix.height(), resultMatrix.width(), limFrac = 0.6F)
+			val corner = nearWhichCorner(it.x, it.y, resultMatrix.height(), resultMatrix.width(), limFrac = 0.4F)
 			if (corner == -1) return@forEach
 
 			if (it.weight > 0.45) {
@@ -130,23 +130,19 @@ object CropHelper {
 			if (needed[corner]) {
 				needed[corner] = false
 				needChange--
-				val pointFromIt = Point(it.y.toDouble(), it.x.toDouble())
+				val pointFromIt = Point(it.y.toDouble() + pattern.width().toDouble() / 2, it.x.toDouble() + pattern.height().toDouble() / 2)
 				when (corner) {
 					UPPER_LEFT -> {
 						upperLeftPoint = pointFromIt
 					}
 					UPPER_RIGHT -> {
 						upperRightPoint = pointFromIt
-						upperRightPoint.x += pattern.height().toDouble()
 					}
 					LOWER_RIGHT -> {
 						lowerRightPoint = pointFromIt
-						lowerRightPoint.x += pattern.height().toDouble()
-						lowerRightPoint.y += pattern.width().toDouble()
 					}
 					LOWER_LEFT -> {
 						lowerLeftPoint = pointFromIt
-						lowerLeftPoint.y += pattern.width().toDouble()
 					}
 				}
 			}
@@ -319,6 +315,6 @@ object CropHelper {
 	 * @return weight
 	 */
 	private fun getWeight(normDistance: Double): Double {
-		return 1 + 1 * normDistance.pow(1.5)
+		return 1 + 1 * normDistance.pow(0.5)
 	}
 }
-- 
GitLab