Skip to content

Commit

Permalink
Change style of update_as_u_axis
Browse files Browse the repository at this point in the history
  • Loading branch information
hannobraun committed Nov 11, 2022
1 parent c001b18 commit 7e5500a
Show file tree
Hide file tree
Showing 6 changed files with 58 additions and 62 deletions.
32 changes: 16 additions & 16 deletions crates/fj-kernel/src/algorithms/intersect/curve_edge.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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)?;
Expand All @@ -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,
Expand All @@ -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,
Expand All @@ -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)?;
Expand Down
18 changes: 8 additions & 10 deletions crates/fj-kernel/src/algorithms/intersect/surface_surface.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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)?,
Expand Down
9 changes: 4 additions & 5 deletions crates/fj-kernel/src/algorithms/sweep/vertex.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
7 changes: 3 additions & 4 deletions crates/fj-kernel/src/builder/curve.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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 {
Expand Down
18 changes: 8 additions & 10 deletions crates/fj-kernel/src/iter.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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());
Expand Down Expand Up @@ -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.]))?;
Expand Down
36 changes: 19 additions & 17 deletions crates/fj-kernel/src/validate/vertex.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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(),
Expand All @@ -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(),
Expand Down

0 comments on commit 7e5500a

Please sign in to comment.