Skip to content

Commit

Permalink
Merge pull request #17 from godaddy/feature/remove-java-math
Browse files Browse the repository at this point in the history
Remove java.util.Math usages
  • Loading branch information
Rebecca Franks authored Jan 25, 2022
2 parents 9f197e9 + 8e686fa commit e2380bd
Show file tree
Hide file tree
Showing 5 changed files with 29 additions and 6 deletions.
15 changes: 14 additions & 1 deletion .github/workflows/android.yml
Original file line number Diff line number Diff line change
Expand Up @@ -22,5 +22,18 @@ jobs:

- name: Grant execute permission for gradlew
run: chmod +x gradlew
- name: Configure GPG Key
run: |
mkdir ~/.gpgkey
echo $GPG_KEY > ~/.gpgkey/secring.gpg.b64
base64 -d ~/.gpgkey/secring.gpg.b64 > ~/.gpgkey/secring.gpg
env:
GPG_KEY: ${{ secrets.GPG_KEY }}
- name: Build with Gradle
run: ./gradlew build
env:
ORG_GRADLE_PROJECT_mavenCentralUsername: ${{ secrets.MAVEN_CENTRAL_USERNAME }}
ORG_GRADLE_PROJECT_mavenCentralPassword: ${{ secrets.MAVEN_CENTRAL_PASSWORD }}
run: |
./gradlew build --no-parallel --no-daemon -Psigning.keyId=${{secrets.GPG_KEY_ID}} -Psigning.password=${{secrets.GPG_KEY_PASSWORD}} -Psigning.secretKeyRingFile=$(echo ~/.gpgkey/secring.gpg)
- 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,8 @@
package com.godaddy.android.colorpicker

import kotlin.math.PI

internal fun Float.toRadian(): Float = this / 180.0f * PI.toFloat()
internal fun Double.toRadian(): Double = this / 180 * PI
internal fun Float.toDegree(): Float = this * 180.0f / PI.toFloat()
internal fun Double.toDegree(): Double = this * 180 / 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

0 comments on commit e2380bd

Please sign in to comment.