soui 5.0.0.1
Soui5 Doc
 
Loading...
Searching...
No Matches
SPoint.h
1/*
2 * Copyright 2006 The Android Open Source Project
3 *
4 * Use of this source code is governed by a BSD-style license that can be
5 * found in the LICENSE file.
6 */
7
8#ifndef _SPoint_DEFINED_
9#define _SPoint_DEFINED_
10
11#include <interface/SRender-i.h>
12#include <matrix/SFloat.h>
13
14SNSBEGIN
15
16struct SOUI_EXP SPoint : public fPoint
17{
18 static SPoint Make(float x, float y)
19 {
20 SPoint pt;
21 pt.set(x, y);
22 return pt;
23 }
24
25 static SPoint IMake(int32_t x, int32_t y)
26 {
27 SPoint pt;
28 pt.iset(x, y);
29 return pt;
30 }
31
32 static SPoint IMake(const POINT &src)
33 {
34 SPoint pt;
35 pt.iset(src.x, src.y);
36 return pt;
37 }
38
39 float x() const
40 {
41 return fX;
42 }
43 float y() const
44 {
45 return fY;
46 }
47
48 /**
49 * Returns true iff fX and fY are both zero.
50 */
51 bool isZero() const
52 {
53 return (0 == fX) & (0 == fY);
54 }
55
56 /** Set the point's X and Y coordinates */
57 void set(float x, float y)
58 {
59 fX = x;
60 fY = y;
61 }
62
63 /** Set the point's X and Y coordinates by automatically promoting (x,y) to
64 float values.
65 */
66 void iset(int32_t x, int32_t y);
67
68 /** Set the point's X and Y coordinates by automatically promoting p's
69 coordinates to float values.
70 */
71 void iset(const POINT &p);
72
73 /** Return the euclidian distance from (0,0) to the point
74 */
75 float length() const
76 {
77 return SPoint::Length(fX, fY);
78 }
79 /** Returns a new point whose coordinates are the negative of the point's
80 */
81 SPoint operator-() const
82 {
83 SPoint neg;
84 neg.fX = -fX;
85 neg.fY = -fY;
86 return neg;
87 }
88
89 /** Add v's coordinates to the point's
90 */
91 void operator+=(const SPoint &v)
92 {
93 fX += v.fX;
94 fY += v.fY;
95 }
96
97 /** Subtract v's coordinates from the point's
98 */
99 void operator-=(const SPoint &v)
100 {
101 fX -= v.fX;
102 fY -= v.fY;
103 }
104
105 friend bool operator==(const SPoint &a, const SPoint &b)
106 {
107 return a.fX == b.fX && a.fY == b.fY;
108 }
109
110 friend bool operator!=(const SPoint &a, const SPoint &b)
111 {
112 return a.fX != b.fX || a.fY != b.fY;
113 }
114
115 /** Returns a new point whose coordinates are the difference between
116 a's and b's (a - b)
117 */
118 friend SPoint operator-(const SPoint &a, const SPoint &b)
119 {
120 SPoint v;
121 v.set(a.fX - b.fX, a.fY - b.fY);
122 return v;
123 }
124
125 /** Returns a new point whose coordinates are the sum of a's and b's (a + b)
126 */
127 friend SPoint operator+(const SPoint &a, const SPoint &b)
128 {
129 SPoint v;
130 v.set(a.fX + b.fX, a.fY + b.fY);
131 return v;
132 }
133 /** Returns the euclidian distance from (0,0) to (x,y)
134 */
135 static float Length(float x, float y);
136
137 /** Returns the dot product of a and b, treating them as 2D vectors
138 */
139 static float DotProduct(const SPoint &a, const SPoint &b);
140
141 float dot(const SPoint &vec) const;
142
143 POINT toPoint() const;
144};
145
146typedef SPoint SVector2D;
147SNSEND
148#endif