Skip to content

Commit 92ed3a4

Browse files
committed
-Fix Triangle2D constructor taking two edges and a point instead of one edge and one point, which is incorrect.
-Fix circumcircle calculations using float instead of double and causing rounding errors.
1 parent 28f055b commit 92ed3a4

3 files changed

Lines changed: 24 additions & 16 deletions

File tree

CHANGELOG.md

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,13 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
77

88
## [Unreleased]
99

10+
## [0.3.3] - 2023-02-01
11+
12+
### Fixed
13+
14+
- Triangle2D constructor taking two edges and a point instead of one edge and one point.
15+
- Circumcircle calculations using float instead of double and causing rounding errors.
16+
1017
## [0.3.2] - 2023-02-01
1118

1219
### Added
@@ -72,7 +79,8 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
7279
- PointComputations.cs, to facilitate convex hull computation, point cloud simplification, and continuing on, any solely point-based methods.
7380
- Conversion.cs, to allow conversion of Vector types.
7481

75-
[unreleased]: https://github.com/IrishFix/Computational-Geometry/compare/v0.3.2...HEAD
82+
[unreleased]: https://github.com/IrishFix/Computational-Geometry/compare/v0.3.3...HEAD
83+
[0.3.3]: https://github.com/IrishFix/Computational-Geometry/compare/v0.3.2...v0.3.3
7684
[0.3.2]: https://github.com/IrishFix/Computational-Geometry/compare/v0.3.1...v0.3.2
7785
[0.3.1]: https://github.com/IrishFix/Computational-Geometry/compare/v0.3.0...v0.3.1
7886
[0.3.0]: https://github.com/IrishFix/Computational-Geometry/compare/v0.2.2...v0.3.0

Runtime/Triangle2D.cs

Lines changed: 14 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -26,21 +26,21 @@ public class Triangle2D {
2626
[SerializeField] public Edge2D[] Edges;
2727
[SerializeField] public Vector2[] Vertices;
2828

29-
internal Vector2 A => Vertices[0];
30-
internal Vector2 B => Vertices[1];
31-
internal Vector2 C => Vertices[2];
29+
public Vector2 A => Vertices[0];
30+
public Vector2 B => Vertices[1];
31+
public Vector2 C => Vertices[2];
3232

33-
[SerializeField] internal Vector2 Circumcenter;
34-
[SerializeField] internal double RadiusSquared;
33+
[SerializeField] public Vector2 Circumcenter;
34+
[SerializeField] public double RadiusSquared;
3535

3636
public Triangle2D(Vector2 a, Vector2 b, Vector2 c) {
3737
Vertices = !IsCounterClockwise(a,b,c) ? new[] {a,c,b} : new[] {a,b,c};
3838
Edges = new[] {new Edge2D(Vertices[0],Vertices[1]),new Edge2D(Vertices[1],Vertices[2]),new Edge2D(Vertices[2],Vertices[0])};
3939
UpdateCircumcircle();
4040
}
4141

42-
public Triangle2D(Edge2D a, Edge2D b, Vector2 c) {
43-
Vertices = !IsCounterClockwise(a.Vertices[0],b.Vertices[0],c) ? new[] {a.Vertices[0],c,b.Vertices[0]} : new[] {a.Vertices[0],b.Vertices[0],c};
42+
public Triangle2D(Edge2D a, Vector2 b) {
43+
Vertices = !IsCounterClockwise(a.Vertices[0],a.Vertices[1],b) ? new[] {a.Vertices[0],b,a.Vertices[1]} : new[] {a.Vertices[0],a.Vertices[1],b};
4444
Edges = new[] {new Edge2D(Vertices[0],Vertices[1]),new Edge2D(Vertices[1],Vertices[2]),new Edge2D(Vertices[2],Vertices[0])};
4545
UpdateCircumcircle();
4646
}
@@ -77,20 +77,20 @@ public void UpdateCircumcircle() {
7777
Vector2 p1 = Vertices[1];
7878
Vector2 p2 = Vertices[2];
7979

80-
float dA = p0.x * p0.x + p0.y * p0.y;
81-
float dB = p1.x * p1.x + p1.y * p1.y;
82-
float dC = p2.x * p2.x + p2.y * p2.y;
80+
double dA = p0.x * p0.x + p0.y * p0.y;
81+
double dB = p1.x * p1.x + p1.y * p1.y;
82+
double dC = p2.x * p2.x + p2.y * p2.y;
8383

84-
float aux1 = dA * (p2.y - p1.y) + dB * (p0.y - p2.y) + dC * (p1.y - p0.y);
85-
float aux2 = -(dA * (p2.x - p1.x) + dB * (p0.x - p2.x) + dC * (p1.x - p0.x));
86-
float div = 2 * (p0.x * (p2.y - p1.y) + p1.x * (p0.y - p2.y) + p2.x * (p1.y - p0.y));
84+
double aux1 = dA * (p2.y - p1.y) + dB * (p0.y - p2.y) + dC * (p1.y - p0.y);
85+
double aux2 = -(dA * (p2.x - p1.x) + dB * (p0.x - p2.x) + dC * (p1.x - p0.x));
86+
double div = 2 * (p0.x * (p2.y - p1.y) + p1.x * (p0.y - p2.y) + p2.x * (p1.y - p0.y));
8787

8888
if (div == 0) {
8989
Debug.LogWarning("Division by 0 caught. UpdateCircumcircle() did not complete.");
9090
return;
9191
}
9292

93-
Vector2 Center = new(aux1 / div, aux2 / div);
93+
Vector2 Center = new((float)(aux1 / div), (float)(aux2 / div));
9494

9595
Circumcenter = Center;
9696
RadiusSquared = (Center.x - p0.x) * (Center.x - p0.x) + (Center.y - p0.y) * (Center.y - p0.y);

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
"description": "Computational Geometry is a mathematical package oriented on making triangulation, point manipulation, intersection calculation and more; as simple as possible.",
55
"unity": "2021.3",
66
"unityRelease": "17f1",
7-
"version": "0.3.2",
7+
"version": "0.3.3",
88
"keywords": ["Mathematics", "Maths", "Math", "Computation", "Geometry", "Triangulation", "Delaunay"],
99
"license": "AGPL-3.0-only",
1010
"licensesUrl": "https://spdx.org/licenses/AGPL-3.0-only.html",

0 commit comments

Comments
 (0)