diff --git a/Source/Core/Geometry/EarClipPolygon.cs b/Source/Core/Geometry/EarClipPolygon.cs index 9dac3255..23750b9a 100755 --- a/Source/Core/Geometry/EarClipPolygon.cs +++ b/Source/Core/Geometry/EarClipPolygon.cs @@ -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 n1 = base.First; - while(firstcalculated < 2) - { - LinkedListNode 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 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