Fixed: CalculateArea was doing some weird shit (resolves #372)

This commit is contained in:
ZZYZX 2020-01-18 22:08:48 +02:00
parent 6e4a02fb2b
commit 973a4b1447

View file

@ -73,22 +73,21 @@ namespace CodeImp.DoomBuilder.Geometry
// This calculates the area // This calculates the area
public float CalculateArea() public float CalculateArea()
{ {
// Multiply the x coordinate of each vertex by the y coordinate of the next vertex. float area = 0;
// Multiply the y coordinate of each vertex by the x coordinate of the next vertex. LinkedListNode<EarClipVertex> v = First;
// Subtract these. do
float result = 0.0f; {
int firstcalculated = 0;
LinkedListNode<EarClipVertex> n1 = base.First; EarClipVertex v1 = v.Value;
while(firstcalculated < 2) EarClipVertex v2 = (v.Next != null) ? v.Next.Value : First.Value;
{
LinkedListNode<EarClipVertex> n2 = n1.Next ?? base.First; area += (v2.Position.x + v1.Position.x) * (v2.Position.y - v1.Position.y);
float a = n1.Value.Position.x * n2.Value.Position.y;
float b = n1.Value.Position.y * n2.Value.Position.x; v = v.Next;
result += a - b;
n1 = n2; }
if(n2 == base.First) firstcalculated++; while (v != null);
} return Math.Abs(area * 0.5f);
return Math.Abs(result / 2.0f);
} }
// This creates a bounding box from the outer polygon // This creates a bounding box from the outer polygon