Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit b8a6bf6

Browse files
committed
Make some C++ bool conversions explicit.
1 parent 2364037 commit b8a6bf6

File tree

4 files changed

+32
-27
lines changed

4 files changed

+32
-27
lines changed

src/_backend_agg.h

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -281,8 +281,8 @@ class RendererAgg
281281
DashesVector &linestyles,
282282
AntialiasedArray &antialiaseds,
283283
e_offset_position offset_position,
284-
int check_snap,
285-
int has_curves);
284+
bool check_snap,
285+
bool has_curves);
286286

287287
template <class PointArray, class ColorArray>
288288
void _draw_gouraud_triangle(PointArray &points,
@@ -915,8 +915,8 @@ inline void RendererAgg::_draw_path_collection_generic(GCAgg &gc,
915915
DashesVector &linestyles,
916916
AntialiasedArray &antialiaseds,
917917
e_offset_position offset_position,
918-
int check_snap,
919-
int has_curves)
918+
bool check_snap,
919+
bool has_curves)
920920
{
921921
typedef agg::conv_transform<typename PathGenerator::path_iterator> transformed_path_t;
922922
typedef PathNanRemover<transformed_path_t> nan_removed_t;
@@ -1068,8 +1068,8 @@ inline void RendererAgg::draw_path_collection(GCAgg &gc,
10681068
linestyles,
10691069
antialiaseds,
10701070
offset_position,
1071-
1,
1072-
1);
1071+
true,
1072+
true);
10731073
}
10741074

10751075
template <class CoordinateArray>
@@ -1186,8 +1186,8 @@ inline void RendererAgg::draw_quad_mesh(GCAgg &gc,
11861186
linestyles,
11871187
antialiaseds,
11881188
OFFSET_POSITION_FIGURE,
1189-
0,
1190-
0);
1189+
false,
1190+
false);
11911191
}
11921192

11931193
template <class PointArray, class ColorArray>

src/_contour.cpp

Lines changed: 15 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -60,15 +60,15 @@
6060
#define Z_NW Z_LEVEL(POINT_NW)
6161
#define Z_SE Z_LEVEL(POINT_SE)
6262
#define Z_SW Z_LEVEL(POINT_SW)
63-
#define VISITED(quad,li) (_cache[quad] & (li==1 ? MASK_VISITED_1 : MASK_VISITED_2))
64-
#define VISITED_S(quad) (_cache[quad] & MASK_VISITED_S)
65-
#define VISITED_W(quad) (_cache[quad] & MASK_VISITED_W)
66-
#define VISITED_CORNER(quad) (_cache[quad] & MASK_VISITED_CORNER)
67-
#define SADDLE(quad,li) (_cache[quad] & (li==1 ? MASK_SADDLE_1 : MASK_SADDLE_2))
68-
#define SADDLE_LEFT(quad,li) (_cache[quad] & (li==1 ? MASK_SADDLE_LEFT_1 : MASK_SADDLE_LEFT_2))
69-
#define SADDLE_START_SW(quad,li) (_cache[quad] & (li==1 ? MASK_SADDLE_START_SW_1 : MASK_SADDLE_START_SW_2))
70-
#define BOUNDARY_S(quad) (_cache[quad] & MASK_BOUNDARY_S)
71-
#define BOUNDARY_W(quad) (_cache[quad] & MASK_BOUNDARY_W)
63+
#define VISITED(quad,li) ((_cache[quad] & (li==1 ? MASK_VISITED_1 : MASK_VISITED_2)) != 0)
64+
#define VISITED_S(quad) ((_cache[quad] & MASK_VISITED_S) != 0)
65+
#define VISITED_W(quad) ((_cache[quad] & MASK_VISITED_W) != 0)
66+
#define VISITED_CORNER(quad) ((_cache[quad] & MASK_VISITED_CORNER) != 0)
67+
#define SADDLE(quad,li) ((_cache[quad] & (li==1 ? MASK_SADDLE_1 : MASK_SADDLE_2)) != 0)
68+
#define SADDLE_LEFT(quad,li) ((_cache[quad] & (li==1 ? MASK_SADDLE_LEFT_1 : MASK_SADDLE_LEFT_2)) != 0)
69+
#define SADDLE_START_SW(quad,li) ((_cache[quad] & (li==1 ? MASK_SADDLE_START_SW_1 : MASK_SADDLE_START_SW_2)) != 0)
70+
#define BOUNDARY_S(quad) ((_cache[quad] & MASK_BOUNDARY_S) != 0)
71+
#define BOUNDARY_W(quad) ((_cache[quad] & MASK_BOUNDARY_W) != 0)
7272
#define BOUNDARY_N(quad) BOUNDARY_S(quad+_nx)
7373
#define BOUNDARY_E(quad) BOUNDARY_W(quad+1)
7474
#define EXISTS_QUAD(quad) ((_cache[quad] & MASK_EXISTS) == MASK_EXISTS_QUAD)
@@ -1773,12 +1773,12 @@ void QuadContourGenerator::write_cache_quad(long quad, bool grid_only) const
17731773
std::cout << " BNDY=" << (BOUNDARY_S(quad)>0) << (BOUNDARY_W(quad)>0);
17741774
if (!grid_only) {
17751775
std::cout << " Z=" << Z_LEVEL(quad)
1776-
<< " SAD=" << (SADDLE(quad,1)>0) << (SADDLE(quad,2)>0)
1777-
<< " LEFT=" << (SADDLE_LEFT(quad,1)>0) << (SADDLE_LEFT(quad,2)>0)
1778-
<< " NW=" << (SADDLE_START_SW(quad,1)>0) << (SADDLE_START_SW(quad,2)>0)
1779-
<< " VIS=" << (VISITED(quad,1)>0) << (VISITED(quad,2)>0)
1780-
<< (VISITED_S(quad)>0) << (VISITED_W(quad)>0)
1781-
<< (VISITED_CORNER(quad)>0);
1776+
<< " SAD=" << SADDLE(quad,1) << SADDLE(quad,2)
1777+
<< " LEFT=" << SADDLE_LEFT(quad,1) << SADDLE_LEFT(quad,2)
1778+
<< " NW=" << SADDLE_START_SW(quad,1) << SADDLE_START_SW(quad,2)
1779+
<< " VIS=" << VISITED(quad,1) << VISITED(quad,2)
1780+
<< VISITED_S(quad) << VISITED_W(quad)
1781+
<< VISITED_CORNER(quad);
17821782
}
17831783
std::cout << std::endl;
17841784
}

src/_path.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -278,7 +278,7 @@ inline bool point_in_path(
278278

279279
points_in_path(points, r, path, trans, result);
280280

281-
return (bool)result[0];
281+
return result[0] != 0;
282282
}
283283

284284
template <class PathIterator, class PointArray, class ResultArray>
@@ -320,7 +320,7 @@ inline bool point_on_path(
320320

321321
points_on_path(points, r, path, trans, result);
322322

323-
return (bool)result[0];
323+
return result[0] != 0;
324324
}
325325

326326
struct extent_limits

src/py_converters.cpp

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -109,8 +109,13 @@ int convert_double(PyObject *obj, void *p)
109109
int convert_bool(PyObject *obj, void *p)
110110
{
111111
bool *val = (bool *)p;
112+
int ret;
112113

113-
*val = PyObject_IsTrue(obj);
114+
ret = PyObject_IsTrue(obj);
115+
if (ret == -1) {
116+
return 0;
117+
}
118+
*val = ret != 0;
114119

115120
return 1;
116121
}
@@ -387,7 +392,7 @@ int convert_path(PyObject *obj, void *pathp)
387392
if (should_simplify_obj == NULL) {
388393
goto exit;
389394
}
390-
should_simplify = PyObject_IsTrue(should_simplify_obj);
395+
should_simplify = PyObject_IsTrue(should_simplify_obj) != 0;
391396

392397
simplify_threshold_obj = PyObject_GetAttrString(obj, "simplify_threshold");
393398
if (simplify_threshold_obj == NULL) {

0 commit comments

Comments
 (0)