Skip to content

Commit

Permalink
Misc linting.
Browse files Browse the repository at this point in the history
  • Loading branch information
gregersn committed Aug 31, 2024
1 parent 77fb402 commit 483e556
Show file tree
Hide file tree
Showing 13 changed files with 59 additions and 93 deletions.
8 changes: 1 addition & 7 deletions .vscode/settings.json
Original file line number Diff line number Diff line change
@@ -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",
Expand All @@ -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": {
Expand Down
14 changes: 7 additions & 7 deletions include/opensimplexnoise.h
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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
Expand Down Expand Up @@ -76,12 +76,12 @@ class OpenSimplexNoise
static const std::array<int8_t, 256> gradients4D;

public:
OpenSimplexNoise() : OpenSimplexNoise(DEFAULT_SEED){};
OpenSimplexNoise(std::array<int16_t, 256> perm);
OpenSimplexNoise(long seed);
OpenSimplexNoise() : OpenSimplexNoise(DEFAULT_SEED) {};
explicit OpenSimplexNoise(std::array<int16_t, 256> 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
#endif
1 change: 0 additions & 1 deletion include/pyro/graphics_cairo.h
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
26 changes: 15 additions & 11 deletions include/pyro/math.h
Original file line number Diff line number Diff line change
Expand Up @@ -23,12 +23,14 @@ namespace Pyro
};

template <typename T>
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 <typename T>
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);
};

Expand All @@ -41,12 +43,14 @@ namespace Pyro
};

template <typename T>
T mag(T a, T b) {
T mag(T a, T b)
{
return sqrt(a * a + b * b);
};

template <typename T>
T mag(T a, T b, T c) {
T mag(T a, T b, T c)
{
return sqrt(a * a + b * b + c * c);
};

Expand Down Expand Up @@ -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

Expand Down
6 changes: 3 additions & 3 deletions include/pyro/pyro.h
Original file line number Diff line number Diff line change
Expand Up @@ -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); };
Expand All @@ -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); };
Expand All @@ -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); };
Expand Down
10 changes: 5 additions & 5 deletions include/pyro/sdl.h
Original file line number Diff line number Diff line change
Expand Up @@ -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;
};
}

Expand Down
2 changes: 1 addition & 1 deletion screenshot-tests/screenshotmatcher.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand Down
2 changes: 1 addition & 1 deletion screenshot-tests/test-lines.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand Down
23 changes: 3 additions & 20 deletions src/graphics.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand Down Expand Up @@ -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;
Expand All @@ -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;
Expand All @@ -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;
Expand All @@ -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;
Expand Down Expand Up @@ -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;
Expand Down Expand Up @@ -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)
Expand Down
14 changes: 0 additions & 14 deletions src/graphics_cairo.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
4 changes: 2 additions & 2 deletions src/image.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}

Expand Down Expand Up @@ -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;
}
Expand Down
36 changes: 18 additions & 18 deletions src/math.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
Expand All @@ -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);
}


}
6 changes: 3 additions & 3 deletions src/vector.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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));
Expand Down

0 comments on commit 483e556

Please sign in to comment.