/* * Copyright (C) 2011 The Android Open Source Project * * 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. */ #ifndef VEC2_H #define VEC2_H #include #include // Implements a class to represent the location of a pixel. template class Vec2{ public: Vec2(T inputX, T inputY) { mX = inputX; mY = inputY; } Vec2() {} inline Vec2 operator+ (const Vec2 ¶m) const { Vec2 temp(mX + param.x(), mY + param.y()); return temp; } inline Vec2 operator- (const Vec2 ¶m) const { Vec2 temp(mX - param.x(), mY - param.y()); return temp; } inline Vec2 operator/ (const int param) const { assert(param != 0); return Vec2(static_cast(mX) / static_cast(param), static_cast(mY) / static_cast(param)); } template float squareDistance(const Vec2 ¶m) const { int difference = 0.f; difference = (static_cast(mX) - static_cast(param.x())) * (static_cast(mX) - static_cast(param.x())) + (static_cast(mY) - static_cast(param.y())) * (static_cast(mY) - static_cast(param.y())); return difference; } inline T x() const { return mX; } inline T y() const { return mY; } inline void set(const T inputX, const T inputY) { mX = inputX; mY = inputY; } private: T mX; T mY; }; typedef Vec2 Vec2i; typedef Vec2 Vec2f; #endif