Skip to content

Commit

Permalink
Deduplicate transforms on insertion
Browse files Browse the repository at this point in the history
  • Loading branch information
sethrj committed Mar 2, 2024
1 parent 675ce05 commit 31d19f2
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 17 deletions.
11 changes: 11 additions & 0 deletions src/orange/orangeinp/detail/CsgUnitBuilder.cc
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
#include "corecel/io/Logger.hh"
#include "corecel/io/StreamableVariant.hh"
#include "orange/transform/TransformIO.hh"
#include "orange/transform/TransformSimplifier.hh"

namespace celeritas
{
Expand Down Expand Up @@ -49,6 +50,16 @@ BoundingZone const& CsgUnitBuilder::bounds(NodeId nid) const
return iter->second.bounds;
}

//---------------------------------------------------------------------------//
/*!
* Insert transform with simplification and deduplication.
*/
TransformId CsgUnitBuilder::insert_transform(VariantTransform const& vt)
{
auto simplified = std::visit(TransformSimplifier(tol_), vt);
return this->insert_transform_(std::move(simplified));
}

//---------------------------------------------------------------------------//
/*!
* Set a bounding zone and transform for a node.
Expand Down
11 changes: 1 addition & 10 deletions src/orange/orangeinp/detail/CsgUnitBuilder.hh
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,7 @@ class CsgUnitBuilder
inline NodeInsertion insert_csg(Args&&... args);

// Insert a transform
inline TransformId insert_transform(VariantTransform&& vt);
TransformId insert_transform(VariantTransform const& vt);

// Insert node metadata
inline void insert_md(NodeId node, Metadata&& md);
Expand Down Expand Up @@ -173,15 +173,6 @@ auto CsgUnitBuilder::insert_csg(Args&&... args) -> NodeInsertion
return result;
}

//---------------------------------------------------------------------------//
/*!
* Insert transform with deduplication.
*/
TransformId CsgUnitBuilder::insert_transform(VariantTransform&& vt)
{
return this->insert_transform_(std::move(vt));
}

//---------------------------------------------------------------------------//
/*!
* Insert node metadata.
Expand Down
9 changes: 2 additions & 7 deletions test/orange/orangeinp/Transformed.test.cc
Original file line number Diff line number Diff line change
Expand Up @@ -159,12 +159,7 @@ TEST_F(TransformedTest, inverse)
this->build_volume(Transformed{
transformed,
Transformation{make_rotation(Axis::x, Turn{0.25}), {0, 0, -2}}});
static char const* const expected_log_messages[] = {
"While re-inserting region for node 7: existing transform {} "
"differs from new transform {{{1,0,0},{0,1,0},{0,0,1}}, {0,0,0}}"};
EXPECT_VEC_EQ(expected_log_messages, scoped_log_.messages());
static char const* const expected_log_levels[] = {"warning"};
EXPECT_VEC_EQ(expected_log_levels, scoped_log_.levels());
EXPECT_TRUE(scoped_log_.empty()) << scoped_log_;
}

static char const* const expected_surface_strings[] = {
Expand Down Expand Up @@ -218,7 +213,7 @@ TEST_F(TransformedTest, deduplicated_inverse)
= {"Sphere: r=2", "Sphere: r=1"};
static char const* const expected_volume_strings[] = {"-0", "-1"};
static char const* const expected_trans_strings[]
= {"3: t=0 -> {}", "5: t=2 -> {{{1,0,0},{0,1,0},{0,0,1}}, {0,0,0}}"};
= {"3: t=0 -> {}", "5: t=0"};
static int const expected_volume_nodes[] = {3, 5};

auto const& u = this->unit();
Expand Down

0 comments on commit 31d19f2

Please sign in to comment.