computeAabb method
Computes the aabb from the vertices of all the polygons.
Implementation
@override
@protected
void computeAabb(Aabb2 aabb) {
final polygons = globalPolygons();
if (polygons.isEmpty) {
super.computeAabb(aabb);
return;
}
final first = polygons.first.first;
var minX = first.x;
var minY = first.y;
var maxX = first.x;
var maxY = first.y;
for (final vertices in polygons) {
for (final v in vertices) {
if (v.x < minX) {
minX = v.x;
}
if (v.y < minY) {
minY = v.y;
}
if (v.x > maxX) {
maxX = v.x;
}
if (v.y > maxY) {
maxY = v.y;
}
}
}
// Add a small epsilon since points on the AABB edge are counted as outside.
const epsilon = 0.000000000000001;
aabb.min.setValues(minX - epsilon, minY - epsilon);
aabb.max.setValues(maxX + epsilon, maxY + epsilon);
}