/// <summary> /// builds the Polygon edge normals. These are lazily created and updated only by the edgeNormals getter /// </summary> void BuildEdgeNormals() { // for boxes we only require 2 edges since the other 2 are parallel var totalEdges = isBox ? 2 : Points.Length; if (_edgeNormals == null || _edgeNormals.Length != totalEdges) { _edgeNormals = new Vector2[totalEdges]; } Vector2 p2; for (var i = 0; i < totalEdges; i++) { var p1 = Points[i]; if (i + 1 >= Points.Length) { p2 = Points[0]; } else { p2 = Points[i + 1]; } var perp = Vector2Ext.Perpendicular(ref p1, ref p2); Vector2Ext.Normalize(ref perp); _edgeNormals[i] = perp; } return; }