Return LineSegment from line_segment_at

This commit is contained in:
Hanno Braun 2024-09-25 19:21:12 +02:00
parent eecfa66461
commit b61e5025eb
4 changed files with 20 additions and 9 deletions

View File

@ -5,7 +5,10 @@ use std::iter;
use approx::AbsDiffEq; use approx::AbsDiffEq;
use fj_math::{Aabb, Point, Scalar, Sign, Transform, Vector}; use fj_math::{Aabb, Point, Scalar, Sign, Transform, Vector};
use crate::geometry::{traits::GenPolyline, CurveBoundary, Tolerance}; use crate::geometry::{
traits::{GenPolyline, LineSegment},
CurveBoundary, Tolerance,
};
/// An n-dimensional circle /// An n-dimensional circle
/// ///
@ -188,7 +191,7 @@ impl<const D: usize> GenPolyline<D> for Circle<D> {
&self, &self,
point: Point<1>, point: Point<1>,
tolerance: Tolerance, tolerance: Tolerance,
) -> [Point<D>; 2] { ) -> LineSegment<D> {
let params = CircleApproxParams::new(self, tolerance); let params = CircleApproxParams::new(self, tolerance);
// The approximation parameters have an increment, in curve coordinates, // The approximation parameters have an increment, in curve coordinates,
@ -211,8 +214,10 @@ impl<const D: usize> GenPolyline<D> for Circle<D> {
}); });
// And finally, convert those into points of the desired dimensionality. // And finally, convert those into points of the desired dimensionality.
points_curve let points = points_curve
.map(|point_curve| self.point_from_circle_coords([point_curve])) .map(|point_curve| self.point_from_circle_coords([point_curve]));
LineSegment { points }
} }
fn generate_polyline( fn generate_polyline(

View File

@ -2,18 +2,23 @@
use fj_math::{Line, Point}; use fj_math::{Line, Point};
use crate::geometry::{traits::GenPolyline, CurveBoundary, Tolerance}; use crate::geometry::{
traits::{GenPolyline, LineSegment},
CurveBoundary, Tolerance,
};
impl<const D: usize> GenPolyline<D> for Line<D> { impl<const D: usize> GenPolyline<D> for Line<D> {
fn origin(&self) -> Point<D> { fn origin(&self) -> Point<D> {
self.origin() self.origin()
} }
fn line_segment_at(&self, point: Point<1>, _: Tolerance) -> [Point<D>; 2] { fn line_segment_at(&self, point: Point<1>, _: Tolerance) -> LineSegment<D> {
// Collapse line segment into a point, as per documentation. // Collapse line segment into a point, as per documentation.
let point = self.origin() + self.direction() * point.t; let point = self.origin() + self.direction() * point.t;
[point, point] LineSegment {
points: [point, point],
}
} }
fn generate_polyline( fn generate_polyline(

View File

@ -66,6 +66,7 @@ impl SurfaceGeom {
let [a, b] = self let [a, b] = self
.u .u
.line_segment_at(Point::from([point_surface.u]), tolerance.into()) .line_segment_at(Point::from([point_surface.u]), tolerance.into())
.points
.map(|point_global| point_global + self.v * point_surface.v); .map(|point_global| point_global + self.v * point_surface.v);
let c = a + (b - a) / 2.; let c = a + (b - a) / 2.;

View File

@ -48,7 +48,7 @@ pub trait GenPolyline<const D: usize> {
&self, &self,
point: Point<1>, point: Point<1>,
tolerance: Tolerance, tolerance: Tolerance,
) -> [Point<D>; 2]; ) -> LineSegment<D>;
/// # Generate a polyline within the provided boundary /// # Generate a polyline within the provided boundary
fn generate_polyline( fn generate_polyline(
@ -72,7 +72,7 @@ impl<const D: usize> GenPolyline<D> for Path<D> {
&self, &self,
point: Point<1>, point: Point<1>,
tolerance: Tolerance, tolerance: Tolerance,
) -> [Point<D>; 2] { ) -> LineSegment<D> {
match self { match self {
Self::Circle(circle) => circle.line_segment_at(point, tolerance), Self::Circle(circle) => circle.line_segment_at(point, tolerance),
Self::Line(line) => line.line_segment_at(point, tolerance), Self::Line(line) => line.line_segment_at(point, tolerance),