/* * All or portions of this file Copyright (c) Amazon.com, Inc. or its affiliates or * its licensors. * * For complete copyright and license terms please see the LICENSE at the root of this * distribution (the "License"). All use of this software is governed by the License, * or, if provided, by the license below or the license accompanying this file. Do not * remove or modify any license notices. This file is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * */ // Original file Copyright Crytek GMBH or its affiliates, used under license. #ifndef CRYINCLUDE_CRYAISYSTEM_NAVIGATION_MNM_FIXEDVEC2_H #define CRYINCLUDE_CRYAISYSTEM_NAVIGATION_MNM_FIXEDVEC2_H #pragma once #include #include "FixedVec3.h" namespace MNM { template struct FixedVec2 { typedef fixed_t value_type; value_type x, y; inline FixedVec2() { } inline FixedVec2(const value_type& _x) : x(_x) , y(_x) { } template inline FixedVec2(const FixedVec2& _x) : x(value_type(_x.x)) , y(value_type(_x.y)) { } template inline explicit FixedVec2(const FixedVec3& _x) : x(value_type(_x.x)) , y(value_type(_x.y)) { } inline FixedVec2(const value_type& _x, const value_type& _y) : x(_x) , y(_y) { } inline const value_type& operator[](size_t i) const { assert(i < 2); return ((value_type*)&x)[i]; } inline value_type& operator[](size_t i) { assert(i < 2); return ((value_type*)&x)[i]; } template inline FixedVec2 operator+(const FixedVec2& other) const { return FixedVec2(x + other.x, y + other.y); } template inline FixedVec2 operator-(const FixedVec2& other) const { return FixedVec2(x - other.x, y - other.y); } template inline FixedVec2& operator+=(const FixedVec2& other) { x += other.x; y += other.y; return *this; } template inline FixedVec2& operator-=(const FixedVec2& other) { x -= other.x; y -= other.y; return *this; } template inline FixedVec2 operator/(const FixedVec2& other) const { return FixedVec2(x / other.x, y / other.y); } template inline FixedVec2 operator*(const FixedVec2& other) const { return FixedVec2(x * other.x, y * other.y); } template inline FixedVec2 operator/(const fixed_t& value) const { return FixedVec2(x / value, y / value); } template inline FixedVec2 operator*(const fixed_t& value) const { return FixedVec2(x * value, y * value); } template inline bool operator==(const FixedVec2& other) const { return (x == other.x) && (y == other.y); } template inline bool operator!=(const FixedVec2& other) const { return (x != other.x) || (y != other.y); } inline value_type dot(const FixedVec2& other) const { return x * other.x + y * other.y; } inline value_type cross(const FixedVec2& other) const { return x * other.y - y * other.x; } inline value_type len() const { return sqrtf(lenSq()); } template inline fixed_t len() const { return sqrtf(lenSq()); } inline value_type lenSq() const { return x * x + y * y; } template inline fixed_t lenSq() const { return fixed_t(x) * fixed_t(x) + fixed_t(y) * fixed_t(y); } inline FixedVec2 abs() { return FixedVec2(fabsf(x), fabsf(y)); } inline static FixedVec2 minimize(const FixedVec2& a, const FixedVec2& b) { return FixedVec2(std::min(a.x, b.x), std::min(a.y, b.y)); } inline static FixedVec2 minimize(const FixedVec2& a, const FixedVec2& b, const FixedVec2& c) { return FixedVec2(std::min(std::min(a.x, b.x), c.x), std::min(std::min(a.y, b.y), c.y)); } inline static FixedVec2 maximize(const FixedVec2& a, const FixedVec2& b) { return FixedVec2(std::max(a.x, b.x), std::max(a.y, b.y)); } inline static FixedVec2 maximize(const FixedVec2& a, const FixedVec2& b, const FixedVec2& c) { return FixedVec2(std::max(std::max(a.x, b.x), c.x), std::max(std::max(a.y, b.y), c.y)); } inline Vec3 GetVec2() const { return Vec3(x.as_float(), y.as_float()); } }; } #endif // CRYINCLUDE_CRYAISYSTEM_NAVIGATION_MNM_FIXEDVEC2_H