LArSoft  v10_04_05
Liquid Argon Software toolkit - https://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 353 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 354 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 355 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 364 of file SimpleGeo.h.

364  : lower(lower), upper(upper)
365  {
366  if (doSort) sort();
367  }
void sort()
Ensures order of boundaries. Corrupts invalid ranges.
Definition: SimpleGeo.h:396
Data_t upper
Ending coordinate.
Definition: SimpleGeo.h:358
Data_t lower
Starting coordinate.
Definition: SimpleGeo.h:357

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 376 of file SimpleGeo.h.

Referenced by lar::util::simple_geo::Rectangle< double >::contains().

376 { return (v >= lower) && (v <= upper); }
Data_t upper
Ending coordinate.
Definition: SimpleGeo.h:358
Data_t lower
Starting coordinate.
Definition: SimpleGeo.h:357
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 472 of file SimpleGeo.h.

Referenced by geo::PlaneGeo::DeltaFromActivePlane().

473 {
474 
475  if (v < (lower + margin)) return lower + margin - v; // always positive
476  if (v > (upper - margin)) return upper - margin - v; // always negative
477  return 0.0; // always zero
478 
479 } // lar::util::simple_geo::Range<Data>::delta()
Data_t upper
Ending coordinate.
Definition: SimpleGeo.h:358
Data_t lower
Starting coordinate.
Definition: SimpleGeo.h:357
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 483 of file SimpleGeo.h.

484 {
485 
486  if (lower > upper)
487  lower = upper = v;
488  else if (lower > v)
489  lower = v;
490  else if (upper < v)
491  upper = v;
492 
493 } // lar::util::simple_geo::Range<Data>::extendToInclude()
Data_t upper
Ending coordinate.
Definition: SimpleGeo.h:358
Data_t lower
Starting coordinate.
Definition: SimpleGeo.h:357
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 497 of file SimpleGeo.h.

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

498 {
499 
500  if (r.isNull()) return;
501  if (isNull()) {
502  *this = r;
503  return;
504  }
505  extendToInclude(r.lower);
506  extendToInclude(r.upper);
507 
508 } // lar::util::simple_geo::Range<Data>::extendToInclude()
TRandom r
Definition: spectrum.C:23
void extendToInclude(Data_t)
Extends the range to include the specified point.
Definition: SimpleGeo.h:483
bool isNull() const
Returns whether the range is empty.
Definition: SimpleGeo.h:370
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 512 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.

513 {
514  // this implementation explicitly makes the range default-constructed-null
515  // if the intersection results empty
516  if (isNull()) return;
517  if (r.isNull()) {
518  makeNull();
519  return;
520  }
521  if (lower < r.lower) lower = r.lower;
522  if (upper > r.upper) upper = r.upper;
523  if (lower > upper) makeNull();
524 } // lar::util::simple_geo::Range<Data>::intersect()
TRandom r
Definition: spectrum.C:23
void makeNull()
Resets this range to be empty (that is, like default-constructed).
Definition: SimpleGeo.h:402
Data_t upper
Ending coordinate.
Definition: SimpleGeo.h:358
bool isNull() const
Returns whether the range is empty.
Definition: SimpleGeo.h:370
Data_t lower
Starting coordinate.
Definition: SimpleGeo.h:357
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 373 of file SimpleGeo.h.

373 { return std::max(upper - lower, Data_t(0.0)); }
Data Data_t
Numeric type for boundaries.
Definition: SimpleGeo.h:354
Data_t upper
Ending coordinate.
Definition: SimpleGeo.h:358
Data_t lower
Starting coordinate.
Definition: SimpleGeo.h:357
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 402 of file SimpleGeo.h.

402 { *this = Range_t{}; }
Range< Data > Range_t
This range type.
Definition: SimpleGeo.h:355
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 528 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.

529 {
530  if (isNull() || r.isNull()) return false;
531  return (r.lower < upper) && (lower < r.upper);
532 } // lar::util::simple_geo::Range<Data>::overlaps()
TRandom r
Definition: spectrum.C:23
Data_t upper
Ending coordinate.
Definition: SimpleGeo.h:358
bool isNull() const
Returns whether the range is empty.
Definition: SimpleGeo.h:370
Data_t lower
Starting coordinate.
Definition: SimpleGeo.h:357
template<typename Data = double>
void lar::util::simple_geo::Range< Data >::sort ( )
inlineprivate

Ensures order of boundaries. Corrupts invalid ranges.

Definition at line 396 of file SimpleGeo.h.

397  {
398  if (lower > upper) std::swap(lower, upper);
399  }
Data_t upper
Ending coordinate.
Definition: SimpleGeo.h:358
void swap(lar::deep_const_fwd_iterator_nested< CITER, INNERCONTEXTRACT > &a, lar::deep_const_fwd_iterator_nested< CITER, INNERCONTEXTRACT > &b)
Data_t lower
Starting coordinate.
Definition: SimpleGeo.h:357

Member Data Documentation


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