Code Quality Issue: Duplicated Path Logic in Select.kt

Open
#258 0 comments 0 reactions 0 assignees View on GitHub

Maintainers usually reply within 1 day

Nobody has claimed this yet.

Assessment

Difficulty
2/5
Estimated time
1-3 hours
Newbie friendliness
54/100
Issue type
Refactor
Clarity
Clearly specified
Activity status
Quiet
Tech stack
kotlin
Domain
mobile

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

priority:low

(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

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

More from Ethran/notable

All issues in Ethran/notable

Similar issues

More Kotlin issues

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.