Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Return line coordinates from Line::from_points #1455

Merged
merged 6 commits into from
Dec 16, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 4 additions & 8 deletions crates/fj-kernel/src/algorithms/sweep/vertex.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
use fj_math::{Line, Point, Scalar, Vector};
use fj_math::{Point, Scalar, Vector};

use crate::{
geometry::path::SurfacePath,
Expand Down Expand Up @@ -87,14 +87,10 @@ impl Sweep for (Handle<Vertex>, Handle<Surface>) {
// Armed with those coordinates, creating the `Curve` of the output
// `Edge` is straight-forward.
let curve = {
let line = Line::from_points(points_surface);
let path = SurfacePath::line_from_points(points_surface);

Curve::new(
surface.clone(),
SurfacePath::Line(line),
edge_global.curve().clone(),
)
.insert(objects)
Curve::new(surface.clone(), path, edge_global.curve().clone())
.insert(objects)
};

let vertices_surface = {
Expand Down
4 changes: 2 additions & 2 deletions crates/fj-kernel/src/builder/surface.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
use fj_math::{Line, Point, Vector};
use fj_math::{Point, Vector};

use crate::{
geometry::{path::GlobalPath, surface::SurfaceGeometry},
Expand Down Expand Up @@ -26,7 +26,7 @@ impl SurfaceBuilder for PartialSurface {
fn plane_from_points(points: [impl Into<Point<3>>; 3]) -> Self {
let [a, b, c] = points.map(Into::into);

let u = GlobalPath::Line(Line::from_points([a, b]));
let u = GlobalPath::line_from_points([a, b]);
let v = c - a;

Self {
Expand Down
8 changes: 5 additions & 3 deletions crates/fj-kernel/src/geometry/path.rs
Original file line number Diff line number Diff line change
Expand Up @@ -44,10 +44,11 @@ impl SurfacePath {

/// Construct a line from two points
pub fn line_from_points(points: [impl Into<Point<2>>; 2]) -> Self {
Self::Line(Line::from_points(points))
let (line, _) = Line::from_points(points);
Self::Line(line)
}

/// Convert a point on the path into global coordinates
/// Convert a point on the path into surface coordinates
pub fn point_from_path_coords(
&self,
point: impl Into<Point<1>>,
Expand Down Expand Up @@ -103,7 +104,8 @@ impl GlobalPath {

/// Construct a line from two points
pub fn line_from_points(points: [impl Into<Point<3>>; 2]) -> Self {
Self::Line(Line::from_points(points))
let (line, _) = Line::from_points(points);
Self::Line(line)
}

/// Access the origin of the path's coordinate system
Expand Down
20 changes: 14 additions & 6 deletions crates/fj-math/src/line.rs
Original file line number Diff line number Diff line change
Expand Up @@ -31,13 +31,21 @@ impl<const D: usize> Line<D> {

/// Create a line from two points
///
/// Also returns the lines coordinates of the provided points on the new
/// line.
///
/// # Panics
///
/// Panics, if the points are coincident.
pub fn from_points(points: [impl Into<Point<D>>; 2]) -> Self {
pub fn from_points(
points: [impl Into<Point<D>>; 2],
) -> (Self, [Point<1>; 2]) {
let [a, b] = points.map(Into::into);

Self::from_origin_and_direction(a, b - a)
let line = Self::from_origin_and_direction(a, b - a);
let coords = [[0.], [1.]].map(Point::from);

(line, coords)
}

/// Create a line from two points that include line coordinates
Expand Down Expand Up @@ -175,11 +183,11 @@ mod tests {

#[test]
fn is_coincident_with() {
let line = Line::from_points([[0., 0.], [1., 0.]]);
let (line, _) = Line::from_points([[0., 0.], [1., 0.]]);

let a = Line::from_points([[0., 0.], [1., 0.]]);
let b = Line::from_points([[0., 0.], [-1., 0.]]);
let c = Line::from_points([[0., 1.], [1., 1.]]);
let (a, _) = Line::from_points([[0., 0.], [1., 0.]]);
let (b, _) = Line::from_points([[0., 0.], [-1., 0.]]);
let (c, _) = Line::from_points([[0., 1.], [1., 1.]]);

assert!(line.is_coincident_with(&a));
assert!(line.is_coincident_with(&b));
Expand Down