kviewshell
length.h
Go to the documentation of this file.00001 // -*- C++ -*- 00002 // 00003 // Class: length 00004 // 00005 // Part of KVIESHELL 00006 // 00007 // (C) 2005 Stefan Kebekus. Distributed under the GPL. 00008 00009 00010 #ifndef _length_h_ 00011 #define _length_h_ 00012 00013 #define mm_per_cm 10.0 00014 #define mm_per_m 1000.0 00015 #define mm_per_inch 25.4 00016 #define mm_per_TeXPoint (2540.0/7227.0) 00017 #define mm_per_bigPoint (25.4/72.0) 00018 #define mm_per_pica (25.4/6.0) 00019 #define mm_per_didot (25.4*0.0148) 00020 #define mm_per_cicero (25.4*0.178) 00021 #define mm_per_scaledPoint (25.4/(72.27 * 65536.0)) 00022 00023 00024 #include <math.h> 00025 00041 class Length 00042 { 00043 public: 00045 Length() {length_in_mm = 0;} 00046 00048 void setLength_in_mm(double l) {length_in_mm = l;} 00049 00051 void setLength_in_cm(double l) {length_in_mm = l*mm_per_cm;} 00052 00054 void setLength_in_m(double l) {length_in_mm = l*mm_per_m;} 00055 00057 void setLength_in_inch(double l) {length_in_mm = l*mm_per_inch;} 00058 00060 void setLength_in_TeXPoints(double l) {length_in_mm = l*mm_per_TeXPoint;} 00061 00063 void setLength_in_bigPoints(double l) {length_in_mm = l*mm_per_bigPoint;} 00064 00066 void setLength_in_pica(double l) {length_in_mm = l*mm_per_pica;} 00067 00069 void setLength_in_didot(double l) {length_in_mm = l*mm_per_didot;} 00070 00072 void setLength_in_cicero(double l) {length_in_mm = l*mm_per_cicero;} 00073 00075 void setLength_in_scaledPoints(double l) {length_in_mm = l*mm_per_scaledPoint;} 00076 00077 00079 double getLength_in_mm() const {return length_in_mm;} 00080 00082 double getLength_in_cm() const {return length_in_mm/mm_per_cm;} 00083 00085 double getLength_in_m() const {return length_in_mm/mm_per_m;} 00086 00088 double getLength_in_inch() const {return length_in_mm/mm_per_inch;} 00089 00091 double getLength_in_TeXPoints() const {return length_in_mm/mm_per_TeXPoint;} 00092 00094 double getLength_in_bigPoints() const {return length_in_mm/mm_per_bigPoint;} 00095 00097 double getLength_in_pica() const {return length_in_mm/mm_per_pica;} 00098 00100 double getLength_in_didot() const {return length_in_mm/mm_per_didot;} 00101 00103 double getLength_in_cicero() const {return length_in_mm/mm_per_cicero;} 00104 00106 double getLength_in_scaledPoints() const {return length_in_mm/mm_per_scaledPoint;} 00107 00109 bool isNearlyEqual(const Length &o) const {return fabs(length_in_mm-o.getLength_in_mm()) <= 2.0;} 00110 00112 bool operator > (const Length &o) const {return (length_in_mm > o.getLength_in_mm());} 00113 bool operator < (const Length &o) const {return (length_in_mm < o.getLength_in_mm());} 00114 00116 bool operator >= (const Length &o) const {return (length_in_mm >= o.getLength_in_mm());} 00117 bool operator <= (const Length &o) const {return (length_in_mm <= o.getLength_in_mm());} 00118 00127 double operator / (const Length &o) const {return (length_in_mm/o.getLength_in_mm());} 00128 00133 Length operator + (const Length &o) const {Length r; r.length_in_mm = length_in_mm + o.length_in_mm; return r; } 00134 00139 Length operator - (const Length &o) const {Length r; r.length_in_mm = length_in_mm - o.length_in_mm; return r; } 00140 00149 Length operator / (const double l) const {Length r; r.length_in_mm = length_in_mm/l; return r; } 00150 00155 Length operator * (const double l) const {Length r; r.length_in_mm = length_in_mm*l; return r; } 00156 00157 private: 00159 double length_in_mm; 00160 }; 00161 00162 #undef mm_per_cm 00163 #undef mm_per_m 00164 #undef mm_per_inch 00165 #undef mm_per_TeXPoint 00166 #undef mm_per_bigPoint 00167 #undef mm_per_pica 00168 #undef mm_per_didot 00169 #undef mm_per_cicero 00170 #undef mm_per_scaledPoint 00171 00172 00173 #endif