Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 9 additions & 0 deletions crates/difftest/src/units/boolean_merge_p2.rs
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@ use solidcore::geom::object::{NotifyOperation, ObjectRef};
use solidcore::heal::stitch::p1::{DefaultStitchCallback, Stitch};
use solidcore::kernel::Kernel;
use solidcore::topology;
use solidcore::topology::brep_cache::{arena_identity, CacheObject};
use solidcore::topology::topology::Topology;
use solidcore::topology::topology_traverser::Marks;
use solidcore::topology::{
Expand Down Expand Up @@ -637,6 +638,14 @@ fn run_rust(i: &Inputs, p: &Prepared) -> Result<Output, HarnessError> {
let edge_dest = |e: EdgeId| key(2_000_000, edge::TYPE, e.index());
let face_source = |f: FaceId| key(5_000_000, face::p2::TYPE, f.index());
let face_dest = |f: FaceId| key(4_000_000, face::p2::TYPE, f.index());
// The operands' edges and faces own their curves and surfaces under these
// names, as the library names them (`MakeFace`'s infinite-region rays solve
// on a B-rep cache whose trees hold only geometry owned under them).
let brep = Some(arena_identity(CacheObject::Brep));
crate::util::own_edge_curves(&mut a, &edge_dest, brep);
crate::util::own_face_surfaces(&mut a, &face_dest);
crate::util::own_edge_curves(b, &edge_source, brep);
crate::util::own_face_surfaces(b, &face_source);
let mut copy = TopologyCopy {
vertices: VertexCopy {
records: &mut records,
Expand Down
5 changes: 5 additions & 0 deletions crates/difftest/src/units/topology_brep_p6.rs
Original file line number Diff line number Diff line change
Expand Up @@ -927,6 +927,11 @@ fn make_faces_rust(i: &Inputs) -> Result<Output, HarnessError> {
counts(&fixture.graph).ok_or_else(|| harness("fixture construction failed"))?;
let (mut b, _) = shared::import(&fixture.graph)?;
b.set_key(ObjectKey(0xB000_0000));
// The fixture's edges own their curves, as its faces own their surfaces (the import
// gives those the face names of `key_of`). The ray fires of the infinite-region
// search find an edge from its curve's owner, under the runner's names.
let brep = solidcore::topology::brep::p2::brep_ref(&b);
crate::util::own_edge_curves(&mut b, &|e| key_of(EntityRef::Edge(e)), Some(brep));
let resolved = resolve(i, &b)?;
let mut records = seeded_records(&b);
let mut attributes = AttributeStore::default();
Expand Down
32 changes: 26 additions & 6 deletions crates/difftest/src/util.rs
Original file line number Diff line number Diff line change
@@ -1,8 +1,9 @@
//! Small conversions shared by the unit runners in [`crate::units`].

use solidcore::geom::object::ObjectRef;
use solidcore::math::{Point2, Vec3};
use solidcore::topology::brep_cache::{arena_identity, CacheObject};
use solidcore::topology::Brep;
use solidcore::topology::{Brep, EdgeId, FaceId};

/// A JSON `[x, y, z]` as a [`Vec3`].
#[must_use]
Expand Down Expand Up @@ -182,19 +183,38 @@ fn nurb_bits(b: &solidcore::nurbs::b_spline_surface::BSplineSurface) -> Option<V
/// B-rep's geometry has (its edge or face, by [`arena_identity`]; curves also the
/// B-rep), which the B-rep cache solves read (the import leaves geometry unowned).
pub fn own_arena_geometry(b: &mut Brep) {
own_edge_curves(
b,
&|id| arena_identity(CacheObject::Edge(id)),
Some(arena_identity(CacheObject::Brep)),
);
own_face_surfaces(b, &|id| arena_identity(CacheObject::Face(id)));
}

/// Gives every edge curve of an imported B-rep its edge as owner, under `edge_key`:
/// the name the runner hands the library for that edge (its `key_of` or cache keys).
/// The topology solver's B-rep trees and edge lookups compare owners with those names;
/// `brep` is the owner edge's B-rep as `Curve::set_owner` takes it.
pub fn own_edge_curves(
b: &mut Brep,
edge_key: &dyn Fn(EdgeId) -> ObjectRef,
brep: Option<ObjectRef>,
) {
let edges: Vec<_> = b.edges().ids().collect();
for id in edges {
if let Some(curve) = b.edge_mut(id).ok().and_then(|e| e.curve.as_mut()) {
let _ = curve.set_owner(
Some(arena_identity(CacheObject::Edge(id))),
Some(arena_identity(CacheObject::Brep)),
);
let _ = curve.set_owner(Some(edge_key(id)), brep);
}
}
}

/// Gives every face surface of an imported B-rep its face as owner, under `face_key`
/// (as [`own_edge_curves`] for edges).
pub fn own_face_surfaces(b: &mut Brep, face_key: &dyn Fn(FaceId) -> ObjectRef) {
let faces: Vec<_> = b.faces().ids().collect();
for id in faces {
if let Some(surface) = b.face_mut(id).ok().and_then(|f| f.surface.as_mut()) {
let _ = surface.set_owner(Some(arena_identity(CacheObject::Face(id))));
let _ = surface.set_owner(Some(face_key(id)));
}
}
}
Loading