1 // Copyright (c) 2012 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file.
5 #ifndef UI_GFX_POINT_BASE_H_
6 #define UI_GFX_POINT_BASE_H_
10 #include "base/compiler_specific.h"
11 #include "build/build_config.h"
12 #include "ui/gfx/gfx_export.h"
16 // A point has an x and y coordinate.
17 template<typename Class, typename Type, typename VectorClass>
18 class GFX_EXPORT PointBase {
20 Type x() const { return x_; }
21 Type y() const { return y_; }
23 void SetPoint(Type x, Type y) {
28 void set_x(Type x) { x_ = x; }
29 void set_y(Type y) { y_ = y; }
31 void Offset(Type delta_x, Type delta_y) {
36 void operator+=(const VectorClass& vector) {
41 void operator-=(const VectorClass& vector) {
46 void SetToMin(const Class& other) {
47 x_ = x_ <= other.x_ ? x_ : other.x_;
48 y_ = y_ <= other.y_ ? y_ : other.y_;
51 void SetToMax(const Class& other) {
52 x_ = x_ >= other.x_ ? x_ : other.x_;
53 y_ = y_ >= other.y_ ? y_ : other.y_;
56 bool IsOrigin() const {
57 return x_ == 0 && y_ == 0;
60 VectorClass OffsetFromOrigin() const {
61 return VectorClass(x_, y_);
64 // A point is less than another point if its y-value is closer
65 // to the origin. If the y-values are the same, then point with
66 // the x-value closer to the origin is considered less than the
68 // This comparison is required to use Point in sets, or sorted
70 bool operator<(const Class& rhs) const {
71 return (y_ == rhs.y_) ? (x_ < rhs.x_) : (y_ < rhs.y_);
75 PointBase(Type x, Type y) : x_(x), y_(y) {}
76 // Destructor is intentionally made non virtual and protected.
77 // Do not make this public.
87 #endif // UI_GFX_POINT_BASE_H_