1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
use core::{
    convert::{TryFrom, TryInto},
    fmt,
    ops::{Add, AddAssign, Div, DivAssign, Index, Mul, MulAssign, Neg, Sub, SubAssign},
};

use crate::geometry::Size;

/// 2D point.
///
/// A point can be used to define the position of a graphics object. For example, a [`Rectangle`]
/// may be defined that has its top left corner at `(-1, -2)`. To specify the size of an object
/// [`Size`] should be used instead.
///
/// [Nalgebra] support can be enabled with the `nalgebra_support` feature. This implements
/// `From<Vector2<N>>` and `From<&Vector2<N>>` where `N` is `Scalar + Into<i32>`. This allows use
/// of Nalgebra's [`Vector2`] with embedded-graphics where `i8`, `i16`, `i32`, `u16` or `u8` is used
/// for value storage.
///
/// # Examples
///
/// ## Create a `Point` from two integers
///
/// ```rust
/// use embedded_graphics::geometry::Point;
///
/// // Create a coord using the `new` constructor method
/// let p = Point::new(10, 20);
/// ```
///
/// ## Create a `Point` from a Nalgebra `Vector2`
///
/// _Be sure to enable the `nalgebra_support` feature to get [Nalgebra] integration._
///
/// ```rust
/// # #[cfg(feature = "nalgebra_support")] {
/// use embedded_graphics::geometry::Point;
/// use nalgebra::Vector2;
///
/// let n_coord = Vector2::new(10i32, 20);
///
/// assert_eq!(Point::from(n_coord), Point::new(10, 20));
/// # }
/// ```
///
/// ## Convert a `Vector2<u8>` into a `Point`
///
/// _Be sure to enable the `nalgebra_support` feature to get [Nalgebra] integration._
///
/// Smaller unsigned types that can be converted to `i32` are also supported in conversions.
///
/// ```rust
/// # #[cfg(feature = "nalgebra_support")] {
/// use embedded_graphics::geometry::Point;
/// use nalgebra::Vector2;
///
/// let n_coord = Vector2::new(10u8, 20);
///
/// assert_eq!(Point::from(n_coord), Point::new(10, 20));
/// # }
/// ```
///
/// [`Rectangle`]: crate::primitives::rectangle::Rectangle
/// [`Vector2<N>`]: https://docs.rs/nalgebra/0.18.0/nalgebra/base/type.Vector2.html
/// [`Vector2`]: https://docs.rs/nalgebra/0.18.0/nalgebra/base/type.Vector2.html
/// [Nalgebra]: https://docs.rs/nalgebra
#[derive(Copy, Clone, Eq, PartialEq, Ord, PartialOrd, Hash, Debug, Default)]
#[cfg_attr(feature = "defmt", derive(::defmt::Format))]
pub struct Point {
    /// The x coordinate.
    pub x: i32,

    /// The y coordinate.
    pub y: i32,
}

impl Point {
    /// Creates a point from  X and Y coordinates.
    pub const fn new(x: i32, y: i32) -> Self {
        Point { x, y }
    }

    /// Creates a point with X and Y values set to an equal value.
    ///
    /// # Examples
    ///
    /// ```rust
    /// use embedded_graphics::geometry::Point;
    ///
    /// let point = Point::new_equal(11);
    ///
    /// assert_eq!(point, Point { x: 11, y: 11 });
    /// ```
    pub const fn new_equal(value: i32) -> Self {
        Point { x: value, y: value }
    }

    /// Creates a point with X and Y equal to zero.
    pub const fn zero() -> Self {
        Point { x: 0, y: 0 }
    }

    /// Returns a point with equal `x` value and `y` set to `0`.
    ///
    /// # Examples
    ///
    /// ## Move a `Point` along the X axis.
    ///
    /// ```rust
    /// use embedded_graphics::geometry::Point;
    ///
    /// let translate = Point::new(20, 30);
    ///
    /// let point = Point::new(10, 15);
    ///
    /// let moved_x = point + translate.x_axis();
    ///
    /// assert_eq!(moved_x, Point::new(30, 15));
    /// ```
    pub const fn x_axis(self) -> Self {
        Self { x: self.x, y: 0 }
    }

    /// Returns a point with equal `y` value and `x` set to `0`.
    ///
    /// # Examples
    ///
    /// ## Move a `Point` along the Y axis.
    ///
    /// ```rust
    /// use embedded_graphics::geometry::Point;
    ///
    /// let translate = Point::new(20, 30);
    ///
    /// let point = Point::new(10, 15);
    ///
    /// let moved_y = point + translate.y_axis();
    ///
    /// assert_eq!(moved_y, Point::new(10, 45));
    /// ```
    pub const fn y_axis(self) -> Self {
        Self { x: 0, y: self.y }
    }

    /// Remove the sign from a coordinate
    ///
    /// # Examples
    ///
    /// ```
    /// # use embedded_graphics::geometry::Point;
    /// #
    /// let point = Point::new(-5, -10);
    ///
    /// assert_eq!(point.abs(), Point::new(5, 10));
    /// ```
    pub const fn abs(self) -> Self {
        Point::new(self.x.abs(), self.y.abs())
    }

    /// Offsets a point by subtracting a size.
    ///
    /// This method provides a workaround for the `Sub` trait not being usable in `const` contexts.
    ///
    /// # Panics
    ///
    /// This function will panic if `width` or `height` are too large to be represented as an `i32`
    /// and debug assertions are enabled.
    pub(crate) const fn sub_size(self, other: Size) -> Point {
        let width = other.width as i32;
        let height = other.height as i32;

        debug_assert!(width >= 0, "width is too large");
        debug_assert!(height >= 0, "height is too large");

        Point::new(self.x - width, self.y - height)
    }

    /// Returns the componentwise minimum of two `Point`s
    ///
    /// # Examples
    ///
    /// ```rust
    /// use embedded_graphics::geometry::Point;
    ///
    /// let min = Point::new(20, 30).component_min(Point::new(15, 50));
    ///
    /// assert_eq!(min, Point::new(15, 30));
    /// ```
    pub fn component_min(self, other: Self) -> Self {
        Self::new(self.x.min(other.x), self.y.min(other.y))
    }

    /// Returns the componentwise maximum of two `Point`s
    ///
    /// # Examples
    ///
    /// ```rust
    /// use embedded_graphics::geometry::Point;
    ///
    /// let min = Point::new(20, 30).component_max(Point::new(15, 50));
    ///
    /// assert_eq!(min, Point::new(20, 50));
    /// ```
    pub fn component_max(self, other: Self) -> Self {
        Self::new(self.x.max(other.x), self.y.max(other.y))
    }

    /// Returns the componentwise multiplication of two `Point`s.
    ///
    /// ```rust
    /// use embedded_graphics::geometry::Point;
    ///
    /// let result = Point::new(20, 30).component_mul(Point::new(-2, 3));
    ///
    /// assert_eq!(result, Point::new(-40, 90));
    /// ```
    pub const fn component_mul(self, other: Self) -> Self {
        Self::new(self.x * other.x, self.y * other.y)
    }

    /// Returns the componentwise division of two `Points`s.
    ///
    /// # Panics
    ///
    /// Panics if one of the components of `other` equals zero.
    ///
    /// ```rust
    /// use embedded_graphics::geometry::Point;
    ///
    /// let result = Point::new(20, 30).component_div(Point::new(10, -3));
    ///
    /// assert_eq!(result, Point::new(2, -10));
    /// ```
    pub const fn component_div(self, other: Self) -> Self {
        Self::new(self.x / other.x, self.y / other.y)
    }
}

impl Add for Point {
    type Output = Point;

    fn add(self, other: Point) -> Point {
        Point::new(self.x + other.x, self.y + other.y)
    }
}

impl Add<Size> for Point {
    type Output = Point;

    /// Offsets a point by adding a size.
    ///
    /// # Panics
    ///
    /// This function will panic if `width` or `height` are too large to be represented as an `i32`
    /// and debug assertions are enabled.
    fn add(self, other: Size) -> Point {
        let width = other.width as i32;
        let height = other.height as i32;

        debug_assert!(width >= 0, "width is too large");
        debug_assert!(height >= 0, "height is too large");

        Point::new(self.x + width, self.y + height)
    }
}

impl AddAssign for Point {
    fn add_assign(&mut self, other: Point) {
        self.x += other.x;
        self.y += other.y;
    }
}

impl AddAssign<Size> for Point {
    /// Offsets a point by adding a size.
    ///
    /// # Panics
    ///
    /// This function will panic if `width` or `height` are too large to be represented as an `i32`
    /// and debug assertions are enabled.
    fn add_assign(&mut self, other: Size) {
        let width = other.width as i32;
        let height = other.height as i32;

        debug_assert!(width >= 0, "width is too large");
        debug_assert!(height >= 0, "height is too large");

        self.x += width;
        self.y += height;
    }
}

impl Sub for Point {
    type Output = Point;

    fn sub(self, other: Point) -> Point {
        Point::new(self.x - other.x, self.y - other.y)
    }
}

impl Sub<Size> for Point {
    type Output = Point;

    /// Offsets a point by subtracting a size.
    ///
    /// # Panics
    ///
    /// This function will panic if `width` or `height` are too large to be represented as an `i32`
    /// and debug assertions are enabled.
    fn sub(self, other: Size) -> Point {
        self.sub_size(other)
    }
}

impl SubAssign for Point {
    fn sub_assign(&mut self, other: Point) {
        self.x -= other.x;
        self.y -= other.y;
    }
}

impl SubAssign<Size> for Point {
    /// Offsets a point by subtracting a size.
    ///
    /// # Panics
    ///
    /// This function will panic if `width` or `height` are too large to be represented as an `i32`
    /// and debug assertions are enabled.
    fn sub_assign(&mut self, other: Size) {
        let width = other.width as i32;
        let height = other.height as i32;

        debug_assert!(width >= 0, "width is too large");
        debug_assert!(height >= 0, "height is too large");

        self.x -= width;
        self.y -= height;
    }
}

impl Mul<i32> for Point {
    type Output = Point;

    fn mul(self, rhs: i32) -> Point {
        Point::new(self.x * rhs, self.y * rhs)
    }
}

impl MulAssign<i32> for Point {
    fn mul_assign(&mut self, rhs: i32) {
        self.x *= rhs;
        self.y *= rhs;
    }
}

impl Div<i32> for Point {
    type Output = Point;

    fn div(self, rhs: i32) -> Point {
        Point::new(self.x / rhs, self.y / rhs)
    }
}

impl DivAssign<i32> for Point {
    fn div_assign(&mut self, rhs: i32) {
        self.x /= rhs;
        self.y /= rhs;
    }
}

impl Index<usize> for Point {
    type Output = i32;

    fn index(&self, idx: usize) -> &i32 {
        match idx {
            0 => &self.x,
            1 => &self.y,
            _ => panic!("index out of bounds: the len is 2 but the index is {}", idx),
        }
    }
}

impl Neg for Point {
    type Output = Point;

    fn neg(self) -> Self::Output {
        Point::new(-self.x, -self.y)
    }
}

impl From<(i32, i32)> for Point {
    fn from(other: (i32, i32)) -> Self {
        Point::new(other.0, other.1)
    }
}

impl From<[i32; 2]> for Point {
    fn from(other: [i32; 2]) -> Self {
        Point::new(other[0], other[1])
    }
}

impl From<&[i32; 2]> for Point {
    fn from(other: &[i32; 2]) -> Self {
        Point::new(other[0], other[1])
    }
}

impl From<Point> for (i32, i32) {
    fn from(other: Point) -> (i32, i32) {
        (other.x, other.y)
    }
}

impl From<Point> for [i32; 2] {
    fn from(other: Point) -> [i32; 2] {
        [other.x, other.y]
    }
}

impl From<&Point> for (i32, i32) {
    fn from(other: &Point) -> (i32, i32) {
        (other.x, other.y)
    }
}

impl TryFrom<Point> for (u32, u32) {
    type Error = core::num::TryFromIntError;

    fn try_from(point: Point) -> Result<Self, Self::Error> {
        Ok((point.x.try_into()?, point.y.try_into()?))
    }
}

impl TryFrom<(u32, u32)> for Point {
    type Error = core::num::TryFromIntError;

    fn try_from(point: (u32, u32)) -> Result<Self, Self::Error> {
        let x = point.0.try_into()?;
        let y = point.1.try_into()?;

        Ok(Point::new(x, y))
    }
}

impl TryFrom<Point> for [u32; 2] {
    type Error = core::num::TryFromIntError;

    fn try_from(point: Point) -> Result<Self, Self::Error> {
        Ok([point.x.try_into()?, point.y.try_into()?])
    }
}

impl TryFrom<[u32; 2]> for Point {
    type Error = core::num::TryFromIntError;

    fn try_from(point: [u32; 2]) -> Result<Self, Self::Error> {
        let x = point[0].try_into()?;
        let y = point[1].try_into()?;

        Ok(Point::new(x, y))
    }
}

impl TryFrom<&[u32; 2]> for Point {
    type Error = core::num::TryFromIntError;

    fn try_from(point: &[u32; 2]) -> Result<Self, Self::Error> {
        let x = point[0].try_into()?;
        let y = point[1].try_into()?;

        Ok(Point::new(x, y))
    }
}

impl fmt::Display for Point {
    fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
        write!(f, "{}, {}", self.x, self.y)
    }
}

#[cfg(feature = "nalgebra_support")]
use nalgebra::{base::Scalar, Vector2};

#[cfg(feature = "nalgebra_support")]
impl<N> From<Vector2<N>> for Point
where
    N: Into<i32> + Scalar + Copy,
{
    fn from(other: Vector2<N>) -> Self {
        Self::new(other[0].into(), other[1].into())
    }
}

#[cfg(feature = "nalgebra_support")]
impl<N> From<&Vector2<N>> for Point
where
    N: Into<i32> + Scalar + Copy,
{
    fn from(other: &Vector2<N>) -> Self {
        Self::new(other[0].into(), other[1].into())
    }
}

#[cfg(test)]
mod tests {
    use super::*;

    use core::fmt::Write;

    #[test]
    fn convert_positive_to_u32_tuple() {
        let p = Point::new(10, 20);

        let tuple: (u32, u32) = p.try_into().unwrap();
        let array: [u32; 2] = p.try_into().unwrap();

        assert_eq!(tuple, (10, 20));
        assert_eq!(array, [10, 20]);
    }

    #[test]
    fn convert_i32_max_to_u32_tuple() {
        let p = Point::new(i32::max_value(), i32::max_value());

        let tuple: (u32, u32) = p.try_into().unwrap();
        let array: [u32; 2] = p.try_into().unwrap();

        // Literal value taken from https://doc.rust-lang.org/std/primitive.i32.html#method.max_value
        assert_eq!(tuple, (2147483647, 2147483647));
        assert_eq!(array, [2147483647, 2147483647]);
    }

    #[test]
    fn convert_negative_to_u32_tuple() {
        let p = Point::new(-50, -10);

        let tuple: Result<(u32, u32), _> = p.try_into();
        let array: Result<[u32; 2], _> = p.try_into();

        assert!(tuple.is_err());
        assert!(array.is_err());
    }

    #[test]
    fn convert_i32_min_to_u32_tuple() {
        let p = Point::new(i32::min_value(), i32::min_value());

        let tuple: Result<(u32, u32), _> = p.try_into();
        let array: Result<[u32; 2], _> = p.try_into();

        assert!(tuple.is_err());
        assert!(array.is_err());
    }

    #[test]
    fn points_can_be_added() {
        let mut left = Point::new(10, 20);
        let right = Point::new(30, 40);

        assert_eq!(left + right, Point::new(40, 60));

        left += right;
        assert_eq!(left, Point::new(40, 60));
    }

    #[test]
    fn point_and_size_can_be_added() {
        let mut left = Point::new(11, 21);
        let right = Size::new(30, 40);

        assert_eq!(left + right, Point::new(41, 61));

        left += right;
        assert_eq!(left, Point::new(41, 61));
    }

    #[test]
    fn points_can_be_subtracted() {
        let mut left = Point::new(30, 50);
        let right = Point::new(10, 20);

        assert_eq!(left - right, Point::new(20, 30));

        left -= right;
        assert_eq!(left, Point::new(20, 30));
    }

    #[test]
    fn point_and_size_can_be_subtracted() {
        let mut left = Point::new(30, 40);
        let right = Size::new(11, 22);

        assert_eq!(left - right, Point::new(19, 18));

        left -= right;
        assert_eq!(left, Point::new(19, 18));
    }

    #[test]
    fn points_can_be_negative_after_subtraction() {
        let left = Point::new(10, 20);
        let right = Point::new(30, 50);

        assert_eq!(left - right, Point::new(-20, -30));

        let left = Point::new(10, 20);
        let right = Size::new(31, 42);

        assert_eq!(left - right, Point::new(-21, -22));
    }

    #[test]
    fn points_can_be_multiplied_by_scalar() {
        let p = Point::new(1, 2);
        assert_eq!(p * 3, Point::new(3, 6));

        let mut p = Point::new(3, 4);
        p *= -5;
        assert_eq!(p, Point::new(-15, -20));
    }

    #[test]
    fn points_can_be_divided_by_scalar() {
        let p = Point::new(10, 20);
        assert_eq!(p / 2, Point::new(5, 10));

        let mut p = Point::new(-10, 10);
        p /= -5;
        assert_eq!(p, Point::new(2, -2));
    }

    #[test]
    #[should_panic(expected = "width is too large")]
    #[cfg(debug_assertions)]
    fn too_large_width_can_not_be_added() {
        let p = Point::zero();
        let _ = p + Size::new(u32::max_value(), 0);
    }

    #[test]
    #[should_panic(expected = "width is too large")]
    #[cfg(debug_assertions)]
    fn too_large_width_can_not_be_add_assigned() {
        let mut p = Point::zero();
        p += Size::new(u32::max_value(), 0);
    }

    #[test]
    #[should_panic(expected = "height is too large")]
    #[cfg(debug_assertions)]
    fn too_large_height_can_not_be_added() {
        let p = Point::zero();
        let _ = p + Size::new(0, 0x80000000);
    }

    #[test]
    #[should_panic(expected = "height is too large")]
    #[cfg(debug_assertions)]
    fn too_large_height_can_not_be_add_assigned() {
        let mut p = Point::zero();
        p += Size::new(0, 0x80000000);
    }

    #[test]
    #[should_panic(expected = "width is too large")]
    #[cfg(debug_assertions)]
    fn too_large_width_can_not_be_subtracted() {
        let p = Point::zero();
        let _ = p - Size::new(u32::max_value(), 0);
    }

    #[test]
    #[should_panic(expected = "width is too large")]
    #[cfg(debug_assertions)]
    fn too_large_width_can_not_be_sub_assigned() {
        let mut p = Point::zero();
        p -= Size::new(u32::max_value(), 0);
    }

    #[test]
    #[should_panic(expected = "height is too large")]
    #[cfg(debug_assertions)]
    fn too_large_height_can_not_be_subtracted() {
        let p = Point::zero();
        let _ = p - Size::new(0, 0x80000000);
    }

    #[test]
    #[should_panic(expected = "height is too large")]
    #[cfg(debug_assertions)]
    fn too_large_height_can_not_be_sub_assigned() {
        let mut p = Point::zero();
        p -= Size::new(0, 0x80000000);
    }

    #[test]
    fn from_tuple() {
        assert_eq!(Point::from((20i32, 30i32)), Point::new(20, 30));
        assert_eq!(Point::from((20i32, 30i32)), Point::new(20, 30));
    }

    #[test]
    fn from_array() {
        assert_eq!(Point::from([20i32, 30i32]), Point::new(20, 30));
        assert_eq!(Point::from([20i32, 30i32]), Point::new(20, 30));
    }

    #[test]
    fn from_array_ref() {
        assert_eq!(Point::from(&[20i32, 30i32]), Point::new(20, 30));
        assert_eq!(Point::from(&[20i32, 30i32]), Point::new(20, 30));
    }

    #[test]
    fn neg() {
        assert_eq!(-Point::new(10, 20), Point::new(-10, -20));
        assert_eq!(-Point::new(-40, -50), Point::new(40, 50));
    }

    #[test]
    fn index() {
        let point = Point::new(12, -34);

        assert_eq!(point.x, point[0]);
        assert_eq!(point.y, point[1]);
    }

    #[test]
    #[should_panic]
    fn index_out_of_bounds() {
        let point = Point::new(1, 2);
        let _ = point[2];
    }

    #[test]
    #[cfg(feature = "nalgebra_support")]
    fn nalgebra_support() {
        let left = nalgebra::Vector2::new(30, 40);
        let right = nalgebra::Vector2::new(10, 20);

        assert_eq!(Point::from(left - right), Point::new(20, 20));
    }

    #[test]
    #[cfg(feature = "nalgebra_support")]
    fn convert_ref() {
        let left = nalgebra::Vector2::new(30, 40);
        let right = nalgebra::Vector2::new(10, 20);

        let c = left - right;

        assert_eq!(Point::from(&c), Point::new(20, 20));
    }

    #[test]
    fn component_min_max() {
        let a = Point::new(20, 30);
        let b = Point::new(15, 50);

        assert_eq!(a.component_min(b), Point::new(15, 30));
        assert_eq!(a.component_max(b), Point::new(20, 50));
    }

    #[test]
    fn display() {
        let mut buffer = arrayvec::ArrayString::<32>::new();
        write!(buffer, "{}", Point::new(123, -456)).unwrap();

        assert_eq!(&buffer, "123, -456");
    }
}