Skip to content

Commit ac6d5fd

Browse files
committed
Style.
1 parent 6f2bb54 commit ac6d5fd

File tree

2 files changed

+34
-39
lines changed

2 files changed

+34
-39
lines changed

src/_mplcairo.cpp

+23-26
Original file line numberDiff line numberDiff line change
@@ -613,9 +613,9 @@ void GraphicsContextRenderer::set_clip_path(
613613
auto const& [path, transform] =
614614
transformed_path->attr("get_transformed_path_and_affine")()
615615
.cast<std::tuple<py::object, py::object>>();
616-
auto const& matrix =
616+
auto const& mtx =
617617
matrix_from_transform(transform, get_additional_state().height);
618-
load_path_exact(cr_, path, &matrix);
618+
load_path_exact(cr_, path, &mtx);
619619
get_additional_state().clip_path =
620620
{transformed_path, {cairo_copy_path(cr_), cairo_path_destroy}};
621621
} else {
@@ -778,8 +778,7 @@ void GraphicsContextRenderer::draw_gouraud_triangles(
778778
throw std::invalid_argument{"non-matching GraphicsContext"};
779779
}
780780
auto const& ac = _additional_context();
781-
auto matrix =
782-
matrix_from_transform(transform, get_additional_state().height);
781+
auto mtx = matrix_from_transform(transform, get_additional_state().height);
783782
auto const& tri_raw = triangles.unchecked<3>();
784783
auto const& col_raw = colors.unchecked<3>();
785784
auto const& n = tri_raw.shape(0);
@@ -803,8 +802,8 @@ void GraphicsContextRenderer::draw_gouraud_triangles(
803802
}
804803
cairo_mesh_pattern_end_patch(pattern);
805804
}
806-
cairo_matrix_invert(&matrix);
807-
cairo_pattern_set_matrix(pattern, &matrix);
805+
cairo_matrix_invert(&mtx);
806+
cairo_pattern_set_matrix(pattern, &mtx);
808807
cairo_set_source(cr_, pattern);
809808
cairo_pattern_destroy(pattern);
810809
cairo_paint(cr_);
@@ -879,9 +878,9 @@ void GraphicsContextRenderer::draw_image(
879878
}
880879
auto const& pattern = cairo_pattern_create_for_surface(surface);
881880
cairo_surface_destroy(surface);
882-
auto const& matrix =
881+
auto const& mtx =
883882
cairo_matrix_t{1, 0, 0, -1, -x, -y + get_additional_state().height};
884-
cairo_pattern_set_matrix(pattern, &matrix);
883+
cairo_pattern_set_matrix(pattern, &mtx);
885884
cairo_set_source(cr_, pattern);
886885
cairo_pattern_destroy(pattern);
887886
cairo_paint(cr_);
@@ -909,7 +908,7 @@ void GraphicsContextRenderer::draw_markers(
909908
auto const& n_vertices = vertices.shape(0);
910909

911910
auto const& marker_matrix = matrix_from_transform(marker_transform);
912-
auto const& matrix =
911+
auto const& mtx =
913912
matrix_from_transform(transform, get_additional_state().height);
914913

915914
auto const& fc_raw_opt =
@@ -998,7 +997,7 @@ void GraphicsContextRenderer::draw_markers(
998997
auto worker = [&](cairo_t* ctx, int start, int stop) {
999998
for (auto i = start; i < stop; ++i) {
1000999
auto x = vertices(i, 0), y = vertices(i, 1);
1001-
cairo_matrix_transform_point(&matrix, &x, &y);
1000+
cairo_matrix_transform_point(&mtx, &x, &y);
10021001
auto const& target_x = x + x0,
10031002
& target_y = y + y0;
10041003
if (!(std::isfinite(target_x) && std::isfinite(target_y))) {
@@ -1011,7 +1010,7 @@ void GraphicsContextRenderer::draw_markers(
10111010
auto const& idx =
10121011
int(n_subpix * f_target_x) * n_subpix + int(n_subpix * f_target_y);
10131012
auto const& pattern = patterns[idx];
1014-
// Offsetting by height is already taken care of by matrix.
1013+
// Offsetting by height is already taken care of by mtx.
10151014
auto const& pattern_matrix =
10161015
cairo_matrix_t{1, 0, 0, 1, -i_target_x, -i_target_y};
10171016
cairo_pattern_set_matrix(pattern, &pattern_matrix);
@@ -1068,7 +1067,7 @@ void GraphicsContextRenderer::draw_markers(
10681067
cairo_surface_flush(surface);
10691068
for (auto i = 0; i < n_vertices; ++i) {
10701069
auto x = vertices(i, 0), y = vertices(i, 1);
1071-
cairo_matrix_transform_point(&matrix, &x, &y);
1070+
cairo_matrix_transform_point(&mtx, &x, &y);
10721071
if (!(std::isfinite(x) && std::isfinite(y))) {
10731072
continue;
10741073
}
@@ -1082,7 +1081,7 @@ void GraphicsContextRenderer::draw_markers(
10821081
for (auto i = 0; i < n_vertices; ++i) {
10831082
cairo_save(cr_);
10841083
auto x = vertices(i, 0), y = vertices(i, 1);
1085-
cairo_matrix_transform_point(&matrix, &x, &y);
1084+
cairo_matrix_transform_point(&mtx, &x, &y);
10861085
if (!(std::isfinite(x) && std::isfinite(y))) {
10871086
cairo_restore(cr_);
10881087
continue;
@@ -1104,19 +1103,18 @@ void GraphicsContextRenderer::draw_path(
11041103
}
11051104
auto const& ac = _additional_context();
11061105
auto path_loaded = false;
1107-
auto matrix =
1108-
matrix_from_transform(transform, get_additional_state().height);
1106+
auto mtx = matrix_from_transform(transform, get_additional_state().height);
11091107
auto const& load_path = [&] {
11101108
if (!path_loaded) {
1111-
load_path_exact(cr_, path, &matrix);
1109+
load_path_exact(cr_, path, &mtx);
11121110
path_loaded = true;
11131111
}
11141112
};
11151113
if (auto const& sketch = get_additional_state().sketch) {
11161114
path =
11171115
path.attr("cleaned")(
11181116
"transform"_a=transform, "curves"_a=true, "sketch"_a=sketch);
1119-
matrix = cairo_matrix_t{1, 0, 0, -1, 0, get_additional_state().height};
1117+
mtx = cairo_matrix_t{1, 0, 0, -1, 0, get_additional_state().height};
11201118
}
11211119
if (fc) {
11221120
load_path();
@@ -1140,11 +1138,11 @@ void GraphicsContextRenderer::draw_path(
11401138
hatch_cr, double(dpi), double(dpi), double(dpi)};
11411139
hatch_gcr.get_additional_state().snap = false;
11421140
hatch_gcr.set_linewidth(get_additional_state().get_hatch_linewidth());
1143-
auto const& matrix =
1141+
auto const& mtx =
11441142
cairo_matrix_t{double(dpi), 0, 0, -double(dpi), 0, double(dpi)};
11451143
auto const& hatch_color = get_additional_state().get_hatch_color();
11461144
fill_and_stroke_exact(
1147-
hatch_cr, *hatch_path, &matrix, hatch_color, hatch_color);
1145+
hatch_cr, *hatch_path, &mtx, hatch_color, hatch_color);
11481146
auto const& hatch_pattern =
11491147
cairo_pattern_create_for_surface(cairo_get_target(hatch_cr));
11501148
cairo_pattern_set_extend(hatch_pattern, CAIRO_EXTEND_REPEAT);
@@ -1163,8 +1161,7 @@ void GraphicsContextRenderer::draw_path(
11631161
auto const& vertices = path.attr("vertices").cast<py::array_t<double>>();
11641162
auto const& n = vertices.shape(0);
11651163
for (auto i = decltype(n)(0); i < n; i += chunksize) {
1166-
load_path_exact(
1167-
cr_, vertices, i, std::min(i + chunksize + 1, n), &matrix);
1164+
load_path_exact(cr_, vertices, i, std::min(i + chunksize + 1, n), &mtx);
11681165
cairo_stroke(cr_);
11691166
}
11701167
}
@@ -1270,7 +1267,7 @@ void GraphicsContextRenderer::draw_path_collection(
12701267
// FIXME: Implement parallelization.
12711268
for (auto i = 0; i < n; ++i) {
12721269
auto const& path = paths[i % n_paths];
1273-
auto const& matrix = matrices[i % n_transforms];
1270+
auto const& mtx = matrices[i % n_transforms];
12741271
auto x = offsets_raw(i % n_offsets, 0), y = offsets_raw(i % n_offsets, 1);
12751272
cairo_matrix_transform_point(&offset_matrix, &x, &y);
12761273
if (!(std::isfinite(x) && std::isfinite(y))) {
@@ -1281,7 +1278,7 @@ void GraphicsContextRenderer::draw_path_collection(
12811278
cairo_set_source_rgba(
12821279
cr_, fcs_raw(i_mod, 0), fcs_raw(i_mod, 1),
12831280
fcs_raw(i_mod, 2), fcs_raw(i_mod, 3));
1284-
cache.mask(cr_, path, matrix, draw_func_t::Fill, 0, {}, x, y);
1281+
cache.mask(cr_, path, mtx, draw_func_t::Fill, 0, {}, x, y);
12851282
}
12861283
if (ecs_raw.size()) {
12871284
auto const& i_mod = i % ecs_raw.shape(0);
@@ -1292,7 +1289,7 @@ void GraphicsContextRenderer::draw_path_collection(
12921289
? points_to_pixels(lws_raw[i % lws_raw.size()])
12931290
: cairo_get_line_width(cr_);
12941291
auto const& dash = dashes_raw[i % n_dashes];
1295-
cache.mask(cr_, path, matrix, draw_func_t::Stroke, lw, dash, x, y);
1292+
cache.mask(cr_, path, mtx, draw_func_t::Stroke, lw, dash, x, y);
12961293
}
12971294
// NOTE: We drop antialiaseds because that just seems silly.
12981295
// We drop urls as they should be handled in a post-processing step anyways
@@ -1325,7 +1322,7 @@ void GraphicsContextRenderer::draw_quad_mesh(
13251322
throw std::invalid_argument{"non-matching GraphicsContext"};
13261323
}
13271324
auto const& ac = _additional_context();
1328-
auto const& matrix =
1325+
auto const& mtx =
13291326
matrix_from_transform(master_transform, get_additional_state().height);
13301327
auto const& fcs_raw = fcs.unchecked<2>(),
13311328
& ecs_raw = ecs.unchecked<2>();
@@ -1353,7 +1350,7 @@ void GraphicsContextRenderer::draw_quad_mesh(
13531350
for (auto i = 0; i < mesh_height + 1; ++i) {
13541351
for (auto j = 0; j < mesh_width + 1; ++j) {
13551352
cairo_matrix_transform_point(
1356-
&matrix,
1353+
&mtx,
13571354
coords_raw.mutable_data(i, j, 0), coords_raw.mutable_data(i, j, 1));
13581355
}
13591356
}

src/_util.cpp

+11-13
Original file line numberDiff line numberDiff line change
@@ -147,12 +147,12 @@ cairo_matrix_t matrix_from_transform(
147147
"not {.shape}"_format(transform).cast<std::string>()};
148148
}
149149
// The y flip is already handled by the master matrix.
150-
auto matrix = cairo_matrix_t{
150+
auto mtx = cairo_matrix_t{
151151
py_matrix(0, 0), py_matrix(1, 0),
152152
py_matrix(0, 1), py_matrix(1, 1),
153153
py_matrix(0, 2), py_matrix(1, 2)};
154-
cairo_matrix_multiply(&matrix, &matrix, master_matrix);
155-
return matrix;
154+
cairo_matrix_multiply(&mtx, &mtx, master_matrix);
155+
return mtx;
156156
}
157157

158158
bool has_vector_surface(cairo_t* cr)
@@ -184,24 +184,22 @@ bool has_vector_surface(cairo_t* cr)
184184
// for cairo_t*'s that we may not have initialized.
185185
AdditionalState& get_additional_state(cairo_t* cr)
186186
{
187-
auto const& data = cairo_get_user_data(cr, &detail::STATE_KEY);
188-
if (!data) {
187+
auto const stack = static_cast<std::stack<AdditionalState>*>(
188+
cairo_get_user_data(cr, &detail::STATE_KEY));
189+
if (!stack || stack->empty()) {
189190
throw std::runtime_error{"cairo_t* missing additional state"};
190191
}
191-
auto& stack = *static_cast<std::stack<AdditionalState>*>(data);
192-
if (stack.empty()) {
193-
throw std::runtime_error{"cairo_t* missing additional state"};
194-
}
195-
return stack.top();
192+
return stack->top();
196193
}
197194

198195
void restore_init_matrix(cairo_t* cr)
199196
{
200-
auto const& data = cairo_get_user_data(cr, &detail::INIT_MATRIX_KEY);
201-
if (!data) {
197+
auto const mtx = static_cast<cairo_matrix_t*>(
198+
cairo_get_user_data(cr, &detail::INIT_MATRIX_KEY));
199+
if (!mtx) {
202200
cairo_identity_matrix(cr);
203201
} else {
204-
cairo_set_matrix(cr, static_cast<cairo_matrix_t*>(data));
202+
cairo_set_matrix(cr, mtx);
205203
}
206204
}
207205

0 commit comments

Comments
 (0)