Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(5)

Side by Side Diff: third_party/WebKit/Source/platform/geometry/FloatRoundedRect.cpp

Issue 2191233002: Add platform/geometry pretty printers for logging and testing (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Adjust tests to work around uninteresting cross-platform differences Created 4 years, 4 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
1 /* 1 /*
2 * Copyright (C) 2013 Adobe Systems Incorporated. All rights reserved. 2 * Copyright (C) 2013 Adobe Systems Incorporated. All rights reserved.
3 * 3 *
4 * Redistribution and use in source and binary forms, with or without 4 * Redistribution and use in source and binary forms, with or without
5 * modification, are permitted provided that the following conditions 5 * modification, are permitted provided that the following conditions
6 * are met: 6 * are met:
7 * 7 *
8 * 1. Redistributions of source code must retain the above 8 * 1. Redistributions of source code must retain the above
9 * copyright notice, this list of conditions and the following 9 * copyright notice, this list of conditions and the following
10 * disclaimer. 10 * disclaimer.
(...skipping 14 matching lines...) Expand all
25 * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) 25 * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
26 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED 26 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED
27 * OF THE POSSIBILITY OF SUCH DAMAGE. 27 * OF THE POSSIBILITY OF SUCH DAMAGE.
28 */ 28 */
29 29
30 #include "platform/geometry/FloatRoundedRect.h" 30 #include "platform/geometry/FloatRoundedRect.h"
31 31
32 #include "platform/geometry/FloatQuad.h" 32 #include "platform/geometry/FloatQuad.h"
33 33
34 #include <algorithm> 34 #include <algorithm>
35 35 #include <ostream> // NOLINT
36 #ifndef NDEBUG
37 #include <stdio.h>
38 #endif
39 36
40 namespace blink { 37 namespace blink {
41 38
42 FloatRoundedRect::FloatRoundedRect(float x, float y, float width, float height) 39 FloatRoundedRect::FloatRoundedRect(float x, float y, float width, float height)
43 : m_rect(x, y, width, height) 40 : m_rect(x, y, width, height)
44 { 41 {
45 } 42 }
46 43
47 FloatRoundedRect::FloatRoundedRect(const FloatRect& rect, const Radii& radii) 44 FloatRoundedRect::FloatRoundedRect(const FloatRect& rect, const Radii& radii)
48 : m_rect(rect) 45 : m_rect(rect)
(...skipping 84 matching lines...) Expand 10 before | Expand all | Expand 10 after
133 if (m_bottomLeft.width() > 0 && m_bottomLeft.height() > 0) { 130 if (m_bottomLeft.width() > 0 && m_bottomLeft.height() > 0) {
134 m_bottomLeft.setWidth(m_bottomLeft.width() + leftWidth); 131 m_bottomLeft.setWidth(m_bottomLeft.width() + leftWidth);
135 m_bottomLeft.setHeight(m_bottomLeft.height() + bottomWidth); 132 m_bottomLeft.setHeight(m_bottomLeft.height() + bottomWidth);
136 } 133 }
137 if (m_bottomRight.width() > 0 && m_bottomRight.height() > 0) { 134 if (m_bottomRight.width() > 0 && m_bottomRight.height() > 0) {
138 m_bottomRight.setWidth(m_bottomRight.width() + rightWidth); 135 m_bottomRight.setWidth(m_bottomRight.width() + rightWidth);
139 m_bottomRight.setHeight(m_bottomRight.height() + bottomWidth); 136 m_bottomRight.setHeight(m_bottomRight.height() + bottomWidth);
140 } 137 }
141 } 138 }
142 139
143 #ifndef NDEBUG
144 void FloatRoundedRect::Radii::show() const
145 {
146 fprintf(stderr, "topLeft=[%f,%f], topRight=[%f,%f], bottomLeft=[%f,%f], bott omRight=[%f,%f]\n",
147 topLeft().width(), topLeft().height(), topRight().width(), topRight().he ight(),
148 bottomLeft().width(), bottomLeft().height(), bottomRight().width(), bott omRight().height());
149 }
150 #endif
151
152 static inline float cornerRectIntercept(float y, const FloatRect& cornerRect) 140 static inline float cornerRectIntercept(float y, const FloatRect& cornerRect)
153 { 141 {
154 ASSERT(cornerRect.height() > 0); 142 ASSERT(cornerRect.height() > 0);
155 return cornerRect.width() * sqrt(1 - (y * y) / (cornerRect.height() * corner Rect.height())); 143 return cornerRect.width() * sqrt(1 - (y * y) / (cornerRect.height() * corner Rect.height()));
156 } 144 }
157 145
158 FloatRect FloatRoundedRect::radiusCenterRect() const 146 FloatRect FloatRoundedRect::radiusCenterRect() const
159 { 147 {
160 FloatRectOutsets maximumRadiusInsets( 148 FloatRectOutsets maximumRadiusInsets(
161 -std::max(m_radii.topLeft().height(), m_radii.topRight().height()), 149 -std::max(m_radii.topLeft().height(), m_radii.topRight().height()),
(...skipping 180 matching lines...) Expand 10 before | Expand all | Expand 10 after
342 330
343 if (maxRadiusWidth <= 0 || maxRadiusHeight <= 0) { 331 if (maxRadiusWidth <= 0 || maxRadiusHeight <= 0) {
344 m_radii.scale(0.0f); 332 m_radii.scale(0.0f);
345 return; 333 return;
346 } 334 }
347 float widthRatio = static_cast<float>(m_rect.width()) / maxRadiusWidth; 335 float widthRatio = static_cast<float>(m_rect.width()) / maxRadiusWidth;
348 float heightRatio = static_cast<float>(m_rect.height()) / maxRadiusHeight; 336 float heightRatio = static_cast<float>(m_rect.height()) / maxRadiusHeight;
349 m_radii.scale(widthRatio < heightRatio ? widthRatio : heightRatio); 337 m_radii.scale(widthRatio < heightRatio ? widthRatio : heightRatio);
350 } 338 }
351 339
352 #ifndef NDEBUG 340 std::ostream& operator<<(std::ostream& os, const FloatRoundedRect::Radii& radii)
353 void FloatRoundedRect::show() const
354 { 341 {
355 fprintf(stderr, "FloatRoundedRect:\n rect: "); 342 os << "FloatRoundedRect::Radii("
356 m_rect.show(); 343 << "topLeft=" << radii.topLeft() << ", "
357 fprintf(stderr, " radii: "); 344 << "topRight=" << radii.topRight() << ", "
358 m_radii.show(); 345 << "bottomLeft" << radii.bottomLeft() << ", "
346 << "bottomRight=" << radii.bottomRight() << ")";
347 return os;
359 } 348 }
360 #endif 349
350 std::ostream& operator<<(std::ostream& os, const FloatRoundedRect& roundedRect)
351 {
352 os << "FloatRoundedRect("
353 << "rect=" << roundedRect.rect() << ", "
354 << "radii=" << roundedRect.getRadii() << ")";
355 return os;
356 }
361 357
362 } // namespace blink 358 } // namespace blink
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698