Ignore:
Timestamp:
Jul 7, 2010, 6:33:46 PM (12 years ago)
Author:
Peter
Message:

adding a function that takes intersection of two Sections. refs #635

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/yat/utility/Segment.h

    r2291 r2293  
    143143  }
    144144
     145  /**
     146     \return intersection of \a a and \a b. If \a a and \b do not
     147     overlap an empty Section is returned (begin==end), but the exact
     148     value of begin is undefined.
     149
     150     \relates Segment
     151
     152     \since new in yat 0.7
     153   */
     154  template<typename T, class Compare>
     155  Segment<T, Compare> intersection(const Segment<T, Compare>& a,
     156                                   const Segment<T, Compare>& b)
     157  {
     158    Compare comp;
     159    Segment<T, Compare> result;
     160
     161    result.begin() = std::max(a.begin(), b.begin(), comp);
     162    result.end() = std::max(result.begin(),
     163                            std::min(a.end(), b.end(), comp),
     164                            comp);
     165    return result;
     166  }
     167
    145168}}}
    146169#endif
Note: See TracChangeset for help on using the changeset viewer.