31 #ifndef PT_GFX_POINT_H
32 #define PT_GFX_POINT_H
34 #include <Pt/Gfx/Api.h>
53 Point(Float x, Float y)
58 : _x(pt._x), _y(pt._y)
67 void set(Float xpos, Float ypos)
85 const Point& addX(Float x)
91 const Point& subX(Float x)
97 const Point& addY(Float y)
103 const Point& subY(Float y)
109 const Point& move(Float dx, Float dy)
116 Float distanceTo(
const Point& other)
const
121 return hypot(_x - other._x, _y - other._y);
131 bool isEqual(
const Point& other, Float eps = FloatNearlyZero)
const
133 return std::abs(_x - other._x) <= eps &&
134 std::abs(_y - other._y) <= eps;
146 return Point(_x + pt._x, _y + pt._y);
158 return Point(_x - pt._x, _y - pt._y);
161 Point operator*(Float factor)
const
163 return Point(_x * factor, _y * factor);
166 Point operator/(Float factor)
const
168 return Point(_x / factor, _y / factor);
171 Point operator+(Float factor)
const
173 return Point(_x + factor, _y + factor);
178 return Point(_x - factor, _y - factor);
181 Point& operator*=(Float factor)
188 Point& operator/=(Float factor)
198 {
return _x == 0 && _y == 0; }
203 {
return Point(-_x, -_y); }
208 {
return hypot(_x, _y); }
213 {
return _x * _x + _y * _y; }
219 const Float len = this->
length();
222 return Point(_x / len, _y / len);
250 typedef Point PointF;
266 : _x(pt._x), _y(pt._y)
275 void set(Int xpos, Int ypos)
317 const PointI& move(Int dx, Int dy)
331 bool operator==(
const PointI& pt)
const
332 {
return (_x == pt._x && _y == pt._y); }
334 bool operator!=(
const PointI& pt)
const
335 {
return (_x != pt._x || _y != pt._y); }
346 return PointI(_x + pt._x, _y + pt._y);
358 return PointI(_x - pt._x, _y - pt._y);
361 PointI operator*(Int factor)
const
363 return PointI(_x * factor, _y * factor);
366 PointI operator+(Int offset)
const
368 return PointI(_x + offset, _y + offset);
373 return PointI(_x - offset, _y - offset);
376 PointI& operator*=(Int factor)
386 {
return _x == 0 && _y == 0; }
391 {
return PointI(-_x, -_y); }
399 : _x(static_cast<Float>(pt.x())), _y(static_cast<Float>(pt.y()))
404 _x =
static_cast<Float
>(pt.x());
405 _y =
static_cast<Float
>(pt.y());
411 return PointI(
static_cast<Int
>(std::lround(_x)),
412 static_cast<Int
>(std::lround(_y)));
417 return PointI(
static_cast<Int
>(std::floor(_x)),
418 static_cast<Int
>(std::floor(_y)));
423 return PointI(
static_cast<Int
>(std::ceil(_x)),
424 static_cast<Int
>(std::ceil(_y)));