// Copyright 2013 The OMath Developers. For a full listing of the authors, // refer to the AUTHORS file at the top-level directory of this distribution. // // Licensed under the Apache License, Version 2.0 (the "License"); // you may not use this file except in compliance with the License. // You may obtain a copy of the License at // // http://www.apache.org/licenses/LICENSE-2.0 // // Unless required by applicable law or agreed to in writing, software // distributed under the License is distributed on an "AS IS" BASIS, // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. // See the License for the specific language governing permissions and // limitations under the License. //! Points are fixed positions in affine space with no length or direction. This //! disinguishes them from vectors, which have a length and direction, but do //! not have a fixed position. use traits::alg::*; use traits::util::*; use types::vector::{Vec2, Vec3}; #[deriving(Eq, Zero, Clone)] struct Point2 { x: S, y: S } #[deriving(Eq, Zero, Clone)] struct Point3 { x: S, y: S, z: S } impl Point2 { #[inline] pub fn new(x: S, y: S) -> Point2 { Point2 { x: x, y: y } } } impl Point3 { #[inline] pub fn new(x: S, y: S, z: S) -> Point3 { Point3 { x: x, y: y, z: z } } } // Operator impls impl Mul> for Point2 { #[inline(always)] fn mul(&self, s: &S) -> Point2 { self.map(|x| x.mul(s)) } } impl Mul> for Point3 { #[inline(always)] fn mul(&self, s: &S) -> Point3 { self.map(|x| x.mul(s)) } } impl Div> for Point2 { #[inline(always)] fn div(&self, s: &S) -> Point2 { self.map(|x| x.div(s)) } } impl Div> for Point3 { #[inline(always)] fn div(&self, s: &S) -> Point3 { self.map(|x| x.div(s)) } } impl Rem> for Point2 { #[inline(always)] fn rem(&self, s: &S) -> Point2 { self.map(|x| x.rem(s)) } } impl Rem> for Point3 { #[inline(always)] fn rem(&self, s: &S) -> Point3 { self.map(|x| x.rem(s)) } } impl Add, Point2> for Point2 { #[inline(always)] fn add(&self, other: &Vec2) -> Point2 { self.bimap(other, |a, b| a.add(b)) } } impl Add, Point3> for Point3 { #[inline(always)] fn add(&self, other: &Vec3) -> Point3 { self.bimap(other, |a, b| a.add(b)) } } impl Sub, Vec2> for Point2 { #[inline(always)] fn sub(&self, other: &Point2) -> Vec2 { self.bimap(other, |a, b| a.sub(b)) } } impl Sub, Vec3> for Point3 { #[inline(always)] fn sub(&self, other: &Point3) -> Vec3 { self.bimap(other, |a, b| a.sub(b)) } } // Trait impls impl_indexable!(Point2, [T, ..2]) impl_indexable!(Point3, [T, ..3]) impl Swappable for Point2; impl Swappable for Point3; impl Coordinate for Point2; impl Coordinate for Point3; impl ScalarMul for Point2; impl ScalarMul for Point3; impl AffineSpace> for Point2; impl AffineSpace> for Point3;