Skip to content

Commit eb32338

Browse files
committed
0.5.1
1 parent 5f23f4c commit eb32338

12 files changed

Lines changed: 319 additions & 4 deletions

CHANGELOG.md

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,10 @@
1-
# eppz.Geometry
1+
# eppz! <sub>Geometry</sub>
2+
3+
* 0.5.1
4+
5+
+ Added `Lines` (renderer classes)
6+
+ Added `Scenes`
7+
+ Yet with a single scene `0. Polygon-point containment`
28

39
* 0.5.0
410

Components/PolygonSource.cs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,7 @@ void Update()
3939
{
4040
// Update polygon model with transforms, also update calculations.
4141
polygon.UpdatePointPositionsWithSource(this);
42+
windingDirection = polygon.windingDirection;
4243
if (offset != 0.0f) polygon = polygon.OffsetPolygon(offset);
4344
}
4445
}

Lines/CornerLineRenderer.cs

Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
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+
19+
20+
public class CornerLineRenderer : GeometryLineRenderer
21+
{
22+
23+
24+
public Color segmentAColor;
25+
public Color segmentBColor;
26+
public Color segmentNormalColor;
27+
28+
public Segment segmentA;
29+
public Segment segmentB;
30+
public Segment normal;
31+
32+
33+
protected override void OnDraw()
34+
{
35+
DrawSegment(segmentA, segmentAColor);
36+
DrawSegment(segmentB, segmentBColor);
37+
DrawSegment(normal, segmentNormalColor);
38+
}
39+
}
40+
}
41+
#endif

Lines/GeometryLineRenderer.cs

Lines changed: 48 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,48 @@
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+
19+
20+
public class GeometryLineRenderer : DirectLineRenderer
21+
{
22+
23+
24+
protected void DrawSegment(Segment segment, Color color)
25+
{ DrawLine(segment.a, segment.b, color); }
26+
27+
protected void DrawPolygon(Polygon polygon, Color color)
28+
{ polygon.EnumerateEdgesRecursive((Edge eachEdge) => DrawLine(eachEdge.a, eachEdge.b, color)); }
29+
30+
protected void DrawPolygonWithTransform(Polygon polygon, Color color, Transform transform_)
31+
{ DrawPolygonWithTransform(polygon, color, transform_, false); }
32+
33+
protected void DrawPolygonWithTransform(Polygon polygon, Color color, Transform transform_, bool drawNormals)
34+
{
35+
polygon.EnumerateEdgesRecursive((Edge eachEdge) =>
36+
{
37+
DrawLineWithTransform(eachEdge.a, eachEdge.b, color, transform_);
38+
if (drawNormals)
39+
{
40+
Vector2 halfie = eachEdge.a + ((eachEdge.b - eachEdge.a) / 2.0f);
41+
DrawLineWithTransform(halfie, halfie + eachEdge.normal * 0.1f, color, transform_);
42+
}
43+
});
44+
}
45+
}
46+
}
47+
#endif
48+

Lines/PolygonLineRenderer.cs

Lines changed: 80 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,80 @@
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 PolygonLineRenderer : GeometryLineRenderer
22+
{
23+
24+
25+
public Color lineColor;
26+
public Color boundsColor;
27+
public GameObject windingDirectionObject;
28+
public TextMesh areaTextMesh;
29+
public bool normals = false;
30+
31+
private float _previousArea;
32+
private Polygon.WindingDirection _previousWindingDirection;
33+
34+
public Polygon polygon;
35+
36+
37+
void Start()
38+
{
39+
// 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 = (windingDirectionObject != null);
51+
bool windingChanged = (polygon.windingDirection != _previousWindingDirection);
52+
if (hasWindingDirectionObject && windingChanged)
53+
{
54+
windingDirectionObject.transform.localScale = (polygon.isCW) ? Vector3.one : new Vector3 (1.0f, -1.0f, 1.0f);
55+
windingDirectionObject.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.windingDirection;
68+
_previousArea = polygon.area;
69+
}
70+
71+
protected override void OnDraw()
72+
{
73+
if (polygon == null) return; // Only having polygon
74+
75+
DrawRect(polygon.bounds, boundsColor);
76+
DrawPolygonWithTransform(polygon, lineColor, transform, normals);
77+
}
78+
}
79+
}
80+
#endif

Lines/SegmentLineRenderer.cs

Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,44 @@
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 SegmentLineRenderer : GeometryLineRenderer
22+
{
23+
24+
25+
public Color lineColor;
26+
public Color boundsColor;
27+
private Segment segment;
28+
29+
30+
void Start()
31+
{
32+
// Model reference.
33+
SegmentSource segmentSource_ = GetComponent<SegmentSource>();
34+
segment = segmentSource_.segment;
35+
}
36+
37+
protected override void OnDraw()
38+
{
39+
DrawRect(segment.bounds, boundsColor);
40+
DrawSegment(segment, lineColor);
41+
}
42+
}
43+
}
44+
#endif

README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
# eppz.Geometry
1+
# eppz! <sub>Geometry</sub>
22
> part of [**Unity.Library.eppz**](https://github.com/eppz/Unity.Library.eppz)
33
44
**📐 2D geometry for Unity.**
50 KB
Binary file not shown.

Scenes/Controllers/Controller_0.cs

Lines changed: 61 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,61 @@
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+
/// 0. Polygon-point containment
22+
/// </summary>
23+
public class Controller_0 : MonoBehaviour
24+
{
25+
26+
27+
public Color defaultColor;
28+
public Color passingColor;
29+
30+
public PolygonSource polygonSource;
31+
public GameObject[] pointObjects;
32+
public PolygonLineRenderer polygonRenderer;
33+
34+
Polygon polygon { get { return polygonSource.polygon; } }
35+
36+
37+
void Update()
38+
{ RenderTestResult(PointContainmentTest()); }
39+
40+
bool PointContainmentTest()
41+
{
42+
bool containsAllPoints = true;
43+
foreach (GameObject eachPointObject in pointObjects)
44+
{
45+
Vector2 eachPoint = eachPointObject.transform.position.xy();
46+
containsAllPoints &= polygon.ContainsPoint(eachPoint);
47+
}
48+
return containsAllPoints;
49+
}
50+
51+
void RenderTestResult(bool testResult)
52+
{
53+
Color color = (testResult) ? passingColor : defaultColor;
54+
55+
// Layout colors.
56+
polygonRenderer.lineColor = color;
57+
foreach (GameObject eachPointObject in pointObjects)
58+
{ eachPointObject.GetComponent<Renderer>().material.color = color; }
59+
}
60+
}
61+
}
Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
Shader "eppz!/Geometry/Solid color"
2+
{
3+
Properties
4+
{
5+
_Color ("Color", Color) = (1,1,1)
6+
}
7+
8+
SubShader
9+
{
10+
Color [_Color]
11+
Pass {}
12+
}
13+
}

0 commit comments

Comments
 (0)