diff --git a/crates/geometry/src/two_lines.rs b/crates/geometry/src/two_lines.rs
index df666beb32..25ccd4412f 100644
--- a/crates/geometry/src/two_lines.rs
+++ b/crates/geometry/src/two_lines.rs
@@ -7,7 +7,7 @@ use crate::{
Distance,
};
-/// A corner given by a point and the directions of two outgoing rays.
+/// Two intersecting lines given by their intersection point and directions.
#[derive(
Copy,
Clone,
@@ -21,40 +21,41 @@ use crate::{
PathDeserialize,
)]
pub struct TwoLines {
- pub point: Point2,
- pub direction1: Vector2,
- pub direction2: Vector2,
+ pub intersection_point: Point2,
+ pub first_direction: Vector2,
+ pub second_direction: Vector2,
}
impl TwoLines {
/// Creates two orthogonal lines from a line and a point outside the line.
pub fn from_line_and_point_orthogonal(line: &Line2, point: Point2) -> Self {
- let corner_point = line.closest_point(point);
+ let intersection_point = line.closest_point(point);
let direction1 = line.direction;
- let direction2 = point - corner_point;
+ let direction2 = point - intersection_point;
Self {
- point: corner_point,
- direction1,
- direction2,
+ intersection_point,
+ first_direction: direction1,
+ second_direction: direction2,
}
}
}
impl Distance> for TwoLines {
fn squared_distance_to(&self, point: Point2) -> f32 {
- let line1 = Line {
- point: self.point,
- direction: self.direction1,
+ let first_line = Line {
+ point: self.intersection_point,
+ direction: self.first_direction,
};
- let line2 = Line {
- point: self.point,
- direction: self.direction2,
+ let second_line = Line {
+ point: self.intersection_point,
+ direction: self.second_direction,
};
- line1
- .squared_distance_to(point)
- .min(line2.squared_distance_to(point))
+ let squared_distance_to_first_line = first_line.squared_distance_to(point);
+ let squared_distance_to_second_line = second_line.squared_distance_to(point);
+
+ squared_distance_to_first_line.min(squared_distance_to_second_line)
}
}
@@ -71,9 +72,9 @@ mod tests {
struct SomeFrame;
const TWO_LINES: TwoLines = TwoLines {
- point: point![5.0, 5.0],
- direction1: vector![0.0, 3.0],
- direction2: vector![-10.0, 0.0],
+ intersection_point: point![5.0, 5.0],
+ first_direction: vector![0.0, 3.0],
+ second_direction: vector![-10.0, 0.0],
};
#[test]
@@ -86,8 +87,8 @@ mod tests {
let corner_point = point![15.0, 0.0];
let corner = TwoLines::from_line_and_point_orthogonal(&line, point);
- assert_relative_eq!(corner.point, corner_point);
- assert_relative_eq!(corner.direction1.dot(corner.direction2), 0.0);
+ assert_relative_eq!(corner.intersection_point, corner_point);
+ assert_relative_eq!(corner.first_direction.dot(corner.second_direction), 0.0);
}
#[test]
diff --git a/crates/ransac/src/lib.rs b/crates/ransac/src/lib.rs
index d89b2ffe15..7ca1d1eefa 100644
--- a/crates/ransac/src/lib.rs
+++ b/crates/ransac/src/lib.rs
@@ -24,7 +24,7 @@ impl RansacFeature {
let line = Line::from_points(point1, point2);
let two_lines = TwoLines::from_line_and_point_orthogonal(&line, point3);
- if two_lines.direction2.norm() > f32::EPSILON {
+ if two_lines.second_direction.norm() > f32::EPSILON {
Self::TwoLines(two_lines)
} else {
Self::Line(line)
@@ -73,12 +73,14 @@ impl IntoIterator for RansacResult {
}
RansacFeature::TwoLines(two_lines) => {
let dividing_line1 = Line {
- point: two_lines.point,
- direction: two_lines.direction1.normalize() + two_lines.direction2.normalize(),
+ point: two_lines.intersection_point,
+ direction: two_lines.first_direction.normalize()
+ + two_lines.second_direction.normalize(),
};
let dividing_line2 = Line {
- point: two_lines.point,
- direction: two_lines.direction1.normalize() - two_lines.direction2.normalize(),
+ point: two_lines.intersection_point,
+ direction: two_lines.first_direction.normalize()
+ - two_lines.second_direction.normalize(),
};
let (used_points1, used_points2): (Vec<_>, Vec<_>) =
@@ -86,12 +88,12 @@ impl IntoIterator for RansacResult {
dividing_line1.is_above(*point) != dividing_line2.is_above(*point)
});
let line1 = Line {
- point: two_lines.point,
- direction: two_lines.direction1,
+ point: two_lines.intersection_point,
+ direction: two_lines.first_direction,
};
let line2 = Line {
- point: two_lines.point,
- direction: two_lines.direction2,
+ point: two_lines.intersection_point,
+ direction: two_lines.second_direction,
};
[
diff --git a/crates/vision/src/line_detection.rs b/crates/vision/src/line_detection.rs
index 0bf2676356..07f4939bd3 100644
--- a/crates/vision/src/line_detection.rs
+++ b/crates/vision/src/line_detection.rs
@@ -250,22 +250,28 @@ impl LineDetection {
.unwrap(),
)),
RansacFeature::TwoLines(two_lines) => {
- let point = context
+ let intersection_point = context
.camera_matrix
- .ground_to_pixel(two_lines.point)
+ .ground_to_pixel(two_lines.intersection_point)
.unwrap();
RansacFeature::TwoLines(TwoLines {
- point,
- direction1: context
+ intersection_point,
+ first_direction: context
.camera_matrix
- .ground_to_pixel(two_lines.point + two_lines.direction1.normalize())
- .unwrap_or(point)
- - point,
- direction2: context
+ .ground_to_pixel(
+ two_lines.intersection_point
+ + two_lines.first_direction.normalize(),
+ )
+ .unwrap_or(intersection_point)
+ - intersection_point,
+ second_direction: context
.camera_matrix
- .ground_to_pixel(two_lines.point + two_lines.direction2.normalize())
- .unwrap_or(point)
- - point,
+ .ground_to_pixel(
+ two_lines.intersection_point
+ + two_lines.second_direction.normalize(),
+ )
+ .unwrap_or(intersection_point)
+ - intersection_point,
})
}
})
diff --git a/tools/twix/src/panels/image/overlays/line_detection.rs b/tools/twix/src/panels/image/overlays/line_detection.rs
index d347509cf4..2a420fff29 100644
--- a/tools/twix/src/panels/image/overlays/line_detection.rs
+++ b/tools/twix/src/panels/image/overlays/line_detection.rs
@@ -64,13 +64,13 @@ impl Overlay for LineDetection {
}
RansacFeature::TwoLines(two_lines) => {
painter.line(
- two_lines.point,
- two_lines.direction1,
+ two_lines.intersection_point,
+ two_lines.first_direction,
Stroke::new(2.0, Color32::GREEN),
);
painter.line(
- two_lines.point,
- two_lines.direction2,
+ two_lines.intersection_point,
+ two_lines.second_direction,
Stroke::new(2.0, Color32::GREEN),
);
}