-
Notifications
You must be signed in to change notification settings - Fork 2
geoLib API
The geoLib library provides basic geometric primitives designed for cross-platform compatibility. It was created to avoid dependencies on platform-specific libraries like System.Drawing, making it suitable for headless environments and multi-platform operations.
- Cross-platform compatibility - Works on Windows, Linux, and macOS
- Integer and floating-point support - Provides both precision modes
- Lightweight design - Minimal dependencies
- Clipper2Lib integration - Uses modern polygon library data types
using geoLib;Represents a vertex in 2D space with additional geometric properties for shape definition.
public double X { get; set; } // X coordinate
public double Y { get; set; } // Y coordinate
public typeDirection direction { get; set; } // Direction type
public bool vertical { get; set; } // True if attached to vertical edge
public bool inner { get; set; } // True if inner vertex
public typeVertex type { get; set; } // Vertex type (corner or center)
public bool xBiasApplied { get; set; } // X bias tracking
public bool yBiasApplied { get; set; } // Y bias tracking// Create vertex with full properties
MyVertex(double X, double Y, typeDirection direction, bool vertical, bool inner, typeVertex type)
// Copy constructor
MyVertex(MyVertex source)// Create a corner vertex
var vertex = new MyVertex(100.0, 50.0, typeDirection.up1, false, false, typeVertex.corner);
// Copy existing vertex
var vertexCopy = new MyVertex(vertex);Represents rounding information for geometric elements.
public int index { get; set; } // Index identifier
public int verFace { get; set; } // Vertical face identifier
public int horFace { get; set; } // Horizontal face identifier
public double MaxRadius { get; set; } // Maximum radius for rounding
public typeRound direction { get; set; } // Rounding direction (inner/exterior)Array configuration with integer coordinates for geometric operations.
public Point64 point { get; set; } // Base point for the array
public Point64 pitch { get; init; } // Spacing between elements (read-only after init)
public Point64 count { get; init; } // Number of elements in each directionvar array = new GeoLibArray
{
point = new Point64(0, 0),
pitch = new Point64(100, 100), // 100 unit spacing in both directions
count = new Point64(5, 3) // 5x3 array
};Array configuration with floating-point coordinates for precise positioning.
public PointD point { get; set; } // Base point (floating-point)
public PointD pitch { get; set; } // Spacing between elements
public Point64 count { get; set; } // Number of elements in each directionvar preciseArray = new GeoLibArrayF
{
point = new PointD(0.5, 0.5),
pitch = new PointD(10.25, 15.75),
count = new Point64(4, 6)
};3D vector implementation for geometric calculations.
public double x { get; set; } // X component
public double y { get; set; } // Y component
public double z { get; set; } // Z component// Copy constructor
GeoLibVector3(GeoLibVector3 source)
// Integer coordinates
GeoLibVector3(int X, int Y, int Z)
// Floating-point coordinates
GeoLibVector3(double X, double Y, double Z)// Create vectors
var origin = new GeoLibVector3(0, 0, 0);
var point = new GeoLibVector3(10.5, 20.3, 5.0);
var copy = new GeoLibVector3(point);Matrix operations for 2D transformations.
public double[] m { get; set; } // 6-element transformation matrix [m11, m12, m21, m22, dx, dy]GeoLibMatrix(float m11, float m12, float m21, float m22, float dx, float dy)public void Rotate(double ang) // Rotate by angle in radians
public PointD transform(PointD inputPt) // Transform a point
public Point64 transform(Point64 inputPt) // Transform integer point// Create identity matrix with translation
var matrix = new GeoLibMatrix(1.0f, 0.0f, 0.0f, 1.0f, 10.0f, 20.0f);
// Rotate by 45 degrees
matrix.Rotate(Math.PI / 4);
// Transform points
var transformed = matrix.transform(new PointD(100, 100));Cross-platform rectangle implementation avoiding System.Drawing dependencies.
public Point64 Location { get; set; } // Top-left corner location
public int Width { get; set; } // Rectangle width
public int Height { get; set; } // Rectangle heightGeoLibRectangle() // Default (0,0,0,0)
GeoLibRectangle(int x, int y, int width, int height) // With dimensions// Create rectangle
var rect = new GeoLibRectangle(10, 20, 100, 50);
// Access properties
Console.WriteLine($"Area: {rect.Width * rect.Height}");
Console.WriteLine($"Top-left: ({rect.Location.X}, {rect.Location.Y})");Direction types for geometry elements.
public enum typeDirection { left1, right1, up1, down1, tilt1 }Vertex type classification.
public enum typeVertex { corner, center }Rounding types for geometric elements.
public enum typeRound { inner, exter }geoLib is designed to work seamlessly with Clipper2Lib data types:
- Uses
Point64for integer coordinates - Uses
PointDfor floating-point coordinates - Compatible with
PathDandPathsDfor polygon operations
// Convert geoLib structures to Clipper2Lib paths
var vertices = new List<MyVertex> { /* vertices */ };
var path = new PathD();
foreach (var vertex in vertices)
{
path.Add(new PointD(vertex.X, vertex.Y));
}- Use integer coordinates (
Point64) for precise manufacturing/layout applications - Use floating-point coordinates (
PointD) for graphics and approximate calculations - Consider scaling factors when converting between coordinate systems
- geoLib structures are lightweight value types where possible
- Copy constructors create deep copies to avoid reference issues
- Arrays use read-only properties after initialization to prevent accidental modification
- Most geoLib structures are immutable or provide value semantics
- Matrix operations should be performed on separate instances in multi-threaded scenarios
- No global state is maintained by the library
var vertices = new List<MyVertex>
{
new MyVertex(0, 0, typeDirection.right1, false, false, typeVertex.corner),
new MyVertex(100, 0, typeDirection.up1, true, false, typeVertex.corner),
new MyVertex(100, 50, typeDirection.left1, false, false, typeVertex.corner),
new MyVertex(0, 50, typeDirection.down1, true, false, typeVertex.corner)
};// Create regular grid
var grid = new GeoLibArray
{
point = new Point64(0, 0),
pitch = new Point64(100, 100),
count = new Point64(10, 10)
};
// Generate array positions
var positions = new List<Point64>();
for (int x = 0; x < grid.count.X; x++)
{
for (int y = 0; y < grid.count.Y; y++)
{
positions.Add(new Point64(
grid.point.X + x * grid.pitch.X,
grid.point.Y + y * grid.pitch.Y
));
}
}// Create transformation pipeline
var translate = new GeoLibMatrix(1, 0, 0, 1, 50, 100); // Translate by (50, 100)
var rotate = new GeoLibMatrix(1, 0, 0, 1, 0, 0); // Identity matrix
rotate.Rotate(Math.PI / 6); // Rotate by 30 degrees
// Apply transformations
var point = new PointD(10, 10);
point = translate.transform(point);
point = rotate.transform(point);- Clipper2Lib - For Point64 and PointD data types
- .NET 8.0 - Target framework
- geoWrangler - Advanced geometry operations using geoLib primitives
- shapeEngine - Shape generation using geoLib structures
- clipper - Polygon operations on geoLib-compatible data types