10 #ifndef LARCOREALG_GEOMETRY_SIMPLEGEO_H 11 #define LARCOREALG_GEOMETRY_SIMPLEGEO_H 42 namespace simple_geo {
48 template <
typename Data =
double>
63 return (a.x == b.x) && (a.y == b.y);
68 return (a.x != b.x) || (a.y != b.y);
73 return {a.x + b.x, a.y + b.y};
78 return {p.x *
f, p.y * f};
83 return {p.x /
f, p.y / f};
85 template <
typename Stream,
typename T>
86 Stream& operator<<(Stream&& out, Point2D<T>
const& p)
88 out <<
"( " << p.x <<
" ; " << p.y <<
" )";
93 template <
typename Data =
double>
105 template <
typename T>
108 return (a.
x == b.
x) && (a.
y == b.
y) && (a.
z == b.
z);
110 template <
typename T>
113 return (a.
x != b.
x) || (a.
y != b.
y) || (a.
z != b.
z);
115 template <
typename T>
118 return {a.
x + b.
x, a.
y + b.
y, a.
z + b.
z};
120 template <
typename T>
123 return {p.
x *
f, p.
y *
f, p.
z * f};
125 template <
typename T>
128 return {p.
x /
f, p.
y /
f, p.
z / f};
130 template <
typename Stream,
typename T>
131 Stream& operator<<(Stream&& out, Point3D<T>
const& p)
133 out <<
"( " << p.x <<
" ; " << p.y <<
" ; " << p.z <<
" )";
143 template <
typename Po
int>
151 using std::runtime_error::runtime_error;
162 auto DeltaX()
const {
return Max().x - Min().x; }
164 bool isNullX()
const {
return Max().x < Min().x; }
165 bool isNull()
const {
return isNullX(); }
167 bool isEmpty()
const {
return nonEmptyDims() == 0; }
168 bool isLine()
const {
return nonEmptyDims() == 1; }
179 IncludePoint(area.
min);
180 IncludePoint(area.
max);
185 set_max(min.x, area.
min.x);
186 set_min(max.x, area.
max.x);
200 if (val < var) var = val;
205 if (val > var) var = val;
210 set_min(min_var, val);
211 set_max(max_var, val);
229 template <
typename Po
int = Po
int2D<
double>>
241 Base_t::set_sorted(Base_t::min.
y, Base_t::max.y, a.y, b.y);
244 auto DeltaY()
const {
return Base_t::Max().y - Base_t::Min().y; }
246 unsigned int nonEmptyDims()
const {
return Base_t::nonEmptyDims() + (isEmptyY() ? 0 : 1); }
247 bool isNullY()
const {
return Base_t::Max().y < Base_t::Min().y; }
248 bool isNull()
const {
return Base_t::isNull() || isNullY(); }
249 bool isEmpty()
const {
return nonEmptyDims() == 0; }
250 bool isLine()
const {
return nonEmptyDims() == 1; }
251 bool isPlane()
const {
return nonEmptyDims() == 2; }
253 auto thinnestSize()
const {
return std::min(DeltaY(), Base_t::thinnestSize()); }
258 return (DeltaY() < Base_t::thinnestSize()) ? 1 : Base_t::thinnestSide();
263 Base_t::IncludePoint(point);
264 Base_t::set_min_max(Base_t::min.
y, Base_t::max.y, point.y);
269 IncludePoint(area.
min);
270 IncludePoint(area.
max);
275 Base_t::Intersect(area);
276 Base_t::set_max(Base_t::min.
y, area.
min.y);
277 Base_t::set_min(Base_t::max.y, area.
max.y);
283 template <
typename Stream,
typename Po
int>
284 Stream& operator<<(Stream&& out, AreaBase<Point>
const& area)
286 out << area.Min() <<
" - " << area.Max();
291 template <
typename Po
int = Po
int3D<
double>>
303 Base_t::set_sorted(Base_t::min.
z, Base_t::max.z, a.z, b.z);
306 auto DeltaZ()
const {
return Base_t::Max().z - Base_t::Min().z; }
308 unsigned int nonEmptyDims()
const {
return Base_t::nonEmptyDims() + (isEmptyZ() ? 0 : 1); }
309 bool isNullZ()
const {
return Base_t::Max().z < Base_t::Min().z; }
310 bool isNull()
const {
return Base_t::isNull() || isNullZ(); }
311 bool isEmpty()
const {
return nonEmptyDims() == 0; }
312 bool isLine()
const {
return nonEmptyDims() == 1; }
313 bool isPlane()
const {
return nonEmptyDims() == 2; }
314 bool isVolume()
const {
return nonEmptyDims() == 3; }
316 auto thinnestSize()
const {
return std::min(DeltaZ(), Base_t::thinnestSize()); }
321 return (DeltaZ() < Base_t::thinnestSize()) ? 2 : Base_t::thinnestSide();
326 Base_t::IncludePoint(point);
327 Base_t::set_min_max(Base_t::min.
z, Base_t::max.z, point.z);
332 IncludePoint(volume.
min);
333 IncludePoint(volume.
max);
338 Base_t::Intersect(volume);
339 Base_t::set_max(Base_t::min.
z, volume.
min.z);
340 Base_t::set_min(Base_t::max.z, volume.
max.z);
352 template <
typename Data =
double>
370 bool isNull()
const {
return lower >= upper; }
379 bool overlaps(
Range_t const&
r)
const;
386 void extendToInclude(
Data_t);
389 void extendToInclude(
Range_t const& r);
392 void intersect(
Range_t const& r);
398 if (lower > upper) std::swap(lower, upper);
407 template <
typename Stream,
typename Data>
408 Stream& operator<<(Stream&& out, Range<Data>
const& range);
422 template <
typename Data =
double>
452 template <
typename Stream,
typename Data>
453 Stream& operator<<(Stream&& out, Rectangle<Data>
const& rect);
471 template <
typename Data>
475 if (v < (lower + margin))
return lower + margin - v;
476 if (v > (upper - margin))
return upper - margin - v;
482 template <
typename Data>
496 template <
typename Data>
505 extendToInclude(r.
lower);
506 extendToInclude(r.
upper);
511 template <
typename Data>
516 if (isNull())
return;
523 if (lower > upper) makeNull();
527 template <
typename Data>
530 if (isNull() || r.
isNull())
return false;
531 return (r.
lower < upper) && (lower < r.
upper);
535 template <
typename Stream,
typename Data>
536 Stream& lar::util::simple_geo::operator<<(Stream&& out, Range<Data>
const& range)
538 out <<
"( " << range.lower <<
" -- " << range.upper <<
" )";
543 template <
typename Data>
546 width.extendToInclude(r.
width);
547 depth.extendToInclude(r.
depth);
551 template <
typename Data>
554 if (isNull() || r.
isNull())
return false;
555 return width.overlap(r.
width) && depth.overlap(r.
depth);
559 template <
typename Stream,
typename Data>
560 Stream& lar::util::simple_geo::operator<<(Stream&& out, Rectangle<Data>
const& rect)
562 out <<
"w=" << rect.width <<
" d=" << rect.depth;
568 #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)