LArSoft  v07_13_02
Liquid Argon Software toolkit - http://larsoft.org/
lar::util::simple_geo::Range< Data > Struct Template Reference

Definition of a range along one dimension. More...

#include "SimpleGeo.h"

Public Types

using Data_t = Data
 Numeric type for boundaries. More...
 
using Range_t = Range< Data >
 This range type. More...
 

Public Member Functions

 Range ()=default
 Default constructor: empty range. More...
 
 Range (Data_t lower, Data_t upper, bool doSort=false)
 Constructor from lower and upper bounds. More...
 
bool isNull () const
 Returns whether the range is empty. More...
 
Data_t length () const
 Returns the distance between upper and lower bounds. More...
 
bool contains (Data_t v) const
 Returns whether the specified value is within the range. More...
 
bool overlaps (Range_t const &r) const
 Returns whether the specified range overlaps this range. More...
 
Data_t delta (Data_t v, Data_t margin=0.0) const
 
void extendToInclude (Data_t)
 Extends the range to include the specified point. More...
 
void extendToInclude (Range_t const &r)
 Extends the range to include the specified point. More...
 
void intersect (Range_t const &r)
 Shortens this range to include only points also in r. More...
 

Public Attributes

Data_t lower = 1.0
 Starting coordinate. More...
 
Data_t upper = 0.0
 Ending coordinate. More...
 

Private Member Functions

void sort ()
 Ensures order of boundaries. Corrupts invalid ranges. More...
 
void makeNull ()
 Resets this range to be empty (that is, like default-constructed). More...
 

Detailed Description

template<typename Data = double>
struct lar::util::simple_geo::Range< Data >

Definition of a range along one dimension.

Definition at line 322 of file SimpleGeo.h.

Member Typedef Documentation

template<typename Data = double>
using lar::util::simple_geo::Range< Data >::Data_t = Data

Numeric type for boundaries.

Definition at line 323 of file SimpleGeo.h.

template<typename Data = double>
using lar::util::simple_geo::Range< Data >::Range_t = Range<Data>

This range type.

Definition at line 324 of file SimpleGeo.h.

Constructor & Destructor Documentation

template<typename Data = double>
lar::util::simple_geo::Range< Data >::Range ( )
default

Default constructor: empty range.

template<typename Data = double>
lar::util::simple_geo::Range< Data >::Range ( Data_t  lower,
Data_t  upper,
bool  doSort = false 
)
inline

Constructor from lower and upper bounds.

Definition at line 333 of file SimpleGeo.h.

334  : lower(lower), upper(upper)
335  { if (doSort) sort(); }
void sort()
Ensures order of boundaries. Corrupts invalid ranges.
Definition: SimpleGeo.h:364
Data_t upper
Ending coordinate.
Definition: SimpleGeo.h:327
Data_t lower
Starting coordinate.
Definition: SimpleGeo.h:326

Member Function Documentation

template<typename Data = double>
bool lar::util::simple_geo::Range< Data >::contains ( Data_t  v) const
inline

Returns whether the specified value is within the range.

Definition at line 344 of file SimpleGeo.h.

Referenced by lar::util::simple_geo::Rectangle< double >::contains(), and geo::DriftPartitions::DriftVolume_t::coversDrift().

344 { return (v >= lower) && (v <= upper); }
Data_t upper
Ending coordinate.
Definition: SimpleGeo.h:327
Data_t lower
Starting coordinate.
Definition: SimpleGeo.h:326
template<typename Data >
auto lar::util::simple_geo::Range< Data >::delta ( Data_t  v,
Data_t  margin = 0.0 
) const

Returns a value that, added to v, makes it fall within a margin in the range.

Definition at line 443 of file SimpleGeo.h.

Referenced by lar::util::simple_geo::Rectangle< double >::contains(), and geo::PlaneGeo::DeltaFromActivePlane().

445 {
446 
447  if (v < (lower + margin)) return lower + margin - v; // always positive
448  if (v > (upper - margin)) return upper - margin - v; // always negative
449  return 0.0; // always zero
450 
451 } // lar::util::simple_geo::Range<Data>::delta()
Data_t upper
Ending coordinate.
Definition: SimpleGeo.h:327
Data_t lower
Starting coordinate.
Definition: SimpleGeo.h:326
template<typename Data >
void lar::util::simple_geo::Range< Data >::extendToInclude ( Data_t  v)

Extends the range to include the specified point.

Definition at line 456 of file SimpleGeo.h.

Referenced by geo::DriftPartitions::computeCoverage(), and geo::details::ActiveAreaCalculator::includeAllWireEnds().

456  {
457 
458  if (lower > upper) lower = upper = v;
459  else if (lower > v) lower = v;
460  else if (upper < v) upper = v;
461 
462 } // lar::util::simple_geo::Range<Data>::extendToInclude()
Data_t upper
Ending coordinate.
Definition: SimpleGeo.h:327
Data_t lower
Starting coordinate.
Definition: SimpleGeo.h:326
template<typename Data >
void lar::util::simple_geo::Range< Data >::extendToInclude ( Range_t const &  r)

Extends the range to include the specified point.

Definition at line 467 of file SimpleGeo.h.

References lar::util::simple_geo::Range< Data >::isNull(), lar::util::simple_geo::Range< Data >::lower, and lar::util::simple_geo::Range< Data >::upper.

467  {
468 
469  if (r.isNull()) return;
470  if (isNull()) {
471  *this = r;
472  return;
473  }
474  extendToInclude(r.lower);
475  extendToInclude(r.upper);
476 
477 } // lar::util::simple_geo::Range<Data>::extendToInclude()
void extendToInclude(Data_t)
Extends the range to include the specified point.
Definition: SimpleGeo.h:456
bool isNull() const
Returns whether the range is empty.
Definition: SimpleGeo.h:338
template<typename Data >
void lar::util::simple_geo::Range< Data >::intersect ( Range_t const &  r)

Shortens this range to include only points also in r.

Definition at line 482 of file SimpleGeo.h.

References lar::util::simple_geo::Range< Data >::isNull(), lar::util::simple_geo::Range< Data >::lower, and lar::util::simple_geo::Range< Data >::upper.

482  {
483  // this implementation explicitly makes the range default-constructed-null
484  // if the intersection results empty
485  if (isNull()) return;
486  if (r.isNull()) {
487  makeNull();
488  return;
489  }
490  if (lower < r.lower) lower = r.lower;
491  if (upper > r.upper) upper = r.upper;
492  if (lower > upper) makeNull();
493 } // lar::util::simple_geo::Range<Data>::intersect()
void makeNull()
Resets this range to be empty (that is, like default-constructed).
Definition: SimpleGeo.h:367
Data_t upper
Ending coordinate.
Definition: SimpleGeo.h:327
bool isNull() const
Returns whether the range is empty.
Definition: SimpleGeo.h:338
Data_t lower
Starting coordinate.
Definition: SimpleGeo.h:326
template<typename Data = double>
bool lar::util::simple_geo::Range< Data >::isNull ( ) const
inline
template<typename Data = double>
Data_t lar::util::simple_geo::Range< Data >::length ( ) const
inline

Returns the distance between upper and lower bounds.

Definition at line 341 of file SimpleGeo.h.

341 { return std::max(upper - lower, Data_t(0.0)); }
Data Data_t
Numeric type for boundaries.
Definition: SimpleGeo.h:323
Int_t max
Definition: plot.C:27
Data_t upper
Ending coordinate.
Definition: SimpleGeo.h:327
Data_t lower
Starting coordinate.
Definition: SimpleGeo.h:326
template<typename Data = double>
void lar::util::simple_geo::Range< Data >::makeNull ( )
inlineprivate

Resets this range to be empty (that is, like default-constructed).

Definition at line 367 of file SimpleGeo.h.

367 { *this = Range_t{}; }
Range< Data > Range_t
This range type.
Definition: SimpleGeo.h:324
template<typename Data >
bool lar::util::simple_geo::Range< Data >::overlaps ( Range_t const &  r) const

Returns whether the specified range overlaps this range.

Definition at line 498 of file SimpleGeo.h.

References lar::util::simple_geo::Range< Data >::isNull(), lar::util::simple_geo::Range< Data >::lower, and lar::util::simple_geo::Range< Data >::upper.

498  {
499  if (isNull() || r.isNull()) return false;
500  return (r.lower < upper) && (lower < r.upper);
501 } // lar::util::simple_geo::Range<Data>::overlaps()
Data_t upper
Ending coordinate.
Definition: SimpleGeo.h:327
bool isNull() const
Returns whether the range is empty.
Definition: SimpleGeo.h:338
Data_t lower
Starting coordinate.
Definition: SimpleGeo.h:326
template<typename Data = double>
void lar::util::simple_geo::Range< Data >::sort ( )
inlineprivate

Ensures order of boundaries. Corrupts invalid ranges.

Definition at line 364 of file SimpleGeo.h.

364 { if (lower > upper) std::swap(lower, upper); }
void swap(art::HLTGlobalStatus &lhs, art::HLTGlobalStatus &rhs)
Data_t upper
Ending coordinate.
Definition: SimpleGeo.h:327
Data_t lower
Starting coordinate.
Definition: SimpleGeo.h:326

Member Data Documentation


The documentation for this struct was generated from the following file: