-
Notifications
You must be signed in to change notification settings - Fork 0
/
VECTOR2D.cpp
49 lines (35 loc) · 991 Bytes
/
VECTOR2D.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
//////////////////////////////////////////////////////////////////////////////////////////
// VECTOR2D.cpp
// Function definitions for 2d vector class
// You may use this code however you wish, but if you do, please credit me and
// provide a link to my website in a readme file or similar
// Downloaded from: www.paulsprojects.net
//////////////////////////////////////////////////////////////////////////////////////////
#include "VECTOR2D.h"
void VECTOR2D::Normalize()
{
float length;
float scalefactor;
length=GetLength();
if(length==1 || length==0) //return if length is 1 or 0
return;
scalefactor = 1.0f/length;
x *= scalefactor;
y *= scalefactor;
}
VECTOR2D VECTOR2D::GetNormalized() const
{
VECTOR2D result(*this);
result.Normalize();
return result;
}
VECTOR2D operator*(float scaleFactor, const VECTOR2D & rhs)
{
return rhs*scaleFactor;
}
bool VECTOR2D::operator==(const VECTOR2D & rhs) const
{
if(x==rhs.x && y==rhs.y)
return true;
return false;
}