Skip to content

Commit

Permalink
Manually fixed google checks
Browse files Browse the repository at this point in the history
refactored PlaceholderString

c style cast to static_cast
replaced char const* with std::string

fixed all google-* checks
  • Loading branch information
Febbe committed Dec 3, 2019
1 parent 3415e6b commit b708c89
Show file tree
Hide file tree
Showing 44 changed files with 229 additions and 378 deletions.
4 changes: 3 additions & 1 deletion .clang-tidy
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
Checks: "*,\
Checks: "cppcoreguidelines*,\
-cppcoreguidelines-pro-bounds-pointer-arithmetic,\
-cppcoreguidelines-pro-type-cstyle-cast,\
-readability-identifier-naming,\
-misc-unused-parameters,\
-cppcoreguidelines-pro-type-union-access,\
Expand Down
4 changes: 2 additions & 2 deletions src/control/ClipboardHandler.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -116,8 +116,8 @@ class ClipboardContents
}
else if (atomSvg1 == target || atomSvg2 == target)
{
gtk_selection_data_set(selection, target, 8, (guchar*) contents->svg.c_str(),
contents->svg.length());
gtk_selection_data_set(selection, target, 8, reinterpret_cast<guchar const*>(contents->svg.c_str()),
contents->svg.length());
}
else if (atomXournal == target)
{
Expand Down
6 changes: 3 additions & 3 deletions src/control/Control.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1816,13 +1816,13 @@ void Control::undoRedoPageChanged(PageRef page)
{
for (XojPage* p: this->changedPages)
{
if (p == (XojPage*) page)
if (p == static_cast<XojPage*>(page))
{
return;
}
}

auto* p = (XojPage*) page;
auto* p = static_cast<XojPage*>(page);
this->changedPages.push_back(p);
p->reference();
}
Expand Down Expand Up @@ -2451,7 +2451,7 @@ void Control::loadMetadata(MetadataEntry md)
g_idle_add(reinterpret_cast<GSourceFunc>(loadMetadataCallback), data);
}

auto Control::annotatePdf(Path filename, bool attachPdf, bool attachToDocument) -> bool
auto Control::annotatePdf(Path filename, bool /*attachPdf*/, bool attachToDocument) -> bool
{
if (!this->close(false))
{
Expand Down
6 changes: 3 additions & 3 deletions src/control/FullscreenHandler.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,7 @@ void FullscreenHandler::hideWidget(MainWindow* win, const string& widgetName)

void FullscreenHandler::enableFullscreen(MainWindow* win)
{
gtk_window_fullscreen((GtkWindow*) *win);
gtk_window_fullscreen(static_cast<GtkWindow*>(*win));

string hideWidgets = settings->getFullscreenHideElements();
for (const string& s: StringUtils::split(hideWidgets, ','))
Expand All @@ -75,7 +75,7 @@ void FullscreenHandler::enableFullscreen(MainWindow* win)

void FullscreenHandler::disableFullscreen(MainWindow* win)
{
gtk_window_unfullscreen((GtkWindow*) *win);
gtk_window_unfullscreen(static_cast<GtkWindow*>(*win));

for (GtkWidget* w : hiddenFullscreenWidgets)
{
Expand Down Expand Up @@ -191,7 +191,7 @@ auto gtk_invisible_get_type() -> GType
// instance init
nullptr,
// value table
(const GTypeValueTable*) nullptr};
nullptr};

gtk_invisible_menu_type = g_type_register_static(GTK_TYPE_FIXED, "GtkInvisibleMenu", &gtk_inivisible_menu_info,
static_cast<GTypeFlags>(0));
Expand Down
4 changes: 2 additions & 2 deletions src/control/XournalMain.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -371,7 +371,7 @@ auto XournalMain::run(int argc, char* argv[]) -> int
{
string msg = _("Sorry, Xournal++ can only open one file at once.\n"
"Others are ignored.");
XojMsgBox::showErrorToUser((GtkWindow*) *win, msg);
XojMsgBox::showErrorToUser(static_cast<GtkWindow*>(*win), msg);
}

GFile* file = g_file_new_for_commandline_arg(optFilename[0]);
Expand All @@ -386,7 +386,7 @@ auto XournalMain::run(int argc, char* argv[]) -> int
{
string msg = _("Sorry, Xournal++ cannot open remote files at the moment.\n"
"You have to copy the file to a local directory.");
XojMsgBox::showErrorToUser((GtkWindow*) *win, msg);
XojMsgBox::showErrorToUser(static_cast<GtkWindow*>(*win), msg);
}
}

Expand Down
8 changes: 4 additions & 4 deletions src/control/settings/Settings.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -949,19 +949,19 @@ void Settings::save()

if (this->scrollbarHideType == SCROLLBAR_HIDE_BOTH)
{
saveProperty((const char*) "scrollbarHideType", "both", root);
saveProperty("scrollbarHideType", "both", root);
}
else if (this->scrollbarHideType == SCROLLBAR_HIDE_HORIZONTAL)
{
saveProperty((const char*) "scrollbarHideType", "horizontal", root);
saveProperty("scrollbarHideType", "horizontal", root);
}
else if (this->scrollbarHideType == SCROLLBAR_HIDE_VERTICAL)
{
saveProperty((const char*) "scrollbarHideType", "vertical", root);
saveProperty("scrollbarHideType", "vertical", root);
}
else
{
saveProperty((const char*) "scrollbarHideType", "none", root);
saveProperty("scrollbarHideType", "none", root);
}

WRITE_BOOL_PROP(autoloadPdfXoj);
Expand Down
25 changes: 1 addition & 24 deletions src/control/shaperecognizer/RecoSegment.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -3,32 +3,9 @@
#include "Inertia.h"
#include <cmath>

#include <cmath>
#include <cstdlib>

RecoSegment::RecoSegment()
{
this->stroke = nullptr;
this->angle = 0;
this->endpt = 0;

this->radius = 0;
this->reversed = false;
this->startpt = 0;
this->x1 = 0;
this->x2 = 0;
this->xcenter = 0;
this->y1 = 0;
this->y2 = 0;
this->ycenter = 0;
}

RecoSegment::~RecoSegment() = default;

auto RecoSegment::calcEdgeIsect(RecoSegment* r2) const -> Point
{
double t = NAN;
t = (r2->xcenter - this->xcenter) * sin(r2->angle) - (r2->ycenter - this->ycenter) * cos(r2->angle);
double t = (r2->xcenter - this->xcenter) * sin(r2->angle) - (r2->ycenter - this->ycenter) * cos(r2->angle);
t /= sin(r2->angle - this->angle);
double x = this->xcenter + t * cos(this->angle);
double y = this->ycenter + t * sin(this->angle);
Expand Down
35 changes: 13 additions & 22 deletions src/control/shaperecognizer/RecoSegment.h
Original file line number Diff line number Diff line change
Expand Up @@ -8,44 +8,35 @@
*
* @license GNU GPLv2 or later
*/

#pragma once

#include "model/Point.h"

#include <XournalType.h>

class Stroke;
class Inertia;

class RecoSegment
struct RecoSegment final
{
public:
RecoSegment();
virtual ~RecoSegment();

public:
Point calcEdgeIsect(RecoSegment* r2) const;

/**
* Find the geometry of a recognized segment
*/
void calcSegmentGeometry(const Point* pt, int start, int end, Inertia* s);

public:
Stroke* stroke;
int startpt;
int endpt;
Stroke* stroke{nullptr};
int startpt{0};
int endpt{0};

double xcenter;
double ycenter;
double angle;
double radius;
double xcenter{0};
double ycenter{0};
double angle{0};
double radius{0};

double x1;
double y1;
double x2;
double y2;
double x1{0};
double y1{0};
double x2{0};
double y2{0};

bool reversed;
bool reversed{};
};
84 changes: 9 additions & 75 deletions src/control/shaperecognizer/ShapeRecognizer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -26,12 +26,7 @@ ShapeRecognizer::~ShapeRecognizer()
void ShapeRecognizer::resetRecognizer()
{
RDEBUG("reset");

for (auto& i: this->queue)
{
i.stroke = nullptr;
}

this->queue = {};
this->queueLength = 0;
}

Expand Down Expand Up @@ -150,11 +145,11 @@ auto ShapeRecognizer::tryArrow() -> Stroke*
return nullptr;
}

double x1 = NAN;
double y1 = NAN;
double x2 = NAN;
double y2 = NAN;
double angle = NAN;
double x1{};
double y1{};
double x2{};
double y2{};
double angle{};

if (rev[1])
{
Expand Down Expand Up @@ -321,8 +316,8 @@ auto ShapeRecognizer::findPolygonal(const Point* pt, int start, int end, int nsi
return 0; // failed!
}

double det1 = NAN;
double det2 = NAN;
double det1{};
double det2{};
Inertia s1;
Inertia s2;

Expand Down Expand Up @@ -458,67 +453,6 @@ void ShapeRecognizer::optimizePolygonal(const Point* pt, int nsides, int* breaks
}
}

auto ShapeRecognizer::tryClosedPolygon(int nsides) -> Stroke*
{
//to eliminate bug #52, remove this until it's perfected
return nullptr;

/*
RecoSegment* r1 = nullptr;
RecoSegment* r2 = nullptr;
// first, we need whole strokes to combine to nsides segments...
if (this->queueLength < nsides)
{
return nullptr;
}
RecoSegment* rs = &this->queue[this->queueLength - nsides];
if (rs->startpt != 0)
{
return nullptr;
}
// check vertices roughly match
for (int i = 0; i < nsides; i++)
{
r1 = rs + i;
r2 = rs + (i + 1) % nsides;
// test if r1 points away from r2 rather than towards it
Point pt = r1->calcEdgeIsect(r2);
r1->reversed = (hypot(pt.x - r1->x1, pt.y - r1->y1) < hypot(pt.x - r1->x2, pt.y - r1->y2));
}
for (int i = 0; i < nsides; i++)
{
r1 = rs + i;
r2 = rs + (i + 1) % nsides;
Point pt = r1->calcEdgeIsect(r2);
double dist = hypot((r1->reversed ? r1->x1 : r1->x2) - pt.x,
(r1->reversed ? r1->y1 : r1->y2) - pt.y)
+ hypot((r2->reversed ? r2->x2 : r2->x1) - pt.x,
(r2->reversed ? r2->y2 : r2->y1) - pt.y);
if (dist > POLYGON_LINEAR_TOLERANCE * (r1->radius + r2->radius))
{
return nullptr;
}
}
Stroke* s = new Stroke();
s->applyStyleFrom(this->stroke);
for (int i = 0; i < nsides; i++)
{
Point p = rs[i].calcEdgeIsect(&rs[(i + 1) % nsides]);
s->addPoint(p);
}
s->addPoint(s->getPoint(0));
return s;
*/
}

/**
* The main pattern recognition function
*/
Expand Down Expand Up @@ -558,7 +492,7 @@ auto ShapeRecognizer::recognizePatterns(Stroke* stroke) -> ShapeRecognizerResult
i++;
}
queueLength -= i;
g_memmove(queue, queue + i, queueLength * sizeof(RecoSegment));
std::move(std::next(begin(queue), i), std::next(begin(queue), i + queueLength), begin(queue));
}

RDEBUG("Queue now has %i + %i edges", this->queueLength, n);
Expand Down
5 changes: 2 additions & 3 deletions src/control/shaperecognizer/ShapeRecognizer.h
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
#include "RecoSegment.h"
#include "ShapeRecognizerConfig.h"

#include <XournalType.h>
#include <array>

class Stroke;
class Point;
Expand All @@ -33,13 +33,12 @@ class ShapeRecognizer
Stroke* tryRectangle();
Stroke* tryArrow();

static Stroke* tryClosedPolygon(int nsides);
static void optimizePolygonal(const Point* pt, int nsides, int* breaks, Inertia* ss);

int findPolygonal(const Point* pt, int start, int end, int nsides, int* breaks, Inertia* ss);

private:
RecoSegment queue[MAX_POLYGON_SIDES + 1];
std::array<RecoSegment, MAX_POLYGON_SIDES + 1> queue{};
int queueLength;

Stroke* stroke;
Expand Down
2 changes: 1 addition & 1 deletion src/gui/MainWindow.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -659,7 +659,7 @@ auto MainWindow::getToolbarName(GtkToolbar* toolbar) -> const char*
{
for (int i = 0; i < TOOLBAR_DEFINITIONS_LEN; i++)
{
if ((void*) this->toolbarWidgets[i] == (void*) toolbar)
if (static_cast<void*>(this->toolbarWidgets[i]) == static_cast<void*>(toolbar))
{
return TOOLBAR_DEFINITIONS[i].propName;
}
Expand Down
Loading

0 comments on commit b708c89

Please sign in to comment.