mymath.h

Go to the documentation of this file.
00001 #ifndef mymath_h
00002 #define mymath_h
00003 
00004 #include <OS/math.h>
00005 #include <InterViews/geometry.h>
00006 
00007 extern "C" {
00008 extern int nrn_isdouble(double*, double, double);
00009 }
00010 
00011 class Extension;
00012 
00013 class MyMath {
00014 public:
00015    // increase all around in screen coords
00016    static void extend(Extension&, Coord);
00017    static void extend(Extension&, const Extension&);
00018    
00019    static void minmax(Coord& min, Coord& max);
00020    static boolean inside(Coord x, Coord min, Coord max);
00021 
00022    static float min(int count, const float*);
00023    static float max(int count, const float*);
00024    
00025    static boolean inside(
00026       Coord x, Coord y,
00027       Coord left, Coord bottom, Coord right, Coord top
00028    );
00029 
00030    // within epsilon distance from the infinite line
00031    static boolean near_line(
00032       Coord x, Coord y,
00033       Coord x1, Coord y1, Coord x2, Coord y2,
00034       float epsilon
00035    );
00036 
00037    // within epsilon distance from the line segment
00038    static boolean near_line_segment(
00039       Coord x, Coord y,
00040       Coord x1, Coord y1, Coord x2, Coord y2,
00041       float epsilon
00042    );
00043 
00044    // returns distance between point and line segment
00045    static float distance_to_line_segment(
00046       Coord x, Coord y,
00047       Coord x1, Coord y1, Coord x2, Coord y2
00048    );
00049 
00050    // returns distance between point and line
00051    static float distance_to_line(
00052       Coord x, Coord y,
00053       Coord x1, Coord y1, Coord x2, Coord y2
00054    );
00055 
00056    
00057    // returns square norm
00058    static float norm2(Coord x, Coord y) {
00059       return x*x + y*y;
00060    }
00061 
00062    // unit length vector perpindicular to vector (x, y)
00063    static boolean unit_normal(Coord x, Coord y, Coord* perp);
00064    
00065    // returns range extended to nearest 1.5 digit accuracy.
00066    // ie. digit is 1, 2, or 5
00067    static void round_range(Coord x1, Coord x2, double& y1, double& y2,
00068       int& ntic);
00069    static void round_range_down(Coord x1, Coord x2, double& y1, double& y2,
00070       int& ntic);
00071 
00072    enum {Expand, Contract, Higher, Lower};
00073    static double round(float& x1, float& x2, int direction, int digits);
00074     
00075    static void box(Requisition&, Coord& x1, Coord& y1, Coord& x2, Coord& y2);
00076 
00077    static double anint(double); /* round toward nearest integer */
00078    static double resolution(double); // 100, 10, .1,... least significant digit
00079 
00080    static boolean lt(double x, double y, double e) { return x < (y-e); }
00081    static boolean le(double x, double y, double e) { return x <= (y+e); }
00082    static boolean eq(double x, double y, double e) { return Math::equal(x,y,e);}
00083 };
00084 
00085 inline void MyMath::extend(Extension& e, const Extension& x) {
00086    e.set_xy(nil, e.left() + x.left(), e.bottom() + x.bottom(),
00087       e.right() + x.right(), e.top() + x.top());
00088 }
00089 
00090 inline void MyMath::extend(Extension& e, Coord x) {
00091    e.set_xy(nil, e.left() - x, e.bottom() - x, e.right() + x, e.top() + x);
00092 }
00093 
00094 inline void MyMath::minmax(Coord& x, Coord& y) {
00095    if (y < x) {Coord z = x; x = y; y = z;}
00096 }
00097 
00098 inline boolean MyMath::inside(Coord x, Coord x1, Coord x2) {
00099    return (x >= x1 && x <= x2);
00100 }
00101 
00102 inline boolean MyMath::inside(Coord x, Coord y, Coord x1, Coord y1, Coord x2, Coord y2) {
00103    return inside(x, x1, x2) && inside(y, y1, y2);
00104 }
00105 
00106 #endif
Generated on Mon Jun 13 08:10:24 2011 for NEURON by  doxygen 1.6.3