00001 // Filename: lvecBase2_src.h 00002 // Created by: drose (08Mar00) 00003 // 00004 //////////////////////////////////////////////////////////////////// 00005 // 00006 // PANDA 3D SOFTWARE 00007 // Copyright (c) 2001, Disney Enterprises, Inc. All rights reserved 00008 // 00009 // All use of this software is subject to the terms of the Panda 3d 00010 // Software license. You should have received a copy of this license 00011 // along with this source code; you will also find a current copy of 00012 // the license at http://www.panda3d.org/license.txt . 00013 // 00014 // To contact the maintainers of this program write to 00015 // panda3d@yahoogroups.com . 00016 // 00017 //////////////////////////////////////////////////////////////////// 00018 00019 //typedef struct {FLOATTYPE _0, _1} FLOATNAME(data); 00020 00021 00022 //////////////////////////////////////////////////////////////////// 00023 // Class : LVecBase2 00024 // Description : This is the base class for all two-component 00025 // vectors and points. 00026 //////////////////////////////////////////////////////////////////// 00027 class EXPCL_PANDA FLOATNAME(LVecBase2) { 00028 PUBLISHED: 00029 typedef const FLOATTYPE *iterator; 00030 typedef const FLOATTYPE *const_iterator; 00031 00032 INLINE_LINMATH FLOATNAME(LVecBase2)(); 00033 INLINE_LINMATH FLOATNAME(LVecBase2)(const FLOATNAME(LVecBase2) ©); 00034 INLINE_LINMATH FLOATNAME(LVecBase2) &operator = (const FLOATNAME(LVecBase2) ©); 00035 INLINE_LINMATH FLOATNAME(LVecBase2) &operator = (FLOATTYPE fill_value); 00036 INLINE_LINMATH FLOATNAME(LVecBase2)(FLOATTYPE fill_value); 00037 INLINE_LINMATH FLOATNAME(LVecBase2)(FLOATTYPE x, FLOATTYPE y); 00038 00039 INLINE_LINMATH static const FLOATNAME(LVecBase2) &zero(); 00040 INLINE_LINMATH static const FLOATNAME(LVecBase2) &unit_x(); 00041 INLINE_LINMATH static const FLOATNAME(LVecBase2) &unit_y(); 00042 00043 INLINE_LINMATH ~FLOATNAME(LVecBase2)(); 00044 00045 INLINE_LINMATH FLOATTYPE operator [](int i) const; 00046 INLINE_LINMATH FLOATTYPE &operator [](int i); 00047 00048 INLINE_LINMATH bool is_nan() const; 00049 00050 INLINE_LINMATH FLOATTYPE get_cell(int i) const; 00051 INLINE_LINMATH FLOATTYPE get_x() const; 00052 INLINE_LINMATH FLOATTYPE get_y() const; 00053 INLINE_LINMATH void set_cell(int i, FLOATTYPE value); 00054 INLINE_LINMATH void set_x(FLOATTYPE value); 00055 INLINE_LINMATH void set_y(FLOATTYPE value); 00056 00057 INLINE_LINMATH const FLOATTYPE *get_data() const; 00058 INLINE_LINMATH int get_num_components() const; 00059 00060 public: 00061 INLINE_LINMATH iterator begin(); 00062 INLINE_LINMATH iterator end(); 00063 00064 INLINE_LINMATH const_iterator begin() const; 00065 INLINE_LINMATH const_iterator end() const; 00066 00067 PUBLISHED: 00068 INLINE_LINMATH void fill(FLOATTYPE fill_value); 00069 INLINE_LINMATH void set(FLOATTYPE x, FLOATTYPE y); 00070 00071 INLINE_LINMATH FLOATTYPE dot(const FLOATNAME(LVecBase2) &other) const; 00072 00073 INLINE_LINMATH bool operator < (const FLOATNAME(LVecBase2) &other) const; 00074 INLINE_LINMATH bool operator == (const FLOATNAME(LVecBase2) &other) const; 00075 INLINE_LINMATH bool operator != (const FLOATNAME(LVecBase2) &other) const; 00076 00077 INLINE_LINMATH int compare_to(const FLOATNAME(LVecBase2) &other) const; 00078 INLINE_LINMATH int compare_to(const FLOATNAME(LVecBase2) &other, 00079 FLOATTYPE threshold) const; 00080 00081 00082 INLINE_LINMATH FLOATNAME(LVecBase2) operator - () const; 00083 00084 INLINE_LINMATH FLOATNAME(LVecBase2) 00085 operator + (const FLOATNAME(LVecBase2) &other) const; 00086 INLINE_LINMATH FLOATNAME(LVecBase2) 00087 operator - (const FLOATNAME(LVecBase2) &other) const; 00088 00089 INLINE_LINMATH FLOATNAME(LVecBase2) operator * (FLOATTYPE scalar) const; 00090 INLINE_LINMATH FLOATNAME(LVecBase2) operator / (FLOATTYPE scalar) const; 00091 00092 INLINE_LINMATH void operator += (const FLOATNAME(LVecBase2) &other); 00093 INLINE_LINMATH void operator -= (const FLOATNAME(LVecBase2) &other); 00094 00095 INLINE_LINMATH void operator *= (FLOATTYPE scalar); 00096 INLINE_LINMATH void operator /= (FLOATTYPE scalar); 00097 00098 INLINE_LINMATH bool almost_equal(const FLOATNAME(LVecBase2) &other, 00099 FLOATTYPE threshold) const; 00100 INLINE_LINMATH bool almost_equal(const FLOATNAME(LVecBase2) &other) const; 00101 00102 INLINE_LINMATH void output(ostream &out) const; 00103 00104 public: 00105 INLINE_LINMATH void generate_hash(ChecksumHashGenerator &hashgen) const; 00106 INLINE_LINMATH void generate_hash(ChecksumHashGenerator &hashgen, 00107 FLOATTYPE threshold) const; 00108 00109 public: 00110 union { 00111 FLOATTYPE data[2]; 00112 struct {FLOATTYPE _0, _1;} v; 00113 } _v; 00114 00115 private: 00116 static const FLOATNAME(LVecBase2) _zero; 00117 static const FLOATNAME(LVecBase2) _unit_x; 00118 static const FLOATNAME(LVecBase2) _unit_y; 00119 00120 public: 00121 INLINE_LINMATH void write_datagram(Datagram &destination) const; 00122 INLINE_LINMATH void read_datagram(DatagramIterator &source); 00123 00124 public: 00125 static TypeHandle get_class_type() { 00126 return _type_handle; 00127 } 00128 static void init_type(); 00129 00130 private: 00131 static TypeHandle _type_handle; 00132 }; 00133 00134 00135 INLINE_LINMATH ostream &operator << (ostream &out, const FLOATNAME(LVecBase2) &vec) { 00136 vec.output(out); 00137 return out; 00138 } 00139 00140 #include "lvecBase2_src.I"