[Bf-blender-cvs] [947ece8d395] master: LineArt: Variable name cleanups.

Yiming Wu noreply at git.blender.org
Thu Jun 16 16:44:47 CEST 2022


Commit: 947ece8d395a61bdae52da0d2a760873d43d2305
Author: Yiming Wu
Date:   Tue Jun 14 21:30:41 2022 +0800
Branches: master
https://developer.blender.org/rB947ece8d395a61bdae52da0d2a760873d43d2305

LineArt: Variable name cleanups.

Use more descriptive names for some of the two character variables.

Reviewed By: Sebastian Parborg (zeddb)

Differential Revision: https://developer.blender.org/D15192

===================================================================

M	source/blender/gpencil_modifiers/intern/lineart/MOD_lineart.h
M	source/blender/gpencil_modifiers/intern/lineart/lineart_cpu.c
M	source/blender/gpencil_modifiers/intern/lineart/lineart_ops.c

===================================================================

diff --git a/source/blender/gpencil_modifiers/intern/lineart/MOD_lineart.h b/source/blender/gpencil_modifiers/intern/lineart/MOD_lineart.h
index 6ca6fe2ff96..a72ce76d591 100644
--- a/source/blender/gpencil_modifiers/intern/lineart/MOD_lineart.h
+++ b/source/blender/gpencil_modifiers/intern/lineart/MOD_lineart.h
@@ -102,7 +102,7 @@ typedef struct LineartVert {
    * size of the struct is extended to include intersection data.
    * See #eLineArtVertFlags.
    */
-  char flag;
+  uint8_t flag;
 
 } LineartVert;
 
@@ -460,9 +460,6 @@ typedef struct LineartBoundingArea {
 
 #define LRT_MIN3_INDEX_ABC(x, y, z) (x < y ? (x < z ? a : (y < z ? b : c)) : (y < z ? b : c))
 
-#define LRT_ABC(index) (index == 0 ? a : (index == 1 ? b : c))
-#define LRT_PABC(index) (index == 0 ? pa : (index == 1 ? pb : pc))
-
 #define DBL_LOOSER 1e-5
 #define LRT_DOUBLE_CLOSE_LOOSER(a, b) (((a) + DBL_LOOSER) >= (b) && ((a)-DBL_LOOSER) <= (b))
 #define LRT_DOUBLE_CLOSE_ENOUGH(a, b) (((a) + DBL_EDGE_LIM) >= (b) && ((a)-DBL_EDGE_LIM) <= (b))
diff --git a/source/blender/gpencil_modifiers/intern/lineart/lineart_cpu.c b/source/blender/gpencil_modifiers/intern/lineart/lineart_cpu.c
index 9a46f8d72ca..c08bf3e0fe9 100644
--- a/source/blender/gpencil_modifiers/intern/lineart/lineart_cpu.c
+++ b/source/blender/gpencil_modifiers/intern/lineart/lineart_cpu.c
@@ -168,9 +168,9 @@ static void lineart_edge_cut(LineartData *ld,
                              uchar material_mask_bits,
                              uchar mat_occlusion)
 {
-  LineartEdgeSegment *es, *ies, *next_es, *prev_es;
+  LineartEdgeSegment *seg, *i_seg, *next_seg, *prev_seg;
   LineartEdgeSegment *cut_start_before = 0, *cut_end_before = 0;
-  LineartEdgeSegment *ns = 0, *ns2 = 0;
+  LineartEdgeSegment *new_seg1 = 0, *new_seg2 = 0;
   int untouched = 0;
 
   /* If for some reason the occlusion function may give a result that has zero length, or reversed
@@ -197,136 +197,136 @@ static void lineart_edge_cut(LineartData *ld,
   /* Begin looking for starting position of the segment. */
   /* Not using a list iteration macro because of it more clear when using for loops to iterate
    * through the segments. */
-  for (es = e->segments.first; es; es = es->next) {
-    if (LRT_DOUBLE_CLOSE_ENOUGH(es->at, start)) {
-      cut_start_before = es;
-      ns = cut_start_before;
+  for (seg = e->segments.first; seg; seg = seg->next) {
+    if (LRT_DOUBLE_CLOSE_ENOUGH(seg->at, start)) {
+      cut_start_before = seg;
+      new_seg1 = cut_start_before;
       break;
     }
-    if (es->next == NULL) {
+    if (seg->next == NULL) {
       break;
     }
-    ies = es->next;
-    if (ies->at > start + 1e-09 && start > es->at) {
-      cut_start_before = ies;
-      ns = lineart_give_segment(ld);
+    i_seg = seg->next;
+    if (i_seg->at > start + 1e-09 && start > seg->at) {
+      cut_start_before = i_seg;
+      new_seg1 = lineart_give_segment(ld);
       break;
     }
   }
   if (!cut_start_before && LRT_DOUBLE_CLOSE_ENOUGH(1, end)) {
     untouched = 1;
   }
-  for (es = cut_start_before; es; es = es->next) {
+  for (seg = cut_start_before; seg; seg = seg->next) {
     /* We tried to cut at existing cutting point (e.g. where the line's occluded by a triangle
      * strip). */
-    if (LRT_DOUBLE_CLOSE_ENOUGH(es->at, end)) {
-      cut_end_before = es;
-      ns2 = cut_end_before;
+    if (LRT_DOUBLE_CLOSE_ENOUGH(seg->at, end)) {
+      cut_end_before = seg;
+      new_seg2 = cut_end_before;
       break;
     }
     /* This check is to prevent `es->at == 1.0` (where we don't need to cut because we are at the
      * end point). */
-    if (!es->next && LRT_DOUBLE_CLOSE_ENOUGH(1, end)) {
-      cut_end_before = es;
-      ns2 = cut_end_before;
+    if (!seg->next && LRT_DOUBLE_CLOSE_ENOUGH(1, end)) {
+      cut_end_before = seg;
+      new_seg2 = cut_end_before;
       untouched = 1;
       break;
     }
     /* When an actual cut is needed in the line. */
-    if (es->at > end) {
-      cut_end_before = es;
-      ns2 = lineart_give_segment(ld);
+    if (seg->at > end) {
+      cut_end_before = seg;
+      new_seg2 = lineart_give_segment(ld);
       break;
     }
   }
 
   /* When we still can't find any existing cut in the line, we allocate new ones. */
-  if (ns == NULL) {
-    ns = lineart_give_segment(ld);
+  if (new_seg1 == NULL) {
+    new_seg1 = lineart_give_segment(ld);
   }
-  if (ns2 == NULL) {
+  if (new_seg2 == NULL) {
     if (untouched) {
-      ns2 = ns;
-      cut_end_before = ns2;
+      new_seg2 = new_seg1;
+      cut_end_before = new_seg2;
     }
     else {
-      ns2 = lineart_give_segment(ld);
+      new_seg2 = lineart_give_segment(ld);
     }
   }
 
   if (cut_start_before) {
-    if (cut_start_before != ns) {
+    if (cut_start_before != new_seg1) {
       /* Insert cutting points for when a new cut is needed. */
-      ies = cut_start_before->prev ? cut_start_before->prev : NULL;
-      if (ies) {
-        ns->occlusion = ies->occlusion;
-        ns->material_mask_bits = ies->material_mask_bits;
+      i_seg = cut_start_before->prev ? cut_start_before->prev : NULL;
+      if (i_seg) {
+        new_seg1->occlusion = i_seg->occlusion;
+        new_seg1->material_mask_bits = i_seg->material_mask_bits;
       }
-      BLI_insertlinkbefore(&e->segments, cut_start_before, ns);
+      BLI_insertlinkbefore(&e->segments, cut_start_before, new_seg1);
     }
     /* Otherwise we already found a existing cutting point, no need to insert a new one. */
   }
   else {
     /* We have yet to reach a existing cutting point even after we searched the whole line, so we
      * append the new cut to the end. */
-    ies = e->segments.last;
-    ns->occlusion = ies->occlusion;
-    ns->material_mask_bits = ies->material_mask_bits;
-    BLI_addtail(&e->segments, ns);
+    i_seg = e->segments.last;
+    new_seg1->occlusion = i_seg->occlusion;
+    new_seg1->material_mask_bits = i_seg->material_mask_bits;
+    BLI_addtail(&e->segments, new_seg1);
   }
   if (cut_end_before) {
     /* The same manipulation as on "cut_start_before". */
-    if (cut_end_before != ns2) {
-      ies = cut_end_before->prev ? cut_end_before->prev : NULL;
-      if (ies) {
-        ns2->occlusion = ies->occlusion;
-        ns2->material_mask_bits = ies->material_mask_bits;
+    if (cut_end_before != new_seg2) {
+      i_seg = cut_end_before->prev ? cut_end_before->prev : NULL;
+      if (i_seg) {
+        new_seg2->occlusion = i_seg->occlusion;
+        new_seg2->material_mask_bits = i_seg->material_mask_bits;
       }
-      BLI_insertlinkbefore(&e->segments, cut_end_before, ns2);
+      BLI_insertlinkbefore(&e->segments, cut_end_before, new_seg2);
     }
   }
   else {
-    ies = e->segments.last;
-    ns2->occlusion = ies->occlusion;
-    ns2->material_mask_bits = ies->material_mask_bits;
-    BLI_addtail(&e->segments, ns2);
+    i_seg = e->segments.last;
+    new_seg2->occlusion = i_seg->occlusion;
+    new_seg2->material_mask_bits = i_seg->material_mask_bits;
+    BLI_addtail(&e->segments, new_seg2);
   }
 
   /* If we touched the cut list, we assign the new cut position based on new cut position,
    * this way we accommodate precision lost due to multiple cut inserts. */
-  ns->at = start;
+  new_seg1->at = start;
   if (!untouched) {
-    ns2->at = end;
+    new_seg2->at = end;
   }
   else {
     /* For the convenience of the loop below. */
-    ns2 = ns2->next;
+    new_seg2 = new_seg2->next;
   }
 
   /* Register 1 level of occlusion for all touched segments. */
-  for (es = ns; es && es != ns2; es = es->next) {
-    es->occlusion += mat_occlusion;
-    es->material_mask_bits |= material_mask_bits;
+  for (seg = new_seg1; seg && seg != new_seg2; seg = seg->next) {
+    seg->occlusion += mat_occlusion;
+    seg->material_mask_bits |= material_mask_bits;
   }
 
   /* Reduce adjacent cutting points of the same level, which saves memory. */
   int8_t min_occ = 127;
-  prev_es = NULL;
-  for (es = e->segments.first; es; es = next_es) {
-    next_es = es->next;
+  prev_seg = NULL;
+  for (seg = e->segments.first; seg; seg = next_seg) {
+    next_seg = seg->next;
 
-    if (prev_es && prev_es->occlusion == es->occlusion &&
-        prev_es->material_mask_bits == es->material_mask_bits) {
-      BLI_remlink(&e->segments, es);
+    if (prev_seg && prev_seg->occlusion == seg->occlusion &&
+        prev_seg->material_mask_bits == seg->material_mask_bits) {
+      BLI_remlink(&e->segments, seg);
       /* This puts the node back to the render buffer, if more cut happens, these unused nodes get
        * picked first. */
-      lineart_discard_segment(ld, es);
+      lineart_discard_segment(ld, seg);
       continue;
     }
 
-    min_occ = MIN2(min_occ, es->occlusion);
+    min_occ = MIN2(min_occ, seg->occlusion);
 
-    prev_es = es;
+    prev_seg = seg;
   }
   e->min_occ = min_occ;
 }
@@ -570,6 +570,12 @@ static int lineart_point_on_line_segment(double v[2], double v0[2], double v1[2]
   return 0;
 }
 
+enum LineartPointTri {
+  LRT_OUTSIDE_TRIANGLE = 0,
+  LRT_ON_TRIANGLE = 1,
+  LRT_INSIDE_TRIANGLE = 2,
+};
+
 /**
  * Same algorithm as lineart_point_inside_triangle(), but returns differently:
  * 0-outside 1-on the edge 2-inside.
@@ -580,7 +586,7 @@ static int lineart_point_triangle_relation(double v[2], double v0[2], double v1[
   double r;
   if (lineart_point_on_line_segment(v, v0, v1) || lineart_point_on_line_segment(v, v1, v2) ||
       lineart_point_on_line_segment(v, v2, v0)) {
-    return 1;
+    return LRT_ON_TRIANGLE;
   }
 
   cl = (v0[0] - v[0]) * (v1[1] - v[1]) - (v0[1] - v[1]) * (v1[0] - v[0]);
@@ -588,28 +594,28 @@ static int lineart_point_triangle_relation(double v[2], double v0[2], double v1[
 
   cl = (v1[0] - v[0]) * (v2[1] - v[1]) - (v1[1] - v[1]) * (v2[0] - v[0]);
   if ((r = c * cl) < 0) {
-    return 0;
+    return LRT_OUTSIDE_TRIANGLE;
   }
 
   c = cl;
 
   cl = (v2[0] - v[0]) * (v0[1] - v[1]) - (v2[1] - v[1]) * (v0[0] - v[0]);
   if ((r = c * cl) < 0) {
-    return 0;
+    return LRT_OUTSIDE_TRIANGLE;
   }
 
   c = cl;
 
   cl = (v0[0] - v[0]) * (v1[1] - v[1]) - (v0[1] - v[1]) * (v1[0] - v[0]);
   if ((r = c * cl) < 0) {
-    return 0;
+    return LRT_OUTSIDE_TRIANGLE;
   }
 
   if (r == 0) {
-    return 1;
+    return LRT_ON_TR

@@ Diff output truncated at 10240 characters. @@



More information about the Bf-blender-cvs mailing list