Change style of `update_as_u_axis`

This commit is contained in:
Hanno Braun 2022-11-11 14:49:20 +01:00
parent c001b18fbd
commit 7e5500a884
6 changed files with 58 additions and 62 deletions

View File

@ -87,12 +87,12 @@ mod tests {
let objects = Objects::new(); let objects = Objects::new();
let surface = objects.surfaces.xy_plane(); let surface = objects.surfaces.xy_plane();
let curve = PartialCurve { let mut curve = PartialCurve {
surface: Some(surface.clone()), surface: Some(surface.clone()),
..Default::default() ..Default::default()
} };
.update_as_u_axis() curve.update_as_u_axis();
.build(&objects)?; let curve = curve.build(&objects)?;
let half_edge = HalfEdge::partial() let half_edge = HalfEdge::partial()
.update_as_line_segment_from_points(surface, [[1., -1.], [1., 1.]]) .update_as_line_segment_from_points(surface, [[1., -1.], [1., 1.]])
.build(&objects)?; .build(&objects)?;
@ -113,12 +113,12 @@ mod tests {
let objects = Objects::new(); let objects = Objects::new();
let surface = objects.surfaces.xy_plane(); let surface = objects.surfaces.xy_plane();
let curve = PartialCurve { let mut curve = PartialCurve {
surface: Some(surface.clone()), surface: Some(surface.clone()),
..Default::default() ..Default::default()
} };
.update_as_u_axis() curve.update_as_u_axis();
.build(&objects)?; let curve = curve.build(&objects)?;
let half_edge = HalfEdge::partial() let half_edge = HalfEdge::partial()
.update_as_line_segment_from_points( .update_as_line_segment_from_points(
surface, surface,
@ -142,12 +142,12 @@ mod tests {
let objects = Objects::new(); let objects = Objects::new();
let surface = objects.surfaces.xy_plane(); let surface = objects.surfaces.xy_plane();
let curve = PartialCurve { let mut curve = PartialCurve {
surface: Some(surface.clone()), surface: Some(surface.clone()),
..Default::default() ..Default::default()
} };
.update_as_u_axis() curve.update_as_u_axis();
.build(&objects)?; let curve = curve.build(&objects)?;
let half_edge = HalfEdge::partial() let half_edge = HalfEdge::partial()
.update_as_line_segment_from_points( .update_as_line_segment_from_points(
surface, surface,
@ -166,12 +166,12 @@ mod tests {
let objects = Objects::new(); let objects = Objects::new();
let surface = objects.surfaces.xy_plane(); let surface = objects.surfaces.xy_plane();
let curve = PartialCurve { let mut curve = PartialCurve {
surface: Some(surface.clone()), surface: Some(surface.clone()),
..Default::default() ..Default::default()
} };
.update_as_u_axis() curve.update_as_u_axis();
.build(&objects)?; let curve = curve.build(&objects)?;
let half_edge = HalfEdge::partial() let half_edge = HalfEdge::partial()
.update_as_line_segment_from_points(surface, [[-1., 0.], [1., 0.]]) .update_as_line_segment_from_points(surface, [[-1., 0.], [1., 0.]])
.build(&objects)?; .build(&objects)?;

View File

@ -119,20 +119,18 @@ mod tests {
None, None,
); );
let expected_xy = PartialCurve { let mut expected_xy = PartialCurve {
surface: Some(xy.clone()), surface: Some(xy.clone()),
..Default::default() ..Default::default()
} };
.update_as_u_axis() expected_xy.update_as_u_axis();
.build(&objects)? let expected_xy = expected_xy.build(&objects)?.insert(&objects)?;
.insert(&objects)?; let mut expected_xz = PartialCurve {
let expected_xz = PartialCurve {
surface: Some(xz.clone()), surface: Some(xz.clone()),
..Default::default() ..Default::default()
} };
.update_as_u_axis() expected_xz.update_as_u_axis();
.build(&objects)? let expected_xz = expected_xz.build(&objects)?.insert(&objects)?;
.insert(&objects)?;
assert_eq!( assert_eq!(
SurfaceSurfaceIntersection::compute([xy, xz], &objects)?, SurfaceSurfaceIntersection::compute([xy, xz], &objects)?,

View File

@ -179,13 +179,12 @@ mod tests {
let objects = Objects::new(); let objects = Objects::new();
let surface = objects.surfaces.xz_plane(); let surface = objects.surfaces.xz_plane();
let curve = PartialCurve { let mut curve = PartialCurve {
surface: Some(surface.clone()), surface: Some(surface.clone()),
..Default::default() ..Default::default()
} };
.update_as_u_axis() curve.update_as_u_axis();
.build(&objects)? let curve = curve.build(&objects)?.insert(&objects)?;
.insert(&objects)?;
let vertex = Vertex::partial() let vertex = Vertex::partial()
.with_position(Some([0.])) .with_position(Some([0.]))
.with_curve(curve) .with_curve(curve)

View File

@ -5,7 +5,7 @@ use crate::{partial::PartialCurve, path::SurfacePath};
/// Builder API for [`PartialCurve`] /// Builder API for [`PartialCurve`]
pub trait CurveBuilder { pub trait CurveBuilder {
/// Update partial curve to represent the u-axis /// Update partial curve to represent the u-axis
fn update_as_u_axis(self) -> Self; fn update_as_u_axis(&mut self) -> &mut Self;
/// Update partial curve to represent the v-axis /// Update partial curve to represent the v-axis
fn update_as_v_axis(&mut self) -> &mut Self; fn update_as_v_axis(&mut self) -> &mut Self;
@ -24,12 +24,11 @@ pub trait CurveBuilder {
} }
impl CurveBuilder for PartialCurve { impl CurveBuilder for PartialCurve {
fn update_as_u_axis(mut self) -> Self { fn update_as_u_axis(&mut self) -> &mut Self {
let a = Point::origin(); let a = Point::origin();
let b = a + Vector::unit_u(); let b = a + Vector::unit_u();
self.update_as_line_from_points([a, b]); self.update_as_line_from_points([a, b])
self
} }
fn update_as_v_axis(&mut self) -> &mut Self { fn update_as_v_axis(&mut self) -> &mut Self {

View File

@ -376,13 +376,12 @@ mod tests {
let objects = Objects::new(); let objects = Objects::new();
let surface = objects.surfaces.xy_plane(); let surface = objects.surfaces.xy_plane();
let object = PartialCurve { let mut object = PartialCurve {
surface: Some(surface), surface: Some(surface),
..Default::default() ..Default::default()
} };
.update_as_u_axis() object.update_as_u_axis();
.build(&objects)? let object = object.build(&objects)?.insert(&objects)?;
.insert(&objects)?;
assert_eq!(1, object.curve_iter().count()); assert_eq!(1, object.curve_iter().count());
assert_eq!(0, object.cycle_iter().count()); assert_eq!(0, object.cycle_iter().count());
@ -618,13 +617,12 @@ mod tests {
let objects = Objects::new(); let objects = Objects::new();
let surface = objects.surfaces.xy_plane(); let surface = objects.surfaces.xy_plane();
let curve = PartialCurve { let mut curve = PartialCurve {
surface: Some(surface.clone()), surface: Some(surface.clone()),
..Default::default() ..Default::default()
} };
.update_as_u_axis() curve.update_as_u_axis();
.build(&objects)? let curve = curve.build(&objects)?.insert(&objects)?;
.insert(&objects)?;
let global_vertex = objects let global_vertex = objects
.global_vertices .global_vertices
.insert(GlobalVertex::from_position([0., 0., 0.]))?; .insert(GlobalVertex::from_position([0., 0., 0.]))?;

View File

@ -190,15 +190,15 @@ mod tests {
fn vertex_surface_mismatch() -> anyhow::Result<()> { fn vertex_surface_mismatch() -> anyhow::Result<()> {
let objects = Objects::new(); let objects = Objects::new();
let mut curve = PartialCurve {
surface: Some(objects.surfaces.xy_plane()),
..Default::default()
};
curve.update_as_u_axis();
let valid = Vertex::partial() let valid = Vertex::partial()
.with_position(Some([0.])) .with_position(Some([0.]))
.with_curve( .with_curve(curve)
PartialCurve {
surface: Some(objects.surfaces.xy_plane()),
..Default::default()
}
.update_as_u_axis(),
)
.build(&objects)?; .build(&objects)?;
let invalid = Vertex::new( let invalid = Vertex::new(
valid.position(), valid.position(),
@ -221,16 +221,18 @@ mod tests {
fn vertex_position_mismatch() -> anyhow::Result<()> { fn vertex_position_mismatch() -> anyhow::Result<()> {
let objects = Objects::new(); let objects = Objects::new();
let valid = Vertex::partial() let valid = {
.with_position(Some([0.])) let mut curve = PartialCurve {
.with_curve( surface: Some(objects.surfaces.xy_plane()),
PartialCurve { ..Default::default()
surface: Some(objects.surfaces.xy_plane()), };
..Default::default() curve.update_as_u_axis();
}
.update_as_u_axis(), Vertex::partial()
) .with_position(Some([0.]))
.build(&objects)?; .with_curve(curve)
.build(&objects)?
};
let invalid = Vertex::new( let invalid = Vertex::new(
valid.position(), valid.position(),
valid.curve().clone(), valid.curve().clone(),