[consider merging] incremental value placeholders for rulers

This commit is contained in:
Matthias Koefferlein 2026-01-18 18:27:54 +01:00
parent c2c941078d
commit 18c2f5dfa4
2 changed files with 102 additions and 41 deletions

View File

@ -426,7 +426,24 @@ class AnnotationEvalFunction
: public tl::EvalFunction : public tl::EvalFunction
{ {
public: public:
AnnotationEvalFunction (char function, const AnnotationEval *eval, size_t index) enum FunctionType {
ManhattanLength, // L
ManhattanLengthIncremental, // LL
EuclidianDistance, // D
EuclidianDistanceIncremental, // DD
XDelta, // X
XDeltaIncremental, // XX
YDelta, // Y
YDeltaIncremental, // YY
P1X, // U
P1Y, // V
P2X, // P
P2Y, // Q
Area, // A
Angle // G
};
AnnotationEvalFunction (FunctionType function, const AnnotationEval *eval, size_t index)
: m_function (function), mp_eval (eval), m_index (index) : m_function (function), mp_eval (eval), m_index (index)
{ {
// .. nothing yet .. // .. nothing yet ..
@ -441,25 +458,53 @@ public:
const Object &obj = mp_eval->obj (); const Object &obj = mp_eval->obj ();
const db::DFTrans &trans = mp_eval->trans (); const db::DFTrans &trans = mp_eval->trans ();
if (m_function == 'L') { if (m_function == ManhattanLength) {
out = fabs (delta_x (obj, trans)) + fabs (delta_y (obj, trans)); out = fabs (delta_x (obj, trans, m_index)) + fabs (delta_y (obj, trans, m_index));
} else if (m_function == 'D') { } else if (m_function == ManhattanLengthIncremental) {
out = sqrt (delta_x (obj, trans) * delta_x (obj, trans) + delta_y (obj, trans) * delta_y (obj, trans)); double res = 0.0;
} else if (m_function == 'A') { for (size_t index = 0; index <= m_index; ++index) {
out = delta_x (obj, trans) * delta_y (obj, trans) * 1e-6; res += fabs (delta_x (obj, trans, index)) + fabs (delta_y (obj, trans, index));
} else if (m_function == 'X') { }
out = delta_x (obj, trans); out = res;
} else if (m_function == 'Y') { } else if (m_function == EuclidianDistance) {
out = delta_y (obj, trans); auto dx = delta_x (obj, trans, m_index);
} else if (m_function == 'U') { auto dy = delta_y (obj, trans, m_index);
out = (trans * p1 (obj)).x (); out = sqrt (dx * dx + dy * dy);
} else if (m_function == 'V') { } else if (m_function == EuclidianDistanceIncremental) {
out = (trans * p1 (obj)).y (); double res = 0.0;
} else if (m_function == 'P') { for (size_t index = 0; index <= m_index; ++index) {
out = (trans * p2 (obj)).x (); auto dx = delta_x (obj, trans, index);
} else if (m_function == 'Q') { auto dy = delta_y (obj, trans, index);
out = (trans * p2 (obj)).y (); res += sqrt (dx * dx + dy * dy);
} else if (m_function == 'G') { }
out = res;
} else if (m_function == Area) {
out = delta_x (obj, trans, m_index) * delta_y (obj, trans, m_index) * 1e-6;
} else if (m_function == XDelta) {
out = delta_x (obj, trans, m_index);
} else if (m_function == XDeltaIncremental) {
double res = 0.0;
for (size_t index = 0; index <= m_index; ++index) {
res += delta_x (obj, trans, index);
}
out = res;
} else if (m_function == YDelta) {
out = delta_y (obj, trans, m_index);
} else if (m_function == YDeltaIncremental) {
double res = 0.0;
for (size_t index = 0; index <= m_index; ++index) {
res += delta_y (obj, trans, index);
}
out = res;
} else if (m_function == P1X) {
out = (trans * p1 (obj, m_index)).x ();
} else if (m_function == P1Y) {
out = (trans * p1 (obj, m_index)).y ();
} else if (m_function == P2X) {
out = (trans * p2 (obj, m_index)).x ();
} else if (m_function == P2Y) {
out = (trans * p2 (obj, m_index)).y ();
} else if (m_function == Angle) {
double r, a1, a2; double r, a1, a2;
db::DPoint c; db::DPoint c;
if (obj.compute_angle_parameters (r, c, a1, a2)) { if (obj.compute_angle_parameters (r, c, a1, a2)) {
@ -472,20 +517,20 @@ public:
} }
} }
db::DPoint p1 (const Object &obj) const db::DPoint p1 (const Object &obj, size_t index) const
{ {
return obj.seg_p1 (m_index); return obj.seg_p1 (index);
} }
db::DPoint p2 (const Object &obj) const db::DPoint p2 (const Object &obj, size_t index) const
{ {
return obj.seg_p2 (m_index); return obj.seg_p2 (index);
} }
double double
delta_x (const Object &obj, const db::DFTrans &t) const delta_x (const Object &obj, const db::DFTrans &t, size_t index) const
{ {
double dx = ((t * p2 (obj)).x () - (t * p1 (obj)).x ()); double dx = ((t * p2 (obj, index)).x () - (t * p1 (obj, index)).x ());
// avoid "almost 0" outputs // avoid "almost 0" outputs
if (fabs (dx) < 1e-5 /*micron*/) { if (fabs (dx) < 1e-5 /*micron*/) {
@ -496,9 +541,9 @@ public:
} }
double double
delta_y (const Object &obj, const db::DFTrans &t) const delta_y (const Object &obj, const db::DFTrans &t, size_t index) const
{ {
double dy = ((t * p2 (obj)).y () - (t * p1 (obj)).y ()); double dy = ((t * p2 (obj, index)).y () - (t * p1 (obj, index)).y ());
// avoid "almost 0" outputs // avoid "almost 0" outputs
if (fabs (dy) < 1e-5 /*micron*/) { if (fabs (dy) < 1e-5 /*micron*/) {
@ -509,7 +554,7 @@ public:
} }
private: private:
char m_function; FunctionType m_function;
const AnnotationEval *mp_eval; const AnnotationEval *mp_eval;
size_t m_index; size_t m_index;
}; };
@ -518,16 +563,20 @@ std::string
Object::formatted (const std::string &fmt, const db::DFTrans &t, size_t index) const Object::formatted (const std::string &fmt, const db::DFTrans &t, size_t index) const
{ {
AnnotationEval eval (*this, t); AnnotationEval eval (*this, t);
eval.define_function ("L", new AnnotationEvalFunction('L', &eval, index)); // manhattan length eval.define_function ("L", new AnnotationEvalFunction (AnnotationEvalFunction::ManhattanLength, &eval, index)); // manhattan length
eval.define_function ("D", new AnnotationEvalFunction('D', &eval, index)); // euclidian distance eval.define_function ("LL", new AnnotationEvalFunction (AnnotationEvalFunction::ManhattanLengthIncremental, &eval, index)); // manhattan length
eval.define_function ("X", new AnnotationEvalFunction('X', &eval, index)); // x delta eval.define_function ("D", new AnnotationEvalFunction (AnnotationEvalFunction::EuclidianDistance, &eval, index)); // euclidian distance
eval.define_function ("Y", new AnnotationEvalFunction('Y', &eval, index)); // y delta eval.define_function ("DD", new AnnotationEvalFunction (AnnotationEvalFunction::EuclidianDistanceIncremental, &eval, index)); // euclidian distance (incremental, for multi-rulers)
eval.define_function ("U", new AnnotationEvalFunction('U', &eval, index)); // p1.x eval.define_function ("X", new AnnotationEvalFunction (AnnotationEvalFunction::XDelta, &eval, index)); // x delta
eval.define_function ("V", new AnnotationEvalFunction('V', &eval, index)); // p1.y eval.define_function ("XX", new AnnotationEvalFunction (AnnotationEvalFunction::XDeltaIncremental, &eval, index)); // x delta (incremental, for multi-rulers)
eval.define_function ("P", new AnnotationEvalFunction('P', &eval, index)); // p2.x eval.define_function ("Y", new AnnotationEvalFunction (AnnotationEvalFunction::YDelta, &eval, index)); // y delta
eval.define_function ("Q", new AnnotationEvalFunction('Q', &eval, index)); // p2.y eval.define_function ("YY", new AnnotationEvalFunction (AnnotationEvalFunction::YDeltaIncremental, &eval, index)); // y delta (incremental, for multi-rulers)
eval.define_function ("A", new AnnotationEvalFunction('A', &eval, index)); // area mm2 eval.define_function ("U", new AnnotationEvalFunction (AnnotationEvalFunction::P1X, &eval, index)); // p1.x
eval.define_function ("G", new AnnotationEvalFunction('G', &eval, index)); // angle (if applicable) eval.define_function ("V", new AnnotationEvalFunction (AnnotationEvalFunction::P1Y, &eval, index)); // p1.y
eval.define_function ("P", new AnnotationEvalFunction (AnnotationEvalFunction::P2X, &eval, index)); // p2.x
eval.define_function ("Q", new AnnotationEvalFunction (AnnotationEvalFunction::P2Y, &eval, index)); // p2.y
eval.define_function ("A", new AnnotationEvalFunction (AnnotationEvalFunction::Area, &eval, index)); // area mm2
eval.define_function ("G", new AnnotationEvalFunction (AnnotationEvalFunction::Angle, &eval, index)); // angle (if applicable)
return eval.interpolate (fmt); return eval.interpolate (fmt);
} }

View File

@ -54,7 +54,7 @@
<ul> <ul>
<li><b>$X</b>: The value of the X variable (the horizontal distance, see below for a complete list of variables).</li> <li><b>$X</b>: The value of the X variable (the horizontal distance, see below for a complete list of variables).</li>
<li><b>$(sprintf('%.2f',X))</b>: The value of the 'X' variable formatted as two digit fixed precision value.</li> <li><b>$(sprintf('%.2f',X))</b>: The value of the 'X' variable formatted as two digit fixed precision value.</li>
<li><b>$(abs(X)+abs(Y))</b>: The manhattan distance of the ruler.</li> <li><b>$(abs(X)+abs(Y))</b>: The Manhattan distance of the ruler.</li>
<li><b>$min(X,Y)</b>: The minimum of X and Y.</li> <li><b>$min(X,Y)</b>: The minimum of X and Y.</li>
</ul> </ul>
@ -68,7 +68,7 @@
<ul> <ul>
<li><b>D:</b> The length of the ruler in micron units.</li> <li><b>D:</b> The length of the ruler in micron units.</li>
<li><b>L:</b> The manhattan length of the ruler in micron units.</li> <li><b>L:</b> The Manhattan length of the ruler in micron units.</li>
<li><b>U:</b> The x-position of the ruler's first point in micron units.</li> <li><b>U:</b> The x-position of the ruler's first point in micron units.</li>
<li><b>V:</b> The y-position of the ruler's first point in micron units.</li> <li><b>V:</b> The y-position of the ruler's first point in micron units.</li>
<li><b>P:</b> The x-position of the ruler's second point in micron units.</li> <li><b>P:</b> The x-position of the ruler's second point in micron units.</li>
@ -79,5 +79,17 @@
<li><b>G:</b> The angle enclosed by the first and last segment of the ruler (used for angle measurement rulers).</li> <li><b>G:</b> The angle enclosed by the first and last segment of the ruler (used for angle measurement rulers).</li>
</ul> </ul>
<p>
For multi-rulers additional variables are provided for "incremental" values.
These are the sums of the respective values up to the given part:
</p>
<ul>
<li><b>DD:</b> The sum of all lengths.</li>
<li><b>LL:</b> The sum of all Manhattan.</li>
<li><b>XX:</b> The horizonal distance between first and current point.</li>
<li><b>YY:</b> The vertical distance between first and current point.</li>
</ul>
</doc> </doc>