krita

kis_vec.cc

00001 /*
00002  *  kis_vec.cc - part of KImageShop
00003  *
00004  *  Copyright (c) 1999 Matthias Elter <me@kde.org>
00005  *
00006  *  This program is free software; you can redistribute it and/or modify
00007  *  it under the terms of the GNU General Public License as published by
00008  *  the Free Software Foundation; either version 2 of the License, or
00009  *  (at your option) any later version.
00010  *
00011  *  This program is distributed in the hope that it will be useful,
00012  *  but WITHOUT ANY WARRANTY; without even the implied warranty of
00013  *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00014  *  GNU General Public License for more details.
00015  *
00016  *  You should have received a copy of the GNU General Public License
00017  *  along with this program; if not, write to the Free Software
00018  *  Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
00019  */
00020 
00021 #include "kis_vec.h"
00022 
00023 KisVector2D& KisVector2D::normalize()
00024 {
00025     double length, ilength;
00026   
00027     length = m_x*m_x + m_y*m_y;
00028     length = sqrt (length);
00029   
00030     if (length > epsilon)
00031     {
00032         ilength = 1/length;
00033         m_x *= ilength;
00034         m_y *= ilength;
00035     }
00036     return *this;
00037 }
00038 
00039 KisVector3D& KisVector3D::normalize()
00040 {
00041     double length, ilength;
00042   
00043     length = m_x*m_x + m_y*m_y + m_z*m_z;
00044     length = sqrt (length);
00045   
00046     if (length > epsilon)
00047     {
00048         ilength = 1/length;
00049         m_x *= ilength;
00050         m_y *= ilength;
00051         m_z *= ilength;
00052     }
00053     return *this;
00054 }
00055 
00056 KisVector3D& KisVector3D::crossProduct(const KisVector3D &v)
00057 {
00058     double x,y,z;
00059   
00060     x = m_y*v.m_z - m_z*v.m_y;
00061     y = m_z*v.m_x - m_x*v.m_z;
00062     z = m_x*v.m_y - m_y*v.m_x;
00063     m_x=x; m_y=y; m_z=z;
00064   
00065     return *this;
00066 }
00067 
KDE Home | KDE Accessibility Home | Description of Access Keys