1use core::fmt::Debug;
2use derive_more::{Add, AddAssign, Div, Mul, Sub, SubAssign};
3use refineable::Refineable;
4use std::ops::{Add, AddAssign, Div, Mul, MulAssign, Sub, SubAssign};
5
6#[derive(Refineable, Default, Add, AddAssign, Sub, SubAssign, Copy, Debug, PartialEq, Eq, Hash)]
7#[refineable(debug)]
8#[repr(C)]
9pub struct Point<T: Clone + Debug> {
10 pub x: T,
11 pub y: T,
12}
13
14pub fn point<T: Clone + Debug>(x: T, y: T) -> Point<T> {
15 Point { x, y }
16}
17
18impl<T: Clone + Debug> Point<T> {
19 pub fn new(x: T, y: T) -> Self {
20 Self { x, y }
21 }
22
23 pub fn map<U: Clone + Debug, F: Fn(T) -> U>(&self, f: F) -> Point<U> {
24 Point {
25 x: f(self.x.clone()),
26 y: f(self.y.clone()),
27 }
28 }
29}
30
31impl Point<Pixels> {
32 pub fn scale(&self, factor: f32) -> Point<ScaledPixels> {
33 Point {
34 x: self.x.scale(factor),
35 y: self.y.scale(factor),
36 }
37 }
38}
39
40impl<T, Rhs> Mul<Rhs> for Point<T>
41where
42 T: Mul<Rhs, Output = T> + Clone + Debug,
43 Rhs: Clone + Debug,
44{
45 type Output = Point<T>;
46
47 fn mul(self, rhs: Rhs) -> Self::Output {
48 Point {
49 x: self.x * rhs.clone(),
50 y: self.y * rhs,
51 }
52 }
53}
54
55impl<T: Clone + Debug + Mul<S, Output = T>, S: Clone> MulAssign<S> for Point<T> {
56 fn mul_assign(&mut self, rhs: S) {
57 self.x = self.x.clone() * rhs.clone();
58 self.y = self.y.clone() * rhs;
59 }
60}
61
62impl<T: Clone + Debug + Sub<Output = T>> SubAssign<Size<T>> for Point<T> {
63 fn sub_assign(&mut self, rhs: Size<T>) {
64 self.x = self.x.clone() - rhs.width;
65 self.y = self.y.clone() - rhs.height;
66 }
67}
68
69impl<T: Clone + Debug + Add<Output = T> + Copy> AddAssign<T> for Point<T> {
70 fn add_assign(&mut self, rhs: T) {
71 self.x = self.x.clone() + rhs;
72 self.y = self.y.clone() + rhs;
73 }
74}
75
76impl<T: Clone + Debug + Div<S, Output = T>, S: Clone> Div<S> for Point<T> {
77 type Output = Self;
78
79 fn div(self, rhs: S) -> Self::Output {
80 Self {
81 x: self.x / rhs.clone(),
82 y: self.y / rhs,
83 }
84 }
85}
86
87impl<T: Clone + Debug + std::cmp::PartialOrd> Point<T> {
88 pub fn max(&self, other: &Self) -> Self {
89 Point {
90 x: if self.x >= other.x {
91 self.x.clone()
92 } else {
93 other.x.clone()
94 },
95 y: if self.y >= other.y {
96 self.y.clone()
97 } else {
98 other.y.clone()
99 },
100 }
101 }
102}
103
104impl<T: Clone + Debug> Clone for Point<T> {
105 fn clone(&self) -> Self {
106 Self {
107 x: self.x.clone(),
108 y: self.y.clone(),
109 }
110 }
111}
112
113#[derive(Refineable, Default, Clone, Copy, Debug, PartialEq, Div, Hash)]
114#[refineable(debug)]
115#[repr(C)]
116pub struct Size<T: Clone + Debug> {
117 pub width: T,
118 pub height: T,
119}
120
121pub fn size<T: Clone + Debug>(width: T, height: T) -> Size<T> {
122 Size { width, height }
123}
124
125impl<T: Clone + Debug> Size<T> {
126 pub fn map<U: Clone + Debug, F: Fn(T) -> U>(&self, f: F) -> Size<U> {
127 Size {
128 width: f(self.width.clone()),
129 height: f(self.height.clone()),
130 }
131 }
132}
133
134impl Size<Pixels> {
135 pub fn scale(&self, factor: f32) -> Size<ScaledPixels> {
136 Size {
137 width: self.width.scale(factor),
138 height: self.height.scale(factor),
139 }
140 }
141}
142
143impl<T: Clone + Debug + Ord> Size<T> {
144 pub fn max(&self, other: &Self) -> Self {
145 Size {
146 width: if self.width >= other.width {
147 self.width.clone()
148 } else {
149 other.width.clone()
150 },
151 height: if self.height >= other.height {
152 self.height.clone()
153 } else {
154 other.height.clone()
155 },
156 }
157 }
158}
159
160impl<T, Rhs> Mul<Rhs> for Size<T>
161where
162 T: Mul<Rhs, Output = Rhs> + Debug + Clone,
163 Rhs: Debug + Clone,
164{
165 type Output = Size<Rhs>;
166
167 fn mul(self, rhs: Rhs) -> Self::Output {
168 Size {
169 width: self.width * rhs.clone(),
170 height: self.height * rhs,
171 }
172 }
173}
174
175impl<T: Clone + Debug + Mul<S, Output = T>, S: Clone> MulAssign<S> for Size<T> {
176 fn mul_assign(&mut self, rhs: S) {
177 self.width = self.width.clone() * rhs.clone();
178 self.height = self.height.clone() * rhs;
179 }
180}
181
182impl<T: Eq + Debug + Clone> Eq for Size<T> {}
183
184impl From<Size<Option<Pixels>>> for Size<Option<f32>> {
185 fn from(val: Size<Option<Pixels>>) -> Self {
186 Size {
187 width: val.width.map(|p| p.0 as f32),
188 height: val.height.map(|p| p.0 as f32),
189 }
190 }
191}
192
193impl Size<Length> {
194 pub fn full() -> Self {
195 Self {
196 width: relative(1.).into(),
197 height: relative(1.).into(),
198 }
199 }
200}
201
202impl Size<DefiniteLength> {
203 pub fn zero() -> Self {
204 Self {
205 width: px(0.).into(),
206 height: px(0.).into(),
207 }
208 }
209}
210
211impl Size<Length> {
212 pub fn auto() -> Self {
213 Self {
214 width: Length::Auto,
215 height: Length::Auto,
216 }
217 }
218}
219
220#[derive(Refineable, Clone, Default, Debug, Eq, PartialEq)]
221#[refineable(debug)]
222#[repr(C)]
223pub struct Bounds<T: Clone + Debug> {
224 pub origin: Point<T>,
225 pub size: Size<T>,
226}
227
228impl<T, Rhs> Mul<Rhs> for Bounds<T>
229where
230 T: Mul<Rhs, Output = Rhs> + Clone + Debug,
231 Point<T>: Mul<Rhs, Output = Point<Rhs>>,
232 Rhs: Clone + Debug,
233{
234 type Output = Bounds<Rhs>;
235
236 fn mul(self, rhs: Rhs) -> Self::Output {
237 Bounds {
238 origin: self.origin * rhs.clone(),
239 size: self.size * rhs,
240 }
241 }
242}
243
244impl<T: Clone + Debug + Mul<S, Output = T>, S: Clone> MulAssign<S> for Bounds<T> {
245 fn mul_assign(&mut self, rhs: S) {
246 self.origin *= rhs.clone();
247 self.size *= rhs;
248 }
249}
250
251impl<T: Clone + Debug + Div<S, Output = T>, S: Clone> Div<S> for Bounds<T>
252where
253 Size<T>: Div<S, Output = Size<T>>,
254{
255 type Output = Self;
256
257 fn div(self, rhs: S) -> Self {
258 Self {
259 origin: self.origin / rhs.clone(),
260 size: self.size / rhs,
261 }
262 }
263}
264
265impl<T: Clone + Debug + Add<T, Output = T>> Bounds<T> {
266 pub fn upper_right(&self) -> Point<T> {
267 Point {
268 x: self.origin.x.clone() + self.size.width.clone(),
269 y: self.origin.y.clone(),
270 }
271 }
272
273 pub fn lower_right(&self) -> Point<T> {
274 Point {
275 x: self.origin.x.clone() + self.size.width.clone(),
276 y: self.origin.y.clone() + self.size.height.clone(),
277 }
278 }
279}
280
281impl<T: Clone + Debug + PartialOrd + Add<T, Output = T>> Bounds<T> {
282 pub fn contains_point(&self, point: Point<T>) -> bool {
283 point.x >= self.origin.x
284 && point.x <= self.origin.x.clone() + self.size.width.clone()
285 && point.y >= self.origin.y
286 && point.y <= self.origin.y.clone() + self.size.height.clone()
287 }
288
289 pub fn map<U: Clone + Debug, F: Fn(T) -> U>(&self, f: F) -> Bounds<U> {
290 Bounds {
291 origin: self.origin.map(&f),
292 size: self.size.map(f),
293 }
294 }
295}
296
297impl Bounds<Pixels> {
298 pub fn scale(&self, factor: f32) -> Bounds<ScaledPixels> {
299 Bounds {
300 origin: self.origin.scale(factor),
301 size: self.size.scale(factor),
302 }
303 }
304}
305
306impl<T: Clone + Debug + Copy> Copy for Bounds<T> {}
307
308#[derive(Refineable, Clone, Default, Debug, Eq, PartialEq)]
309#[refineable(debug)]
310#[repr(C)]
311pub struct Edges<T: Clone + Debug> {
312 pub top: T,
313 pub right: T,
314 pub bottom: T,
315 pub left: T,
316}
317
318impl<T: Clone + Debug + Mul<Output = T>> Mul for Edges<T> {
319 type Output = Self;
320
321 fn mul(self, rhs: Self) -> Self::Output {
322 Self {
323 top: self.top.clone() * rhs.top,
324 right: self.right.clone() * rhs.right,
325 bottom: self.bottom.clone() * rhs.bottom,
326 left: self.left.clone() * rhs.left,
327 }
328 }
329}
330
331impl<T: Clone + Debug + Mul<S, Output = T>, S: Clone> MulAssign<S> for Edges<T> {
332 fn mul_assign(&mut self, rhs: S) {
333 self.top = self.top.clone() * rhs.clone();
334 self.right = self.right.clone() * rhs.clone();
335 self.bottom = self.bottom.clone() * rhs.clone();
336 self.left = self.left.clone() * rhs.clone();
337 }
338}
339
340impl<T: Clone + Debug + Copy> Copy for Edges<T> {}
341
342impl<T: Clone + Debug> Edges<T> {
343 pub fn map<U: Clone + Debug, F: Fn(&T) -> U>(&self, f: F) -> Edges<U> {
344 Edges {
345 top: f(&self.top),
346 right: f(&self.right),
347 bottom: f(&self.bottom),
348 left: f(&self.left),
349 }
350 }
351
352 pub fn any<F: Fn(&T) -> bool>(&self, predicate: F) -> bool {
353 predicate(&self.top)
354 || predicate(&self.right)
355 || predicate(&self.bottom)
356 || predicate(&self.left)
357 }
358}
359
360impl Edges<Length> {
361 pub fn auto() -> Self {
362 Self {
363 top: Length::Auto,
364 right: Length::Auto,
365 bottom: Length::Auto,
366 left: Length::Auto,
367 }
368 }
369
370 pub fn zero() -> Self {
371 Self {
372 top: px(0.).into(),
373 right: px(0.).into(),
374 bottom: px(0.).into(),
375 left: px(0.).into(),
376 }
377 }
378}
379
380impl Edges<DefiniteLength> {
381 pub fn zero() -> Self {
382 Self {
383 top: px(0.).into(),
384 right: px(0.).into(),
385 bottom: px(0.).into(),
386 left: px(0.).into(),
387 }
388 }
389}
390
391impl Edges<AbsoluteLength> {
392 pub fn zero() -> Self {
393 Self {
394 top: px(0.).into(),
395 right: px(0.).into(),
396 bottom: px(0.).into(),
397 left: px(0.).into(),
398 }
399 }
400
401 pub fn to_pixels(&self, rem_size: Pixels) -> Edges<Pixels> {
402 Edges {
403 top: self.top.to_pixels(rem_size),
404 right: self.right.to_pixels(rem_size),
405 bottom: self.bottom.to_pixels(rem_size),
406 left: self.left.to_pixels(rem_size),
407 }
408 }
409}
410
411#[derive(Refineable, Clone, Default, Debug, Eq, PartialEq)]
412#[refineable(debug)]
413#[repr(C)]
414pub struct Corners<T: Clone + Debug> {
415 pub top_left: T,
416 pub top_right: T,
417 pub bottom_right: T,
418 pub bottom_left: T,
419}
420
421impl<T: Clone + Debug> Corners<T> {
422 pub fn map<U: Clone + Debug, F: Fn(&T) -> U>(&self, f: F) -> Corners<U> {
423 Corners {
424 top_left: f(&self.top_left),
425 top_right: f(&self.top_right),
426 bottom_right: f(&self.bottom_right),
427 bottom_left: f(&self.bottom_left),
428 }
429 }
430}
431
432impl<T: Clone + Debug + Mul<Output = T>> Mul for Corners<T> {
433 type Output = Self;
434
435 fn mul(self, rhs: Self) -> Self::Output {
436 Self {
437 top_left: self.top_left.clone() * rhs.top_left,
438 top_right: self.top_right.clone() * rhs.top_right,
439 bottom_right: self.bottom_right.clone() * rhs.bottom_right,
440 bottom_left: self.bottom_left.clone() * rhs.bottom_left,
441 }
442 }
443}
444
445impl<T: Clone + Debug + Mul<S, Output = T>, S: Clone> MulAssign<S> for Corners<T> {
446 fn mul_assign(&mut self, rhs: S) {
447 self.top_left = self.top_left.clone() * rhs.clone();
448 self.top_right = self.top_right.clone() * rhs.clone();
449 self.bottom_right = self.bottom_right.clone() * rhs.clone();
450 self.bottom_left = self.bottom_left.clone() * rhs;
451 }
452}
453
454impl<T: Clone + Debug + Copy> Copy for Corners<T> {}
455
456#[derive(Clone, Copy, Default, Add, AddAssign, Sub, SubAssign, Div, PartialEq, PartialOrd)]
457#[repr(transparent)]
458pub struct Pixels(pub(crate) f32);
459
460impl Mul<f32> for Pixels {
461 type Output = Pixels;
462
463 fn mul(self, other: f32) -> Pixels {
464 Pixels(self.0 * other)
465 }
466}
467
468impl Mul<Pixels> for f32 {
469 type Output = Pixels;
470
471 fn mul(self, rhs: Pixels) -> Self::Output {
472 Pixels(self * rhs.0)
473 }
474}
475
476impl MulAssign<f32> for Pixels {
477 fn mul_assign(&mut self, other: f32) {
478 self.0 *= other;
479 }
480}
481
482impl Pixels {
483 pub fn round(&self) -> Self {
484 Self(self.0.round())
485 }
486
487 pub fn scale(&self, factor: f32) -> ScaledPixels {
488 ScaledPixels(self.0 * factor)
489 }
490}
491
492impl Mul<Pixels> for Pixels {
493 type Output = Pixels;
494
495 fn mul(self, rhs: Pixels) -> Self::Output {
496 Pixels(self.0 * rhs.0)
497 }
498}
499
500impl Eq for Pixels {}
501
502impl Ord for Pixels {
503 fn cmp(&self, other: &Self) -> std::cmp::Ordering {
504 self.0.partial_cmp(&other.0).unwrap()
505 }
506}
507
508impl std::hash::Hash for Pixels {
509 fn hash<H: std::hash::Hasher>(&self, state: &mut H) {
510 self.0.to_bits().hash(state);
511 }
512}
513
514impl From<f64> for Pixels {
515 fn from(val: f64) -> Self {
516 Pixels(val as f32)
517 }
518}
519
520impl From<f32> for Pixels {
521 fn from(val: f32) -> Self {
522 Pixels(val)
523 }
524}
525
526impl Debug for Pixels {
527 fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
528 write!(f, "{} px", self.0)
529 }
530}
531
532impl From<Pixels> for f32 {
533 fn from(pixels: Pixels) -> Self {
534 pixels.0
535 }
536}
537
538impl From<&Pixels> for f32 {
539 fn from(pixels: &Pixels) -> Self {
540 pixels.0
541 }
542}
543
544impl From<Pixels> for f64 {
545 fn from(pixels: Pixels) -> Self {
546 pixels.0 as f64
547 }
548}
549
550#[derive(
551 Add, AddAssign, Clone, Copy, Default, Div, Eq, Hash, Ord, PartialEq, PartialOrd, Sub, SubAssign,
552)]
553#[repr(transparent)]
554pub struct DevicePixels(pub(crate) i32);
555
556impl DevicePixels {
557 pub fn to_bytes(&self, bytes_per_pixel: u8) -> u32 {
558 self.0 as u32 * bytes_per_pixel as u32
559 }
560}
561
562impl std::fmt::Debug for DevicePixels {
563 fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
564 write!(f, "{} px (device)", self.0)
565 }
566}
567
568impl From<DevicePixels> for i32 {
569 fn from(device_pixels: DevicePixels) -> Self {
570 device_pixels.0
571 }
572}
573
574impl From<i32> for DevicePixels {
575 fn from(val: i32) -> Self {
576 DevicePixels(val)
577 }
578}
579
580impl From<DevicePixels> for u64 {
581 fn from(device_pixels: DevicePixels) -> Self {
582 device_pixels.0 as u64
583 }
584}
585
586impl From<u64> for DevicePixels {
587 fn from(val: u64) -> Self {
588 DevicePixels(val as i32)
589 }
590}
591
592#[derive(Clone, Copy, Default, Add, AddAssign, Sub, SubAssign, Div, PartialEq, PartialOrd)]
593#[repr(transparent)]
594pub struct ScaledPixels(pub(crate) f32);
595
596impl ScaledPixels {
597 pub fn floor(&self) -> Self {
598 Self(self.0.floor())
599 }
600}
601
602impl Eq for ScaledPixels {}
603
604impl Debug for ScaledPixels {
605 fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
606 write!(f, "{} px (scaled)", self.0)
607 }
608}
609
610impl From<ScaledPixels> for DevicePixels {
611 fn from(scaled: ScaledPixels) -> Self {
612 DevicePixels(scaled.0.ceil() as i32)
613 }
614}
615
616impl From<DevicePixels> for ScaledPixels {
617 fn from(device: DevicePixels) -> Self {
618 ScaledPixels(device.0 as f32)
619 }
620}
621
622#[derive(Clone, Copy, Default, Add, Sub, Mul, Div)]
623pub struct Rems(f32);
624
625impl Mul<Pixels> for Rems {
626 type Output = Pixels;
627
628 fn mul(self, other: Pixels) -> Pixels {
629 Pixels(self.0 * other.0)
630 }
631}
632
633impl Debug for Rems {
634 fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
635 write!(f, "{} rem", self.0)
636 }
637}
638
639#[derive(Clone, Copy, Debug)]
640pub enum AbsoluteLength {
641 Pixels(Pixels),
642 Rems(Rems),
643}
644
645impl AbsoluteLength {
646 pub fn is_zero(&self) -> bool {
647 match self {
648 AbsoluteLength::Pixels(px) => px.0 == 0.,
649 AbsoluteLength::Rems(rems) => rems.0 == 0.,
650 }
651 }
652}
653
654impl From<Pixels> for AbsoluteLength {
655 fn from(pixels: Pixels) -> Self {
656 AbsoluteLength::Pixels(pixels)
657 }
658}
659
660impl From<Rems> for AbsoluteLength {
661 fn from(rems: Rems) -> Self {
662 AbsoluteLength::Rems(rems)
663 }
664}
665
666impl AbsoluteLength {
667 pub fn to_pixels(&self, rem_size: Pixels) -> Pixels {
668 match self {
669 AbsoluteLength::Pixels(pixels) => *pixels,
670 AbsoluteLength::Rems(rems) => *rems * rem_size,
671 }
672 }
673}
674
675impl Default for AbsoluteLength {
676 fn default() -> Self {
677 px(0.).into()
678 }
679}
680
681/// A non-auto length that can be defined in pixels, rems, or percent of parent.
682#[derive(Clone, Copy)]
683pub enum DefiniteLength {
684 Absolute(AbsoluteLength),
685 /// A fraction of the parent's size between 0 and 1.
686 Fraction(f32),
687}
688
689impl DefiniteLength {
690 pub fn to_pixels(&self, base_size: AbsoluteLength, rem_size: Pixels) -> Pixels {
691 match self {
692 DefiniteLength::Absolute(size) => size.to_pixels(rem_size),
693 DefiniteLength::Fraction(fraction) => match base_size {
694 AbsoluteLength::Pixels(px) => px * *fraction,
695 AbsoluteLength::Rems(rems) => rems * rem_size * *fraction,
696 },
697 }
698 }
699}
700
701impl Debug for DefiniteLength {
702 fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
703 match self {
704 DefiniteLength::Absolute(length) => Debug::fmt(length, f),
705 DefiniteLength::Fraction(fract) => write!(f, "{}%", (fract * 100.0) as i32),
706 }
707 }
708}
709
710impl From<Pixels> for DefiniteLength {
711 fn from(pixels: Pixels) -> Self {
712 Self::Absolute(pixels.into())
713 }
714}
715
716impl From<Rems> for DefiniteLength {
717 fn from(rems: Rems) -> Self {
718 Self::Absolute(rems.into())
719 }
720}
721
722impl From<AbsoluteLength> for DefiniteLength {
723 fn from(length: AbsoluteLength) -> Self {
724 Self::Absolute(length)
725 }
726}
727
728impl Default for DefiniteLength {
729 fn default() -> Self {
730 Self::Absolute(AbsoluteLength::default())
731 }
732}
733
734/// A length that can be defined in pixels, rems, percent of parent, or auto.
735#[derive(Clone, Copy)]
736pub enum Length {
737 Definite(DefiniteLength),
738 Auto,
739}
740
741impl Debug for Length {
742 fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
743 match self {
744 Length::Definite(definite_length) => write!(f, "{:?}", definite_length),
745 Length::Auto => write!(f, "auto"),
746 }
747 }
748}
749
750pub fn relative(fraction: f32) -> DefiniteLength {
751 DefiniteLength::Fraction(fraction).into()
752}
753
754/// Returns the Golden Ratio, i.e. `~(1.0 + sqrt(5.0)) / 2.0`.
755pub fn phi() -> DefiniteLength {
756 relative(1.61803398875)
757}
758
759pub fn rems(rems: f32) -> Rems {
760 Rems(rems)
761}
762
763pub fn px(pixels: f32) -> Pixels {
764 Pixels(pixels)
765}
766
767pub fn auto() -> Length {
768 Length::Auto
769}
770
771impl From<Pixels> for Length {
772 fn from(pixels: Pixels) -> Self {
773 Self::Definite(pixels.into())
774 }
775}
776
777impl From<Rems> for Length {
778 fn from(rems: Rems) -> Self {
779 Self::Definite(rems.into())
780 }
781}
782
783impl From<DefiniteLength> for Length {
784 fn from(length: DefiniteLength) -> Self {
785 Self::Definite(length)
786 }
787}
788
789impl From<AbsoluteLength> for Length {
790 fn from(length: AbsoluteLength) -> Self {
791 Self::Definite(length.into())
792 }
793}
794
795impl Default for Length {
796 fn default() -> Self {
797 Self::Definite(DefiniteLength::default())
798 }
799}
800
801impl From<()> for Length {
802 fn from(_: ()) -> Self {
803 Self::Definite(DefiniteLength::default())
804 }
805}
806
807pub trait IsZero {
808 fn is_zero(&self) -> bool;
809}
810
811impl IsZero for DevicePixels {
812 fn is_zero(&self) -> bool {
813 self.0 == 0
814 }
815}
816
817impl IsZero for ScaledPixels {
818 fn is_zero(&self) -> bool {
819 self.0 == 0.
820 }
821}
822
823impl IsZero for Pixels {
824 fn is_zero(&self) -> bool {
825 self.0 == 0.
826 }
827}
828
829impl IsZero for Rems {
830 fn is_zero(&self) -> bool {
831 self.0 == 0.
832 }
833}
834
835impl IsZero for AbsoluteLength {
836 fn is_zero(&self) -> bool {
837 match self {
838 AbsoluteLength::Pixels(pixels) => pixels.is_zero(),
839 AbsoluteLength::Rems(rems) => rems.is_zero(),
840 }
841 }
842}
843
844impl IsZero for DefiniteLength {
845 fn is_zero(&self) -> bool {
846 match self {
847 DefiniteLength::Absolute(length) => length.is_zero(),
848 DefiniteLength::Fraction(fraction) => *fraction == 0.,
849 }
850 }
851}
852
853impl IsZero for Length {
854 fn is_zero(&self) -> bool {
855 match self {
856 Length::Definite(length) => length.is_zero(),
857 Length::Auto => false,
858 }
859 }
860}
861
862impl<T: IsZero + Debug + Clone> IsZero for Point<T> {
863 fn is_zero(&self) -> bool {
864 self.x.is_zero() && self.y.is_zero()
865 }
866}
867
868impl<T: IsZero + Debug + Clone> IsZero for Size<T> {
869 fn is_zero(&self) -> bool {
870 self.width.is_zero() && self.height.is_zero()
871 }
872}
873
874impl<T: IsZero + Debug + Clone> IsZero for Bounds<T> {
875 fn is_zero(&self) -> bool {
876 self.origin.is_zero() && self.size.is_zero()
877 }
878}