Skip to content

Commit 555efff

Browse files
committed
0.5.6
1 parent 00223ac commit 555efff

File tree

5 files changed

+88
-4
lines changed

5 files changed

+88
-4
lines changed

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.6
4+
5+
+ Test scene `1. Polygon-Segment intersection`
6+
37
* 0.5.5
48

59
+ Only calculated winding direction
53.5 KB
Binary file not shown.

Scenes/Controllers/Controller_0.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ namespace EPPZ.Geometry.Scenes
1818

1919

2020
/// <summary>
21-
/// 0. Polygon-point containment
21+
/// 0. Polygon-Point containment
2222
/// </summary>
2323
public class Controller_0 : MonoBehaviour
2424
{

Scenes/Controllers/Controller_1.cs

Lines changed: 63 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,63 @@
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+
/// 1. Polygon-Segment intersection
22+
/// </summary>
23+
public class Controller_1 : MonoBehaviour
24+
{
25+
26+
27+
public Color defaultColor;
28+
public Color passingColor;
29+
30+
public PolygonSource polygonSource;
31+
public SegmentSource segmentSourceA;
32+
public SegmentSource segmentSourceB;
33+
public PolygonLineRenderer polygonRenderer;
34+
public SegmentLineRenderer segmentRendererA;
35+
public SegmentLineRenderer segmentRendererB;
36+
37+
private Polygon polygon { get { return polygonSource.polygon; } }
38+
private Segment segment_a { get { return segmentSourceA.segment; } }
39+
private Segment segment_b { get { return segmentSourceB.segment; } }
40+
41+
42+
void Update()
43+
{ RenderTestResult(SegmentIntersectingTest()); }
44+
45+
bool SegmentIntersectingTest()
46+
{
47+
return (
48+
polygon.IsIntersectingWithSegment(segment_a) ||
49+
polygon.IsIntersectingWithSegment(segment_b)
50+
);
51+
}
52+
53+
void RenderTestResult(bool testResult)
54+
{
55+
Color color = (testResult) ? passingColor : defaultColor;
56+
57+
// Layout colors.
58+
polygonRenderer.lineColor = color;
59+
segmentRendererA.lineColor = color;
60+
segmentRendererB.lineColor = color;
61+
}
62+
}
63+
}

Scenes/README.md

Lines changed: 20 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,11 @@
1-
# eppz! <sub>Geometry</sub>
1+
# eppz! `Geometry`
22
> part of [**Unity.Library.eppz**](https://github.com/eppz/Unity.Library.eppz)
33
44
## Test scenes
55

6+
+ [Polygon-Point containment](#0-polygon-point-containment)
7+
+ [Polygon-Segment intersection test](#1-polygon-segment-intersection)
8+
69
These test scenes are designed to experience / proof the **eppz! Geometry** library features. Hit play, then manipulate the geometry in Scene window while in game mode (watch out to move the points directly instead their parent container). Every relevant code is in the corresponding `Controller_#.cs`, so you can see **how to use the API**.
710

811
You can define a polygon with simple `Vector2[]` array, but for sake of simplicity, test scenes uses some **polygon sourcing helper classes** ([`Components.PolygonSource`](../Components/PolygonSource.cs)) those take simple `GameObject` transforms as input. They also keep the polygon models updated on `GameObject` changes.
@@ -11,7 +14,7 @@ Another helper objects are **polygon line renderers** ([`Lines.PolygonLineRender
1114

1215
Beside these helper classes, you can easily construct `Polygon` / `Segment` instances using simple `Vector2` inputs as well. Having these test scenes, you can easily provision the mechanism of each geometry feature even with your own polygons.
1316

14-
## 0. Polygon-point containment
17+
## 0. Polygon-Point containment
1518

1619
The star polygon drawn yellow when it contains all three points.
1720

@@ -22,7 +25,21 @@ Usage:
2225
```C#
2326
bool test = polygon.ContainsPoint(point);
2427
```
25-
See [`Controller_0.cs`](Controllers/Controller_0,cs) for the full context.
28+
See [`Controller_0.cs`](Controllers/Controller_0,cs) for the full script context.
29+
30+
## 1. Polygon-Segment intersection
31+
32+
The star polygon drawn yellow when any of the two segments intersects any polygon edge.
33+
34+
+ Returns false when a segment endpoint appears to be on a polygon edge
35+
+ Returns false when a segment endpoint is at a polygon vertex
36+
37+
Usage:
38+
```C#
39+
bool test = polygon.IsIntersectingWithSegment(segment);
40+
```
41+
See [`Controller_1.cs`](Controllers/Controller_1,cs) for the full script context.
42+
2643

2744
## License
2845

0 commit comments

Comments
 (0)