Skip to content

Commit

Permalink
Update stroke recognizer to preserve line endpoints. (#3285)
Browse files Browse the repository at this point in the history
* Update stroke recognizer so recognized lines preserve endpoints.

* Fix vertical/horizontal line drawing
  • Loading branch information
kenballus committed Aug 4, 2021
1 parent b20500b commit 5b4bc64
Showing 1 changed file with 13 additions and 5 deletions.
18 changes: 13 additions & 5 deletions src/control/shaperecognizer/ShapeRecognizer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -297,22 +297,30 @@ auto ShapeRecognizer::recognizePatterns(Stroke* stroke) -> ShapeRecognizerResult

if (n == 1) // current stroke is a line
{
bool aligned = true;
if (fabs(rs->angle) < SLANT_TOLERANCE) // nearly horizontal
{
rs->angle = 0.0;
rs->y1 = rs->y2 = rs->ycenter;
}
if (fabs(rs->angle) > M_PI / 2 - SLANT_TOLERANCE) // nearly vertical
{
} else if (fabs(rs->angle) > M_PI / 2 - SLANT_TOLERANCE) { // nearly vertical
rs->angle = (rs->angle > 0) ? (M_PI / 2) : (-M_PI / 2);
rs->x1 = rs->x2 = rs->xcenter;
} else {
aligned = false;
}

auto* s = new Stroke();
s->applyStyleFrom(this->stroke);

s->addPoint(Point(rs->x1, rs->y1));
s->addPoint(Point(rs->x2, rs->y2));
if (aligned) {
s->addPoint(Point(rs->x1, rs->y1));
s->addPoint(Point(rs->x2, rs->y2));
} else {
auto points = stroke->getPointVector();
s->addPoint(points.front());
s->addPoint(points.back());
}

rs->stroke = s;
auto* result = new ShapeRecognizerResult(s);
RDEBUG("return line");
Expand Down

0 comments on commit 5b4bc64

Please sign in to comment.