chalk

kis_vec.cpp
1/*
2 * kis_vec.cpp - part of KImageShop
3 *
4 * Copyright (c) 1999 Matthias Elter <me@kde.org>
5 *
6 * This program is free software; you can redistribute it and/or modify
7 * it under the terms of the GNU General Public License as published by
8 * the Free Software Foundation; either version 2 of the License, or
9 * (at your option) any later version.
10 *
11 * This program is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 * GNU General Public License for more details.
15 *
16 * You should have received a copy of the GNU General Public License
17 * along with this program; if not, write to the Free Software
18 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
19 */
20
21#include "kis_vec.h"
22
23KisVector2D& KisVector2D::normalize()
24{
25 double length, ilength;
26
27 length = m_x*m_x + m_y*m_y;
28 length = sqrt (length);
29
30 if (length > epsilon)
31 {
32 ilength = 1/length;
33 m_x *= ilength;
34 m_y *= ilength;
35 }
36 return *this;
37}
38
39KisVector3D& KisVector3D::normalize()
40{
41 double length, ilength;
42
43 length = m_x*m_x + m_y*m_y + m_z*m_z;
44 length = sqrt (length);
45
46 if (length > epsilon)
47 {
48 ilength = 1/length;
49 m_x *= ilength;
50 m_y *= ilength;
51 m_z *= ilength;
52 }
53 return *this;
54}
55
56KisVector3D& KisVector3D::crossProduct(const KisVector3D &v)
57{
58 double x,y,z;
59
60 x = m_y*v.m_z - m_z*v.m_y;
61 y = m_z*v.m_x - m_x*v.m_z;
62 z = m_x*v.m_y - m_y*v.m_x;
63 m_x=x; m_y=y; m_z=z;
64
65 return *this;
66}
67