Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Remove java.util.Math usages #17

Merged
merged 4 commits into from
Jan 25, 2022
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions .github/workflows/android.yml
Original file line number Diff line number Diff line change
Expand Up @@ -24,3 +24,5 @@ jobs:
run: chmod +x gradlew
- name: Build with Gradle
run: ./gradlew build
- name: Run spotless
run: ./gradlew spotlessCheck
2 changes: 1 addition & 1 deletion color-picker/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -98,7 +98,7 @@ publishing {
publications.withType(MavenPublication::class) {
groupId = "com.godaddy.android.colorpicker"
artifactId = "compose-color-picker"
version = "0.4.1"
version = "0.4.2"

artifact(tasks["javadocJar"])

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
package com.godaddy.android.colorpicker

internal fun Float.toRadian(): Float = this / 180.0f * Math.PI.toFloat()
internal fun Double.toRadian(): Double = this / 180 * Math.PI
internal fun Float.toDegree(): Float = this * 180.0f / Math.PI.toFloat()
internal fun Double.toDegree(): Double = this * 180 / Math.PI
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ import androidx.compose.ui.geometry.Offset
import androidx.compose.ui.platform.LocalDensity
import androidx.compose.ui.unit.IntSize
import com.godaddy.android.colorpicker.HsvColor
import com.godaddy.android.colorpicker.toRadian
import kotlin.math.cos
import kotlin.math.sin

Expand Down Expand Up @@ -51,10 +52,10 @@ internal fun HarmonyColorMagnifiers(
}

private fun positionForColor(color: HsvColor, size: IntSize): Offset {
val radians = Math.toRadians(color.hue.toDouble())
val radians = color.hue.toRadian()
val phi = color.saturation
val x: Float = ((phi * cos(radians)).toFloat() + 1) / 2f
val y: Float = ((phi * sin(radians)).toFloat() + 1) / 2f
val x: Float = ((phi * cos(radians)) + 1) / 2f
val y: Float = ((phi * sin(radians)) + 1) / 2f
return Offset(
x = (x * size.width),
y = (y * size.height)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ import androidx.compose.ui.input.pointer.pointerInput
import androidx.compose.ui.unit.IntSize
import androidx.compose.ui.unit.dp
import com.godaddy.android.colorpicker.HsvColor
import com.godaddy.android.colorpicker.toDegree
import kotlin.math.atan2
import kotlin.math.hypot
import kotlin.math.min
Expand Down Expand Up @@ -133,7 +134,7 @@ private fun colorForPosition(position: Offset, size: IntSize, value: Float): Hsv
val xOffset: Double = position.x - centerX
val yOffset: Double = position.y - centerY
val centerOffset = hypot(xOffset, yOffset)
val rawAngle = Math.toDegrees(atan2(yOffset, xOffset))
val rawAngle = atan2(yOffset, xOffset).toDegree()
val centerAngle = (rawAngle + 360.0) % 360.0
return if (centerOffset <= radius) {
HsvColor(
Expand Down