ZGeometry 0.2.2
dotnet add package ZGeometry --version 0.2.2
NuGet\Install-Package ZGeometry -Version 0.2.2
<PackageReference Include="ZGeometry" Version="0.2.2" />
<PackageVersion Include="ZGeometry" Version="0.2.2" />
<PackageReference Include="ZGeometry" />
paket add ZGeometry --version 0.2.2
#r "nuget: ZGeometry, 0.2.2"
#:package ZGeometry@0.2.2
#addin nuget:?package=ZGeometry&version=0.2.2
#tool nuget:?package=ZGeometry&version=0.2.2
ZGeometry
A small, generic 2D geometry library for .NET. It provides a numeric vector type and a handful of 2D primitives (circle, rectangle, triangle, line, point) with a fluent API for the common spatial queries: overlaps, contains, and intersects.
Everything is generic over the numeric type (float, double, int, long, decimal, byte)
via System.Numerics.INumber<T>, so you can pick the precision you need.
⚠️ Disclaimer: This is a small hobby library. It's handy for games, prototypes, and learning, but it is not a comprehensive or heavily optimised computational-geometry package. Expect a limited primitive set and possible breaking changes between versions.
Features
Vector2D<T>— a generic 2D vector with arithmetic operators and helpers:Magnitude,Normalize,DotProduct,CrossProduct,Perpendicular,Lerp,Reflect,Clamp, polar/cartesian conversion, and more.- Primitives —
Circle<T>,Rectangle<T>,Triangle<T>,Line<T>, each withCreate(...)factories. - Fluent spatial queries —
Overlaps,Contains, andIntersectsextension methods across primitive pairs. - Tuple sugar —
(T, T)implicitly converts toVector2D<T>, so call sites stay terse.
Installation
dotnet add package ZGeometry
Getting started
Vectors
using ZGeometry.Primitives.Point;
var a = Vector2D<float>.Create(3, 4);
var b = new Vector2D<float>(1, 2);
var sum = a + b; // (4, 6)
var scaled = a * 2f; // (6, 8)
var length = a.Magnitude(); // 5
var unit = a.Normalize();
var dot = a.DotProduct(b);
Primitives
Each primitive has a Create factory. The numeric type is inferred from the arguments, and (x, y)
tuples convert to vectors automatically.
using ZGeometry.Primitives.Circle;
using ZGeometry.Primitives.Rectangle;
using ZGeometry.Primitives.Line;
using ZGeometry.Primitives.Triangle;
var circle = Circle<float>.Create((100, 100), 40);
var rectangle = Rectangle<float>.Create((10, 10), (200, 120)); // position, size
var line = Line<float>.Create((0, 0), (300, 300));
var triangle = Triangle<float>.Create((0, 0), (100, 0), (50, 80));
Spatial queries
The fluent extension methods read naturally. Overlaps and Contains return bool; Intersects
returns the boundary intersection points.
using ZGeometry.Logic;
bool touching = circle.Overlaps(rectangle);
bool inside = circle.Contains(line);
var crossings = circle.Intersects(line); // IEnumerable<Vector2D<float>>
Namespaces at a glance
| Namespace | What's in it |
|---|---|
ZGeometry.Primitives.Point |
Vector2D<T> |
ZGeometry.Primitives.Circle |
Circle<T> and its Create factory |
ZGeometry.Primitives.Rectangle |
Rectangle<T> and its Create factory |
ZGeometry.Primitives.Triangle |
Triangle<T> and its Create factory |
ZGeometry.Primitives.Line |
Line<T> and its Create factory |
ZGeometry.Logic |
Overlaps, Contains, Intersects fluent queries |
License
| Product | Versions Compatible and additional computed target framework versions. |
|---|---|
| .NET | net8.0 is compatible. net8.0-android was computed. net8.0-browser was computed. net8.0-ios was computed. net8.0-maccatalyst was computed. net8.0-macos was computed. net8.0-tvos was computed. net8.0-windows was computed. net9.0 was computed. net9.0-android was computed. net9.0-browser was computed. net9.0-ios was computed. net9.0-maccatalyst was computed. net9.0-macos was computed. net9.0-tvos was computed. net9.0-windows was computed. net10.0 was computed. net10.0-android was computed. net10.0-browser was computed. net10.0-ios was computed. net10.0-maccatalyst was computed. net10.0-macos was computed. net10.0-tvos was computed. net10.0-windows was computed. |
-
net8.0
- No dependencies.
NuGet packages (1)
Showing the top 1 NuGet packages that depend on ZGeometry:
| Package | Downloads |
|---|---|
|
SimpleHMEngine
A small, hobby 2D game engine built on SFML.Net: game loop, scene/component tree, input binding, camera, simple collision, an immediate-mode drawing helper, and a lightweight UI toolkit. Great for prototypes, game jams and learning — not a production engine. |
GitHub repositories
This package is not used by any popular GitHub repositories.
0.2.2: Circle intersection correctness fixes. The segment-versus-circle intersection now computes crossings from the true perpendicular foot instead of clamping to the segment first, so the points no longer drift off the circle near segment ends, and it keeps crossings by their segment parameter instead of re-testing collinearity with a tolerance that was discarding valid float-rounded points. Triangle-versus-circle and rectangle-versus-circle intersections no longer report interior vertices or corners as intersection points (a vertex inside the circle is containment, not a boundary crossing). Triangle-versus-circle overlap is now decided independently, from the centre-inside test plus per-edge distance, so it stays correct without depending on the intersection-point set.