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