42 if (
callback(x1, y1, user_data) == 0) {
47 const int sign_x = (x2 > x1) ? 1 : -1;
48 const int sign_y = (y2 > y1) ? 1 : -1;
50 const int delta_x = (sign_x == 1) ? (x2 - x1) : (x1 - x2);
51 const int delta_y = (sign_y == 1) ? (y2 - y1) : (y1 - y2);
53 const int delta_x_step = delta_x * 2;
54 const int delta_y_step = delta_y * 2;
56 if (delta_x >= delta_y) {
58 int error = delta_y_step - delta_x;
62 if (
error || (sign_x == 1)) {
64 error -= delta_x_step;
71 error += delta_y_step;
73 if (
callback(x1, y1, user_data) == 0) {
80 int error = delta_x_step - delta_y;
84 if (
error || (sign_y == 1)) {
86 error -= delta_y_step;
93 error += delta_x_step;
95 if (
callback(x1, y1, user_data) == 0) {
213 void (*
callback)(
int x,
int x_end,
int y,
void *),
222 if (p2[1] == p3[1]) {
229 else if (p1[1] == p2[1]) {
244 const float inv_slope_p21 =
inv_slope(p2, p1);
245 const float inv_slope_p31 =
inv_slope(p3, p1);
246 const float inv_slope_p32 =
inv_slope(p3, p2);
248 float inv_slope1_max, inv_slope2_max;
249 float inv_slope2_min, inv_slope1_min;
251 if (inv_slope_p21 < inv_slope_p31) {
252 inv_slope1_max = inv_slope_p21;
253 inv_slope2_max = inv_slope_p31;
254 inv_slope2_min = inv_slope_p31;
255 inv_slope1_min = inv_slope_p32;
258 inv_slope1_max = inv_slope_p31;
259 inv_slope2_max = inv_slope_p21;
260 inv_slope2_min = inv_slope_p32;
261 inv_slope1_min = inv_slope_p31;
325 void (*
callback)(
int x,
int x_end,
int y,
void *),
334 for (
int i_curr = 0, i_prev =
int(
verts.size() - 1); i_curr <
verts.size(); i_prev = i_curr++) {
335 const int *co_prev =
verts[i_prev];
336 const int *co_curr =
verts[i_curr];
338 if (co_prev[1] != co_curr[1]) {
340 if ((
min_ii(co_prev[1], co_curr[1]) >= ymax) || (
max_ii(co_prev[1], co_curr[1]) < ymin)) {
344 int *s = span_y[span_y_len++];
345 if (co_prev[1] < co_curr[1]) {
360 (
void *)
verts.data());
368 int span_y_index = 0;
369 if (span_y_len != 0 &&
verts[span_y[0][0]][1] < ymin) {
370 while ((span_y_index < span_y_len) && (
verts[span_y[span_y_index][0]][1] < ymin)) {
372 if (
verts[span_y[span_y_index][1]][1] >= ymin) {
373 NodeX *n = &node_x[node_x_len++];
374 n->span_y_index = span_y_index;
381 for (
int pixel_y = ymin; pixel_y < ymax; pixel_y++) {
382 bool is_sorted =
true;
383 bool do_remove =
false;
385 for (
int i = 0, x_ix_prev = INT_MIN; i < node_x_len; i++) {
386 NodeX *n = &node_x[i];
387 const int *s = span_y[n->span_y_index];
388 const int *co_prev =
verts[s[0]];
389 const int *co_curr =
verts[s[1]];
391 BLI_assert(co_prev[1] < pixel_y && co_curr[1] >= pixel_y);
393 const double x = (co_prev[0] - co_curr[0]);
394 const double y = (co_prev[1] - co_curr[1]);
395 const double y_px = (pixel_y - co_curr[1]);
396 const int x_ix = int(
double(co_curr[0]) + ((y_px /
y) *
x));
399 if (is_sorted && (x_ix_prev > x_ix)) {
402 if (do_remove ==
false && co_curr[1] == pixel_y) {
409 if (is_sorted ==
false) {
411 const int node_x_end = node_x_len - 1;
412 while (i < node_x_end) {
413 if (node_x[i].
x > node_x[i + 1].
x) {
414 SWAP(NodeX, node_x[i], node_x[i + 1]);
426 for (
int i = 0; i < node_x_len; i += 2) {
427 int x_src = node_x[i].x;
428 int x_dst = node_x[i + 1].x;
435 x_src = std::max(x_src, xmin);
436 x_dst = std::min(x_dst, xmax);
439 callback(x_src - xmin, x_dst - xmin, pixel_y - ymin, user_data);
446 if (do_remove ==
true) {
448 for (
int i_src = 0; i_src < node_x_len; i_src += 1) {
449 const int *s = span_y[node_x[i_src].span_y_index];
450 const int *co =
verts[s[1]];
451 if (co[1] != pixel_y) {
452 if (i_dst != i_src) {
454 node_x[i_dst].span_y_index = node_x[i_src].span_y_index;
463 while ((span_y_index < span_y_len) && (
verts[span_y[span_y_index][0]][1] == pixel_y)) {
468 NodeX *n = &node_x[node_x_len++];
469 n->span_y_index = span_y_index;
void BLI_bitmap_draw_2d_poly_v2i_n(const int xmin, const int ymin, const int xmax, const int ymax, const Span< int2 > verts, void(*callback)(int x, int x_end, int y, void *), void *user_data)
void BLI_bitmap_draw_2d_tri_v2i(const int p1[2], const int p2[2], const int p3[2], void(*callback)(int x, int x_end, int y, void *), void *user_data)
static void draw_tri_flat_max(const int p[2], const int max_y, const float inv_slope1, const float inv_slope2, void(*callback)(int x, int x_end, int y, void *), void *user_data)
static void draw_tri_flat_min(const int p[2], const int min_y, const float inv_slope1, const float inv_slope2, void(*callback)(int x, int x_end, int y, void *), void *user_data)