Wiki

Clone wiki

Geometry Class Library / Overview

This library exists to provide a better abstraction for representing real world objects in software.

Most geometry libraries have classes that look like this:

#!c#

    class Point
    {
        double x;

        double y;
    }

    class Line
    {
        Point start;
        Point end;

        public double Length()
        {
            return DistanceFormula(start, end);
        }

        public Point MidPoint()
        {
            return MidPointFormula(start, end);
        }
    }
You may notice above that the Point Class only handles two dimensions and that x and y are both of type double.

This type of implementation appears to have two advantages: Easier implementation, and a low learning curve. Everyone who has programmed in C# even a little bit have worked with doubles and understand how they work.

However the disadvantages of this implementation become evident when attempting to use this framework in a real world setting. What does the variable x stand for: number of inches in the x direction? meters? It isn't clear from the code what the person using it will assign the default unit type to be. For some applications this is probably preferable. A lot video games and things don't care what the actual distance is and dealing with just a number is simpler. But when dealing with numbers that come from measuring devices or that need to be used in the physical world, there needs to be a better way to deal with variables that represent units. This becomes an even more interesting challenge when you start considering ideas such as rotation or translation when rounding errors can occur. Even if doubles are the type of x and y, 10.00001 == 10.00002 still equates to false without additional logic. Attempting to write a generic geometry library that can handle different scales and precisions is no small task.

To solve all of the above limitations, this library is built on the Unit Class Library. The Unit Class Library provides classes that represent Distances, Angles, Areas, Etc. It also handles all of the conversions between units and comparisons, and provides intelligent tools for equality comparisions that can meet the needs of any application.

So the classes contained within the Geometry Class Library take a similar form to this:

#!c#

    public class Point
    {

        public Distance X;
        public Distance Y;
        public Distance Z;

    }

    class LineSegment
    {
        Point StartPoint;
        Point EndPoint;

        Distance Length
        {
            //distance formula etc..
        }
    }

    class Polygon
    {
        List<LineSegment> Edges

        Area Area
        {
             ///Area calculation code
        }
    }

    class Polyhedron
    {
        List<Polygon> Faces
        {
        }
    }

With the above implementation, there is no "Default" unit that has to be used to describe the geometry's points and at any level of the hierarchy you can modify and visualize properties intuitively. The ability to extrude a polygon 3 inches in one line of code and then lengthen a line by 5 meters in the next is the kind of flexibility we want you to have while using this API. We also want you to know that if you do find a crazy use case that does match the previous sentence, you don't have to worry about how to compare those two distances.

There are several different Geometry libraries that exist in the world and this is just one. Our goal with this project is to make it the most intuitive to use without sacrificing power and accuracy.

Updated