Skip to content

Polygon Area calculation returns negative #166

@alvpickmans

Description

@alvpickmans

Describe the bug
When polygon's vertices are defined clockwise, the area calculation returns negative value.

To Reproduce

using Elements.Geometry;
using NUnit.Framework;
using System.Linq;

namespace Tests
{
    public class Tests
    {

        [Test]
        public void PolygonAreaTest()
        {
            double side = 20;
            Vector3[] vertices = new Vector3[4]
            {
                new Vector3(0,0,0),
                new Vector3(side, 0, 0),
                new Vector3(side, side, 0),
                new Vector3(0, side, 0)
            };

            Polygon ccw = new Polygon(vertices);
            Polygon cw = new Polygon(vertices.Reverse().ToArray());

            double expected = side * side;

            // This passes
            Assert.AreEqual(expected, ccw.Area());

            // This fails
            Assert.AreEqual(expected, cw.Area());
            Assert.IsTrue(ccw.Area() == cw.Area());
        }
    }
}

Metadata

Metadata

Assignees

Labels

Type

No type

Projects

No projects

Relationships

None yet

Development

No branches or pull requests

Issue actions