1// Copyright 2019 The Fuchsia 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.
45/// Coordinate type
6pub type Coord = f32;
7/// A two-dimensional point
8pub type Point = euclid::default::Point2D<Coord>;
9/// A two-dimensional rectangle
10pub type Rect = euclid::default::Rect<Coord>;
11/// A type representing the extent of an element
12/// in two-dimensionals.
13pub type Size = euclid::default::Size2D<Coord>;
1415/// Integer cordinate type
16pub type IntCoord = i32;
17/// A two-dimensional integer point
18pub type IntPoint = euclid::default::Point2D<IntCoord>;
19/// A two-dimensional integer rectangle
20pub type IntRect = euclid::default::Rect<IntCoord>;
21/// A type representing the extent of an element
22/// in two-dimensionals.
23pub type IntSize = euclid::default::Size2D<IntCoord>;
24/// A type alias for an integer 2D vector.
25pub type IntVector = euclid::default::Vector2D<IntCoord>;
2627/// A type representing the extent of an element
28/// in two-dimensions.
29pub type UintSize = euclid::default::Size2D<u32>;
3031/// Replacement for methods removed from Euclid
32#[allow(missing_docs)]
33pub trait Corners {
34fn top_left(&self) -> Point;
35fn top_right(&self) -> Point;
36fn bottom_left(&self) -> Point;
37fn bottom_right(&self) -> Point;
38}
3940impl Corners for Rect {
41fn top_left(&self) -> Point {
42 euclid::point2(self.min_x(), self.min_y())
43 }
4445fn top_right(&self) -> Point {
46 euclid::point2(self.max_x(), self.min_y())
47 }
4849fn bottom_left(&self) -> Point {
50 euclid::point2(self.min_x(), self.max_y())
51 }
5253fn bottom_right(&self) -> Point {
54 euclid::point2(self.max_x(), self.max_y())
55 }
56}
5758pub(crate) trait LimitToBounds {
59fn limit_to_bounds(&self, point: IntPoint) -> IntPoint;
60}
6162impl LimitToBounds for IntRect {
63fn limit_to_bounds(&self, point: IntPoint) -> IntPoint {
64let x = point.x.min(self.max_x()).max(self.min_x());
65let y = point.y.min(self.max_y()).max(self.min_y());
66 euclid::point2(x, y)
67 }
68}