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

View File

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

View File

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

View File

@ -5,7 +5,7 @@ use crate::{partial::PartialCurve, path::SurfacePath};
/// Builder API for [`PartialCurve`]
pub trait CurveBuilder {
/// 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
fn update_as_v_axis(&mut self) -> &mut Self;
@ -24,12 +24,11 @@ pub trait CurveBuilder {
}
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 b = a + Vector::unit_u();
self.update_as_line_from_points([a, b]);
self
self.update_as_line_from_points([a, b])
}
fn update_as_v_axis(&mut self) -> &mut Self {

View File

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

View File

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