Unverified Commit 93367672 authored by alexander-gorshenev's avatar alexander-gorshenev Committed by GitHub

Fixed assert in Canvas::drawVertices (#208)

Added a test for Canvas::drawVertices
parent d53b7857
...@@ -852,8 +852,16 @@ open class Canvas internal constructor(ptr: NativePointer, managed: Boolean, int ...@@ -852,8 +852,16 @@ open class Canvas internal constructor(ptr: NativePointer, managed: Boolean, int
mode: BlendMode, mode: BlendMode,
paint: Paint paint: Paint
): Canvas { ): Canvas {
require(colors == null || colors.size == positions.size) { "Expected colors.length == positions.length, got: " + colors!!.size + " != " + positions.size } require(positions.size % 2 == 0) {
require(texCoords == null || texCoords.size == positions.size) { "Expected texCoords.length == positions.length, got: " + texCoords!!.size + " != " + positions.size } "Expected even number of positions: ${positions.size}"
}
val points = positions.size / 2
require(colors == null || colors.size == points) {
"Expected colors.length == positions.length / 2, got: " + colors!!.size + " != " + points
}
require(texCoords == null || texCoords.size == positions.size) {
"Expected texCoords.length == positions.length, got: " + texCoords!!.size + " != " + positions.size
}
Stats.onNativeCall() Stats.onNativeCall()
interopScope { interopScope {
_nDrawVertices( _nDrawVertices(
......
package org.jetbrains.skiko
import org.jetbrains.skia.*
import org.jetbrains.skiko.util.ScreenshotTestRule
import org.junit.Rule
import org.junit.Test
class CanvasTest {
@get:Rule
val screenshots = ScreenshotTestRule()
@Test
fun drawVertices() {
val surface = Surface.makeRasterN32Premul(16, 16)
val positions = Point.flattenArray(
arrayOf(
Point(0f, 0f),
Point(16f, 0f),
Point(8f, 8f),
Point(16f, 8f),
Point(0f, 16f),
Point(16f, 16f),
)
)!!
val colors = listOf(
Color.RED, Color.GREEN, Color.BLUE, Color.CYAN, Color.MAGENTA, Color.YELLOW
).toIntArray()
val indices = shortArrayOf(0, 1, 2, 3, 4, 5)
surface.canvas.drawVertices(
VertexMode.TRIANGLES,
positions,
colors,
positions,
indices,
BlendMode.SRC_OVER,
Paint()
)
screenshots.assert(surface.makeImageSnapshot())
}
}
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment