Check if the order of the points in the polygon is counter-clockwise

The vertices in the polygon need to be sorted

var p1 = new Point[Float](0.0, 0.0)
var p2 = new Point[Float](5.0, 0.0)
var p3 = new Point[Float](0.0, 5.0)
var p4 = new Point[Float](5.0, 5.0)
var arr = new Array[Point[Float]].with_items(p1, p2, p3, p4)
var poly = new ConvexPolygon(arr)
poly.sort_ccw
assert poly.is_ccw

Property definitions

geometry $ ConvexPolygon :: is_ccw
	# Check if the order of the points in the polygon is counter-clockwise
	# The vertices in the polygon need to be sorted
	#
	# ~~~
	# var p1 = new Point[Float](0.0, 0.0)
	# var p2 = new Point[Float](5.0, 0.0)
	# var p3 = new Point[Float](0.0, 5.0)
	# var p4 = new Point[Float](5.0, 5.0)
	# var arr = new Array[Point[Float]].with_items(p1, p2, p3, p4)
	# var poly = new ConvexPolygon(arr)
	# poly.sort_ccw
	# assert poly.is_ccw
	# ~~~
	fun is_ccw: Bool do
		var min = points[0].y
		var min_index = 0
		for i in [1..points.length - 1[ do
			if points[i].y < min then
				min = points[i].y
				min_index = i
			end
		end
		var prev = points[(min_index - 1 + points.length) % points.length]
		var next = points[(min_index + 1) % points.length]
		return not turn_left(prev, points[min_index], next)
	end
lib/geometry/polygon.nit:227,2--252,4