feat: simplified centroid

pull/38/head
alestiago 4 years ago
parent 78ce5face4
commit af626b927c

@ -110,15 +110,7 @@ num factorial(num n) {
/// ///
/// For more information read: https://en.wikipedia.org/wiki/Centroid /// For more information read: https://en.wikipedia.org/wiki/Centroid
Vector2 centroid(List<Vector2> vertices) { Vector2 centroid(List<Vector2> vertices) {
assert( assert(vertices.isNotEmpty, 'Vertices must not be empty');
vertices.isNotEmpty, final sum = vertices.reduce((a, b) => a + b);
'At least one vertex needed to calculate the centroid', return sum / vertices.length.toDouble();
);
final centroid = Vector2.zero();
for (final vertex in vertices) {
centroid.add(vertex);
}
return centroid / vertices.length.toDouble();
} }

Loading…
Cancel
Save