Skip to content

Commit a2ded99

Browse files
committed
0.5.7
1 parent 555efff commit a2ded99

10 files changed

Lines changed: 164 additions & 4 deletions

CHANGELOG.md

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

3+
* 0.5.7
4+
5+
+ Test scene `2. Polygon permiter-Point containment (Precise)`
6+
37
* 0.5.6
48

59
+ Test scene `1. Polygon-Segment intersection`

README.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
# eppz! `Geometry`
22
> part of [**Unity.Library.eppz**](https://github.com/eppz/Unity.Library.eppz)
33
4-
**📐 2D geometry for Unity.**
4+
**📐 2D geometry for Unity.** Suited for everyday polygon hassle.
55

66
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.
77

@@ -61,7 +61,7 @@ Most of the basic 2D geometry algorithm collection is implemented in this static
6161

6262
## Segment point containment methods
6363

64-
**Points contained by a segment** (even edge or polygon circumfence) 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.
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.
6565

6666
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.
6767

41 KB
Binary file not shown.
90.3 KB
Binary file not shown.

Scenes/Controllers/Controller_2.cs

Lines changed: 58 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,58 @@
1+
//
2+
// Copyright (c) 2017 Geri Borbás http://www.twitter.com/_eppz
3+
//
4+
// Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
5+
// The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
6+
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
7+
//
8+
using UnityEngine;
9+
using System.Collections;
10+
11+
12+
namespace EPPZ.Geometry.Scenes
13+
{
14+
15+
16+
using Components;
17+
using Lines;
18+
19+
20+
/// <summary>
21+
/// 2. Polygon permiter-Point containment (precise)
22+
/// </summary>
23+
public class Controller_2 : MonoBehaviour
24+
{
25+
26+
27+
public Color defaultColor;
28+
public Color passingColor;
29+
30+
public float accuracy = 1.0f;
31+
private float _previousAccuracy;
32+
33+
public PolygonSource polygonSource;
34+
public GameObject pointSource;
35+
public PolygonLineRenderer polygonRenderer;
36+
37+
private Polygon polygon { get { return polygonSource.polygon; } }
38+
private Vector2 point { get { return pointSource.transform.position.xy(); } }
39+
40+
41+
void Update()
42+
{ RenderTestResult(PointContainmentTest()); }
43+
44+
bool PointContainmentTest()
45+
{
46+
return polygon.PermiterContainsPoint(point, accuracy, Segment.ContainmentMethod.Precise);
47+
}
48+
49+
void RenderTestResult(bool testResult)
50+
{
51+
Color color = (testResult) ? passingColor : defaultColor;
52+
53+
// Layout colors.
54+
polygonRenderer.lineColor = color;
55+
pointSource.GetComponent<Renderer>().material.color = color;
56+
}
57+
}
58+
}
4.34 KB
Binary file not shown.
4.16 KB
Binary file not shown.
19.3 KB
Loading
Lines changed: 79 additions & 0 deletions
Loading

Scenes/README.md

Lines changed: 21 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
# eppz! `Geometry`
22
> part of [**Unity.Library.eppz**](https://github.com/eppz/Unity.Library.eppz)
33
4+
45
## Test scenes
56

67
+ [Polygon-Point containment](#0-polygon-point-containment)
@@ -21,26 +22,44 @@ The star polygon drawn yellow when it contains all three points.
2122
+ When points appear to be on a polygon edge, test will return false
2223
+ When point is at a polygon vertex, test will return false
2324

24-
Usage:
2525
```C#
2626
bool test = polygon.ContainsPoint(point);
2727
```
2828
See [`Controller_0.cs`](Controllers/Controller_0,cs) for the full script context.
2929

30+
3031
## 1. Polygon-Segment intersection
3132

3233
The star polygon drawn yellow when any of the two segments intersects any polygon edge.
3334

3435
+ Returns false when a segment endpoint appears to be on a polygon edge
3536
+ Returns false when a segment endpoint is at a polygon vertex
3637

37-
Usage:
3838
```C#
3939
bool test = polygon.IsIntersectingWithSegment(segment);
4040
```
4141
See [`Controller_1.cs`](Controllers/Controller_1,cs) for the full script context.
4242

4343

44+
## 2. Polygon permiter-Point containment (Precise)
45+
46+
The star polygon drawn yellow when the point is contained by the polygon permiter. Accuracy means the line width of the polygon permiter (is `1.0f` by default).
47+
48+
+ Returns true even if the point appears to be on a polygon edge
49+
+ Returns true even if the point is at a polygon vertex
50+
51+
```C#
52+
bool test = polygon.PermiterContainsPoint(point, accuracy, Segment.ContainmentMethod.Precise);
53+
```
54+
See [`Controller_2.cs`](Controllers/Controller_2,cs) for the full script context.
55+
56+
**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 (like above).
57+
58+
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.
59+
60+
![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)
61+
62+
4463
## License
4564

4665
> Licensed under the [**MIT License**](https://en.wikipedia.org/wiki/MIT_License).

0 commit comments

Comments
 (0)