OLD | NEW |
---|---|
(Empty) | |
1 /* | |
2 * Copyright (c) 2014, Google Inc. All rights reserved. | |
3 * | |
4 * Redistribution and use in source and binary forms, with or without | |
5 * modification, are permitted provided that the following conditions are | |
6 * met: | |
7 * | |
8 * * Redistributions of source code must retain the above copyright | |
9 * notice, this list of conditions and the following disclaimer. | |
10 * * Redistributions in binary form must reproduce the above | |
11 * copyright notice, this list of conditions and the following disclaimer | |
12 * in the documentation and/or other materials provided with the | |
13 * distribution. | |
14 * * Neither the name of Google Inc. nor the names of its | |
15 * contributors may be used to endorse or promote products derived from | |
16 * this software without specific prior written permission. | |
17 * | |
18 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS | |
19 * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT | |
20 * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR | |
21 * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT | |
22 * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, | |
23 * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT | |
24 * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, | |
25 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY | |
26 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT | |
27 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE | |
28 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. | |
29 */ | |
30 #ifndef FloatBox_h | |
31 #define FloatBox_h | |
32 | |
33 #include "platform/geometry/FloatPoint3D.h" | |
34 #include <cmath> | |
35 | |
36 namespace WebCore { | |
37 | |
38 class FloatBox { | |
39 public: | |
40 | |
Ian Vollick
2014/06/16 15:23:37
nit: extra ws.
awoloszyn
2014/06/17 14:26:00
Done.
| |
41 FloatBox() | |
42 : m_x(0) | |
43 , m_y(0) | |
44 , m_z(0) | |
45 , m_width(0) | |
46 , m_height(0) | |
47 , m_depth(0) | |
48 { | |
49 } | |
50 | |
51 FloatBox(float x, float y, float z, float width, float height, float depth) | |
52 : m_x(x) | |
53 , m_y(y) | |
54 , m_z(z) | |
55 , m_width(width) | |
56 , m_height(height) | |
57 , m_depth(depth) | |
58 { | |
59 } | |
60 | |
61 FloatBox(const FloatBox& box) | |
62 : m_x(box.x()) | |
63 , m_y(box.y()) | |
64 , m_z(box.z()) | |
65 , m_width(box.width()) | |
66 , m_height(box.height()) | |
67 , m_depth(box.depth()) | |
68 { | |
69 } | |
70 | |
71 void setOrigin(const FloatPoint3D& origin) | |
72 { | |
73 m_x = origin.x(); | |
74 m_y = origin.y(); | |
75 m_z = origin.z(); | |
76 } | |
77 | |
78 void setSize(const FloatPoint3D& origin) | |
79 { | |
80 ASSERT(origin.x() >= 0); | |
81 ASSERT(origin.y() >= 0); | |
82 ASSERT(origin.z() >= 0); | |
83 | |
84 m_width = origin.x(); | |
85 m_height = origin.y(); | |
86 m_depth = origin.z(); | |
87 } | |
88 | |
89 void move(const FloatPoint3D& location) | |
90 { | |
91 m_x += location.x(); | |
92 m_y += location.y(); | |
93 m_z += location.z(); | |
94 } | |
95 | |
96 void flatten() | |
97 { | |
98 m_z = 0; | |
99 m_depth = 0; | |
100 } | |
101 | |
102 void expandTo(const FloatPoint3D& low, const FloatPoint3D& high) | |
103 { | |
104 ASSERT(low.x() <= high.x()); | |
105 ASSERT(low.y() <= high.y()); | |
106 ASSERT(low.z() <= high.z()); | |
107 | |
108 float minX = std::min(m_x, low.x()); | |
109 float minY = std::min(m_y, low.y()); | |
110 float minZ = std::min(m_z, low.z()); | |
111 | |
112 float maxX = std::max(right(), high.x()); | |
113 float maxY = std::max(bottom(), high.y()); | |
114 float maxZ = std::max(front(), high.z()); | |
115 | |
116 m_x = minX; | |
117 m_y = minY; | |
118 m_z = minZ; | |
119 | |
120 m_width = maxX - minX; | |
121 m_height = maxY - minY; | |
122 m_depth = maxZ - minZ; | |
123 } | |
124 | |
125 void expandTo(const FloatPoint3D& point) | |
126 { | |
127 expandTo(point, point); | |
128 } | |
129 | |
130 void expandTo(const FloatBox& box) | |
131 { | |
132 expandTo(FloatPoint3D(box.x(), box.y(), box.z()), FloatPoint3D(box.right (), box.bottom(), box.front())); | |
133 } | |
134 | |
135 void unionBounds(const FloatBox& box) | |
136 { | |
137 if (box.isEmpty()) | |
138 return; | |
139 | |
140 if (isEmpty()) { | |
141 *this = box; | |
142 return; | |
143 } | |
144 | |
145 expandTo(box); | |
146 } | |
147 | |
148 bool isEmpty() const { return (m_width <= 0 && m_height <= 0) || (m_width <= 0 && m_depth <= 0) || (m_height <= 0 && m_depth <= 0); } | |
149 | |
150 float right() const { return m_x + m_width; } | |
151 float bottom() const { return m_y + m_height; } | |
152 float front() const { return m_z + m_depth; } | |
153 float x() const { return m_x; } | |
154 float y() const { return m_y; } | |
155 float z() const { return m_z; } | |
156 float width() const { return m_width; } | |
157 float height() const { return m_height; } | |
158 float depth() const { return m_depth; } | |
159 private: | |
160 float m_x; | |
161 float m_y; | |
162 float m_z; | |
163 float m_width; | |
164 float m_height; | |
165 float m_depth; | |
166 }; | |
167 | |
168 inline bool operator==(const FloatBox& a, const FloatBox& b) | |
169 { | |
170 return a.x() == b.x() && a.y() == b.y() && a.z() == b.z() && a.width() == b. width() | |
171 && a.height() == b.height() && a.depth() == b.depth(); | |
172 } | |
173 | |
174 inline bool operator!=(const FloatBox& a, const FloatBox& b) | |
175 { | |
176 return !(a == b); | |
177 } | |
178 | |
179 } // namespace WebKit | |
180 | |
181 #endif | |
OLD | NEW |