#ifndef Magnum_Math_Vector2_h #define Magnum_Math_Vector2_h /* Copyright © 2010, 2011, 2012 Vladimír Vondruš This file is part of Magnum. Magnum is free software: you can redistribute it and/or modify it under the terms of the GNU Lesser General Public License version 2 only, as published by the Free Software Foundation. Magnum is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License version 2 for more details. */ /** @file * @brief Class Magnum::Math::Vector2 */ #include "Vector.h" namespace Magnum { namespace Math { /** @brief Two-component vector */ template class Vector2: public Vector { public: /** @copydoc Vector::from(T*) */ inline constexpr static Vector2& from(T* data) { return *reinterpret_cast*>(data); } /** @copydoc Vector::from(const T*) */ inline constexpr static const Vector2& from(const T* data) { return *reinterpret_cast*>(data); } /** @copydoc Vector::Vector(T) */ inline constexpr explicit Vector2(T value = T()): Vector(value, value) {} /** @copydoc Vector::Vector(const Vector&) */ inline constexpr Vector2(const Vector& other): Vector(other) {} /** * @brief Constructor * @param x X value * @param y Y value */ inline constexpr Vector2(T x, T y): Vector(x, y) {} inline constexpr T x() const { return Vector::at(0); } /**< @brief X component */ inline constexpr T y() const { return Vector::at(1); } /**< @brief Y component */ inline void setX(T value) { this->set(0, value); } /**< @brief Set X component */ inline void setY(T value) { this->set(1, value); } /**< @brief Set Y component */ /** @copydoc Vector::operator=() */ inline Vector2& operator=(const Vector& other) { return Vector::operator=(other); } /** @copydoc Vector::operator*(const Vector&) const */ inline T operator*(const Vector& other) const { return Vector::operator*(other); } /** @copydoc Vector::operator*(T) const */ inline Vector2 operator*(T number) const { return Vector::operator*(number); } /** @copydoc Vector::operator*=() */ inline Vector2& operator*=(T number) { Vector::operator*=(number); return *this; } /** @copydoc Vector::operator/() */ inline Vector2 operator/(T number) const { return Vector::operator/(number); } /** @copydoc Vector::operator/=() */ inline Vector2& operator/=(T number) { Vector::operator/=(number); return *this; } /** @copydoc Vector::operator+() */ inline Vector2 operator+(const Vector& other) const { return Vector::operator+(other); } /** @copydoc Vector::operator+=() */ inline Vector2& operator+=(const Vector& other) { Vector::operator+=(other); return *this; } /** @copydoc Vector::operator-(const Vector&) const */ inline Vector2 operator-(const Vector& other) const { return Vector::operator-(other); } /** @copydoc Vector::operator-=() */ inline Vector2& operator-=(const Vector& other) { Vector::operator-=(other); return *this; } /** @copydoc Vector::operator-() */ inline Vector2 operator-() const { return Vector::operator-(); } /** @copydoc Vector::normalized() */ inline Vector2 normalized() const { return Vector::normalized(); } }; #ifndef DOXYGEN_GENERATING_OUTPUT template Corrade::Utility::Debug operator<<(Corrade::Utility::Debug debug, const Magnum::Math::Vector2& value) { return debug << static_cast&>(value); } #endif }} #endif