All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
Public Types | Public Member Functions | Public Attributes | Private Member Functions | List of all members
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.

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.

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.

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.

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
esac echo uname r
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.

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
esac echo uname r
template<typename Data = double>
bool lar::util::simple_geo::Range< Data >::isNull ( ) const
inline

Returns whether the range is empty.

Definition at line 338 of file SimpleGeo.h.

338 { return lower >= upper; }
Data_t upper
Ending coordinate.
Definition: SimpleGeo.h:327
Data_t lower
Starting coordinate.
Definition: SimpleGeo.h:326
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
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.

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
esac echo uname r
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); }
Data_t upper
Ending coordinate.
Definition: SimpleGeo.h:327
Data_t lower
Starting coordinate.
Definition: SimpleGeo.h:326

Member Data Documentation

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

Starting coordinate.

Definition at line 326 of file SimpleGeo.h.

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

Ending coordinate.

Definition at line 327 of file SimpleGeo.h.


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