From d63d33e6918b4dba12b77d0055cd732a62ad0dee Mon Sep 17 00:00:00 2001 From: askastitva Date: Fri, 20 Oct 2023 16:02:41 +0530 Subject: [PATCH] Add atan2 to FixedPoint --- copying.md | 1 + libopenage/util/fixed_point.h | 9 +++++++++ libopenage/util/fixed_point_test.cpp | 3 ++- 3 files changed, 12 insertions(+), 1 deletion(-) diff --git a/copying.md b/copying.md index b524367fb0..cd024a0a13 100644 --- a/copying.md +++ b/copying.md @@ -150,6 +150,7 @@ _the openage authors_ are: | Munawar Hafiz | munahaf | munawar dawt hafiz à gmail dawt com | | Md Ashhar | ashhar | mdashhar01 à gmail dawt com | | Fábio Barkoski | fabiobarkoski | fabiobarkoskii à gmail dawt com | +| Astitva Kamble | askastitva | astitvakamble5 à gmail dawt com | If you're a first-time committer, add yourself to the above list. This is not just for legal reasons, but also to keep an overview of all those nicknames. diff --git a/libopenage/util/fixed_point.h b/libopenage/util/fixed_point.h index 196ca17f54..1e27d15082 100644 --- a/libopenage/util/fixed_point.h +++ b/libopenage/util/fixed_point.h @@ -370,6 +370,10 @@ class FixedPoint { constexpr double sqrt() { return std::sqrt(this->to_double()); } + + constexpr double atan2(const FixedPoint &n) { + return std::atan2(this->to_double(), n.to_double()); + } }; @@ -481,6 +485,11 @@ constexpr double sqrt(openage::util::FixedPoint n) { return n.sqrt(); } +template +constexpr double atan2(openage::util::FixedPoint x, openage::util::FixedPoint y) { + return x.atan2(y); +} + template constexpr openage::util::FixedPoint min(openage::util::FixedPoint x, openage::util::FixedPoint y) { return openage::util::FixedPoint::from_raw_value( diff --git a/libopenage/util/fixed_point_test.cpp b/libopenage/util/fixed_point_test.cpp index 569d177e42..e5728f518c 100644 --- a/libopenage/util/fixed_point_test.cpp +++ b/libopenage/util/fixed_point_test.cpp @@ -1,4 +1,4 @@ -// Copyright 2016-2018 the openage authors. See copying.md for legal info. +// Copyright 2016-2023 the openage authors. See copying.md for legal info. #include "fixed_point.h" @@ -58,6 +58,7 @@ void fixed_point() { TESTEQUALS_FLOAT((e * 10).to_double(), 108.3 * 10, 1e-7); TESTEQUALS_FLOAT((e / 10).to_double(), 108.3 / 10, 1e-7); TESTEQUALS_FLOAT(std::sqrt(e), sqrt(108.3), 1e-7); + TESTEQUALS_FLOAT(std::atan2(e, f), atan2(108.3, -12.4), 1e-7); TESTEQUALS_FLOAT(std::abs(-e).to_double(), 108.3, 1e-7); TESTEQUALS_FLOAT(std::hypot(e, f), hypot(108.3, -12.4), 1e-7); TESTEQUALS_FLOAT(std::min(e, f), -12.4, 1e-7);