/**
* 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;
/**
* @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 = "";
* @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 = "";
/**
* 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;
/**
* @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
/**
* @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;
/**
* 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)
{
}
else
{
- RS_DEBUG->print(RS_Debug::D_WARNING, "RS_Units::convert: invalid factor");
+ DEBUG->print(Debug::D_WARNING, "Units::convert: invalid factor");
return val;
}
}
/**
* 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));
}
* @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;
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;
}
* @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;
* @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;
if (showUnit)
unitString = unitToSign(unit);
- ret = RS_Math::doubleToString(length, prec);
+ ret = Math::doubleToString(length, prec);
if (showUnit)
ret += unitString;
* @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;
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")
{
* @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);
* @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;
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)
// Simplify the fraction
if (nominator != 0 && denominator != 0)
{
- int gcd = RS_Math::findGCD(nominator, denominator);
+ int gcd = Math::findGCD(nominator, denominator);
if (gcd != 0)
{
}
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;
}
*
* @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;
{
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;
}
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);
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")
{
/**
* @return Size of the given paper format.
*/
-Vector RS_Units::paperFormatToSize(RS2::PaperFormat p)
+Vector Units::paperFormatToSize(RS2::PaperFormat p)
{
Vector ret(false);
* 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)
/**
* 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 = "";
/**
* 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;
/**
* 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");
{
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");
/*
- 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\"");
*/