Skip to content
This repository was archived by the owner on Mar 26, 2025. It is now read-only.

Commit 136e61a

Browse files
author
Artem Pichugin
committed
Fix rectangle
1 parent 71f4850 commit 136e61a

File tree

1 file changed

+19
-2
lines changed
  • app/src/main/java/ru/arti1208/digitiscope

1 file changed

+19
-2
lines changed

app/src/main/java/ru/arti1208/digitiscope/Drawing.kt

Lines changed: 19 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ import androidx.compose.ui.geometry.Size
66
import androidx.compose.ui.graphics.Path
77
import ru.arti1208.digitiscope.model.Tool
88
import kotlin.math.max
9+
import kotlin.math.min
910

1011
fun Path.applyDrawing(
1112
tool: Tool,
@@ -33,14 +34,30 @@ fun Path.applyDrawing(
3334
lastOffset.y
3435
)
3536

36-
Tool.Shape.Oval -> addOval(Rect(originalOffset, lastOffset))
37+
Tool.Shape.Oval -> {
38+
val left = min(originalOffset.x, lastOffset.x)
39+
val top = min(originalOffset.y, lastOffset.y)
40+
val right = max(originalOffset.x, lastOffset.x)
41+
val bottom = max(originalOffset.y, lastOffset.y)
42+
val rect = Rect(left, top, right, bottom)
43+
44+
addOval(rect)
45+
}
3746
Tool.Shape.Circle -> addOval(
3847
Rect(originalOffset, lastOffset.run {
3948
max(x - originalOffset.x, y - originalOffset.y)
4049
})
4150
)
4251

43-
Tool.Shape.Rectangle -> addRect(Rect(originalOffset, lastOffset))
52+
Tool.Shape.Rectangle -> {
53+
val left = min(originalOffset.x, lastOffset.x)
54+
val top = min(originalOffset.y, lastOffset.y)
55+
val right = max(originalOffset.x, lastOffset.x)
56+
val bottom = max(originalOffset.y, lastOffset.y)
57+
val rect = Rect(left, top, right, bottom)
58+
59+
addRect(rect)
60+
}
4461
Tool.Shape.Square -> addRect(
4562
Rect(originalOffset, lastOffset.run {
4663
max(x - originalOffset.x, y - originalOffset.y)

0 commit comments

Comments
 (0)