Redefined the ==, != operators of Point and BoundingBox classes

to become members of their respective classes to avoid type clashes
through implicit casting operators of ConfigOption classes.
This commit is contained in:
bubnikv 2017-10-17 14:36:30 +02:00
parent a191fbbec8
commit a91d7cb2f7
2 changed files with 24 additions and 16 deletions

View File

@ -15,7 +15,7 @@ typedef Pointf3 Sizef3;
template <class PointClass>
class BoundingBoxBase
{
public:
public:
PointClass min;
PointClass max;
bool defined;
@ -42,12 +42,14 @@ class BoundingBoxBase
return ! (this->max.x < other.min.x || this->min.x > other.max.x ||
this->max.y < other.min.y || this->min.y > other.max.y);
}
bool operator==(const BoundingBoxBase<PointClass> &rhs) { return this->min == rhs.min && this->max == rhs.max; }
bool operator!=(const BoundingBoxBase<PointClass> &rhs) { return ! (*this == rhs); }
};
template <class PointClass>
class BoundingBox3Base : public BoundingBoxBase<PointClass>
{
public:
public:
BoundingBox3Base() : BoundingBoxBase<PointClass>() {};
BoundingBox3Base(const PointClass &pmin, const PointClass &pmax) :
BoundingBoxBase<PointClass>(pmin, pmax)
@ -66,7 +68,7 @@ class BoundingBox3Base : public BoundingBoxBase<PointClass>
class BoundingBox : public BoundingBoxBase<Point>
{
public:
public:
void polygon(Polygon* polygon) const;
Polygon polygon() const;
BoundingBox rotated(double angle) const;
@ -87,6 +89,7 @@ class BoundingBox : public BoundingBoxBase<Point>
class BoundingBox3 : public BoundingBox3Base<Point3>
{
public:
BoundingBox3() : BoundingBox3Base<Point3>() {};
BoundingBox3(const Point3 &pmin, const Point3 &pmax) : BoundingBox3Base<Point3>(pmin, pmax) {};
BoundingBox3(const std::vector<Point3> &points) : BoundingBox3Base<Point3>(points) {};
@ -108,18 +111,6 @@ public:
BoundingBoxf3(const std::vector<Pointf3> &points) : BoundingBox3Base<Pointf3>(points) {};
};
template<typename VT>
inline bool operator==(const BoundingBoxBase<VT> &bb1, const BoundingBoxBase<VT> &bb2)
{
return bb1.min == bb2.min && bb1.max == bb2.max;
}
template<typename VT>
inline bool operator!=(const BoundingBoxBase<VT> &bb1, const BoundingBoxBase<VT> &bb2)
{
return !(bb1 == bb2);
}
template<typename VT>
inline bool empty(const BoundingBoxBase<VT> &bb)
{

View File

@ -184,6 +184,12 @@ public:
coord_t z;
explicit Point3(coord_t _x = 0, coord_t _y = 0, coord_t _z = 0): Point(_x, _y), z(_z) {};
static Point3 new_scale(coordf_t x, coordf_t y, coordf_t z) { return Point3(coord_t(scale_(x)), coord_t(scale_(y)), coord_t(scale_(z))); }
bool operator==(const Point3 &rhs) const { return this->x == rhs.x && this->y == rhs.y && this->z == rhs.z; }
bool operator!=(const Point3 &rhs) const { return ! (*this == rhs); }
private:
// Hide the following inherited methods:
bool operator==(const Point &rhs);
bool operator!=(const Point &rhs);
};
std::ostream& operator<<(std::ostream &stm, const Pointf &pointf);
@ -214,6 +220,9 @@ public:
Pointf& operator+=(const Pointf& rhs) { this->x += rhs.x; this->y += rhs.y; return *this; }
Pointf& operator-=(const Pointf& rhs) { this->x -= rhs.x; this->y -= rhs.y; return *this; }
Pointf& operator*=(const coordf_t& rhs) { this->x *= rhs; this->y *= rhs; return *this; }
bool operator==(const Pointf &rhs) const { return this->x == rhs.x && this->y == rhs.y; }
bool operator!=(const Pointf &rhs) const { return ! (*this == rhs); }
};
inline Pointf operator+(const Pointf& point1, const Pointf& point2) { return Pointf(point1.x + point2.x, point1.y + point2.y); }
@ -228,7 +237,7 @@ inline double l2(const Vectorf &v) { return dot(v); }
class Pointf3 : public Pointf
{
public:
public:
coordf_t z;
explicit Pointf3(coordf_t _x = 0, coordf_t _y = 0, coordf_t _z = 0): Pointf(_x, _y), z(_z) {};
static Pointf3 new_unscale(coord_t x, coord_t y, coord_t z) {
@ -240,6 +249,14 @@ class Pointf3 : public Pointf
double distance_to(const Pointf3 &point) const;
Pointf3 negative() const;
Vectorf3 vector_to(const Pointf3 &point) const;
bool operator==(const Pointf3 &rhs) const { return this->x == rhs.x && this->y == rhs.y && this->z == rhs.z; }
bool operator!=(const Pointf3 &rhs) const { return ! (*this == rhs); }
private:
// Hide the following inherited methods:
bool operator==(const Pointf &rhs);
bool operator!=(const Pointf &rhs);
};
template<typename TO> inline TO convert_to(const Point &src) { return TO(typename TO::coord_type(src.x), typename TO::coord_type(src.y)); }