mirror of
https://github.com/hannobraun/Fornjot
synced 2025-05-08 11:58:27 +00:00
Merge pull request #2301 from hannobraun/approx
Remove color from `FaceApprox`
This commit is contained in:
commit
cb00617258
@ -4,10 +4,8 @@
|
|||||||
|
|
||||||
use std::{collections::BTreeSet, ops::Deref};
|
use std::{collections::BTreeSet, ops::Deref};
|
||||||
|
|
||||||
use fj_interop::Color;
|
|
||||||
|
|
||||||
use crate::{
|
use crate::{
|
||||||
operations::presentation::GetColor,
|
storage::Handle,
|
||||||
topology::{Face, Handedness, ObjectSet},
|
topology::{Face, Handedness, ObjectSet},
|
||||||
validation::ValidationConfig,
|
validation::ValidationConfig,
|
||||||
Core,
|
Core,
|
||||||
@ -32,7 +30,7 @@ impl Approx for &ObjectSet<Face> {
|
|||||||
|
|
||||||
let approx = self
|
let approx = self
|
||||||
.into_iter()
|
.into_iter()
|
||||||
.map(|face| face.approx_with_cache(tolerance, cache, core))
|
.map(|face| face.clone().approx_with_cache(tolerance, cache, core))
|
||||||
.collect();
|
.collect();
|
||||||
|
|
||||||
let min_distance = ValidationConfig::default().distinct_min_distance;
|
let min_distance = ValidationConfig::default().distinct_min_distance;
|
||||||
@ -65,7 +63,7 @@ impl Approx for &ObjectSet<Face> {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
impl Approx for &Face {
|
impl Approx for Handle<Face> {
|
||||||
type Approximation = FaceApprox;
|
type Approximation = FaceApprox;
|
||||||
type Cache = HalfEdgeApproxCache;
|
type Cache = HalfEdgeApproxCache;
|
||||||
|
|
||||||
@ -100,11 +98,12 @@ impl Approx for &Face {
|
|||||||
interiors.insert(cycle);
|
interiors.insert(cycle);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
let coord_handedness = self.coord_handedness(&core.layers.geometry);
|
||||||
FaceApprox {
|
FaceApprox {
|
||||||
|
face: self,
|
||||||
exterior,
|
exterior,
|
||||||
interiors,
|
interiors,
|
||||||
color: self.region().get_color(core),
|
coord_handedness,
|
||||||
coord_handedness: self.coord_handedness(&core.layers.geometry),
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -112,15 +111,15 @@ impl Approx for &Face {
|
|||||||
/// An approximation of a [`Face`]
|
/// An approximation of a [`Face`]
|
||||||
#[derive(Debug, Eq, PartialEq, Ord, PartialOrd)]
|
#[derive(Debug, Eq, PartialEq, Ord, PartialOrd)]
|
||||||
pub struct FaceApprox {
|
pub struct FaceApprox {
|
||||||
|
/// The [`Face`], that this approximates
|
||||||
|
pub face: Handle<Face>,
|
||||||
|
|
||||||
/// Approximation of the exterior cycle
|
/// Approximation of the exterior cycle
|
||||||
pub exterior: CycleApprox,
|
pub exterior: CycleApprox,
|
||||||
|
|
||||||
/// Approximations of the interior cycles
|
/// Approximations of the interior cycles
|
||||||
pub interiors: BTreeSet<CycleApprox>,
|
pub interiors: BTreeSet<CycleApprox>,
|
||||||
|
|
||||||
/// The color of the approximated face
|
|
||||||
pub color: Option<Color>,
|
|
||||||
|
|
||||||
/// The handedness of the approximated face's front-side coordinate system
|
/// The handedness of the approximated face's front-side coordinate system
|
||||||
pub coord_handedness: Handedness,
|
pub coord_handedness: Handedness,
|
||||||
}
|
}
|
||||||
|
@ -6,7 +6,7 @@ mod polygon;
|
|||||||
use fj_interop::Mesh;
|
use fj_interop::Mesh;
|
||||||
use fj_math::Point;
|
use fj_math::Point;
|
||||||
|
|
||||||
use crate::Core;
|
use crate::{operations::presentation::GetColor, Core};
|
||||||
|
|
||||||
use self::polygon::Polygon;
|
use self::polygon::Polygon;
|
||||||
|
|
||||||
@ -45,11 +45,7 @@ where
|
|||||||
}
|
}
|
||||||
|
|
||||||
impl Triangulate for FaceApprox {
|
impl Triangulate for FaceApprox {
|
||||||
fn triangulate_into_mesh(
|
fn triangulate_into_mesh(self, mesh: &mut Mesh<Point<3>>, core: &mut Core) {
|
||||||
self,
|
|
||||||
mesh: &mut Mesh<Point<3>>,
|
|
||||||
_core: &mut Core,
|
|
||||||
) {
|
|
||||||
let face_as_polygon = Polygon::new()
|
let face_as_polygon = Polygon::new()
|
||||||
.with_exterior(
|
.with_exterior(
|
||||||
self.exterior
|
self.exterior
|
||||||
@ -69,7 +65,7 @@ impl Triangulate for FaceApprox {
|
|||||||
.contains_triangle(triangle.map(|point| point.point_surface))
|
.contains_triangle(triangle.map(|point| point.point_surface))
|
||||||
});
|
});
|
||||||
|
|
||||||
let color = self.color.unwrap_or_default();
|
let color = self.face.region().get_color(core).unwrap_or_default();
|
||||||
|
|
||||||
for triangle in triangles {
|
for triangle in triangles {
|
||||||
let points = triangle.map(|point| point.point_global);
|
let points = triangle.map(|point| point.point_global);
|
||||||
@ -87,8 +83,10 @@ mod tests {
|
|||||||
algorithms::approx::{Approx, Tolerance},
|
algorithms::approx::{Approx, Tolerance},
|
||||||
operations::{
|
operations::{
|
||||||
build::{BuildCycle, BuildFace},
|
build::{BuildCycle, BuildFace},
|
||||||
|
insert::Insert,
|
||||||
update::{UpdateFace, UpdateRegion},
|
update::{UpdateFace, UpdateRegion},
|
||||||
},
|
},
|
||||||
|
storage::Handle,
|
||||||
topology::{Cycle, Face},
|
topology::{Cycle, Face},
|
||||||
Core,
|
Core,
|
||||||
};
|
};
|
||||||
@ -114,7 +112,8 @@ mod tests {
|
|||||||
)
|
)
|
||||||
},
|
},
|
||||||
&mut core,
|
&mut core,
|
||||||
);
|
)
|
||||||
|
.insert(&mut core);
|
||||||
|
|
||||||
let a = Point::from(a).to_xyz();
|
let a = Point::from(a).to_xyz();
|
||||||
let b = Point::from(b).to_xyz();
|
let b = Point::from(b).to_xyz();
|
||||||
@ -147,17 +146,22 @@ mod tests {
|
|||||||
|
|
||||||
let surface = core.layers.topology.surfaces.xy_plane();
|
let surface = core.layers.topology.surfaces.xy_plane();
|
||||||
|
|
||||||
let face = Face::unbound(surface.clone(), &mut core).update_region(
|
let face = Face::unbound(surface.clone(), &mut core)
|
||||||
|region, core| {
|
.update_region(
|
||||||
region
|
|region, core| {
|
||||||
.update_exterior(
|
region
|
||||||
|_, core| Cycle::polygon([a, b, c, d], core),
|
.update_exterior(
|
||||||
core,
|
|_, core| Cycle::polygon([a, b, c, d], core),
|
||||||
)
|
core,
|
||||||
.add_interiors([Cycle::polygon([e, f, g, h], core)], core)
|
)
|
||||||
},
|
.add_interiors(
|
||||||
&mut core,
|
[Cycle::polygon([e, f, g, h], core)],
|
||||||
);
|
core,
|
||||||
|
)
|
||||||
|
},
|
||||||
|
&mut core,
|
||||||
|
)
|
||||||
|
.insert(&mut core);
|
||||||
|
|
||||||
let triangles = triangulate(face, &mut core)?;
|
let triangles = triangulate(face, &mut core)?;
|
||||||
|
|
||||||
@ -236,15 +240,17 @@ mod tests {
|
|||||||
|
|
||||||
let surface = core.layers.topology.surfaces.xy_plane();
|
let surface = core.layers.topology.surfaces.xy_plane();
|
||||||
|
|
||||||
let face = Face::unbound(surface.clone(), &mut core).update_region(
|
let face = Face::unbound(surface.clone(), &mut core)
|
||||||
|region, core| {
|
.update_region(
|
||||||
region.update_exterior(
|
|region, core| {
|
||||||
|_, core| Cycle::polygon([a, b, c, d, e], core),
|
region.update_exterior(
|
||||||
core,
|
|_, core| Cycle::polygon([a, b, c, d, e], core),
|
||||||
)
|
core,
|
||||||
},
|
)
|
||||||
&mut core,
|
},
|
||||||
);
|
&mut core,
|
||||||
|
)
|
||||||
|
.insert(&mut core);
|
||||||
|
|
||||||
let triangles = triangulate(face, &mut core)?;
|
let triangles = triangulate(face, &mut core)?;
|
||||||
|
|
||||||
@ -282,7 +288,7 @@ mod tests {
|
|||||||
}
|
}
|
||||||
|
|
||||||
fn triangulate(
|
fn triangulate(
|
||||||
face: Face,
|
face: Handle<Face>,
|
||||||
core: &mut Core,
|
core: &mut Core,
|
||||||
) -> anyhow::Result<Mesh<Point<3>>> {
|
) -> anyhow::Result<Mesh<Point<3>>> {
|
||||||
let tolerance = Tolerance::from_scalar(Scalar::ONE)?;
|
let tolerance = Tolerance::from_scalar(Scalar::ONE)?;
|
||||||
|
Loading…
Reference in New Issue
Block a user