pub struct LogicalRect {
pub x: f64,
pub y: f64,
pub width: f64,
pub height: f64,
}Expand description
A rectangle in logical coordinates.
Serialized as [x, y, width, height], not as an object.
Fields§
§x: f64Left edge.
y: f64Top edge.
width: f64Extent along x. Must be positive.
height: f64Extent along y. Must be positive.
Implementations§
Source§impl LogicalRect
impl LogicalRect
Sourcepub fn is_valid(&self) -> bool
pub fn is_valid(&self) -> bool
Whether every component is finite and the extents are positive.
Zero-area rects are rejected: they render as nothing, so they are always a bug in the caller rather than an intentional annotation.
Sourcepub fn center(&self) -> LogicalPoint
pub fn center(&self) -> LogicalPoint
The centre of the rectangle.
Sourcepub fn into_valid(self) -> Option<Self>
pub fn into_valid(self) -> Option<Self>
This rectangle if it is drawable, None if it is not.
For the callers that treat a region as an optional refinement rather than the answer. Something derived from a measurement, a model’s guess, or arithmetic on either can come out degenerate, and dropping it is better than propagating a rect that renders as nothing.
Sourcepub fn containing(points: &[LogicalPoint]) -> Self
pub fn containing(points: &[LogicalPoint]) -> Self
The smallest rectangle containing every one of these points.
Always drawable. An empty run of points has no extent to describe and a straight one has none in a single axis, and both come back a point wide rather than as a rect that renders as nothing.