-
Notifications
You must be signed in to change notification settings - Fork 31
/
SenseEvaluator.hh
85 lines (76 loc) · 2.72 KB
/
SenseEvaluator.hh
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
//----------------------------------*-C++-*----------------------------------//
// Copyright 2024 UT-Battelle, LLC, and other Celeritas developers.
// See the top-level COPYRIGHT file for details.
// SPDX-License-Identifier: (Apache-2.0 OR MIT)
//---------------------------------------------------------------------------//
//! \file orange/orangeinp/detail/SenseEvaluator.hh
//---------------------------------------------------------------------------//
#pragma once
#include "corecel/cont/VariantUtils.hh"
#include "orange/OrangeTypes.hh"
#include "orange/surf/VariantSurface.hh"
#include "../CsgTree.hh"
namespace celeritas
{
namespace orangeinp
{
namespace detail
{
//---------------------------------------------------------------------------//
/*!
* Evaluate whether a point is inside a CSG tree node.
*
* This is a construction-time helper that combines \c SenseCalculator with \c
* LogicEvaluator. Its intended use is primarily for testing.
*/
class SenseEvaluator
{
public:
//!@{
//! \name Type aliases
using result_type = SignedSense;
using VecSurface = std::vector<VariantSurface>;
//!@}
public:
// Construct with a CSG tree, surfaces, and a point
inline SenseEvaluator(CsgTree const& tree,
VecSurface const& surfaces,
Real3 const& pos);
//! Visit from a node ID
result_type operator()(NodeId const& n) const;
//!@{
//! \name Visit a node directly
//! Point is always inside
result_type operator()(True const&) const { return SignedSense::inside; }
//! Point is always outside
result_type operator()(False const&) const { return SignedSense::outside; }
// Evaluate a surface
result_type operator()(Surface const&) const;
// Redirect an alias
result_type operator()(Aliased const&) const;
// Negate the daughter result
result_type operator()(Negated const&) const;
// Visit daughter nodes using short circuit logic
result_type operator()(Joined const&) const;
//!@}
private:
ContainerVisitor<CsgTree const&, NodeId> visit_node_;
VecSurface const& surfaces_;
Real3 pos_;
};
//---------------------------------------------------------------------------//
// INLINE DEFINITIONS
//---------------------------------------------------------------------------//
/*!
* Construct with a CSG tree and the position to test.
*/
SenseEvaluator::SenseEvaluator(CsgTree const& tree,
VecSurface const& surfaces,
Real3 const& pos)
: visit_node_{tree}, surfaces_{surfaces}, pos_{pos}
{
}
//---------------------------------------------------------------------------//
} // namespace detail
} // namespace orangeinp
} // namespace celeritas