Curve: use zero length array for BevList for less confusing syntax

This commit is contained in:
Campbell Barton 2014-06-15 14:23:23 +10:00
parent 716430ab64
commit 57372f4ef8
5 changed files with 55 additions and 52 deletions

@ -513,7 +513,7 @@ void calc_curvepath(Object *ob, ListBase *nurbs)
dist = (float *)MEM_mallocN(sizeof(float) * (tot + 1), "calcpathdist"); dist = (float *)MEM_mallocN(sizeof(float) * (tot + 1), "calcpathdist");
/* all lengths in *dist */ /* all lengths in *dist */
bevp = bevpfirst = (BevPoint *)(bl + 1); bevp = bevpfirst = bl->bevpoints;
fp = dist; fp = dist;
*fp = 0.0f; *fp = 0.0f;
for (a = 0; a < tot; a++) { for (a = 0; a < tot; a++) {

@ -1855,7 +1855,7 @@ static bool bevelinside(BevList *bl1, BevList *bl2)
/* take first vertex of possible hole */ /* take first vertex of possible hole */
bevp = (BevPoint *)(bl2 + 1); bevp = bl2->bevpoints;
hvec1[0] = bevp->vec[0]; hvec1[0] = bevp->vec[0];
hvec1[1] = bevp->vec[1]; hvec1[1] = bevp->vec[1];
hvec1[2] = 0.0; hvec1[2] = 0.0;
@ -1865,7 +1865,7 @@ static bool bevelinside(BevList *bl1, BevList *bl2)
/* test it with all edges of potential surounding poly */ /* test it with all edges of potential surounding poly */
/* count number of transitions left-right */ /* count number of transitions left-right */
bevp = (BevPoint *)(bl1 + 1); bevp = bl1->bevpoints;
nr = bl1->nr; nr = bl1->nr;
prevbevp = bevp + (nr - 1); prevbevp = bevp + (nr - 1);
@ -2051,7 +2051,7 @@ static void bevel_list_calc_bisect(BevList *bl)
bool is_cyclic = bl->poly != -1; bool is_cyclic = bl->poly != -1;
if (is_cyclic) { if (is_cyclic) {
bevp2 = (BevPoint *)(bl + 1); bevp2 = bl->bevpoints;
bevp1 = bevp2 + (bl->nr - 1); bevp1 = bevp2 + (bl->nr - 1);
bevp0 = bevp1 - 1; bevp0 = bevp1 - 1;
nr = bl->nr; nr = bl->nr;
@ -2065,7 +2065,7 @@ static void bevel_list_calc_bisect(BevList *bl)
* of direction for this guys. * of direction for this guys.
*/ */
bevp0 = (BevPoint *)(bl + 1); bevp0 = bl->bevpoints;
bevp1 = bevp0 + 1; bevp1 = bevp0 + 1;
bevp2 = bevp1 + 1; bevp2 = bevp1 + 1;
@ -2086,7 +2086,7 @@ static void bevel_list_flip_tangents(BevList *bl)
BevPoint *bevp2, *bevp1, *bevp0; BevPoint *bevp2, *bevp1, *bevp0;
int nr; int nr;
bevp2 = (BevPoint *)(bl + 1); bevp2 = bl->bevpoints;
bevp1 = bevp2 + (bl->nr - 1); bevp1 = bevp2 + (bl->nr - 1);
bevp0 = bevp1 - 1; bevp0 = bevp1 - 1;
@ -2107,7 +2107,7 @@ static void bevel_list_apply_tilt(BevList *bl)
int nr; int nr;
float q[4]; float q[4];
bevp2 = (BevPoint *)(bl + 1); bevp2 = bl->bevpoints;
bevp1 = bevp2 + (bl->nr - 1); bevp1 = bevp2 + (bl->nr - 1);
nr = bl->nr; nr = bl->nr;
@ -2131,7 +2131,7 @@ static void bevel_list_smooth(BevList *bl, int smooth_iter)
int a; int a;
for (a = 0; a < smooth_iter; a++) { for (a = 0; a < smooth_iter; a++) {
bevp2 = (BevPoint *)(bl + 1); bevp2 = bl->bevpoints;
bevp1 = bevp2 + (bl->nr - 1); bevp1 = bevp2 + (bl->nr - 1);
bevp0 = bevp1 - 1; bevp0 = bevp1 - 1;
@ -2177,7 +2177,7 @@ static void bevel_list_smooth(BevList *bl, int smooth_iter)
static void make_bevel_list_3D_zup(BevList *bl) static void make_bevel_list_3D_zup(BevList *bl)
{ {
BevPoint *bevp = (BevPoint *)(bl + 1); BevPoint *bevp = bl->bevpoints;
int nr = bl->nr; int nr = bl->nr;
bevel_list_calc_bisect(bl); bevel_list_calc_bisect(bl);
@ -2212,7 +2212,7 @@ static void make_bevel_list_3D_minimum_twist(BevList *bl)
bevel_list_calc_bisect(bl); bevel_list_calc_bisect(bl);
bevp2 = (BevPoint *)(bl + 1); bevp2 = bl->bevpoints;
bevp1 = bevp2 + (bl->nr - 1); bevp1 = bevp2 + (bl->nr - 1);
bevp0 = bevp1 - 1; bevp0 = bevp1 - 1;
@ -2250,7 +2250,7 @@ static void make_bevel_list_3D_minimum_twist(BevList *bl)
BevPoint *bevp_last; BevPoint *bevp_last;
bevp_first = (BevPoint *)(bl + 1); bevp_first = bl->bevpoints;
bevp_first += bl->nr - 1; bevp_first += bl->nr - 1;
bevp_last = bevp_first; bevp_last = bevp_first;
bevp_last--; bevp_last--;
@ -2278,7 +2278,7 @@ static void make_bevel_list_3D_minimum_twist(BevList *bl)
if (angle_normalized_v3v3(bevp_first->dir, cross_tmp) < DEG2RADF(90.0f)) if (angle_normalized_v3v3(bevp_first->dir, cross_tmp) < DEG2RADF(90.0f))
angle = -angle; angle = -angle;
bevp2 = (BevPoint *)(bl + 1); bevp2 = bl->bevpoints;
bevp1 = bevp2 + (bl->nr - 1); bevp1 = bevp2 + (bl->nr - 1);
bevp0 = bevp1 - 1; bevp0 = bevp1 - 1;
@ -2300,11 +2300,11 @@ static void make_bevel_list_3D_minimum_twist(BevList *bl)
* using it's own direction, which might not correspond * using it's own direction, which might not correspond
* the twist of neighbor point. * the twist of neighbor point.
*/ */
bevp1 = (BevPoint *)(bl + 1); bevp1 = bl->bevpoints;
bevp0 = bevp1 + 1; bevp0 = bevp1 + 1;
minimum_twist_between_two_points(bevp1, bevp0); minimum_twist_between_two_points(bevp1, bevp0);
bevp2 = (BevPoint *)(bl + 1); bevp2 = bl->bevpoints;
bevp1 = bevp2 + (bl->nr - 1); bevp1 = bevp2 + (bl->nr - 1);
bevp0 = bevp1 - 1; bevp0 = bevp1 - 1;
minimum_twist_between_two_points(bevp1, bevp0); minimum_twist_between_two_points(bevp1, bevp0);
@ -2322,7 +2322,7 @@ static void make_bevel_list_3D_tangent(BevList *bl)
bevel_list_flip_tangents(bl); bevel_list_flip_tangents(bl);
/* correct the tangents */ /* correct the tangents */
bevp2 = (BevPoint *)(bl + 1); bevp2 = bl->bevpoints;
bevp1 = bevp2 + (bl->nr - 1); bevp1 = bevp2 + (bl->nr - 1);
bevp0 = bevp1 - 1; bevp0 = bevp1 - 1;
@ -2340,7 +2340,7 @@ static void make_bevel_list_3D_tangent(BevList *bl)
/* now for the real twist calc */ /* now for the real twist calc */
bevp2 = (BevPoint *)(bl + 1); bevp2 = bl->bevpoints;
bevp1 = bevp2 + (bl->nr - 1); bevp1 = bevp2 + (bl->nr - 1);
bevp0 = bevp1 - 1; bevp0 = bevp1 - 1;
@ -2387,7 +2387,7 @@ static void make_bevel_list_segment_3D(BevList *bl)
{ {
float q[4]; float q[4];
BevPoint *bevp2 = (BevPoint *)(bl + 1); BevPoint *bevp2 = bl->bevpoints;
BevPoint *bevp1 = bevp2 + 1; BevPoint *bevp1 = bevp2 + 1;
/* simple quat/dir */ /* simple quat/dir */
@ -2406,7 +2406,7 @@ static void make_bevel_list_segment_3D(BevList *bl)
/* only for 2 points */ /* only for 2 points */
static void make_bevel_list_segment_2D(BevList *bl) static void make_bevel_list_segment_2D(BevList *bl)
{ {
BevPoint *bevp2 = (BevPoint *)(bl + 1); BevPoint *bevp2 = bl->bevpoints;
BevPoint *bevp1 = bevp2 + 1; BevPoint *bevp1 = bevp2 + 1;
const float x1 = bevp1->vec[0] - bevp2->vec[0]; const float x1 = bevp1->vec[0] - bevp2->vec[0];
@ -2429,13 +2429,13 @@ static void make_bevel_list_2D(BevList *bl)
int nr; int nr;
if (bl->poly != -1) { if (bl->poly != -1) {
bevp2 = (BevPoint *)(bl + 1); bevp2 = bl->bevpoints;
bevp1 = bevp2 + (bl->nr - 1); bevp1 = bevp2 + (bl->nr - 1);
bevp0 = bevp1 - 1; bevp0 = bevp1 - 1;
nr = bl->nr; nr = bl->nr;
} }
else { else {
bevp0 = (BevPoint *)(bl + 1); bevp0 = bl->bevpoints;
bevp1 = bevp0 + 1; bevp1 = bevp0 + 1;
bevp2 = bevp1 + 1; bevp2 = bevp1 + 1;
@ -2467,14 +2467,14 @@ static void make_bevel_list_2D(BevList *bl)
float angle; float angle;
/* first */ /* first */
bevp = (BevPoint *)(bl + 1); bevp = bl->bevpoints;
angle = atan2(bevp->dir[0], bevp->dir[1]) - M_PI / 2.0; angle = atan2(bevp->dir[0], bevp->dir[1]) - M_PI / 2.0;
bevp->sina = sinf(angle); bevp->sina = sinf(angle);
bevp->cosa = cosf(angle); bevp->cosa = cosf(angle);
vec_to_quat(bevp->quat, bevp->dir, 5, 1); vec_to_quat(bevp->quat, bevp->dir, 5, 1);
/* last */ /* last */
bevp = (BevPoint *)(bl + 1); bevp = bl->bevpoints;
bevp += (bl->nr - 1); bevp += (bl->nr - 1);
angle = atan2(bevp->dir[0], bevp->dir[1]) - M_PI / 2.0; angle = atan2(bevp->dir[0], bevp->dir[1]) - M_PI / 2.0;
bevp->sina = sinf(angle); bevp->sina = sinf(angle);
@ -2489,7 +2489,7 @@ static void bevlist_firstlast_direction_calc_from_bpoint(Nurb *nu, BevList *bl)
BPoint *first_bp = nu->bp, *last_bp = nu->bp + (nu->pntsu - 1); BPoint *first_bp = nu->bp, *last_bp = nu->bp + (nu->pntsu - 1);
BevPoint *first_bevp, *last_bevp; BevPoint *first_bevp, *last_bevp;
first_bevp = (BevPoint *)(bl + 1); first_bevp = bl->bevpoints;
last_bevp = first_bevp + (bl->nr - 1); last_bevp = first_bevp + (bl->nr - 1);
sub_v3_v3v3(first_bevp->dir, (first_bp + 1)->vec, first_bp->vec); sub_v3_v3v3(first_bevp->dir, (first_bp + 1)->vec, first_bp->vec);
@ -2570,7 +2570,7 @@ void BKE_curve_bevelList_make(Object *ob, ListBase *nurbs, bool for_render)
bl->nr = len; bl->nr = len;
bl->dupe_nr = 0; bl->dupe_nr = 0;
bl->charidx = nu->charidx; bl->charidx = nu->charidx;
bevp = (BevPoint *)(bl + 1); bevp = bl->bevpoints;
bp = nu->bp; bp = nu->bp;
while (len--) { while (len--) {
@ -2595,7 +2595,7 @@ void BKE_curve_bevelList_make(Object *ob, ListBase *nurbs, bool for_render)
bl->poly = (nu->flagu & CU_NURB_CYCLIC) ? 0 : -1; bl->poly = (nu->flagu & CU_NURB_CYCLIC) ? 0 : -1;
bl->charidx = nu->charidx; bl->charidx = nu->charidx;
bevp = (BevPoint *)(bl + 1); bevp = bl->bevpoints;
a = nu->pntsu - 1; a = nu->pntsu - 1;
bezt = nu->bezt; bezt = nu->bezt;
@ -2689,7 +2689,7 @@ void BKE_curve_bevelList_make(Object *ob, ListBase *nurbs, bool for_render)
bl->dupe_nr = 0; bl->dupe_nr = 0;
bl->poly = (nu->flagu & CU_NURB_CYCLIC) ? 0 : -1; bl->poly = (nu->flagu & CU_NURB_CYCLIC) ? 0 : -1;
bl->charidx = nu->charidx; bl->charidx = nu->charidx;
bevp = (BevPoint *)(bl + 1); bevp = bl->bevpoints;
BKE_nurb_makeCurve(nu, &bevp->vec[0], BKE_nurb_makeCurve(nu, &bevp->vec[0],
do_tilt ? &bevp->alfa : NULL, do_tilt ? &bevp->alfa : NULL,
@ -2712,11 +2712,11 @@ void BKE_curve_bevelList_make(Object *ob, ListBase *nurbs, bool for_render)
bool is_cyclic = bl->poly != -1; bool is_cyclic = bl->poly != -1;
nr = bl->nr; nr = bl->nr;
if (is_cyclic) { if (is_cyclic) {
bevp1 = (BevPoint *)(bl + 1); bevp1 = bl->bevpoints;
bevp0 = bevp1 + (nr - 1); bevp0 = bevp1 + (nr - 1);
} }
else { else {
bevp0 = (BevPoint *)(bl + 1); bevp0 = bl->bevpoints;
bevp1 = bevp0 + 1; bevp1 = bevp0 + 1;
} }
nr--; nr--;
@ -2745,8 +2745,8 @@ void BKE_curve_bevelList_make(Object *ob, ListBase *nurbs, bool for_render)
blnew->nr = 0; blnew->nr = 0;
BLI_remlink(bev, bl); BLI_remlink(bev, bl);
BLI_insertlinkbefore(bev, blnext, blnew); /* to make sure bevlijst is tuned with nurblist */ BLI_insertlinkbefore(bev, blnext, blnew); /* to make sure bevlijst is tuned with nurblist */
bevp0 = (BevPoint *)(bl + 1); bevp0 = bl->bevpoints;
bevp1 = (BevPoint *)(blnew + 1); bevp1 = blnew->bevpoints;
nr = bl->nr; nr = bl->nr;
while (nr--) { while (nr--) {
if (bevp0->dupe_tag == 0) { if (bevp0->dupe_tag == 0) {
@ -2782,7 +2782,7 @@ void BKE_curve_bevelList_make(Object *ob, ListBase *nurbs, bool for_render)
if (bl->poly > 0) { if (bl->poly > 0) {
min = 300000.0; min = 300000.0;
bevp = (BevPoint *)(bl + 1); bevp = bl->bevpoints;
nr = bl->nr; nr = bl->nr;
while (nr--) { while (nr--) {
if (min > bevp->vec[0]) { if (min > bevp->vec[0]) {
@ -2794,14 +2794,14 @@ void BKE_curve_bevelList_make(Object *ob, ListBase *nurbs, bool for_render)
sd->bl = bl; sd->bl = bl;
sd->left = min; sd->left = min;
bevp = (BevPoint *)(bl + 1); bevp = bl->bevpoints;
if (bevp1 == bevp) if (bevp1 == bevp)
bevp0 = bevp + (bl->nr - 1); bevp0 = bevp + (bl->nr - 1);
else else
bevp0 = bevp1 - 1; bevp0 = bevp1 - 1;
bevp = bevp + (bl->nr - 1); bevp = bevp + (bl->nr - 1);
if (bevp1 == bevp) if (bevp1 == bevp)
bevp2 = (BevPoint *)(bl + 1); bevp2 = bl->bevpoints;
else else
bevp2 = bevp1 + 1; bevp2 = bevp1 + 1;
@ -2840,7 +2840,7 @@ void BKE_curve_bevelList_make(Object *ob, ListBase *nurbs, bool for_render)
for (a = 0; a < poly; a++, sd++) { for (a = 0; a < poly; a++, sd++) {
if (sd->bl->hole == sd->dir) { if (sd->bl->hole == sd->dir) {
bl = sd->bl; bl = sd->bl;
bevp1 = (BevPoint *)(bl + 1); bevp1 = bl->bevpoints;
bevp2 = bevp1 + (bl->nr - 1); bevp2 = bevp1 + (bl->nr - 1);
nr = bl->nr / 2; nr = bl->nr / 2;
while (nr--) { while (nr--) {
@ -2859,7 +2859,7 @@ void BKE_curve_bevelList_make(Object *ob, ListBase *nurbs, bool for_render)
/* 2D Curves */ /* 2D Curves */
for (bl = bev->first; bl; bl = bl->next) { for (bl = bev->first; bl; bl = bl->next) {
if (bl->nr < 2) { if (bl->nr < 2) {
BevPoint *bevp = (BevPoint *)(bl + 1); BevPoint *bevp = bl->bevpoints;
unit_qt(bevp->quat); unit_qt(bevp->quat);
} }
else if (bl->nr == 2) { /* 2 pnt, treat separate */ else if (bl->nr == 2) { /* 2 pnt, treat separate */
@ -2874,7 +2874,7 @@ void BKE_curve_bevelList_make(Object *ob, ListBase *nurbs, bool for_render)
/* 3D Curves */ /* 3D Curves */
for (bl = bev->first; bl; bl = bl->next) { for (bl = bev->first; bl; bl = bl->next) {
if (bl->nr < 2) { if (bl->nr < 2) {
BevPoint *bevp = (BevPoint *)(bl + 1); BevPoint *bevp = bl->bevpoints;
unit_qt(bevp->quat); unit_qt(bevp->quat);
} }
else if (bl->nr == 2) { /* 2 pnt, treat separate */ else if (bl->nr == 2) { /* 2 pnt, treat separate */

@ -1425,7 +1425,7 @@ static void calc_bevfac_mapping(
bevp_array = MEM_mallocN(sizeof(*bevp_array) * (bl->nr - 1), "bevp_dists"); bevp_array = MEM_mallocN(sizeof(*bevp_array) * (bl->nr - 1), "bevp_dists");
segments = MEM_callocN(sizeof(*segments) * segcount, "bevp_segmentlengths"); segments = MEM_callocN(sizeof(*segments) * segcount, "bevp_segmentlengths");
bevp_prev = (BevPoint *)(bl + 1); bevp_prev = bl->bevpoints;
bevp = bevp_prev + 1; bevp = bevp_prev + 1;
if (nu->type == CU_BEZIER) { if (nu->type == CU_BEZIER) {
@ -1644,7 +1644,7 @@ static void do_makeDispListCurveTypes(Scene *scene, Object *ob, ListBase *dispba
dl->rt = nu->flag & ~CU_2D; dl->rt = nu->flag & ~CU_2D;
a = dl->nr; a = dl->nr;
bevp = (BevPoint *)(bl + 1); bevp = bl->bevpoints;
data = dl->verts; data = dl->verts;
while (a--) { while (a--) {
data[0] = bevp->vec[0] + widfac * bevp->sina; data[0] = bevp->vec[0] + widfac * bevp->sina;
@ -1704,9 +1704,9 @@ static void do_makeDispListCurveTypes(Scene *scene, Object *ob, ListBase *dispba
"bevelSplitFlag"); "bevelSplitFlag");
/* for each point of poly make a bevel piece */ /* for each point of poly make a bevel piece */
bevp_first = (BevPoint *)(bl + 1); bevp_first = bl->bevpoints;
bevp_last = (BevPoint *)(bl + 1) + (bl->nr - 1); bevp_last = &bl->bevpoints[bl->nr - 1];
bevp = (BevPoint *)(bl + 1) + start; bevp = &bl->bevpoints[start];
for (i = start, a = 0; a < steps; i++, bevp++, a++) { for (i = start, a = 0; a < steps; i++, bevp++, a++) {
float fac = 1.0; float fac = 1.0;
float *cur_data = data; float *cur_data = data;

@ -5913,7 +5913,7 @@ static void drawnurb(Scene *scene, View3D *v3d, RegionView3D *rv3d, Base *base,
UI_ThemeColor(TH_WIRE_EDIT); UI_ThemeColor(TH_WIRE_EDIT);
for (bl = ob->curve_cache->bev.first, nu = nurb; nu && bl; bl = bl->next, nu = nu->next) { for (bl = ob->curve_cache->bev.first, nu = nurb; nu && bl; bl = bl->next, nu = nu->next) {
BevPoint *bevp = (BevPoint *)(bl + 1); BevPoint *bevp = bl->bevpoints;
int nr = bl->nr; int nr = bl->nr;
int skip = nu->resolu / 16; int skip = nu->resolu / 16;

@ -68,16 +68,6 @@ typedef struct Path {
float totdist; float totdist;
} Path; } Path;
/* These two Lines with # tell makesdna this struct can be excluded. */
#
#
typedef struct BevList {
struct BevList *next, *prev;
int nr, dupe_nr;
int poly, hole;
int charidx;
} BevList;
/* These two Lines with # tell makesdna this struct can be excluded. */ /* These two Lines with # tell makesdna this struct can be excluded. */
# #
# #
@ -88,6 +78,19 @@ typedef struct BevPoint {
short split_tag, dupe_tag; short split_tag, dupe_tag;
} BevPoint; } BevPoint;
/* These two Lines with # tell makesdna this struct can be excluded. */
#
#
typedef struct BevList {
struct BevList *next, *prev;
int nr, dupe_nr;
int poly, hole;
int charidx;
/* over-alloc */
BevPoint bevpoints[0];
} BevList;
/** /**
* Keyframes on F-Curves (allows code reuse of Bezier eval code) and * Keyframes on F-Curves (allows code reuse of Bezier eval code) and
* Points on Bezier Curves/Paths are generally BezTriples * Points on Bezier Curves/Paths are generally BezTriples