00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013 #ifndef __MMX_RIEMANN_GERM_HPP
00014 #define __MMX_RIEMANN_GERM_HPP
00015 #include <analyziz/polynomial_double.hpp>
00016
00017 namespace mmx {
00018 class std_germ {};
00019 #define TMPL_DEF template<typename R,typename V= std_germ>
00020 #define TMPL template<typename R,typename V>
00021 #define C complex<R>
00022 #define Germ riemann_germ<R,V>
00023 #define Germ_rep riemann_germ_rep<R,V>
00024
00025
00026
00027
00028
00029 TMPL_DEF
00030 class riemann_germ_rep REP_STRUCT {
00031 public:
00032 polynomial<C > p;
00033 C c;
00034 R r;
00035 public:
00036 inline riemann_germ_rep (const polynomial<C >& p2, const C& c2, const R& r2):
00037 p (p2), c (c2), r (r2) {}
00038 };
00039
00040 TMPL_DEF
00041 class riemann_germ {
00042 INDIRECT_PROTO_2 (riemann_germ, riemann_germ_rep, R, V)
00043 public:
00044 inline riemann_germ ():
00045 rep (new Germ_rep (polynomial<C > (), C (), R ())) {}
00046 inline riemann_germ (const format<R>& fm):
00047 rep (new Germ_rep (polynomial<C > (C (promote (0, fm))),
00048 C (promote (0, fm)), promote (0, fm))) {}
00049 inline riemann_germ (const polynomial<C >& p, const C& c, const R& r):
00050 rep (new Germ_rep (p, c, r)) {}
00051 };
00052 INDIRECT_IMPL_2 (riemann_germ, riemann_germ_rep,
00053 typename R, R, typename V, V)
00054 DEFINE_UNARY_FORMAT_2 (riemann_germ)
00055
00056 TMPL inline C center (const Germ& g) { return g->c; }
00057 TMPL inline R radius (const Germ& g) { return g->r; }
00058 TMPL inline format<R> CF (const Germ& g) {
00059 return get_format (radius (g)); }
00060 TMPL inline C eval (const Germ& g, const C& z) {
00061 return eval (g->p, z - g->c); }
00062 TMPL inline bool inside (const C& z, const Germ& g) {
00063 return abs (z - g->c) < g->r; }
00064 TMPL inline bool better (const C& z, const Germ& g1, const Germ& g2) {
00065 return abs (z - g1->c) < abs (z - g2->c); }
00066
00067
00068
00069
00070
00071 template<typename Op, typename R, typename V> nat
00072 unary_hash (const Germ& s) {
00073 return hard_hash (s);
00074 }
00075
00076 template<typename Op, typename R, typename V> bool
00077 binary_test (const Germ& s1, const Germ& s2) {
00078 return hard_eq (s1, s2);
00079 }
00080
00081 TRUE_IDENTITY_OP_SUGAR(TMPL,Germ)
00082 EXACT_IDENTITY_OP_SUGAR(TMPL,Germ)
00083
00084 TMPL syntactic
00085 flatten (const Germ& g) {
00086 return apply ("germ", flatten (g->p), flatten (g->c), flatten (g->r));
00087 }
00088
00089 TMPL
00090 struct binary_helper<Germ >: public void_binary_helper<Germ > {
00091 static inline string short_type_name () {
00092 return "Rger" * Short_type_name (R); }
00093 static inline generic full_type_name () {
00094 return gen ("Riemann_germ", Full_type_name (R)); }
00095 static inline generic disassemble (const Germ& g) {
00096 return gen_vec (as<generic> (g->p),
00097 as<generic> (center (g)),
00098 as<generic> (radius (g))); }
00099 static inline Germ assemble (const generic& v) {
00100 return Germ (as<polynomial<C> > (vector_access (v, 0)),
00101 as<C > (vector_access (v, 1)),
00102 as<R > (vector_access (v, 2))); }
00103 static inline void write (const port& out, const Germ& g) {
00104 binary_write<polynomial<C > > (out, g->p);
00105 binary_write<C > (out, center (g));
00106 binary_write<R > (out, radius (g)); }
00107 static inline Germ read (const port& in) {
00108 polynomial<C > p= binary_read<polynomial<C> > (in);
00109 C c= binary_read<C > (in);
00110 R r= binary_read<R > (in);
00111 return Germ (p, c, r); }
00112 };
00113
00114 #undef TMPL_DEF
00115 #undef TMPL
00116 #undef C
00117 #undef Germ
00118 #undef Germ_rep
00119 }
00120 #endif // __MMX_RIEMANN_GERM_HPP