差分
このページの2つのバージョン間の差分を表示します。
| 両方とも前のリビジョン前のリビジョン次のリビジョン | 前のリビジョン | ||
| cgfs:filled_triangles [2025/12/12 15:14] – using std::swap; freemikan | cgfs:filled_triangles [2025/12/12 15:59] (現在) – Replace an overused back_inserter freemikan | ||
|---|---|---|---|
| 行 8: | 行 8: | ||
| #include < | #include < | ||
| + | #include < | ||
| #include < | #include < | ||
| #include < | #include < | ||
| 行 15: | 行 16: | ||
| #include " | #include " | ||
| - | int const Cw = 600; | + | int const Cw = 600; // Canvas width |
| - | int const Ch = 600; | + | int const Ch = 600; // Canvas height |
| using vec2 = vmath:: | using vec2 = vmath:: | ||
| 行 32: | 行 33: | ||
| } | } | ||
| - | | + | |
| - | | + | |
| for (int i = i0; i <= i1; ++i) { | for (int i = i0; i <= i1; ++i) { | ||
| - | *out++ = d; | + | *out = d; |
| + | ++out; | ||
| d += a; | d += a; | ||
| } | } | ||
| 行 54: | 行 56: | ||
| swap(y0, y1); | swap(y0, y1); | ||
| } | } | ||
| - | | + | |
| - | | + | |
| - | | + | std:: |
| Interpolate(i0, | Interpolate(i0, | ||
| 行 68: | 行 70: | ||
| swap(x0, x1); | swap(x0, x1); | ||
| } | } | ||
| - | | + | |
| - | | + | |
| - | | + | std:: |
| Interpolate(i0, | Interpolate(i0, | ||
| 行 106: | 行 108: | ||
| } | } | ||
| - | | + | |
| - | | + | |
| - | | + | |
| - | | + | std:: |
| - | | + | std:: |
| - | | + | std:: |
| Interpolate(i0, | Interpolate(i0, | ||
| 行 117: | 行 119: | ||
| Interpolate(i0, | Interpolate(i0, | ||
| + | // remove an overlapping point at x01.back and x12.front | ||
| x01.pop_back(); | x01.pop_back(); | ||
| - | | + | std:: |
| - | | + | |
| - | | + | |
| - | std:: | + | |
| auto &x_left = x012; | auto &x_left = x012; | ||
| 行 133: | 行 135: | ||
| for (int y = i0; y < i2; ++y) { | for (int y = i0; y < i2; ++y) { | ||
| - | | + | |
| - | | + | |
| for (int x = x_l; x <= x_r; ++x) { | for (int x = x_l; x <= x_r; ++x) { | ||
| PutPixel(x, y, color); | PutPixel(x, y, color); | ||
