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