Skip to content

Commit 88c6c6e

Browse files
committed
feat(points/2d): move border stuff to a separate module
- leave a reexport for backwards-compatibility - mark it as deprecated - doesn't actually work, see^[1] ^[1]: rust-lang/rust#84584
1 parent 0a7316c commit 88c6c6e

File tree

3 files changed

+30
-25
lines changed

3 files changed

+30
-25
lines changed

src/border.rs

+27
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
use crate::points::Point2D;
2+
use itertools::Itertools;
3+
4+
#[derive(Debug)]
5+
pub struct Border2D<T, U = T> {
6+
pub left: T,
7+
pub right: T,
8+
pub top: U,
9+
pub down: U,
10+
}
11+
12+
pub fn min_enclosing_rectangle<'a, I, T, U>(positions1: I, positions2: I) -> Border2D<T, U>
13+
where
14+
T: Copy + PartialOrd + 'a,
15+
U: Copy + PartialOrd + 'a,
16+
I: Iterator<Item = &'a Point2D<T, U>>,
17+
{
18+
let (left, right) = positions1.map(Point2D::x).minmax().into_option().unwrap();
19+
let (top, down) = positions2.map(Point2D::y).minmax().into_option().unwrap();
20+
21+
Border2D {
22+
left,
23+
right,
24+
top,
25+
down,
26+
}
27+
}

src/lib.rs

+1
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
#[macro_use]
22
pub mod parse;
3+
pub mod border;
34
pub mod direction;
45
pub mod map;
56
pub mod points;

src/points/two_d.rs

+2-25
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
11
use crate::points::{ManhattanDistance, Neighbours};
22
use core::{fmt::Debug, ops::Add};
3-
use itertools::Itertools;
43

54
#[derive(PartialEq, Eq, Hash, Clone, Copy, Default)]
65
pub struct Point2D<T, U = T>(pub T, pub U);
@@ -87,27 +86,5 @@ macro_rules! impl_neighbours_2d_unsigned {
8786

8887
impl_neighbours_2d_unsigned!(u32, usize);
8988

90-
#[derive(Debug)]
91-
pub struct Border2D<T, U = T> {
92-
pub left: T,
93-
pub right: T,
94-
pub top: U,
95-
pub down: U,
96-
}
97-
98-
pub fn min_enclosing_rectangle<'a, I, T, U>(positions1: I, positions2: I) -> Border2D<T, U>
99-
where
100-
T: Copy + PartialOrd + 'a,
101-
U: Copy + PartialOrd + 'a,
102-
I: Iterator<Item = &'a Point2D<T, U>>,
103-
{
104-
let (left, right) = positions1.map(Point2D::x).minmax().into_option().unwrap();
105-
let (top, down) = positions2.map(Point2D::y).minmax().into_option().unwrap();
106-
107-
Border2D {
108-
left,
109-
right,
110-
top,
111-
down,
112-
}
113-
}
89+
#[deprecated(since = "0.5.0", note = "moved to `crate::border`")]
90+
pub use crate::border::{min_enclosing_rectangle, Border2D};

0 commit comments

Comments
 (0)