Convert free function into constructor

This commit is contained in:
Hanno Braun 2025-04-14 13:50:13 +02:00
parent 05b53189bf
commit 463b458bc1

View File

@ -38,7 +38,7 @@ impl Sketch {
let VerticesFromSegments { let VerticesFromSegments {
vertices, vertices,
coincident_vertices, coincident_vertices,
} = vertices_from_segments(&self.segments, &surface); } = VerticesFromSegments::new(&self.segments, &surface);
let half_edges = vertices.into_iter().circular_tuple_windows().map( let half_edges = vertices.into_iter().circular_tuple_windows().map(
|(start, end)| { |(start, end)| {
@ -81,38 +81,38 @@ struct VerticesFromSegments {
coincident_vertices: BTreeSet<Handle<Vertex>>, coincident_vertices: BTreeSet<Handle<Vertex>>,
} }
fn vertices_from_segments( impl VerticesFromSegments {
segments: &[SketchSegment], fn new(segments: &[SketchSegment], surface: &Handle<Surface>) -> Self {
surface: &Handle<Surface>, let mut vertices_by_local_point: BTreeMap<_, Vec<_>> = BTreeMap::new();
) -> VerticesFromSegments { let mut coincident_vertices = BTreeSet::new();
let mut vertices_by_local_point: BTreeMap<_, Vec<_>> = BTreeMap::new();
let mut coincident_vertices = BTreeSet::new();
let vertices = segments let vertices = segments
.iter() .iter()
.map(SketchSegment::start) .map(SketchSegment::start)
.copied() .copied()
.map(|point_local| { .map(|point_local| {
let point_global = surface.geometry.point_from_local(point_local); let point_global =
let vertex = Handle::new(Vertex::new(point_global)); surface.geometry.point_from_local(point_local);
let vertex = Handle::new(Vertex::new(point_global));
vertices_by_local_point vertices_by_local_point
.entry(point_local) .entry(point_local)
.or_default() .or_default()
.push(vertex.clone()); .push(vertex.clone());
vertex vertex
}) })
.collect::<Vec<_>>(); .collect::<Vec<_>>();
for vertices in vertices_by_local_point.into_values() { for vertices in vertices_by_local_point.into_values() {
if vertices.len() > 1 { if vertices.len() > 1 {
coincident_vertices.extend(vertices); coincident_vertices.extend(vertices);
}
}
VerticesFromSegments {
vertices,
coincident_vertices,
} }
} }
VerticesFromSegments {
vertices,
coincident_vertices,
}
} }