From 5dcd983ee3bf3525055f0f3fc6d70490e6ecf5b5 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=C3=89milie=20Feral?= Date: Tue, 17 Sep 2019 17:30:29 +0200 Subject: [PATCH] =?UTF-8?q?[apps/graph]=20GraphView:=20change=20the=20step?= =?UTF-8?q?=20with=20which=20the=20function=20is=20evaluated=20to=20draw?= =?UTF-8?q?=20curve.=20Fix=20bug:=20polar=20function=20sin(5=CE=B8)=20was?= =?UTF-8?q?=20not=20drawn=20at=20all?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- apps/graph/graph/graph_view.cpp | 13 ++++++++++++- 1 file changed, 12 insertions(+), 1 deletion(-) 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) {