Skip to content

Commit

Permalink
feat(points/2d): move border stuff to a separate module
Browse files Browse the repository at this point in the history
- leave a reexport for backwards-compatibility
  - mark it as deprecated
    - doesn't actually work, see^[1]

^[1]: rust-lang/rust#84584
  • Loading branch information
ada4a committed Oct 23, 2024
1 parent 0a7316c commit 88c6c6e
Show file tree
Hide file tree
Showing 3 changed files with 30 additions and 25 deletions.
27 changes: 27 additions & 0 deletions src/border.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
use crate::points::Point2D;
use itertools::Itertools;

#[derive(Debug)]
pub struct Border2D<T, U = T> {
pub left: T,
pub right: T,
pub top: U,
pub down: U,
}

pub fn min_enclosing_rectangle<'a, I, T, U>(positions1: I, positions2: I) -> Border2D<T, U>
where
T: Copy + PartialOrd + 'a,
U: Copy + PartialOrd + 'a,
I: Iterator<Item = &'a Point2D<T, U>>,
{
let (left, right) = positions1.map(Point2D::x).minmax().into_option().unwrap();
let (top, down) = positions2.map(Point2D::y).minmax().into_option().unwrap();

Border2D {
left,
right,
top,
down,
}
}
1 change: 1 addition & 0 deletions src/lib.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
#[macro_use]
pub mod parse;
pub mod border;
pub mod direction;
pub mod map;
pub mod points;
27 changes: 2 additions & 25 deletions src/points/two_d.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
use crate::points::{ManhattanDistance, Neighbours};
use core::{fmt::Debug, ops::Add};
use itertools::Itertools;

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

impl_neighbours_2d_unsigned!(u32, usize);

#[derive(Debug)]
pub struct Border2D<T, U = T> {
pub left: T,
pub right: T,
pub top: U,
pub down: U,
}

pub fn min_enclosing_rectangle<'a, I, T, U>(positions1: I, positions2: I) -> Border2D<T, U>
where
T: Copy + PartialOrd + 'a,
U: Copy + PartialOrd + 'a,
I: Iterator<Item = &'a Point2D<T, U>>,
{
let (left, right) = positions1.map(Point2D::x).minmax().into_option().unwrap();
let (top, down) = positions2.map(Point2D::y).minmax().into_option().unwrap();

Border2D {
left,
right,
top,
down,
}
}
#[deprecated(since = "0.5.0", note = "moved to `crate::border`")]
pub use crate::border::{min_enclosing_rectangle, Border2D};

0 comments on commit 88c6c6e

Please sign in to comment.