path-string.cpp revision 117336bcc334c1d380b7592f1639c1a586a28559
/*
* Inkscape::SVG::PathString - builder for SVG path strings
*
* Copyright 2008 Jasper van de Gronde <th.v.d.gronde@hccnet.nl>
*
* modify it under the terms of the GNU General Public License
* as published by the Free Software Foundation; either version 2
* of the License, or (at your option) any later version.
*
* See the file COPYING for details.
*
*/
#include "svg/path-string.h"
#include "svg/stringstream.h"
#include "prefs-utils.h"
#include <algorithm>
allow_relative_coordinates(0 != prefs_get_int_attribute("options.svgoutput", "allowrelativecoordinates", 1)),
{}
if ( _rel_state.str.size()+2 < _abs_state.str.size()+abs_added_size && allow_relative_coordinates ) {
// Copy rel to abs
abs_op_repeated = false;
// We do not have to copy abs to rel:
// _rel_state.str.size()+2 < _abs_state.str.size()+abs_added_size
// _rel_state.str.size()+rel_added_size < _abs_state.str.size()+2
// _abs_state.str.size()+2 > _rel_state.str.size()+rel_added_size
// Copy abs to rel
rel_op_repeated = false;
}
}
os << ' ' << v;
}
}
os << v;
double c;
rv = c;
/*{
Inkscape::SVGOStringStream ost;
ost << rv;
FILE* file = fopen("pathstring log.txt","at");
fprintf(file, "v: %g, rv: %g\n", v, rv);
fclose(file);
}
}*/
}
str += ' ';
str += ',';
}
str += ' ';
}
// NOTE: The following two appendRelative methods will not be exact if the total number of digits needed
// to represent the difference exceeds the precision of a double. This is not very likely though, and if
// it does happen the imprecise value is not likely to be chosen (because it will probably be a lot longer
// than the absolute value).
int digitsEnd = (int)floor(log10(std::min(fabs(v),fabs(r)))) - precision; // Position just beyond the last significant digit of the smallest (in absolute sense) number
if (r == 0) {
os << v;
} else if (v == 0) {
os << -r;
} else if (numDigits>0) {
os << (v-r);
} else {
// This assumes the input numbers are already rounded to 'precision' digits
os << '0';
}
{
/*double c;
sp_svg_number_read_d(os.str().c_str(), &c);
if (fabs((v-r)-c)>5.*pow(10.,digitsEnd)) {
FILE* file = fopen("pathstring log.txt","at");
fprintf(file, "bad, v: %.9g, r: %.9g, os: %s, c: %.12g, roundeddiff: %.12g, precision: %d, digitsEnd: %d, numDigits: %d\n", v, r, os.str().c_str(), c, roundeddiff, precision, digitsEnd, numDigits);
fclose(file);
}
Inkscape::SVGOStringStream ostr1, ostr2;
ostr1 << v;
ostr2 << (r+c);
FILE* file = fopen("pathstring log.txt","at");
fprintf(file, "bad, v: %.9g, r: %.9g, os: %s, c: %.12g, ostr1: %s, ostr2: %s, roundeddiff: %.12g\n", v, r, os.str().c_str(), c, ostr1.str().c_str(), ostr2.str().c_str(), roundeddiff);
fclose(file);
}*/
/*FILE* file = fopen("pathstring log.txt","at");
fprintf(file, "good, v: %.9g, r: %.9g, os: %s, c: %.12g, roundeddiff: %.12g, precision: %d, digitsEnd: %d, numDigits: %d\n", v, r, os.str().c_str(), c, roundeddiff, precision, digitsEnd, numDigits);
fclose(file);*/
}
}
str += ' ';
str += ',';
}
str += ' ';
appendRelativeCoord(str, v, r);
}
/*
Local Variables:
mode:c++
c-file-style:"stroustrup"
c-file-offsets:((innamespace . 0)(inline-open . 0)(case-label . +))
indent-tabs-mode:nil
fill-column:99
End:
*/
// vim: filetype=cpp:expandtab:shiftwidth=4:tabstop=8:softtabstop=4:encoding=utf-8:textwidth=99 :