1
  2
  3
  4
  5
  6
  7
  8
  9
 10
 11
 12
 13
 14
 15
 16
 17
 18
 19
 20
 21
 22
 23
 24
 25
 26
 27
 28
 29
 30
 31
 32
 33
 34
 35
 36
 37
 38
 39
 40
 41
 42
 43
 44
 45
 46
 47
 48
 49
 50
 51
 52
 53
 54
 55
 56
 57
 58
 59
 60
 61
 62
 63
 64
 65
 66
 67
 68
 69
 70
 71
 72
 73
 74
 75
 76
 77
 78
 79
 80
 81
 82
 83
 84
 85
 86
 87
 88
 89
 90
 91
 92
 93
 94
 95
 96
 97
 98
 99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
use curves::*;

use std::f32;
use std::ops::{Mul, Add, Sub};

///
/// A point in a path
/// 
#[derive(Clone, Copy, PartialEq, Debug)]
pub struct PathPoint {
    /// X, Y coordinates of this point
    pub position: (f32, f32)
}

impl PathPoint {
    ///
    /// Creates a new path point
    /// 
    pub fn new(x: f32, y: f32) -> PathPoint {
        PathPoint {
            position: (x, y)
        }
    }

    pub fn x(&self) -> f32 {
        self.position.0
    }

    pub fn y(&self) -> f32 {
        self.position.1
    }
}

impl Add<PathPoint> for PathPoint {
    type Output=PathPoint;

    #[inline]
    fn add(self, rhs: PathPoint) -> PathPoint {
        PathPoint {
            position: (self.position.0 + rhs.position.0, self.position.1 + rhs.position.1)
        }
    }
}

impl Sub<PathPoint> for PathPoint {
    type Output=PathPoint;

    #[inline]
    fn sub(self, rhs: PathPoint) -> PathPoint {
        PathPoint {
            position: (self.position.0 - rhs.position.0, self.position.1 - rhs.position.1)
        }
    }
}

impl Mul<f64> for PathPoint {
    type Output=PathPoint;

    #[inline]
    fn mul(self, rhs: f64) -> PathPoint {
        let rhs = rhs as f32;

        PathPoint {
            position: (self.position.0 * rhs, self.position.1 * rhs)
        }
    }
}

impl Coordinate for PathPoint {
    ///
    /// Creates a new coordinate from the specified set of components
    /// 
    #[inline]
    fn from_components(components: &[f64]) -> Self {
        PathPoint {
            position: (components[0] as f32, components[1] as f32)
        }
    }

    ///
    /// Returns the origin coordinate
    /// 
    #[inline]
    fn origin() -> Self {
        PathPoint {
            position: (0.0,0.0)
        }
    }

    ///
    /// The number of components in this coordinate
    /// 
    fn len() -> usize {
        2
    }

    ///
    /// Retrieves the component at the specified index
    /// 
    #[inline]
    fn get(&self, index: usize) -> f64 {
        match index {
            0 => self.position.0 as f64,
            1 => self.position.1 as f64,

            _ => 0.0
        }
    }

    ///
    /// Returns a point made up of the biggest components of the two points
    /// 
    #[inline]
    fn from_biggest_components(p1: Self, p2: Self) -> Self {
        PathPoint {
            position: (
                f32::max(p1.position.0, p2.position.0),
                f32::max(p1.position.1, p2.position.1)
            )
        }
    }

    ///
    /// Returns a point made up of the smallest components of the two points
    ///
    #[inline]
    fn from_smallest_components(p1: Self, p2: Self) -> Self {
        PathPoint {
            position: (
                f32::min(p1.position.0, p2.position.0),
                f32::min(p1.position.1, p2.position.1)
            )
        }
    }
}