Skip to content

Commit

Permalink
some improvements
Browse files Browse the repository at this point in the history
  • Loading branch information
T8RIN committed May 3, 2024
1 parent 3325645 commit 32c6bfe
Show file tree
Hide file tree
Showing 3 changed files with 52 additions and 3 deletions.
Expand Up @@ -15,16 +15,65 @@
* along with this program. If not, see <http://www.apache.org/licenses/LICENSE-2.0>.
*/

@file:Suppress("NOTHING_TO_INLINE")

package ru.tech.imageresizershrinker.feature.draw.domain

import ru.tech.imageresizershrinker.core.domain.model.IntegerSize
import kotlin.math.min

private const val NORMALIZATION_FACTOR = 500

@JvmInline
value class Pt(val value: Float) {
fun toPx(
size: IntegerSize
): Float = min(size.width * (value / 500), size.height * (value / 500))
): Float = min(
size.width * (value / NORMALIZATION_FACTOR),
size.height * (value / NORMALIZATION_FACTOR)
)


/**
* Add two [Pt]s together.
*/
inline operator fun plus(other: Pt) = Pt(this.value + other.value)

/**
* Subtract a Pt from another one.
*/
inline operator fun minus(other: Pt) = Pt(this.value - other.value)

/**
* This is the same as multiplying the Pt by -1.0.
*/
inline operator fun unaryMinus() = Pt(-value)

/**
* Divide a Pt by a scalar.
*/
inline operator fun div(other: Float): Pt = Pt(value / other)


inline operator fun div(other: Int): Pt = Pt(value / other)

/**
* Divide by another Pt to get a scalar.
*/
inline operator fun div(other: Pt): Float = value / other.value

/**
* Multiply a Pt by a scalar.
*/
inline operator fun times(other: Float): Pt = Pt(value * other)


inline operator fun times(other: Int): Pt = Pt(value * other)

/**
* Support comparing Dimensions with comparison operators.
*/
inline operator fun compareTo(other: Pt) = value.compareTo(other.value)
}

inline val Float.pt: Pt get() = Pt(this)
Expand Down
Expand Up @@ -521,7 +521,7 @@ fun EraseBackgroundScreen(
.padding(
start = 16.dp,
end = 16.dp,
bottom = 16.dp
top = 8.dp
),
shape = RoundedCornerShape(24.dp),
title = stringResource(R.string.magnifier),
Expand Down
Expand Up @@ -281,7 +281,6 @@ fun EraseBackgroundEditOption(
start = 16.dp,
end = 16.dp,
top = 8.dp,
bottom = 16.dp
)
)
val settingsInteractor = LocalSettingsInteractor.current
Expand All @@ -291,6 +290,7 @@ fun EraseBackgroundEditOption(
.padding(
start = 16.dp,
end = 16.dp,
top = 8.dp,
bottom = 16.dp
),
shape = RoundedCornerShape(24.dp),
Expand Down

0 comments on commit 32c6bfe

Please sign in to comment.