Skip to content

Commit

Permalink
Improved getArea method, now also works on (already) closed paths
Browse files Browse the repository at this point in the history
  • Loading branch information
rubendel committed Jul 17, 2019
1 parent 90f1c7f commit 49ac16c
Showing 1 changed file with 8 additions and 5 deletions.
13 changes: 8 additions & 5 deletions PluginBase/src/org/bimserver/utils/IfcTools2D.java
Original file line number Diff line number Diff line change
Expand Up @@ -464,7 +464,7 @@ public static Area findSmallest(Area area) {
return null;
}

public static float getArea(Area area) {
public static float getArea(Area area) {
float sum = 0;
PathIterator pathIterator = area.getPathIterator(null);
float[] coords = new float[6];
Expand All @@ -473,23 +473,26 @@ public static float getArea(Area area) {
while (!pathIterator.isDone()) {
int currentSegment = pathIterator.currentSegment(coords);
if (currentSegment == PathIterator.SEG_CLOSE) {

} else if (currentSegment == PathIterator.SEG_MOVETO) {
if (last != null) {
sum = sum + Math.abs(last[0] * coords[1] - last[1] * coords[0]);
}
last = new float[]{coords[0], coords[1]};
} else if (currentSegment == PathIterator.SEG_MOVETO) {
last = new float[]{coords[0], coords[1]};
if (first == null) {
first = new float[]{coords[0], coords[1]};
}
} else if (currentSegment == PathIterator.SEG_LINETO) {
if (last != null) {
sum = sum + last[0] * coords[1] - last[1] * coords[0];
sum = sum + Math.abs(last[0] * coords[1] - last[1] * coords[0]);
}

last = new float[]{coords[0], coords[1]};
}
pathIterator.next();
}
if (last != null && first != null) {
sum = sum + last[0] * first[1] - last[1] * first[0];
sum += Math.abs(last[0] * first[1] - last[1] * first[0]);
}
return sum / 2f;
}
Expand Down

0 comments on commit 49ac16c

Please sign in to comment.