X-Git-Url: http://shamusworld.gotdns.org/cgi-bin/gitweb.cgi?a=blobdiff_plain;f=src%2Fbase%2Funits.cpp;h=5ee0d448b2d469fabceede896b06449fca5f3510;hb=5adb444f3e523d3fd028617ced72d1ea6661db21;hp=eb34a077fe82381ba69412bd34bd6225ce57d1bb;hpb=3239ef39dcee08fa6e8cd68cdf2727fc68cc7a8c;p=architektonas diff --git a/src/base/units.cpp b/src/base/units.cpp index eb34a07..5ee0d44 100644 --- a/src/base/units.cpp +++ b/src/base/units.cpp @@ -23,7 +23,7 @@ /** * Converts a DXF integer () to a Unit enum. */ -RS2::Unit RS_Units::dxfint2unit(int dxfint) +RS2::Unit Units::dxfint2unit(int dxfint) { return (RS2::Unit)dxfint; @@ -77,7 +77,7 @@ RS2::Unit RS_Units::dxfint2unit(int dxfint) /** * @return a short string representing the given unit (e.g. "mm") */ -QString RS_Units::unitToSign(RS2::Unit u) +QString Units::unitToSign(RS2::Unit u) { QString ret = ""; @@ -159,7 +159,7 @@ QString RS_Units::unitToSign(RS2::Unit u) * @return a string representing the given unit (e.g. "Millimeter"). * translated if @a t is true (the default). */ -QString RS_Units::unitToString(RS2::Unit u, bool t) +QString Units::unitToString(RS2::Unit u, bool t) { QString ret = ""; @@ -240,7 +240,7 @@ QString RS_Units::unitToString(RS2::Unit u, bool t) /** * Converts a string into a unit enum. */ -RS2::Unit RS_Units::stringToUnit(const QString & u) +RS2::Unit Units::stringToUnit(const QString & u) { RS2::Unit ret = RS2::None; @@ -293,7 +293,7 @@ RS2::Unit RS_Units::stringToUnit(const QString & u) /** * @return true: the unit is metric, false: the unit is imperial. */ -bool RS_Units::isMetric(RS2::Unit u) +bool Units::isMetric(RS2::Unit u) { if (u == RS2::Millimeter || u == RS2::Centimeter || u == RS2::Meter || u == RS2::Kilometer || u == RS2::Angstrom || u == RS2::Nanometer @@ -308,7 +308,7 @@ bool RS_Units::isMetric(RS2::Unit u) /** * @return factor to convert the given unit to Millimeters. */ -double RS_Units::getFactorToMM(RS2::Unit u) +double Units::getFactorToMM(RS2::Unit u) { double ret = 1.0; @@ -388,7 +388,7 @@ double RS_Units::getFactorToMM(RS2::Unit u) /** * Converts the given value 'val' from unit 'src' to unit 'dest'. */ -double RS_Units::convert(double val, RS2::Unit src, RS2::Unit dest) +double Units::convert(double val, RS2::Unit src, RS2::Unit dest) { if (getFactorToMM(dest) > 0.0) { @@ -396,7 +396,7 @@ double RS_Units::convert(double val, RS2::Unit src, RS2::Unit dest) } else { - RS_DEBUG->print(RS_Debug::D_WARNING, "RS_Units::convert: invalid factor"); + DEBUG->print(Debug::D_WARNING, "Units::convert: invalid factor"); return val; } } @@ -404,7 +404,7 @@ double RS_Units::convert(double val, RS2::Unit src, RS2::Unit dest) /** * Converts the given vector 'val' from unit 'src' to unit 'dest'. */ -Vector RS_Units::convert(const Vector val, RS2::Unit src, RS2::Unit dest) +Vector Units::convert(const Vector val, RS2::Unit src, RS2::Unit dest) { return Vector(convert(val.x, src, dest), convert(val.y, src, dest), convert(val.z, src, dest)); } @@ -417,7 +417,7 @@ Vector RS_Units::convert(const Vector val, RS2::Unit src, RS2::Unit dest) * @param prec Precisision of the value (e.g. 0.001 or 1/128 = 0.0078125) & @param showUnit Append unit to the value. */ -QString RS_Units::formatLinear(double length, RS2::Unit unit, RS2::LinearFormat format, +QString Units::formatLinear(double length, RS2::Unit unit, RS2::LinearFormat format, int prec, bool showUnit) { QString ret; @@ -452,8 +452,8 @@ QString RS_Units::formatLinear(double length, RS2::Unit unit, RS2::LinearFormat break; default: - RS_DEBUG->print(RS_Debug::D_WARNING, - "RS_Units::formatLinear: Unknown format"); + DEBUG->print(Debug::D_WARNING, + "Units::formatLinear: Unknown format"); ret = ""; break; } @@ -468,7 +468,7 @@ QString RS_Units::formatLinear(double length, RS2::Unit unit, RS2::LinearFormat * @param prec Precisision of the value (e.g. 0.001 or 1/128 = 0.0078125) & @param showUnit Append unit to the value. */ -QString RS_Units::formatScientific(double length, RS2::Unit unit, int prec, bool showUnit) +QString Units::formatScientific(double length, RS2::Unit unit, int prec, bool showUnit) { QString ret; @@ -492,7 +492,7 @@ QString RS_Units::formatScientific(double length, RS2::Unit unit, int prec, bool * @param prec Precisision of the value (e.g. 0.001) & @param showUnit Append unit to the value. */ -QString RS_Units::formatDecimal(double length, RS2::Unit unit, int prec, bool showUnit) +QString Units::formatDecimal(double length, RS2::Unit unit, int prec, bool showUnit) { QString ret; @@ -502,7 +502,7 @@ QString RS_Units::formatDecimal(double length, RS2::Unit unit, int prec, bool sh if (showUnit) unitString = unitToSign(unit); - ret = RS_Math::doubleToString(length, prec); + ret = Math::doubleToString(length, prec); if (showUnit) ret += unitString; @@ -517,7 +517,7 @@ QString RS_Units::formatDecimal(double length, RS2::Unit unit, int prec, bool sh * @param prec Precisision of the value (e.g. 0.001 or 1/128 = 0.0078125) & @param showUnit Append unit to the value. */ -QString RS_Units::formatEngineering(double length, RS2::Unit /*unit*/, int prec, bool /*showUnit*/) +QString Units::formatEngineering(double length, RS2::Unit /*unit*/, int prec, bool /*showUnit*/) { QString ret; @@ -525,7 +525,7 @@ QString RS_Units::formatEngineering(double length, RS2::Unit /*unit*/, int prec, int feet = (int)floor(fabs(length) / 12); double inches = fabs(length) - feet * 12; - QString sInches = RS_Math::doubleToString(inches, prec); + QString sInches = Math::doubleToString(inches, prec); if (sInches == "12") { @@ -555,7 +555,7 @@ QString RS_Units::formatEngineering(double length, RS2::Unit /*unit*/, int prec, * @param prec Precisision of the value (e.g. 0.001 or 1/128 = 0.0078125) & @param showUnit Append unit to the value. */ -QString RS_Units::formatArchitectural(double length, RS2::Unit /*unit*/, int prec, bool showUnit) +QString Units::formatArchitectural(double length, RS2::Unit /*unit*/, int prec, bool showUnit) { QString ret; bool neg = (length < 0.0); @@ -590,7 +590,7 @@ QString RS_Units::formatArchitectural(double length, RS2::Unit /*unit*/, int pre * @param prec Precisision of the value (e.g. 0.001 or 1/128 = 0.0078125) & @param showUnit Append unit to the value. */ -QString RS_Units::formatFractional(double length, RS2::Unit /*unit*/, int prec, bool /*showUnit*/) +QString Units::formatFractional(double length, RS2::Unit /*unit*/, int prec, bool /*showUnit*/) { QString ret; @@ -609,8 +609,8 @@ QString RS_Units::formatFractional(double length, RS2::Unit /*unit*/, int prec, num = (int)floor(length); - denominator = (int)RS_Math::pow(2, prec); - nominator = RS_Math::round((length - num) * denominator); + denominator = (int)Math::pow(2, prec); + nominator = Math::round((length - num) * denominator); // fraction rounds up to 1: if (nominator == denominator) @@ -623,7 +623,7 @@ QString RS_Units::formatFractional(double length, RS2::Unit /*unit*/, int prec, // Simplify the fraction if (nominator != 0 && denominator != 0) { - int gcd = RS_Math::findGCD(nominator, denominator); + int gcd = Math::findGCD(nominator, denominator); if (gcd != 0) { @@ -632,7 +632,7 @@ QString RS_Units::formatFractional(double length, RS2::Unit /*unit*/, int prec, } else { - RS_DEBUG->print(RS_Debug::D_WARNING, "RS_Units::formatFractional: invalid gcd"); + DEBUG->print(Debug::D_WARNING, "Units::formatFractional: invalid gcd"); nominator = 0; denominator = 0; } @@ -667,7 +667,7 @@ QString RS_Units::formatFractional(double length, RS2::Unit /*unit*/, int prec, * * @ret String with the formatted angle. */ -QString RS_Units::formatAngle(double angle, RS2::AngleFormat format, int prec) +QString Units::formatAngle(double angle, RS2::AngleFormat format, int prec) { QString ret; double value; @@ -676,16 +676,16 @@ QString RS_Units::formatAngle(double angle, RS2::AngleFormat format, int prec) { case RS2::DegreesDecimal: case RS2::DegreesMinutesSeconds: - value = RS_Math::rad2deg(angle); + value = Math::rad2deg(angle); break; case RS2::Radians: value = angle; break; case RS2::Gradians: - value = RS_Math::rad2gra(angle); + value = Math::rad2gra(angle); break; default: - RS_DEBUG->print(RS_Debug::D_WARNING, "RS_Units::formatAngle: Unknown Angle Unit"); + DEBUG->print(Debug::D_WARNING, "Units::formatAngle: Unknown Angle Unit"); return ""; break; } @@ -695,7 +695,7 @@ QString RS_Units::formatAngle(double angle, RS2::AngleFormat format, int prec) case RS2::DegreesDecimal: case RS2::Radians: case RS2::Gradians: - ret = RS_Math::doubleToString(value, prec); + ret = Math::doubleToString(value, prec); if (format == RS2::DegreesDecimal) ret += QChar(0xB0); @@ -715,7 +715,7 @@ QString RS_Units::formatAngle(double angle, RS2::AngleFormat format, int prec) vMinutes = (int)floor((value - vDegrees) * 60.0); vSeconds = (value - vDegrees - (vMinutes / 60.0)) * 3600.0; - seconds = RS_Math::doubleToString(vSeconds, (prec > 1 ? prec - 2 : 0)); + seconds = Math::doubleToString(vSeconds, (prec > 1 ? prec - 2 : 0)); if (seconds == "60") { @@ -766,7 +766,7 @@ QString RS_Units::formatAngle(double angle, RS2::AngleFormat format, int prec) /** * @return Size of the given paper format. */ -Vector RS_Units::paperFormatToSize(RS2::PaperFormat p) +Vector Units::paperFormatToSize(RS2::PaperFormat p) { Vector ret(false); @@ -917,14 +917,14 @@ Vector RS_Units::paperFormatToSize(RS2::PaperFormat p) * Gets the paper format which matches the given size. If no * format matches, RS2::Custom is returned. */ -RS2::PaperFormat RS_Units::paperSizeToFormat(const Vector s) +RS2::PaperFormat Units::paperSizeToFormat(const Vector s) { Vector ts1; Vector ts2; for(int i=(int)RS2::Custom; i<=(int)RS2::NPageSize; ++i) { - ts1 = RS_Units::paperFormatToSize((RS2::PaperFormat)i); + ts1 = Units::paperFormatToSize((RS2::PaperFormat)i); ts2 = Vector(ts1.y, ts1.x); if (ts1.distanceTo(s) < 1.0e-4 || ts2.distanceTo(s) < 1.0e-4) @@ -937,7 +937,7 @@ RS2::PaperFormat RS_Units::paperSizeToFormat(const Vector s) /** * Converts a paper format to a string (e.g. for a combobox). */ -QString RS_Units::paperFormatToString(RS2::PaperFormat p) +QString Units::paperFormatToString(RS2::PaperFormat p) { QString ret = ""; @@ -1084,7 +1084,7 @@ QString RS_Units::paperFormatToString(RS2::PaperFormat p) /** * Converts a string to a paper format. */ -RS2::PaperFormat RS_Units::stringToPaperFormat(const QString & p) +RS2::PaperFormat Units::stringToPaperFormat(const QString & p) { QString ls = p.toLower(); RS2::PaperFormat ret = RS2::Custom; @@ -1183,102 +1183,102 @@ RS2::PaperFormat RS_Units::stringToPaperFormat(const QString & p) /** * Performs some testing for the math class. */ -void RS_Units::test() +void Units::test() { QString s; double v; /* - std::cout << "RS_Units::test: formatLinear (decimal):\n"; + std::cout << "Units::test: formatLinear (decimal):\n"; v = 0.1; - s = RS_Units::formatLinear(v, RS2::Millimeter, RS2::Decimal, + s = Units::formatLinear(v, RS2::Millimeter, RS2::Decimal, 3, false); std::cout << "s: " << s << "\n"; assert(s=="0.1"); v = 0.01; - s = RS_Units::formatLinear(v, RS2::Millimeter, RS2::Decimal, + s = Units::formatLinear(v, RS2::Millimeter, RS2::Decimal, 3, false); std::cout << "s: " << s << "\n"; assert(s=="0.01"); v = 0.001; - s = RS_Units::formatLinear(v, RS2::Millimeter, RS2::Decimal, + s = Units::formatLinear(v, RS2::Millimeter, RS2::Decimal, 3, false); std::cout << "s: " << s << "\n"; assert(s=="0.001"); v = 0.009; - s = RS_Units::formatLinear(v, RS2::Millimeter, RS2::Decimal, + s = Units::formatLinear(v, RS2::Millimeter, RS2::Decimal, 2, false); std::cout << "s: " << s << "\n"; assert(s=="0.01"); v = 0.005; - s = RS_Units::formatLinear(v, RS2::Millimeter, RS2::Decimal, + s = Units::formatLinear(v, RS2::Millimeter, RS2::Decimal, 2, false); std::cout << "s: " << s << "\n"; assert(s=="0.01"); v = 0.0049999; - s = RS_Units::formatLinear(v, RS2::Millimeter, RS2::Decimal, + s = Units::formatLinear(v, RS2::Millimeter, RS2::Decimal, 2, false); std::cout << "s: " << s << "\n"; assert(s=="0"); v = 0.1; - s = RS_Units::formatLinear(v, RS2::Millimeter, RS2::Decimal, + s = Units::formatLinear(v, RS2::Millimeter, RS2::Decimal, 4, true); std::cout << "s: " << s << "\n"; assert(s=="0.1mm"); - std::cout << "RS_Units::test: formatLinear (fractional):\n"; + std::cout << "Units::test: formatLinear (fractional):\n"; v = 1.2; - s = RS_Units::formatLinear(v, RS2::Inch, RS2::Fractional, + s = Units::formatLinear(v, RS2::Inch, RS2::Fractional, 6, false); std::cout << "s: " << s << "\n"; assert(s=="1 13/64"); v = 1.2; - s = RS_Units::formatLinear(v, RS2::Inch, RS2::Fractional, + s = Units::formatLinear(v, RS2::Inch, RS2::Fractional, 8, false); std::cout << "s: " << s << "\n"; assert(s=="1 51/256"); v = 0.2; - s = RS_Units::formatLinear(v, RS2::Inch, RS2::Fractional, + s = Units::formatLinear(v, RS2::Inch, RS2::Fractional, 8, false); std::cout << "s: " << s << "\n"; assert(s=="51/256"); v = 4.5; - s = RS_Units::formatLinear(v, RS2::Inch, RS2::Fractional, + s = Units::formatLinear(v, RS2::Inch, RS2::Fractional, 6, true); std::cout << "s: " << s << "\n"; assert(s=="4 1/2"); v = 0.001; - s = RS_Units::formatLinear(v, RS2::Inch, RS2::Fractional, + s = Units::formatLinear(v, RS2::Inch, RS2::Fractional, 0, false); std::cout << "s: " << s << "\n"; assert(s=="0"); v = 0.01; - s = RS_Units::formatLinear(v, RS2::Inch, RS2::Fractional, + s = Units::formatLinear(v, RS2::Inch, RS2::Fractional, 8, false); std::cout << "s: " << s << "\n"; assert(s=="3/256"); v = 0.0078125; - s = RS_Units::formatLinear(v, RS2::Inch, RS2::Fractional, + s = Units::formatLinear(v, RS2::Inch, RS2::Fractional, 8, false); std::cout << "s: " << s << "\n"; assert(s=="1/128"); v = 0.001; - s = RS_Units::formatLinear(v, RS2::Inch, RS2::Fractional, + s = Units::formatLinear(v, RS2::Inch, RS2::Fractional, 8, false); std::cout << "s: " << s << "\n"; assert(s=="0"); v = 9.9999; - s = RS_Units::formatLinear(v, RS2::Inch, RS2::Fractional, + s = Units::formatLinear(v, RS2::Inch, RS2::Fractional, 6, false); std::cout << "s: " << s << "\n"; assert(s=="10"); @@ -1288,21 +1288,21 @@ void RS_Units::test() { for(int prec=0; prec<=6; ++prec) { - s = RS_Units::formatLinear(v, RS2::Inch, RS2::Architectural, prec, true); + s = Units::formatLinear(v, RS2::Inch, RS2::Architectural, prec, true); std::cout << "prec: " << prec << " v: " << v << " s: " << s.toAscii().data() << "\n"; } } /*for (v=0.0; v<10.0; v+=0.001) { - s = RS_Units::formatLinear(v, RS2::Foot, RS2::Fractional, + s = Units::formatLinear(v, RS2::Foot, RS2::Fractional, 1.0/128.0, true); std::cout << "v: " << v << " s: " << s << "\n"; }*/ /* - std::cout << "RS_Units::test: formatLinear (scientific):\n"; + std::cout << "Units::test: formatLinear (scientific):\n"; v = 0.001; - s = RS_Units::formatLinear(v, RS2::Millimeter, RS2::Scientific, + s = Units::formatLinear(v, RS2::Millimeter, RS2::Scientific, 0.0001, false); std::cout << "s: " << s << "\n"; assert(s=="1.0e-3"); @@ -1310,31 +1310,31 @@ void RS_Units::test() /* - std::cout << "RS_Units::test: formatAngle (deg / decimal):\n"; + std::cout << "Units::test: formatAngle (deg / decimal):\n"; v = 0.0261799; - s = RS_Units::formatAngle(v, RS2::DegreesDecimal, 2); + s = Units::formatAngle(v, RS2::DegreesDecimal, 2); std::cout << "s: " << s << "\n"; assert(s=="1.5�"); v = 0; - s = RS_Units::formatAngle(v, RS2::DegreesDecimal, 2); + s = Units::formatAngle(v, RS2::DegreesDecimal, 2); std::cout << "s: " << s << "\n"; assert(s=="0�"); v = 1.5707963; - s = RS_Units::formatAngle(v, RS2::DegreesDecimal, 2); + s = Units::formatAngle(v, RS2::DegreesDecimal, 2); std::cout << "s: " << s << "\n"; assert(s=="90�"); - std::cout << "RS_Units::test: formatAngle (deg / d/m/s):\n"; + std::cout << "Units::test: formatAngle (deg / d/m/s):\n"; v = 0.0260926; - s = RS_Units::formatAngle(v, RS2::DegreesMinutesSeconds, 1); + s = Units::formatAngle(v, RS2::DegreesMinutesSeconds, 1); std::cout << "s: " << s << "\n"; assert(s=="1� 29' 42\""); v = 0.0261799; - s = RS_Units::formatAngle(v, RS2::DegreesMinutesSeconds, 1); + s = Units::formatAngle(v, RS2::DegreesMinutesSeconds, 1); std::cout << "s: " << s << "\n"; assert(s=="1� 30' 0\""); */