Skip to content

Commit 06447eb

Browse files
committed
0.5.8
1 parent a2ded99 commit 06447eb

13 files changed

Lines changed: 181 additions & 13 deletions

CHANGELOG.md

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,14 @@
11
# eppz! `Geometry`
22

3+
* 0.5.8
4+
5+
+ Test scenes
6+
+ `3. Polygon permiter-Point containment (Default)`
7+
+ `4. Polygon-Segment containment`
8+
+ Polygon / segment sources use world position (!) instead local
9+
+ Line renderers use world positions as well (both segment and polygon)
10+
+ Polygon and segment sources can be updated on `LateUpdate()`
11+
312
* 0.5.7
413

514
+ Test scene `2. Polygon permiter-Point containment (Precise)`

Lines/GeometryLineRenderer.cs

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,19 @@ protected void DrawSegment(Segment segment, Color color)
2727
protected void DrawPolygon(Polygon polygon, Color color)
2828
{ polygon.EnumerateEdgesRecursive((Edge eachEdge) => DrawLine(eachEdge.a, eachEdge.b, color)); }
2929

30+
protected void DrawPolygon(Polygon polygon, Color color, bool drawNormals)
31+
{
32+
polygon.EnumerateEdgesRecursive((Edge eachEdge) =>
33+
{
34+
DrawLine(eachEdge.a, eachEdge.b, color);
35+
if (drawNormals)
36+
{
37+
Vector2 halfie = eachEdge.a + ((eachEdge.b - eachEdge.a) / 2.0f);
38+
DrawLine(halfie, halfie + eachEdge.normal * 0.1f, color);
39+
}
40+
});
41+
}
42+
3043
protected void DrawPolygonWithTransform(Polygon polygon, Color color, Transform transform_)
3144
{ DrawPolygonWithTransform(polygon, color, transform_, false); }
3245

Lines/PolygonLineRenderer.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -73,7 +73,7 @@ protected override void OnDraw()
7373
if (polygon == null) return; // Only having polygon
7474

7575
DrawRect(polygon.bounds, boundsColor);
76-
DrawPolygonWithTransform(polygon, lineColor, transform, normals);
76+
DrawPolygon(polygon, lineColor, normals);
7777
}
7878
}
7979
}

Model/Polygon.cs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -107,14 +107,14 @@ public static Polygon PolygonWithPolygon(Polygon polygon)
107107
return rootPolygon;
108108
}
109109

110-
public static Polygon PolygonWithPointTransforms(Transform[] pointTransforms) // Uses Transform.localPosition.xy()
110+
public static Polygon PolygonWithPointTransforms(Transform[] pointTransforms)
111111
{
112112
// Create points array.
113113
Vector2[] points = new Vector2[pointTransforms.Length];
114114
for (int index = 0; index < pointTransforms.Length; index++)
115115
{
116116
Transform eachPointTransform = pointTransforms[index];
117-
points[index] = eachPointTransform.localPosition.xy();
117+
points[index] = eachPointTransform.position.xy();
118118
}
119119

120120
return Polygon.PolygonWithPoints(points);
@@ -168,7 +168,7 @@ public void UpdatePointPositionsWithTransforms(Transform[] pointTransforms) // A
168168
for (int index = 0; index < pointTransforms.Length; index++)
169169
{
170170
Transform eachPointTransform = pointTransforms[index];
171-
_points[index] = eachPointTransform.localPosition.xy();
171+
_points[index] = eachPointTransform.position.xy();
172172
}
173173

174174
// Polygon calculations.

README.md

Lines changed: 1 addition & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -56,17 +56,9 @@ Most of the basic 2D geometry algorithm collection is implemented in this static
5656
* **Polygon** (using `EPPZ.Geometry.Polygon`)
5757
+ `bool IsPolygonContainsPoint(Polygon polygon, Vector2 point)`
5858
+ 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.
59-
+ `Vector2 CentroidOfPolygons(Polygon[] polygons, Polygon.WindingDirection windingDirection = Polygon.WindingDirection.Unknown)`
59+
+ `Vector2 CentroidOfPolygons(Polygon[] polygons)`
6060
+ Returns the compound centroid of multiple polygon using [Geometric decomposition](https://en.wikipedia.org/wiki/Centroid#By_geometric_decomposition).
6161

62-
## Segment point containment methods
63-
64-
**Points contained by a segment** (even edge or polygon permiter) should be calculated with a given **accuracy**. This accuracy is set to `1e-6f` by default, but **can be set to any value** per each containment test. For example, you may want to set accuracy to 1f, if testing containment to a 1 pixel width segment.
65-
66-
Point containment tests has two **containment method**, `ContainmentMethod.Default` and `ContainmentMethod.Precise`. The former is less computation intensive than the latter. Depending on your ue case, you may trade precision over performance. The figure below summarizes the dissimilarities of the two method.
67-
68-
![Unity.Library.eppz.Geometry.Segment.ContainsPoint.ContainmentMethod](https://github.com/eppz/Unity.Library.eppz.Geometry/raw/Documentation/Documentation/Unity.Library.eppz.Geometry.Segment.ContainsPoint.ContainmentMethod.png)
69-
7062
## Modules
7163

7264
For clipping, offsetting, triangulating the library use these brilliant third party `C#` libraries below.
-64 Bytes
Binary file not shown.
0 Bytes
Binary file not shown.
0 Bytes
Binary file not shown.
49.5 KB
Binary file not shown.
42.1 KB
Binary file not shown.

0 commit comments

Comments
 (0)