Fix obsolete function signatures

This commit is contained in:
2024-05-27 16:27:12 -04:00
parent 78415d2a88
commit ff777d1867
10 changed files with 135 additions and 24 deletions

View File

@@ -68,6 +68,11 @@ namespace J3ML::Geometry
float MaxY() const; ///< [similarOverload: MaxX]
float MaxZ() const; ///< [similarOverload: MaxX]
Vector3 MinPoint() const;
Vector3 MaxPoint() const;
/// Returns the smallest sphere that contains this AABB.
/// This function computes the minimal volume sphere that contains all the points inside this AABB
Sphere MinimalEnclosingSphere() const;

View File

@@ -30,14 +30,20 @@ namespace J3ML::Geometry {
inline static int NumEdges() { return 12; }
inline static int NumVertices() { return 8; }
float MinX() const;
float MinY() const;
float MinZ() const;
float MaxX() const;
float MaxY() const;
float MaxZ() const;
Vector3 MinPoint() const;
Vector3 MaxPoint() const;
Polyhedron ToPolyhedron() const;
//PBVolume<6> ToPBVolume() const;
AABB MinimalEnclosingAABB() const
{
AABB aabb;
aabb.SetFrom(*this);
return aabb;
}
AABB MinimalEnclosingAABB() const;
bool Intersects(const LineSegment &lineSegment) const;

View File

@@ -786,4 +786,12 @@ namespace J3ML::Geometry {
dMax = s + r;
}
Vector3 AABB::MinPoint() const {
return {MinX(), MinY(), MinZ()};
}
Vector3 AABB::MaxPoint() const {
return {MaxX(), MaxY(), MaxZ()};
}
}

View File

@@ -197,7 +197,7 @@ namespace J3ML::Geometry {
}
Vector3 LineSegment::Dir() const {
return (B - A).Normalize();
return (B - A).Normalized();
}
float LineSegment::Length() const {

View File

@@ -343,9 +343,9 @@ namespace J3ML::Geometry
o.axis[0] = transform.Mul(o.r.x * o.axis[0]);
o.axis[1] = transform.Mul(o.r.y * o.axis[1]);
o.axis[2] = transform.Mul(o.r.z * o.axis[2]);
o.r.x = o.axis[0].Normalize().x;
o.r.y = o.axis[1].Normalize().y;
o.r.z = o.axis[2].Normalize().z;
o.r.x = o.axis[0].Normalized().x;
o.r.y = o.axis[1].Normalized().y;
o.r.z = o.axis[2].Normalized().z;
}
void OBB::SetFrom(const AABB& aabb, const Matrix3x3 &transform) {
@@ -446,6 +446,98 @@ namespace J3ML::Geometry
this->axis[2] = axis2;
}
AABB OBB::MinimalEnclosingAABB() const {
AABB aabb;
aabb.SetFrom(*this);
return aabb;
}
Vector3 OBB::MinPoint() const {
return {MinX(), MinY(), MinZ()};
}
float OBB::MinX() const {
auto c0 = CornerPoint(0);
auto c1 = CornerPoint(1);
auto c2 = CornerPoint(2);
auto c3 = CornerPoint(3);
auto c4 = CornerPoint(4);
auto c5 = CornerPoint(5);
auto c6 = CornerPoint(6);
auto c7 = CornerPoint(7);
return std::min({c0.x, c1.x, c2.x, c3.x, c4.x, c5.x, c6.x, c7.x});
}
float OBB::MinY() const {
auto c0 = CornerPoint(0);
auto c1 = CornerPoint(1);
auto c2 = CornerPoint(2);
auto c3 = CornerPoint(3);
auto c4 = CornerPoint(4);
auto c5 = CornerPoint(5);
auto c6 = CornerPoint(6);
auto c7 = CornerPoint(7);
return std::min({c0.y, c1.y, c2.y, c3.y, c4.y, c5.y, c6.y, c7.y});
}
float OBB::MinZ() const {
auto c0 = CornerPoint(0);
auto c1 = CornerPoint(1);
auto c2 = CornerPoint(2);
auto c3 = CornerPoint(3);
auto c4 = CornerPoint(4);
auto c5 = CornerPoint(5);
auto c6 = CornerPoint(6);
auto c7 = CornerPoint(7);
return std::min({c0.z, c1.z, c2.z, c3.z, c4.z, c5.z, c6.z, c7.z});
}
float OBB::MaxX() const {
auto c0 = CornerPoint(0);
auto c1 = CornerPoint(1);
auto c2 = CornerPoint(2);
auto c3 = CornerPoint(3);
auto c4 = CornerPoint(4);
auto c5 = CornerPoint(5);
auto c6 = CornerPoint(6);
auto c7 = CornerPoint(7);
return std::max({c0.x, c1.x, c2.x, c3.x, c4.x, c5.x, c6.x, c7.x});
}
float OBB::MaxY() const {
auto c0 = CornerPoint(0);
auto c1 = CornerPoint(1);
auto c2 = CornerPoint(2);
auto c3 = CornerPoint(3);
auto c4 = CornerPoint(4);
auto c5 = CornerPoint(5);
auto c6 = CornerPoint(6);
auto c7 = CornerPoint(7);
return std::max({c0.y, c1.y, c2.y, c3.y, c4.y, c5.y, c6.y, c7.y});
}
float OBB::MaxZ() const {
auto c0 = CornerPoint(0);
auto c1 = CornerPoint(1);
auto c2 = CornerPoint(2);
auto c3 = CornerPoint(3);
auto c4 = CornerPoint(4);
auto c5 = CornerPoint(5);
auto c6 = CornerPoint(6);
auto c7 = CornerPoint(7);
return std::max({c0.z, c1.z, c2.z, c3.z, c4.z, c5.z, c6.z, c7.z});
}
Vector3 OBB::MaxPoint() const {
return {MaxX(), MaxY(), MaxZ()};
}
}

View File

@@ -107,7 +107,7 @@ namespace J3ML::Geometry
Plane::Plane(const Line &line, const Vector3 &normal) {
Vector3 perpNormal = normal - normal.ProjectToNorm(line.Direction);
Set(line.Position, perpNormal.Normalize());
Set(line.Position, perpNormal.Normalized());
}
void Plane::Set(const Vector3 &v1, const Vector3 &v2, const Vector3 &v3) {

View File

@@ -78,7 +78,7 @@ namespace J3ML::Geometry {
if (vertices.size() < 2)
return Vector3::Right;
Vector3 u = (Vector3)vertices[1] - (Vector3)vertices[0];
u = u.Normalize(); // Always succeeds, even if u was zero (generates (1,0,0)).
u = u.Normalized(); // Always succeeds, even if u was zero (generates (1,0,0)).
return u;
}
@@ -86,7 +86,7 @@ namespace J3ML::Geometry {
{
if (vertices.size() < 2)
return Vector3::Down;
return Vector3::Cross(PlaneCCW().Normal, BasisU()).Normalize();
return Vector3::Cross(PlaneCCW().Normal, BasisU()).Normalized();
}
Plane Polygon::PlaneCCW() const
@@ -116,14 +116,14 @@ namespace J3ML::Geometry {
// Polygon contains multiple points, but they are all collinear.
// Pick an arbitrary plane along the line as the polygon plane (as if the polygon had only two points)
Vector3 dir = (Vector3(vertices[1])-Vector3(vertices[0])).Normalize();
Vector3 dir = (Vector3(vertices[1])-Vector3(vertices[0])).Normalized();
return Plane(Line(vertices[0], dir), dir.Perpendicular());
}
if (vertices.size() == 3)
return Plane(vertices[0], vertices[1], vertices[2]);
if (vertices.size() == 2)
{
Vector3 dir = (Vector3(vertices[1])-Vector3(vertices[0])).Normalize();
Vector3 dir = (Vector3(vertices[1])-Vector3(vertices[0])).Normalized();
return Plane(Line(vertices[0], dir), dir.Perpendicular());
}
if (vertices.size() == 1)

View File

@@ -213,7 +213,7 @@ namespace J3ML::Geometry
Vector3 basisU = (Vector3)v[vertices[1]] - (Vector3)v[vertices[0]];
basisU.Normalize();
Vector3 basisV = Vector3::Cross(p.Normal, basisU).Normalize();
Vector3 basisV = Vector3::Cross(p.Normal, basisU).Normalized();
assert(basisU.IsNormalized());
assert(basisV.IsNormalized());
assert(basisU.IsPerpendicular(basisV));

View File

@@ -20,7 +20,7 @@ namespace J3ML::Geometry
RaycastResult Ray::Cast(const Sphere &target, float maxDistance)
{
Vector3 p0 = this->Origin;
Vector3 d = this->Direction.Normalize();
Vector3 d = this->Direction.Normalized();
Vector3 c = target.Position;
float r = target.Radius;
@@ -48,7 +48,7 @@ namespace J3ML::Geometry
Vector3 intersection = p0.Project(d*t);
Vector3 intersection_from_sphere_origin = (intersection - target.Position);
Vector3 normal = -intersection_from_sphere_origin.Normalize();
Vector3 normal = -intersection_from_sphere_origin.Normalized();
return RaycastResult{
intersection,
@@ -85,7 +85,7 @@ namespace J3ML::Geometry
t = tmin;
Vector3 p0 = this->Origin;
Vector3 d = this->Direction.Normalize();
Vector3 d = this->Direction.Normalized();
// TODO: Verify this
Vector3 intersection = p0.Project(d*t);
@@ -94,7 +94,7 @@ namespace J3ML::Geometry
// TODO: Calculate surfacenormal against rectangle
Vector3 intersection_from_sphere_origin = (intersection - target.Centroid());
Vector3 normal = -intersection_from_sphere_origin.Normalize();
Vector3 normal = -intersection_from_sphere_origin.Normalized();
return RaycastResult
{
@@ -114,7 +114,7 @@ namespace J3ML::Geometry
float t = (target.distance - pn) / nd;
Vector3 d = this->Direction.Normalize();
Vector3 d = this->Direction.Normalized();
// TODO: verify this
Vector3 intersection = this->Origin.Project(d*t);

View File

@@ -174,7 +174,7 @@ TEST(Vector3Test, V3_Normalize) {
Vector3 Input {2, 0, 0};
Vector3 ExpectedResult {1, 0, 0};
EXPECT_V3_EQ(Input.Normalize(), ExpectedResult);
EXPECT_V3_EQ(Input.Normalized(), ExpectedResult);
}
TEST(Vector3Test, V3_Lerp)
{
@@ -188,8 +188,8 @@ TEST(Vector3Test, V3_AngleBetween) {
using J3ML::LinearAlgebra::Angle2D;
Vector3 A{ .5f, .5f, .5f};
Vector3 B {.25f, .75f, .25f};
A = A.Normalize();
B = B.Normalize();
A = A.Normalized();
B = B.Normalized();
Angle2D ExpectedResult {-0.69791365, -2.3561945};
std::cout << A.AngleBetween(B).x << ", " << A.AngleBetween(B).y << "";
auto angle = A.AngleBetween(B);