I have a room object defined by a collection of looping line segments that I need to calculate the area for. The classes can be described as follows (in pseudo-code):
class Point {
float x;
float y;
...
float distanceFrom(Point p);
}
class Segment {
Point start;
Point end;
...
float length();
}
class Room {
List<Segment> walls;
...
float area();
}
The walls of a room can never intersect anywhere but at the endpoints of the segments and any "sub-loops" created will also be separated into a new room. The solution does not need to be perfectly accurate (10% margin of error is acceptable) and is also not computed very often (<1/s).
Room
to contain a list ofPoint
s, and then get the segments by connecting each point together and then loop it back around. Otherwise, with your current setup, it's very east to get incorrect values (e.g. unclosed room, room with wall in middle, etc.). This would be the best option. \$\endgroup\$Room
s to always be complete, and that may not be the case if I have the player build theRoom
s usingSegment
s. Also, a closed-room function is easy to define (just loop through theSegment
s and make sure they create a room). \$\endgroup\$