1*635a8641SAndroid Build Coastguard Worker // Copyright (c) 2012 The Chromium Authors. All rights reserved.
2*635a8641SAndroid Build Coastguard Worker // Use of this source code is governed by a BSD-style license that can be
3*635a8641SAndroid Build Coastguard Worker // found in the LICENSE file.
4*635a8641SAndroid Build Coastguard Worker
5*635a8641SAndroid Build Coastguard Worker #include "ui/gfx/geometry/point.h"
6*635a8641SAndroid Build Coastguard Worker
7*635a8641SAndroid Build Coastguard Worker #include "base/strings/stringprintf.h"
8*635a8641SAndroid Build Coastguard Worker #include "build/build_config.h"
9*635a8641SAndroid Build Coastguard Worker #include "ui/gfx/geometry/point_conversions.h"
10*635a8641SAndroid Build Coastguard Worker #include "ui/gfx/geometry/point_f.h"
11*635a8641SAndroid Build Coastguard Worker
12*635a8641SAndroid Build Coastguard Worker #if defined(OS_WIN)
13*635a8641SAndroid Build Coastguard Worker #include <windows.h>
14*635a8641SAndroid Build Coastguard Worker #elif defined(OS_IOS)
15*635a8641SAndroid Build Coastguard Worker #include <CoreGraphics/CoreGraphics.h>
16*635a8641SAndroid Build Coastguard Worker #elif defined(OS_MACOSX)
17*635a8641SAndroid Build Coastguard Worker #include <ApplicationServices/ApplicationServices.h>
18*635a8641SAndroid Build Coastguard Worker #endif
19*635a8641SAndroid Build Coastguard Worker
20*635a8641SAndroid Build Coastguard Worker namespace gfx {
21*635a8641SAndroid Build Coastguard Worker
22*635a8641SAndroid Build Coastguard Worker #if defined(OS_WIN)
Point(DWORD point)23*635a8641SAndroid Build Coastguard Worker Point::Point(DWORD point) {
24*635a8641SAndroid Build Coastguard Worker POINTS points = MAKEPOINTS(point);
25*635a8641SAndroid Build Coastguard Worker x_ = points.x;
26*635a8641SAndroid Build Coastguard Worker y_ = points.y;
27*635a8641SAndroid Build Coastguard Worker }
28*635a8641SAndroid Build Coastguard Worker
Point(const POINT & point)29*635a8641SAndroid Build Coastguard Worker Point::Point(const POINT& point) : x_(point.x), y_(point.y) {
30*635a8641SAndroid Build Coastguard Worker }
31*635a8641SAndroid Build Coastguard Worker
operator =(const POINT & point)32*635a8641SAndroid Build Coastguard Worker Point& Point::operator=(const POINT& point) {
33*635a8641SAndroid Build Coastguard Worker x_ = point.x;
34*635a8641SAndroid Build Coastguard Worker y_ = point.y;
35*635a8641SAndroid Build Coastguard Worker return *this;
36*635a8641SAndroid Build Coastguard Worker }
37*635a8641SAndroid Build Coastguard Worker #elif defined(OS_MACOSX)
38*635a8641SAndroid Build Coastguard Worker Point::Point(const CGPoint& point) : x_(point.x), y_(point.y) {
39*635a8641SAndroid Build Coastguard Worker }
40*635a8641SAndroid Build Coastguard Worker #endif
41*635a8641SAndroid Build Coastguard Worker
42*635a8641SAndroid Build Coastguard Worker #if defined(OS_WIN)
ToPOINT() const43*635a8641SAndroid Build Coastguard Worker POINT Point::ToPOINT() const {
44*635a8641SAndroid Build Coastguard Worker POINT p;
45*635a8641SAndroid Build Coastguard Worker p.x = x();
46*635a8641SAndroid Build Coastguard Worker p.y = y();
47*635a8641SAndroid Build Coastguard Worker return p;
48*635a8641SAndroid Build Coastguard Worker }
49*635a8641SAndroid Build Coastguard Worker #elif defined(OS_MACOSX)
ToCGPoint() const50*635a8641SAndroid Build Coastguard Worker CGPoint Point::ToCGPoint() const {
51*635a8641SAndroid Build Coastguard Worker return CGPointMake(x(), y());
52*635a8641SAndroid Build Coastguard Worker }
53*635a8641SAndroid Build Coastguard Worker #endif
54*635a8641SAndroid Build Coastguard Worker
SetToMin(const Point & other)55*635a8641SAndroid Build Coastguard Worker void Point::SetToMin(const Point& other) {
56*635a8641SAndroid Build Coastguard Worker x_ = x_ <= other.x_ ? x_ : other.x_;
57*635a8641SAndroid Build Coastguard Worker y_ = y_ <= other.y_ ? y_ : other.y_;
58*635a8641SAndroid Build Coastguard Worker }
59*635a8641SAndroid Build Coastguard Worker
SetToMax(const Point & other)60*635a8641SAndroid Build Coastguard Worker void Point::SetToMax(const Point& other) {
61*635a8641SAndroid Build Coastguard Worker x_ = x_ >= other.x_ ? x_ : other.x_;
62*635a8641SAndroid Build Coastguard Worker y_ = y_ >= other.y_ ? y_ : other.y_;
63*635a8641SAndroid Build Coastguard Worker }
64*635a8641SAndroid Build Coastguard Worker
ToString() const65*635a8641SAndroid Build Coastguard Worker std::string Point::ToString() const {
66*635a8641SAndroid Build Coastguard Worker return base::StringPrintf("%d,%d", x(), y());
67*635a8641SAndroid Build Coastguard Worker }
68*635a8641SAndroid Build Coastguard Worker
ScaleToCeiledPoint(const Point & point,float x_scale,float y_scale)69*635a8641SAndroid Build Coastguard Worker Point ScaleToCeiledPoint(const Point& point, float x_scale, float y_scale) {
70*635a8641SAndroid Build Coastguard Worker if (x_scale == 1.f && y_scale == 1.f)
71*635a8641SAndroid Build Coastguard Worker return point;
72*635a8641SAndroid Build Coastguard Worker return ToCeiledPoint(ScalePoint(gfx::PointF(point), x_scale, y_scale));
73*635a8641SAndroid Build Coastguard Worker }
74*635a8641SAndroid Build Coastguard Worker
ScaleToCeiledPoint(const Point & point,float scale)75*635a8641SAndroid Build Coastguard Worker Point ScaleToCeiledPoint(const Point& point, float scale) {
76*635a8641SAndroid Build Coastguard Worker if (scale == 1.f)
77*635a8641SAndroid Build Coastguard Worker return point;
78*635a8641SAndroid Build Coastguard Worker return ToCeiledPoint(ScalePoint(gfx::PointF(point), scale, scale));
79*635a8641SAndroid Build Coastguard Worker }
80*635a8641SAndroid Build Coastguard Worker
ScaleToFlooredPoint(const Point & point,float x_scale,float y_scale)81*635a8641SAndroid Build Coastguard Worker Point ScaleToFlooredPoint(const Point& point, float x_scale, float y_scale) {
82*635a8641SAndroid Build Coastguard Worker if (x_scale == 1.f && y_scale == 1.f)
83*635a8641SAndroid Build Coastguard Worker return point;
84*635a8641SAndroid Build Coastguard Worker return ToFlooredPoint(ScalePoint(gfx::PointF(point), x_scale, y_scale));
85*635a8641SAndroid Build Coastguard Worker }
86*635a8641SAndroid Build Coastguard Worker
ScaleToFlooredPoint(const Point & point,float scale)87*635a8641SAndroid Build Coastguard Worker Point ScaleToFlooredPoint(const Point& point, float scale) {
88*635a8641SAndroid Build Coastguard Worker if (scale == 1.f)
89*635a8641SAndroid Build Coastguard Worker return point;
90*635a8641SAndroid Build Coastguard Worker return ToFlooredPoint(ScalePoint(gfx::PointF(point), scale, scale));
91*635a8641SAndroid Build Coastguard Worker }
92*635a8641SAndroid Build Coastguard Worker
ScaleToRoundedPoint(const Point & point,float x_scale,float y_scale)93*635a8641SAndroid Build Coastguard Worker Point ScaleToRoundedPoint(const Point& point, float x_scale, float y_scale) {
94*635a8641SAndroid Build Coastguard Worker if (x_scale == 1.f && y_scale == 1.f)
95*635a8641SAndroid Build Coastguard Worker return point;
96*635a8641SAndroid Build Coastguard Worker return ToRoundedPoint(ScalePoint(gfx::PointF(point), x_scale, y_scale));
97*635a8641SAndroid Build Coastguard Worker }
98*635a8641SAndroid Build Coastguard Worker
ScaleToRoundedPoint(const Point & point,float scale)99*635a8641SAndroid Build Coastguard Worker Point ScaleToRoundedPoint(const Point& point, float scale) {
100*635a8641SAndroid Build Coastguard Worker if (scale == 1.f)
101*635a8641SAndroid Build Coastguard Worker return point;
102*635a8641SAndroid Build Coastguard Worker return ToRoundedPoint(ScalePoint(gfx::PointF(point), scale, scale));
103*635a8641SAndroid Build Coastguard Worker }
104*635a8641SAndroid Build Coastguard Worker
105*635a8641SAndroid Build Coastguard Worker } // namespace gfx
106