summaryrefslogtreecommitdiff
path: root/Userland/Demos
diff options
context:
space:
mode:
authorHendiadyoin1 <leon2002.la@gmail.com>2021-07-17 18:29:28 +0200
committerAli Mohammad Pur <Ali.mpfard@gmail.com>2021-07-19 16:34:21 +0430
commited46d52252375be732841d980f9eec02ea7691f5 (patch)
tree60c8ff281cb3a07e2a33629184c6c0aec2a7f528 /Userland/Demos
parentc5f6ba6e71ee7ebce578828fd35ba119e9a6b41a (diff)
downloadserenity-ed46d52252375be732841d980f9eec02ea7691f5.zip
Everywhere: Use AK/Math.h if applicable
AK's version should see better inlining behaviors, than the LibM one. We avoid mixed usage for now though. Also clean up some stale math includes and improper floatingpoint usage.
Diffstat (limited to 'Userland/Demos')
-rw-r--r--Userland/Demos/CatDog/CatDog.h1
-rw-r--r--Userland/Demos/Eyes/EyesWidget.cpp8
-rw-r--r--Userland/Demos/Mouse/main.cpp19
3 files changed, 13 insertions, 15 deletions
diff --git a/Userland/Demos/CatDog/CatDog.h b/Userland/Demos/CatDog/CatDog.h
index 6d9ba5ea3a..6c730df0a8 100644
--- a/Userland/Demos/CatDog/CatDog.h
+++ b/Userland/Demos/CatDog/CatDog.h
@@ -7,7 +7,6 @@
#include <LibCore/ElapsedTimer.h>
#include <LibGUI/Menu.h>
#include <LibGUI/Widget.h>
-#include <math.h>
#include <unistd.h>
#pragma once
diff --git a/Userland/Demos/Eyes/EyesWidget.cpp b/Userland/Demos/Eyes/EyesWidget.cpp
index 87eb099787..64c1f1e7f1 100644
--- a/Userland/Demos/Eyes/EyesWidget.cpp
+++ b/Userland/Demos/Eyes/EyesWidget.cpp
@@ -5,12 +5,12 @@
*/
#include "EyesWidget.h"
+#include <AK/Math.h>
#include <AK/StdLibExtraDetails.h>
#include <LibGUI/Painter.h>
#include <LibGUI/Window.h>
#include <LibGUI/WindowServerConnection.h>
#include <LibGfx/Palette.h>
-#include <math.h>
EyesWidget::~EyesWidget()
{
@@ -79,7 +79,7 @@ Gfx::IntPoint EyesWidget::pupil_center(Gfx::IntRect& eyeball_bounds) const
auto mouse_vector = m_mouse_position - eyeball_bounds.center();
double dx = mouse_vector.x();
double dy = mouse_vector.y();
- double mouse_distance = sqrt(dx * dx + dy * dy);
+ double mouse_distance = AK::hypot(dx, dy);
if (mouse_distance == 0.0)
return eyeball_bounds.center();
@@ -93,14 +93,14 @@ Gfx::IntPoint EyesWidget::pupil_center(Gfx::IntRect& eyeball_bounds) const
if (dx != 0 && AK::abs(dx) >= AK::abs(dy)) {
double slope = dy / dx;
double slope_squared = slope * slope;
- max_distance_along_this_direction = 0.25 * sqrt(
+ max_distance_along_this_direction = 0.25 * AK::sqrt(
(slope_squared + 1) /
(1 / width_squared + slope_squared / height_squared)
);
} else if (dy != 0 && AK::abs(dy) >= AK::abs(dx)) {
double slope = dx / dy;
double slope_squared = slope * slope;
- max_distance_along_this_direction = 0.25 * sqrt(
+ max_distance_along_this_direction = 0.25 * AK::sqrt(
(slope_squared + 1) /
(slope_squared / width_squared + 1 / height_squared)
);
diff --git a/Userland/Demos/Mouse/main.cpp b/Userland/Demos/Mouse/main.cpp
index ec3a8c8216..7e1cbf30e5 100644
--- a/Userland/Demos/Mouse/main.cpp
+++ b/Userland/Demos/Mouse/main.cpp
@@ -4,6 +4,7 @@
* SPDX-License-Identifier: BSD-2-Clause
*/
+#include <AK/Math.h>
#include <LibGUI/Action.h>
#include <LibGUI/Application.h>
#include <LibGUI/BoxLayout.h>
@@ -18,8 +19,6 @@
#include <LibGfx/Path.h>
#include <unistd.h>
-#include <math.h>
-
class MainFrame final : public GUI::Frame {
C_OBJECT(MainFrame);
@@ -100,17 +99,17 @@ public:
Gfx::IntPoint p3;
Gfx::IntPoint p4;
- p1.set_x(radius * cos(M_PI * m_wheel_delta_acc / 18) + off_x);
- p1.set_y(radius * sin(M_PI * m_wheel_delta_acc / 18) + off_y);
+ p1.set_x(radius * AK::cos(AK::Pi<double> * m_wheel_delta_acc / 18.) + off_x);
+ p1.set_y(radius * AK::sin(AK::Pi<double> * m_wheel_delta_acc / 18.) + off_y);
- p2.set_x(radius * cos(M_PI * (m_wheel_delta_acc + 18) / 18) + off_x);
- p2.set_y(radius * sin(M_PI * (m_wheel_delta_acc + 18) / 18) + off_y);
+ p2.set_x(radius * AK::cos(AK::Pi<double> * (m_wheel_delta_acc + 18) / 18.) + off_x);
+ p2.set_y(radius * AK::sin(AK::Pi<double> * (m_wheel_delta_acc + 18) / 18.) + off_y);
- p3.set_x(radius * cos(M_PI * (m_wheel_delta_acc + 9) / 18) + off_x);
- p3.set_y(radius * sin(M_PI * (m_wheel_delta_acc + 9) / 18) + off_y);
+ p3.set_x(radius * AK::cos(AK::Pi<double> * (m_wheel_delta_acc + 9) / 18.) + off_x);
+ p3.set_y(radius * AK::sin(AK::Pi<double> * (m_wheel_delta_acc + 9) / 18.) + off_y);
- p4.set_x(radius * cos(M_PI * (m_wheel_delta_acc + 27) / 18) + off_x);
- p4.set_y(radius * sin(M_PI * (m_wheel_delta_acc + 27) / 18) + off_y);
+ p4.set_x(radius * AK::cos(AK::Pi<double> * (m_wheel_delta_acc + 27) / 18.) + off_x);
+ p4.set_y(radius * AK::sin(AK::Pi<double> * (m_wheel_delta_acc + 27) / 18.) + off_y);
painter.draw_line(p1, p2, Color::Red, 2);
painter.draw_line(p3, p4, Color::Red, 2);