Cleanup: Store cursor location in tGPspoint as an array

Fixes many instances of `-Wstringop-overread` warning on GCC 11

Differential Revision: https://developer.blender.org/D13672
This commit is contained in:
Aaron Carlisle 2021-12-26 16:32:57 -05:00
parent 11ac276caa
commit 5814de65f9
8 changed files with 100 additions and 104 deletions

View File

@ -642,7 +642,7 @@ static void gpencil_sbuffer_stroke_ensure(bGPdata *gpd, bool do_stroke, bool do_
float(*tpoints2d)[2] = MEM_mallocN(sizeof(*tpoints2d) * vert_len, __func__);
/* Triangulate in 2D. */
for (int i = 0; i < vert_len; i++) {
copy_v2_v2(tpoints2d[i], &tpoints[i].x);
copy_v2_v2(tpoints2d[i], tpoints[i].m_xy);
}
/* Compute directly inside the IBO data buffer. */
/* OPTI: This is a bottleneck if the stroke is very long. */

View File

@ -165,7 +165,7 @@ static void annotation_draw_stroke_buffer(bGPdata *gps,
immBindBuiltinProgram(GPU_SHADER_3D_POINT_UNIFORM_SIZE_UNIFORM_COLOR_AA);
immUniformColor3fvAlpha(ink, ink[3]);
immBegin(GPU_PRIM_POINTS, 1);
immVertex2fv(pos, &pt->x);
immVertex2fv(pos, pt->m_xy);
}
else {
float oldpressure = points[0].pressure;
@ -191,7 +191,7 @@ static void annotation_draw_stroke_buffer(bGPdata *gps,
if (fabsf(pt->pressure - oldpressure) > 0.2f) {
/* need to have 2 points to avoid immEnd assert error */
if (draw_points < 2) {
immVertex2fv(pos, &(pt - 1)->x);
immVertex2fv(pos, (pt - 1)->m_xy);
}
immEnd();
@ -202,7 +202,7 @@ static void annotation_draw_stroke_buffer(bGPdata *gps,
/* need to roll-back one point to ensure that there are no gaps in the stroke */
if (i != 0) {
immVertex2fv(pos, &(pt - 1)->x);
immVertex2fv(pos, (pt - 1)->m_xy);
draw_points++;
}
@ -210,12 +210,12 @@ static void annotation_draw_stroke_buffer(bGPdata *gps,
}
/* now the point we want */
immVertex2fv(pos, &pt->x);
immVertex2fv(pos, pt->m_xy);
draw_points++;
}
/* need to have 2 points to avoid immEnd assert error */
if (draw_points < 2) {
immVertex2fv(pos, &(pt - 1)->x);
immVertex2fv(pos, (pt - 1)->m_xy);
}
}
@ -227,14 +227,14 @@ static void annotation_draw_stroke_buffer(bGPdata *gps,
if ((sflag & GP_STROKE_USE_ARROW_END) &&
(runtime.arrow_end_style != GP_STROKE_ARROWSTYLE_NONE)) {
float end[2];
copy_v2_fl2(end, points[1].x, points[1].y);
copy_v2_v2(end, points[1].m_xy);
annotation_draw_stroke_arrow_buffer(pos, end, runtime.arrow_end, runtime.arrow_end_style);
}
/* Draw starting arrow stroke. */
if ((sflag & GP_STROKE_USE_ARROW_START) &&
(runtime.arrow_start_style != GP_STROKE_ARROWSTYLE_NONE)) {
float start[2];
copy_v2_fl2(start, points[0].x, points[0].y);
copy_v2_v2(start, points[0].m_xy);
annotation_draw_stroke_arrow_buffer(
pos, start, runtime.arrow_start, runtime.arrow_start_style);
}

View File

@ -426,25 +426,25 @@ static void annotation_smooth_buffer(tGPsdata *p, float inf, int idx)
/* Compute smoothed coordinate by taking the ones nearby */
if (pta) {
copy_v2_v2(a, &pta->x);
copy_v2_v2(a, pta->m_xy);
madd_v2_v2fl(sco, a, average_fac);
}
if (ptb) {
copy_v2_v2(b, &ptb->x);
copy_v2_v2(b, ptb->m_xy);
madd_v2_v2fl(sco, b, average_fac);
}
if (ptc) {
copy_v2_v2(c, &ptc->x);
copy_v2_v2(c, ptc->m_xy);
madd_v2_v2fl(sco, c, average_fac);
}
if (ptd) {
copy_v2_v2(d, &ptd->x);
copy_v2_v2(d, ptd->m_xy);
madd_v2_v2fl(sco, d, average_fac);
}
/* Based on influence factor, blend between original and optimal smoothed coordinate */
interp_v2_v2v2(c, c, sco, inf);
copy_v2_v2(&ptc->x, c);
copy_v2_v2(ptc->m_xy, c);
}
static void annotation_stroke_arrow_calc_points_segment(float stroke_points[8],
@ -492,8 +492,8 @@ static void annotation_stroke_arrow_calc_points(tGPspoint *point,
case GP_STROKE_ARROWSTYLE_CLOSED:
mul_v2_fl(norm_dir, arrow_length);
if (point != NULL) {
add_v2_v2(&point->x, norm_dir);
copy_v2_v2(corner, &point->x);
add_v2_v2(point->m_xy, norm_dir);
copy_v2_v2(corner, point->m_xy);
}
annotation_stroke_arrow_calc_points_segment(stroke_points,
corner,
@ -507,8 +507,8 @@ static void annotation_stroke_arrow_calc_points(tGPspoint *point,
case GP_STROKE_ARROWSTYLE_SQUARE:
mul_v2_fl(norm_dir, arrow_length * 1.5f);
if (point != NULL) {
add_v2_v2(&point->x, norm_dir);
copy_v2_v2(corner, &point->x);
add_v2_v2(point->m_xy, norm_dir);
copy_v2_v2(corner, point->m_xy);
}
annotation_stroke_arrow_calc_points_segment(stroke_points,
corner,
@ -544,7 +544,7 @@ static short annotation_stroke_addpoint(tGPsdata *p,
pt = (tGPspoint *)(gpd->runtime.sbuffer);
/* store settings */
copy_v2_v2(&pt->x, mval);
copy_v2_v2(pt->m_xy, mval);
/* T44932 - Pressure vals are unreliable, so ignore for now */
pt->pressure = 1.0f;
pt->strength = 1.0f;
@ -560,7 +560,7 @@ static short annotation_stroke_addpoint(tGPsdata *p,
pt = ((tGPspoint *)(gpd->runtime.sbuffer) + 1);
/* store settings */
copy_v2_v2(&pt->x, mval);
copy_v2_v2(pt->m_xy, mval);
/* T44932 - Pressure vals are unreliable, so ignore for now */
pt->pressure = 1.0f;
pt->strength = 1.0f;
@ -573,10 +573,10 @@ static short annotation_stroke_addpoint(tGPsdata *p,
if (gpd->runtime.sbuffer_sflag & (GP_STROKE_USE_ARROW_START | GP_STROKE_USE_ARROW_END)) {
/* Store start and end point coords for arrows. */
float end[2];
copy_v2_v2(end, &pt->x);
copy_v2_v2(end, pt->m_xy);
pt = ((tGPspoint *)(gpd->runtime.sbuffer));
float start[2];
copy_v2_v2(start, &pt->x);
copy_v2_v2(start, pt->m_xy);
/* Arrow end corner. */
if (gpd->runtime.sbuffer_sflag & GP_STROKE_USE_ARROW_END) {
@ -609,7 +609,7 @@ static short annotation_stroke_addpoint(tGPsdata *p,
pt = ((tGPspoint *)(gpd->runtime.sbuffer) + gpd->runtime.sbuffer_used);
/* store settings */
copy_v2_v2(&pt->x, mval);
copy_v2_v2(pt->m_xy, mval);
pt->pressure = pressure;
/* Unused for annotations, but initialize for easier conversions to GP Object. */
pt->strength = 1.0f;
@ -636,7 +636,7 @@ static short annotation_stroke_addpoint(tGPsdata *p,
pt = (tGPspoint *)gpd->runtime.sbuffer;
/* store settings */
copy_v2_v2(&pt->x, mval);
copy_v2_v2(pt->m_xy, mval);
/* T44932 - Pressure vals are unreliable, so ignore for now */
pt->pressure = 1.0f;
pt->strength = 1.0f;
@ -678,7 +678,7 @@ static short annotation_stroke_addpoint(tGPsdata *p,
}
/* convert screen-coordinates to appropriate coordinates (and store them) */
annotation_stroke_convertcoords(p, &pt->x, &pts->x, NULL);
annotation_stroke_convertcoords(p, pt->m_xy, &pts->x, NULL);
/* copy pressure and time */
pts->pressure = pt->pressure;
@ -717,8 +717,8 @@ static void annotation_stroke_arrow_init_point(
{
/* NOTE: provided co_idx should be always pair number as it's [x1, y1, x2, y2, x3, y3]. */
const float real_co[2] = {co[co_idx], co[co_idx + 1]};
copy_v2_v2(&ptc->x, real_co);
annotation_stroke_convertcoords(p, &ptc->x, &pt->x, NULL);
copy_v2_v2(ptc->m_xy, real_co);
annotation_stroke_convertcoords(p, ptc->m_xy, &pt->x, NULL);
annotation_stroke_arrow_init_point_default(pt);
}
@ -885,7 +885,7 @@ static void annotation_stroke_newfrombuffer(tGPsdata *p)
ptc = gpd->runtime.sbuffer;
/* convert screen-coordinates to appropriate coordinates (and store them) */
annotation_stroke_convertcoords(p, &ptc->x, &pt->x, NULL);
annotation_stroke_convertcoords(p, ptc->m_xy, &pt->x, NULL);
/* copy pressure and time */
pt->pressure = ptc->pressure;
@ -903,7 +903,7 @@ static void annotation_stroke_newfrombuffer(tGPsdata *p)
ptc = ((tGPspoint *)runtime.sbuffer) + (runtime.sbuffer_used - 1);
/* Convert screen-coordinates to appropriate coordinates (and store them). */
annotation_stroke_convertcoords(p, &ptc->x, &pt->x, NULL);
annotation_stroke_convertcoords(p, ptc->m_xy, &pt->x, NULL);
/* Copy pressure and time. */
pt->pressure = ptc->pressure;
@ -926,7 +926,7 @@ static void annotation_stroke_newfrombuffer(tGPsdata *p)
/* End point. */
ptc = ((tGPspoint *)runtime.sbuffer) + (runtime.sbuffer_used - 1);
annotation_stroke_convertcoords(p, &ptc->x, &pt->x, NULL);
annotation_stroke_convertcoords(p, ptc->m_xy, &pt->x, NULL);
annotation_stroke_arrow_init_point_default(pt);
/* Fill and convert arrow points to create arrow shape. */
@ -947,7 +947,7 @@ static void annotation_stroke_newfrombuffer(tGPsdata *p)
/* Start point. */
ptc = runtime.sbuffer;
annotation_stroke_convertcoords(p, &ptc->x, &pt->x, NULL);
annotation_stroke_convertcoords(p, ptc->m_xy, &pt->x, NULL);
annotation_stroke_arrow_init_point_default(pt);
/* Fill and convert arrow points to create arrow shape. */
@ -961,7 +961,7 @@ static void annotation_stroke_newfrombuffer(tGPsdata *p)
ptc = gpd->runtime.sbuffer;
/* convert screen-coordinates to appropriate coordinates (and store them) */
annotation_stroke_convertcoords(p, &ptc->x, &pt->x, NULL);
annotation_stroke_convertcoords(p, ptc->m_xy, &pt->x, NULL);
/* copy pressure and time */
pt->pressure = ptc->pressure;
@ -981,7 +981,7 @@ static void annotation_stroke_newfrombuffer(tGPsdata *p)
const ViewDepths *depths = p->depths;
for (i = 0, ptc = gpd->runtime.sbuffer; i < gpd->runtime.sbuffer_used; i++, ptc++, pt++) {
round_v2i_v2fl(mval_i, &ptc->x);
round_v2i_v2fl(mval_i, ptc->m_xy);
if ((ED_view3d_depth_read_cached(depths, mval_i, depth_margin, depth_arr + i) == 0) &&
(i && (ED_view3d_depth_read_cached_seg(
@ -1041,7 +1041,7 @@ static void annotation_stroke_newfrombuffer(tGPsdata *p)
for (i = 0, ptc = gpd->runtime.sbuffer; i < gpd->runtime.sbuffer_used && ptc;
i++, ptc++, pt++) {
/* convert screen-coordinates to appropriate coordinates (and store them) */
annotation_stroke_convertcoords(p, &ptc->x, &pt->x, depth_arr ? depth_arr + i : NULL);
annotation_stroke_convertcoords(p, ptc->m_xy, &pt->x, depth_arr ? depth_arr + i : NULL);
/* copy pressure and time */
pt->pressure = ptc->pressure;
@ -1811,7 +1811,7 @@ static void annotation_draw_stabilizer(bContext *C, int x, int y, void *p_ptr)
/* Rope Simple. */
immUniformColor4f(color[0], color[1], color[2], 0.8f);
immBegin(GPU_PRIM_LINES, 2);
immVertex2f(pos, pt->x + region->winrct.xmin, pt->y + region->winrct.ymin);
immVertex2f(pos, pt->m_xy[0] + region->winrct.xmin, pt->m_xy[1] + region->winrct.ymin);
immVertex2f(pos, x, y);
immEnd();

View File

@ -1072,7 +1072,7 @@ static void gpencil_erase_processed_area(tGPDfill *tgpf)
/* First set in blue the perimeter. */
for (int i = 0; i < tgpf->sbuffer_used && point2D; i++, point2D++) {
int image_idx = ibuf->x * (int)point2D->y + (int)point2D->x;
int image_idx = ibuf->x * (int)point2D->m_xy[1] + (int)point2D->m_xy[0];
set_pixel(ibuf, image_idx, blue_col);
}
@ -1393,7 +1393,7 @@ static void gpencil_get_depth_array(tGPDfill *tgpf)
for (i = 0, ptc = tgpf->sbuffer; i < totpoints; i++, ptc++) {
int mval_i[2];
round_v2i_v2fl(mval_i, &ptc->x);
round_v2i_v2fl(mval_i, ptc->m_xy);
if ((ED_view3d_depth_read_cached(depths, mval_i, depth_margin, tgpf->depth_arr + i) == 0) &&
(i && (ED_view3d_depth_read_cached_seg(
@ -1437,9 +1437,9 @@ static int gpencil_points_from_stack(tGPDfill *tgpf)
while (!BLI_stack_is_empty(tgpf->stack)) {
int v[2];
BLI_stack_pop(tgpf->stack, &v);
copy_v2fl_v2i(&point2D->x, v);
copy_v2fl_v2i(point2D->m_xy, v);
/* shift points to center of pixel */
add_v2_fl(&point2D->x, 0.5f);
add_v2_fl(point2D->m_xy, 0.5f);
point2D->pressure = 1.0f;
point2D->strength = 1.0f;
point2D->time = 0.0f;
@ -2125,7 +2125,7 @@ static int gpencil_fill_modal(bContext *C, wmOperator *op, const wmEvent *event)
tgpf->gps_mouse = BKE_gpencil_stroke_new(0, 1, 10.0f);
tGPspoint point2D;
bGPDspoint *pt = &tgpf->gps_mouse->points[0];
copy_v2fl_v2i(&point2D.x, tgpf->mouse);
copy_v2fl_v2i(point2D.m_xy, tgpf->mouse);
gpencil_stroke_convertcoords_tpoint(
tgpf->scene, tgpf->region, tgpf->ob, &point2D, NULL, &pt->x);

View File

@ -493,7 +493,7 @@ static void gpencil_brush_jitter(bGPdata *gpd, tGPspoint *pt, const float amplit
/* Mouse movement in ints -> floats. */
if (gpd->runtime.sbuffer_used > 1) {
tGPspoint *pt_prev = pt - 1;
sub_v2_v2v2(mvec, &pt->x, &pt_prev->x);
sub_v2_v2v2(mvec, pt->m_xy, pt_prev->m_xy);
normalize_v2(mvec);
/* Rotate mvec by 90 degrees... */
float angle = angle_v2v2(mvec, axis);
@ -502,7 +502,7 @@ static void gpencil_brush_jitter(bGPdata *gpd, tGPspoint *pt, const float amplit
mvec[1] *= sin(angle);
/* Scale by displacement amount, and apply. */
madd_v2_v2fl(&pt->x, mvec, amplitude * 10.0f);
madd_v2_v2fl(pt->m_xy, mvec, amplitude * 10.0f);
}
}
@ -520,8 +520,7 @@ static void gpencil_brush_angle(bGPdata *gpd, Brush *brush, tGPspoint *pt, const
/* Apply to first point (only if there are 2 points because before no data to do it ) */
if (gpd->runtime.sbuffer_used == 1) {
mvec[0] = (mval[0] - (pt - 1)->x);
mvec[1] = (mval[1] - (pt - 1)->y);
sub_v2_v2v2(mvec, mval, (pt - 1)->m_xy);
normalize_v2(mvec);
/* uses > 1.0f to get a smooth transition in first point */
@ -533,8 +532,7 @@ static void gpencil_brush_angle(bGPdata *gpd, Brush *brush, tGPspoint *pt, const
/* apply from second point */
if (gpd->runtime.sbuffer_used >= 1) {
mvec[0] = (mval[0] - (pt - 1)->x);
mvec[1] = (mval[1] - (pt - 1)->y);
sub_v2_v2v2(mvec, mval, (pt - 1)->m_xy);
normalize_v2(mvec);
fac = 1.0f - fabs(dot_v2v2(v0, mvec)); /* 0.0 to 1.0 */
@ -581,25 +579,25 @@ static void gpencil_smooth_buffer(tGPsdata *p, float inf, int idx)
/* Compute smoothed coordinate by taking the ones nearby */
if (pta) {
copy_v2_v2(a, &pta->x);
copy_v2_v2(a, pta->m_xy);
madd_v2_v2fl(sco, a, average_fac);
pressure += pta->pressure * average_fac;
strength += pta->strength * average_fac;
}
if (ptb) {
copy_v2_v2(b, &ptb->x);
copy_v2_v2(b, &ptb->m_xy);
madd_v2_v2fl(sco, b, average_fac);
pressure += ptb->pressure * average_fac;
strength += ptb->strength * average_fac;
}
if (ptc) {
copy_v2_v2(c, &ptc->x);
copy_v2_v2(c, ptc->m_xy);
madd_v2_v2fl(sco, c, average_fac);
pressure += ptc->pressure * average_fac;
strength += ptc->strength * average_fac;
}
if (ptd) {
copy_v2_v2(d, &ptd->x);
copy_v2_v2(d, ptd->m_xy);
madd_v2_v2fl(sco, d, average_fac);
pressure += ptd->pressure * average_fac;
strength += ptd->strength * average_fac;
@ -609,7 +607,7 @@ static void gpencil_smooth_buffer(tGPsdata *p, float inf, int idx)
* for Guide mode. */
if (!guide->use_guide) {
interp_v2_v2v2(c, c, sco, inf);
copy_v2_v2(&ptc->x, c);
copy_v2_v2(ptc->m_xy, c);
}
/* Interpolate pressure. */
ptc->pressure = interpf(ptc->pressure, pressure, inf);
@ -646,37 +644,37 @@ static void gpencil_smooth_segment(bGPdata *gpd, const float inf, int from_idx,
/* Compute smoothed coordinate by taking the ones nearby */
if (pta) {
madd_v2_v2fl(sco, &pta->x, average_fac);
madd_v2_v2fl(sco, pta->m_xy, average_fac);
pressure += pta->pressure * average_fac;
strength += pta->strength * average_fac;
}
else {
madd_v2_v2fl(sco, &ptc->x, average_fac);
madd_v2_v2fl(sco, ptc->m_xy, average_fac);
pressure += ptc->pressure * average_fac;
strength += ptc->strength * average_fac;
}
if (ptb) {
madd_v2_v2fl(sco, &ptb->x, average_fac);
madd_v2_v2fl(sco, ptb->m_xy, average_fac);
pressure += ptb->pressure * average_fac;
strength += ptb->strength * average_fac;
}
else {
madd_v2_v2fl(sco, &ptc->x, average_fac);
madd_v2_v2fl(sco, ptc->m_xy, average_fac);
pressure += ptc->pressure * average_fac;
strength += ptc->strength * average_fac;
}
madd_v2_v2fl(sco, &ptc->x, average_fac);
madd_v2_v2fl(sco, ptc->m_xy, average_fac);
pressure += ptc->pressure * average_fac;
strength += ptc->strength * average_fac;
madd_v2_v2fl(sco, &ptd->x, average_fac);
madd_v2_v2fl(sco, ptd->m_xy, average_fac);
pressure += ptd->pressure * average_fac;
strength += ptd->strength * average_fac;
/* Based on influence factor, blend between original and optimal smoothed coordinate. */
interp_v2_v2v2(&ptc->x, &ptc->x, sco, inf);
interp_v2_v2v2(ptc->m_xy, ptc->m_xy, sco, inf);
/* Interpolate pressure. */
ptc->pressure = interpf(ptc->pressure, pressure, inf);
@ -738,7 +736,7 @@ static void gpencil_apply_randomness(tGPsdata *p,
/* Apply randomness to uv texture rotation. */
if ((brush_settings->uv_random > 0.0f) && (uv)) {
if ((brush_settings->flag2 & GP_BRUSH_USE_UV_AT_STROKE) == 0) {
float rand = BLI_hash_int_01(BLI_hash_int_2d((int)pt->x, gpd->runtime.sbuffer_used)) * 2.0f -
float rand = BLI_hash_int_01(BLI_hash_int_2d((int)pt->m_xy[0], gpd->runtime.sbuffer_used)) * 2.0f -
1.0f;
value = rand * M_PI_2 * brush_settings->uv_random;
}
@ -778,7 +776,7 @@ static short gpencil_stroke_addpoint(tGPsdata *p,
pt = (tGPspoint *)(gpd->runtime.sbuffer);
/* store settings */
copy_v2_v2(&pt->x, mval);
copy_v2_v2(pt->m_xy, mval);
/* T44932 - Pressure vals are unreliable, so ignore for now */
pt->pressure = 1.0f;
pt->strength = 1.0f;
@ -794,7 +792,7 @@ static short gpencil_stroke_addpoint(tGPsdata *p,
pt = ((tGPspoint *)(gpd->runtime.sbuffer) + 1);
/* store settings */
copy_v2_v2(&pt->x, mval);
copy_v2_v2(pt->m_xy, mval);
/* T44932 - Pressure vals are unreliable, so ignore for now */
pt->pressure = 1.0f;
pt->strength = 1.0f;
@ -825,7 +823,7 @@ static short gpencil_stroke_addpoint(tGPsdata *p,
pt->strength = brush_settings->draw_strength;
pt->pressure = 1.0f;
pt->uv_rot = 0.0f;
copy_v2_v2(&pt->x, mval);
copy_v2_v2(pt->m_xy, mval);
/* pressure */
if (brush_settings->flag & GP_BRUSH_USE_PRESSURE) {
@ -1013,7 +1011,7 @@ static void gpencil_stroke_newfrombuffer(tGPsdata *p)
ptc = gpd->runtime.sbuffer;
/* convert screen-coordinates to appropriate coordinates (and store them) */
gpencil_stroke_convertcoords(p, &ptc->x, &pt->x, NULL);
gpencil_stroke_convertcoords(p, ptc->m_xy, &pt->x, NULL);
/* copy pressure and time */
pt->pressure = ptc->pressure;
pt->strength = ptc->strength;
@ -1047,7 +1045,7 @@ static void gpencil_stroke_newfrombuffer(tGPsdata *p)
ptc = ((tGPspoint *)gpd->runtime.sbuffer) + (gpd->runtime.sbuffer_used - 1);
/* convert screen-coordinates to appropriate coordinates (and store them) */
gpencil_stroke_convertcoords(p, &ptc->x, &pt->x, NULL);
gpencil_stroke_convertcoords(p, ptc->m_xy, &pt->x, NULL);
/* copy pressure and time */
pt->pressure = ptc->pressure;
pt->strength = ptc->strength;
@ -1100,7 +1098,7 @@ static void gpencil_stroke_newfrombuffer(tGPsdata *p)
int i;
for (i = 0, ptc = gpd->runtime.sbuffer; i < gpd->runtime.sbuffer_used; i++, ptc++, pt++) {
round_v2i_v2fl(mval_i, &ptc->x);
round_v2i_v2fl(mval_i, ptc->m_xy);
if ((ED_view3d_depth_read_cached(depths, mval_i, depth_margin, depth_arr + i) == 0) &&
(i && (ED_view3d_depth_read_cached_seg(
@ -1171,7 +1169,7 @@ static void gpencil_stroke_newfrombuffer(tGPsdata *p)
for (i = 0, ptc = gpd->runtime.sbuffer; i < gpd->runtime.sbuffer_used && ptc;
i++, ptc++, pt++) {
/* convert screen-coordinates to appropriate coordinates (and store them) */
gpencil_stroke_convertcoords(p, &ptc->x, &pt->x, depth_arr ? depth_arr + i : NULL);
gpencil_stroke_convertcoords(p, ptc->m_xy, &pt->x, depth_arr ? depth_arr + i : NULL);
/* copy pressure and time */
pt->pressure = ptc->pressure;
@ -2798,14 +2796,14 @@ static void gpencil_draw_apply(bContext *C, wmOperator *op, tGPsdata *p, Depsgra
pt = (tGPspoint *)gpd->runtime.sbuffer + gpd->runtime.sbuffer_used - 1;
if (p->paintmode != GP_PAINTMODE_ERASER) {
ED_gpencil_toggle_brush_cursor(C, true, &pt->x);
ED_gpencil_toggle_brush_cursor(C, true, pt->m_xy);
}
}
else if ((p->brush->gpencil_settings->flag & GP_BRUSH_STABILIZE_MOUSE_TEMP) &&
(gpd->runtime.sbuffer_used > 0)) {
pt = (tGPspoint *)gpd->runtime.sbuffer + gpd->runtime.sbuffer_used - 1;
if (p->paintmode != GP_PAINTMODE_ERASER) {
ED_gpencil_toggle_brush_cursor(C, true, &pt->x);
ED_gpencil_toggle_brush_cursor(C, true, pt->m_xy);
}
}
}
@ -3303,8 +3301,7 @@ static void gpencil_brush_angle_segment(tGPsdata *p, tGPspoint *pt_prev, tGPspoi
/* angle vector of the brush with full thickness */
const float v0[2] = {cos(angle), sin(angle)};
mvec[0] = pt->x - pt_prev->x;
mvec[1] = pt->y - pt_prev->y;
sub_v2_v2v2(mvec, pt->m_xy, pt_prev->m_xy);
normalize_v2(mvec);
fac = 1.0f - fabs(dot_v2v2(v0, mvec)); /* 0.0 to 1.0 */
/* interpolate with previous point for smoother transitions */
@ -3355,11 +3352,11 @@ static void gpencil_add_arc_points(tGPsdata *p, const float mval[2], int segment
* for arc curve.
*/
float v_prev[2], v_cur[2], v_half[2];
sub_v2_v2v2(v_cur, mval, &pt_prev->x);
sub_v2_v2v2(v_cur, mval, pt_prev->m_xy);
sub_v2_v2v2(v_prev, &pt_prev->x, &pt_before->x);
interp_v2_v2v2(v_half, &pt_prev->x, mval, 0.5f);
sub_v2_v2(v_half, &pt_prev->x);
sub_v2_v2v2(v_prev, pt_prev->m_xy, pt_before->m_xy);
interp_v2_v2v2(v_half, pt_prev->m_xy, mval, 0.5f);
sub_v2_v2(v_half, pt_prev->m_xy);
/* If angle is too sharp undo all changes and return. */
const float min_angle = DEG2RADF(120.0f);
@ -3378,14 +3375,14 @@ static void gpencil_add_arc_points(tGPsdata *p, const float mval[2], int segment
/* Calc the position of the control point. */
float ctl[2];
add_v2_v2v2(ctl, &pt_prev->x, v_prev);
add_v2_v2v2(ctl, pt_prev->m_xy, v_prev);
float step = M_PI_2 / (float)(segments + 1);
float a = step;
float midpoint[2], start[2], end[2], cp1[2], corner[2];
mid_v2_v2v2(midpoint, &pt_prev->x, mval);
copy_v2_v2(start, &pt_prev->x);
mid_v2_v2v2(midpoint, pt_prev->m_xy, mval);
copy_v2_v2(start, pt_prev->m_xy);
copy_v2_v2(end, mval);
copy_v2_v2(cp1, ctl);
@ -3396,8 +3393,8 @@ static void gpencil_add_arc_points(tGPsdata *p, const float mval[2], int segment
tGPspoint *pt_step = pt_prev;
for (int i = 0; i < segments; i++) {
pt = &points[idx_prev + i - 1];
pt->x = corner[0] + (end[0] - corner[0]) * sinf(a) + (start[0] - corner[0]) * cosf(a);
pt->y = corner[1] + (end[1] - corner[1]) * sinf(a) + (start[1] - corner[1]) * cosf(a);
pt->m_xy[0] = corner[0] + (end[0] - corner[0]) * sinf(a) + (start[0] - corner[0]) * cosf(a);
pt->m_xy[1] = corner[1] + (end[1] - corner[1]) * sinf(a) + (start[1] - corner[1]) * cosf(a);
/* Set pressure and strength equals to previous. It will be smoothed later. */
pt->pressure = pt_prev->pressure;
@ -3460,8 +3457,8 @@ static void gpencil_add_guide_points(const tGPsdata *p,
for (int i = 0; i < segments; i++) {
pt = &points[idx_prev + i - 1];
gpencil_rotate_v2_v2v2fl(&pt->x, start, p->guide.origin, -a);
gpencil_snap_to_guide(p, guide, &pt->x);
gpencil_rotate_v2_v2v2fl(pt->m_xy, start, p->guide.origin, -a);
gpencil_snap_to_guide(p, guide, pt->m_xy);
a += step;
/* Set pressure and strength equals to previous. It will be smoothed later. */
@ -3477,8 +3474,8 @@ static void gpencil_add_guide_points(const tGPsdata *p,
for (int i = 0; i < segments; i++) {
pt = &points[idx_prev + i - 1];
interp_v2_v2v2(&pt->x, start, end, a);
gpencil_snap_to_guide(p, guide, &pt->x);
interp_v2_v2v2(pt->m_xy, start, end, a);
gpencil_snap_to_guide(p, guide, pt->m_xy);
a += step;
/* Set pressure and strength equals to previous. It will be smoothed later. */

View File

@ -541,7 +541,7 @@ static void gpencil_primitive_rectangle(tGPDprimitive *tgpi, tGPspoint *points2D
if (tgpi->tot_edges == 1) {
for (int j = 0; j < 4; j++) {
tGPspoint *p2d = &points2D[j];
copy_v2_v2(&p2d->x, coords[j]);
copy_v2_v2(p2d->m_xy, coords[j]);
}
}
else {
@ -551,7 +551,7 @@ static void gpencil_primitive_rectangle(tGPDprimitive *tgpi, tGPspoint *points2D
float a = 0.0f;
for (int k = 0; k < tgpi->tot_edges; k++) {
tGPspoint *p2d = &points2D[i];
interp_v2_v2v2(&p2d->x, coords[j], coords[j + 1], a);
interp_v2_v2v2(p2d->m_xy, coords[j], coords[j + 1], a);
a += step;
i++;
}
@ -582,7 +582,7 @@ static void gpencil_primitive_line(tGPDprimitive *tgpi, tGPspoint *points2D, boo
for (int i = tgpi->tot_stored_edges; i < totpoints; i++) {
tGPspoint *p2d = &points2D[i];
interp_v2_v2v2(&p2d->x, tgpi->start, tgpi->end, a);
interp_v2_v2v2(p2d->m_xy, tgpi->start, tgpi->end, a);
a += step;
}
@ -628,8 +628,8 @@ static void gpencil_primitive_arc(tGPDprimitive *tgpi, tGPspoint *points2D)
for (int i = tgpi->tot_stored_edges; i < totpoints; i++) {
tGPspoint *p2d = &points2D[i];
p2d->x = corner[0] + (end[0] - corner[0]) * sinf(a) + (start[0] - corner[0]) * cosf(a);
p2d->y = corner[1] + (end[1] - corner[1]) * sinf(a) + (start[1] - corner[1]) * cosf(a);
p2d->m_xy[0] = corner[0] + (end[0] - corner[0]) * sinf(a) + (start[0] - corner[0]) * cosf(a);
p2d->m_xy[1] = corner[1] + (end[1] - corner[1]) * sinf(a) + (start[1] - corner[1]) * cosf(a);
a += step;
}
float color[4];
@ -664,7 +664,7 @@ static void gpencil_primitive_bezier(tGPDprimitive *tgpi, tGPspoint *points2D)
for (int i = tgpi->tot_stored_edges; i < totpoints; i++) {
tGPspoint *p2d = &points2D[i];
interp_v2_v2v2v2v2_cubic(&p2d->x, bcp1, bcp2, bcp3, bcp4, a);
interp_v2_v2v2v2v2_cubic(p2d->m_xy, bcp1, bcp2, bcp3, bcp4, a);
a += step;
}
float color[4];
@ -698,8 +698,8 @@ static void gpencil_primitive_circle(tGPDprimitive *tgpi, tGPspoint *points2D)
for (int i = tgpi->tot_stored_edges; i < totpoints; i++) {
tGPspoint *p2d = &points2D[i];
p2d->x = (center[0] + cosf(a) * radius[0]);
p2d->y = (center[1] + sinf(a) * radius[1]);
p2d->m_xy[0] = (center[0] + cosf(a) * radius[0]);
p2d->m_xy[1] = (center[1] + sinf(a) * radius[1]);
a += step;
}
float color[4];
@ -801,7 +801,7 @@ static void gpencil_primitive_update_strokes(bContext *C, tGPDprimitive *tgpi)
const ViewDepths *depths = tgpi->depths;
tGPspoint *ptc = &points2D[0];
for (int i = 0; i < gps->totpoints; i++, ptc++) {
round_v2i_v2fl(mval_i, &ptc->x);
round_v2i_v2fl(mval_i, ptc->m_xy);
if ((ED_view3d_depth_read_cached(depths, mval_i, depth_margin, depth_arr + i) == 0) &&
(i && (ED_view3d_depth_read_cached_seg(
depths, mval_i, mval_prev, depth_margin + 1, depth_arr + i) == 0))) {
@ -894,7 +894,7 @@ static void gpencil_primitive_update_strokes(bContext *C, tGPDprimitive *tgpi)
/* Store original points */
float tmp_xyp[2];
copy_v2_v2(tmp_xyp, &p2d->x);
copy_v2_v2(tmp_xyp, p2d->m_xy);
/* calc pressure */
float curve_pressure = 1.0;
@ -926,8 +926,7 @@ static void gpencil_primitive_update_strokes(bContext *C, tGPDprimitive *tgpi)
/* vector */
float mvec[2], svec[2];
if (i > 0) {
mvec[0] = (p2d->x - (p2d - 1)->x);
mvec[1] = (p2d->y - (p2d - 1)->y);
sub_v2_v2v2(mvec, p2d->m_xy, (p2d - 1)->m_xy);
normalize_v2(mvec);
}
else {
@ -942,7 +941,7 @@ static void gpencil_primitive_update_strokes(bContext *C, tGPDprimitive *tgpi)
else {
mul_v2_fl(svec, fac);
}
add_v2_v2(&p2d->x, svec);
add_v2_v2(p2d->m_xy, svec);
}
/* color strength */
@ -992,7 +991,7 @@ static void gpencil_primitive_update_strokes(bContext *C, tGPDprimitive *tgpi)
}
}
copy_v2_v2(&tpt->x, &p2d->x);
copy_v2_v2(tpt->m_xy, p2d->m_xy);
tpt->pressure = pressure;
tpt->strength = strength;
@ -1064,7 +1063,7 @@ static void gpencil_primitive_update_strokes(bContext *C, tGPDprimitive *tgpi)
}
/* Restore original points */
copy_v2_v2(&p2d->x, tmp_xyp);
copy_v2_v2(p2d->m_xy, tmp_xyp);
}
/* store cps and convert coords */
@ -1617,7 +1616,7 @@ static void gpencil_primitive_move(tGPDprimitive *tgpi, bool reset)
for (int i = 0; i < gps->totpoints; i++) {
tGPspoint *p2d = &points2D[i];
add_v2_v2(&p2d->x, move);
add_v2_v2(p2d->m_xy, move);
}
add_v2_v2(tgpi->start, move);

View File

@ -870,7 +870,7 @@ void gpencil_stroke_convertcoords_tpoint(Scene *scene,
}
int mval_i[2];
round_v2i_v2fl(mval_i, &point2D->x);
round_v2i_v2fl(mval_i, point2D->m_xy);
if ((depth != NULL) && (ED_view3d_autodist_simple(region, mval_i, r_out, 0, depth))) {
/* projecting onto 3D-Geometry
@ -878,7 +878,7 @@ void gpencil_stroke_convertcoords_tpoint(Scene *scene,
*/
}
else {
float mval_f[2] = {point2D->x, point2D->y};
float mval_f[2] = {UNPACK2(point2D->m_xy)};
float mval_prj[2];
float rvec[3], dvec[3];
float zfac;
@ -2020,7 +2020,7 @@ static void gpencil_stroke_convertcoords(ARegion *region,
const float origin[3],
float out[3])
{
float mval_f[2] = {(float)point2D->x, (float)point2D->y};
float mval_f[2] = {UNPACK2(point2D->m_xy)};
float mval_prj[2];
float rvec[3], dvec[3];
float zfac;
@ -2808,8 +2808,8 @@ static void gpencil_sbuffer_vertex_color_random(
if (brush_settings->flag & GP_BRUSH_GROUP_RANDOM) {
int seed = ((uint)(ceil(PIL_check_seconds_timer())) + 1) % 128;
int ix = (int)(tpt->x * seed);
int iy = (int)(tpt->y * seed);
int ix = (int)(tpt->m_xy[0] * seed);
int iy = (int)(tpt->m_xy[1] * seed);
int iz = ix + iy * seed;
float hsv[3];
float factor_value[3];

View File

@ -94,7 +94,7 @@ typedef enum eGP_TargetObjectMode {
*/
typedef struct tGPspoint {
/** Coordinates x and y of cursor (in relative to area). */
float x, y;
float m_xy[2];
/** Pressure of tablet at this point. */
float pressure;
/** Pressure of tablet at this point for alpha factor. */