use std::cmp::Ordering;
use std::cmp::Ordering::Less;
use std::ops::Sub;
use std::time::Instant;

use rand::prelude::*;

#[derive(Clone, PartialEq, Debug)]
struct Point {
    pub coords: Vec<f32>,
}

impl<'a, 'b> Sub<&'b Point> for &'a Point {
    type Output = Point;

    fn sub(self, rhs: &Point) -> Point {
        assert_eq!(self.coords.len(), rhs.coords.len());
        Point {
            coords: self
                .coords
                .iter()
                .zip(rhs.coords.iter())
                .map(|(&x, &y)| x - y)
                .collect(),
        }
    }
}

impl Point {
    fn norm_sq(&self) -> f32 {
        self.coords.iter().map(|n| n * n).sum()
    }
}

struct KDTreeNode {
    point: Point,
    dim: usize,