11 #ifndef LARCOREALG_GEOMETRY_SIMPLEGEO_H 12 #define LARCOREALG_GEOMETRY_SIMPLEGEO_H 45 namespace simple_geo {
51 template <
typename Data =
double>
65 {
return (a.
x == b.
x) && (a.
y == b.
y); }
68 {
return (a.
x != b.
x) || (a.
y != b.
y); }
71 {
return { a.
x + b.
x, a.
y + b.
y }; }
74 {
return { p.
x *
f, p.
y * f }; }
77 {
return { p.
x /
f, p.
y / f }; }
78 template <
typename Stream,
typename T>
79 Stream& operator<< (Stream&& out, Point2D<T>
const& p)
80 { out <<
"( " << p.
x <<
" ; " << p.y <<
" )";
return out; }
84 template <
typename Data =
double>
98 {
return (a.
x == b.
x) && (a.
y == b.
y) && (a.
z == b.
z); }
101 {
return (a.
x != b.
x) || (a.
y != b.
y) || (a.
z != b.
z); }
102 template <
typename T>
104 {
return { a.
x + b.
x, a.
y + b.
y, a.
z + b.
z }; }
105 template <
typename T>
107 {
return { p.
x *
f, p.
y *
f, p.
z * f }; }
108 template <
typename T>
110 {
return { p.
x /
f, p.
y /
f, p.
z / f }; }
111 template <
typename Stream,
typename T>
112 Stream& operator<< (Stream&& out, Point3D<T>
const& p)
114 out <<
"( " << p.
x <<
" ; " << p.y <<
" ; " << p.z <<
" )";
124 template <
typename Po
int>
132 {
using std::runtime_error::runtime_error; };
138 { set_sorted(
min.x,
max.x, a.x, b.x); }
144 auto DeltaX()
const {
return Max().x - Min().x; }
146 bool isNullX()
const {
return Max().x < Min().x; }
147 bool isNull()
const {
return isNullX(); }
149 bool isEmpty()
const {
return nonEmptyDims() == 0; }
150 bool isLine()
const {
return nonEmptyDims() == 1; }
158 { set_min_max(
min.x,
max.x, point.x); }
161 { IncludePoint(area.
min); IncludePoint(area.
max); }
165 set_max(
min.x, area.
min.x);
166 set_min(
max.x, area.
max.x);
181 {
if (val < var) var = val; }
184 {
if (val > var) var = val; }
187 { set_min(min_var, val); set_max(max_var, val); }
189 static void set_sorted
192 if (a > b) { min_var = b; max_var = a; }
193 else { min_var = a; max_var = b; }
200 template <
typename Po
int = Po
int2D<
double>>
214 auto DeltaY()
const {
return Base_t::Max().y - Base_t::Min().y; }
217 {
return Base_t::nonEmptyDims() + (isEmptyY()? 0: 1); }
218 bool isNullY()
const {
return Base_t::Max().y < Base_t::Min().y; }
219 bool isNull()
const {
return Base_t::isNull() || isNullY(); }
220 bool isEmpty()
const {
return nonEmptyDims() == 0; }
221 bool isLine()
const {
return nonEmptyDims() == 1; }
222 bool isPlane()
const {
return nonEmptyDims() == 2; }
225 {
return std::min(DeltaY(), Base_t::thinnestSize()); }
231 (DeltaY() < Base_t::thinnestSize())? 1: Base_t::thinnestSide();
236 Base_t::IncludePoint(point);
241 { IncludePoint(area.
min); IncludePoint(area.
max); }
245 Base_t::Intersect(area);
254 template <
typename Stream,
typename Po
int>
255 Stream& operator<< (Stream&& out, AreaBase<Point>
const& area)
256 { out << area.Min() <<
" - " << area.Max();
return out; }
260 template <
typename Po
int = Po
int3D<
double>>
274 auto DeltaZ()
const {
return Base_t::Max().z - Base_t::Min().z; }
277 {
return Base_t::nonEmptyDims() + (isEmptyZ()? 0: 1); }
278 bool isNullZ()
const {
return Base_t::Max().z < Base_t::Min().z; }
279 bool isNull()
const {
return Base_t::isNull() || isNullZ(); }
280 bool isEmpty()
const {
return nonEmptyDims() == 0; }
281 bool isLine()
const {
return nonEmptyDims() == 1; }
282 bool isPlane()
const {
return nonEmptyDims() == 2; }
283 bool isVolume()
const {
return nonEmptyDims() == 3; }
286 {
return std::min(DeltaZ(), Base_t::thinnestSize()); }
292 (DeltaZ() < Base_t::thinnestSize())? 2: Base_t::thinnestSide();
297 Base_t::IncludePoint(point);
302 { IncludePoint(volume.
min); IncludePoint(volume.
max); }
306 Base_t::Intersect(volume);
321 template <
typename Data =
double>
334 : lower(lower), upper(upper)
335 {
if (doSort) sort(); }
338 bool isNull()
const {
return lower >= upper; }
347 bool overlaps(
Range_t const& r)
const;
354 void extendToInclude(
Data_t);
357 void extendToInclude(
Range_t const& r);
360 void intersect(
Range_t const& r);
364 void sort() {
if (lower > upper) std::swap(lower, upper); }
372 template <
typename Stream,
typename Data>
373 Stream& operator<< (Stream&& out, Range<Data>
const& range);
387 template <
typename Data =
double>
401 : width(width), depth(depth)
420 template <
typename Stream,
typename Data>
421 Stream& operator<< (Stream&& out, Rectangle<Data>
const& rect);
441 template <
typename Data>
447 if (v < (lower + margin))
return lower + margin - v;
448 if (v > (upper - margin))
return upper - margin - v;
455 template <
typename Data>
458 if (lower > upper) lower = upper = v;
459 else if (lower > v) lower = v;
460 else if (upper < v) upper = v;
466 template <
typename Data>
474 extendToInclude(r.
lower);
475 extendToInclude(r.
upper);
481 template <
typename Data>
485 if (isNull())
return;
492 if (lower > upper) makeNull();
497 template <
typename Data>
499 if (isNull() || r.
isNull())
return false;
500 return (r.
lower < upper) && (lower < r.
upper);
505 template <
typename Stream,
typename Data>
506 Stream& lar::util::simple_geo::operator<<
509 out <<
"( " << range.lower <<
" -- " << range.upper <<
" )";
515 template <
typename Data>
519 width.extendToInclude(r.
width);
520 depth.extendToInclude(r.
depth);
525 template <
typename Data>
529 if (isNull() || r.
isNull())
return false;
530 return width.overlap(r.
width) && depth.overlap(r.
depth);
535 template <
typename Stream,
typename Data>
536 Stream& lar::util::simple_geo::operator<<
539 out <<
"w=" << rect.width <<
" d=" << rect.depth;
547 #endif // LARCOREALG_GEOMETRY_SIMPLEGEO_H
unsigned int nonEmptyDims() const
Namespace for general, non-LArSoft-specific utilities.
AreaBase(Point_t const &a, Point_t const &b)
2D point (x, y) (by default, with double precision)
Definition of a range along one dimension.
void Intersect(Area_t const &area)
auto thinnestSize() const
Point_t const & Min() const
void sort()
Ensures order of boundaries. Corrupts invalid ranges.
Point2D< T > operator/(Point2D< T > const &p, typename Point2D< T >::Data_t f)
unsigned int nonEmptyDims() const
Point_t const & Max() const
::fhicl::TupleAs< Point(::geo::Length_t,::geo::Length_t,::geo::Length_t)> Point3D
Atom object for reading a 3D point or vector (centimeters).
void extendToInclude(Data_t)
Extends the range to include the specified point.
Data_t Data_t
Numeric type for boundaries.
Volume delimited by two points.
bool contains(Data_t w, Data_t d) const
Returns whether the specified point is in the area.
bool operator!=(Point2D< T > const &a, Point2D< T > const &b)
Rectangle(Range_t const &width, Range_t const &depth)
Constructor from width and depth ranges.
static void set_min_max(Data_t &min_var, Data_t &max_var, Data_t val)
bool isNull() const
Returns whether the rectangle has null area.
recob::tracking::Point_t Point_t
unsigned int thinnestSide() const
Returns the index of the thinnest side (0 is x, 1 is y)
void makeNull()
Resets this range to be empty (that is, like default-constructed).
Point2D< T > operator*(Point2D< T > const &p, typename Point2D< T >::Data_t f)
Volume(Point_t const &a, Point_t const &b)
Exception thrown when result of intersection is null.
auto thinnestSize() const
Point2D< T > operator+(Point2D< T > const &a, Point2D< T > const &b)
Area(Point_t const &a, Point_t const &b)
unsigned int thinnestSide() const
Returns the index of the thinnest side (0 is x)
std::tuple< double, double, const reco::ClusterHit3D * > Point
Definitions used by the VoronoiDiagram algorithm.
bool overlaps(Range_t const &r) const
Returns whether the specified range overlaps this range.
auto thinnestSize() const
bool overlaps(Rectangle_t const &r) const
Returns whether this and the specified rectangle overlap.
bool operator==(Point2D< T > const &a, Point2D< T > const &b)
3D point (x, y, z) (by default, with double precision)
bool contains(Data_t v) const
Returns whether the specified value is within the range.
Range_t width
Range along width direction.
void IncludePoint(Point_t const &point)
void Include(Area_t const &area)
Area delimited by two points.
unsigned int thinnestSide() const
Returns the index of the thinnest side (0 is x, 1 is y)
Range_t depth
Range along depth direction.
void Intersect(Volume_t const &volume)
unsigned int nonEmptyDims() const
Data_t delta(Data_t v, Data_t margin=0.0) const
Point3D(Data_t x, Data_t y, Data_t z)
LArSoft-specific namespace.
double Data_t
Numerical type for boundaries.
Definition of a rectangle from dimension ranges.
void IncludePoint(Point_t const &point)
Data_t upper
Ending coordinate.
void IncludePoint(Point_t const &point)
void extendToInclude(Rectangle_t const &r)
Extends the range to include the specified point.
typename Point_t::Data_t Data_t
bool isNull() const
Returns whether the range is empty.
void Include(Area_t const &area)
Range(Data_t lower, Data_t upper, bool doSort=false)
Constructor from lower and upper bounds.
void Intersect(Area_t const &area)
Data_t lower
Starting coordinate.
Area/volume delimited by points: base/1D implementation.
Point2D(Data_t x, Data_t y)
static void set_min(Data_t &var, Data_t val)
Data_t length() const
Returns the distance between upper and lower bounds.
void intersect(Range_t const &r)
Shortens this range to include only points also in r.
void Include(Volume_t const &volume)
static void set_max(Data_t &var, Data_t val)