Struct kurbo::Rect [−][src]
Expand description
A rectangle.
Fields
x0: f64
The minimum x coordinate (left edge).
y0: f64
The minimum y coordinate (top edge in y-down spaces).
x1: f64
The maximum x coordinate (right edge).
y1: f64
The maximum y coordinate (bottom edge in y-down spaces).
Implementations
A new rectangle from minimum and maximum coordinates.
A new rectangle from two points.
The result will have non-negative width and height.
A new rectangle from origin and size.
The result will have non-negative width and height.
A new rectangle from center and size.
Create a new Rect
with the same size as self
and a new origin.
Create a new Rect
with the same origin as self
and a new size.
The origin of the rectangle.
This is the top left corner in a y-down space and with non-negative width and height.
Whether this rectangle has zero area.
Note: a rectangle with negative area is not considered empty.
Take absolute value of width and height.
The resulting rect has the same extents as the original, but is guaranteed to have non-negative width and height.
The smallest rectangle enclosing two rectangles.
Results are valid only if width and height are non-negative.
Compute the union with one point.
This method includes the perimeter of zero-area rectangles.
Thus, a succession of union_pt
operations on a series of
points yields their enclosing rectangle.
Results are valid only if width and height are non-negative.
The intersection of two rectangles.
The result is zero-area if either input has negative width or height. The result always has non-negative width and height.
Expand a rectangle by a constant amount in both directions.
The logic simply applies the amount in each direction. If rectangle area or added dimensions are negative, this could give odd results.
Returns a new Rect
,
with each coordinate value rounded to the nearest integer.
Examples
use kurbo::Rect;
let rect = Rect::new(3.3, 3.6, 3.0, -3.1).round();
assert_eq!(rect.x0, 3.0);
assert_eq!(rect.y0, 4.0);
assert_eq!(rect.x1, 3.0);
assert_eq!(rect.y1, -3.0);
Returns a new Rect
,
with each coordinate value rounded up to the nearest integer,
unless they are already an integer.
Examples
use kurbo::Rect;
let rect = Rect::new(3.3, 3.6, 3.0, -3.1).ceil();
assert_eq!(rect.x0, 4.0);
assert_eq!(rect.y0, 4.0);
assert_eq!(rect.x1, 3.0);
assert_eq!(rect.y1, -3.0);
Returns a new Rect
,
with each coordinate value rounded down to the nearest integer,
unless they are already an integer.
Examples
use kurbo::Rect;
let rect = Rect::new(3.3, 3.6, 3.0, -3.1).floor();
assert_eq!(rect.x0, 3.0);
assert_eq!(rect.y0, 3.0);
assert_eq!(rect.x1, 3.0);
assert_eq!(rect.y1, -4.0);
Returns a new Rect
,
with each coordinate value rounded away from the center of the Rect
to the nearest integer, unless they are already an integer.
That is to say this function will return the smallest possible Rect
with integer coordinates that is a superset of self
.
Examples
use kurbo::Rect;
// In positive space
let rect = Rect::new(3.3, 3.6, 5.6, 4.1).expand();
assert_eq!(rect.x0, 3.0);
assert_eq!(rect.y0, 3.0);
assert_eq!(rect.x1, 6.0);
assert_eq!(rect.y1, 5.0);
// In both positive and negative space
let rect = Rect::new(-3.3, -3.6, 5.6, 4.1).expand();
assert_eq!(rect.x0, -4.0);
assert_eq!(rect.y0, -4.0);
assert_eq!(rect.x1, 6.0);
assert_eq!(rect.y1, 5.0);
// In negative space
let rect = Rect::new(-5.6, -4.1, -3.3, -3.6).expand();
assert_eq!(rect.x0, -6.0);
assert_eq!(rect.y0, -5.0);
assert_eq!(rect.x1, -3.0);
assert_eq!(rect.y1, -3.0);
// Inverse orientation
let rect = Rect::new(5.6, -3.6, 3.3, -4.1).expand();
assert_eq!(rect.x0, 6.0);
assert_eq!(rect.y0, -3.0);
assert_eq!(rect.x1, 3.0);
assert_eq!(rect.y1, -5.0);
Returns a new Rect
,
with each coordinate value rounded towards the center of the Rect
to the nearest integer, unless they are already an integer.
That is to say this function will return the biggest possible Rect
with integer coordinates that is a subset of self
.
Examples
use kurbo::Rect;
// In positive space
let rect = Rect::new(3.3, 3.6, 5.6, 4.1).trunc();
assert_eq!(rect.x0, 4.0);
assert_eq!(rect.y0, 4.0);
assert_eq!(rect.x1, 5.0);
assert_eq!(rect.y1, 4.0);
// In both positive and negative space
let rect = Rect::new(-3.3, -3.6, 5.6, 4.1).trunc();
assert_eq!(rect.x0, -3.0);
assert_eq!(rect.y0, -3.0);
assert_eq!(rect.x1, 5.0);
assert_eq!(rect.y1, 4.0);
// In negative space
let rect = Rect::new(-5.6, -4.1, -3.3, -3.6).trunc();
assert_eq!(rect.x0, -5.0);
assert_eq!(rect.y0, -4.0);
assert_eq!(rect.x1, -4.0);
assert_eq!(rect.y1, -4.0);
// Inverse orientation
let rect = Rect::new(5.6, -3.6, 3.3, -4.1).trunc();
assert_eq!(rect.x0, 5.0);
assert_eq!(rect.y0, -4.0);
assert_eq!(rect.x1, 4.0);
assert_eq!(rect.y1, -4.0);
Scales the Rect
by factor
with respect to the origin (the point (0, 0)
).
Examples
use kurbo::Rect;
let rect = Rect::new(2., 2., 4., 6.).scale_from_origin(2.);
assert_eq!(rect.x0, 4.);
assert_eq!(rect.x1, 8.);
Creates a new RoundedRect
from this Rect
and the provided
corner radius.
Returns the Ellipse
that is bounded by this Rect
.
The aspect ratio of the Rect
.
This is defined as the height divided by the width. It measures the
“squareness” of the rectangle (a value of 1
is square).
If the width is 0
the output will be sign(y1 - y0) * infinity
.
If The width and height are 0
, the result will be NaN
.
Returns the largest possible Rect
that is fully contained in self
with the given aspect_ratio
.
The aspect ratio is specified fractionally, as height / width
.
The resulting rectangle will be centered if it is smaller than the input rectangle.
For the special case where the aspect ratio is 1.0
, the resulting
Rect
will be square.
Examples
let outer = Rect::new(0.0, 0.0, 10.0, 20.0);
let inner = outer.contained_rect_with_aspect_ratio(1.0);
// The new `Rect` is a square centered at the center of `outer`.
assert_eq!(inner, Rect::new(0.0, 5.0, 10.0, 15.0));
Trait Implementations
fn deserialize<__D>(__deserializer: __D) -> Result<Self, __D::Error> where
__D: Deserializer<'de>,
fn deserialize<__D>(__deserializer: __D) -> Result<Self, __D::Error> where
__D: Deserializer<'de>,
Deserialize this value from the given Serde deserializer. Read more
Note: this function is carefully designed so that if the plane is tiled with rectangles, the winding number will be nonzero for exactly one of them.
type PathElementsIter = RectPathIter
type PathElementsIter = RectPathIter
The iterator returned by the path_elements
method. Read more
The smallest rectangle that encloses the shape.
If the shape is a rounded rectangle, make it available.
Auto Trait Implementations
impl RefUnwindSafe for Rect
impl UnwindSafe for Rect
Blanket Implementations
Mutably borrows from an owned value. Read more