| OLD | NEW |
| 1 // Copyright 2012 The Chromium Authors. All rights reserved. | 1 // Copyright 2012 The Chromium Authors. All rights reserved. |
| 2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
| 4 | 4 |
| 5 #include "config.h" | 5 #include "config.h" |
| 6 | 6 |
| 7 #include "CCMathUtil.h" | 7 #include "CCMathUtil.h" |
| 8 | 8 |
| 9 #include "FloatPoint.h" | 9 #include "FloatPoint.h" |
| 10 #include "FloatQuad.h" | 10 #include "FloatQuad.h" |
| (...skipping 77 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 88 ymin = std::min(p.y(), ymin); | 88 ymin = std::min(p.y(), ymin); |
| 89 ymax = std::max(p.y(), ymax); | 89 ymax = std::max(p.y(), ymax); |
| 90 } | 90 } |
| 91 | 91 |
| 92 static inline void addVertexToClippedQuad(const FloatPoint& newVertex, FloatPoin
t clippedQuad[8], int& numVerticesInClippedQuad) | 92 static inline void addVertexToClippedQuad(const FloatPoint& newVertex, FloatPoin
t clippedQuad[8], int& numVerticesInClippedQuad) |
| 93 { | 93 { |
| 94 clippedQuad[numVerticesInClippedQuad] = newVertex; | 94 clippedQuad[numVerticesInClippedQuad] = newVertex; |
| 95 numVerticesInClippedQuad++; | 95 numVerticesInClippedQuad++; |
| 96 } | 96 } |
| 97 | 97 |
| 98 IntRect CCMathUtil::mapClippedRect(const WebTransformationMatrix& transform, con
st IntRect& srcRect) | 98 IntRect MathUtil::mapClippedRect(const WebTransformationMatrix& transform, const
IntRect& srcRect) |
| 99 { | 99 { |
| 100 return enclosingIntRect(mapClippedRect(transform, FloatRect(srcRect))); | 100 return enclosingIntRect(mapClippedRect(transform, FloatRect(srcRect))); |
| 101 } | 101 } |
| 102 | 102 |
| 103 FloatRect CCMathUtil::mapClippedRect(const WebTransformationMatrix& transform, c
onst FloatRect& srcRect) | 103 FloatRect MathUtil::mapClippedRect(const WebTransformationMatrix& transform, con
st FloatRect& srcRect) |
| 104 { | 104 { |
| 105 if (transform.isIdentityOrTranslation()) { | 105 if (transform.isIdentityOrTranslation()) { |
| 106 FloatRect mappedRect(srcRect); | 106 FloatRect mappedRect(srcRect); |
| 107 mappedRect.move(static_cast<float>(transform.m41()), static_cast<float>(
transform.m42())); | 107 mappedRect.move(static_cast<float>(transform.m41()), static_cast<float>(
transform.m42())); |
| 108 return mappedRect; | 108 return mappedRect; |
| 109 } | 109 } |
| 110 | 110 |
| 111 // Apply the transform, but retain the result in homogeneous coordinates. | 111 // Apply the transform, but retain the result in homogeneous coordinates. |
| 112 FloatQuad q = FloatQuad(FloatRect(srcRect)); | 112 FloatQuad q = FloatQuad(FloatRect(srcRect)); |
| 113 HomogeneousCoordinate h1 = mapHomogeneousPoint(transform, q.p1()); | 113 HomogeneousCoordinate h1 = mapHomogeneousPoint(transform, q.p1()); |
| 114 HomogeneousCoordinate h2 = mapHomogeneousPoint(transform, q.p2()); | 114 HomogeneousCoordinate h2 = mapHomogeneousPoint(transform, q.p2()); |
| 115 HomogeneousCoordinate h3 = mapHomogeneousPoint(transform, q.p3()); | 115 HomogeneousCoordinate h3 = mapHomogeneousPoint(transform, q.p3()); |
| 116 HomogeneousCoordinate h4 = mapHomogeneousPoint(transform, q.p4()); | 116 HomogeneousCoordinate h4 = mapHomogeneousPoint(transform, q.p4()); |
| 117 | 117 |
| 118 return computeEnclosingClippedRect(h1, h2, h3, h4); | 118 return computeEnclosingClippedRect(h1, h2, h3, h4); |
| 119 } | 119 } |
| 120 | 120 |
| 121 FloatRect CCMathUtil::projectClippedRect(const WebTransformationMatrix& transfor
m, const FloatRect& srcRect) | 121 FloatRect MathUtil::projectClippedRect(const WebTransformationMatrix& transform,
const FloatRect& srcRect) |
| 122 { | 122 { |
| 123 // Perform the projection, but retain the result in homogeneous coordinates. | 123 // Perform the projection, but retain the result in homogeneous coordinates. |
| 124 FloatQuad q = FloatQuad(FloatRect(srcRect)); | 124 FloatQuad q = FloatQuad(FloatRect(srcRect)); |
| 125 HomogeneousCoordinate h1 = projectHomogeneousPoint(transform, q.p1()); | 125 HomogeneousCoordinate h1 = projectHomogeneousPoint(transform, q.p1()); |
| 126 HomogeneousCoordinate h2 = projectHomogeneousPoint(transform, q.p2()); | 126 HomogeneousCoordinate h2 = projectHomogeneousPoint(transform, q.p2()); |
| 127 HomogeneousCoordinate h3 = projectHomogeneousPoint(transform, q.p3()); | 127 HomogeneousCoordinate h3 = projectHomogeneousPoint(transform, q.p3()); |
| 128 HomogeneousCoordinate h4 = projectHomogeneousPoint(transform, q.p4()); | 128 HomogeneousCoordinate h4 = projectHomogeneousPoint(transform, q.p4()); |
| 129 | 129 |
| 130 return computeEnclosingClippedRect(h1, h2, h3, h4); | 130 return computeEnclosingClippedRect(h1, h2, h3, h4); |
| 131 } | 131 } |
| 132 | 132 |
| 133 void CCMathUtil::mapClippedQuad(const WebTransformationMatrix& transform, const
FloatQuad& srcQuad, FloatPoint clippedQuad[8], int& numVerticesInClippedQuad) | 133 void MathUtil::mapClippedQuad(const WebTransformationMatrix& transform, const Fl
oatQuad& srcQuad, FloatPoint clippedQuad[8], int& numVerticesInClippedQuad) |
| 134 { | 134 { |
| 135 HomogeneousCoordinate h1 = mapHomogeneousPoint(transform, srcQuad.p1()); | 135 HomogeneousCoordinate h1 = mapHomogeneousPoint(transform, srcQuad.p1()); |
| 136 HomogeneousCoordinate h2 = mapHomogeneousPoint(transform, srcQuad.p2()); | 136 HomogeneousCoordinate h2 = mapHomogeneousPoint(transform, srcQuad.p2()); |
| 137 HomogeneousCoordinate h3 = mapHomogeneousPoint(transform, srcQuad.p3()); | 137 HomogeneousCoordinate h3 = mapHomogeneousPoint(transform, srcQuad.p3()); |
| 138 HomogeneousCoordinate h4 = mapHomogeneousPoint(transform, srcQuad.p4()); | 138 HomogeneousCoordinate h4 = mapHomogeneousPoint(transform, srcQuad.p4()); |
| 139 | 139 |
| 140 // The order of adding the vertices to the array is chosen so that clockwise
/ counter-clockwise orientation is retained. | 140 // The order of adding the vertices to the array is chosen so that clockwise
/ counter-clockwise orientation is retained. |
| 141 | 141 |
| 142 numVerticesInClippedQuad = 0; | 142 numVerticesInClippedQuad = 0; |
| 143 | 143 |
| (...skipping 17 matching lines...) Expand all Loading... |
| 161 | 161 |
| 162 if (!h4.shouldBeClipped()) | 162 if (!h4.shouldBeClipped()) |
| 163 addVertexToClippedQuad(h4.cartesianPoint2d(), clippedQuad, numVerticesIn
ClippedQuad); | 163 addVertexToClippedQuad(h4.cartesianPoint2d(), clippedQuad, numVerticesIn
ClippedQuad); |
| 164 | 164 |
| 165 if (h4.shouldBeClipped() ^ h1.shouldBeClipped()) | 165 if (h4.shouldBeClipped() ^ h1.shouldBeClipped()) |
| 166 addVertexToClippedQuad(computeClippedPointForEdge(h4, h1).cartesianPoint
2d(), clippedQuad, numVerticesInClippedQuad); | 166 addVertexToClippedQuad(computeClippedPointForEdge(h4, h1).cartesianPoint
2d(), clippedQuad, numVerticesInClippedQuad); |
| 167 | 167 |
| 168 ASSERT(numVerticesInClippedQuad <= 8); | 168 ASSERT(numVerticesInClippedQuad <= 8); |
| 169 } | 169 } |
| 170 | 170 |
| 171 FloatRect CCMathUtil::computeEnclosingRectOfVertices(FloatPoint vertices[], int
numVertices) | 171 FloatRect MathUtil::computeEnclosingRectOfVertices(FloatPoint vertices[], int nu
mVertices) |
| 172 { | 172 { |
| 173 if (numVertices < 2) | 173 if (numVertices < 2) |
| 174 return FloatRect(); | 174 return FloatRect(); |
| 175 | 175 |
| 176 float xmin = std::numeric_limits<float>::max(); | 176 float xmin = std::numeric_limits<float>::max(); |
| 177 float xmax = -std::numeric_limits<float>::max(); | 177 float xmax = -std::numeric_limits<float>::max(); |
| 178 float ymin = std::numeric_limits<float>::max(); | 178 float ymin = std::numeric_limits<float>::max(); |
| 179 float ymax = -std::numeric_limits<float>::max(); | 179 float ymax = -std::numeric_limits<float>::max(); |
| 180 | 180 |
| 181 for (int i = 0; i < numVertices; ++i) | 181 for (int i = 0; i < numVertices; ++i) |
| 182 expandBoundsToIncludePoint(xmin, xmax, ymin, ymax, vertices[i]); | 182 expandBoundsToIncludePoint(xmin, xmax, ymin, ymax, vertices[i]); |
| 183 | 183 |
| 184 return FloatRect(FloatPoint(xmin, ymin), FloatSize(xmax - xmin, ymax - ymin)
); | 184 return FloatRect(FloatPoint(xmin, ymin), FloatSize(xmax - xmin, ymax - ymin)
); |
| 185 } | 185 } |
| 186 | 186 |
| 187 FloatRect CCMathUtil::computeEnclosingClippedRect(const HomogeneousCoordinate& h
1, const HomogeneousCoordinate& h2, const HomogeneousCoordinate& h3, const Homog
eneousCoordinate& h4) | 187 FloatRect MathUtil::computeEnclosingClippedRect(const HomogeneousCoordinate& h1,
const HomogeneousCoordinate& h2, const HomogeneousCoordinate& h3, const Homogen
eousCoordinate& h4) |
| 188 { | 188 { |
| 189 // This function performs clipping as necessary and computes the enclosing 2
d | 189 // This function performs clipping as necessary and computes the enclosing 2
d |
| 190 // FloatRect of the vertices. Doing these two steps simultaneously allows us
to avoid | 190 // FloatRect of the vertices. Doing these two steps simultaneously allows us
to avoid |
| 191 // the overhead of storing an unknown number of clipped vertices. | 191 // the overhead of storing an unknown number of clipped vertices. |
| 192 | 192 |
| 193 // If no vertices on the quad are clipped, then we can simply return the enc
losing rect directly. | 193 // If no vertices on the quad are clipped, then we can simply return the enc
losing rect directly. |
| 194 bool somethingClipped = h1.shouldBeClipped() || h2.shouldBeClipped() || h3.s
houldBeClipped() || h4.shouldBeClipped(); | 194 bool somethingClipped = h1.shouldBeClipped() || h2.shouldBeClipped() || h3.s
houldBeClipped() || h4.shouldBeClipped(); |
| 195 if (!somethingClipped) { | 195 if (!somethingClipped) { |
| 196 FloatQuad mappedQuad = FloatQuad(h1.cartesianPoint2d(), h2.cartesianPoin
t2d(), h3.cartesianPoint2d(), h4.cartesianPoint2d()); | 196 FloatQuad mappedQuad = FloatQuad(h1.cartesianPoint2d(), h2.cartesianPoin
t2d(), h3.cartesianPoint2d(), h4.cartesianPoint2d()); |
| 197 return mappedQuad.boundingBox(); | 197 return mappedQuad.boundingBox(); |
| (...skipping 29 matching lines...) Expand all Loading... |
| 227 | 227 |
| 228 if (!h4.shouldBeClipped()) | 228 if (!h4.shouldBeClipped()) |
| 229 expandBoundsToIncludePoint(xmin, xmax, ymin, ymax, h4.cartesianPoint2d()
); | 229 expandBoundsToIncludePoint(xmin, xmax, ymin, ymax, h4.cartesianPoint2d()
); |
| 230 | 230 |
| 231 if (h4.shouldBeClipped() ^ h1.shouldBeClipped()) | 231 if (h4.shouldBeClipped() ^ h1.shouldBeClipped()) |
| 232 expandBoundsToIncludePoint(xmin, xmax, ymin, ymax, computeClippedPointFo
rEdge(h4, h1).cartesianPoint2d()); | 232 expandBoundsToIncludePoint(xmin, xmax, ymin, ymax, computeClippedPointFo
rEdge(h4, h1).cartesianPoint2d()); |
| 233 | 233 |
| 234 return FloatRect(FloatPoint(xmin, ymin), FloatSize(xmax - xmin, ymax - ymin)
); | 234 return FloatRect(FloatPoint(xmin, ymin), FloatSize(xmax - xmin, ymax - ymin)
); |
| 235 } | 235 } |
| 236 | 236 |
| 237 FloatQuad CCMathUtil::mapQuad(const WebTransformationMatrix& transform, const Fl
oatQuad& q, bool& clipped) | 237 FloatQuad MathUtil::mapQuad(const WebTransformationMatrix& transform, const Floa
tQuad& q, bool& clipped) |
| 238 { | 238 { |
| 239 if (transform.isIdentityOrTranslation()) { | 239 if (transform.isIdentityOrTranslation()) { |
| 240 FloatQuad mappedQuad(q); | 240 FloatQuad mappedQuad(q); |
| 241 mappedQuad.move(static_cast<float>(transform.m41()), static_cast<float>(
transform.m42())); | 241 mappedQuad.move(static_cast<float>(transform.m41()), static_cast<float>(
transform.m42())); |
| 242 clipped = false; | 242 clipped = false; |
| 243 return mappedQuad; | 243 return mappedQuad; |
| 244 } | 244 } |
| 245 | 245 |
| 246 HomogeneousCoordinate h1 = mapHomogeneousPoint(transform, q.p1()); | 246 HomogeneousCoordinate h1 = mapHomogeneousPoint(transform, q.p1()); |
| 247 HomogeneousCoordinate h2 = mapHomogeneousPoint(transform, q.p2()); | 247 HomogeneousCoordinate h2 = mapHomogeneousPoint(transform, q.p2()); |
| 248 HomogeneousCoordinate h3 = mapHomogeneousPoint(transform, q.p3()); | 248 HomogeneousCoordinate h3 = mapHomogeneousPoint(transform, q.p3()); |
| 249 HomogeneousCoordinate h4 = mapHomogeneousPoint(transform, q.p4()); | 249 HomogeneousCoordinate h4 = mapHomogeneousPoint(transform, q.p4()); |
| 250 | 250 |
| 251 clipped = h1.shouldBeClipped() || h2.shouldBeClipped() || h3.shouldBeClipped
() || h4.shouldBeClipped(); | 251 clipped = h1.shouldBeClipped() || h2.shouldBeClipped() || h3.shouldBeClipped
() || h4.shouldBeClipped(); |
| 252 | 252 |
| 253 // Result will be invalid if clipped == true. But, compute it anyway just in
case, to emulate existing behavior. | 253 // Result will be invalid if clipped == true. But, compute it anyway just in
case, to emulate existing behavior. |
| 254 return FloatQuad(h1.cartesianPoint2d(), h2.cartesianPoint2d(), h3.cartesianP
oint2d(), h4.cartesianPoint2d()); | 254 return FloatQuad(h1.cartesianPoint2d(), h2.cartesianPoint2d(), h3.cartesianP
oint2d(), h4.cartesianPoint2d()); |
| 255 } | 255 } |
| 256 | 256 |
| 257 FloatPoint CCMathUtil::mapPoint(const WebTransformationMatrix& transform, const
FloatPoint& p, bool& clipped) | 257 FloatPoint MathUtil::mapPoint(const WebTransformationMatrix& transform, const Fl
oatPoint& p, bool& clipped) |
| 258 { | 258 { |
| 259 HomogeneousCoordinate h = mapHomogeneousPoint(transform, p); | 259 HomogeneousCoordinate h = mapHomogeneousPoint(transform, p); |
| 260 | 260 |
| 261 if (h.w > 0) { | 261 if (h.w > 0) { |
| 262 clipped = false; | 262 clipped = false; |
| 263 return h.cartesianPoint2d(); | 263 return h.cartesianPoint2d(); |
| 264 } | 264 } |
| 265 | 265 |
| 266 // The cartesian coordinates will be invalid after dividing by w. | 266 // The cartesian coordinates will be invalid after dividing by w. |
| 267 clipped = true; | 267 clipped = true; |
| 268 | 268 |
| 269 // Avoid dividing by w if w == 0. | 269 // Avoid dividing by w if w == 0. |
| 270 if (!h.w) | 270 if (!h.w) |
| 271 return FloatPoint(); | 271 return FloatPoint(); |
| 272 | 272 |
| 273 // This return value will be invalid because clipped == true, but (1) users
of this | 273 // This return value will be invalid because clipped == true, but (1) users
of this |
| 274 // code should be ignoring the return value when clipped == true anyway, and
(2) this | 274 // code should be ignoring the return value when clipped == true anyway, and
(2) this |
| 275 // behavior is more consistent with existing behavior of WebKit transforms i
f the user | 275 // behavior is more consistent with existing behavior of WebKit transforms i
f the user |
| 276 // really does not ignore the return value. | 276 // really does not ignore the return value. |
| 277 return h.cartesianPoint2d(); | 277 return h.cartesianPoint2d(); |
| 278 } | 278 } |
| 279 | 279 |
| 280 FloatPoint3D CCMathUtil::mapPoint(const WebTransformationMatrix& transform, cons
t FloatPoint3D& p, bool& clipped) | 280 FloatPoint3D MathUtil::mapPoint(const WebTransformationMatrix& transform, const
FloatPoint3D& p, bool& clipped) |
| 281 { | 281 { |
| 282 HomogeneousCoordinate h = mapHomogeneousPoint(transform, p); | 282 HomogeneousCoordinate h = mapHomogeneousPoint(transform, p); |
| 283 | 283 |
| 284 if (h.w > 0) { | 284 if (h.w > 0) { |
| 285 clipped = false; | 285 clipped = false; |
| 286 return h.cartesianPoint3d(); | 286 return h.cartesianPoint3d(); |
| 287 } | 287 } |
| 288 | 288 |
| 289 // The cartesian coordinates will be invalid after dividing by w. | 289 // The cartesian coordinates will be invalid after dividing by w. |
| 290 clipped = true; | 290 clipped = true; |
| 291 | 291 |
| 292 // Avoid dividing by w if w == 0. | 292 // Avoid dividing by w if w == 0. |
| 293 if (!h.w) | 293 if (!h.w) |
| 294 return FloatPoint3D(); | 294 return FloatPoint3D(); |
| 295 | 295 |
| 296 // This return value will be invalid because clipped == true, but (1) users
of this | 296 // This return value will be invalid because clipped == true, but (1) users
of this |
| 297 // code should be ignoring the return value when clipped == true anyway, and
(2) this | 297 // code should be ignoring the return value when clipped == true anyway, and
(2) this |
| 298 // behavior is more consistent with existing behavior of WebKit transforms i
f the user | 298 // behavior is more consistent with existing behavior of WebKit transforms i
f the user |
| 299 // really does not ignore the return value. | 299 // really does not ignore the return value. |
| 300 return h.cartesianPoint3d(); | 300 return h.cartesianPoint3d(); |
| 301 } | 301 } |
| 302 | 302 |
| 303 FloatQuad CCMathUtil::projectQuad(const WebTransformationMatrix& transform, cons
t FloatQuad& q, bool& clipped) | 303 FloatQuad MathUtil::projectQuad(const WebTransformationMatrix& transform, const
FloatQuad& q, bool& clipped) |
| 304 { | 304 { |
| 305 FloatQuad projectedQuad; | 305 FloatQuad projectedQuad; |
| 306 bool clippedPoint; | 306 bool clippedPoint; |
| 307 projectedQuad.setP1(projectPoint(transform, q.p1(), clippedPoint)); | 307 projectedQuad.setP1(projectPoint(transform, q.p1(), clippedPoint)); |
| 308 clipped = clippedPoint; | 308 clipped = clippedPoint; |
| 309 projectedQuad.setP2(projectPoint(transform, q.p2(), clippedPoint)); | 309 projectedQuad.setP2(projectPoint(transform, q.p2(), clippedPoint)); |
| 310 clipped |= clippedPoint; | 310 clipped |= clippedPoint; |
| 311 projectedQuad.setP3(projectPoint(transform, q.p3(), clippedPoint)); | 311 projectedQuad.setP3(projectPoint(transform, q.p3(), clippedPoint)); |
| 312 clipped |= clippedPoint; | 312 clipped |= clippedPoint; |
| 313 projectedQuad.setP4(projectPoint(transform, q.p4(), clippedPoint)); | 313 projectedQuad.setP4(projectPoint(transform, q.p4(), clippedPoint)); |
| 314 clipped |= clippedPoint; | 314 clipped |= clippedPoint; |
| 315 | 315 |
| 316 return projectedQuad; | 316 return projectedQuad; |
| 317 } | 317 } |
| 318 | 318 |
| 319 FloatPoint CCMathUtil::projectPoint(const WebTransformationMatrix& transform, co
nst FloatPoint& p, bool& clipped) | 319 FloatPoint MathUtil::projectPoint(const WebTransformationMatrix& transform, cons
t FloatPoint& p, bool& clipped) |
| 320 { | 320 { |
| 321 HomogeneousCoordinate h = projectHomogeneousPoint(transform, p); | 321 HomogeneousCoordinate h = projectHomogeneousPoint(transform, p); |
| 322 | 322 |
| 323 if (h.w > 0) { | 323 if (h.w > 0) { |
| 324 // The cartesian coordinates will be valid in this case. | 324 // The cartesian coordinates will be valid in this case. |
| 325 clipped = false; | 325 clipped = false; |
| 326 return h.cartesianPoint2d(); | 326 return h.cartesianPoint2d(); |
| 327 } | 327 } |
| 328 | 328 |
| 329 // The cartesian coordinates will be invalid after dividing by w. | 329 // The cartesian coordinates will be invalid after dividing by w. |
| 330 clipped = true; | 330 clipped = true; |
| 331 | 331 |
| 332 // Avoid dividing by w if w == 0. | 332 // Avoid dividing by w if w == 0. |
| 333 if (!h.w) | 333 if (!h.w) |
| 334 return FloatPoint(); | 334 return FloatPoint(); |
| 335 | 335 |
| 336 // This return value will be invalid because clipped == true, but (1) users
of this | 336 // This return value will be invalid because clipped == true, but (1) users
of this |
| 337 // code should be ignoring the return value when clipped == true anyway, and
(2) this | 337 // code should be ignoring the return value when clipped == true anyway, and
(2) this |
| 338 // behavior is more consistent with existing behavior of WebKit transforms i
f the user | 338 // behavior is more consistent with existing behavior of WebKit transforms i
f the user |
| 339 // really does not ignore the return value. | 339 // really does not ignore the return value. |
| 340 return h.cartesianPoint2d(); | 340 return h.cartesianPoint2d(); |
| 341 } | 341 } |
| 342 | 342 |
| 343 void CCMathUtil::flattenTransformTo2d(WebTransformationMatrix& transform) | 343 void MathUtil::flattenTransformTo2d(WebTransformationMatrix& transform) |
| 344 { | 344 { |
| 345 // Set both the 3rd row and 3rd column to (0, 0, 1, 0). | 345 // Set both the 3rd row and 3rd column to (0, 0, 1, 0). |
| 346 // | 346 // |
| 347 // One useful interpretation of doing this operation: | 347 // One useful interpretation of doing this operation: |
| 348 // - For x and y values, the new transform behaves effectively like an orth
ographic | 348 // - For x and y values, the new transform behaves effectively like an orth
ographic |
| 349 // projection was added to the matrix sequence. | 349 // projection was added to the matrix sequence. |
| 350 // - For z values, the new transform overrides any effect that the transfor
m had on | 350 // - For z values, the new transform overrides any effect that the transfor
m had on |
| 351 // z, and instead it preserves the z value for any points that are transf
ormed. | 351 // z, and instead it preserves the z value for any points that are transf
ormed. |
| 352 // - Because of linearity of transforms, this flattened transform also pres
erves the | 352 // - Because of linearity of transforms, this flattened transform also pres
erves the |
| 353 // effect that any subsequent (post-multiplied) transforms would have on
z values. | 353 // effect that any subsequent (post-multiplied) transforms would have on
z values. |
| 354 // | 354 // |
| 355 transform.setM13(0); | 355 transform.setM13(0); |
| 356 transform.setM23(0); | 356 transform.setM23(0); |
| 357 transform.setM31(0); | 357 transform.setM31(0); |
| 358 transform.setM32(0); | 358 transform.setM32(0); |
| 359 transform.setM33(1); | 359 transform.setM33(1); |
| 360 transform.setM34(0); | 360 transform.setM34(0); |
| 361 transform.setM43(0); | 361 transform.setM43(0); |
| 362 } | 362 } |
| 363 | 363 |
| 364 float CCMathUtil::smallestAngleBetweenVectors(const FloatSize& v1, const FloatSi
ze& v2) | 364 float MathUtil::smallestAngleBetweenVectors(const FloatSize& v1, const FloatSize
& v2) |
| 365 { | 365 { |
| 366 float dotProduct = (v1.width() * v2.width() + v1.height() * v2.height()) / (
v1.diagonalLength() * v2.diagonalLength()); | 366 float dotProduct = (v1.width() * v2.width() + v1.height() * v2.height()) / (
v1.diagonalLength() * v2.diagonalLength()); |
| 367 // Clamp to compensate for rounding errors. | 367 // Clamp to compensate for rounding errors. |
| 368 dotProduct = std::max(-1.f, std::min(1.f, dotProduct)); | 368 dotProduct = std::max(-1.f, std::min(1.f, dotProduct)); |
| 369 return rad2deg(acosf(dotProduct)); | 369 return rad2deg(acosf(dotProduct)); |
| 370 } | 370 } |
| 371 | 371 |
| 372 FloatSize CCMathUtil::projectVector(const FloatSize& source, const FloatSize& de
stination) | 372 FloatSize MathUtil::projectVector(const FloatSize& source, const FloatSize& dest
ination) |
| 373 { | 373 { |
| 374 float sourceDotDestination = source.width() * destination.width() + source.h
eight() * destination.height(); | 374 float sourceDotDestination = source.width() * destination.width() + source.h
eight() * destination.height(); |
| 375 float projectedLength = sourceDotDestination / destination.diagonalLengthSqu
ared(); | 375 float projectedLength = sourceDotDestination / destination.diagonalLengthSqu
ared(); |
| 376 return FloatSize(projectedLength * destination.width(), projectedLength * de
stination.height()); | 376 return FloatSize(projectedLength * destination.width(), projectedLength * de
stination.height()); |
| 377 } | 377 } |
| 378 | 378 |
| 379 } // namespace cc | 379 } // namespace cc |
| OLD | NEW |