// Description: header and in-line definitions for sweep status structure and associated function object classes // Revision history: 5/8/99/LY #ifndef SWEEP #define SWEEP #include "decl.h" // Function object class used in key comparison operations on sweep status structure // operator() effectively computes whether the upper endpoint of sw_lhs lies to the left or // sw_rhs, and returns true or false accordingly. See sweep.cpp for definition. class SweepKeyCmp { public: bool operator() (const SweepElementKey& sw_lhs, const SweepElementKey& sw_rhs) const; }; // function object class for representing key fields of elements in sweep status structure class SweepElementKey { public: SweepElementKey(const Coordinates& upper_endpoint, const Coordinates& lower_endpoint): upper(upper_endpoint), lower(lower_endpoint) { slope = calc_slope(upper_endpoint, lower_endpoint); } bool operator==(const SweepElementKey& rhs) const { return upper == rhs.upper && lower == rhs.lower; } bool operator<(const SweepElementKey& rhs) const { return upper < rhs.upper || (upper == rhs.upper && lower < rhs.lower); } Coordinates upper, lower; double slope; private: // calc_slope finds slope dx/dy and returns it double calc_slope(const Coordinates& upper_endpoint, const Coordinates& lower_endpoint) { return (lower_endpoint.first - upper_endpoint.first) / (lower_endpoint.second - upper_endpoint.second); } }; // function object class for finding line segments intersecting the sweep line whose upper endpoint // coincide with the event point (used in conjunction with the equal_range algorithm) class SweepCmp { public: bool operator() (const pair& sw_elem, const pair& value) { if (sw_elem.first.upper == value.first.upper) { return false; } return (SweepKeyCmp())(sw_elem.first, value.first); } }; #endif