diff --git a/.vscode/settings.json b/.vscode/settings.json index f094999..b0d6de1 100644 --- a/.vscode/settings.json +++ b/.vscode/settings.json @@ -1,13 +1,9 @@ { - "c-cpp-flylint.clang.enable": true, "c-cpp-flylint.clang.includePaths": [ "./include", "./subprojects/eigen-3.4.0" ], - "c-cpp-flylint.cppcheck.enable": true, "c-cpp-flylint.cppcheck.includePaths": ["./include"], - "c-cpp-flylint.flawfinder.enable": false, - "c-cpp-flylint.flexelint.enable": true, "c-cpp-flylint.flexelint.headerArgs": [ "-e749", "-e750", @@ -18,11 +14,9 @@ "-e1526", "-e1714", ], - "c-cpp-flylint.lizard.enable": true, - "c-cpp-flylint.pclintplus.enable": true, "c-cpp-flylint.standard": [ "c99", - "c++14" + "c++20" ], "C_Cpp.errorSquiggles": "enabled", "files.associations": { diff --git a/include/opensimplexnoise.h b/include/opensimplexnoise.h index 554e5db..f09e533 100644 --- a/include/opensimplexnoise.h +++ b/include/opensimplexnoise.h @@ -3,8 +3,8 @@ * by Kurt Spencer * Converted to C++ in 2020 * by Greger Stolt Nilsen - * - * + * + * * v1.1 (October 5, 2014) * - Added 2D and 4D implementations. * - Proper gradient sets for all dimensions, from a @@ -15,7 +15,7 @@ * - Changed seed-based constructor to be independent * of any particular randomization library, so results * will be the same when ported to other languages. - * + * * This is free and unencumbered software released into the public domain. Anyone is free to copy, modify, publish, use, compile, sell, or @@ -76,12 +76,12 @@ class OpenSimplexNoise static const std::array gradients4D; public: - OpenSimplexNoise() : OpenSimplexNoise(DEFAULT_SEED){}; - OpenSimplexNoise(std::array perm); - OpenSimplexNoise(long seed); + OpenSimplexNoise() : OpenSimplexNoise(DEFAULT_SEED) {}; + explicit OpenSimplexNoise(std::array perm); + explicit OpenSimplexNoise(long seed); ~OpenSimplexNoise(); double eval(double x, double y); double eval(double x, double y, double z); double eval(double x, double y, double z, double w); }; -#endif \ No newline at end of file +#endif diff --git a/include/pyro/graphics_cairo.h b/include/pyro/graphics_cairo.h index 4987dc4..8d5a59e 100644 --- a/include/pyro/graphics_cairo.h +++ b/include/pyro/graphics_cairo.h @@ -35,7 +35,6 @@ namespace Pyro void shape(Shape s, float x, float y) override; void line(float x0, float y0, float x1, float y1) override; - void ellipse(float x, float y, float w, float h, unsigned int segments); void background(float r, float g, float b, float a) override; void smooth() override; void nosmooth() override; diff --git a/include/pyro/math.h b/include/pyro/math.h index 51241af..9945a30 100644 --- a/include/pyro/math.h +++ b/include/pyro/math.h @@ -23,12 +23,14 @@ namespace Pyro }; template - T dist(T x1, T y1, T x2, T y2) { + T dist(T x1, T y1, T x2, T y2) + { return mag(x2 - x1, y2 - y1); }; template - T dist(T x1, T y1, T z1, T x2, T y2, T z2) { + T dist(T x1, T y1, T z1, T x2, T y2, T z2) + { return mag(x2 - x1, y2 - y1, z2 - z1); }; @@ -41,12 +43,14 @@ namespace Pyro }; template - T mag(T a, T b) { + T mag(T a, T b) + { return sqrt(a * a + b * b); }; template - T mag(T a, T b, T c) { + T mag(T a, T b, T c) + { return sqrt(a * a + b * b + c * c); }; @@ -109,13 +113,13 @@ namespace Pyro // TODO: randomgaussian void randomseed(unsigned int seed); - int random(int range); - int random(int low, int high); - double random(); // Returns a random number between 0 and 1 - double random(double range); - double random(double low, double high); - unsigned int random(unsigned int range); - unsigned int random(unsigned int low, unsigned int high); + int random(int range); /* Flawfinder: ignore */ + int random(int low, int high); /* Flawfinder: ignore */ + double random(); /* Flawfinder: ignore */ // Returns a random number between 0 and 1 + double random(double range); /* Flawfinder: ignore */ + double random(double low, double high); /* Flawfinder: ignore */ + unsigned int random(unsigned int range); /* Flawfinder: ignore */ + unsigned int random(unsigned int low, unsigned int high); /* Flawfinder: ignore */ } // namespace Pyro diff --git a/include/pyro/pyro.h b/include/pyro/pyro.h index 0d09d2f..7275acd 100644 --- a/include/pyro/pyro.h +++ b/include/pyro/pyro.h @@ -37,7 +37,7 @@ namespace Pyro // Drawing functions // **** COLOR **** - inline void background(const Color &c) { pg->background(c); }; + inline void background(Color const &c) { pg->background(c); }; inline void background(int c, int a = 255) { pg->background(c / 255.0f, c / 255.0f, c / 255.0f, a / 255.0); }; inline void background(int r, int g, int b, int a = 255) { pg->background(r / 255.0f, g / 255.0f, b / 255.0f, a / 255.0f); }; @@ -48,7 +48,7 @@ namespace Pyro // TODO: clear // TODO: colormode - inline void fill(const Color &c) { pg->fill(c); }; + inline void fill(Color const &c) { pg->fill(c); }; inline void fill(float c, float a = 1.0) { pg->fill(c, c, c, a); }; inline void fill(float r, float g, float b, float a = 1.0) { pg->fill(r, g, b, a); }; inline void fill(int c, int a = 255) { pg->fill(c, a); }; @@ -57,7 +57,7 @@ namespace Pyro inline void nofill() { pg->nofill(); }; inline void nostroke() { pg->nostroke(); }; - inline void stroke(Color c) { pg->stroke(c); }; + inline void stroke(Color const &c) { pg->stroke(c); }; inline void stroke(float c, float a = 1.0) { pg->stroke(c, c, c, a); }; inline void stroke(float r, float g, float b, float a = 1.0) { pg->stroke(r, g, b, a); }; inline void stroke(int c, int a = 255) { pg->stroke(c, a); }; diff --git a/include/pyro/sdl.h b/include/pyro/sdl.h index 6f07358..f32f51e 100644 --- a/include/pyro/sdl.h +++ b/include/pyro/sdl.h @@ -22,13 +22,13 @@ namespace Pyro unsigned int height; public: - SDLRunner(bool headless = false); + explicit SDLRunner(bool headless = false); SDLRunner(const SDLRunner &in); SDLRunner &operator=(const SDLRunner &in); - ~SDLRunner(); - int update(); - int quit(); - int init(unsigned int width, unsigned int height); + ~SDLRunner() override; + int update() override; + int quit() override; + int init(unsigned int width, unsigned int height) override; }; } diff --git a/screenshot-tests/screenshotmatcher.cpp b/screenshot-tests/screenshotmatcher.cpp index e4ccf0f..aac3c26 100644 --- a/screenshot-tests/screenshotmatcher.cpp +++ b/screenshot-tests/screenshotmatcher.cpp @@ -40,7 +40,7 @@ bool ImageMatch::match(std::filesystem::path const &filename) const } // Check all pixels - uint8_t *actual_pixels = actual->load_bytes(); + const uint8_t *actual_pixels = actual->load_bytes(); uint8_t *input_pixels = input->load_bytes(); bool result = true; diff --git a/screenshot-tests/test-lines.cpp b/screenshot-tests/test-lines.cpp index 6b2b4ce..fbef9b3 100644 --- a/screenshot-tests/test-lines.cpp +++ b/screenshot-tests/test-lines.cpp @@ -132,7 +132,7 @@ TEST_CASE("Bezier curve", "[shapes]") SECTION("Draw with beziervertex()") { Pyro::Graphics *p = Pyro::creategraphics(100, 100, testmode); - std::filesystem::path filename = "shape_curve_bezier_vertex.png"; + filename = "shape_curve_bezier_vertex.png"; p->background(192); p->nofill(); p->beginshape(); diff --git a/src/graphics.cpp b/src/graphics.cpp index dc33187..658af13 100644 --- a/src/graphics.cpp +++ b/src/graphics.cpp @@ -52,8 +52,6 @@ namespace Pyro void Graphics::point(float x, float y) { - if (unit == Unit::CURRENT) - unit = this->unit; x = x * pixel_multiplier; y = y * pixel_multiplier; @@ -141,9 +139,6 @@ namespace Pyro void Graphics::triangle(float x0, float y0, float x1, float y1, float x2, float y2) { - if (unit == Unit::CURRENT) - unit = this->unit; - x0 = x0 * pixel_multiplier; y0 = y0 * pixel_multiplier; x1 = x1 * pixel_multiplier; @@ -162,9 +157,6 @@ namespace Pyro void Graphics::rect(float a, float b, float c, float d) { - if (unit == Unit::CURRENT) - unit = this->unit; - a = a * pixel_multiplier; b = b * pixel_multiplier; c = c * pixel_multiplier; @@ -188,9 +180,6 @@ namespace Pyro void Graphics::curve(float x0, float y0, float x1, float y1, float x2, float y2, float x3, float y3) { - if (unit == Unit::CURRENT) - unit = this->unit; - x0 = x0 * pixel_multiplier; y0 = y0 * pixel_multiplier; x1 = x1 * pixel_multiplier; @@ -212,9 +201,6 @@ namespace Pyro void Graphics::bezier(float x0, float y0, float x1, float y1, float x2, float y2, float x3, float y3) { - if (unit == Unit::CURRENT) - unit = this->unit; - x0 = x0 * pixel_multiplier; y0 = y0 * pixel_multiplier; x1 = x1 * pixel_multiplier; @@ -246,9 +232,6 @@ namespace Pyro void Graphics::quad(float x0, float y0, float x1, float y1, float x2, float y2, float x3, float y3) { - if (unit == Unit::CURRENT) - unit = this->unit; - x0 = x0 * pixel_multiplier; y0 = y0 * pixel_multiplier; x1 = x1 * pixel_multiplier; @@ -315,12 +298,12 @@ namespace Pyro h = h * pixel_multiplier; for (unsigned int i = 0; i < segments; i++) { - s.vertex(cos(i * da) * w / 2.0f + x, - sin(i * da) * h / 2.0f + y); + s.vertex(cos(i * da) * w / 2.0f, + sin(i * da) * h / 2.0f); } s.end(CLOSE); - this->shape(s, 0, 0); + this->shape(s, x, y); } void Graphics::stroke(float r, float g, float b, float a) diff --git a/src/graphics_cairo.cpp b/src/graphics_cairo.cpp index 7abac5b..e1bfa47 100644 --- a/src/graphics_cairo.cpp +++ b/src/graphics_cairo.cpp @@ -209,20 +209,6 @@ namespace Pyro } } - void GraphicsCairo::ellipse(float x, float y, float w, float h, unsigned int segments) - { - Shape s{Shape()}; - s.begin(); - double da{M_PI / (segments / 2)}; - for (unsigned int i{0}; i < segments; i++) - { - s.vertex(cos(i * da) * w / 2, sin(i * da) * h / 2); - } - s.end(CLOSE); - - this->shape(s, x, y); - } - void GraphicsCairo::background(float r, float g, float b, float a) { Graphics::background(r, g, b, a); // memset(this->data, 0, this->_pixelwidth * this->_pixelheight * 4); diff --git a/src/image.cpp b/src/image.cpp index 6c54208..bdf246e 100644 --- a/src/image.cpp +++ b/src/image.cpp @@ -98,7 +98,7 @@ namespace Pyro this->data = nullptr; this->cache = nullptr; this->data = (uint32_t *)::operator new(this->_pixelwidth *this->_pixelheight * sizeof(uint32_t)); - std::memcpy(this->get_data(), in.get_data(), this->_pixelwidth * this->_pixelheight * sizeof(uint32_t)); + std::memcpy(this->get_data(), in.get_data(), this->_pixelwidth * this->_pixelheight * sizeof(uint32_t)); /* Flawfinder: ignore */ this->initialized = true; } @@ -158,7 +158,7 @@ namespace Pyro this->data = nullptr; this->cache = nullptr; this->data = (uint32_t *)::operator new(this->_pixelwidth *this->_pixelheight * sizeof(uint32_t)); - std::memcpy(this->get_data(), in.get_data(), this->_pixelwidth * this->_pixelheight * sizeof(uint32_t)); + std::memcpy(this->get_data(), in.get_data(), this->_pixelwidth * this->_pixelheight * sizeof(uint32_t)); /* Flawfinder: ignore */ return *this; } diff --git a/src/math.cpp b/src/math.cpp index ff86649..7e84a8a 100644 --- a/src/math.cpp +++ b/src/math.cpp @@ -15,40 +15,40 @@ namespace Pyro return radians * 180.0 / M_PI; } - int random(int range) + int random(int range) /* Flawfinder: ignore */ { - return (int)(random() * range); + return (int)(random() * range); /* Flawfinder: ignore */ } - int random(int low, int high) + int random(int low, int high) /* Flawfinder: ignore */ { assert(high > low); - return (int)((random() * (high - low)) + low); + return (int)((random() * (high - low)) + low); /* Flawfinder: ignore */ } - unsigned int random(unsigned int range) + unsigned int random(unsigned int range) /* Flawfinder: ignore */ { - return (unsigned int)(random() * range); + return (unsigned int)(random() * range); /* Flawfinder: ignore */ } - unsigned int random(unsigned int low, unsigned int high) + unsigned int random(unsigned int low, unsigned int high) /* Flawfinder: ignore */ { assert(high > low); - return (unsigned int)((random() * (high - low)) + low); + return (unsigned int)((random() * (high - low)) + low); /* Flawfinder: ignore */ } - double random(double range) + double random(double range) /* Flawfinder: ignore */ { - return random() * range; + return random() * range; /* Flawfinder: ignore */ } - double random(double low, double high) + double random(double low, double high) /* Flawfinder: ignore */ { assert(high > low); - return (random() * (high - low)) + low; + return (random() * (high - low)) + low; /* Flawfinder: ignore */ } - double random() + double random() /* Flawfinder: ignore */ { return rng_dist(rng); } @@ -58,13 +58,13 @@ namespace Pyro rng.seed(seed); } - float norm(float value, float start, float stop) - { + float norm(float value, float start, float stop) + { return map(value, start, stop, 0.0f, 1.0f); } - float exp(float n) { - return std::exp(n); + float exp(float n) + { + return std::exp(n); } - } diff --git a/src/vector.cpp b/src/vector.cpp index 9378bac..cd75434 100644 --- a/src/vector.cpp +++ b/src/vector.cpp @@ -9,13 +9,13 @@ namespace Pyro Vector Vector::random2d() { - return Vector::fromangle(Pyro::random(1.0f) * M_PI * 2.0); + return Vector::fromangle(Pyro::random(1.0f) * M_PI * 2.0); /* Flawfinder: ignore */ } Vector Vector::random3d() { - float phi = Pyro::random(0.0f, 1.0f * M_PI * 2.0); - float costheta = Pyro::random(-1.0f, 1.0f); + float phi = Pyro::random(0.0f, 1.0f * M_PI * 2.0); /* Flawfinder: ignore */ + float costheta = Pyro::random(-1.0f, 1.0f); /* Flawfinder: ignore */ float theta = acos(costheta); return Vector(sin(theta) * cos(phi), sin(theta) * sin(phi), cos(theta));