From e3d62fccc38e9eec106f3aca725b13987396d310 Mon Sep 17 00:00:00 2001 From: alestiago Date: Fri, 11 Mar 2022 09:54:29 +0000 Subject: [PATCH] refactor: moved centroid function --- lib/game/components/sling_shot.dart | 20 ++++++++++---------- 1 file changed, 10 insertions(+), 10 deletions(-) diff --git a/lib/game/components/sling_shot.dart b/lib/game/components/sling_shot.dart index 3d1f5839..f59e7c0d 100644 --- a/lib/game/components/sling_shot.dart +++ b/lib/game/components/sling_shot.dart @@ -53,16 +53,6 @@ class SlingShot extends BodyComponent { return fixtures; } - /// https://en.wikipedia.org/wiki/Centroid - // TODO(alestiago): use from geometry package. - static Vector2 centroid(List vertices) { - final centroid = Vector2.zero(); - for (final vertex in vertices) { - centroid.add(vertex); - } - return centroid / vertices.length.toDouble(); - } - @override Body createBody() { final bodyDef = BodyDef()..position = _position; @@ -72,3 +62,13 @@ class SlingShot extends BodyComponent { return body; } } + +/// For more information: https://en.wikipedia.org/wiki/Centroid +// TODO(alestiago): move to geometry package. +Vector2 centroid(List vertices) { + final centroid = Vector2.zero(); + for (final vertex in vertices) { + centroid.add(vertex); + } + return centroid / vertices.length.toDouble(); +}