Code Quality Issue: Duplicated Path Logic in Select.kt
Maintainers usually reply within 1 day
Nobody has claimed this yet.
Assessment
- Difficulty
- 2/5
- Estimated time
- 1-3 hours
- Newbie friendliness
- 54/100
Research direction
Read app/src/main/java/com/ethran/notable/editor/utils/Select.kt, focusing on selectStrokesFromPath and selectImagesFromPath and their duplicated bounds and region calculations. Extract the shared logic into a helper and update both functions to use it; done when both use one implementation and the selection behavior is preserved.
Written by the indexing model from the issue text.
Description
(by Claude AI)
Description
In app/src/main/java/com/ethran/notable/editor/utils/Select.kt, there is explicit code duplication between selectStrokesFromPath and selectImagesFromPath functions.
Both functions contain the exact same logic for computing the bounds of a path and shifting it into a 16-bit region format:
val bounds = RectF()
path.computeBounds(bounds, true)
//region is only 16 bit, so we need to move our region
val translatedPath = Path(path)
translatedPath.offset(0f, -bounds.top)
val region = pathToRegion(translatedPath)
This violates the DRY (Don't Repeat Yourself) principle. Any changes to how the selection boundaries are calculated or how the region offset is handled (e.g. for fixing the 16-bit clipping issue) would need to be made in two separate places.
Recommended Fix
Extract the common bounds and region calculation logic into a reusable helper function or class.
data class SelectionRegion(val bounds: RectF, val region: Region)
fun createSelectionRegion(path: Path): SelectionRegion {
val bounds = RectF()
path.computeBounds(bounds, true)
val translatedPath = Path(path)
translatedPath.offset(0f, -bounds.top)
return SelectionRegion(bounds, pathToRegion(translatedPath))
}
Then, update both selectStrokesFromPath and selectImagesFromPath to utilize this single source of truth for generating the selection boundary.
- Dominant language
- Kotlin
- Stars
- 269
- Forks
- 44
- Avg merge
- 1d 17h
- Merged PRs (30d)
- 22
Getting set up
This project ships no dev container, Dockerfile or contributing guide, so setting up is up to you: start from its README, and see our first-contribution guide for the general steps.
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
More from Ethran/notable
-
Difficulty 2/5 1-3 hours Newbie friendliness 70/100
Maintainers usually reply within 1 day
-
[AI] Line tool saves raw pen pressure (clamped to full pressure)Possibly taken @kal-kaliper claimed this 1 day ago. Openbug
Difficulty 2/5 1-3 hours Newbie friendliness 90/100
Maintainers usually reply within 1 day
-
Editor burger menuOpenbug
Difficulty 3/5 1-2 days Newbie friendliness 55/100
Maintainers usually reply within 1 day
-
Difficulty 5/5 Over a week Newbie friendliness 30/100
Maintainers usually reply within 1 day
-
[Feature Suggestion] Independent Zoom Controls: Decouple Zoom-In from Zoom-Out (with 1.0x Snap)Open
Difficulty 4/5 3-5 days Newbie friendliness 48/100
Maintainers usually reply within 1 day
Similar issues
-
area:data-quality importer size:S
Difficulty 2/5 1-3 hours Newbie friendliness 72/100
enorm-labs/event-junkie#5136 ·
Maintainers usually reply within 1 day
-
0. Needs triage bug
Difficulty 2/5 1-3 hours Newbie friendliness 64/100
Maintainers usually reply within 1 day
-
Type: Possible bug
Difficulty 2/5 1-3 hours Newbie friendliness 68/100
spacecowboy/Feeder#1318 ·
Maintainers usually reply within 1 day
-
Difficulty 2/5 1-3 hours Newbie friendliness 70/100
wangzan101/Mika#644 ·
Maintainers usually reply within 1 day
-
good first issue
Difficulty 2/5 1-3 hours Newbie friendliness 65/100
commons-app/apps-android-commons#7341 ·
Maintainers usually reply within 1 day