use geo::{BoundingRect, EuclideanDistance};
use geo::{Line, Point};
use rstar::RTreeObject;
use rstar::AABB;
#[derive(Debug, Clone)]
pub struct TarLine(pub Line<f64>, pub f64);
impl TarLine {
pub fn envelope(&self) -> AABB<Point> {
let padding_dist = self.1;
let bb = self.0.bounding_rect();
let (ll_x, ll_y) = bb.min().x_y();
let (ur_x, ur_y) = bb.max().x_y();
let ll = Point::new(ll_x - padding_dist, ll_y - padding_dist);
let ur = Point::new(ur_x + padding_dist, ur_y + padding_dist);
AABB::from_corners(ll, ur)
}
pub fn distance(&self, other: &Line) -> f64 {
self.0.euclidean_distance(other)
}
}
impl RTreeObject for TarLine {
type Envelope = AABB<Point>;
fn envelope(&self) -> Self::Envelope {
self.envelope()
}
}