From 64ee540a2fe663a4a13f54abc00e1acdf7b46aad Mon Sep 17 00:00:00 2001 From: Altair1618 <farhannabilsuryono3@gmail.com> Date: Sat, 16 Mar 2024 20:50:20 +0700 Subject: [PATCH] chore: apply formatting --- .../k2_9/omrekap/activities/ResultActivity.kt | 2 +- .../java/com/k2_9/omrekap/utils/CropHelper.kt | 106 ++++++++++-------- 2 files changed, 59 insertions(+), 49 deletions(-) diff --git a/app/src/main/java/com/k2_9/omrekap/activities/ResultActivity.kt b/app/src/main/java/com/k2_9/omrekap/activities/ResultActivity.kt index c00c72b..e795b04 100644 --- a/app/src/main/java/com/k2_9/omrekap/activities/ResultActivity.kt +++ b/app/src/main/java/com/k2_9/omrekap/activities/ResultActivity.kt @@ -151,7 +151,7 @@ abstract class ResultActivity : MainActivity() { override fun onCreate(savedInstanceState: Bundle?) { super.onCreate(savedInstanceState) - OpenCVLoader.initLocal() + OpenCVLoader.initLocal() if (Build.VERSION.SDK_INT <= Build.VERSION_CODES.Q) { requirePermission(Manifest.permission.WRITE_EXTERNAL_STORAGE, false) {} 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 4f1aa85..d9a7ccc 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 @@ -19,49 +19,57 @@ class CropHelper { ): Bitmap { val mult = 0.03 - val newTopLeft = Point( - points.topLeft.x - (points.topRight.x - points.topLeft.x) * mult - (points.bottomLeft.x - points.topLeft.x) * mult, - points.topLeft.y - (points.topRight.y - points.topLeft.y) * mult - (points.bottomLeft.y - points.topLeft.y) * mult, - ) - - val newTopRight = Point( - points.topRight.x + (points.topRight.x - points.topLeft.x) * mult - (points.bottomRight.x - points.topRight.x) * mult, - points.topRight.y + (points.topRight.y - points.topLeft.y) * mult - (points.bottomRight.y - points.topRight.y) * mult, - ) - - val newBottomRight = Point( - points.bottomRight.x + (points.bottomRight.x - points.topRight.x) * mult + (points.bottomRight.x - points.bottomLeft.x) * mult, - points.bottomRight.y + (points.bottomRight.y - points.topRight.y) * mult + (points.bottomRight.y - points.bottomLeft.y) * mult, - ) - - val newBottomLeft = Point( - points.bottomLeft.x - (points.bottomRight.x - points.bottomLeft.x) * mult + (points.bottomRight.x - points.topRight.x) * mult, - points.bottomLeft.y - (points.bottomRight.y - points.bottomLeft.y) * mult + (points.bottomRight.y - points.topRight.y) * mult, - ) + val newTopLeft = + Point( + points.topLeft.x - (points.topRight.x - points.topLeft.x) * mult - (points.bottomLeft.x - points.topLeft.x) * mult, + points.topLeft.y - (points.topRight.y - points.topLeft.y) * mult - (points.bottomLeft.y - points.topLeft.y) * mult, + ) + + val newTopRight = + Point( + points.topRight.x + (points.topRight.x - points.topLeft.x) * mult - (points.bottomRight.x - points.topRight.x) * mult, + points.topRight.y + (points.topRight.y - points.topLeft.y) * mult - (points.bottomRight.y - points.topRight.y) * mult, + ) + + val newBottomRight = + Point( + points.bottomRight.x + (points.bottomRight.x - points.topRight.x) * mult + (points.bottomRight.x - points.bottomLeft.x) * mult, + points.bottomRight.y + (points.bottomRight.y - points.topRight.y) * mult + (points.bottomRight.y - points.bottomLeft.y) * mult, + ) + + val newBottomLeft = + Point( + points.bottomLeft.x - (points.bottomRight.x - points.bottomLeft.x) * mult + (points.bottomRight.x - points.topRight.x) * mult, + points.bottomLeft.y - (points.bottomRight.y - points.bottomLeft.y) * mult + (points.bottomRight.y - points.topRight.y) * mult, + ) val newPoints = CornerPoints(newTopLeft, newTopRight, newBottomRight, newBottomLeft) - val topWidth = sqrt( - (newPoints.topRight.x - newPoints.topLeft.x).pow(2) + - (newPoints.topRight.y - newPoints.topLeft.y).pow(2) - ) + val topWidth = + sqrt( + (newPoints.topRight.x - newPoints.topLeft.x).pow(2) + + (newPoints.topRight.y - newPoints.topLeft.y).pow(2), + ) - val bottomWidth = sqrt( - (newPoints.bottomRight.x - newPoints.bottomLeft.x).pow(2) + - (newPoints.bottomRight.y - newPoints.bottomLeft.y).pow(2) - ) + val bottomWidth = + sqrt( + (newPoints.bottomRight.x - newPoints.bottomLeft.x).pow(2) + + (newPoints.bottomRight.y - newPoints.bottomLeft.y).pow(2), + ) val maxWidth = maxOf(topWidth, bottomWidth) - val leftHeight = sqrt( - (newPoints.bottomLeft.x - newPoints.topLeft.x).pow(2) + - (newPoints.bottomLeft.y - newPoints.topLeft.y).pow(2) - ) + val leftHeight = + sqrt( + (newPoints.bottomLeft.x - newPoints.topLeft.x).pow(2) + + (newPoints.bottomLeft.y - newPoints.topLeft.y).pow(2), + ) - val rightHeight = sqrt( - (newPoints.bottomRight.x - newPoints.topRight.x).pow(2) + - (newPoints.bottomRight.y - newPoints.topRight.y).pow(2) - ) + val rightHeight = + sqrt( + (newPoints.bottomRight.x - newPoints.topRight.x).pow(2) + + (newPoints.bottomRight.y - newPoints.topRight.y).pow(2), + ) val maxHeight = maxOf(leftHeight, rightHeight) @@ -70,19 +78,21 @@ class CropHelper { val width = 800 val height = (width / aspectRatio).toInt() - val srcMatrix = MatOfPoint2f( - newPoints.topLeft, - newPoints.topRight, - newPoints.bottomRight, - newPoints.bottomLeft, - ) - - val dstMatrix = MatOfPoint2f( - Point(0.0, 0.0), - Point(width - 1.0, 0.0), - Point(0.0, height - 1.0), - Point(width - 1.0, height - 1.0), - ) + val srcMatrix = + MatOfPoint2f( + newPoints.topLeft, + newPoints.topRight, + newPoints.bottomRight, + newPoints.bottomLeft, + ) + + val dstMatrix = + MatOfPoint2f( + Point(0.0, 0.0), + Point(width - 1.0, 0.0), + Point(0.0, height - 1.0), + Point(width - 1.0, height - 1.0), + ) val transformMatrix = getPerspectiveTransform(srcMatrix, dstMatrix) -- GitLab