polygon

fun polygon(points: List<Vec2>): Shape(source)

Returns a convex polygon through points, which may go round either way: polygon(listOf(Vec2(0f, 0f), Vec2(20f, 0f), Vec2(10f, 15f))) is a triangle. A dent, a crossing, or points in a line are refused: a concave shape is made of several convex ones, as a compound body.

Throws

if there are fewer than 3 or more than MAX_VERTICES points, a point is not finite, two points are the same, three are in a line, or the polygon is not convex or crosses itself.

Samples

val ball = Shape.circle(radius = 8f)
val crate = Shape.box(width = 20f, height = 20f)
val pill = Shape.capsule(length = 30f, radius = 5f)
val wedge = Shape.polygon(listOf(Vec2(0f, 0f), Vec2(30f, 0f), Vec2(0f, -20f)))
assertPrints(crate, "Shape(POLYGON, vertices=4, radius=0.0)")
assertPrints(ball.contains(0f, 7f), "true")
assertPrints(pill.vertexCount, "2")
assertPrints(wedge.area, "300.0")