Skip to content

Commit

Permalink
Added functions to get boundary data
Browse files Browse the repository at this point in the history
Before this it was not possible to get information about the boundary of
a quad tree.
  • Loading branch information
Julian-Alberts committed Apr 16, 2024
1 parent 4f45e0f commit c68a65c
Showing 1 changed file with 54 additions and 0 deletions.
54 changes: 54 additions & 0 deletions src/boundary.rs
Original file line number Diff line number Diff line change
Expand Up @@ -70,6 +70,36 @@ where
}
}

// Returns the left border (the smaller x value given at creation)
pub fn left_border(&self) -> C {

Check warning on line 74 in src/boundary.rs

View workflow job for this annotation

GitHub Actions / Run tests

missing documentation for a method
self.p1.x
}

// Returns the right border (the bigger x value given at creation)
pub fn right_border(&self) -> C {

Check warning on line 79 in src/boundary.rs

View workflow job for this annotation

GitHub Actions / Run tests

missing documentation for a method
self.p2.x
}

// Returns the top border (the smaller y value given at creation)
pub fn top_border(&self) -> C {

Check warning on line 84 in src/boundary.rs

View workflow job for this annotation

GitHub Actions / Run tests

missing documentation for a method
self.p1.y
}

// Returns the bottom border (the bigger y value given at creation)
pub fn bottom_border(&self) -> C {

Check warning on line 89 in src/boundary.rs

View workflow job for this annotation

GitHub Actions / Run tests

missing documentation for a method
self.p2.y
}

// Returns the width
pub fn width(&self) -> C {

Check warning on line 94 in src/boundary.rs

View workflow job for this annotation

GitHub Actions / Run tests

missing documentation for a method
self.right_border() - self.left_border()
}

// Returns the height
pub fn height(&self) -> C {

Check warning on line 99 in src/boundary.rs

View workflow job for this annotation

GitHub Actions / Run tests

missing documentation for a method
self.top_border() - self.bottom_border()
}

pub(crate) fn split(&self) -> [Boundary<C>; 4] {
let dx = self.p2.x - self.p1.x;
let dy = self.p2.y - self.p1.y;
Expand Down Expand Up @@ -236,4 +266,28 @@ mod tests {
}
);
}

#[test_case((1,2), (10,20) => 1;"0")]
#[test_case((-1,-2), (10,20) => -1;"1")]
fn left_border(p1: impl Into<Point<i32>>, p2: impl Into<Point<i32>>) -> i32 {
Boundary::between_points(p1, p2).left_border()
}

#[test_case((1,2), (10,20) => 10;"0")]
#[test_case((-1,-2), (20,20) => 20;"1")]
fn right_border(p1: impl Into<Point<i32>>, p2: impl Into<Point<i32>>) -> i32 {
Boundary::between_points(p1, p2).right_border()
}

#[test_case((1,2), (10,20) => 2;"0")]
#[test_case((-1,-2), (10,20) => -2;"1")]
fn top_border(p1: impl Into<Point<i32>>, p2: impl Into<Point<i32>>) -> i32 {
Boundary::between_points(p1, p2).top_border()
}

#[test_case((1,2), (20,10) => 10;"0")]
#[test_case((-1,-2), (10,20) => 20;"1")]
fn bottom_border(p1: impl Into<Point<i32>>, p2: impl Into<Point<i32>>) -> i32 {
Boundary::between_points(p1, p2).bottom_border()
}
}

0 comments on commit c68a65c

Please sign in to comment.