Flutter Engine
The Flutter Engine
Loading...
Searching...
No Matches
point.cc
Go to the documentation of this file.
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.
4
5#include "point.h"
6
8#include "base/string_utils.h"
9#include "point_conversions.h"
10#include "point_f.h"
11
12#if defined(OS_WIN)
13#include <windows.h>
14#elif defined(OS_IOS)
15#include <CoreGraphics/CoreGraphics.h>
16#elif defined(OS_APPLE)
17#include <ApplicationServices/ApplicationServices.h>
18#endif
19
20namespace gfx {
21
22#if defined(OS_WIN)
23Point::Point(DWORD point) {
24 POINTS points = MAKEPOINTS(point);
25 x_ = points.x;
26 y_ = points.y;
27}
28
29Point::Point(const POINT& point) : x_(point.x), y_(point.y) {}
30
31Point& Point::operator=(const POINT& point) {
32 x_ = point.x;
33 y_ = point.y;
34 return *this;
35}
36#elif defined(OS_APPLE)
37Point::Point(const CGPoint& point) : x_(point.x), y_(point.y) {}
38#endif
39
40#if defined(OS_WIN)
41POINT Point::ToPOINT() const {
42 POINT p;
43 p.x = x();
44 p.y = y();
45 return p;
46}
47#elif defined(OS_APPLE)
48CGPoint Point::ToCGPoint() const {
49 return CGPointMake(x(), y());
50}
51#endif
52
53void Point::SetToMin(const Point& other) {
54 x_ = x_ <= other.x_ ? x_ : other.x_;
55 y_ = y_ <= other.y_ ? y_ : other.y_;
56}
57
58void Point::SetToMax(const Point& other) {
59 x_ = x_ >= other.x_ ? x_ : other.x_;
60 y_ = y_ >= other.y_ ? y_ : other.y_;
61}
62
63std::string Point::ToString() const {
64 return base::StringPrintf("%d,%d", x(), y());
65}
66
67Point ScaleToCeiledPoint(const Point& point, float x_scale, float y_scale) {
68 if (x_scale == 1.f && y_scale == 1.f)
69 return point;
70 return ToCeiledPoint(ScalePoint(gfx::PointF(point), x_scale, y_scale));
71}
72
73Point ScaleToCeiledPoint(const Point& point, float scale) {
74 if (scale == 1.f)
75 return point;
77}
78
79Point ScaleToFlooredPoint(const Point& point, float x_scale, float y_scale) {
80 if (x_scale == 1.f && y_scale == 1.f)
81 return point;
82 return ToFlooredPoint(ScalePoint(gfx::PointF(point), x_scale, y_scale));
83}
84
85Point ScaleToFlooredPoint(const Point& point, float scale) {
86 if (scale == 1.f)
87 return point;
89}
90
91Point ScaleToRoundedPoint(const Point& point, float x_scale, float y_scale) {
92 if (x_scale == 1.f && y_scale == 1.f)
93 return point;
94 return ToRoundedPoint(ScalePoint(gfx::PointF(point), x_scale, y_scale));
95}
96
97Point ScaleToRoundedPoint(const Point& point, float scale) {
98 if (scale == 1.f)
99 return point;
101}
102
103} // namespace gfx
static const int points[]
constexpr Point()
Definition point.h:29
double y
double x
std::string StringPrintf(const std::string &format, Args... args)
Definition insets.cc:10
Point ScaleToCeiledPoint(const Point &point, float x_scale, float y_scale)
Definition point.cc:67
Point ToRoundedPoint(const PointF &point)
Point ScaleToFlooredPoint(const Point &point, float x_scale, float y_scale)
Definition point.cc:79
PointF ScalePoint(const PointF &p, float x_scale, float y_scale)
Definition point_f.cc:25
Point ToCeiledPoint(const PointF &point)
Point ScaleToRoundedPoint(const Point &point, float x_scale, float y_scale)
Definition point.cc:91
Point ToFlooredPoint(const PointF &point)
TPoint< Scalar > Point
Definition point.h:316
const Scalar scale
unsigned long DWORD