Skip to content

Commit

Permalink
Add an INIFNITY constant to Size. (#413)
Browse files Browse the repository at this point in the history
This pull request adds the `INFINITY` constant to `Size`.

```rust
const INFINITY: Size = Size::new(f64::INFINITY, f64::INFINITY);
```

I found myself writing a lot of infinite sizes manually to represent "no
constraint", and thought it would be cleaner to have it as an associated
constant instead.

# Potential questions

Is there any other constants we might want for `Size`? `INFINITY` is the
only one I personally needed, but maybe there are others.
  • Loading branch information
nils-mathieu authored Feb 19, 2025
1 parent f2c153b commit b487bda
Showing 1 changed file with 3 additions and 0 deletions.
3 changes: 3 additions & 0 deletions src/size.rs
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,9 @@ impl Size {
/// A size with zero width or height.
pub const ZERO: Size = Size::new(0., 0.);

/// A size with width and height set to `f64::INFINITY`.
pub const INFINITY: Size = Size::new(f64::INFINITY, f64::INFINITY);

/// Create a new `Size` with the provided `width` and `height`.
#[inline]
pub const fn new(width: f64, height: f64) -> Self {
Expand Down

0 comments on commit b487bda

Please sign in to comment.