Mirror reflection library 0.5.13

/home/chochlik/devel/mirror-lib/src/mirror/example/factories/tetrahedron.hpp

Go to the documentation of this file.
00001 
00012 #ifndef MIRROR_EXAMPLE_FACTORIES_TETRAHEDRON_1011291729_HPP
00013 #define MIRROR_EXAMPLE_FACTORIES_TETRAHEDRON_1011291729_HPP
00014 
00015 #include <cmath>
00016 #include <mirror/meta_class.hpp>
00017 #include <mirror/pre_registered/type/native.hpp>
00018 
00019 namespace test {
00020 
00021 struct vector
00022 {
00023     double x,y,z;
00024 
00025     vector(double _x, double _y, double _z)
00026      : x(_x)
00027      , y(_y)
00028      , z(_z)
00029     { }
00030 
00031     vector(double _w)
00032      : x(_w)
00033      , y(_w)
00034      , z(_w)
00035     { }
00036 
00037     vector(void)
00038      : x(0.0)
00039      , y(0.0)
00040      , z(0.0)
00041     { }
00042 
00043     // addition
00044     friend vector operator + (const vector& a, const vector& b)
00045     {
00046         return vector(a.x + b.x, a.y + b.y, a.z + b.z);
00047     }
00048 
00049     // subtraction
00050     friend vector operator - (const vector& a, const vector& b)
00051     {
00052         return vector(a.x - b.x, a.y - b.y, a.z - b.z);
00053     }
00054 
00055     // cross product
00056     friend vector operator % (const vector& a, const vector& b)
00057     {
00058         return vector(
00059             a.y * b.z - a.z * b.y,
00060             a.z * b.x - a.x * b.z,
00061             a.x * b.y - a.y * b.x
00062         );
00063     }
00064 
00065     // dot product
00066     friend double operator * (const vector& a, const vector& b)
00067     {
00068         return a.x*b.x + a.y*b.y + a.z*b.z;
00069     }
00070 
00071     double length(void) const
00072     {
00073         return std::sqrt(x*x + y*y + z*z);
00074     }
00075 };
00076 
00077 struct triangle
00078 {
00079     vector a, b, c;
00080 
00081     triangle(const vector& _a, const vector& _b, const vector& _c)
00082      : a(_a)
00083      , b(_b)
00084      , c(_c)
00085     { }
00086 
00087     triangle(void){ }
00088 
00089 
00090     double area(void) const
00091     {
00092         return ((b-a)%(c-a)).length()/2.0;
00093     }
00094 };
00095 
00096 struct tetrahedron
00097 {
00098     triangle base;
00099     vector apex;
00100 
00101     tetrahedron(const triangle& _base, const vector& _apex)
00102      : base(_base)
00103      , apex(_apex)
00104     { }
00105 
00106     tetrahedron(
00107         const vector& a,
00108         const vector& b,
00109         const vector& c,
00110         const vector& d
00111     ): base(a, b, c)
00112      , apex(d)
00113     { }
00114 
00115     const vector& a(void) const {return base.a;}
00116     const vector& b(void) const {return base.b;}
00117     const vector& c(void) const {return base.c;}
00118     const vector& d(void) const {return apex;}
00119 
00120     void reset_apex(const vector& _apex)
00121     {
00122         apex = _apex;
00123     }
00124 
00125     void reset_apex(double x, double y, double z)
00126     {
00127         apex = vector(x, y, z);
00128     }
00129 
00130     double volume(void) const
00131     {
00132         return std::fabs(((a()-d())*((b()-d())%(c()-d()))))/6.0;
00133     }
00134 };
00135 
00136 
00137 } // namespace test
00138 
00139 
00140 MIRROR_REG_BEGIN
00141 
00142 // register the ::test namespace
00143 MIRROR_QREG_GLOBAL_SCOPE_NAMESPACE(test)
00144 
00145 // register the test::vector struct
00146 MIRROR_REG_CLASS_BEGIN(struct, test, vector)
00147   MIRROR_REG_CLASS_MEM_VARS_BEGIN
00148     MIRROR_REG_CLASS_MEM_VAR(_, _, _, x)
00149     MIRROR_REG_CLASS_MEM_VAR(_, _, _, y)
00150     MIRROR_REG_CLASS_MEM_VAR(_, _, _, z)
00151   MIRROR_REG_CLASS_MEM_VARS_END
00152 
00153   MIRROR_REG_CONSTRUCTORS_BEGIN
00154     MIRROR_REG_CONSTRUCTOR_BEGIN(public, xyz)
00155       MIRROR_REG_CONSTRUCTOR_PARAM(_, x)
00156       MIRROR_REG_CONSTRUCTOR_PARAM(_, y)
00157       MIRROR_REG_CONSTRUCTOR_PARAM(_, z)
00158     MIRROR_REG_CONSTRUCTOR_END(xyz)
00159 
00160     MIRROR_REG_CONSTRUCTOR_BEGIN(public, w)
00161       MIRROR_REG_CONSTRUCTOR_PARAM(double, w)
00162     MIRROR_REG_CONSTRUCTOR_END(w)
00163 
00164     MIRROR_REG_DEFAULT_CONSTRUCTOR(_)
00165     MIRROR_REG_COPY_CONSTRUCTOR(_)
00166   MIRROR_REG_CONSTRUCTORS_END
00167 MIRROR_REG_CLASS_END
00168 
00169 // register the test::triangle struct
00170 MIRROR_REG_CLASS_BEGIN(struct, test, triangle)
00171   MIRROR_REG_CLASS_MEM_VARS_BEGIN
00172     MIRROR_REG_CLASS_MEM_VAR(_, _, _, a)
00173     MIRROR_REG_CLASS_MEM_VAR(_, _, _, b)
00174     MIRROR_REG_CLASS_MEM_VAR(_, _, _, c)
00175   MIRROR_REG_CLASS_MEM_VARS_END
00176 
00177   MIRROR_REG_CONSTRUCTORS_BEGIN
00178     MIRROR_REG_CONSTRUCTOR_BEGIN(public, abc)
00179       MIRROR_REG_CONSTRUCTOR_PARAM(_, a)
00180       MIRROR_REG_CONSTRUCTOR_PARAM(_, b)
00181       MIRROR_REG_CONSTRUCTOR_PARAM(_, c)
00182     MIRROR_REG_CONSTRUCTOR_END(abc)
00183 
00184     MIRROR_REG_DEFAULT_CONSTRUCTOR(_)
00185     MIRROR_REG_COPY_CONSTRUCTOR(_)
00186   MIRROR_REG_CONSTRUCTORS_END
00187 MIRROR_REG_CLASS_END
00188 
00189 // register the test::tetrahedron struct
00190 MIRROR_REG_CLASS_BEGIN(struct, test, tetrahedron)
00191   MIRROR_REG_CLASS_MEM_VARS_BEGIN
00192     MIRROR_REG_CLASS_MEM_VAR(_, _, _, base)
00193     MIRROR_REG_CLASS_MEM_VAR(_, _, _, apex)
00194   MIRROR_REG_CLASS_MEM_VARS_END
00195 
00196   MIRROR_REG_CONSTRUCTORS_BEGIN
00197     MIRROR_REG_CONSTRUCTOR_BEGIN(public, ba)
00198       MIRROR_REG_CONSTRUCTOR_PARAM(_, base)
00199       MIRROR_REG_CONSTRUCTOR_PARAM(_, apex)
00200     MIRROR_REG_CONSTRUCTOR_END(ba)
00201 
00202     MIRROR_REG_CONSTRUCTOR_BEGIN(public, abcd)
00203       MIRROR_REG_CONSTRUCTOR_PARAM(test::vector, a)
00204       MIRROR_REG_CONSTRUCTOR_PARAM(test::vector, b)
00205       MIRROR_REG_CONSTRUCTOR_PARAM(test::vector, c)
00206       MIRROR_REG_CONSTRUCTOR_PARAM(test::vector, d)
00207     MIRROR_REG_CONSTRUCTOR_END(abcd)
00208 
00209     MIRROR_REG_COPY_CONSTRUCTOR(_)
00210   MIRROR_REG_CONSTRUCTORS_END
00211 
00212   MIRROR_REG_MEM_FUNCTIONS_BEGIN
00213     MIRROR_REG_MEM_OVLD_FUNC_BEGIN(reset_apex)
00214     MIRROR_REG_MEM_FUNCTION_BEGIN(public, _, void, reset_apex, 1)
00215       MIRROR_REG_MEM_FUNCTION_PARAM(_, apex)
00216     MIRROR_REG_MEM_FUNCTION_END(1, _)
00217     MIRROR_REG_MEM_FUNCTION_BEGIN(public, _, void, reset_apex, 2)
00218       MIRROR_REG_MEM_FUNCTION_PARAM(double, x)
00219       MIRROR_REG_MEM_FUNCTION_PARAM(double, y)
00220       MIRROR_REG_MEM_FUNCTION_PARAM(double, z)
00221     MIRROR_REG_MEM_FUNCTION_END(2, _)
00222     MIRROR_REG_MEM_OVLD_FUNC_END(reset_apex)
00223   MIRROR_REG_MEM_FUNCTIONS_END
00224 MIRROR_REG_CLASS_END
00225 
00226 MIRROR_REG_END
00227 
00228 #endif
00229 

Copyright © 2006-2011 Matus Chochlik, University of Zilina, Zilina, Slovakia.
<matus.chochlik -at- fri.uniza.sk>
<chochlik -at -gmail.com>
Documentation generated on Fri Dec 16 2011 by Doxygen (version 1.7.3).
Important note: Although the 'boostified' version of Mirror uses the Boost C++ libraries Coding Guidelines and is implemented inside of the boost namespace, it IS NOT an officially reviewed and accepted Boost library. Mirror is being developed with the intention to be submitted for review for inclusion to the Boost C++ libraries.