Use `iter_fixed` to zip arrays

This is a bit more verbose, but it gives us support for zipping arrays
of arbitrary sizes.
This commit is contained in:
Hanno Braun 2022-11-11 12:20:07 +01:00
parent 647777ebee
commit 27b0b202c7
5 changed files with 41 additions and 20 deletions

View File

@ -1,4 +1,5 @@
use fj_interop::ext::ArrayExt; use fj_interop::ext::ArrayExt;
use iter_fixed::IntoIteratorFixed;
use crate::{ use crate::{
objects::{Curve, Face, Objects}, objects::{Curve, Face, Objects},
@ -41,8 +42,10 @@ impl FaceFaceIntersection {
let curve_face_intersections = intersection_curves let curve_face_intersections = intersection_curves
.each_ref_ext() .each_ref_ext()
.zip_ext(faces) .into_iter_fixed()
.map(|(curve, face)| CurveFaceIntersection::compute(curve, face)); .zip(faces)
.map(|(curve, face)| CurveFaceIntersection::compute(curve, face))
.collect::<[_; 2]>();
let intersection_intervals = { let intersection_intervals = {
let [a, b] = curve_face_intersections; let [a, b] = curve_face_intersections;

View File

@ -1,5 +1,6 @@
use fj_interop::{ext::ArrayExt, mesh::Color}; use fj_interop::{ext::ArrayExt, mesh::Color};
use fj_math::{Line, Scalar, Vector}; use fj_math::{Line, Scalar, Vector};
use iter_fixed::IntoIteratorFixed;
use crate::{ use crate::{
algorithms::{reverse::Reverse, transform::TransformObject}, algorithms::{reverse::Reverse, transform::TransformObject},
@ -65,7 +66,9 @@ impl Sweep for (Handle<HalfEdge>, Color) {
vertices vertices
.each_ref_ext() .each_ref_ext()
.zip_ext(points_surface) .into_iter_fixed()
.zip(points_surface)
.collect::<[_; 2]>()
.try_map_ext( .try_map_ext(
|(vertex, point_surface)| -> Result<_, ValidationError> { |(vertex, point_surface)| -> Result<_, ValidationError> {
let surface_vertex = objects.surface_vertices.insert( let surface_vertex = objects.surface_vertices.insert(
@ -135,7 +138,9 @@ impl Sweep for (Handle<HalfEdge>, Color) {
let vertices = bottom_vertices let vertices = bottom_vertices
.each_ref_ext() .each_ref_ext()
.zip_ext(surface_vertices) .into_iter_fixed()
.zip(surface_vertices)
.collect::<[_; 2]>()
.try_map_ext(|(vertex, surface_form)| { .try_map_ext(|(vertex, surface_form)| {
objects.vertices.insert(Vertex::new( objects.vertices.insert(Vertex::new(
vertex.position(), vertex.position(),

View File

@ -1,5 +1,5 @@
use fj_interop::ext::ArrayExt;
use fj_math::{Point, Scalar}; use fj_math::{Point, Scalar};
use iter_fixed::IntoIteratorFixed;
use crate::{ use crate::{
insert::Insert, insert::Insert,
@ -187,17 +187,21 @@ impl HalfEdgeBuilder for PartialHalfEdge {
.unwrap_or([None, None]) .unwrap_or([None, None])
}; };
vertices.zip_ext(global_forms).map(|(vertex, global_form)| { vertices
vertex.update_partial(|vertex| { .into_iter_fixed()
vertex.clone().with_surface_form( .zip(global_forms)
vertex.surface_form().update_partial( .collect::<[_; 2]>()
|surface_vertex| { .map(|(vertex, global_form)| {
surface_vertex.with_global_form(global_form) vertex.update_partial(|vertex| {
}, vertex.clone().with_surface_form(
), vertex.surface_form().update_partial(
) |surface_vertex| {
surface_vertex.with_global_form(global_form)
},
),
)
})
}) })
})
}; };
self.with_curve(curve).with_vertices([back, front]) self.with_curve(curve).with_vertices([back, front])

View File

@ -2,6 +2,7 @@ use std::array;
use fj_interop::ext::{ArrayExt, SliceExt}; use fj_interop::ext::{ArrayExt, SliceExt};
use fj_math::Scalar; use fj_math::Scalar;
use iter_fixed::IntoIteratorFixed;
use crate::{ use crate::{
algorithms::transform::TransformObject, algorithms::transform::TransformObject,
@ -235,8 +236,11 @@ impl<'a> ShellBuilder<'a> {
let mut edges = top_edges.iter(); let mut edges = top_edges.iter();
let half_edges = array::from_fn(|_| edges.next().unwrap()); let half_edges = array::from_fn(|_| edges.next().unwrap());
let [a, b, c, d] = let [a, b, c, d] = points
points.zip_ext(half_edges).map(|(point, edge)| { .into_iter_fixed()
.zip(half_edges)
.collect::<[_; 4]>()
.map(|(point, edge)| {
let vertex = edge.back(); let vertex = edge.back();
SurfaceVertex::partial() SurfaceVertex::partial()
@ -263,7 +267,9 @@ impl<'a> ShellBuilder<'a> {
let vertices = edge let vertices = edge
.vertices() .vertices()
.each_ref_ext() .each_ref_ext()
.zip_ext(surface_vertices.clone()) .into_iter_fixed()
.zip(surface_vertices.clone())
.collect::<[_; 2]>()
.map(|(vertex, surface_form)| { .map(|(vertex, surface_form)| {
Vertex::partial() Vertex::partial()
.with_position(Some(vertex.position())) .with_position(Some(vertex.position()))

View File

@ -1,4 +1,4 @@
use fj_interop::ext::ArrayExt; use iter_fixed::IntoIteratorFixed;
use super::{HasPartial, MaybePartial}; use super::{HasPartial, MaybePartial};
@ -22,5 +22,8 @@ pub fn merge_arrays<T: HasPartial>(
a: [MaybePartial<T>; 2], a: [MaybePartial<T>; 2],
b: [MaybePartial<T>; 2], b: [MaybePartial<T>; 2],
) -> [MaybePartial<T>; 2] { ) -> [MaybePartial<T>; 2] {
a.zip_ext(b).map(|(a, b)| a.merge_with(b)) a.into_iter_fixed()
.zip(b)
.collect::<[_; 2]>()
.map(|(a, b)| a.merge_with(b))
} }