Reorg: new package for domain

This commit is contained in:
Pierre-Yves Nicolas
2025-11-18 17:04:33 +01:00
parent 1f734e9d95
commit 8f9d51e65a
12 changed files with 26 additions and 21 deletions

View File

@@ -12,7 +12,7 @@
* You should have received a copy of the GNU General Public License along with * You should have received a copy of the GNU General Public License along with
* this program. If not, see <https://www.gnu.org/licenses/>. * this program. If not, see <https://www.gnu.org/licenses/>.
*/ */
package org.fairscan.app package org.fairscan.app.domain
import android.content.Context import android.content.Context
import android.graphics.Bitmap import android.graphics.Bitmap
@@ -51,8 +51,8 @@ class DocumentDetectionTest {
segmentationService.runSegmentationAndReturn(bitmap, 0) segmentationService.runSegmentationAndReturn(bitmap, 0)
} }
if (segmentationResult != null) { if (segmentationResult != null) {
val mask = segmentationResult.segmentation.toBinaryMask() val mask = segmentationResult.segmentation
val quad = detectDocumentQuad(mask) val quad = detectDocumentQuad(mask, false)
if (quad != null) { if (quad != null) {
val resizedQuad = val resizedQuad =
quad.scaledTo(mask.width, mask.height, bitmap.width, bitmap.height) quad.scaledTo(mask.width, mask.height, bitmap.width, bitmap.height)

View File

@@ -16,6 +16,7 @@ package org.fairscan.app
import android.graphics.Bitmap import android.graphics.Bitmap
import androidx.compose.runtime.Immutable import androidx.compose.runtime.Immutable
import org.fairscan.app.domain.Quad
@Immutable @Immutable
data class LiveAnalysisState( data class LiveAnalysisState(

View File

@@ -40,6 +40,10 @@ import kotlinx.coroutines.flow.update
import kotlinx.coroutines.launch import kotlinx.coroutines.launch
import kotlinx.coroutines.withContext import kotlinx.coroutines.withContext
import org.fairscan.app.data.recentDocumentsDataStore import org.fairscan.app.data.recentDocumentsDataStore
import org.fairscan.app.domain.ImageSegmentationService
import org.fairscan.app.domain.detectDocumentQuad
import org.fairscan.app.domain.extractDocument
import org.fairscan.app.domain.scaledTo
import org.fairscan.app.ui.PdfGenerationUiState import org.fairscan.app.ui.PdfGenerationUiState
import org.fairscan.app.ui.RecentDocumentUiState import org.fairscan.app.ui.RecentDocumentUiState
import org.fairscan.app.view.DocumentUiModel import org.fairscan.app.view.DocumentUiModel

View File

@@ -12,14 +12,14 @@
* You should have received a copy of the GNU General Public License along with * You should have received a copy of the GNU General Public License along with
* this program. If not, see <https://www.gnu.org/licenses/>. * this program. If not, see <https://www.gnu.org/licenses/>.
*/ */
package org.fairscan.app package org.fairscan.app.domain
import android.graphics.Bitmap import android.graphics.Bitmap
import androidx.core.graphics.createBitmap import androidx.core.graphics.createBitmap
import org.fairscan.app.ImageSegmentationService.Segmentation import org.fairscan.app.domain.ImageSegmentationService.Segmentation
import org.fairscan.app.quad.detectDocumentQuadFromProbmap import org.fairscan.app.domain.quad.detectDocumentQuadFromProbmap
import org.fairscan.app.quad.findQuadFromRightAngles import org.fairscan.app.domain.quad.findQuadFromRightAngles
import org.fairscan.app.quad.minAreaRect import org.fairscan.app.domain.quad.minAreaRect
import org.opencv.android.Utils import org.opencv.android.Utils
import org.opencv.core.Core import org.opencv.core.Core
import org.opencv.core.CvType import org.opencv.core.CvType

View File

@@ -12,9 +12,10 @@
* You should have received a copy of the GNU General Public License along with * You should have received a copy of the GNU General Public License along with
* this program. If not, see <https://www.gnu.org/licenses/>. * this program. If not, see <https://www.gnu.org/licenses/>.
*/ */
package org.fairscan.app package org.fairscan.app.domain
import kotlin.math.atan2 import kotlin.math.atan2
import kotlin.math.hypot
data class Point(val x: Double, val y: Double) { data class Point(val x: Double, val y: Double) {
constructor(x: Int, y: Int) : this (x.toDouble(), y.toDouble()) constructor(x: Int, y: Int) : this (x.toDouble(), y.toDouble())
@@ -29,7 +30,7 @@ data class Line(val from: Point, val to: Point) {
fun norm(p1: Point, p2: Point): Double { fun norm(p1: Point, p2: Point): Double {
val dx = (p2.x - p1.x) val dx = (p2.x - p1.x)
val dy = (p2.y - p1.y) val dy = (p2.y - p1.y)
return kotlin.math.hypot(dx, dy) return hypot(dx, dy)
} }
data class Quad( data class Quad(

View File

@@ -12,7 +12,7 @@
* You should have received a copy of the GNU General Public License along with * You should have received a copy of the GNU General Public License along with
* this program. If not, see <https://www.gnu.org/licenses/>. * this program. If not, see <https://www.gnu.org/licenses/>.
*/ */
package org.fairscan.app package org.fairscan.app.domain
import android.content.Context import android.content.Context
import android.graphics.Bitmap import android.graphics.Bitmap

View File

@@ -12,13 +12,12 @@
* You should have received a copy of the GNU General Public License along with * You should have received a copy of the GNU General Public License along with
* this program. If not, see <https://www.gnu.org/licenses/>. * this program. If not, see <https://www.gnu.org/licenses/>.
*/ */
package org.fairscan.app package org.fairscan.app.domain
import android.util.Log import android.util.Log
import org.opencv.core.Core import org.opencv.core.Core
import org.opencv.core.CvType import org.opencv.core.CvType
import org.opencv.core.Mat import org.opencv.core.Mat
import org.opencv.core.MatOfDouble
import org.opencv.core.Scalar import org.opencv.core.Scalar
import org.opencv.core.Size import org.opencv.core.Size
import org.opencv.imgproc.Imgproc import org.opencv.imgproc.Imgproc

View File

@@ -12,7 +12,7 @@
* You should have received a copy of the GNU General Public License along with * You should have received a copy of the GNU General Public License along with
* this program. If not, see <https://www.gnu.org/licenses/>. * this program. If not, see <https://www.gnu.org/licenses/>.
*/ */
package org.fairscan.app.quad package org.fairscan.app.domain.quad
import org.opencv.core.Mat import org.opencv.core.Mat
import org.opencv.core.CvType import org.opencv.core.CvType

View File

@@ -12,9 +12,9 @@
* You should have received a copy of the GNU General Public License along with * You should have received a copy of the GNU General Public License along with
* this program. If not, see <https://www.gnu.org/licenses/>. * this program. If not, see <https://www.gnu.org/licenses/>.
*/ */
package org.fairscan.app.quad package org.fairscan.app.domain.quad
import org.fairscan.app.Point import org.fairscan.app.domain.Point
import kotlin.math.cos import kotlin.math.cos
import kotlin.math.sin import kotlin.math.sin

View File

@@ -12,9 +12,9 @@
* You should have received a copy of the GNU General Public License along with * You should have received a copy of the GNU General Public License along with
* this program. If not, see <https://www.gnu.org/licenses/>. * this program. If not, see <https://www.gnu.org/licenses/>.
*/ */
package org.fairscan.app.quad package org.fairscan.app.domain.quad
import org.fairscan.app.Point import org.fairscan.app.domain.Point
import kotlin.math.abs import kotlin.math.abs
import kotlin.math.acos import kotlin.math.acos
import kotlin.math.sqrt import kotlin.math.sqrt

View File

@@ -55,8 +55,8 @@ import androidx.lifecycle.compose.LocalLifecycleOwner
import com.google.common.util.concurrent.ListenableFuture import com.google.common.util.concurrent.ListenableFuture
import org.fairscan.app.CameraPermissionState import org.fairscan.app.CameraPermissionState
import org.fairscan.app.LiveAnalysisState import org.fairscan.app.LiveAnalysisState
import org.fairscan.app.Point import org.fairscan.app.domain.Point
import org.fairscan.app.scaledTo import org.fairscan.app.domain.scaledTo
import java.util.concurrent.ExecutorService import java.util.concurrent.ExecutorService
import java.util.concurrent.Executors import java.util.concurrent.Executors

View File

@@ -12,7 +12,7 @@
* You should have received a copy of the GNU General Public License along with * You should have received a copy of the GNU General Public License along with
* this program. If not, see <https://www.gnu.org/licenses/>. * this program. If not, see <https://www.gnu.org/licenses/>.
*/ */
package org.fairscan.app package org.fairscan.app.domain
import org.assertj.core.api.Assertions.assertThat import org.assertj.core.api.Assertions.assertThat
import org.assertj.core.api.Assertions.assertThatThrownBy import org.assertj.core.api.Assertions.assertThatThrownBy