1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137
|
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
#ifndef THIRD_PARTY_BLINK_RENDERER_PLATFORM_GEOMETRY_DOUBLE_POINT_H_
#define THIRD_PARTY_BLINK_RENDERER_PLATFORM_GEOMETRY_DOUBLE_POINT_H_
#include <iosfwd>
#include "third_party/blink/renderer/platform/geometry/double_size.h"
#include "third_party/blink/renderer/platform/geometry/float_point.h"
#include "third_party/blink/renderer/platform/geometry/int_point.h"
#include "third_party/blink/renderer/platform/wtf/allocator.h"
#include "third_party/blink/renderer/platform/wtf/forward.h"
namespace blink {
class LayoutPoint;
class PLATFORM_EXPORT DoublePoint {
DISALLOW_NEW();
public:
constexpr DoublePoint() : x_(0), y_(0) {}
constexpr DoublePoint(double x, double y) : x_(x), y_(y) {}
constexpr DoublePoint(const IntPoint& p) : x_(p.X()), y_(p.Y()) {}
constexpr DoublePoint(const FloatPoint& p) : x_(p.X()), y_(p.Y()) {}
explicit DoublePoint(const LayoutPoint&);
constexpr explicit DoublePoint(const IntSize& size)
: x_(size.Width()), y_(size.Height()) {}
explicit DoublePoint(const FloatSize&);
constexpr explicit DoublePoint(const DoubleSize& size)
: x_(size.Width()), y_(size.Height()) {}
static constexpr DoublePoint Zero() { return DoublePoint(); }
DoublePoint ExpandedTo(const DoublePoint&) const;
DoublePoint ShrunkTo(const DoublePoint&) const;
constexpr double X() const { return x_; }
constexpr double Y() const { return y_; }
void SetX(double x) { x_ = x; }
void SetY(double y) { y_ = y; }
void Move(const DoubleSize& s) {
x_ += s.Width();
y_ += s.Height();
}
void Move(double x, double y) {
x_ += x;
y_ += y;
}
void MoveBy(const DoublePoint& p) {
x_ += p.X();
y_ += p.Y();
}
void Scale(float sx, float sy) {
x_ *= sx;
y_ *= sy;
}
DoublePoint ScaledBy(float scale) const {
return DoublePoint(x_ * scale, y_ * scale);
}
String ToString() const;
private:
double x_, y_;
};
constexpr bool operator==(const DoublePoint& a, const DoublePoint& b) {
return a.X() == b.X() && a.Y() == b.Y();
}
constexpr bool operator!=(const DoublePoint& a, const DoublePoint& b) {
return !(a == b);
}
inline DoublePoint& operator+=(DoublePoint& a, const DoubleSize& b) {
a.SetX(a.X() + b.Width());
a.SetY(a.Y() + b.Height());
return a;
}
inline DoublePoint& operator-=(DoublePoint& a, const DoubleSize& b) {
a.SetX(a.X() - b.Width());
a.SetY(a.Y() - b.Height());
return a;
}
constexpr DoublePoint operator+(const DoublePoint& a, const DoubleSize& b) {
return DoublePoint(a.X() + b.Width(), a.Y() + b.Height());
}
constexpr DoubleSize operator-(const DoublePoint& a, const DoublePoint& b) {
return DoubleSize(a.X() - b.X(), a.Y() - b.Y());
}
constexpr DoublePoint operator-(const DoublePoint& a) {
return DoublePoint(-a.X(), -a.Y());
}
constexpr DoublePoint operator-(const DoublePoint& a, const DoubleSize& b) {
return DoublePoint(a.X() - b.Width(), a.Y() - b.Height());
}
inline IntPoint RoundedIntPoint(const DoublePoint& p) {
return IntPoint(clampTo<int>(round(p.X())), clampTo<int>(round(p.Y())));
}
inline IntPoint CeiledIntPoint(const DoublePoint& p) {
return IntPoint(clampTo<int>(ceil(p.X())), clampTo<int>(ceil(p.Y())));
}
inline IntPoint FlooredIntPoint(const DoublePoint& p) {
return IntPoint(clampTo<int>(floor(p.X())), clampTo<int>(floor(p.Y())));
}
constexpr FloatPoint ToFloatPoint(const DoublePoint& a) {
return FloatPoint(a.X(), a.Y());
}
constexpr DoubleSize ToDoubleSize(const DoublePoint& a) {
return DoubleSize(a.X(), a.Y());
}
PLATFORM_EXPORT std::ostream& operator<<(std::ostream&, const DoublePoint&);
} // namespace blink
#endif
|