Skip to content

Commit

Permalink
Pass output values by reference instead of pointers
Browse files Browse the repository at this point in the history
  • Loading branch information
wawanbreton committed Jun 21, 2024
1 parent 677aa84 commit 98c0407
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 11 deletions.
4 changes: 2 additions & 2 deletions include/utils/linearAlg2D.h
Original file line number Diff line number Diff line change
Expand Up @@ -79,8 +79,8 @@ class LinearAlg2D
*
* \return Whether the two line segments intersect.
*/
static bool segmentSegmentIntersection(const Point2LL& p1, const Point2LL& p2, const Point2LL& p3, const Point2LL& p4, float* t, float* u);
static bool lineLineIntersection(const Point2LL& p1, const Point2LL& p2, const Point2LL& p3, const Point2LL& p4, float* t, float* u);
static bool segmentSegmentIntersection(const Point2LL& p1, const Point2LL& p2, const Point2LL& p3, const Point2LL& p4, float& t, float& u);
static bool lineLineIntersection(const Point2LL& p1, const Point2LL& p2, const Point2LL& p3, const Point2LL& p4, float& t, float& u);

static bool lineLineIntersection(const Point2LL& a, const Point2LL& b, const Point2LL& c, const Point2LL& d, Point2LL& output);

Expand Down
2 changes: 1 addition & 1 deletion src/InsetOrderOptimizer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -211,7 +211,7 @@ std::optional<size_t> InsetOrderOptimizer::insertSeamPoint(ExtrusionLine& closed
const auto& next_junction = closed_line.junctions_[(i + 1) % closed_line.junctions_.size()];

float t, u;
if (LinearAlg2D::segmentSegmentIntersection(ray_origin, request_point, junction.p_, next_junction.p_, &t, &u))
if (LinearAlg2D::segmentSegmentIntersection(ray_origin, request_point, junction.p_, next_junction.p_, t, u))
{
const Point2LL intersection = ray_origin + (request_point - ray_origin) * t;
const coord_t distance_sqd = vSize2(request_point - intersection);
Expand Down
16 changes: 8 additions & 8 deletions src/utils/linearAlg2D.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -272,7 +272,7 @@ Point3Matrix LinearAlg2D::rotateAround(const Point2LL& middle, double rotation)
return Point3Matrix::translate(middle).compose(rotation_matrix_homogeneous).compose(Point3Matrix::translate(-middle));
}

bool LinearAlg2D::lineLineIntersection(const Point2LL& p1, const Point2LL& p2, const Point2LL& p3, const Point2LL& p4, float* t, float* u)
bool LinearAlg2D::lineLineIntersection(const Point2LL& p1, const Point2LL& p2, const Point2LL& p3, const Point2LL& p4, float& t, float& u)
{
const float x1mx2 = p1.X - p2.X;
const float x1mx3 = p1.X - p3.X;
Expand All @@ -281,8 +281,8 @@ bool LinearAlg2D::lineLineIntersection(const Point2LL& p1, const Point2LL& p2, c
const float y1my3 = p1.Y - p3.Y;
const float y3my4 = p3.Y - p4.Y;

t[0] = x1mx3 * y3my4 - y1my3 * x3mx4;
u[0] = x1mx3 * y1my2 - y1my3 * x1mx2;
t = x1mx3 * y3my4 - y1my3 * x3mx4;
u = x1mx3 * y1my2 - y1my3 * x1mx2;
const float div = x1mx2 * y3my4 - y1my2 * x3mx4;
if (div == 0.0f)
{
Expand All @@ -291,20 +291,20 @@ bool LinearAlg2D::lineLineIntersection(const Point2LL& p1, const Point2LL& p2, c

// NOTE: In theory the comparison 0 <= par <= 1 can now done without division for each parameter (as an early-out),
// but this is easier & when the intersection _does_ happen and we want the normalized parameters returned anyway.
t[0] /= div;
u[0] /= div;
t /= div;
u /= div;
return true;
}

bool LinearAlg2D::segmentSegmentIntersection(const Point2LL& p1, const Point2LL& p2, const Point2LL& p3, const Point2LL& p4, float* t, float* u)
bool LinearAlg2D::segmentSegmentIntersection(const Point2LL& p1, const Point2LL& p2, const Point2LL& p3, const Point2LL& p4, float& t, float& u)
{
return lineLineIntersection(p1, p2, p3, p4, t, u) && t[0] >= 0.0f && u[0] >= 0.0f && t[0] <= 1.0f && u[0] <= 1.0f;
return lineLineIntersection(p1, p2, p3, p4, t, u) && t >= 0.0f && u >= 0.0f && t <= 1.0f && u <= 1.0f;
}

bool LinearAlg2D::lineLineIntersection(const Point2LL& a, const Point2LL& b, const Point2LL& c, const Point2LL& d, Point2LL& output)
{
float t, u;
if (! lineLineIntersection(a, b, c, d, &t, &u))
if (! lineLineIntersection(a, b, c, d, t, u))
{
return false;
}
Expand Down

0 comments on commit 98c0407

Please sign in to comment.