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; };
181 {
if (val < var) var = val; }
184 {
if (val > var) var = val; }
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>>
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>>
321 template <
typename Data =
double>
334 : lower(lower), upper(upper)
335 {
if (doSort)
sort(); }
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
process_name opflash particleana ie ie ie z
bool operator==(Area_t const &as) const
unsigned int nonEmptyDims() const
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)
Range< Data > Range_t
This range type.
auto thinnestSize() const
Point_t const & Min() const
Range()=default
Default constructor: empty range.
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
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 operator!=(Area_t const &as) const
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.
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)
typename Base_t::Point_t Point_t
Rectangle()=default
Default constructor: an empty rectangle.
Exception thrown when result of intersection is null.
process_name opflash particleana ie ie y
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)
double Data_t
Numerical type for boundaries.
Definition of a rectangle from dimension ranges.
void IncludePoint(Point_t const &point)
Rectangle< Data > Rectangle_t
This type.
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.
static void set_sorted(Data_t &min_var, Data_t &max_var, Data_t a, Data_t b)
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)