Chromium Code Reviews| Index: ui/gfx/win/rect_util.h |
| diff --git a/ui/gfx/win/rect_util.h b/ui/gfx/win/rect_util.h |
| new file mode 100644 |
| index 0000000000000000000000000000000000000000..d74b1f32230f23be73fcf05b4b2c0c7a0e381f7b |
| --- /dev/null |
| +++ b/ui/gfx/win/rect_util.h |
| @@ -0,0 +1,104 @@ |
| +// Copyright 2016 The Chromium Authors. All rights reserved. |
| +// Use of this source code is governed by a BSD-style license that can be |
| +// found in the LICENSE file. |
| + |
| +#ifndef UI_GFX_WIN_RECT_UTIL_H_ |
| +#define UI_GFX_WIN_RECT_UTIL_H_ |
| + |
| +#include <stdint.h> |
| + |
| +#include "ui/gfx/gfx_export.h" |
| + |
| +namespace gfx { |
| + |
| +class Rect; |
| + |
| +namespace win { |
|
sky
2016/02/17 04:40:28
This file name is very generic. I don't think we w
robliao
2016/02/18 00:34:39
Given that this is primarily used by ScreenWin, ho
sky
2016/02/18 17:02:58
SGTM
|
| + |
| +enum class RectEdge { |
| + BOTTOM = 0, |
| + LEFT = 1, |
| + TOP = 2, |
| + RIGHT = 3, |
| + NONE = 4, |
| +}; |
| + |
| +// Returns |ref|'s RectEdge touching |test|. |
|
sky
2016/02/17 17:28:48
Clarify if the two rects are guaranteed to touch.
robliao
2016/02/18 00:34:39
Done.
|
| +GFX_EXPORT RectEdge FindTouchingRectEdge(const gfx::Rect& ref, |
| + const gfx::Rect& test); |
| + |
| +// Returns a scaled and positioned rect based off of target_rect and context. |
|
sky
2016/02/17 04:40:29
there is no context param.
robliao
2016/02/18 00:34:39
Clarified.
|
| +// The reference rectangle and target rectangle may scale at different rates. |
| +// This function attempts to preserve the relative positioning of the target |
| +// rectangle with respect to the scaled rectangle in the face of differing |
| +// scale factors. |
|
sky
2016/02/17 04:40:29
Without looking at the implementation this descrip
sky
2016/02/17 17:28:48
One more comment. It is also isn't clear if the re
robliao
2016/02/18 00:34:39
Clarified the comment and added another example. F
|
| +// |
| +// Examples: |
| +// +--------------+ Since both rectangles are of the same |
| +// | | scale factor, positions and sizes |
| +// | | remain the same. |
| +// | REF 1x +----------+ |
| +// | | | |
| +// +--------------+ 1x | |
| +// | | |
| +// +----------+ |
| +// |
| +// Original |
| +// +--------------+ The 2x rectangle is scaled down while |
| +// | | maintaining a similar neighboring relationship |
| +// | | with the 1x rectangle. |
| +// | REF 1x +----------+ |
| +// | | | |
| +// +--------------+ 2x | |
| +// | | |
| +// +----------+ |
| +// Scaled |
| +// +--------------+ |
| +// | | |
| +// | | |
| +// | REF 1x | |
| +// | +-----+ |
| +// +--------------+ 2x | |
| +// +-----+ |
| +GFX_EXPORT gfx::Rect ScaleAndPositionRect(gfx::Rect ref_scaled_rect, |
|
sky
2016/02/17 04:40:29
const& on the params here and below. Use different
robliao
2016/02/18 00:34:39
Done.
|
| + gfx::Rect ref_original_rect, |
| + gfx::Rect target_rect, |
|
sky
2016/02/17 17:28:48
It's not clear if target_rect is scaled or not.
robliao
2016/02/18 00:34:39
Clarified via rename.
|
| + float target_scale_factor); |
| + |
| +// Returns the squared distance between two rects. |
| +// The distance between two rects is the length of the shortest segment that can |
| +// be drawn between two rectangles. This segment generally connects two opposing |
| +// corners between rectangles like this... |
| +// |
| +// +----------+ |
| +// | | |
| +// +----------+ |
| +// \ <--- Shortest Segment |
| +// \ |
| +// +---+ |
| +// | | |
| +// | | |
| +// +---+ |
| +// |
| +// For rectangles that share coordinates within the same axis, that generally |
| +// means the segment is parallel to the axis and perpendicular to the edges. |
| +// |
| +// One of many shortest segments |
| +// +----------+ / \ +--------+ |
| +// | | | \ | | |
| +// | | V +---+ \ +--------+ |
| +// | |-----| | \-->| |
| +// +----------+ | | +----+ |
| +// | | | | |
| +// +---+ +----+ |
| +// |
| +// For rectangles that intersect each other, the distance is 0. |
| +// |
| +// The squared distance is used to avoid taking the square root as the common |
| +// usage is to compare distances greater than 1 unit. |
| +GFX_EXPORT int64_t SquaredDistanceBetweenRects(gfx::Rect ref, gfx::Rect rect); |
| + |
| +} // namespace win |
| +} // namespace gfx |
| + |
| +#endif // UI_GFX_WIN_RECT_UTIL_H_ |