15821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)// Copyright (c) 2012 The Chromium Authors. All rights reserved.
25821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)// Use of this source code is governed by a BSD-style license that can be
35821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)// found in the LICENSE file.
45821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
55821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)#ifndef UI_GFX_GEOMETRY_RECT_CONVERSIONS_H_
65821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)#define UI_GFX_GEOMETRY_RECT_CONVERSIONS_H_
75821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
85821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)#include "ui/gfx/geometry/rect.h"
95821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)#include "ui/gfx/geometry/rect_f.h"
105821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
115821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)namespace gfx {
125821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
135821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)// Returns the smallest Rect that encloses the given RectF.
145821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)GFX_EXPORT Rect ToEnclosingRect(const RectF& rect);
155821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
165821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)// Returns the largest Rect that is enclosed by the given RectF.
175821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)GFX_EXPORT Rect ToEnclosedRect(const RectF& rect);
185821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
195821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)// Returns the Rect after snapping the corners of the RectF to an integer grid.
205821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)// This should only be used when the RectF you provide is expected to be an
215821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)// integer rect with floating point error. If it is an arbitrary RectF, then
225821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)// you should use a different method.
235821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)GFX_EXPORT Rect ToNearestRect(const RectF& rect);
245821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
255821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)// Returns true if the Rect produced after snapping the corners of the RectF
265821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)// to an integer grid is withing |distance|.
275821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)GFX_EXPORT bool IsNearestRectWithinDistance(
285821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)    const gfx::RectF& rect, float distance);
295821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
305821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)// Returns a Rect obtained by flooring the values of the given RectF.
315821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)// Please prefer the previous two functions in new code.
325821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)GFX_EXPORT Rect ToFlooredRectDeprecated(const RectF& rect);
335821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
345821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)}  // namespace gfx
355821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
365821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)#endif  // UI_GFX_GEOMETRY_RECT_CONVERSIONS_H_
375821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)