Skip to content

Commit 0feec0a

Browse files
committed
Use the word "snapping" everywhere for consistency. This is the word used in the outward-facing interface all along.
svn path=/trunk/matplotlib/; revision=8437
1 parent 9e7c950 commit 0feec0a

File tree

8 files changed

+106
-105
lines changed

8 files changed

+106
-105
lines changed

lib/matplotlib/path.py

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -188,7 +188,7 @@ def __len__(self):
188188
return len(self.vertices)
189189

190190
def iter_segments(self, transform=None, remove_nans=True, clip=None,
191-
quantize=False, stroke_width=1.0, simplify=None,
191+
snap=False, stroke_width=1.0, simplify=None,
192192
curves=True):
193193
"""
194194
Iterates over all of the curve segments in the path. Each
@@ -208,11 +208,12 @@ def iter_segments(self, transform=None, remove_nans=True, clip=None,
208208
*clip*: if not None, must be a four-tuple (x1, y1, x2, y2)
209209
defining a rectangle in which to clip the path.
210210
211-
*quantize*: if None, auto-quantize. If True, force quantize,
212-
and if False, don't quantize.
211+
*snap*: if None, auto-snap to pixels, to reduce
212+
fuzziness of rectilinear lines. If True, force snapping, and
213+
if False, don't snap.
213214
214215
*stroke_width*: the width of the stroke being drawn. Needed
215-
as a hint for the quantizer.
216+
as a hint for the snapping algorithm.
216217
217218
*simplify*: if True, perform simplification, to remove
218219
vertices that do not affect the appearance of the path. If
@@ -236,7 +237,7 @@ def iter_segments(self, transform=None, remove_nans=True, clip=None,
236237
STOP = self.STOP
237238

238239
vertices, codes = cleanup_path(self, transform, remove_nans, clip,
239-
quantize, stroke_width, simplify, curves)
240+
snap, stroke_width, simplify, curves)
240241
len_vertices = len(vertices)
241242

242243
i = 0

src/_backend_agg.cpp

Lines changed: 25 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -270,11 +270,11 @@ GCAgg::_set_snap( const Py::Object& gc) {
270270
Py::Callable method(method_obj);
271271
Py::Object py_snap = method.apply(Py::Tuple());
272272
if (py_snap.isNone()) {
273-
quantize_mode = QUANTIZE_AUTO;
273+
snap_mode = SNAP_AUTO;
274274
} else if (py_snap.isTrue()) {
275-
quantize_mode = QUANTIZE_TRUE;
275+
snap_mode = SNAP_TRUE;
276276
} else {
277-
quantize_mode = QUANTIZE_FALSE;
277+
snap_mode = SNAP_FALSE;
278278
}
279279
}
280280

@@ -506,8 +506,8 @@ bool RendererAgg::render_clippath(const Py::Object& clippath, const agg::trans_a
506506
Py::Object
507507
RendererAgg::draw_markers(const Py::Tuple& args) {
508508
typedef agg::conv_transform<PathIterator> transformed_path_t;
509-
typedef PathQuantizer<transformed_path_t> quantize_t;
510-
typedef agg::conv_curve<quantize_t> curve_t;
509+
typedef PathSnapper<transformed_path_t> snap_t;
510+
typedef agg::conv_curve<snap_t> curve_t;
511511
typedef agg::conv_stroke<curve_t> stroke_t;
512512
typedef agg::pixfmt_amask_adaptor<pixfmt, alpha_mask_type> pixfmt_amask_type;
513513
typedef agg::renderer_base<pixfmt_amask_type> amask_ren_type;
@@ -533,19 +533,19 @@ RendererAgg::draw_markers(const Py::Tuple& args) {
533533

534534
PathIterator marker_path(marker_path_obj);
535535
transformed_path_t marker_path_transformed(marker_path, marker_trans);
536-
quantize_t marker_path_quantized(marker_path_transformed,
537-
gc.quantize_mode,
538-
marker_path.total_vertices(),
539-
gc.linewidth);
540-
curve_t marker_path_curve(marker_path_quantized);
536+
snap_t marker_path_snapped(marker_path_transformed,
537+
gc.snap_mode,
538+
marker_path.total_vertices(),
539+
gc.linewidth);
540+
curve_t marker_path_curve(marker_path_snapped);
541541

542542
PathIterator path(path_obj);
543543
transformed_path_t path_transformed(path, trans);
544-
quantize_t path_quantized(path_transformed,
545-
gc.quantize_mode,
546-
path.total_vertices(),
547-
1.0);
548-
curve_t path_curve(path_quantized);
544+
snap_t path_snapped(path_transformed,
545+
gc.snap_mode,
546+
path.total_vertices(),
547+
1.0);
548+
curve_t path_curve(path_snapped);
549549
path_curve.rewind(0);
550550

551551
facepair_t face = _get_rgba_face(face_obj, gc.alpha);
@@ -1079,8 +1079,8 @@ RendererAgg::draw_path(const Py::Tuple& args) {
10791079
typedef agg::conv_transform<PathIterator> transformed_path_t;
10801080
typedef PathNanRemover<transformed_path_t> nan_removed_t;
10811081
typedef PathClipper<nan_removed_t> clipped_t;
1082-
typedef PathQuantizer<clipped_t> quantized_t;
1083-
typedef PathSimplifier<quantized_t> simplify_t;
1082+
typedef PathSnapper<clipped_t> snapped_t;
1083+
typedef PathSimplifier<snapped_t> simplify_t;
10841084
typedef agg::conv_curve<simplify_t> curve_t;
10851085

10861086
_VERBOSE("RendererAgg::draw_path");
@@ -1108,8 +1108,8 @@ RendererAgg::draw_path(const Py::Tuple& args) {
11081108
transformed_path_t tpath(path, trans);
11091109
nan_removed_t nan_removed(tpath, true, path.has_curves());
11101110
clipped_t clipped(nan_removed, clip, width, height);
1111-
quantized_t quantized(clipped, gc.quantize_mode, path.total_vertices(), gc.linewidth);
1112-
simplify_t simplified(quantized, simplify, path.simplify_threshold());
1111+
snapped_t snapped(clipped, gc.snap_mode, path.total_vertices(), gc.linewidth);
1112+
simplify_t simplified(snapped, simplify, path.simplify_threshold());
11131113
curve_t curve(simplified);
11141114

11151115
try {
@@ -1141,8 +1141,8 @@ RendererAgg::_draw_path_collection_generic
11411141
typedef agg::conv_transform<typename PathGenerator::path_iterator> transformed_path_t;
11421142
typedef PathNanRemover<transformed_path_t> nan_removed_t;
11431143
typedef PathClipper<nan_removed_t> clipped_t;
1144-
typedef PathQuantizer<clipped_t> quantized_t;
1145-
typedef agg::conv_curve<quantized_t> quantized_curve_t;
1144+
typedef PathSnapper<clipped_t> snapped_t;
1145+
typedef agg::conv_curve<snapped_t> snapped_curve_t;
11461146
typedef agg::conv_curve<clipped_t> curve_t;
11471147

11481148
PyArrayObject* offsets = NULL;
@@ -1275,13 +1275,13 @@ RendererAgg::_draw_path_collection_generic
12751275
transformed_path_t tpath(path, trans);
12761276
nan_removed_t nan_removed(tpath, true, has_curves);
12771277
clipped_t clipped(nan_removed, do_clip, width, height);
1278-
quantized_t quantized(clipped, gc.quantize_mode,
1279-
path.total_vertices(), gc.linewidth);
1278+
snapped_t snapped(clipped, gc.snap_mode,
1279+
path.total_vertices(), gc.linewidth);
12801280
if (has_curves) {
1281-
quantized_curve_t curve(quantized);
1281+
snapped_curve_t curve(snapped);
12821282
_draw_path(curve, has_clippath, face, gc);
12831283
} else {
1284-
_draw_path(quantized, has_clippath, face, gc);
1284+
_draw_path(snapped, has_clippath, face, gc);
12851285
}
12861286
} else {
12871287
gc.isaa = bool(Py::Int(antialiaseds[i % Naa]));

src/_backend_agg.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -123,7 +123,7 @@ class GCAgg {
123123
typedef std::vector<std::pair<double, double> > dash_t;
124124
double dashOffset;
125125
dash_t dashes;
126-
e_quantize_mode quantize_mode;
126+
e_snap_mode snap_mode;
127127

128128
Py::Object hatchpath;
129129

src/_macosx.m

Lines changed: 14 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -288,7 +288,7 @@ static void _draw_hatch(void *info, CGContextRef cr)
288288
0,
289289
0,
290290
rect,
291-
QUANTIZE_FALSE,
291+
SNAP_FALSE,
292292
1.0,
293293
0);
294294
Py_DECREF(transform);
@@ -446,13 +446,13 @@ static CGMutablePathRef _create_path(void* iterator)
446446
return p;
447447
}
448448

449-
static int _get_snap(GraphicsContext* self, enum e_quantize_mode* mode)
449+
static int _get_snap(GraphicsContext* self, enum e_snap_mode* mode)
450450
{
451451
PyObject* snap = PyObject_CallMethod((PyObject*)self, "get_snap", "");
452452
if(!snap) return 0;
453-
if(snap==Py_None) *mode = QUANTIZE_AUTO;
454-
else if (PyBool_Check(snap)) *mode = QUANTIZE_TRUE;
455-
else *mode = QUANTIZE_FALSE;
453+
if(snap==Py_None) *mode = SNAP_AUTO;
454+
else if (PyBool_Check(snap)) *mode = SNAP_TRUE;
455+
else *mode = SNAP_FALSE;
456456
Py_DECREF(snap);
457457
return 1;
458458
}
@@ -662,7 +662,7 @@ static int _get_snap(GraphicsContext* self, enum e_quantize_mode* mode)
662662
0,
663663
0,
664664
rect,
665-
QUANTIZE_AUTO,
665+
SNAP_AUTO,
666666
1.0,
667667
0);
668668
Py_DECREF(transform);
@@ -892,7 +892,7 @@ static int _get_snap(GraphicsContext* self, enum e_quantize_mode* mode)
892892
1,
893893
0,
894894
rect,
895-
QUANTIZE_AUTO,
895+
SNAP_AUTO,
896896
linewidth,
897897
rgbFace == NULL);
898898
if (!iterator)
@@ -970,7 +970,7 @@ static int _get_snap(GraphicsContext* self, enum e_quantize_mode* mode)
970970
1,
971971
0,
972972
rect,
973-
QUANTIZE_AUTO,
973+
SNAP_AUTO,
974974
linewidth,
975975
0);
976976
if (!iterator)
@@ -1006,7 +1006,7 @@ static int _get_snap(GraphicsContext* self, enum e_quantize_mode* mode)
10061006
CGMutablePathRef marker;
10071007
void* iterator;
10081008
double rect[4] = {0.0, 0.0, self->size.width, self->size.height};
1009-
enum e_quantize_mode mode;
1009+
enum e_snap_mode mode;
10101010
double xc, yc;
10111011
unsigned code;
10121012

@@ -1071,7 +1071,7 @@ static int _get_snap(GraphicsContext* self, enum e_quantize_mode* mode)
10711071
1,
10721072
1,
10731073
rect,
1074-
QUANTIZE_TRUE,
1074+
SNAP_TRUE,
10751075
1.0,
10761076
0);
10771077
if (!iterator)
@@ -1225,7 +1225,7 @@ static BOOL _clip(CGContextRef cr, PyObject* object)
12251225
/* --------- Prepare some variables for the path iterator ------------- */
12261226
void* iterator;
12271227
double rect[4] = {0.0, 0.0, self->size.width, self->size.height};
1228-
enum e_quantize_mode mode;
1228+
enum e_snap_mode mode;
12291229
ok = _get_snap(self, &mode);
12301230
if (!ok)
12311231
{
@@ -1382,7 +1382,7 @@ static BOOL _clip(CGContextRef cr, PyObject* object)
13821382
0,
13831383
0,
13841384
rect,
1385-
QUANTIZE_AUTO,
1385+
SNAP_AUTO,
13861386
1.0,
13871387
0);
13881388
if (!iterator)
@@ -1690,7 +1690,7 @@ static BOOL _clip(CGContextRef cr, PyObject* object)
16901690
0,
16911691
0,
16921692
rect,
1693-
QUANTIZE_AUTO,
1693+
SNAP_AUTO,
16941694
1.0,
16951695
0);
16961696
if (iterator)
@@ -2676,7 +2676,7 @@ static void _data_provider_release(void* info, const void* data, size_t size)
26762676
0,
26772677
0,
26782678
rect,
2679-
QUANTIZE_AUTO,
2679+
SNAP_AUTO,
26802680
1.0,
26812681
0);
26822682
if (iterator)

src/_path.cpp

Lines changed: 14 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -55,7 +55,7 @@ class _path_module : public Py::ExtensionModule<_path_module>
5555
add_varargs_method("convert_path_to_polygons", &_path_module::convert_path_to_polygons,
5656
"convert_path_to_polygons(path, trans, width, height)");
5757
add_varargs_method("cleanup_path", &_path_module::cleanup_path,
58-
"cleanup_path(path, trans, remove_nans, clip, quantize, simplify, curves)");
58+
"cleanup_path(path, trans, remove_nans, clip, snap, simplify, curves)");
5959
initialize("Helper functions for paths");
6060
}
6161

@@ -1228,22 +1228,22 @@ void __cleanup_path(VertexSource& source,
12281228
void _cleanup_path(PathIterator& path, const agg::trans_affine& trans,
12291229
bool remove_nans, bool do_clip,
12301230
const agg::rect_base<double>& rect,
1231-
e_quantize_mode quantize_mode, double stroke_width,
1231+
e_snap_mode snap_mode, double stroke_width,
12321232
bool do_simplify, bool return_curves,
12331233
std::vector<double>& vertices,
12341234
std::vector<npy_uint8>& codes) {
12351235
typedef agg::conv_transform<PathIterator> transformed_path_t;
12361236
typedef PathNanRemover<transformed_path_t> nan_removal_t;
12371237
typedef PathClipper<nan_removal_t> clipped_t;
1238-
typedef PathQuantizer<clipped_t> quantized_t;
1239-
typedef PathSimplifier<quantized_t> simplify_t;
1238+
typedef PathSnapper<clipped_t> snapped_t;
1239+
typedef PathSimplifier<snapped_t> simplify_t;
12401240
typedef agg::conv_curve<simplify_t> curve_t;
12411241

12421242
transformed_path_t tpath(path, trans);
12431243
nan_removal_t nan_removed(tpath, remove_nans, path.has_curves());
12441244
clipped_t clipped(nan_removed, do_clip, rect);
1245-
quantized_t quantized(clipped, quantize_mode, path.total_vertices(), stroke_width);
1246-
simplify_t simplified(quantized, do_simplify, path.simplify_threshold());
1245+
snapped_t snapped(clipped, snap_mode, path.total_vertices(), stroke_width);
1246+
simplify_t simplified(snapped, do_simplify, path.simplify_threshold());
12471247

12481248
vertices.reserve(path.total_vertices() * 2);
12491249
codes.reserve(path.total_vertices());
@@ -1286,19 +1286,19 @@ Py::Object _path_module::cleanup_path(const Py::Tuple& args)
12861286
do_clip = true;
12871287
}
12881288

1289-
Py::Object quantize_obj = args[4];
1290-
e_quantize_mode quantize_mode;
1291-
if (quantize_obj.isNone())
1289+
Py::Object snap_obj = args[4];
1290+
e_snap_mode snap_mode;
1291+
if (snap_obj.isNone())
12921292
{
1293-
quantize_mode = QUANTIZE_AUTO;
1293+
snap_mode = SNAP_AUTO;
12941294
}
1295-
else if (quantize_obj.isTrue())
1295+
else if (snap_obj.isTrue())
12961296
{
1297-
quantize_mode = QUANTIZE_TRUE;
1297+
snap_mode = SNAP_TRUE;
12981298
}
12991299
else
13001300
{
1301-
quantize_mode = QUANTIZE_FALSE;
1301+
snap_mode = SNAP_FALSE;
13021302
}
13031303

13041304
double stroke_width = Py::Float(args[5]);
@@ -1319,7 +1319,7 @@ Py::Object _path_module::cleanup_path(const Py::Tuple& args)
13191319
std::vector<double> vertices;
13201320
std::vector<npy_uint8> codes;
13211321

1322-
_cleanup_path(path, trans, remove_nans, do_clip, clip_rect, quantize_mode,
1322+
_cleanup_path(path, trans, remove_nans, do_clip, clip_rect, snap_mode,
13231323
stroke_width, simplify, return_curves, vertices, codes);
13241324

13251325
npy_intp length = codes.size();

src/path_cleanup.cpp

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -12,33 +12,33 @@ class PathCleanupIterator
1212
typedef agg::conv_transform<PathIterator> transformed_path_t;
1313
typedef PathNanRemover<transformed_path_t> nan_removal_t;
1414
typedef PathClipper<nan_removal_t> clipped_t;
15-
typedef PathQuantizer<clipped_t> quantized_t;
16-
typedef PathSimplifier<quantized_t> simplify_t;
15+
typedef PathSnapper<clipped_t> snapped_t;
16+
typedef PathSimplifier<snapped_t> simplify_t;
1717

1818
Py::Object m_path_obj;
1919
PathIterator m_path_iter;
2020
agg::trans_affine m_transform;
2121
transformed_path_t m_transformed;
2222
nan_removal_t m_nan_removed;
2323
clipped_t m_clipped;
24-
quantized_t m_quantized;
24+
snapped_t m_snapped;
2525
simplify_t m_simplify;
2626

2727
public:
2828
PathCleanupIterator(PyObject* path, agg::trans_affine trans,
2929
bool remove_nans, bool do_clip,
3030
const agg::rect_base<double>& rect,
31-
e_quantize_mode quantize_mode, double stroke_width,
31+
e_snap_mode snap_mode, double stroke_width,
3232
bool do_simplify) :
3333
m_path_obj(path, true),
3434
m_path_iter(m_path_obj),
3535
m_transform(trans),
3636
m_transformed(m_path_iter, m_transform),
3737
m_nan_removed(m_transformed, remove_nans, m_path_iter.has_curves()),
3838
m_clipped(m_nan_removed, do_clip, rect),
39-
m_quantized(m_clipped, quantize_mode, m_path_iter.total_vertices(),
40-
stroke_width),
41-
m_simplify(m_quantized, do_simplify && m_path_iter.should_simplify(),
39+
m_snapped(m_clipped, snap_mode, m_path_iter.total_vertices(),
40+
stroke_width),
41+
m_simplify(m_snapped, do_simplify && m_path_iter.should_simplify(),
4242
m_path_iter.simplify_threshold())
4343
{
4444
Py_INCREF(path);
@@ -55,15 +55,15 @@ extern "C" {
5555
void*
5656
get_path_iterator(
5757
PyObject* path, PyObject* trans, int remove_nans, int do_clip,
58-
double rect[4], e_quantize_mode quantize_mode, double stroke_width,
58+
double rect[4], e_snap_mode snap_mode, double stroke_width,
5959
int do_simplify)
6060
{
6161
agg::trans_affine agg_trans = py_to_agg_transformation_matrix(trans, false);
6262
agg::rect_base<double> clip_rect(rect[0], rect[1], rect[2], rect[3]);
6363

6464
PathCleanupIterator* pipeline = new PathCleanupIterator(
6565
path, agg_trans, remove_nans != 0, do_clip != 0,
66-
clip_rect, quantize_mode, stroke_width, do_simplify != 0);
66+
clip_rect, snap_mode, stroke_width, do_simplify != 0);
6767

6868
return (void*)pipeline;
6969
}

0 commit comments

Comments
 (0)