Merge branch 'fs_dir_per_glyph_SPE-1597' into fs_svg

This commit is contained in:
Filip Sykala - NTB T15p 2023-08-08 17:14:27 +02:00
commit d7335a383f
2 changed files with 50 additions and 47 deletions

View File

@ -146,67 +146,68 @@ std::vector<ExtendedPoint> estimate_points_properties(const POINTS
std::vector<float> angles_for_curvature(points.size()); std::vector<float> angles_for_curvature(points.size());
std::vector<float> distances_for_curvature(points.size()); std::vector<float> distances_for_curvature(points.size());
for (int point_idx = 0; point_idx < int(points.size()); ++point_idx) { for (size_t point_idx = 0; point_idx < points.size(); ++point_idx) {
ExtendedPoint &a = points[point_idx]; ExtendedPoint &a = points[point_idx];
ExtendedPoint &prev = points[point_idx > 0 ? point_idx - 1 : point_idx]; size_t prev = prev_idx_modulo(point_idx, points.size());
size_t next = next_idx_modulo(point_idx, points.size());
int prev_point_idx = point_idx; int iter_limit = points.size();
while (prev_point_idx > 0) { while ((a.position - points[prev].position).squaredNorm() < 1 && iter_limit > 0) {
prev_point_idx--; prev = prev_idx_modulo(prev, points.size());
if ((a.position - points[prev_point_idx].position).squaredNorm() > EPSILON) { iter_limit--;
break;
}
} }
int next_point_index = point_idx; while ((a.position - points[next].position).squaredNorm() < 1 && iter_limit > 0) {
while (next_point_index < int(points.size()) - 1) { next = next_idx_modulo(next, points.size());
next_point_index++; iter_limit--;
if ((a.position - points[next_point_index].position).squaredNorm() > EPSILON) {
break;
}
} }
distances_for_curvature[point_idx] = (prev.position - a.position).norm(); distances_for_curvature[point_idx] = (points[prev].position - a.position).norm();
if (prev_point_idx != point_idx && next_point_index != point_idx) { float alfa = angle(a.position - points[prev].position, points[next].position - a.position);
float alfa = angle(a.position - points[prev_point_idx].position, points[next_point_index].position - a.position); angles_for_curvature[point_idx] = alfa;
angles_for_curvature[point_idx] = alfa;
} // else keep zero
} }
for (float window_size : {3.0f, 9.0f, 16.0f}) { if (std::accumulate(distances_for_curvature.begin(), distances_for_curvature.end(), 0) > EPSILON)
size_t tail_point = 0; for (float window_size : {3.0f, 9.0f, 16.0f}) {
float tail_window_acc = 0; size_t tail_point = 0;
float tail_angle_acc = 0; float tail_window_acc = 0;
float tail_angle_acc = 0;
size_t head_point = 0; size_t head_point = 0;
float head_window_acc = 0; float head_window_acc = 0;
float head_angle_acc = 0; float head_angle_acc = 0;
for (int point_idx = 0; point_idx < int(points.size()); ++point_idx) { for (size_t point_idx = 0; point_idx < points.size(); ++point_idx) {
if (point_idx > 0) { if (point_idx == 0) {
tail_window_acc += distances_for_curvature[point_idx - 1]; while (tail_window_acc < window_size * 0.5) {
tail_angle_acc += angles_for_curvature[point_idx - 1]; tail_window_acc += distances_for_curvature[tail_point];
head_window_acc -= distances_for_curvature[point_idx - 1]; tail_angle_acc += angles_for_curvature[tail_point];
head_angle_acc -= angles_for_curvature[point_idx - 1]; tail_point = prev_idx_modulo(tail_point, points.size());
} }
while (tail_window_acc > window_size * 0.5 && int(tail_point) < point_idx) { }
tail_window_acc -= distances_for_curvature[tail_point]; while (tail_window_acc - distances_for_curvature[next_idx_modulo(tail_point, points.size())] > window_size * 0.5) {
tail_angle_acc -= angles_for_curvature[tail_point]; tail_point = next_idx_modulo(tail_point, points.size());
tail_point++; tail_window_acc -= distances_for_curvature[tail_point];
} tail_angle_acc -= angles_for_curvature[tail_point];
}
while (head_window_acc < window_size * 0.5 && int(head_point) < int(points.size()) - 1) { while (head_window_acc < window_size * 0.5) {
head_window_acc += distances_for_curvature[head_point]; head_point = next_idx_modulo(head_point, points.size());
head_angle_acc += angles_for_curvature[head_point]; head_window_acc += distances_for_curvature[head_point];
head_point++; head_angle_acc += angles_for_curvature[head_point];
} }
float curvature = (tail_angle_acc + head_angle_acc) / (tail_window_acc + head_window_acc); float curvature = (tail_angle_acc + head_angle_acc) / window_size;
if (std::abs(curvature) > std::abs(points[point_idx].curvature)) { if (std::abs(curvature) > std::abs(points[point_idx].curvature)) {
points[point_idx].curvature = curvature; points[point_idx].curvature = curvature;
}
tail_window_acc += distances_for_curvature[point_idx];
tail_angle_acc += angles_for_curvature[point_idx];
head_window_acc -= distances_for_curvature[point_idx];
head_angle_acc -= angles_for_curvature[point_idx];
} }
} }
}
return points; return points;
} }

View File

@ -588,6 +588,8 @@ bool TextCtrl::value_was_changed()
case coFloatOrPercent: case coFloatOrPercent:
case coFloatsOrPercents: case coFloatsOrPercents:
return boost::any_cast<std::string>(m_value) != boost::any_cast<std::string>(val); return boost::any_cast<std::string>(m_value) != boost::any_cast<std::string>(val);
case coPoints:
return boost::any_cast<std::vector<Vec2d>>(m_value) != boost::any_cast<std::vector<Vec2d>>(val);
default: default:
return true; return true;
} }