The method draws continuous line between an ordered array of points (poly-line). Signed-off-by: Yordan Karadzhov (VMware) <y.karadz@xxxxxxxxx> --- src/libkshark-plot.c | 32 ++++++++++++++++++++++++++------ src/libkshark-plot.h | 5 +++++ 2 files changed, 31 insertions(+), 6 deletions(-) diff --git a/src/libkshark-plot.c b/src/libkshark-plot.c index f2c5be30..dc49fbd9 100644 --- a/src/libkshark-plot.c +++ b/src/libkshark-plot.c @@ -150,6 +150,30 @@ void ksplot_draw_line(const struct ksplot_point *a, glEnd(); } +/** + * @brief Draw the a polyline. + * + * @param points: Input location for the array of points defining the polyline. + * @param n_points: The size of the array of points. + * @param col: The color of the polyline. + * @param size: The size of the polyline. + */ +void ksplot_draw_polyline(const struct ksplot_point *points, + size_t n_points, + const struct ksplot_color *col, + float size) +{ + if (!points || !n_points || !col || size < .5f) + return; + + /* Loop over the points of the polygon and draw connecting lines. */ + for(size_t i = 1; i < n_points; ++i) + ksplot_draw_line(&points[i - 1], + &points[i], + col, + size); +} + /** * @brief Draw a polygon. * @@ -211,12 +235,8 @@ void ksplot_draw_polygon_contour(const struct ksplot_point *points, if (!points || !n_points || !col || size < .5f) return; - /* Loop over the points of the polygon and draw connecting lines. */ - for(size_t i = 1; i < n_points; ++i) - ksplot_draw_line(&points[i - 1], - &points[i], - col, - size); + /* Loop over the points of the polygon and draw a polyline. */ + ksplot_draw_polyline(points, n_points, col, size); /* Close the contour. */ ksplot_draw_line(&points[0], diff --git a/src/libkshark-plot.h b/src/libkshark-plot.h index 063740d9..d881b20a 100644 --- a/src/libkshark-plot.h +++ b/src/libkshark-plot.h @@ -72,6 +72,11 @@ void ksplot_draw_line(const struct ksplot_point *a, const struct ksplot_color *col, float size); +void ksplot_draw_polyline(const struct ksplot_point *points, + size_t n_points, + const struct ksplot_color *col, + float size); + void ksplot_draw_polygon(const struct ksplot_point *points, size_t n_points, const struct ksplot_color *col, -- 2.25.1