Skip to content

Commit a97ab90

Browse files
committed
Improved documentation
1 parent f8b6a5c commit a97ab90

File tree

3 files changed

+62
-1
lines changed

3 files changed

+62
-1
lines changed

lib/matplotlib/contour.py

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1037,6 +1037,16 @@ def _get_lowers_and_uppers(self):
10371037
return (lowers, uppers)
10381038

10391039
def _make_paths(self, segs, kinds):
1040+
"""
1041+
Create and return Path objects for the specified segments and optional
1042+
kind codes. segs is a list of numpy arrays, each array is either a
1043+
closed line loop or open line strip of 2D points with a shape of
1044+
(npoints, 2). kinds is either None or a list (with the same length as
1045+
segs) of numpy arrays, each array is of shape (npoints,) and contains
1046+
the kinds codes for the corresponding line in segs. If kinds is None
1047+
then the Path constructor creates the kind codes assuming that the line
1048+
is an open strip.
1049+
"""
10401050
if kinds is None:
10411051
return [mpath.Path(seg) for seg in segs]
10421052
else:

src/_contour.cpp

Lines changed: 25 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -386,10 +386,21 @@ void QuadContourGenerator::append_contour_line_to_vertices_and_codes(
386386
PyObject* vertices_list,
387387
PyObject* codes_list) const
388388
{
389+
// Convert ContourLine to Python equivalent, and clear it for reuse.
390+
// This function is called once for each line generated in create_contour().
391+
// A line is either a closed line loop (in which case the last point is
392+
// identical to the first) or an open line strip. Two NumPy arrays are
393+
// created for each line:
394+
// vertices is a double array of shape (npoints, 2) containing the (x, y)
395+
// coordinates of the points in the line
396+
// codes is a uint8 array of shape (npoints,) containing the 'kind codes'
397+
// which are defined in the Path class
398+
// and they are appended to the Python lists vertices_list and codes_list
399+
// respectively for return to the Python calling function.
400+
389401
assert(vertices_list != 0 && "Null python vertices_list");
390402
assert(codes_list != 0 && "Null python codes_list");
391403

392-
// Convert ContourLine to python equivalent, and clear it.
393404
npy_intp npoints = static_cast<npy_intp>(contour_line.size());
394405

395406
npy_intp vertices_dims[2] = {npoints, 2};
@@ -407,6 +418,7 @@ void QuadContourGenerator::append_contour_line_to_vertices_and_codes(
407418
*codes_ptr++ = (point == contour_line.begin() ? MOVETO : LINETO);
408419
}
409420

421+
// Closed line loop has identical first and last (x, y) points.
410422
if (contour_line.size() > 1 && contour_line.front() == contour_line.back())
411423
*(codes_ptr-1) = CLOSEPOLY;
412424

@@ -425,6 +437,18 @@ void QuadContourGenerator::append_contour_to_vertices_and_codes(
425437
PyObject* vertices_list,
426438
PyObject* codes_list) const
427439
{
440+
// Convert Contour to Python equivalent, and clear it for reuse.
441+
// This function is called once for each polygon generated in
442+
// create_filled_contour(). A polygon consists of an outer line loop
443+
// (called the parent) and zero or more inner line loops or holes (called
444+
// the children). Two NumPy arrays are created for each polygon:
445+
// vertices is a double array of shape (npoints, 2) containing the (x, y)
446+
// coordinates of the points in the polygon (parent plus children)
447+
// codes is a uint8 array of shape (npoints,) containing the 'kind codes'
448+
// which are defined in the Path class
449+
// and they are appended to the Python lists vertices_list and codes_list
450+
// respectively for return to the Python calling function.
451+
428452
assert(vertices_list != 0 && "Null python vertices_list");
429453
assert(codes_list != 0 && "Null python codes_list");
430454

src/tri/_tri.cpp

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -602,6 +602,18 @@ void TriContourGenerator::clear_visited_flags(bool include_boundaries)
602602

603603
PyObject* TriContourGenerator::contour_line_to_segs_and_kinds(const Contour& contour)
604604
{
605+
// Convert all of the lines generated by a call to create_contour() into
606+
// their Python equivalents for return to the calling function.
607+
// A line is either a closed line loop (in which case the last point is
608+
// identical to the first) or an open line strip. Two NumPy arrays are
609+
// created for each line:
610+
// vertices is a double array of shape (npoints, 2) containing the (x, y)
611+
// coordinates of the points in the line
612+
// codes is a uint8 array of shape (npoints,) containing the 'kind codes'
613+
// which are defined in the Path class
614+
// and they are appended to the Python lists vertices_list and codes_list
615+
// respectively for return to the Python calling function.
616+
605617
PyObject* vertices_list = PyList_New(contour.size());
606618
if (vertices_list == 0)
607619
throw std::runtime_error("Failed to create Python list");
@@ -633,6 +645,7 @@ PyObject* TriContourGenerator::contour_line_to_segs_and_kinds(const Contour& con
633645
*codes_ptr++ = (it == contour_line.begin() ? MOVETO : LINETO);
634646
}
635647

648+
// Closed line loop has identical first and last (x, y) points.
636649
if (contour_line.size() > 1 &&
637650
contour_line.front() == contour_line.back())
638651
*(codes_ptr-1) = CLOSEPOLY;
@@ -660,6 +673,20 @@ PyObject* TriContourGenerator::contour_line_to_segs_and_kinds(const Contour& con
660673

661674
PyObject* TriContourGenerator::contour_to_segs_and_kinds(const Contour& contour)
662675
{
676+
// Convert all of the polygons generated by a call to
677+
// create_filled_contour() into their Python equivalents for return to the
678+
// calling function. All of the polygons' points and kinds codes are
679+
// combined into single NumPy arrays for each; this avoids having
680+
// to determine which polygons are holes as this will be determined by the
681+
// renderer. If there are ntotal points in all of the polygons, the two
682+
// NumPy arrays created are:
683+
// vertices is a double array of shape (ntotal, 2) containing the (x, y)
684+
// coordinates of the points in the polygons
685+
// codes is a uint8 array of shape (ntotal,) containing the 'kind codes'
686+
// which are defined in the Path class
687+
// and they are returned in the Python lists vertices_list and codes_list
688+
// respectively.
689+
663690
Contour::const_iterator line;
664691
ContourLine::const_iterator point;
665692

0 commit comments

Comments
 (0)