Skip to content

Commit a490b26

Browse files
committed
0.8.0
1 parent a644673 commit a490b26

12 files changed

Lines changed: 303 additions & 37 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.8.0
4+
5+
+ Test scenes
6+
`8. Segment-Segment intersection point`
7+
`9. Polygon offset`
8+
`10. Multiple polygon centroid`
9+
+ `ExtendedPolygonLineRenderer`
10+
+ Winding and area hooks moved down here
11+
312
* 0.7.0
413

514
+ Test scenes
Lines changed: 67 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,67 @@
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+
#if EPPZ_LINES
9+
using UnityEngine;
10+
using System.Collections;
11+
12+
13+
namespace EPPZ.Geometry.Lines
14+
{
15+
16+
17+
using EPPZ.Lines;
18+
using Components;
19+
20+
21+
public class ExtendedPolygonLineRenderer : PolygonLineRenderer
22+
{
23+
24+
25+
public GameObject windingObject;
26+
public TextMesh areaTextMesh;
27+
28+
private float _previousArea;
29+
private Polygon.Winding _previousWindingDirection;
30+
31+
32+
void Start()
33+
{
34+
// Model reference.
35+
PolygonSource polygonSource = GetComponent<PolygonSource>();
36+
if (polygonSource != null)
37+
{ polygon = polygonSource.polygon; }
38+
}
39+
40+
void Update()
41+
{
42+
if (polygon == null) return; // Only having polygon
43+
44+
// Layout winding direction object if any.
45+
bool hasWindingDirectionObject = (windingObject != null);
46+
bool windingChanged = (polygon.winding != _previousWindingDirection);
47+
if (hasWindingDirectionObject && windingChanged)
48+
{
49+
windingObject.transform.localScale = (polygon.isCW) ? Vector3.one : new Vector3 (1.0f, -1.0f, 1.0f);
50+
windingObject.transform.rotation = (polygon.isCW) ? Quaternion.identity : Quaternion.Euler( new Vector3 (0.0f, 0.0f, 90.0f) );
51+
}
52+
53+
// Layout area text mesh if any.
54+
bool hasAreaTextMesh = (areaTextMesh != null);
55+
bool areaChanged = (polygon.area != _previousArea);
56+
if (hasAreaTextMesh && areaChanged)
57+
{
58+
areaTextMesh.text = polygon.area.ToString();
59+
}
60+
61+
// Track.
62+
_previousWindingDirection = polygon.winding;
63+
_previousArea = polygon.area;
64+
}
65+
}
66+
}
67+
#endif

Lines/PolygonLineRenderer.cs

Lines changed: 3 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -24,48 +24,17 @@ public class PolygonLineRenderer : GeometryLineRenderer
2424

2525
public Color lineColor;
2626
public Color boundsColor;
27-
public GameObject windingObject;
28-
public TextMesh areaTextMesh;
2927
public bool normals = false;
3028

31-
private float _previousArea;
32-
private Polygon.Winding _previousWindingDirection;
33-
3429
public Polygon polygon;
3530

3631

3732
void Start()
3833
{
3934
// Model reference.
40-
PolygonSource polygonSource_ = GetComponent<PolygonSource>();
41-
if (polygonSource_ != null)
42-
{ polygon = polygonSource_.polygon; }
43-
}
44-
45-
void Update()
46-
{
47-
if (polygon == null) return; // Only having polygon
48-
49-
// Layout winding direction object if any.
50-
bool hasWindingDirectionObject = (windingObject != null);
51-
bool windingChanged = (polygon.winding != _previousWindingDirection);
52-
if (hasWindingDirectionObject && windingChanged)
53-
{
54-
windingObject.transform.localScale = (polygon.isCW) ? Vector3.one : new Vector3 (1.0f, -1.0f, 1.0f);
55-
windingObject.transform.rotation = (polygon.isCW) ? Quaternion.identity : Quaternion.Euler( new Vector3 (0.0f, 0.0f, 90.0f) );
56-
}
57-
58-
// Layout area text mesh if any.
59-
bool hasAreaTextMesh = (areaTextMesh != null);
60-
bool areaChanged = (polygon.area != _previousArea);
61-
if (hasAreaTextMesh && areaChanged)
62-
{
63-
areaTextMesh.text = polygon.area.ToString();
64-
}
65-
66-
// Track.
67-
_previousWindingDirection = polygon.winding;
68-
_previousArea = polygon.area;
35+
PolygonSource polygonSource = GetComponent<PolygonSource>();
36+
if (polygonSource != null)
37+
{ polygon = polygonSource.polygon; }
6938
}
7039

7140
protected override void OnDraw()

README.md

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
44
**📐 2D geometry for Unity.** Suited for everyday polygon hassle.
55

6-
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.
6+
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.
77

88
The 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).
99

@@ -19,6 +19,9 @@ If you prefer to read example code immediately, you can find example scenes in [
1919
+ [Polygon-Polygon containment](Scenes/README.md/#5-polygon-polygon-containment)
2020
+ [Vertex facing](Scenes/README.md/#6-vertex-facing)
2121
+ [Polygon area, Polygon winding](Scenes/README.md/#7-polygon-area-polygon-winding)
22+
+ [Segment-Segment intersection point](Scenes/README.md/#8-segment-segment-intersection-point)
23+
+ [Polygon offset](Scenes/README.md/#9-polygon-offset)
24+
+ [Multiple polygon centroid](Scenes/README.md/#10-multiple-polygon-centroid)
2225

2326
## Model classes
2427

39.6 KB
Binary file not shown.
0 Bytes
Binary file not shown.
35.1 KB
Binary file not shown.

Scenes/9. Polygon offset.unity

41.2 KB
Binary file not shown.
Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,42 @@
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.Generic;
10+
11+
12+
namespace EPPZ.Geometry.Scenes
13+
{
14+
15+
16+
using Components;
17+
using Lines;
18+
19+
20+
/// <summary>
21+
/// 10. Multiple polygon centroid
22+
/// </summary>
23+
public class Controller_10 : MonoBehaviour
24+
{
25+
26+
public Transform centroid;
27+
public PolygonSource[] polygonSources;
28+
List<Polygon> polygons = new List<Polygon>();
29+
30+
31+
void Update()
32+
{
33+
// Collect polygons.
34+
polygons.Clear();
35+
foreach (PolygonSource eachPolygonSource in polygonSources)
36+
{ polygons.Add(eachPolygonSource.polygon); }
37+
38+
// Calculate compund centroid.
39+
centroid.position = Geometry.CentroidOfPolygons(polygons.ToArray());
40+
}
41+
}
42+
}

Scenes/Controllers/Controller_8.cs

Lines changed: 74 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,74 @@
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+
/// 8. Segment-Segment intersection point
22+
/// </summary>
23+
public class Controller_8 : MonoBehaviour
24+
{
25+
26+
27+
public Color defaultColor;
28+
public Color passingColor;
29+
30+
public float accuracy = 0.0f;
31+
32+
public SegmentSource segmentSourceA;
33+
public SegmentSource segmentSourceB;
34+
public SegmentLineRenderer segmentRendererA;
35+
public SegmentLineRenderer segmentRendererB;
36+
37+
public GameObject intersectionPointObject;
38+
39+
private Segment segment_a { get { return segmentSourceA.segment; } }
40+
private Segment segment_b { get { return segmentSourceB.segment; } }
41+
42+
43+
void Update()
44+
{ RenderTestResult(SegmentIntersectionTest()); }
45+
46+
bool SegmentIntersectionTest()
47+
{
48+
Vector2 intersectionPoint;
49+
bool isIntersecting = segment_a.IntersectionWithSegmentWithAccuracy(segment_b, accuracy, out intersectionPoint);
50+
if (isIntersecting)
51+
{
52+
intersectionPointObject.transform.position = new Vector3(
53+
intersectionPoint.x,
54+
intersectionPoint.y,
55+
intersectionPointObject.transform.position.z
56+
); // Align point
57+
}
58+
59+
return isIntersecting;
60+
}
61+
62+
void RenderTestResult(bool testResult)
63+
{
64+
Color color = (testResult) ? passingColor : defaultColor;
65+
66+
// Layout color.
67+
segmentRendererA.lineColor = color;
68+
segmentRendererB.lineColor = color;
69+
70+
// Show / hide intersection point.
71+
intersectionPointObject.GetComponent<Renderer>().enabled = testResult;
72+
}
73+
}
74+
}

0 commit comments

Comments
 (0)