mirror of https://github.com/hannobraun/Fornjot
Implement `UpdateFace` for `Polygon`
This commit is contained in:
parent
d7b4fcab94
commit
761f9eff14
|
@ -1,5 +1,8 @@
|
||||||
|
use std::array;
|
||||||
|
|
||||||
use crate::{
|
use crate::{
|
||||||
objects::{Cycle, Face},
|
objects::{Cycle, Face},
|
||||||
|
operations::Polygon,
|
||||||
storage::Handle,
|
storage::Handle,
|
||||||
};
|
};
|
||||||
|
|
||||||
|
@ -47,3 +50,41 @@ impl UpdateFace for Face {
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
impl<const D: usize> UpdateFace for Polygon<D> {
|
||||||
|
fn update_exterior(
|
||||||
|
&self,
|
||||||
|
f: impl FnOnce(&Handle<Cycle>) -> Handle<Cycle>,
|
||||||
|
) -> Self {
|
||||||
|
let face = self.face.update_exterior(f);
|
||||||
|
let edges = array::from_fn(|i| {
|
||||||
|
face.exterior()
|
||||||
|
.nth_half_edge(i)
|
||||||
|
.expect("Operation should not have changed length of cycle")
|
||||||
|
.clone()
|
||||||
|
});
|
||||||
|
let vertices = array::from_fn(|i| {
|
||||||
|
// The duplicated code here is unfortunate, but unless we get a
|
||||||
|
// stable `array::each_ref` and something like `array::unzip`, I'm
|
||||||
|
// not sure how to avoid it.
|
||||||
|
face.exterior()
|
||||||
|
.nth_half_edge(i)
|
||||||
|
.expect("Operation should not have changed length of cycle")
|
||||||
|
.start_vertex()
|
||||||
|
.clone()
|
||||||
|
});
|
||||||
|
|
||||||
|
Polygon {
|
||||||
|
face,
|
||||||
|
edges,
|
||||||
|
vertices,
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
fn add_interiors(
|
||||||
|
&self,
|
||||||
|
_: impl IntoIterator<Item = Handle<Cycle>>,
|
||||||
|
) -> Self {
|
||||||
|
panic!("Adding interiors to `Polygon` is not supported.")
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
Loading…
Reference in New Issue