LArSoft  v09_90_00
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 354 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 355 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 356 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 365 of file SimpleGeo.h.

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

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

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

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

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

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

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

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

499 {
500 
501  if (r.isNull()) return;
502  if (isNull()) {
503  *this = r;
504  return;
505  }
506  extendToInclude(r.lower);
507  extendToInclude(r.upper);
508 
509 } // 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:484
bool isNull() const
Returns whether the range is empty.
Definition: SimpleGeo.h:371
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 513 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.

514 {
515  // this implementation explicitly makes the range default-constructed-null
516  // if the intersection results empty
517  if (isNull()) return;
518  if (r.isNull()) {
519  makeNull();
520  return;
521  }
522  if (lower < r.lower) lower = r.lower;
523  if (upper > r.upper) upper = r.upper;
524  if (lower > upper) makeNull();
525 } // 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:403
Data_t upper
Ending coordinate.
Definition: SimpleGeo.h:359
bool isNull() const
Returns whether the range is empty.
Definition: SimpleGeo.h:371
Data_t lower
Starting coordinate.
Definition: SimpleGeo.h:358
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 374 of file SimpleGeo.h.

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

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

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

Ensures order of boundaries. Corrupts invalid ranges.

Definition at line 397 of file SimpleGeo.h.

398  {
399  if (lower > upper) std::swap(lower, upper);
400  }
Data_t upper
Ending coordinate.
Definition: SimpleGeo.h:359
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:358

Member Data Documentation


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