Math.h
1 /*
2 
3 Copyright (c) 2018, Johnathan Corkery. (jcorkery@umich.edu)
4 All rights reserved.
5 
6 This file is part of the Dynacoe project (https://github.com/jcorks/Dynacoe)
7 Dynacoe was released under the MIT License, as detailed below.
8 
9 
10 
11 Permission is hereby granted, free of charge, to any person obtaining a copy
12 of this software and associated documentation files (the "Software"), to deal
13 in the Software without restriction, including without limitation the rights
14 to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
15 copies of the Software, and to permit persons to whom the Software is furnished
16 to do so, subject to the following conditions:
17 
18 The above copyright notice and this permission notice shall
19 be included in all copies or substantial portions of the Software.
20 
21 THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
22 EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
23 MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
24 IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM,
25 DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE,
26 ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
27 DEALINGS IN THE SOFTWARE.
28 
29 
30 
31 */
32 
33 #ifndef H_DC_UTIL_MATH_INCLUDED
34 #define H_DC_UTIL_MATH_INCLUDED
35 
36 #include <Dynacoe/Util/Vector.h>
37 
38 /* Static class that does basic value manipulation and computation
39  geared towards graphical applications
40 
41  Johnathan Corkery 2015
42 
43  */
44 
45 
46 
47 namespace Dynacoe {
48 
51 class Math {
52  public:
59  static void Clamp(double &i, double min, double max);
60  static void Clamp(int&, int min, int max);
61  static void Clamp(float &i, float min, float max);
63 
69  static void SnapToNearest(int & i, int subdiv);
70  static void SnapToNearest(float & i, float subdiv);
71  static void SnapToNearest(double & i, double subdiv);
73 
79  static float Step(float & f, float dest, float stepSize);
80 
83  static float GetHypotenuse(float a,float b);
84 
88  static float RadsToDegrees(float rads);
89  static float DegreesToRads(float degrees);
91 
94  static float Pi();
95 
103  static bool IsVectorWithinBounds(const Dynacoe::Vector & src,
104  const Dynacoe::Vector & boundPos,
105  float boundW, float boundH);
106 
107 
110  static bool IsVectorWithinRange(const Dynacoe::Vector & p1,
111  const Dynacoe::Vector & p2,
112  float range);
113 };
114 }
115 
116 #endif
static float GetHypotenuse(float a, float b)
Returns sqrt((pow(a, 2) + pow(b, 2)).
3D and 2D positional vector.
Definition: Vector.h:55
Definition: AssetID.h:37
static bool IsVectorWithinBounds(const Dynacoe::Vector &src, const Dynacoe::Vector &boundPos, float boundW, float boundH)
Returns whether or not a point is within a rectangle bounding box. The edge of the bounding box is co...
static float Step(float &f, float dest, float stepSize)
Makes a value approach another.
static float Pi()
Returns a standard pi value.
Utility providing some additional math operations.
Definition: Math.h:51
static bool IsVectorWithinRange(const Dynacoe::Vector &p1, const Dynacoe::Vector &p2, float range)
Checks to see if a point is within a certain distance.