rect_conversions.h 2.4 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455
  1. // Copyright (c) 2012 The Chromium Authors. All rights reserved.
  2. // Use of this source code is governed by a BSD-style license that can be
  3. // found in the LICENSE file.
  4. #ifndef UI_GFX_GEOMETRY_RECT_CONVERSIONS_H_
  5. #define UI_GFX_GEOMETRY_RECT_CONVERSIONS_H_
  6. #include "ui/gfx/geometry/rect.h"
  7. #include "ui/gfx/geometry/rect_f.h"
  8. namespace gfx {
  9. // Returns the smallest Rect that encloses the given RectF.
  10. GEOMETRY_EXPORT Rect ToEnclosingRect(const RectF& rect);
  11. // Similar to ToEnclosingRect(), but for each edge, if the distance between the
  12. // edge and the nearest integer grid is smaller than |error|, the edge is
  13. // snapped to the integer grid. Unlike ToNearestRect() which only accepts
  14. // integer rect with or without floating point error, this function also accepts
  15. // non-integer rect.
  16. GEOMETRY_EXPORT Rect ToEnclosingRectIgnoringError(const RectF& rect,
  17. float error);
  18. // Returns the largest Rect that is enclosed by the given RectF.
  19. GEOMETRY_EXPORT Rect ToEnclosedRect(const RectF& rect);
  20. // Similar to ToEnclosedRect(), but for each edge, if the distance between the
  21. // edge and the nearest integer grid is smaller than |error|, the edge is
  22. // snapped to the integer grid. Unlike ToNearestRect() which only accepts
  23. // integer rect with or without floating point error, this function also accepts
  24. // non-integer rect.
  25. GEOMETRY_EXPORT Rect ToEnclosedRectIgnoringError(const RectF& rect,
  26. float error);
  27. // Returns the Rect after snapping the corners of the RectF to an integer grid.
  28. // This should only be used when the RectF you provide is expected to be an
  29. // integer rect with floating point error. If it is an arbitrary RectF, then
  30. // you should use a different method.
  31. GEOMETRY_EXPORT Rect ToNearestRect(const RectF& rect);
  32. // Returns true if the Rect produced after snapping the corners of the RectF
  33. // to an integer grid is withing |distance|.
  34. GEOMETRY_EXPORT bool IsNearestRectWithinDistance(const gfx::RectF& rect,
  35. float distance);
  36. // Returns the Rect after rounding the corners of the RectF to an integer grid.
  37. GEOMETRY_EXPORT gfx::Rect ToRoundedRect(const gfx::RectF& rect);
  38. // Returns a Rect obtained by flooring the values of the given RectF.
  39. // Please prefer the previous two functions in new code.
  40. GEOMETRY_EXPORT Rect ToFlooredRectDeprecated(const RectF& rect);
  41. } // namespace gfx
  42. #endif // UI_GFX_GEOMETRY_RECT_CONVERSIONS_H_