Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
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
Original file line number Diff line number Diff line change
Expand Up @@ -124,6 +124,12 @@ internal object ColorStopUtils {
)
}
lastDefinedIndex = i
} else if (endPosition != null) {
// Current stop has a defined position but there are no unpositioned
// stops between lastDefinedIndex and i. Still need to advance
// lastDefinedIndex so that subsequent interpolation uses the
// correct start point instead of stale data.
lastDefinedIndex = i
}
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -158,4 +158,29 @@ class ColorStopTest {
assertThat(processed[20].color).isEqualTo(Color.BLUE)
assertThat(processed[20].position).isEqualTo(1f)
}

@Test
fun testColorStopsWithPositionedStopAdjacentToUnpositionedStop() {
val colorStops =
listOf(
ColorStop(Color.RED, LengthPercentage(0f, LengthPercentageType.PERCENT)),
ColorStop(Color.GREEN, LengthPercentage(20f, LengthPercentageType.PERCENT)),
ColorStop(Color.BLUE),
ColorStop(Color.YELLOW, LengthPercentage(80f, LengthPercentageType.PERCENT)),
ColorStop(Color.MAGENTA, LengthPercentage(100f, LengthPercentageType.PERCENT)),
)
val processed = ColorStopUtils.getFixedColorStops(colorStops, 100f)

assertThat(processed).hasSize(5)
assertThat(processed[0].color).isEqualTo(Color.RED)
assertThat(processed[0].position).isEqualTo(0f)
assertThat(processed[1].color).isEqualTo(Color.GREEN)
assertThat(processed[1].position).isEqualTo(0.2f)
assertThat(processed[2].color).isEqualTo(Color.BLUE)
assertThat(processed[2].position).isEqualTo(0.5f)
assertThat(processed[3].color).isEqualTo(Color.YELLOW)
assertThat(processed[3].position).isEqualTo(0.8f)
assertThat(processed[4].color).isEqualTo(Color.MAGENTA)
assertThat(processed[4].position).isEqualTo(1f)
}
}