Skip to content

DaveTheCelt/Geometry2D

Repository files navigation

Geometry 2D

A 2D geometry library supporting the following basic 2D primitive shapes:

Circles, Triangles, Infinite Lines, Line Segments, Quads, Polygons

All shapes are structs so there is little heap allocation except for Polygon type which uses a list.

Polymorphism is supported via interfaces. And intersections for each shape is also supported. Each shape also supports a variety of helpful functions.

Note: Naming convention does not follow standard C# convention. This is because I wrote a lot of this originally in HLSL and converted it to C#.

Demo

shapes.mp4

Functions supported

All geometry objects have the following functions:

  • Tangent -> Get the tangent vector nearest to the point
  • Normal -> Get the normal vector nearest to the point
  • Translate -> Move the position of the object
  • SetPosition -> Set the position of the object
  • Scale -> (Not including infinite lines)
  • Rotate -> Rotate the object
  • CalculateBounds -> Get the AABB bounds of the shape
  • OverlapsEdge -> Check if point overlaps an edge
  • SnapTo -> Snap a point to the nearest edge
  • CalculatePerimeter -> Calculate the perimeter of the line/shape
Lines have the following additional functions:
  • Lerp -> Interpolate along the line
  • InverseLerp -> Get the parameterised value from a point
  • IsBetween -> Is a point between the two end points of the line
  • Split -> Split the line into 2 lines
  • Slice -> Slice the line into multiple lines
  • Truncate -> Shorten the line
  • IsLeft -> Is a point left of the line
2DShapes have the following additional functions:
  • CalculateArea -> Calculate area of the shape
  • Overlaps -> Check if a point overlaps the shape

Releases

No releases published

Packages

No packages published

Languages