diff --git a/src/_backend_agg.cpp b/src/_backend_agg.cpp index eed27323ba9e..4d097bc80716 100644 --- a/src/_backend_agg.cpp +++ b/src/_backend_agg.cpp @@ -10,9 +10,9 @@ RendererAgg::RendererAgg(unsigned int width, unsigned int height, double dpi) height(height), dpi(dpi), NUMBYTES((size_t)width * (size_t)height * 4), - pixBuffer(NULL), + pixBuffer(nullptr), renderingBuffer(), - alphaBuffer(NULL), + alphaBuffer(nullptr), alphaMaskRenderingBuffer(), alphaMask(alphaMaskRenderingBuffer), pixfmtAlphaMask(alphaMaskRenderingBuffer), @@ -26,7 +26,7 @@ RendererAgg::RendererAgg(unsigned int width, unsigned int height, double dpi) rendererAA(), rendererBin(), theRasterizer(32768), - lastclippath(NULL), + lastclippath(nullptr), _fill_color(agg::rgba(1, 1, 1, 0)) { if (dpi <= 0.0) { @@ -75,7 +75,7 @@ BufferRegion *RendererAgg::copy_from_bbox(agg::rect_d in_rect) agg::rect_i rect( (int)in_rect.x1, height - (int)in_rect.y2, (int)in_rect.x2, height - (int)in_rect.y1); - BufferRegion *reg = NULL; + BufferRegion *reg = nullptr; reg = new BufferRegion(rect); agg::rendering_buffer rbuf; @@ -90,21 +90,21 @@ BufferRegion *RendererAgg::copy_from_bbox(agg::rect_d in_rect) void RendererAgg::restore_region(BufferRegion ®ion) { - if (region.get_data() == NULL) { + if (region.get_data() == nullptr) { throw std::runtime_error("Cannot restore_region from NULL data"); } agg::rendering_buffer rbuf; rbuf.attach(region.get_data(), region.get_width(), region.get_height(), region.get_stride()); - rendererBase.copy_from(rbuf, 0, region.get_rect().x1, region.get_rect().y1); + rendererBase.copy_from(rbuf, nullptr, region.get_rect().x1, region.get_rect().y1); } // Restore the part of the saved region with offsets void RendererAgg::restore_region(BufferRegion ®ion, int xx1, int yy1, int xx2, int yy2, int x, int y ) { - if (region.get_data() == NULL) { + if (region.get_data() == nullptr) { throw std::runtime_error("Cannot restore_region from NULL data"); } diff --git a/src/_backend_agg.h b/src/_backend_agg.h index 8010508ae920..f1fbf11ea4e5 100644 --- a/src/_backend_agg.h +++ b/src/_backend_agg.h @@ -65,6 +65,10 @@ class BufferRegion delete[] data; }; + // prevent copying + BufferRegion(const BufferRegion &) = delete; + BufferRegion &operator=(const BufferRegion &) = delete; + agg::int8u *get_data() { return data; @@ -96,11 +100,6 @@ class BufferRegion int width; int height; int stride; - - private: - // prevent copying - BufferRegion(const BufferRegion &); - BufferRegion &operator=(const BufferRegion &); }; #define MARKER_CACHE_SIZE 512 @@ -890,7 +889,7 @@ inline void RendererAgg::draw_image(GCAgg &gc, } else { set_clipbox(gc.cliprect, rendererBase); rendererBase.blend_from( - pixf, 0, (int)x, (int)(height - (y + image.shape(0))), (agg::int8u)(alpha * 255)); + pixf, nullptr, (int)x, (int)(height - (y + image.shape(0))), (agg::int8u)(alpha * 255)); } rendererBase.reset_clipping(true); diff --git a/src/_backend_agg_basic_types.h b/src/_backend_agg_basic_types.h index e3e6be9a4532..b424419ec99e 100644 --- a/src/_backend_agg_basic_types.h +++ b/src/_backend_agg_basic_types.h @@ -48,7 +48,7 @@ class Dashes } void add_dash_pair(double length, double skip) { - dashes.push_back(std::make_pair(length, skip)); + dashes.emplace_back(length, skip); } size_t size() const { @@ -59,9 +59,7 @@ class Dashes void dash_to_stroke(T &stroke, double dpi, bool isaa) { double scaleddpi = dpi / 72.0; - for (dash_t::const_iterator i = dashes.begin(); i != dashes.end(); ++i) { - double val0 = i->first; - double val1 = i->second; + for (auto [val0, val1] : dashes) { val0 = val0 * scaleddpi; val1 = val1 * scaleddpi; if (!isaa) { diff --git a/src/_c_internal_utils.cpp b/src/_c_internal_utils.cpp index db6191849bbe..0dddefaf32e3 100644 --- a/src/_c_internal_utils.cpp +++ b/src/_c_internal_utils.cpp @@ -43,11 +43,11 @@ mpl_xdisplay_is_valid(void) && (libX11 = dlopen("libX11.so.6", RTLD_LAZY))) { typedef struct Display* (*XOpenDisplay_t)(char const*); typedef int (*XCloseDisplay_t)(struct Display*); - struct Display* display = NULL; + struct Display* display = nullptr; XOpenDisplay_t XOpenDisplay = (XOpenDisplay_t)dlsym(libX11, "XOpenDisplay"); XCloseDisplay_t XCloseDisplay = (XCloseDisplay_t)dlsym(libX11, "XCloseDisplay"); if (XOpenDisplay && XCloseDisplay - && (display = XOpenDisplay(NULL))) { + && (display = XOpenDisplay(nullptr))) { XCloseDisplay(display); } if (dlclose(libX11)) { @@ -75,13 +75,13 @@ mpl_display_is_valid(void) && (libwayland_client = dlopen("libwayland-client.so.0", RTLD_LAZY))) { typedef struct wl_display* (*wl_display_connect_t)(char const*); typedef void (*wl_display_disconnect_t)(struct wl_display*); - struct wl_display* display = NULL; + struct wl_display* display = nullptr; wl_display_connect_t wl_display_connect = (wl_display_connect_t)dlsym(libwayland_client, "wl_display_connect"); wl_display_disconnect_t wl_display_disconnect = (wl_display_disconnect_t)dlsym(libwayland_client, "wl_display_disconnect"); if (wl_display_connect && wl_display_disconnect - && (display = wl_display_connect(NULL))) { + && (display = wl_display_connect(nullptr))) { wl_display_disconnect(display); } if (dlclose(libwayland_client)) { diff --git a/src/_image_resample.h b/src/_image_resample.h index 282bf8ef82f6..19dc05b32e2a 100644 --- a/src/_image_resample.h +++ b/src/_image_resample.h @@ -60,20 +60,16 @@ namespace agg value_type a; //-------------------------------------------------------------------- - gray64() {} + gray64() = default; //-------------------------------------------------------------------- - explicit gray64(value_type v_, value_type a_ = 1) : - v(v_), a(a_) {} + explicit gray64(value_type v_, value_type a_ = 1) : v(v_), a(a_) {} //-------------------------------------------------------------------- - gray64(const self_type& c, value_type a_) : - v(c.v), a(a_) {} + gray64(const self_type& c, value_type a_) : v(c.v), a(a_) {} //-------------------------------------------------------------------- - gray64(const gray64& c) : - v(c.v), - a(c.a) {} + gray64(const gray64& c) = default; //-------------------------------------------------------------------- static AGG_INLINE double to_double(value_type a) @@ -246,7 +242,7 @@ namespace agg value_type a; //-------------------------------------------------------------------- - rgba64() {} + rgba64() = default; //-------------------------------------------------------------------- rgba64(value_type r_, value_type g_, value_type b_, value_type a_= 1) : @@ -503,51 +499,52 @@ typedef enum { // T is rgba if and only if it has an T::r field. template struct is_grayscale : std::true_type {}; template struct is_grayscale> : std::false_type {}; +template constexpr bool is_grayscale_v = is_grayscale::value; template struct type_mapping { - using blender_type = typename std::conditional< - is_grayscale::value, + using blender_type = std::conditional_t< + is_grayscale_v, agg::blender_gray, - typename std::conditional< - std::is_same::value, + std::conditional_t< + std::is_same_v, fixed_blender_rgba_plain, agg::blender_rgba_plain - >::type - >::type; - using pixfmt_type = typename std::conditional< - is_grayscale::value, + > + >; + using pixfmt_type = std::conditional_t< + is_grayscale_v, agg::pixfmt_alpha_blend_gray, agg::pixfmt_alpha_blend_rgba - >::type; - using pixfmt_pre_type = typename std::conditional< - is_grayscale::value, + >; + using pixfmt_pre_type = std::conditional_t< + is_grayscale_v, pixfmt_type, agg::pixfmt_alpha_blend_rgba< - typename std::conditional< - std::is_same::value, + std::conditional_t< + std::is_same_v, fixed_blender_rgba_pre, agg::blender_rgba_pre - >::type, + >, agg::rendering_buffer> - >::type; - template using span_gen_affine_type = typename std::conditional< - is_grayscale::value, + >; + template using span_gen_affine_type = std::conditional_t< + is_grayscale_v, agg::span_image_resample_gray_affine, agg::span_image_resample_rgba_affine - >::type; - template using span_gen_filter_type = typename std::conditional< - is_grayscale::value, + >; + template using span_gen_filter_type = std::conditional_t< + is_grayscale_v, agg::span_image_filter_gray, agg::span_image_filter_rgba - >::type; - template using span_gen_nn_type = typename std::conditional< - is_grayscale::value, + >; + template using span_gen_nn_type = std::conditional_t< + is_grayscale_v, agg::span_image_filter_gray_nn, agg::span_image_filter_rgba_nn - >::type; + >; }; diff --git a/src/_path.h b/src/_path.h index f5c06e4a6a15..c03703776760 100644 --- a/src/_path.h +++ b/src/_path.h @@ -602,7 +602,6 @@ struct ygt : public bisecty template inline void clip_to_rect_one_step(const Polygon &polygon, Polygon &result, const Filter &filter) { - double sx, sy, px, py, bx, by; bool sinside, pinside; result.clear(); @@ -610,22 +609,19 @@ inline void clip_to_rect_one_step(const Polygon &polygon, Polygon &result, const return; } - sx = polygon.back().x; - sy = polygon.back().y; - for (Polygon::const_iterator i = polygon.begin(); i != polygon.end(); ++i) { - px = i->x; - py = i->y; - + auto [sx, sy] = polygon.back(); + for (auto [px, py] : polygon) { sinside = filter.is_inside(sx, sy); pinside = filter.is_inside(px, py); if (sinside ^ pinside) { + double bx, by; filter.bisect(sx, sy, px, py, &bx, &by); - result.push_back(XY(bx, by)); + result.emplace_back(bx, by); } if (pinside) { - result.push_back(XY(px, py)); + result.emplace_back(px, py); } sx = px; @@ -672,7 +668,7 @@ clip_path_to_rect(PathIterator &path, agg::rect_d &rect, bool inside, std::vecto polygon1.clear(); do { if (code == agg::path_cmd_move_to) { - polygon1.push_back(XY(x, y)); + polygon1.emplace_back(x, y); } code = curve.vertex(&x, &y); @@ -682,7 +678,7 @@ clip_path_to_rect(PathIterator &path, agg::rect_d &rect, bool inside, std::vecto } if (code != agg::path_cmd_move_to) { - polygon1.push_back(XY(x, y)); + polygon1.emplace_back(x, y); } } while ((code & agg::path_cmd_end_poly) != agg::path_cmd_end_poly); @@ -978,23 +974,20 @@ void convert_path_to_polygons(PathIterator &path, simplify_t simplified(clipped, simplify, path.simplify_threshold()); curve_t curve(simplified); - result.push_back(Polygon()); - Polygon *polygon = &result.back(); + Polygon *polygon = &result.emplace_back(); double x, y; unsigned code; while ((code = curve.vertex(&x, &y)) != agg::path_cmd_stop) { if ((code & agg::path_cmd_end_poly) == agg::path_cmd_end_poly) { _finalize_polygon(result, 1); - result.push_back(Polygon()); - polygon = &result.back(); + polygon = &result.emplace_back(); } else { if (code == agg::path_cmd_move_to) { _finalize_polygon(result, closed_only); - result.push_back(Polygon()); - polygon = &result.back(); + polygon = &result.emplace_back(); } - polygon->push_back(XY(x, y)); + polygon->emplace_back(x, y); } } @@ -1086,7 +1079,7 @@ void __add_number(double val, char format_code, int precision, buffer += str; } else { char *str = PyOS_double_to_string( - val, format_code, precision, Py_DTSF_ADD_DOT_0, NULL); + val, format_code, precision, Py_DTSF_ADD_DOT_0, nullptr); // Delete trailing zeros and decimal point char *c = str + strlen(str) - 1; // Start at last character. // Rewind through all the zeros and, if present, the trailing decimal diff --git a/src/_qhull_wrapper.cpp b/src/_qhull_wrapper.cpp index da623a8d1b71..f8a3103b65f1 100644 --- a/src/_qhull_wrapper.cpp +++ b/src/_qhull_wrapper.cpp @@ -167,13 +167,13 @@ delaunay_impl(py::ssize_t npoints, const double* x, const double* y, } /* qhull expects a FILE* to write errors to. */ - FILE* error_file = NULL; + FILE* error_file = nullptr; if (hide_qhull_errors) { /* qhull errors are ignored by writing to OS-equivalent of /dev/null. * Rather than have OS-specific code here, instead it is determined by * meson.build and passed in via the macro MPL_DEVNULL. */ error_file = fopen(STRINGIFY(MPL_DEVNULL), "w"); - if (error_file == NULL) { + if (error_file == nullptr) { throw std::runtime_error("Could not open devnull"); } } @@ -186,7 +186,7 @@ delaunay_impl(py::ssize_t npoints, const double* x, const double* y, QhullInfo info(error_file, qh); qh_zero(qh, error_file); exitcode = qh_new_qhull(qh, ndim, (int)npoints, points.data(), False, - (char*)"qhull d Qt Qbb Qc Qz", NULL, error_file); + (char*)"qhull d Qt Qbb Qc Qz", nullptr, error_file); if (exitcode != qh_ERRnone) { std::string msg = py::str("Error in qhull Delaunay triangulation calculation: {} (exitcode={})") diff --git a/src/_tkagg.cpp b/src/_tkagg.cpp index bfb19cc476ea..5e162caa6dff 100644 --- a/src/_tkagg.cpp +++ b/src/_tkagg.cpp @@ -312,7 +312,7 @@ load_tkinter_funcs() // Load tkinter global funcs from tkinter compiled module. // Try loading from the main program namespace first. - auto main_program = dlopen(NULL, RTLD_LAZY); + auto main_program = dlopen(nullptr, RTLD_LAZY); auto success = load_tcl_tk(main_program); // We don't need to keep a reference open as the main program always exists. if (dlclose(main_program)) { diff --git a/src/array.h b/src/array.h index 97d66dd4a6d2..0e8db3c4cac7 100644 --- a/src/array.h +++ b/src/array.h @@ -56,9 +56,7 @@ class empty public: typedef empty sub_t; - empty() - { - } + empty() = default; T &operator()(int i, int j = 0, int k = 0) { diff --git a/src/ft2font.cpp b/src/ft2font.cpp index c0e8b7c27125..56767ef5235f 100644 --- a/src/ft2font.cpp +++ b/src/ft2font.cpp @@ -63,12 +63,12 @@ void throw_ft_error(std::string message, FT_Error error) { throw std::runtime_error(os.str()); } -FT2Image::FT2Image() : m_buffer(NULL), m_width(0), m_height(0) +FT2Image::FT2Image() : m_buffer(nullptr), m_width(0), m_height(0) { } FT2Image::FT2Image(unsigned long width, unsigned long height) - : m_buffer(NULL), m_width(0), m_height(0) + : m_buffer(nullptr), m_width(0), m_height(0) { resize(width, height); } @@ -91,7 +91,7 @@ void FT2Image::resize(long width, long height) if ((unsigned long)width != m_width || (unsigned long)height != m_height) { if (numBytes > m_width * m_height) { delete[] m_buffer; - m_buffer = NULL; + m_buffer = nullptr; m_buffer = new unsigned char[numBytes]; } @@ -259,7 +259,7 @@ FT2Font::FT2Font(FT_Open_Args &open_args, long hinting_factor_, std::vector &fallback_list, FT2Font::WarnFunc warn) - : ft_glyph_warn(warn), image(), face(NULL) + : ft_glyph_warn(warn), image(), face(nullptr) { clear(); @@ -280,12 +280,12 @@ FT2Font::FT2Font(FT_Open_Args &open_args, throw_ft_error("Could not set the fontsize", error); } - if (open_args.stream != NULL) { + if (open_args.stream != nullptr) { face->face_flags |= FT_FACE_FLAG_EXTERNAL_STREAM; } FT_Matrix transform = { 65536 / hinting_factor, 0, 0, 65536 }; - FT_Set_Transform(face, &transform, 0); + FT_Set_Transform(face, &transform, nullptr); // Set fallbacks std::copy(fallback_list.begin(), fallback_list.end(), std::back_inserter(fallbacks)); @@ -293,8 +293,8 @@ FT2Font::FT2Font(FT_Open_Args &open_args, FT2Font::~FT2Font() { - for (size_t i = 0; i < glyphs.size(); i++) { - FT_Done_Glyph(glyphs[i]); + for (auto & glyph : glyphs) { + FT_Done_Glyph(glyph); } if (face) { @@ -308,16 +308,16 @@ void FT2Font::clear() bbox.xMin = bbox.yMin = bbox.xMax = bbox.yMax = 0; advance = 0; - for (size_t i = 0; i < glyphs.size(); i++) { - FT_Done_Glyph(glyphs[i]); + for (auto & glyph : glyphs) { + FT_Done_Glyph(glyph); } glyphs.clear(); glyph_to_font.clear(); char_to_font.clear(); - for (size_t i = 0; i < fallbacks.size(); i++) { - fallbacks[i]->clear(); + for (auto & fallback : fallbacks) { + fallback->clear(); } } @@ -329,10 +329,10 @@ void FT2Font::set_size(double ptsize, double dpi) throw_ft_error("Could not set the fontsize", error); } FT_Matrix transform = { 65536 / hinting_factor, 0, 0, 65536 }; - FT_Set_Transform(face, &transform, 0); + FT_Set_Transform(face, &transform, nullptr); - for (size_t i = 0; i < fallbacks.size(); i++) { - fallbacks[i]->set_size(ptsize, dpi); + for (auto & fallback : fallbacks) { + fallback->set_size(ptsize, dpi); } } @@ -393,8 +393,8 @@ int FT2Font::get_kerning(FT_UInt left, FT_UInt right, FT_Kerning_Mode mode, void FT2Font::set_kerning_factor(int factor) { kerning_factor = factor; - for (size_t i = 0; i < fallbacks.size(); i++) { - fallbacks[i]->set_kerning_factor(factor); + for (auto & fallback : fallbacks) { + fallback->set_kerning_factor(factor); } } @@ -420,7 +420,7 @@ void FT2Font::set_text( bbox.xMax = bbox.yMax = -32000; FT_UInt previous = 0; - FT2Font *previous_ft_object = NULL; + FT2Font *previous_ft_object = nullptr; for (auto codepoint : text) { FT_UInt glyph_index = 0; @@ -456,8 +456,8 @@ void FT2Font::set_text( FT_Glyph &thisGlyph = glyphs[glyphs.size() - 1]; last_advance = ft_object_with_glyph->get_face()->glyph->advance.x; - FT_Glyph_Transform(thisGlyph, 0, &pen); - FT_Glyph_Transform(thisGlyph, &matrix, 0); + FT_Glyph_Transform(thisGlyph, nullptr, &pen); + FT_Glyph_Transform(thisGlyph, &matrix, nullptr); xys.push_back(pen.x); xys.push_back(pen.y); @@ -492,7 +492,7 @@ void FT2Font::load_char(long charcode, FT_Int32 flags, FT2Font *&ft_object, bool if (fallback && char_to_font.find(charcode) != char_to_font.end()) { ft_object = char_to_font[charcode]; // since it will be assigned to ft_object anyway - FT2Font *throwaway = NULL; + FT2Font *throwaway = nullptr; ft_object->load_char(charcode, flags, throwaway, false); } else if (fallback) { FT_UInt final_glyph_index; @@ -517,7 +517,7 @@ void FT2Font::load_char(long charcode, FT_Int32 flags, FT2Font *&ft_object, bool ft_object = this; FT_UInt glyph_index = FT_Get_Char_Index(face, (FT_ULong) charcode); if (!glyph_index){ - glyph_seen_fonts.insert((face != NULL)?face->family_name: NULL); + glyph_seen_fonts.insert((face != nullptr)?face->family_name: nullptr); ft_glyph_warn((FT_ULong)charcode, glyph_seen_fonts); } if (FT_Error error = FT_Load_Glyph(face, glyph_index, flags)) { @@ -594,8 +594,8 @@ bool FT2Font::load_char_with_fallback(FT2Font *&ft_object_with_glyph, return true; } else { - for (size_t i = 0; i < fallbacks.size(); ++i) { - bool was_found = fallbacks[i]->load_char_with_fallback( + for (auto & fallback : fallbacks) { + bool was_found = fallback->load_char_with_fallback( ft_object_with_glyph, final_glyph_index, parent_glyphs, parent_char_to_font, parent_glyph_to_font, charcode, flags, charcode_error, glyph_error, glyph_seen_fonts, override); @@ -636,7 +636,7 @@ void FT2Font::load_glyph(FT_UInt glyph_index, FT_Int32 flags) FT_UInt FT2Font::get_char_index(FT_ULong charcode, bool fallback = false) { - FT2Font *ft_object = NULL; + FT2Font *ft_object = nullptr; if (fallback && char_to_font.find(charcode) != char_to_font.end()) { // fallback denotes whether we want to search fallback list. // should call set_text/load_char_with_fallback to parent FT2Font before @@ -674,14 +674,14 @@ void FT2Font::draw_glyphs_to_bitmap(bool antialiased) image.resize(width, height); - for (size_t n = 0; n < glyphs.size(); n++) { + for (auto & glyph : glyphs) { FT_Error error = FT_Glyph_To_Bitmap( - &glyphs[n], antialiased ? FT_RENDER_MODE_NORMAL : FT_RENDER_MODE_MONO, 0, 1); + &glyph, antialiased ? FT_RENDER_MODE_NORMAL : FT_RENDER_MODE_MONO, nullptr, 1); if (error) { throw_ft_error("Could not convert glyph to bitmap", error); } - FT_BitmapGlyph bitmap = (FT_BitmapGlyph)glyphs[n]; + FT_BitmapGlyph bitmap = (FT_BitmapGlyph)glyph; // now, draw to our target surface (convert position) // bitmap left and top in pixel, string bbox in subpixel diff --git a/src/ft2font_wrapper.cpp b/src/ft2font_wrapper.cpp index 7e1b3948a00e..7db8421f80d6 100644 --- a/src/ft2font_wrapper.cpp +++ b/src/ft2font_wrapper.cpp @@ -447,9 +447,9 @@ PyFT2Font_init(py::object filename, long hinting_factor = 8, } PyFT2Font *self = new PyFT2Font(); - self->x = NULL; + self->x = nullptr; memset(&self->stream, 0, sizeof(FT_StreamRec)); - self->stream.base = NULL; + self->stream.base = nullptr; self->stream.size = 0x7fffffff; // Unknown size. self->stream.pos = 0; self->stream.descriptor.pointer = self; @@ -486,7 +486,7 @@ PyFT2Font_init(py::object filename, long hinting_factor = 8, "First argument must be a path to a font file or a binary-mode file object"); } self->py_file = filename; - self->stream.close = NULL; + self->stream.close = nullptr; } self->x = new FT2Font(open_args, hinting_factor, fallback_fonts, ft_glyph_warn); @@ -762,7 +762,7 @@ PyFT2Font_load_char(PyFT2Font *self, long charcode, std::variant flags_or_int = LoadFlags::FORCE_AUTOHINT) { bool fallback = true; - FT2Font *ft_object = NULL; + FT2Font *ft_object = nullptr; LoadFlags flags; if (auto value = std::get_if(&flags_or_int)) { @@ -816,7 +816,7 @@ PyFT2Font_load_glyph(PyFT2Font *self, FT_UInt glyph_index, std::variant flags_or_int = LoadFlags::FORCE_AUTOHINT) { bool fallback = true; - FT2Font *ft_object = NULL; + FT2Font *ft_object = nullptr; LoadFlags flags; if (auto value = std::get_if(&flags_or_int)) { @@ -1433,7 +1433,7 @@ static const char * PyFT2Font_postscript_name(PyFT2Font *self) { const char *ps_name = FT_Get_Postscript_Name(self->x->get_face()); - if (ps_name == NULL) { + if (ps_name == nullptr) { ps_name = "UNAVAILABLE"; } @@ -1450,7 +1450,7 @@ static const char * PyFT2Font_family_name(PyFT2Font *self) { const char *name = self->x->get_face()->family_name; - if (name == NULL) { + if (name == nullptr) { name = "UNAVAILABLE"; } return name; @@ -1460,7 +1460,7 @@ static const char * PyFT2Font_style_name(PyFT2Font *self) { const char *name = self->x->get_face()->style_name; - if (name == NULL) { + if (name == nullptr) { name = "UNAVAILABLE"; } return name; diff --git a/src/path_converters.h b/src/path_converters.h index a91b7387581f..1482aeed95f8 100644 --- a/src/path_converters.h +++ b/src/path_converters.h @@ -59,9 +59,7 @@ class EmbeddedQueue struct item { - item() - { - } + item() = default; inline void set(const unsigned cmd_, const double x_, const double y_) { diff --git a/src/tri/_tri.cpp b/src/tri/_tri.cpp index 10d958c5ea11..b74fcbec26fc 100644 --- a/src/tri/_tri.cpp +++ b/src/tri/_tri.cpp @@ -44,8 +44,7 @@ std::ostream& operator<<(std::ostream& os, const TriEdge& tri_edge) -XY::XY() -{} +XY::XY() = default; XY::XY(const double& x_, const double& y_) : x(x_), y(y_) @@ -184,8 +183,9 @@ void ContourLine::push_back(const XY& point) void ContourLine::write() const { std::cout << "ContourLine of " << size() << " points:"; - for (const_iterator it = begin(); it != end(); ++it) - std::cout << ' ' << *it; + for (const auto & it : *this) { + std::cout << ' ' << it; + } std::cout << std::endl; } @@ -194,8 +194,9 @@ void ContourLine::write() const void write_contour(const Contour& contour) { std::cout << "Contour of " << contour.size() << " lines." << std::endl; - for (Contour::const_iterator it = contour.begin(); it != contour.end(); ++it) - it->write(); + for (const auto & it : contour) { + it.write(); + } } @@ -264,14 +265,13 @@ void Triangulation::calculate_boundaries() // time, initialise the _tri_edge_to_boundary_map. while (!boundary_edges.empty()) { // Start of new boundary. - BoundaryEdges::iterator it = boundary_edges.begin(); + auto it = boundary_edges.cbegin(); int tri = it->tri; int edge = it->edge; - _boundaries.push_back(Boundary()); - Boundary& boundary = _boundaries.back(); + Boundary& boundary = _boundaries.emplace_back(); while (true) { - boundary.push_back(TriEdge(tri, edge)); + boundary.emplace_back(tri, edge); boundary_edges.erase(it); _tri_edge_to_boundary_map[TriEdge(tri, edge)] = BoundaryEdge(_boundaries.size()-1, boundary.size()-1); @@ -321,9 +321,9 @@ void Triangulation::calculate_edges() auto edges = _edges.mutable_data(); int i = 0; - for (EdgeSet::const_iterator it = edge_set.begin(); it != edge_set.end(); ++it) { - edges[i++] = it->start; - edges[i++] = it->end; + for (const auto & it : edge_set) { + edges[i++] = it.start; + edges[i++] = it.end; } } @@ -351,8 +351,7 @@ void Triangulation::calculate_neighbors() for (edge = 0; edge < 3; ++edge) { int start = get_triangle_point(tri, edge); int end = get_triangle_point(tri, (edge+1)%3); - EdgeToTriEdgeMap::iterator it = - edge_to_tri_edge_map.find(Edge(end,start)); + const auto it = edge_to_tri_edge_map.find(Edge(end, start)); if (it == edge_to_tri_edge_map.end()) { // No neighbor edge exists in the edge_to_tri_edge_map, so // add this edge to it. @@ -464,10 +463,8 @@ void Triangulation::get_boundary_edge(const TriEdge& triEdge, int& edge) const { get_boundaries(); // Ensure _tri_edge_to_boundary_map has been created. - TriEdgeToBoundaryMap::const_iterator it = - _tri_edge_to_boundary_map.find(triEdge); - assert(it != _tri_edge_to_boundary_map.end() && - "TriEdge is not on a boundary"); + const auto it = _tri_edge_to_boundary_map.find(triEdge); + assert(it != _tri_edge_to_boundary_map.end() && "TriEdge is not on a boundary"); boundary = it->second.boundary; edge = it->second.edge; } @@ -587,13 +584,12 @@ void Triangulation::set_mask(const MaskArray& mask) void Triangulation::write_boundaries() const { - const Boundaries& bs = get_boundaries(); - std::cout << "Number of boundaries: " << bs.size() << std::endl; - for (Boundaries::const_iterator it = bs.begin(); it != bs.end(); ++it) { - const Boundary& b = *it; - std::cout << " Boundary of " << b.size() << " points: "; - for (Boundary::const_iterator itb = b.begin(); itb != b.end(); ++itb) { - std::cout << *itb << ", "; + const Boundaries& boundaries = get_boundaries(); + std::cout << "Number of boundaries: " << boundaries.size() << std::endl; + for (const auto & boundary : boundaries) { + std::cout << " Boundary of " << boundary.size() << " points: "; + for (const auto & point : boundary) { + std::cout << point << ", "; } std::cout << std::endl; } @@ -625,18 +621,18 @@ void TriContourGenerator::clear_visited_flags(bool include_boundaries) // Initialise _boundaries_visited. _boundaries_visited.reserve(boundaries.size()); - for (Boundaries::const_iterator it = boundaries.begin(); - it != boundaries.end(); ++it) - _boundaries_visited.push_back(BoundaryVisited(it->size())); + for (const auto & boundary : boundaries) { + _boundaries_visited.emplace_back(boundary.size()); + } // Initialise _boundaries_used. _boundaries_used = BoundariesUsed(boundaries.size()); } // Clear _boundaries_visited. - for (BoundariesVisited::iterator it = _boundaries_visited.begin(); - it != _boundaries_visited.end(); ++it) - std::fill(it->begin(), it->end(), false); + for (auto & it : _boundaries_visited) { + std::fill(it.begin(), it.end(), false); + } // Clear _boundaries_used. std::fill(_boundaries_used.begin(), _boundaries_used.end(), false); @@ -672,11 +668,13 @@ py::tuple TriContourGenerator::contour_line_to_segs_and_kinds(const Contour& con CodeArray codes(codes_dims); unsigned char* codes_ptr = codes.mutable_data(); - for (ContourLine::const_iterator it = contour_line.begin(); - it != contour_line.end(); ++it) { - *segs_ptr++ = it->x; - *segs_ptr++ = it->y; - *codes_ptr++ = (it == contour_line.begin() ? MOVETO : LINETO); + for (const auto & point : contour_line) { + *segs_ptr++ = point.x; + *segs_ptr++ = point.y; + *codes_ptr++ = LINETO; + } + if (npoints > 0) { + *codes.mutable_data(0) = MOVETO; } // Closed line loop has identical first and last (x, y) points. @@ -707,13 +705,11 @@ py::tuple TriContourGenerator::contour_to_segs_and_kinds(const Contour& contour) // and they are returned in the Python lists vertices_list and codes_list // respectively. - Contour::const_iterator line; - ContourLine::const_iterator point; - // Find total number of points in all contour lines. py::ssize_t n_points = 0; - for (line = contour.begin(); line != contour.end(); ++line) - n_points += static_cast(line->size()); + for (const auto & line : contour) { + n_points += static_cast(line.size()); + } // Create segs array for point coordinates. py::ssize_t segs_dims[2] = {n_points, 2}; @@ -725,15 +721,16 @@ py::tuple TriContourGenerator::contour_to_segs_and_kinds(const Contour& contour) CodeArray codes(codes_dims); unsigned char* codes_ptr = codes.mutable_data(); - for (line = contour.begin(); line != contour.end(); ++line) { - for (point = line->begin(); point != line->end(); point++) { + for (const auto & line : contour) { + for (auto point = line.cbegin(); point != line.cend(); point++) { *segs_ptr++ = point->x; *segs_ptr++ = point->y; - *codes_ptr++ = (point == line->begin() ? MOVETO : LINETO); + *codes_ptr++ = (point == line.cbegin() ? MOVETO : LINETO); } - if (line->size() > 1) + if (line.size() > 1) { *(codes_ptr-1) = CLOSEPOLY; + } } py::list vertices_list(1); @@ -787,13 +784,10 @@ void TriContourGenerator::find_boundary_lines(Contour& contour, // line to its end before continuing. const Triangulation& triang = _triangulation; const Boundaries& boundaries = get_boundaries(); - for (Boundaries::const_iterator it = boundaries.begin(); - it != boundaries.end(); ++it) { - const Boundary& boundary = *it; + for (const auto & boundary : boundaries) { bool startAbove, endAbove = false; - for (Boundary::const_iterator itb = boundary.begin(); - itb != boundary.end(); ++itb) { - if (itb == boundary.begin()) + for (auto itb = boundary.cbegin(); itb != boundary.cend(); ++itb) { + if (itb == boundary.cbegin()) startAbove = get_z(triang.get_triangle_point(*itb)) >= level; else startAbove = endAbove; @@ -802,8 +796,7 @@ void TriContourGenerator::find_boundary_lines(Contour& contour, if (startAbove && !endAbove) { // This boundary edge is the start point for a contour line, // so follow the line. - contour.push_back(ContourLine()); - ContourLine& contour_line = contour.back(); + ContourLine& contour_line = contour.emplace_back(); TriEdge tri_edge = *itb; follow_interior(contour_line, tri_edge, true, level, false); } @@ -836,8 +829,7 @@ void TriContourGenerator::find_boundary_lines_filled(Contour& contour, if (decr_lower || incr_upper) { // Start point for contour line, so follow it. - contour.push_back(ContourLine()); - ContourLine& contour_line = contour.back(); + ContourLine& contour_line = contour.emplace_back(); TriEdge start_tri_edge = boundary[j]; TriEdge tri_edge = start_tri_edge; @@ -865,11 +857,11 @@ void TriContourGenerator::find_boundary_lines_filled(Contour& contour, const Boundary& boundary = boundaries[i]; double z = get_z(triang.get_triangle_point(boundary[0])); if (z >= lower_level && z < upper_level) { - contour.push_back(ContourLine()); - ContourLine& contour_line = contour.back(); - for (Boundary::size_type j = 0; j < boundary.size(); ++j) + ContourLine& contour_line = contour.emplace_back(); + for (auto edge : boundary) { contour_line.push_back(triang.get_point_coords( - triang.get_triangle_point(boundary[j]))); + triang.get_triangle_point(edge))); + } // Close polygon. contour_line.push_back(contour_line.front()); @@ -899,8 +891,7 @@ void TriContourGenerator::find_interior_lines(Contour& contour, continue; // Contour does not pass through this triangle. // Found start of new contour line loop. - contour.push_back(ContourLine()); - ContourLine& contour_line = contour.back(); + ContourLine& contour_line = contour.emplace_back(); TriEdge tri_edge = triang.get_neighbor_edge(tri, edge); follow_interior(contour_line, tri_edge, false, level, on_upper); @@ -1073,8 +1064,8 @@ XY TriContourGenerator::interp(int point1, TrapezoidMapTriFinder::TrapezoidMapTriFinder(Triangulation& triangulation) : _triangulation(triangulation), - _points(0), - _tree(0) + _points(nullptr), + _tree(nullptr) {} TrapezoidMapTriFinder::~TrapezoidMapTriFinder() @@ -1092,9 +1083,9 @@ TrapezoidMapTriFinder::add_edge_to_tree(const Edge& edge) const Point* p = edge.left; const Point* q = edge.right; - Trapezoid* left_old = 0; // old trapezoid to the left. - Trapezoid* left_below = 0; // below trapezoid to the left. - Trapezoid* left_above = 0; // above trapezoid to the left. + Trapezoid* left_old = nullptr; // old trapezoid to the left. + Trapezoid* left_below = nullptr; // below trapezoid to the left. + Trapezoid* left_above = nullptr; // above trapezoid to the left. // Iterate through trapezoids intersecting edge from left to right. // Replace each old trapezoid with 2+ new trapezoids, and replace its @@ -1110,10 +1101,10 @@ TrapezoidMapTriFinder::add_edge_to_tree(const Edge& edge) // Old trapezoid is replaced by up to 4 new trapezoids: left is to the // left of the start point p, below/above are below/above the edge // inserted, and right is to the right of the end point q. - Trapezoid* left = 0; - Trapezoid* below = 0; - Trapezoid* above = 0; - Trapezoid* right = 0; + Trapezoid* left = nullptr; + Trapezoid* below = nullptr; + Trapezoid* above = nullptr; + Trapezoid* right = nullptr; // There are 4 different cases here depending on whether the old // trapezoid in question is the start and/or end trapezoid of those @@ -1301,12 +1292,12 @@ void TrapezoidMapTriFinder::clear() { delete [] _points; - _points = 0; + _points = nullptr; _edges.clear(); delete _tree; - _tree = 0; + _tree = nullptr; } TrapezoidMapTriFinder::TriIndexArray @@ -1335,7 +1326,7 @@ int TrapezoidMapTriFinder::find_one(const XY& xy) { const Node* node = _tree->search(xy); - assert(node != 0 && "Search tree for point returned null node"); + assert(node != nullptr && "Search tree for point returned null node"); return node->get_tri(); } @@ -1348,8 +1339,8 @@ TrapezoidMapTriFinder::find_trapezoids_intersecting_edge( // checks to deal with simple colinear (i.e. invalid) triangles. trapezoids.clear(); Trapezoid* trapezoid = _tree->search(edge); - if (trapezoid == 0) { - assert(trapezoid != 0 && "search(edge) returns null trapezoid"); + if (trapezoid == nullptr) { + assert(trapezoid != nullptr && "search(edge) returns null trapezoid"); return false; } @@ -1372,7 +1363,7 @@ TrapezoidMapTriFinder::find_trapezoids_intersecting_edge( else if (orient == +1) trapezoid = trapezoid->upper_right; - if (trapezoid == 0) { + if (trapezoid == nullptr) { assert(0 && "Expected trapezoid neighbor"); return false; } @@ -1439,8 +1430,10 @@ TrapezoidMapTriFinder::initialize() // Set up edges array. // First the bottom and top edges of the enclosing rectangle. - _edges.push_back(Edge(&_points[npoints], &_points[npoints+1],-1,-1,0,0)); - _edges.push_back(Edge(&_points[npoints+2],&_points[npoints+3],-1,-1,0,0)); + _edges.emplace_back(&_points[npoints], &_points[npoints+1], -1, -1, + nullptr, nullptr); + _edges.emplace_back(&_points[npoints+2], &_points[npoints+3], -1, -1, + nullptr, nullptr); // Add all edges in the triangulation that point to the right. Do not // explicitly include edges that point to the left as the neighboring @@ -1457,13 +1450,14 @@ TrapezoidMapTriFinder::initialize() TriEdge neighbor = triang.get_neighbor_edge(tri,edge); if (end->is_right_of(*start)) { const Point* neighbor_point_below = (neighbor.tri == -1) ? - 0 : _points + triang.get_triangle_point( + nullptr : _points + triang.get_triangle_point( neighbor.tri, (neighbor.edge+2)%3); - _edges.push_back(Edge(start, end, neighbor.tri, tri, - neighbor_point_below, other)); + _edges.emplace_back(start, end, neighbor.tri, tri, + neighbor_point_below, other); + } + else if (neighbor.tri == -1) { + _edges.emplace_back(end, start, tri, -1, other, nullptr); } - else if (neighbor.tri == -1) - _edges.push_back(Edge(end, start, tri, -1, other, 0)); // Set triangle associated with start point if not already set. if (start->tri == -1) @@ -1493,7 +1487,7 @@ TrapezoidMapTriFinder::initialize() void TrapezoidMapTriFinder::print_tree() { - assert(_tree != 0 && "Null Node tree"); + assert(_tree != nullptr && "Null Node tree"); _tree->print(); } @@ -1510,8 +1504,8 @@ TrapezoidMapTriFinder::Edge::Edge(const Point* left_, point_below(point_below_), point_above(point_above_) { - assert(left != 0 && "Null left point"); - assert(right != 0 && "Null right point"); + assert(left != nullptr && "Null left point"); + assert(right != nullptr && "Null right point"); assert(right->is_right_of(*left) && "Incorrect point order"); assert(triangle_below >= -1 && "Invalid triangle below index"); assert(triangle_above >= -1 && "Invalid triangle above index"); @@ -1552,7 +1546,7 @@ TrapezoidMapTriFinder::Edge::get_y_at_x(const double& x) const bool TrapezoidMapTriFinder::Edge::has_point(const Point* point) const { - assert(point != 0 && "Null point"); + assert(point != nullptr && "Null point"); return (left == point || right == point); } @@ -1572,9 +1566,9 @@ TrapezoidMapTriFinder::Edge::print_debug() const TrapezoidMapTriFinder::Node::Node(const Point* point, Node* left, Node* right) : _type(Type_XNode) { - assert(point != 0 && "Invalid point"); - assert(left != 0 && "Invalid left node"); - assert(right != 0 && "Invalid right node"); + assert(point != nullptr && "Invalid point"); + assert(left != nullptr && "Invalid left node"); + assert(right != nullptr && "Invalid right node"); _union.xnode.point = point; _union.xnode.left = left; _union.xnode.right = right; @@ -1585,9 +1579,9 @@ TrapezoidMapTriFinder::Node::Node(const Point* point, Node* left, Node* right) TrapezoidMapTriFinder::Node::Node(const Edge* edge, Node* below, Node* above) : _type(Type_YNode) { - assert(edge != 0 && "Invalid edge"); - assert(below != 0 && "Invalid below node"); - assert(above != 0 && "Invalid above node"); + assert(edge != nullptr && "Invalid edge"); + assert(below != nullptr && "Invalid below node"); + assert(above != nullptr && "Invalid above node"); _union.ynode.edge = edge; _union.ynode.below = below; _union.ynode.above = above; @@ -1598,7 +1592,7 @@ TrapezoidMapTriFinder::Node::Node(const Edge* edge, Node* below, Node* above) TrapezoidMapTriFinder::Node::Node(Trapezoid* trapezoid) : _type(Type_TrapezoidNode) { - assert(trapezoid != 0 && "Null Trapezoid"); + assert(trapezoid != nullptr && "Null Trapezoid"); _union.trapezoid = trapezoid; trapezoid->trapezoid_node = this; } @@ -1627,7 +1621,7 @@ TrapezoidMapTriFinder::Node::~Node() void TrapezoidMapTriFinder::Node::add_parent(Node* parent) { - assert(parent != 0 && "Null parent"); + assert(parent != nullptr && "Null parent"); assert(parent != this && "Cannot be parent of self"); assert(!has_parent(parent) && "Parent already in collection"); _parents.push_back(parent); @@ -1638,9 +1632,7 @@ TrapezoidMapTriFinder::Node::assert_valid(bool tree_complete) const { #ifndef NDEBUG // Check parents. - for (Parents::const_iterator it = _parents.begin(); - it != _parents.end(); ++it) { - Node* parent = *it; + for (const auto & parent : _parents) { assert(parent != this && "Cannot be parent of self"); assert(parent->has_child(this) && "Parent missing child"); } @@ -1648,23 +1640,23 @@ TrapezoidMapTriFinder::Node::assert_valid(bool tree_complete) const // Check children, and recurse. switch (_type) { case Type_XNode: - assert(_union.xnode.left != 0 && "Null left child"); + assert(_union.xnode.left != nullptr && "Null left child"); assert(_union.xnode.left->has_parent(this) && "Incorrect parent"); - assert(_union.xnode.right != 0 && "Null right child"); + assert(_union.xnode.right != nullptr && "Null right child"); assert(_union.xnode.right->has_parent(this) && "Incorrect parent"); _union.xnode.left->assert_valid(tree_complete); _union.xnode.right->assert_valid(tree_complete); break; case Type_YNode: - assert(_union.ynode.below != 0 && "Null below child"); + assert(_union.ynode.below != nullptr && "Null below child"); assert(_union.ynode.below->has_parent(this) && "Incorrect parent"); - assert(_union.ynode.above != 0 && "Null above child"); + assert(_union.ynode.above != nullptr && "Null above child"); assert(_union.ynode.above->has_parent(this) && "Incorrect parent"); _union.ynode.below->assert_valid(tree_complete); _union.ynode.above->assert_valid(tree_complete); break; case Type_TrapezoidNode: - assert(_union.trapezoid != 0 && "Null trapezoid"); + assert(_union.trapezoid != nullptr && "Null trapezoid"); assert(_union.trapezoid->trapezoid_node == this && "Incorrect trapezoid node"); _union.trapezoid->assert_valid(tree_complete); @@ -1724,7 +1716,7 @@ TrapezoidMapTriFinder::Node::get_tri() const bool TrapezoidMapTriFinder::Node::has_child(const Node* child) const { - assert(child != 0 && "Null child node"); + assert(child != nullptr && "Null child node"); switch (_type) { case Type_XNode: return (_union.xnode.left == child || _union.xnode.right == child); @@ -1777,9 +1769,9 @@ TrapezoidMapTriFinder::Node::print(int depth /* = 0 */) const bool TrapezoidMapTriFinder::Node::remove_parent(Node* parent) { - assert(parent != 0 && "Null parent"); + assert(parent != nullptr && "Null parent"); assert(parent != this && "Cannot be parent of self"); - Parents::iterator it = std::find(_parents.begin(), _parents.end(), parent); + auto it = std::find(_parents.begin(), _parents.end(), parent); assert(it != _parents.end() && "Parent not in collection"); _parents.erase(it); return _parents.empty(); @@ -1792,7 +1784,7 @@ TrapezoidMapTriFinder::Node::replace_child(Node* old_child, Node* new_child) case Type_XNode: assert((_union.xnode.left == old_child || _union.xnode.right == old_child) && "Not a child Node"); - assert(new_child != 0 && "Null child node"); + assert(new_child != nullptr && "Null child node"); if (_union.xnode.left == old_child) _union.xnode.left = new_child; else @@ -1801,7 +1793,7 @@ TrapezoidMapTriFinder::Node::replace_child(Node* old_child, Node* new_child) case Type_YNode: assert((_union.ynode.below == old_child || _union.ynode.above == old_child) && "Not a child node"); - assert(new_child != 0 && "Null child node"); + assert(new_child != nullptr && "Null child node"); if (_union.ynode.below == old_child) _union.ynode.below = new_child; else @@ -1818,7 +1810,7 @@ TrapezoidMapTriFinder::Node::replace_child(Node* old_child, Node* new_child) void TrapezoidMapTriFinder::Node::replace_with(Node* new_node) { - assert(new_node != 0 && "Null replacement node"); + assert(new_node != nullptr && "Null replacement node"); // Replace child of each parent with new_node. As each has parent has its // child replaced it is removed from the _parents collection. while (!_parents.empty()) @@ -1876,7 +1868,7 @@ TrapezoidMapTriFinder::Node::search(const Edge& edge) else { assert(0 && "Invalid triangulation, common left points"); - return 0; + return nullptr; } } if (edge.get_slope() > _union.ynode.edge->get_slope()) @@ -1896,7 +1888,7 @@ TrapezoidMapTriFinder::Node::search(const Edge& edge) else { assert(0 && "Invalid triangulation, common right points"); - return 0; + return nullptr; } } if (edge.get_slope() > _union.ynode.edge->get_slope()) @@ -1909,15 +1901,15 @@ TrapezoidMapTriFinder::Node::search(const Edge& edge) _union.ynode.edge->get_point_orientation(*edge.left); if (orient == 0) { // edge.left lies on _union.ynode.edge - if (_union.ynode.edge->point_above != 0 && + if (_union.ynode.edge->point_above != nullptr && edge.has_point(_union.ynode.edge->point_above)) orient = -1; - else if (_union.ynode.edge->point_below != 0 && + else if (_union.ynode.edge->point_below != nullptr && edge.has_point(_union.ynode.edge->point_below)) orient = +1; else { assert(0 && "Invalid triangulation, point on edge"); - return 0; + return nullptr; } } if (orient < 0) @@ -1935,11 +1927,12 @@ TrapezoidMapTriFinder::Trapezoid::Trapezoid(const Point* left_, const Edge& below_, const Edge& above_) : left(left_), right(right_), below(below_), above(above_), - lower_left(0), lower_right(0), upper_left(0), upper_right(0), - trapezoid_node(0) + lower_left(nullptr), lower_right(nullptr), + upper_left(nullptr), upper_right(nullptr), + trapezoid_node(nullptr) { - assert(left != 0 && "Null left point"); - assert(right != 0 && "Null right point"); + assert(left != nullptr && "Null left point"); + assert(right != nullptr && "Null right point"); assert(right->is_right_of(*left) && "Incorrect point order"); } @@ -1947,10 +1940,10 @@ void TrapezoidMapTriFinder::Trapezoid::assert_valid(bool tree_complete) const { #ifndef NDEBUG - assert(left != 0 && "Null left point"); - assert(right != 0 && "Null right point"); + assert(left != nullptr && "Null left point"); + assert(right != nullptr && "Null right point"); - if (lower_left != 0) { + if (lower_left != nullptr) { assert(lower_left->below == below && lower_left->lower_right == this && "Incorrect lower_left trapezoid"); @@ -1958,7 +1951,7 @@ TrapezoidMapTriFinder::Trapezoid::assert_valid(bool tree_complete) const "Incorrect lower left point"); } - if (lower_right != 0) { + if (lower_right != nullptr) { assert(lower_right->below == below && lower_right->lower_left == this && "Incorrect lower_right trapezoid"); @@ -1966,7 +1959,7 @@ TrapezoidMapTriFinder::Trapezoid::assert_valid(bool tree_complete) const "Incorrect lower right point"); } - if (upper_left != 0) { + if (upper_left != nullptr) { assert(upper_left->above == above && upper_left->upper_right == this && "Incorrect upper_left trapezoid"); @@ -1974,7 +1967,7 @@ TrapezoidMapTriFinder::Trapezoid::assert_valid(bool tree_complete) const "Incorrect upper left point"); } - if (upper_right != 0) { + if (upper_right != nullptr) { assert(upper_right->above == above && upper_right->upper_left == this && "Incorrect upper_right trapezoid"); @@ -1982,7 +1975,7 @@ TrapezoidMapTriFinder::Trapezoid::assert_valid(bool tree_complete) const "Incorrect upper right point"); } - assert(trapezoid_node != 0 && "Null trapezoid_node"); + assert(trapezoid_node != nullptr && "Null trapezoid_node"); if (tree_complete) { assert(below.triangle_above == above.triangle_below && @@ -2042,30 +2035,34 @@ void TrapezoidMapTriFinder::Trapezoid::set_lower_left(Trapezoid* lower_left_) { lower_left = lower_left_; - if (lower_left != 0) + if (lower_left != nullptr) { lower_left->lower_right = this; + } } void TrapezoidMapTriFinder::Trapezoid::set_lower_right(Trapezoid* lower_right_) { lower_right = lower_right_; - if (lower_right != 0) + if (lower_right != nullptr) { lower_right->lower_left = this; + } } void TrapezoidMapTriFinder::Trapezoid::set_upper_left(Trapezoid* upper_left_) { upper_left = upper_left_; - if (upper_left != 0) + if (upper_left != nullptr) { upper_left->upper_right = this; + } } void TrapezoidMapTriFinder::Trapezoid::set_upper_right(Trapezoid* upper_right_) { upper_right = upper_right_; - if (upper_right != 0) + if (upper_right != nullptr) { upper_right->upper_left = this; + } }