1 /********************************************************************************
2 *                                                                               *
3 *       D o u b l e - P r e c i s i o n   2 - E l e m e n t   V e c t o r       *
4 *                                                                               *
5 *********************************************************************************
6 * Copyright (C) 1994,2006 by Jeroen van der Zijp.   All Rights Reserved.        *
7 *********************************************************************************
8 * This library is free software; you can redistribute it and/or                 *
9 * modify it under the terms of the GNU Lesser General Public                    *
10 * License as published by the Free Software Foundation; either                  *
11 * version 2.1 of the License, or (at your option) any later version.            *
12 *                                                                               *
13 * This library is distributed in the hope that it will be useful,               *
14 * but WITHOUT ANY WARRANTY; without even the implied warranty of                *
15 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU             *
16 * Lesser General Public License for more details.                               *
17 *                                                                               *
18 * You should have received a copy of the GNU Lesser General Public              *
19 * License along with this library; if not, write to the Free Software           *
20 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA.    *
21 *********************************************************************************
22 * $Id: FXVec2d.cpp 4937 2019-03-10 19:59:30Z arthurcnorman $                          *
23 ********************************************************************************/
24 #include "xincs.h"
25 #include "fxver.h"
26 #include "fxdefs.h"
27 #include "FXHash.h"
28 #include "FXStream.h"
29 #include "FXObject.h"
30 #include "FXVec2d.h"
31 #include "FXVec3d.h"
32 #include "FXMat3d.h"
33 
34 
35 using namespace FX;
36 
37 /*******************************************************************************/
38 
39 namespace FX {
40 
41 
normalize(const FXVec2d & v)42 FXVec2d normalize(const FXVec2d& v){
43   FXdouble t=v.length();
44   if(t>0.0){ return FXVec2d(v.x/t,v.y/t); }
45   return FXVec2d(0.0,0.0);
46   }
47 
48 
49 // Vector times matrix
operator *(const FXMat3d & m) const50 FXVec2d FXVec2d::operator*(const FXMat3d& m) const {
51   FXASSERT(m[0][2]==0.0 && m[1][2]==0.0 && m[2][2]==1.0);
52   return FXVec2d(x*m[0][0]+y*m[1][0]+m[2][0], x*m[0][1]+y*m[1][1]+m[2][1]);
53   }
54 
55 
operator <<(FXStream & store,const FXVec2d & v)56 FXStream& operator<<(FXStream& store,const FXVec2d& v){
57   store << v.x << v.y;
58   return store;
59   }
60 
61 
operator >>(FXStream & store,FXVec2d & v)62 FXStream& operator>>(FXStream& store,FXVec2d& v){
63   store >> v.x >> v.y;
64   return store;
65   }
66 
67 }
68