如何在 c++ 中从 rosettacode 调用这个吴晓林的直线算法

How to calling this Xiaolin Wu's line algorithm from rosettacode in c++

本文关键字:吴晓林 算法 调用 c++ 中从 rosettacode      更新时间:2023-10-16

我正在尝试调用吴的线性算法。我从rosettacode.org上找到了一个版本,但我不知道如何称呼它。

以下是链接:https://rosettacode.org/wiki/Xiaolin_Wu%27s_line_algorithm#C.2B.2B

我不理解的这个部分

const std::function<void(int x, int y, float brightness)>& plot

你能给我举个调用这个函数的例子吗。

这只是意味着最后一个参数是一个在给定坐标和所需亮度的情况下绘制点的函数。

它允许不同的风格,例如使用函数指针或lambdas。

void my_plot(int x, int y, float brightness) {
// plot things
}
int main() { 
WuDrawLine(0, 0, 100, 256, my_plot);
WuDrawLine(0, 100, 0, 256, [](int x, int y, float brightness) { /*do stuff*/ });
return 0;
}