Week 5 recap - Vector update

·

2 min read

Trying to do a vector approach which most other programs with the pixel-perfect algorithm uses. So currently we have a vector strokeCoordinate initiated in kistoolfreehand because that's where strokes gets initiated, doStroke, and endStroke are. The vector contains QPointF, Qpoint floats which is retrieved from convertToPixelCoord(event) and is the specific mini-coordinates of the canvas. These mini-coordinates are pushed in for every pointer event, which is pretty much every little mouse movement, gets rounded ( we can use .toPoint or qFLoor to determine where to actually draw) and put into another vector called points which uses Qpoint (integer version) instead.

To deal with the fact that the vector will contain multiples of the same coordinate in a row due to the way the functions are called per pointer event, we need to remove duplicates that are together. And now we can filter out the L-shapes using a similar function to libresprite (which is explained previously ->while the current point is not the first or the last point in the vector, m_pts[c - 1].x == m_pts[c].x || m_pts[c - 1].y == m_pts[c].y checks if the previous point shares either the same x or y coordinate with the current point, and subsequently m_pts[c+1].x == m_pts[c].x || m_pts[c+1].y == m_pts[c].y checks if the next point shares either the same x or y coordinate with the current point. Then the rest of the code makes sure that the previous and next points do not share the x and y coordinates.) Right now this whole ordeal does somewhat work but the problem is the vector isn't completely accurate for what points go in, due to the fact that it reads in every little one of those smaller QpointFs some of which doesn't get drawn because they don't meet the threshold.

The goal here is to use this vector in kis_brushop and call drawDDALine on this vector. Hopefully we can just call drawDDAline in paintLine using each Qpoint as both the start and end points. A few problems with this is 1.) the accuracy problem where some stray points get in the vector ( we might need set some sort of threshold in doStroke when populating ), 2.) I'm not too sure how to handle passing the vector from kis_tool_freehand to kis_brushop 3.) we need to make sure we are not compromising on speed with this approach.