Tidy
This commit is contained in:
parent
4f2819bd81
commit
e5bf048d21
30
.clang-tidy
Normal file
30
.clang-tidy
Normal file
@ -0,0 +1,30 @@
|
||||
Checks: >
|
||||
clang-analyzer-*,
|
||||
bugprone-*,
|
||||
performance-*,
|
||||
readability-*,
|
||||
modernize-*,
|
||||
portability-*,
|
||||
misc-unused-parameters,
|
||||
misc-unused-alias-decls,
|
||||
misc-unused-using-decls,
|
||||
-readability-magic-numbers,
|
||||
-readability-identifier-naming,
|
||||
-modernize-use-trailing-return-type
|
||||
|
||||
WarningsAsErrors: ''
|
||||
|
||||
HeaderFilterRegex: '.*'
|
||||
|
||||
AnalyzeTemporaryDtors: true
|
||||
FormatStyle: file
|
||||
|
||||
CheckOptions:
|
||||
- key: modernize-use-nullptr.NullMacros
|
||||
value: 'NULL'
|
||||
- key: readability-braces-around-statements.ShortStatementLines
|
||||
value: '1'
|
||||
- key: modernize-loop-convert.MinConfidence
|
||||
value: reasonable
|
||||
- key: readability-function-cognitive-complexity.Threshold
|
||||
value: '25'
|
||||
@ -31,22 +31,22 @@ template <class T> static const char* GetTypeName()
|
||||
return typeid(T).name();
|
||||
}
|
||||
|
||||
template <> static const char* GetTypeName<int>()
|
||||
template <> const char* GetTypeName<int>()
|
||||
{
|
||||
return "integer";
|
||||
}
|
||||
|
||||
template <> static const char* GetTypeName<float>()
|
||||
template <> const char* GetTypeName<float>()
|
||||
{
|
||||
return "float";
|
||||
}
|
||||
|
||||
template <> static const char* GetTypeName<math::Vector>()
|
||||
template <> const char* GetTypeName<math::Vector>()
|
||||
{
|
||||
return "vector";
|
||||
}
|
||||
|
||||
template <> static const char* GetTypeName<std::string>()
|
||||
template <> const char* GetTypeName<std::string>()
|
||||
{
|
||||
return "string";
|
||||
}
|
||||
|
||||
@ -2,8 +2,6 @@
|
||||
|
||||
#include <filesystem>
|
||||
#include <fstream>
|
||||
#include <memory>
|
||||
#include <vector>
|
||||
|
||||
#include "shapes/group.hpp"
|
||||
|
||||
|
||||
1
main.cpp
1
main.cpp
@ -6,6 +6,7 @@
|
||||
#include "input_file.hpp"
|
||||
#include "renderers/pgm_renderer.hpp"
|
||||
#include "renderers/svg_renderer.hpp"
|
||||
#include <charconv>
|
||||
|
||||
template <class T>
|
||||
void Render(const shapes::Group& shapes, const std::filesystem::path& path, size_t width, size_t height)
|
||||
|
||||
@ -2,8 +2,6 @@
|
||||
|
||||
#include <cstddef>
|
||||
#include <cstdint>
|
||||
#include <filesystem>
|
||||
#include <span>
|
||||
#include <vector>
|
||||
|
||||
class Color
|
||||
|
||||
@ -78,24 +78,39 @@ void PgmRenderer::RasterizeLine(int x0, int y0, int x1, int y1)
|
||||
|
||||
// perpendicular offsets for thickness
|
||||
int ox = 0, oy = 0;
|
||||
if (dx > dy) {
|
||||
if (dx > dy)
|
||||
{
|
||||
oy = 1;
|
||||
} else {
|
||||
}
|
||||
else
|
||||
{
|
||||
ox = 1;
|
||||
}
|
||||
|
||||
while (1) {
|
||||
while (1)
|
||||
{
|
||||
// draw a square of pixels for thickness
|
||||
for (int i = -w/2; i <= w/2; i++) {
|
||||
for (int j = -w/2; j <= w/2; j++) {
|
||||
m_bitmap.Put(x0 + i*ox, y0 + j*oy, lineColor, 0xFF);
|
||||
for (int i = -w / 2; i <= w / 2; i++)
|
||||
{
|
||||
for (int j = -w / 2; j <= w / 2; j++)
|
||||
{
|
||||
m_bitmap.Put(x0 + i * ox, y0 + j * oy, lineColor, 0xFF);
|
||||
}
|
||||
}
|
||||
|
||||
if (x0 == x1 && y0 == y1) break;
|
||||
if (x0 == x1 && y0 == y1)
|
||||
break;
|
||||
int e2 = 2 * err;
|
||||
if (e2 > -dy) { err -= dy; x0 += sx; }
|
||||
if (e2 < dx) { err += dx; y0 += sy; }
|
||||
if (e2 > -dy)
|
||||
{
|
||||
err -= dy;
|
||||
x0 += sx;
|
||||
}
|
||||
if (e2 < dx)
|
||||
{
|
||||
err += dx;
|
||||
y0 += sy;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@ -106,15 +121,18 @@ void PgmRenderer::RasterizeCircle(int cx, int cy, int r)
|
||||
const Color circleColor{0x00};
|
||||
float w = 2.0f;
|
||||
|
||||
|
||||
int r_outer = r + w / 2;
|
||||
int r_inner = r - w / 2;
|
||||
if (r_inner < 0) r_inner = 0;
|
||||
if (r_inner < 0)
|
||||
r_inner = 0;
|
||||
|
||||
for (int y = -r_outer; y <= r_outer; y++) {
|
||||
for (int x = -r_outer; x <= r_outer; x++) {
|
||||
int dist2 = x*x + y*y;
|
||||
if (dist2 <= r_outer*r_outer && dist2 >= r_inner*r_inner) {
|
||||
for (int y = -r_outer; y <= r_outer; y++)
|
||||
{
|
||||
for (int x = -r_outer; x <= r_outer; x++)
|
||||
{
|
||||
int dist2 = x * x + y * y;
|
||||
if (dist2 <= r_outer * r_outer && dist2 >= r_inner * r_inner)
|
||||
{
|
||||
m_bitmap.Put(cx + x, cy + y, circleColor, 0xFF);
|
||||
}
|
||||
}
|
||||
|
||||
@ -26,4 +26,4 @@ class PgmRenderer : public Renderer
|
||||
void RasterizeCircle(int xm, int ym, int r);
|
||||
|
||||
void Flush();
|
||||
};
|
||||
};
|
||||
|
||||
@ -8,9 +8,5 @@ class Renderer
|
||||
virtual void DrawRectangle(const math::Vector& pos, const math::Vector& size, float angle) = 0;
|
||||
virtual void DrawCircle(const math::Vector& center, float radius) = 0;
|
||||
|
||||
virtual void Flush()
|
||||
{
|
||||
}
|
||||
|
||||
virtual ~Renderer() = default;
|
||||
};
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user