{"id":20685003,"url":"https://github.com/geri-borbas/unity.library.eppz.geometry","last_synced_at":"2025-04-09T22:18:56.233Z","repository":{"id":70887988,"uuid":"94632562","full_name":"Geri-Borbas/Unity.Library.eppz.Geometry","owner":"Geri-Borbas","description":"2D Geometry for Unity. Suited for everyday polygon hassle. Polygon clipping, polygon winding direction, polygon area, polygon centroid, centroid of multiple polygons, line intersection, point-line distance, segment intersection, polygon-point containment, polygon triangulation, polygon Voronoi diagram, polygon offset, polygon outline, polygon buffer, polygon union, polygon substraction, polygon boolean operations, and more. It is a polygon fest. ","archived":false,"fork":false,"pushed_at":"2018-01-26T04:13:02.000Z","size":4970,"stargazers_count":332,"open_issues_count":5,"forks_count":60,"subscribers_count":16,"default_branch":"master","last_synced_at":"2025-04-09T22:18:52.205Z","etag":null,"topics":["accuracy","buffering","centroid","clipper","clipping","distance-calculation","geometry","intersect","intersection","intersection-point","polygon","scene","segment","triangulation","unity","voronoi","voronoi-diagram"],"latest_commit_sha":null,"homepage":"","language":"C#","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"other","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/Geri-Borbas.png","metadata":{"files":{"readme":"README.md","changelog":"CHANGELOG.md","contributing":null,"funding":null,"license":"LICENSE.md","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null}},"created_at":"2017-06-17T15:32:31.000Z","updated_at":"2025-04-07T01:10:20.000Z","dependencies_parsed_at":"2023-05-02T11:01:32.083Z","dependency_job_id":null,"html_url":"https://github.com/Geri-Borbas/Unity.Library.eppz.Geometry","commit_stats":null,"previous_names":[],"tags_count":1,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Geri-Borbas%2FUnity.Library.eppz.Geometry","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Geri-Borbas%2FUnity.Library.eppz.Geometry/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Geri-Borbas%2FUnity.Library.eppz.Geometry/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Geri-Borbas%2FUnity.Library.eppz.Geometry/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/Geri-Borbas","download_url":"https://codeload.github.com/Geri-Borbas/Unity.Library.eppz.Geometry/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":248119284,"owners_count":21050755,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["accuracy","buffering","centroid","clipper","clipping","distance-calculation","geometry","intersect","intersection","intersection-point","polygon","scene","segment","triangulation","unity","voronoi","voronoi-diagram"],"created_at":"2024-11-16T22:25:03.959Z","updated_at":"2025-04-09T22:18:56.209Z","avatar_url":"https://github.com/Geri-Borbas.png","language":"C#","funding_links":[],"categories":[],"sub_categories":[],"readme":"# eppz! `Geometry`\n\u003e part of [**Unity.Library.eppz**](https://github.com/eppz/Unity.Library.eppz)\n\n**📐 2D geometry for Unity.** Suited for everyday polygon hassle.\n\nPolygon clipping, polygon winding direction, polygon area, polygon centroid, centroid of multiple polygons, line intersection, point-line distance, segment intersection, polygon-point containment, polygon triangulation, polygon Voronoi diagram, polygon offset, polygon outline, polygon buffer, polygon union, polygon substraction, polygon boolean operations, and more.\n\n![Unity.Library.eppz.Geometry.Model.Poygon.Mesh.Triangulation](https://github.com/eppz/Unity.Library.eppz.Geometry/raw/Documentation/Documentation/Unity.Library.eppz.Geometry.Model.Poygon.Mesh.Triangulation.gif)\n\nThe library is **being used in production**. However, it comes with the disclaimed liability and warranty of [MIT License](https://en.wikipedia.org/wiki/MIT_License).\n\n## Examples\n\nIf you prefer to read example code immediately, you can find example scenes in [`Scenes`](Scenes) folder.\n\n+ [Polygon-Point containment](Scenes/README.md/#0-polygon-point-containment)\n+ [Polygon-Segment intersection test](Scenes/README.md/#1-polygon-segment-intersection)\n+ [Polygon permiter-Point containment (Precise)](Scenes/README.md/#2-polygon-permiter-point-containment-precise)\n+ [Polygon permiter-Point containment (Default)](Scenes/README.md/#3-polygon-permiter-point-containment-default)\n+ [Polygon-Segment containment](Scenes/README.md/#4-polygon-segment-containment)\n+ [Polygon-Polygon containment](Scenes/README.md/#5-polygon-polygon-containment)\n+ [Vertex facing](Scenes/README.md/#6-vertex-facing)\n+ [Polygon area, Polygon winding](Scenes/README.md/#7-polygon-area-polygon-winding)\n+ [Segment-Segment intersection point](Scenes/README.md/#8-segment-segment-intersection-point)\n+ [Polygon offset](Scenes/README.md/#9-polygon-offset)\n+ [Multiple polygon centroid](Scenes/README.md/#10-multiple-polygon-centroid)\n+ [Polygon triangulation](Scenes/README.md/#11-polygon-triangulation)\n\n## Model classes\n\n* [`Vertex.cs`](Model/Vertex.cs)\n\t+ Basically a `Vector2` point, but is aware of the polygon context it resides (neighbours, segments, edges, polygon, bisector, normal).\n* [`Segment.cs`](Model/Segment.cs)\n\t+ Segment of two `Vector2` point. Carries out basic geometry features (point distance, point containment, segment intersection).\n* [`Edge.cs`](Model/Edge.cs)\n\t+ Edge of two `Vertex` in a polygon (a special `Segment` subclass). Likewise vertices, this model is also aware of the polygon context it resides (neighbours, segments, edges, polygon, perpendicular, normal).\n* [`Polygon.cs`](Model/Edge.cs)\n\t+ The role player, it really **embodies mostly every feature of this library**. Basically a polygon made of vertices.\n\t+ Can be created with point array, transforms, [`Source.Polygon`](Source/Polygon.cs) components. Further polygons can be embedded into recursively. Vertices, edges, polygons can be enumerated (recursively).\n\t+ Area, winding direction, centroid are being calculated. Also carries the basic geometry features (point containment, line-, segment-, polygon intersection and more).\n\t+ Using library modules, it implements polygon offset (outline), union polygon (polygon clipping), basic mesh triangulation. It implements conversion to both [Clipper](https://github.com/eppz/Clipper) and [Triangle.NET](https://github.com/eppz/Triangle.NET), so you can implement further integration with those (awesome) libraries.\n\n## [`Geometry.cs`](Geometry.cs)\n\nMost of the basic 2D geometry algorithm collection is implemented in this static base class. You can (mostly) **use them with Unity `Vector2` types directly**, so (almost entirely) without the model classes introduced above.\n\n* **Point**\n\t+ [**`ArePointsEqualWithAccuracy()`**](Geometry.cs#L24)\n\t\t+ Determine if points are equal with a given accuracy.\n\t+ [**`ArePointsCCW()`**](Geometry.cs#L30)\n\t\t+ Determine winding direction of three points.\t\t\n* **Rect / Bounds**\n\t+ [**`IsRectContainsRectSizeWithAccuracy()`**](Geometry.cs#L41)\n\t\t+ Determine if `rect2.size` fits into `rect1` (compare sizes only).\n\t+ [**`IsRectContainsRectWithAccuracy()`**](Geometry.cs#L56)\n\t\t+ Determine if `rect2` is contained by `rect1` (even if permiters are touching) with a given accuracy.\n* **Line**\n\t+ [**`IntersectionPointOfLines()`**](Geometry.cs#L78)\n\t\t+ Returns intersection point of two lines (defined by segment endpoints). Returns zero, when segments have common points, or when a segment point lies on other.\n\t+ [**`PointDistanceFromLine()`**](Geometry.cs#L97)\n\t\t+ Determine point distance from line (defined by segment endpoints).\n* **Segment**\n\t+ [**`PointIsLeftOfSegment()`**](Geometry.cs#L109)\n\t\t+ Determine if a given point lies on the left side of a segment (line beneath).\n\t+ [**`AreSegmentsEqualWithAccuracy()`**](Geometry.cs#L116)\n\t\t+ Determine if segments (defined by endpoints) are equal with a given accuracy.\n\t+ [**`HaveSegmentsCommonPointsWithAccuracy()`**](Geometry.cs#L125)\n\t\t+ Determine if segments (defined by endpoints) have common points with a given accuracy.\n\t+ [**`AreSegmentsIntersecting()`**](Geometry.cs#L141)\n\t\t+ Determine if two segments defined by endpoints are intersecting (defined by points). True when the two segments are intersecting. Not true when endpoints are equal, nor when a point is contained by other segment. Credits to [Bryce Boe](https://github.com/bboe) (@bboe) for his writeup [Line Segment Intersection Algorithm](http://bryceboe.com/2006/10/23/line-segment-intersection-algorithm).\n* **Polygon** (using `EPPZ.Geometry.Polygon`)\n\t+ [**`IsPolygonContainsPoint()`**](Geometry.cs#L159)\n\t\t+ Test if a polygon contains the given point (checks for sub-polygons recursive). Uses the same Bryce boe algorithm above, so considerations are the same. See [Point in polygon](https://en.wikipedia.org/wiki/Point_in_polygon#Ray_casting_algorithm) for more.\n\t+ [**`CentroidOfPolygons()`**](Geometry.cs#L177)\n\t\t+ Returns the compound centroid of multiple polygon using [Geometric decomposition](https://en.wikipedia.org/wiki/Centroid#By_geometric_decomposition).\n\n## Modules\n\nFor clipping, offsetting, triangulating the library use these brilliant third party `C#` libraries below.\n\n* [Clipper](https://github.com/eppz/Clipper)\n\n\t+ Polygon and line clipping and offsetting library (C++, C#, Delphi) by Angus Johnson. See standalone project repository [Clipper](https://github.com/eppz/Clipper) for details.\n\n* [Triangle.NET](https://github.com/eppz/Triangle.NET)\n\n\t+ Triangle.NET generates 2D (constrained) Delaunay triangulations and high-quality meshes of point sets or planar straight line graphs. It is a C# port by Christian Woltering of Jonathan Shewchuk's Triangle software. See standalone project repository [Triangle.NET](https://github.com/eppz/Triangle.NET) for details.\n\n## Naming\n\nThe library uses namespaces heavily. I like to **name things as they are**. An edge in this library called `Edge`, a polygon is called `Polygon`. If it is a polygon model, it resides the `Model` namespace (`EPPZ.Geometry.Model` actually). Whether it is a source component for polygon, it resides in the `Source` namespace. It becomes nicely readable, as you declare polygons like `Model.Polygon`, or reference polygon sources as `Source.Polygon`.\n\n\u003e In addition, every class is **namespaced in the folder** it resides. If you look at a folder name, you can tell that classes are namespaced to the same as the folder name.\n\n## Add-ons\n\n* [`ClipperAddOns`](AddOns/ClipperAddOns.cs)\n\n\t+ Mainly `Polygon` extensions for easy conversion between **eppz! Geometry** and [Clipper](https://github.com/eppz/Clipper). It has a method to convert from generic `Vector2[]` array. **[Clipper](https://github.com/eppz/Clipper) works with integers**. So conversion involves a scale up (and a scale down), thus you'll need to pass a scale value to Clipper. (for example **eppz! Geometry** internals use `10e+5f` by default).\n\t\t+ `Polygon PolygonFromClipperPaths(Paths paths, float scale)`\n\t\t+ `Polygon PolygonFromClipperPath(Path path, float scale)`\n\t\t+ `Paths ClipperPaths(this Polygon this_, float scale)`\n\t\t+ `Path ClipperPath(this Polygon this_, float scale)`\n\t\t+ `Vector2[] PointsFromClipperPath(Path path, float scale)`\n\n* [`TriangleNetAddOns`](AddOns/TriangleNetAddOns.cs)\t\t\n\n\t+ Bridges the gap between library `Model.Polygon` objects and `Triangle.NET` models (meshes, voronoi diagrams).\n\t\t+ `TriangleNet.Geometry.Polygon TriangleNetPolygon(this Polygon this_)`\n\t\t+ `Rect Bounds(this TriangleNet.Voronoi.Legacy.SimpleVoronoi this_)`\n\t\t+ `Paths ClipperPathsFromVoronoiRegions(List\u003cTriangleNet.Voronoi.Legacy.VoronoiRegion\u003e voronoiRegions, float scale = 1.0f)`\n\t\t+ `Vector2 VectorFromPoint(TriangleNet.Geometry.Point point)`\n\t\t+ `Vector2[] PointsFromVertices(ICollection\u003cTriangleNet.Geometry.Point\u003e vertices)`\n\n* [`UnityEngineAddOns`](AddOns/UnityEngineAddOns.cs)\n\n\t+ Contains a single `Model.Polygon` (yet enormously useful) extension that triangulates the corresponding polygon, and hooks up the result into a `UnityEngine.MeshFilter` component. This is the core functionality embedded into `Source.Mesh` component (see example scene [Polygon triangulation](Scenes/README.md/#11-polygon-triangulation) for more).\n\t\t+ `UnityEngine.Mesh Mesh(this EPPZ.Geometry.Model.Polygon this_, string name = \"\")`\n\t\t+ `UnityEngine.Mesh Mesh(this EPPZ.Geometry.Model.Polygon this_, TriangulatorType triangulator, string name = \"\")`\n\t\t+ `UnityEngine.Mesh Mesh(this EPPZ.Geometry.Model.Polygon this_, Color color, TriangulatorType triangulator, string name = \"\")`\n\n## License\n\n\u003e Licensed under the [**MIT License**](https://en.wikipedia.org/wiki/MIT_License).\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fgeri-borbas%2Funity.library.eppz.geometry","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fgeri-borbas%2Funity.library.eppz.geometry","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fgeri-borbas%2Funity.library.eppz.geometry/lists"}