Changeset 2293


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

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

Location:
trunk
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • trunk/test/segment_test.cc

    r2291 r2293  
    8282    suite.err() << "error: expected set.upper_bound to return end()\n";
    8383
     84  Segment<double> segment12(0,2);
     85  Segment<double> segment13(1,3);
     86  Segment<double> segment14 = intersection(segment12, segment13);
     87  suite.add(segment14.begin()==1);
     88  suite.add(segment14.end()==2);
     89
    8490  return suite.return_value();
    8591}
  • 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.