Release v0.6.25: recognize pencil strokes as straight lines

This commit is contained in:
2026-11-01 23:00:59 +02:00
parent 20f3b72287
commit 908985d775
11 changed files with 80 additions and 21 deletions
+29
View File
@@ -1,6 +1,35 @@
#pragma once
inline void testStrokeImprovement() {
auto require=[](bool ok,const char *message){if(!ok) throw std::runtime_error(message);};
for(double angle:{0.0,.37,1.57079632679,2.8}) for(bool reverse:{false,true}) {
std::vector<POINT> p;
for(int i=0;i<=20;++i) {
double x=i*10,y=i==0 || i==20?0:(i%3)-1;
p.push_back({LONG(std::lround(300+x*std::cos(angle)-y*std::sin(angle))),
LONG(std::lround(300+x*std::sin(angle)+y*std::cos(angle)))});
}
if(reverse) std::reverse(p.begin(),p.end());
bool line=false; ks::ScreenshotShape shape{};
auto result=ks::improveScreenshotStroke(p,&shape,&line);
require(line && shape==ks::ScreenshotShape::None && result.size()==2 &&
result.front().x==p.front().x && result.front().y==p.front().y &&
result.back().x==p.back().x && result.back().y==p.back().y,
"recognize noisy lines at arbitrary angles and preserve directed endpoints");
}
for(auto p:std::vector<std::vector<POINT>>{
{{0,0},{50,1},{100,0}}, {{0,0},{0,0},{50,0},{100,0}}}) {
bool line=false;
require(ks::improveScreenshotStroke(p,nullptr,&line).size()==2 && line,
"recognize sparsely sampled lines and repeated mouse positions");
}
for(auto p:std::vector<std::vector<POINT>>{
{{0,0},{8,1},{16,0}}, {{0,0},{50,0},{40,0},{80,0},{100,0}},
{{0,0},{25,8},{50,12},{75,8},{100,0}},
{{0,0},{50,0},{51,10},{52,0},{100,0}}, {{0,0},{0,0},{0,0}}}) {
bool line=true;
ks::improveScreenshotStroke(p,nullptr,&line);
require(!line,"do not straighten short strokes, retracing, curves, spikes or stationary input");
}
auto path=[](std::vector<POINT> corners) {
std::vector<POINT> p;
for(size_t i=1;i<corners.size();++i) for(int j=0;j<25;++j) {