#ifndef CLICKDIST_H #define CLICKDIST_H enum class ClickDistType { UNKNOWN, DIRECT, // e.g. distance between cursor and an edge-point, POI, AP, Beacon, ... CUT, // e.g. distance between cursor and an obstacle-line }; /** describes distances between mouse-cursor and objects within the 2D view */ struct ClickDist { /** distance in pixels */ float dst_px; /** distance type */ ClickDistType type; /** ctor */ ClickDist(const float dst_px, const ClickDistType type) : dst_px(dst_px), type(type) {;} /** max-dummy */ static ClickDist max() {return ClickDist(9999999, ClickDistType::UNKNOWN);} /** distance comparison */ bool operator < (const ClickDist o) const { return (this->dst_px * this->mod()) < (o.dst_px * o.mod()); } /** multiply by constant */ ClickDist operator * (const float val) const {return ClickDist(dst_px*val, type);} // /** weighted distance comparison based on ClickDistType */ // bool compare(const ClickDist o) const { // return ((*this)*mod()) < (o*o.mod()); // } private: /** * artificially modify the distance based on the given type. * this enhances the selection in cases of equal distance * like a POI residing dirctly one a line */ float mod() const { switch (type) { case ClickDistType::UNKNOWN: return 1.1; case ClickDistType::CUT: return 1.0; case ClickDistType::DIRECT: return 0.7; default: throw "code error"; } } }; #endif // CLICKDIST_H