diff --git a/apps/graph/graph/graph_view.cpp b/apps/graph/graph/graph_view.cpp index 739225465..3efd6a1ca 100644 --- a/apps/graph/graph/graph_view.cpp +++ b/apps/graph/graph/graph_view.cpp @@ -31,7 +31,18 @@ void GraphView::drawRect(KDContext * ctx, KDRect rect) const { Shared::CartesianFunction::PlotType type = f->plotType(); float tmin = f->tMin(); float tmax = f->tMax(); - float tstep = (tmax-tmin)/10.0f; + /* The step is a fraction of tmax-tmin. We will evaluate the function at + * every step and if the consecutive dots are close enough, we won't + * evaluate any more dot within the step. We pick a very strange fraction + * denominator to avoid evaluating a periodic function periodically. For + * example, if tstep was (tmax - tmin)/10, the polar function r(θ) = sin(5θ) + * defined on 0..2π would be evaluated on r(0) = 0, r(π/5) = 0, r(2*π/5) = 0 + * which would lead to no curve at all. With 10.0938275501223, the + * problematic functions are the functions whose period is proportionned to + * 10.0938275501223 which are hopefully rare enough. + * TODO: The drawCurve algorithm should use the derivative function to know + * how fast the function moves... */ + float tstep = (tmax-tmin)/10.0938275501223f; // Cartesian if (type == Shared::CartesianFunction::PlotType::Cartesian) {