This repository has been archived on 2020-04-08. You can view files and clone it, but cannot push or open issues or pull requests.
Files
IndoorMap/mapview/2D/ClickDist.h
2018-10-25 12:23:40 +02:00

70 lines
1.7 KiB
C++
Raw Permalink Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

/*
* © Copyright 2014 Urheberrechtshinweis
* Alle Rechte vorbehalten / All Rights Reserved
*
* Programmcode ist urheberrechtlich geschuetzt.
* Das Urheberrecht liegt, soweit nicht ausdruecklich anders gekennzeichnet, bei Frank Ebner.
* Keine Verwendung ohne explizite Genehmigung.
* (vgl. § 106 ff UrhG / § 97 UrhG)
*/
#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