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
/*
 * Copyright (C) 2017, Isaac Woods.
 * See LICENCE.md
 */

use std::ops;

#[derive(Clone,Copy)]
pub struct Vec3
{
    x : f32,
    y : f32,
    z : f32,
}

impl Vec3
{
    pub fn new(x : f32, y : f32, z : f32) -> Vec3
    {
        Vec3
        {
            x : x,
            y : y,
            z : z,
        }
    }
}

impl ops::Add<Vec3> for Vec3
{
    type Output = Vec3;

    fn add(self, rhs : Vec3) -> Vec3
    {
        Vec3
        {
            x : self.x + rhs.x,
            y : self.y + rhs.y,
            z : self.z + rhs.z,
        }
    }
}

impl ops::Sub<Vec3> for Vec3
{
    type Output = Vec3;

    fn sub(self, rhs : Vec3) -> Vec3
    {
        Vec3
        {
            x : self.x - rhs.x,
            y : self.y - rhs.y,
            z : self.z - rhs.z,
        }
    }
}

impl ops::Mul<Vec3> for Vec3
{
    type Output = Vec3;

    fn mul(self, rhs : Vec3) -> Vec3
    {
        Vec3
        {
            x : self.x * rhs.x,
            y : self.y * rhs.y,
            z : self.z * rhs.z,
        }
    }
}

impl ops::Div<Vec3> for Vec3
{
    type Output = Vec3;

    fn div(self, rhs : Vec3) -> Vec3
    {
        Vec3
        {
            x : self.x / rhs.x,
            y : self.y / rhs.y,
            z : self.z / rhs.z,
        }
    }
}

impl ops::Neg for Vec3
{
    type Output = Vec3;

    fn neg(self) -> Vec3
    {
        Vec3
        {
            x : -self.x,
            y : -self.y,
            z : -self.z,
        }
    }
}