1use std::ops::{Add, AddAssign, Div, Mul, MulAssign, Neg, Sub, SubAssign};
6
7use serde::{Deserialize, Serialize};
8
9use super::units::{DevicePixels, Half, IsZero, Points, ScaledPixels};
10
11#[derive(Debug, Clone, Copy, PartialEq, Eq, Hash)]
13pub enum Axis {
14 Vertical,
16 Horizontal,
18}
19
20impl Axis {
21 #[inline]
23 pub fn invert(self) -> Self {
24 match self {
25 Axis::Vertical => Axis::Horizontal,
26 Axis::Horizontal => Axis::Vertical,
27 }
28 }
29}
30
31pub trait Along {
33 type Unit;
35
36 fn along(&self, axis: Axis) -> Self::Unit;
38
39 fn apply_along(&self, axis: Axis, f: impl FnOnce(Self::Unit) -> Self::Unit) -> Self;
41}
42
43#[derive(Debug, Clone, Copy, Default, PartialEq, Eq, Hash, Serialize, Deserialize)]
46#[repr(C)]
47pub struct Point<T> {
48 pub x: T,
50 pub y: T,
52}
53
54#[inline]
56pub const fn point<T>(x: T, y: T) -> Point<T> {
57 Point { x, y }
58}
59
60impl<T> Point<T> {
61 #[inline]
63 pub const fn new(x: T, y: T) -> Self {
64 Self { x, y }
65 }
66}
67
68impl<T: Clone> Point<T> {
69 #[inline]
71 pub fn map<U>(&self, f: impl Fn(T) -> U) -> Point<U> {
72 Point {
73 x: f(self.x.clone()),
74 y: f(self.y.clone()),
75 }
76 }
77}
78
79impl<T: Clone + PartialOrd> Point<T> {
80 pub fn max(&self, other: &Self) -> Self {
82 Point {
83 x: if self.x >= other.x { &self.x } else { &other.x }.clone(),
84 y: if self.y >= other.y { &self.y } else { &other.y }.clone(),
85 }
86 }
87
88 pub fn min(&self, other: &Self) -> Self {
90 Point {
91 x: if self.x <= other.x { &self.x } else { &other.x }.clone(),
92 y: if self.y <= other.y { &self.y } else { &other.y }.clone(),
93 }
94 }
95
96 pub fn clamp(&self, min: &Self, max: &Self) -> Self {
98 self.max(min).min(max)
99 }
100}
101
102impl<T: Clone + Sub<Output = T>> Point<T> {
103 #[inline]
105 pub fn relative_to(&self, origin: &Point<T>) -> Point<T> {
106 Point {
107 x: self.x.clone() - origin.x.clone(),
108 y: self.y.clone() - origin.y.clone(),
109 }
110 }
111}
112
113impl<T: Clone> Along for Point<T> {
114 type Unit = T;
115
116 #[inline]
117 fn along(&self, axis: Axis) -> T {
118 match axis {
119 Axis::Horizontal => self.x.clone(),
120 Axis::Vertical => self.y.clone(),
121 }
122 }
123
124 fn apply_along(&self, axis: Axis, f: impl FnOnce(T) -> T) -> Self {
125 match axis {
126 Axis::Horizontal => Point::new(f(self.x.clone()), self.y.clone()),
127 Axis::Vertical => Point::new(self.x.clone(), f(self.y.clone())),
128 }
129 }
130}
131
132impl Point<Points> {
133 #[inline]
135 pub fn scale(&self, factor: f32) -> Point<ScaledPixels> {
136 Point::new(self.x.scale(factor), self.y.scale(factor))
137 }
138
139 #[inline]
141 pub fn magnitude(&self) -> f64 {
142 (self.x.0 as f64).hypot(self.y.0 as f64)
143 }
144}
145
146impl<T: Add<Output = T>> Add for Point<T> {
147 type Output = Self;
148 #[inline]
149 fn add(self, rhs: Self) -> Self {
150 Point::new(self.x + rhs.x, self.y + rhs.y)
151 }
152}
153
154impl<T: Sub<Output = T>> Sub for Point<T> {
155 type Output = Self;
156 #[inline]
157 fn sub(self, rhs: Self) -> Self {
158 Point::new(self.x - rhs.x, self.y - rhs.y)
159 }
160}
161
162impl<T: AddAssign> AddAssign for Point<T> {
163 #[inline]
164 fn add_assign(&mut self, rhs: Self) {
165 self.x += rhs.x;
166 self.y += rhs.y;
167 }
168}
169
170impl<T: SubAssign> SubAssign for Point<T> {
171 #[inline]
172 fn sub_assign(&mut self, rhs: Self) {
173 self.x -= rhs.x;
174 self.y -= rhs.y;
175 }
176}
177
178impl<T: Neg<Output = T>> Neg for Point<T> {
179 type Output = Self;
180 #[inline]
181 fn neg(self) -> Self {
182 Point::new(-self.x, -self.y)
183 }
184}
185
186impl<T: Mul<S, Output = T>, S: Clone> Mul<S> for Point<T> {
187 type Output = Self;
188 #[inline]
189 fn mul(self, rhs: S) -> Self {
190 Point::new(self.x * rhs.clone(), self.y * rhs)
191 }
192}
193
194impl<T: MulAssign<S>, S: Clone> MulAssign<S> for Point<T> {
195 #[inline]
196 fn mul_assign(&mut self, rhs: S) {
197 self.x *= rhs.clone();
198 self.y *= rhs;
199 }
200}
201
202impl<T: Div<S, Output = T>, S: Clone> Div<S> for Point<T> {
203 type Output = Self;
204 #[inline]
205 fn div(self, rhs: S) -> Self {
206 Point::new(self.x / rhs.clone(), self.y / rhs)
207 }
208}
209
210impl<T: IsZero> IsZero for Point<T> {
211 fn is_zero(&self) -> bool {
212 self.x.is_zero() && self.y.is_zero()
213 }
214}
215
216impl<T> From<Size<T>> for Point<T> {
217 #[inline]
218 fn from(s: Size<T>) -> Self {
219 Point::new(s.width, s.height)
220 }
221}
222
223#[derive(Debug, Clone, Copy, Default, PartialEq, Eq, Hash, Serialize, Deserialize)]
225#[repr(C)]
226pub struct Size<T> {
227 pub width: T,
229 pub height: T,
231}
232
233#[inline]
235pub const fn size<T>(width: T, height: T) -> Size<T> {
236 Size { width, height }
237}
238
239impl<T> Size<T> {
240 #[inline]
242 pub const fn new(width: T, height: T) -> Self {
243 Self { width, height }
244 }
245}
246
247impl<T: Clone> Size<T> {
248 #[inline]
250 pub fn map<U>(&self, f: impl Fn(T) -> U) -> Size<U> {
251 Size {
252 width: f(self.width.clone()),
253 height: f(self.height.clone()),
254 }
255 }
256}
257
258impl<T: Clone + PartialOrd> Size<T> {
259 pub fn max(&self, other: &Self) -> Self {
261 Size {
262 width: if self.width >= other.width {
263 &self.width
264 } else {
265 &other.width
266 }
267 .clone(),
268 height: if self.height >= other.height {
269 &self.height
270 } else {
271 &other.height
272 }
273 .clone(),
274 }
275 }
276
277 pub fn min(&self, other: &Self) -> Self {
279 Size {
280 width: if self.width <= other.width {
281 &self.width
282 } else {
283 &other.width
284 }
285 .clone(),
286 height: if self.height <= other.height {
287 &self.height
288 } else {
289 &other.height
290 }
291 .clone(),
292 }
293 }
294}
295
296impl<T: Half> Size<T> {
297 #[inline]
299 pub fn center(&self) -> Point<T> {
300 Point::new(self.width.half(), self.height.half())
301 }
302}
303
304impl<T: Clone> Along for Size<T> {
305 type Unit = T;
306
307 #[inline]
308 fn along(&self, axis: Axis) -> T {
309 match axis {
310 Axis::Horizontal => self.width.clone(),
311 Axis::Vertical => self.height.clone(),
312 }
313 }
314
315 fn apply_along(&self, axis: Axis, f: impl FnOnce(T) -> T) -> Self {
316 match axis {
317 Axis::Horizontal => Size::new(f(self.width.clone()), self.height.clone()),
318 Axis::Vertical => Size::new(self.width.clone(), f(self.height.clone())),
319 }
320 }
321}
322
323impl Size<Points> {
324 #[inline]
326 pub fn scale(&self, factor: f32) -> Size<ScaledPixels> {
327 Size::new(self.width.scale(factor), self.height.scale(factor))
328 }
329
330 #[inline]
332 pub fn to_device_pixels(self, scale_factor: f32) -> Size<DevicePixels> {
333 Size::new(
334 self.width.to_device_pixels(scale_factor),
335 self.height.to_device_pixels(scale_factor),
336 )
337 }
338}
339
340impl Size<DevicePixels> {
341 #[inline]
343 pub fn to_points(self, scale_factor: f32) -> Size<Points> {
344 Size::new(
345 self.width.to_points(scale_factor),
346 self.height.to_points(scale_factor),
347 )
348 }
349}
350
351impl<T: Add<Output = T>> Add for Size<T> {
352 type Output = Self;
353 #[inline]
354 fn add(self, rhs: Self) -> Self {
355 Size::new(self.width + rhs.width, self.height + rhs.height)
356 }
357}
358
359impl<T: Sub<Output = T>> Sub for Size<T> {
360 type Output = Self;
361 #[inline]
362 fn sub(self, rhs: Self) -> Self {
363 Size::new(self.width - rhs.width, self.height - rhs.height)
364 }
365}
366
367impl<T: Mul<S, Output = T>, S: Clone> Mul<S> for Size<T> {
368 type Output = Self;
369 #[inline]
370 fn mul(self, rhs: S) -> Self {
371 Size::new(self.width * rhs.clone(), self.height * rhs)
372 }
373}
374
375impl<T: MulAssign<S>, S: Clone> MulAssign<S> for Size<T> {
376 #[inline]
377 fn mul_assign(&mut self, rhs: S) {
378 self.width *= rhs.clone();
379 self.height *= rhs;
380 }
381}
382
383impl<T: Div<S, Output = T>, S: Clone> Div<S> for Size<T> {
384 type Output = Self;
385 #[inline]
386 fn div(self, rhs: S) -> Self {
387 Size::new(self.width / rhs.clone(), self.height / rhs)
388 }
389}
390
391impl<T: IsZero> IsZero for Size<T> {
392 fn is_zero(&self) -> bool {
394 self.width.is_zero() || self.height.is_zero()
395 }
396}
397
398impl<T> From<Point<T>> for Size<T> {
399 #[inline]
400 fn from(p: Point<T>) -> Self {
401 Size::new(p.x, p.y)
402 }
403}
404
405#[derive(Debug, Clone, Copy, Default, PartialEq, Eq, Hash, Serialize, Deserialize)]
408#[repr(C)]
409pub struct Bounds<T> {
410 pub origin: Point<T>,
412 pub size: Size<T>,
414}
415
416#[inline]
418pub const fn bounds<T>(origin: Point<T>, size: Size<T>) -> Bounds<T> {
419 Bounds { origin, size }
420}
421
422impl<T> Bounds<T> {
423 #[inline]
425 pub const fn new(origin: Point<T>, size: Size<T>) -> Self {
426 Self { origin, size }
427 }
428}
429
430impl<T: Clone> Bounds<T> {
431 #[inline]
433 pub fn map<U>(&self, f: impl Fn(T) -> U) -> Bounds<U> {
434 Bounds {
435 origin: self.origin.map(&f),
436 size: self.size.map(&f),
437 }
438 }
439
440 #[inline]
442 pub fn map_origin(self, f: impl Fn(T) -> T) -> Bounds<T> {
443 Bounds {
444 origin: self.origin.map(f),
445 size: self.size,
446 }
447 }
448
449 #[inline]
451 pub fn map_size(self, f: impl Fn(T) -> T) -> Bounds<T> {
452 Bounds {
453 origin: self.origin,
454 size: self.size.map(f),
455 }
456 }
457}
458
459impl<T: Clone + Add<Output = T> + Sub<Output = T>> Bounds<T> {
460 #[inline]
462 pub fn from_corners(top_left: Point<T>, bottom_right: Point<T>) -> Self {
463 let size = Size::new(
464 bottom_right.x - top_left.x.clone(),
465 bottom_right.y - top_left.y.clone(),
466 );
467 Bounds {
468 origin: top_left,
469 size,
470 }
471 }
472
473 #[inline]
475 pub fn top(&self) -> T {
476 self.origin.y.clone()
477 }
478
479 #[inline]
481 pub fn bottom(&self) -> T {
482 self.origin.y.clone() + self.size.height.clone()
483 }
484
485 #[inline]
487 pub fn left(&self) -> T {
488 self.origin.x.clone()
489 }
490
491 #[inline]
493 pub fn right(&self) -> T {
494 self.origin.x.clone() + self.size.width.clone()
495 }
496
497 #[inline]
499 pub fn top_right(&self) -> Point<T> {
500 Point::new(self.right(), self.top())
501 }
502
503 #[inline]
505 pub fn bottom_right(&self) -> Point<T> {
506 Point::new(self.right(), self.bottom())
507 }
508
509 #[inline]
511 pub fn bottom_left(&self) -> Point<T> {
512 Point::new(self.left(), self.bottom())
513 }
514
515 #[must_use]
517 pub fn dilate(&self, amount: T) -> Self {
518 let double = amount.clone() + amount.clone();
519 Bounds {
520 origin: self.origin.clone() - point(amount.clone(), amount),
521 size: self.size.clone() + size(double.clone(), double),
522 }
523 }
524
525 #[must_use]
527 pub fn extend(&self, amount: Edges<T>) -> Self {
528 Bounds {
529 origin: self.origin.clone() - point(amount.left.clone(), amount.top.clone()),
530 size: self.size.clone() + size(amount.left + amount.right, amount.top + amount.bottom),
531 }
532 }
533
534 pub fn space_within(&self, outer: &Self) -> Edges<T> {
536 Edges {
537 top: self.top() - outer.top(),
538 right: outer.right() - self.right(),
539 bottom: outer.bottom() - self.bottom(),
540 left: self.left() - outer.left(),
541 }
542 }
543}
544
545impl<T: Clone + Add<Output = T> + Sub<Output = T> + Neg<Output = T>> Bounds<T> {
546 #[must_use]
549 pub fn inset(&self, amount: T) -> Self {
550 self.dilate(-amount)
551 }
552}
553
554impl<T: Clone + Add<Output = T> + Sub<Output = T> + Half> Bounds<T> {
555 pub fn centered_at(center: Point<T>, size: Size<T>) -> Self {
557 let origin = Point::new(center.x - size.width.half(), center.y - size.height.half());
558 Bounds { origin, size }
559 }
560
561 #[inline]
563 pub fn center(&self) -> Point<T> {
564 Point::new(
565 self.origin.x.clone() + self.size.width.half(),
566 self.origin.y.clone() + self.size.height.half(),
567 )
568 }
569
570 #[inline]
572 pub fn half_perimeter(&self) -> T {
573 self.size.width.clone() + self.size.height.clone()
574 }
575}
576
577impl<T: Clone + Add<Output = T> + Sub<Output = T> + PartialOrd> Bounds<T> {
578 #[inline]
581 pub fn contains(&self, point: &Point<T>) -> bool {
582 point.x >= self.left()
583 && point.x < self.right()
584 && point.y >= self.top()
585 && point.y < self.bottom()
586 }
587
588 pub fn is_contained_within(&self, other: &Self) -> bool {
590 self.left() >= other.left()
591 && self.right() <= other.right()
592 && self.top() >= other.top()
593 && self.bottom() <= other.bottom()
594 }
595
596 #[inline]
598 pub fn intersects(&self, other: &Self) -> bool {
599 let my_lower_right = self.bottom_right();
600 let their_lower_right = other.bottom_right();
601 self.origin.x < their_lower_right.x
602 && my_lower_right.x > other.origin.x
603 && self.origin.y < their_lower_right.y
604 && my_lower_right.y > other.origin.y
605 }
606
607 pub fn intersect(&self, other: &Self) -> Self {
609 let upper_left = self.origin.max(&other.origin);
610 let bottom_right = self
611 .bottom_right()
612 .min(&other.bottom_right())
613 .max(&upper_left);
614 Self::from_corners(upper_left, bottom_right)
615 }
616
617 pub fn union(&self, other: &Self) -> Self {
619 let top_left = self.origin.min(&other.origin);
620 let bottom_right = self.bottom_right().max(&other.bottom_right());
621 Bounds::from_corners(top_left, bottom_right)
622 }
623
624 pub fn localize(&self, point: &Point<T>) -> Option<Point<T>> {
626 self.contains(point)
627 .then(|| point.relative_to(&self.origin))
628 }
629}
630
631impl<T: PartialOrd + Default> Bounds<T> {
632 #[inline]
634 pub fn is_empty(&self) -> bool {
635 !(self.size.width > T::default() && self.size.height > T::default())
636 }
637}
638
639impl Bounds<Points> {
640 pub(crate) const UNSET: Self = Bounds {
643 origin: Point::new(Points(f32::NAN), Points(f32::NAN)),
644 size: Size::new(Points(f32::NAN), Points(f32::NAN)),
645 };
646
647 #[inline]
649 pub fn scale(&self, factor: f32) -> Bounds<ScaledPixels> {
650 Bounds {
651 origin: self.origin.scale(factor),
652 size: self.size.scale(factor),
653 }
654 }
655
656 #[inline]
658 pub fn to_device_pixels(self, scale_factor: f32) -> Bounds<DevicePixels> {
659 Bounds {
660 origin: self.origin.map(|p| p.to_device_pixels(scale_factor)),
661 size: self.size.to_device_pixels(scale_factor),
662 }
663 }
664}
665
666impl Bounds<DevicePixels> {
667 #[inline]
669 pub fn to_points(self, scale_factor: f32) -> Bounds<Points> {
670 Bounds {
671 origin: self.origin.map(|p| p.to_points(scale_factor)),
672 size: self.size.to_points(scale_factor),
673 }
674 }
675}
676
677impl<T: Add<Output = T>> Add<Point<T>> for Bounds<T> {
679 type Output = Self;
680 #[inline]
681 fn add(self, rhs: Point<T>) -> Self {
682 Bounds {
683 origin: self.origin + rhs,
684 size: self.size,
685 }
686 }
687}
688
689impl<T: Sub<Output = T>> Sub<Point<T>> for Bounds<T> {
691 type Output = Self;
692 #[inline]
693 fn sub(self, rhs: Point<T>) -> Self {
694 Bounds {
695 origin: self.origin - rhs,
696 size: self.size,
697 }
698 }
699}
700
701impl<T: Mul<S, Output = T>, S: Clone> Mul<S> for Bounds<T> {
702 type Output = Self;
703 #[inline]
704 fn mul(self, rhs: S) -> Self {
705 Bounds {
706 origin: self.origin * rhs.clone(),
707 size: self.size * rhs,
708 }
709 }
710}
711
712impl<T: MulAssign<S>, S: Clone> MulAssign<S> for Bounds<T> {
713 #[inline]
714 fn mul_assign(&mut self, rhs: S) {
715 self.origin *= rhs.clone();
716 self.size *= rhs;
717 }
718}
719
720impl<T: Div<S, Output = T>, S: Clone> Div<S> for Bounds<T> {
721 type Output = Self;
722 #[inline]
723 fn div(self, rhs: S) -> Self {
724 Bounds {
725 origin: self.origin / rhs.clone(),
726 size: self.size / rhs,
727 }
728 }
729}
730
731impl<T: IsZero> IsZero for Bounds<T> {
732 fn is_zero(&self) -> bool {
733 self.size.is_zero()
734 }
735}
736
737#[derive(Debug, Clone, Copy, Default, PartialEq, Eq, Hash, Serialize, Deserialize)]
739#[repr(C)]
740pub struct Edges<T> {
741 pub top: T,
743 pub right: T,
745 pub bottom: T,
747 pub left: T,
749}
750
751impl<T: Clone> Edges<T> {
752 #[inline]
754 pub fn all(value: T) -> Self {
755 Edges {
756 top: value.clone(),
757 right: value.clone(),
758 bottom: value.clone(),
759 left: value,
760 }
761 }
762
763 #[inline]
765 pub fn to_array(&self) -> [T; 4] {
766 [
767 self.top.clone(),
768 self.right.clone(),
769 self.bottom.clone(),
770 self.left.clone(),
771 ]
772 }
773}
774
775impl<T> From<[T; 4]> for Edges<T> {
776 fn from([top, right, bottom, left]: [T; 4]) -> Self {
778 Edges {
779 top,
780 right,
781 bottom,
782 left,
783 }
784 }
785}
786
787impl<T> Edges<T> {
788 #[inline]
790 pub fn map<U>(&self, f: impl Fn(&T) -> U) -> Edges<U> {
791 Edges {
792 top: f(&self.top),
793 right: f(&self.right),
794 bottom: f(&self.bottom),
795 left: f(&self.left),
796 }
797 }
798
799 #[inline]
801 pub fn any(&self, predicate: impl Fn(&T) -> bool) -> bool {
802 predicate(&self.top)
803 || predicate(&self.right)
804 || predicate(&self.bottom)
805 || predicate(&self.left)
806 }
807}
808
809impl Edges<Points> {
810 pub fn zero() -> Self {
812 Edges::all(Points::ZERO)
813 }
814
815 pub fn scale(&self, factor: f32) -> Edges<ScaledPixels> {
817 self.map(|p| p.scale(factor))
818 }
819
820 pub fn max(&self) -> Points {
822 self.top.max(self.right).max(self.bottom).max(self.left)
823 }
824}
825
826impl<T: Mul<S, Output = T> + Clone, S: Clone> Mul<S> for Edges<T> {
827 type Output = Self;
828 #[inline]
829 fn mul(self, rhs: S) -> Self {
830 Edges {
831 top: self.top * rhs.clone(),
832 right: self.right * rhs.clone(),
833 bottom: self.bottom * rhs.clone(),
834 left: self.left * rhs,
835 }
836 }
837}
838
839impl<T: IsZero> IsZero for Edges<T> {
840 fn is_zero(&self) -> bool {
841 self.top.is_zero() && self.right.is_zero() && self.bottom.is_zero() && self.left.is_zero()
842 }
843}
844
845impl From<f32> for Edges<Points> {
846 fn from(v: f32) -> Self {
847 Edges::all(Points(v))
848 }
849}
850
851impl From<Points> for Edges<Points> {
852 fn from(p: Points) -> Self {
853 Edges::all(p)
854 }
855}
856
857#[derive(Debug, Clone, Copy, Default, PartialEq, Eq, Hash, Serialize, Deserialize)]
859#[repr(C)]
860pub struct Corners<T> {
861 pub top_left: T,
863 pub top_right: T,
865 pub bottom_right: T,
867 pub bottom_left: T,
869}
870
871impl<T: Clone> Corners<T> {
872 #[inline]
874 pub fn all(value: T) -> Self {
875 Corners {
876 top_left: value.clone(),
877 top_right: value.clone(),
878 bottom_right: value.clone(),
879 bottom_left: value,
880 }
881 }
882
883 #[inline]
886 pub fn to_array(&self) -> [T; 4] {
887 [
888 self.top_left.clone(),
889 self.top_right.clone(),
890 self.bottom_right.clone(),
891 self.bottom_left.clone(),
892 ]
893 }
894}
895
896impl<T> From<[T; 4]> for Corners<T> {
897 fn from([top_left, top_right, bottom_right, bottom_left]: [T; 4]) -> Self {
899 Corners {
900 top_left,
901 top_right,
902 bottom_right,
903 bottom_left,
904 }
905 }
906}
907
908impl<T> Corners<T> {
909 #[inline]
911 pub fn map<U>(&self, f: impl Fn(&T) -> U) -> Corners<U> {
912 Corners {
913 top_left: f(&self.top_left),
914 top_right: f(&self.top_right),
915 bottom_right: f(&self.bottom_right),
916 bottom_left: f(&self.bottom_left),
917 }
918 }
919
920 #[inline]
922 pub fn any(&self, predicate: impl Fn(&T) -> bool) -> bool {
923 predicate(&self.top_left)
924 || predicate(&self.top_right)
925 || predicate(&self.bottom_right)
926 || predicate(&self.bottom_left)
927 }
928}
929
930impl Corners<Points> {
931 pub fn scale(&self, factor: f32) -> Corners<ScaledPixels> {
933 self.map(|p| p.scale(factor))
934 }
935
936 pub fn max(&self) -> Points {
938 self.top_left
939 .max(self.top_right)
940 .max(self.bottom_right)
941 .max(self.bottom_left)
942 }
943
944 pub fn clamp_radii_for_quad_size(self, size: Size<Points>) -> Corners<Points> {
947 let max = size.width.min(size.height) / 2.0;
948 self.map(|r| r.min(max))
949 }
950}
951
952impl<T: Mul<S, Output = T> + Clone, S: Clone> Mul<S> for Corners<T> {
953 type Output = Self;
954 #[inline]
955 fn mul(self, rhs: S) -> Self {
956 Corners {
957 top_left: self.top_left * rhs.clone(),
958 top_right: self.top_right * rhs.clone(),
959 bottom_right: self.bottom_right * rhs.clone(),
960 bottom_left: self.bottom_left * rhs,
961 }
962 }
963}
964
965impl<T: IsZero> IsZero for Corners<T> {
966 fn is_zero(&self) -> bool {
967 self.top_left.is_zero()
968 && self.top_right.is_zero()
969 && self.bottom_right.is_zero()
970 && self.bottom_left.is_zero()
971 }
972}
973
974impl From<f32> for Corners<Points> {
975 fn from(v: f32) -> Self {
976 Corners::all(Points(v))
977 }
978}
979
980impl From<Points> for Corners<Points> {
981 fn from(p: Points) -> Self {
982 Corners::all(p)
983 }
984}