[apps/shared][python/port] CurveView::drawArrow uses pixel computation

instead of float computation to avoid precision errors, by default the
arrow size is decided in pixels.
This commit is contained in:
Émilie Feral
2020-06-03 12:17:08 +02:00
parent a9fbcf99b2
commit 420dd04766
5 changed files with 63 additions and 22 deletions

View File

@@ -106,7 +106,9 @@ mp_obj_t modpyplot_arrow(size_t n_args, const mp_obj_t *args, mp_map_t* kw_args)
mp_map_elem_t * elem;
// Setting arrow width
elem = mp_map_lookup(kw_args, MP_OBJ_NEW_QSTR(MP_QSTR_head_width), MP_MAP_LOOKUP);
mp_obj_t arrowWidth = (elem == nullptr) ? mp_obj_new_float(0.003) : elem->value;
/* Default head_width is 0.0f because we want a default width in pixel
* coordinates which is handled by CurveView::drawArrow. */
mp_obj_t arrowWidth = (elem == nullptr) ? mp_obj_new_float(0.0f) : elem->value;
// Setting arrow color
KDColor color;

View File

@@ -78,7 +78,7 @@ public:
KDColor m_color;
};
void addSegment(mp_obj_t xStart, mp_obj_t yStart, mp_obj_t xEnd, mp_obj_t yEnd, KDColor c, mp_obj_t arrowWidth = mp_obj_new_float(0.0));
void addSegment(mp_obj_t xStart, mp_obj_t yStart, mp_obj_t xEnd, mp_obj_t yEnd, KDColor c, mp_obj_t arrowWidth = mp_obj_new_float(NAN));
Iterable<ListIterator<Segment>> segments() { return Iterable<ListIterator<Segment>>(m_segments); }
// Rect

View File

@@ -46,7 +46,7 @@ void PlotView::traceSegment(KDContext * ctx, KDRect r, PlotStore::Segment segmen
segment.xEnd(), segment.yEnd(),
segment.color()
);
if (segment.arrowWidth() > 0.0f) {
if (!std::isnan(segment.arrowWidth())) {
float dx = segment.xEnd() - segment.xStart();
float dy = segment.yEnd() - segment.yStart();
drawArrow(ctx, r, segment.xEnd(), segment.yEnd(), dx, dy, segment.color(), segment.arrowWidth());