11 #ifndef LARCOREALG_GEOMETRY_SIMPLEGEO_H 12 #define LARCOREALG_GEOMETRY_SIMPLEGEO_H 43 namespace simple_geo {
49 template <
typename Data =
double>
64 return (a.x == b.x) && (a.y == b.y);
69 return (a.x != b.x) || (a.y != b.y);
74 return {a.x + b.x, a.y + b.y};
79 return {p.x *
f, p.y * f};
84 return {p.x /
f, p.y / f};
86 template <
typename Stream,
typename T>
87 Stream& operator<<(Stream&& out, Point2D<T>
const& p)
89 out <<
"( " << p.x <<
" ; " << p.y <<
" )";
94 template <
typename Data =
double>
106 template <
typename T>
109 return (a.
x == b.
x) && (a.
y == b.
y) && (a.
z == b.
z);
111 template <
typename T>
114 return (a.
x != b.
x) || (a.
y != b.
y) || (a.
z != b.
z);
116 template <
typename T>
119 return {a.
x + b.
x, a.
y + b.
y, a.
z + b.
z};
121 template <
typename T>
124 return {p.
x *
f, p.
y *
f, p.
z * f};
126 template <
typename T>
129 return {p.
x /
f, p.
y /
f, p.
z / f};
131 template <
typename Stream,
typename T>
132 Stream& operator<<(Stream&& out, Point3D<T>
const& p)
134 out <<
"( " << p.x <<
" ; " << p.y <<
" ; " << p.z <<
" )";
144 template <
typename Po
int>
152 using std::runtime_error::runtime_error;
163 auto DeltaX()
const {
return Max().x - Min().x; }
165 bool isNullX()
const {
return Max().x < Min().x; }
166 bool isNull()
const {
return isNullX(); }
168 bool isEmpty()
const {
return nonEmptyDims() == 0; }
169 bool isLine()
const {
return nonEmptyDims() == 1; }
180 IncludePoint(area.
min);
181 IncludePoint(area.
max);
186 set_max(min.x, area.
min.x);
187 set_min(max.x, area.
max.x);
201 if (val < var) var = val;
206 if (val > var) var = val;
211 set_min(min_var, val);
212 set_max(max_var, val);
230 template <
typename Po
int = Po
int2D<
double>>
242 Base_t::set_sorted(Base_t::min.
y, Base_t::max.y, a.y, b.y);
245 auto DeltaY()
const {
return Base_t::Max().y - Base_t::Min().y; }
247 unsigned int nonEmptyDims()
const {
return Base_t::nonEmptyDims() + (isEmptyY() ? 0 : 1); }
248 bool isNullY()
const {
return Base_t::Max().y < Base_t::Min().y; }
249 bool isNull()
const {
return Base_t::isNull() || isNullY(); }
250 bool isEmpty()
const {
return nonEmptyDims() == 0; }
251 bool isLine()
const {
return nonEmptyDims() == 1; }
252 bool isPlane()
const {
return nonEmptyDims() == 2; }
254 auto thinnestSize()
const {
return std::min(DeltaY(), Base_t::thinnestSize()); }
259 return (DeltaY() < Base_t::thinnestSize()) ? 1 : Base_t::thinnestSide();
264 Base_t::IncludePoint(point);
265 Base_t::set_min_max(Base_t::min.
y, Base_t::max.y, point.y);
270 IncludePoint(area.
min);
271 IncludePoint(area.
max);
276 Base_t::Intersect(area);
277 Base_t::set_max(Base_t::min.
y, area.
min.y);
278 Base_t::set_min(Base_t::max.y, area.
max.y);
284 template <
typename Stream,
typename Po
int>
285 Stream& operator<<(Stream&& out, AreaBase<Point>
const& area)
287 out << area.Min() <<
" - " << area.Max();
292 template <
typename Po
int = Po
int3D<
double>>
304 Base_t::set_sorted(Base_t::min.
z, Base_t::max.z, a.z, b.z);
307 auto DeltaZ()
const {
return Base_t::Max().z - Base_t::Min().z; }
309 unsigned int nonEmptyDims()
const {
return Base_t::nonEmptyDims() + (isEmptyZ() ? 0 : 1); }
310 bool isNullZ()
const {
return Base_t::Max().z < Base_t::Min().z; }
311 bool isNull()
const {
return Base_t::isNull() || isNullZ(); }
312 bool isEmpty()
const {
return nonEmptyDims() == 0; }
313 bool isLine()
const {
return nonEmptyDims() == 1; }
314 bool isPlane()
const {
return nonEmptyDims() == 2; }
315 bool isVolume()
const {
return nonEmptyDims() == 3; }
317 auto thinnestSize()
const {
return std::min(DeltaZ(), Base_t::thinnestSize()); }
322 return (DeltaZ() < Base_t::thinnestSize()) ? 2 : Base_t::thinnestSide();
327 Base_t::IncludePoint(point);
328 Base_t::set_min_max(Base_t::min.
z, Base_t::max.z, point.z);
333 IncludePoint(volume.
min);
334 IncludePoint(volume.
max);
339 Base_t::Intersect(volume);
340 Base_t::set_max(Base_t::min.
z, volume.
min.z);
341 Base_t::set_min(Base_t::max.z, volume.
max.z);
353 template <
typename Data =
double>
371 bool isNull()
const {
return lower >= upper; }
380 bool overlaps(
Range_t const&
r)
const;
387 void extendToInclude(
Data_t);
390 void extendToInclude(
Range_t const& r);
393 void intersect(
Range_t const& r);
399 if (lower > upper) std::swap(lower, upper);
408 template <
typename Stream,
typename Data>
409 Stream& operator<<(Stream&& out, Range<Data>
const& range);
423 template <
typename Data =
double>
453 template <
typename Stream,
typename Data>
454 Stream& operator<<(Stream&& out, Rectangle<Data>
const& rect);
472 template <
typename Data>
476 if (v < (lower + margin))
return lower + margin - v;
477 if (v > (upper - margin))
return upper - margin - v;
483 template <
typename Data>
497 template <
typename Data>
506 extendToInclude(r.
lower);
507 extendToInclude(r.
upper);
512 template <
typename Data>
517 if (isNull())
return;
524 if (lower > upper) makeNull();
528 template <
typename Data>
531 if (isNull() || r.
isNull())
return false;
532 return (r.
lower < upper) && (lower < r.
upper);
536 template <
typename Stream,
typename Data>
537 Stream& lar::util::simple_geo::operator<<(Stream&& out, Range<Data>
const& range)
539 out <<
"( " << range.lower <<
" -- " << range.upper <<
" )";
544 template <
typename Data>
547 width.extendToInclude(r.
width);
548 depth.extendToInclude(r.
depth);
552 template <
typename Data>
555 if (isNull() || r.
isNull())
return false;
556 return width.overlap(r.
width) && depth.overlap(r.
depth);
560 template <
typename Stream,
typename Data>
561 Stream& lar::util::simple_geo::operator<<(Stream&& out, Rectangle<Data>
const& rect)
563 out <<
"w=" << rect.width <<
" d=" << rect.depth;
569 #endif // LARCOREALG_GEOMETRY_SIMPLEGEO_H
bool operator==(Area_t const &as) const
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
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.
::fhicl::TupleAs< Point(::geo::Length_t,::geo::Length_t,::geo::Length_t)> Point3D
Atom object for reading a 3D point or vector (centimeters).
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.
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)
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)
std::tuple< double, double, const reco::ClusterHit3D * > Point
Definitions used by the VoronoiDiagram algorithm.
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)