Skip to content

Commit

Permalink
Change template icon scheme color order
Browse files Browse the repository at this point in the history
  • Loading branch information
FWDekker committed Oct 15, 2024
1 parent 2261657 commit e19e0ff
Show file tree
Hide file tree
Showing 3 changed files with 20 additions and 18 deletions.
5 changes: 4 additions & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,7 +1,10 @@
# Changelog
## 9.9.9-unreleased
### Changed
* In template icons, change the order of scheme colors to be clockwise starting from the top, instead of counterclockwise starting on the right.

### Fixed
* Hopefully fix "Must be not computed before that call" bug by deferring icon validation to painting. ([#R1](https://github.com/FWDekkerBot/intellij-randomness-issues/issues/1)) ([#R13](https://github.com/FWDekkerBot/intellij-randomness-issues/issues/13)) ([IJPL-163887](https://youtrack.jetbrains.com/issue/IJPL-163887/))
* (Hopefully) fix "Must be not computed before that call" bug by deferring icon validation to painting. ([#R1](https://github.com/FWDekkerBot/intellij-randomness-issues/issues/1)) ([#R13](https://github.com/FWDekkerBot/intellij-randomness-issues/issues/13)) ([IJPL-163887](https://youtrack.jetbrains.com/issue/IJPL-163887/))
* Fixed bug reporter to also check closed issues when checking for duplicates.


Expand Down
14 changes: 7 additions & 7 deletions src/main/kotlin/com/fwdekker/randomness/Icons.kt
Original file line number Diff line number Diff line change
Expand Up @@ -340,21 +340,21 @@ class RadialColorReplacementFilter(


/**
* Returns [toShift] which has its alpha multiplied by that of [shiftBy].
* Returns [base] after multiplying its alpha by the alpha of [shiftBy].
*/
private fun shiftAlpha(toShift: Color, shiftBy: Color) =
ColorUtil.withAlpha(toShift, asFraction(toShift.alpha) * asFraction(shiftBy.alpha))
private fun shiftAlpha(base: Color, shiftBy: Color): Color =
ColorUtil.withAlpha(base, asFraction(base.alpha) * asFraction(shiftBy.alpha))

/**
* Represents a [number] in the range `[0, 256)` as a fraction of that range.
*/
private fun asFraction(number: Int) = number / COMPONENT_MAX.toDouble()
private fun asFraction(number: Int): Double = number / COMPONENT_MAX

/**
* Returns the appropriate color from [colors] for an [offset] relative to the [center].
*/
private fun positionToColor(offset: Pair<Int, Int>): Color {
val angle = 2 * Math.PI - (atan2(offset.second.toDouble(), offset.first.toDouble()) + STARTING_ANGLE)
val angle = 2 * Math.PI + STARTING_ANGLE + atan2(offset.second.toDouble(), offset.first.toDouble())
val index = angle / (2 * Math.PI / colors.size)
return colors[Math.floorMod(index.toInt(), colors.size)]
}
Expand All @@ -367,11 +367,11 @@ class RadialColorReplacementFilter(
/**
* Maximum value for an RGB component.
*/
const val COMPONENT_MAX = 255
const val COMPONENT_MAX: Double = 255.0

/**
* The angle in radians at which the first color should start being displayed.
*/
const val STARTING_ANGLE = -(3 * Math.PI / 4)
const val STARTING_ANGLE: Double = .25 * (2 * Math.PI)
}
}
19 changes: 9 additions & 10 deletions src/test/kotlin/com/fwdekker/randomness/IconsTest.kt
Original file line number Diff line number Diff line change
Expand Up @@ -340,16 +340,15 @@ object RadialColorReplacementFilterTest : FunSpec({
Color(filtered, true).alpha shouldBe 12
}

test("returns the first of four colors if a position above the center is given") {
val filter = RadialColorReplacementFilter(listOf(Color.RED, Color.BLUE, Color.PINK, Color.GRAY), Pair(0, 0))

filter.filterRGB(0, 12, Color.MAGENTA.rgb) shouldBe Color.RED.rgb
}

test("returns the second color of four colors if a position to the right of the center is given") {
val filter = RadialColorReplacementFilter(listOf(Color.RED, Color.BLUE, Color.PINK, Color.GRAY), Pair(0, 0))

filter.filterRGB(104, 0, Color.PINK.rgb) shouldBe Color.BLUE.rgb
test("arranges four colors in clockwise order starting from the top") {
val colors = listOf(Color.RED, Color.BLUE, Color.PINK, Color.GRAY)
val filter = RadialColorReplacementFilter(colors, Pair(0, 0))

// Uses pixel coordinates, so "up" is negative y and "down" is positive y
filter.filterRGB(5, -5, Color.MAGENTA.rgb) shouldBe colors[0].rgb
filter.filterRGB(5, 5, Color.MAGENTA.rgb) shouldBe colors[1].rgb
filter.filterRGB(-5, 5, Color.MAGENTA.rgb) shouldBe colors[2].rgb
filter.filterRGB(-5, -5, Color.MAGENTA.rgb) shouldBe colors[3].rgb
}

test("shifts the color") {
Expand Down

0 comments on commit e19e0ff

Please sign in to comment.