From 70151279f69dddccdab55a58ba6726e4137840e4 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Tomasz=20Kapu=C5=9Bci=C5=84ski?= Date: Fri, 24 Dec 2021 20:44:54 +0100 Subject: [PATCH] Removed Math::Point and minor refactor --- src/CMakeLists.txt | 1 - src/app/input.h | 1 - src/graphics/engine/cloud.h | 1 - src/graphics/engine/engine.h | 1 - src/math/all.h | 1 - src/math/geometry.h | 5 +-- src/math/point.h | 79 ------------------------------------ 7 files changed, 2 insertions(+), 87 deletions(-) delete mode 100644 src/math/point.h diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt index 60a40249..a96ffb36 100644 --- a/src/CMakeLists.txt +++ b/src/CMakeLists.txt @@ -180,7 +180,6 @@ add_library(colobotbase STATIC math/half.cpp math/half.h math/matrix.h - math/point.h math/sphere.h math/vector.h object/auto/auto.cpp diff --git a/src/app/input.h b/src/app/input.h index cc939520..6fda29b8 100644 --- a/src/app/input.h +++ b/src/app/input.h @@ -27,7 +27,6 @@ #include "common/key.h" #include "common/singleton.h" -#include "math/point.h" #include "math/vector.h" #include diff --git a/src/graphics/engine/cloud.h b/src/graphics/engine/cloud.h index 3937a513..f3b56d1a 100644 --- a/src/graphics/engine/cloud.h +++ b/src/graphics/engine/cloud.h @@ -26,7 +26,6 @@ #include "graphics/core/color.h" -#include "math/point.h" #include "math/vector.h" #include diff --git a/src/graphics/engine/engine.h b/src/graphics/engine/engine.h index f5dc5589..7b70e7d8 100644 --- a/src/graphics/engine/engine.h +++ b/src/graphics/engine/engine.h @@ -33,7 +33,6 @@ #include "graphics/core/vertex.h" #include "math/matrix.h" -#include "math/point.h" #include "math/sphere.h" #include "math/vector.h" diff --git a/src/math/all.h b/src/math/all.h index 1a4eed63..d4883c0b 100644 --- a/src/math/all.h +++ b/src/math/all.h @@ -30,6 +30,5 @@ #include "math/geometry.h" #include "math/half.h" #include "math/matrix.h" -#include "math/point.h" #include "math/vector.h" diff --git a/src/math/geometry.h b/src/math/geometry.h index f2b90646..987cba61 100644 --- a/src/math/geometry.h +++ b/src/math/geometry.h @@ -28,7 +28,6 @@ #include "math/const.h" #include "math/func.h" #include "math/matrix.h" -#include "math/point.h" #include "math/vector.h" #include @@ -239,10 +238,10 @@ inline float RotateAngle(float x, float y) */ inline float RotateAngle(const glm::vec2¢er, const glm::vec2&p1, const glm::vec2&p2) { - if (PointsEqual(p1, center)) + if (glm::all(glm::epsilonEqual(p1, center, TOLERANCE))) return 0; - if (PointsEqual(p2, center)) + if (glm::all(glm::epsilonEqual(p2, center, TOLERANCE))) return 0; float a1 = asinf((p1.y - center.y) / glm::distance(p1, center)); diff --git a/src/math/point.h b/src/math/point.h deleted file mode 100644 index 4791ac3a..00000000 --- a/src/math/point.h +++ /dev/null @@ -1,79 +0,0 @@ -/* - * This file is part of the Colobot: Gold Edition source code - * Copyright (C) 2001-2021, Daniel Roux, EPSITEC SA & TerranovaTeam - * http://epsitec.ch; http://colobot.info; http://github.com/colobot - * - * This program is free software: you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation, either version 3 of the License, or - * (at your option) any later version. - * - * This program 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 General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program. If not, see http://gnu.org/licenses - */ - -/** - * \file math/point.h - * \brief Point struct and related functions - */ - -#pragma once - - -#include "math/const.h" -#include "math/func.h" - - -#include -#include -#include - - -// Math module namespace -namespace Math -{ - - -// Temporary type alias -using Point = glm::vec2; - - -//! Returns a string "[x, y]" -inline std::string ToString(const Point& point) -{ - std::stringstream s; - s.precision(3); - s << "[" << point.x << ", " << point.y << "]"; - return s.str(); -} - -//! Checks if two vectors are equal within given \a tolerance -inline bool PointsEqual(const Point &a, const Point &b, float tolerance = TOLERANCE) -{ - return IsEqual(a.x, b.x, tolerance) && IsEqual(a.y, b.y, tolerance); -} - -//! Permutes two points -inline void Swap(Point &a, Point &b) -{ - Point c; - - c = a; - a = b; - b = c; -} - -//! Returns the distance between two points -inline float Distance(const Point &a, const Point &b) -{ - return sqrtf((a.x-b.x)*(a.x-b.x) + (a.y-b.y)*(a.y-b.y)); -} - - -} // namespace Math -