Einige Warnungen mit -Wall gefixt
This commit is contained in:
parent
1e9704dca9
commit
50b65f72c0
5 changed files with 55 additions and 43 deletions
45
Line.cpp
45
Line.cpp
|
@ -3,31 +3,31 @@
|
||||||
|
|
||||||
|
|
||||||
bool Line::contains(const Vertex &v) const {
|
bool Line::contains(const Vertex &v) const {
|
||||||
if(fabs(v1.getX() - v2.getX()) < 1E-6 && fabs(v1.getY() - v2.getY()) < 1E-6) {
|
if(fabsf(v1.getX() - v2.getX()) < 1E-6 && fabsf(v1.getY() - v2.getY()) < 1E-6) {
|
||||||
if(fabs(v1.getX() - v.getX()) < 1E-6 && fabs(v1.getY() - v.getY()) < 1E-6)
|
if(fabsf(v1.getX() - v.getX()) < 1E-6 && fabsf(v1.getY() - v.getY()) < 1E-6)
|
||||||
return true;
|
return true;
|
||||||
else
|
else
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
if(fabs(v1.getX() - v2.getX()) < 1E-6) {
|
if(fabsf(v1.getX() - v2.getX()) < 1E-6) {
|
||||||
if(fabs(v1.getX() - v.getX()) >= 1E-6)
|
if(fabsf(v1.getX() - v.getX()) >= 1E-6)
|
||||||
return false;
|
return false;
|
||||||
else if(v.getY() - fmin(v1.getY(), v2.getY()) > -1E-6 && v.getY() - fmax(v1.getY(), v2.getY()) < 1E-6)
|
else if(v.getY() - fminf(v1.getY(), v2.getY()) > -1E-6 && v.getY() - fmaxf(v1.getY(), v2.getY()) < 1E-6)
|
||||||
return true;
|
return true;
|
||||||
else
|
else
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
if(fabs(v1.getY() - v2.getY()) < 1E-6) {
|
if(fabsf(v1.getY() - v2.getY()) < 1E-6) {
|
||||||
if(fabs(v1.getY() - v.getY()) >= 1E-6)
|
if(fabsf(v1.getY() - v.getY()) >= 1E-6)
|
||||||
return false;
|
return false;
|
||||||
else if(v.getX() - fmin(v1.getX(), v2.getX()) > -1E-6 && v.getX() - fmax(v1.getX(), v2.getX()) < 1E-6)
|
else if(v.getX() - fminf(v1.getX(), v2.getX()) > -1E-6 && v.getX() - fmaxf(v1.getX(), v2.getX()) < 1E-6)
|
||||||
return true;
|
return true;
|
||||||
else
|
else
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
if(fabs((v.getX()-v1.getX())/(v2.getX()-v1.getX()) - (v.getY()-v1.getY())/(v2.getY()-v1.getY())) < 1E-6)
|
if(fabsf((v.getX()-v1.getX())/(v2.getX()-v1.getX()) - (v.getY()-v1.getY())/(v2.getY()-v1.getY())) < 1E-6)
|
||||||
return true;
|
return true;
|
||||||
else
|
else
|
||||||
return false;
|
return false;
|
||||||
|
@ -39,32 +39,32 @@ int Line::intersects(const Line &l, Vertex *v) const {
|
||||||
float xb1 = l.v1.getX(), yb1 = l.v1.getY();
|
float xb1 = l.v1.getX(), yb1 = l.v1.getY();
|
||||||
float xb2 = l.v2.getX(), yb2 = l.v2.getY();
|
float xb2 = l.v2.getX(), yb2 = l.v2.getY();
|
||||||
float temp;
|
float temp;
|
||||||
int switched = 0;
|
bool switched = false;
|
||||||
Vertex v2;
|
Vertex v2;
|
||||||
|
|
||||||
|
|
||||||
if(!v) v = &v2;
|
if(!v) v = &v2;
|
||||||
|
|
||||||
if(fabs(xa1 - xa2) < 1E-6 && fabs(ya1 - ya2) < 1E-6) return INTERSECTION_ERROR;
|
if(fabsf(xa1 - xa2) < 1E-6 && fabsf(ya1 - ya2) < 1E-6) return INTERSECTION_ERROR;
|
||||||
if(fabs(xb1 - xb2) < 1E-6 && fabs(yb1 - yb2) < 1E-6) return INTERSECTION_ERROR;
|
if(fabsf(xb1 - xb2) < 1E-6 && fabsf(yb1 - yb2) < 1E-6) return INTERSECTION_ERROR;
|
||||||
|
|
||||||
if(fabs(xa1 - xa2) < 1E-6 || fabs(xb1 - xb2) < 1E-6) {
|
if(fabsf(xa1 - xa2) < 1E-6 || fabsf(xb1 - xb2) < 1E-6) {
|
||||||
temp = xa1; xa1 = ya1; ya1 = temp;
|
temp = xa1; xa1 = ya1; ya1 = temp;
|
||||||
temp = xa2; xa2 = ya2; ya2 = temp;
|
temp = xa2; xa2 = ya2; ya2 = temp;
|
||||||
temp = xb1; xb1 = yb1; yb1 = temp;
|
temp = xb1; xb1 = yb1; yb1 = temp;
|
||||||
temp = xb2; xb2 = yb2; yb2 = temp;
|
temp = xb2; xb2 = yb2; yb2 = temp;
|
||||||
|
|
||||||
switched = 1;
|
switched = true;
|
||||||
}
|
}
|
||||||
|
|
||||||
if(fabs(xa1 - xa2) < 1E-6 && fabs(xb1 - xb2) < 1E-6)
|
if(fabsf(xa1 - xa2) < 1E-6 && fabsf(xb1 - xb2) < 1E-6)
|
||||||
return (fabs(xa1 - xb1) < 1E-6) ? INTERSECTION_IDENTICAL : INTERSECTION_NONE;
|
return (fabsf(xa1 - xb1) < 1E-6) ? INTERSECTION_IDENTICAL : INTERSECTION_NONE;
|
||||||
|
|
||||||
if(fabs(xa1 - xa2) < 1E-6) {
|
if(fabsf(xa1 - xa2) < 1E-6) {
|
||||||
v->setX(xa1);
|
v->setX(xa1);
|
||||||
v->setY(yb1);
|
v->setY(yb1);
|
||||||
}
|
}
|
||||||
else if(fabs(xb1 - xb2) < 1E-6) {
|
else if(fabsf(xb1 - xb2) < 1E-6) {
|
||||||
v->setX(xb1);
|
v->setX(xb1);
|
||||||
v->setY(ya1);
|
v->setY(ya1);
|
||||||
}
|
}
|
||||||
|
@ -74,7 +74,7 @@ int Line::intersects(const Line &l, Vertex *v) const {
|
||||||
float ba = ya1 - ma*xa1;
|
float ba = ya1 - ma*xa1;
|
||||||
float bb = yb1 - mb*xb1;
|
float bb = yb1 - mb*xb1;
|
||||||
|
|
||||||
if(fabs(ma - mb) < 1E-6) return (fabs(ba - bb) < 1E-6) ? INTERSECTION_IDENTICAL : INTERSECTION_NONE;
|
if(fabsf(ma - mb) < 1E-6) return (fabsf(ba - bb) < 1E-6) ? INTERSECTION_IDENTICAL : INTERSECTION_NONE;
|
||||||
|
|
||||||
v->setX((bb-ba)/(ma-mb));
|
v->setX((bb-ba)/(ma-mb));
|
||||||
v->setY(ma*v->getX() + ba);
|
v->setY(ma*v->getX() + ba);
|
||||||
|
@ -90,14 +90,15 @@ int Line::intersects(const Line &l, Vertex *v) const {
|
||||||
temp = xb2; xb2 = yb2; yb2 = temp;
|
temp = xb2; xb2 = yb2; yb2 = temp;
|
||||||
}
|
}
|
||||||
|
|
||||||
if(v->getX() < fmin(xa1,xa2) || v->getX() > fmax(xa1, xa2) || v->getY() < fmin(ya1,ya2) || v->getY() > fmax(ya1, ya2)) {
|
if(v->getX() < fminf(xa1,xa2) || v->getX() > fmaxf(xa1, xa2) || v->getY() < fminf(ya1,ya2) || v->getY() > fmaxf(ya1, ya2)) {
|
||||||
if(v->getX() < fmin(xb1,xb2) || v->getX() > fmax(xb1, xb2) || v->getY() < fmin(yb1,yb2) || v->getY() > fmax(yb1, yb2))
|
if(v->getX() < fminf(xb1,xb2) || v->getX() > fmaxf(xb1, xb2) || v->getY() < fminf(yb1,yb2) || v->getY() > fmaxf(yb1, yb2))
|
||||||
return INTERSECTION_LINE_LINE;
|
return INTERSECTION_LINE_LINE;
|
||||||
else
|
else
|
||||||
return INTERSECTION_LINE_SEGMENT;
|
return INTERSECTION_LINE_SEGMENT;
|
||||||
}
|
}
|
||||||
else if(v->getX() < fmin(xb1,xb2) || v->getX() > fmax(xb1, xb2) || v->getY() < fmin(yb1,yb2) || v->getY() > fmax(yb1, yb2))
|
else if(v->getX() < fminf(xb1,xb2) || v->getX() > fmaxf(xb1, xb2) || v->getY() < fminf(yb1,yb2) || v->getY() > fmaxf(yb1, yb2))
|
||||||
return INTERSECTION_SEGMENT_LINE;
|
return INTERSECTION_SEGMENT_LINE;
|
||||||
else
|
else
|
||||||
return INTERSECTION_SEGMENT_SEGMENT;
|
return INTERSECTION_SEGMENT_SEGMENT;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
20
Polygon.cpp
20
Polygon.cpp
|
@ -24,7 +24,7 @@ Polygon::Direction Polygon::getDirection() const {
|
||||||
}
|
}
|
||||||
|
|
||||||
float Polygon::area() const {
|
float Polygon::area() const {
|
||||||
return fabs(signedArea());
|
return fabsf(signedArea());
|
||||||
}
|
}
|
||||||
|
|
||||||
float Polygon::perimeter() const {
|
float Polygon::perimeter() const {
|
||||||
|
@ -135,9 +135,9 @@ bool Polygon::isConcave(const Direction &dir, const Vertex &v1, const Vertex &v2
|
||||||
return (v1.getX()-v2.getX())*(v3.getY()-v2.getY()) > (v3.getX()-v2.getX())*(v1.getY()-v2.getY());
|
return (v1.getX()-v2.getX())*(v3.getY()-v2.getY()) > (v3.getX()-v2.getX())*(v1.getY()-v2.getY());
|
||||||
case Triangle::CCW:
|
case Triangle::CCW:
|
||||||
return (v1.getX()-v2.getX())*(v3.getY()-v2.getY()) < (v3.getX()-v2.getX())*(v1.getY()-v2.getY());
|
return (v1.getX()-v2.getX())*(v3.getY()-v2.getY()) < (v3.getX()-v2.getX())*(v1.getY()-v2.getY());
|
||||||
|
default:
|
||||||
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
return false;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
bool Polygon::intersections(std::vector<Intersection> *intersections) const {
|
bool Polygon::intersections(std::vector<Intersection> *intersections) const {
|
||||||
|
@ -180,10 +180,10 @@ bool Polygon::simplify(std::list<Polygon> &polygons) const {
|
||||||
|
|
||||||
if(!intersections(&ins)) return false;
|
if(!intersections(&ins)) return false;
|
||||||
|
|
||||||
int s = size();
|
size_t s = size();
|
||||||
int start = 0;
|
size_t start = 0;
|
||||||
|
|
||||||
for(int i = 1; i < s; i++) {
|
for(size_t i = 1; i < s; i++) {
|
||||||
if(at(i).getX() < at(start).getX())
|
if(at(i).getX() < at(start).getX())
|
||||||
start = i;
|
start = i;
|
||||||
else if(at(i).getX() == at(start).getX() && at(i).getY() < at(start).getY())
|
else if(at(i).getX() == at(start).getX() && at(i).getY() < at(start).getY())
|
||||||
|
@ -192,7 +192,7 @@ bool Polygon::simplify(std::list<Polygon> &polygons) const {
|
||||||
|
|
||||||
int dir = Triangle(at((s+start-1)%s), at(start), at((start+1)%s)).getDirection();
|
int dir = Triangle(at((s+start-1)%s), at(start), at((start+1)%s)).getDirection();
|
||||||
|
|
||||||
int i2 = start;
|
size_t i2 = start;
|
||||||
const Vertex *v2 = &at(i2);
|
const Vertex *v2 = &at(i2);
|
||||||
bool intersected;
|
bool intersected;
|
||||||
|
|
||||||
|
@ -201,7 +201,7 @@ bool Polygon::simplify(std::list<Polygon> &polygons) const {
|
||||||
do {
|
do {
|
||||||
intersected = false;
|
intersected = false;
|
||||||
|
|
||||||
int i = i2;
|
size_t i = i2;
|
||||||
|
|
||||||
if(dir == Triangle::CW)
|
if(dir == Triangle::CW)
|
||||||
i2 = (i2+1)%s;
|
i2 = (i2+1)%s;
|
||||||
|
@ -216,7 +216,7 @@ bool Polygon::simplify(std::list<Polygon> &polygons) const {
|
||||||
Intersection *intr = NULL;
|
Intersection *intr = NULL;
|
||||||
Vertex *v = NULL;
|
Vertex *v = NULL;
|
||||||
float dv = 0;
|
float dv = 0;
|
||||||
int v3, v4;
|
size_t v3 = 0, v4 = 0;
|
||||||
|
|
||||||
for(std::vector<Intersection>::iterator in = ins.begin(); in != ins.end(); ++in) {
|
for(std::vector<Intersection>::iterator in = ins.begin(); in != ins.end(); ++in) {
|
||||||
float di = v2->distanceSq(in->v);
|
float di = v2->distanceSq(in->v);
|
||||||
|
@ -276,7 +276,7 @@ bool Polygon::simplify(std::list<Polygon> &polygons) const {
|
||||||
polygons.back().push_back(polygons.front().back());
|
polygons.back().push_back(polygons.front().back());
|
||||||
polygons.front().pop_back();
|
polygons.front().pop_back();
|
||||||
|
|
||||||
if(v->distanceSq(polygons.back().back()) < 1E-6)
|
if(v->distanceSq(polygons.back().back()) < 1E-12)
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -32,9 +32,9 @@ bool Triangle::contains(const Vertex &v) const {
|
||||||
return ((a < 1E-6) && (b < 1E-6) && (c < 1E-6));
|
return ((a < 1E-6) && (b < 1E-6) && (c < 1E-6));
|
||||||
case CCW:
|
case CCW:
|
||||||
return ((a > -1E-6) && (b > -1E-6) && (c > -1E-6));
|
return ((a > -1E-6) && (b > -1E-6) && (c > -1E-6));
|
||||||
|
default:
|
||||||
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
return false;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
bool Triangle::onEdge(const Vertex &v) const {
|
bool Triangle::onEdge(const Vertex &v) const {
|
||||||
|
|
2
edit.cpp
2
edit.cpp
|
@ -86,7 +86,7 @@ static bool isLineOk(Line *l) {
|
||||||
|
|
||||||
|
|
||||||
if(activeRoom) {
|
if(activeRoom) {
|
||||||
for(int i = 0; i+2 < activeRoom->size(); i++) {
|
for(size_t i = 0; i+2 < activeRoom->size(); i++) {
|
||||||
l2.setVertex1(activeRoom->at(i));
|
l2.setVertex1(activeRoom->at(i));
|
||||||
l2.setVertex2(activeRoom->at(i+1));
|
l2.setVertex2(activeRoom->at(i+1));
|
||||||
|
|
||||||
|
|
27
window.cpp
27
window.cpp
|
@ -124,9 +124,12 @@ static gboolean scrollEvent(GtkWidget *widget, GdkEventScroll *event, gpointer u
|
||||||
switch(event->direction) {
|
switch(event->direction) {
|
||||||
case GDK_SCROLL_UP:
|
case GDK_SCROLL_UP:
|
||||||
zoomIn(1.1f, x, y);
|
zoomIn(1.1f, x, y);
|
||||||
break;
|
return TRUE;
|
||||||
case GDK_SCROLL_DOWN:
|
case GDK_SCROLL_DOWN:
|
||||||
zoomOut(1.1f, x, y);
|
zoomOut(1.1f, x, y);
|
||||||
|
return TRUE;
|
||||||
|
default:
|
||||||
|
return FALSE;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -156,9 +159,11 @@ static gboolean buttonEvent(GtkWidget *widget, GdkEventButton *event, gpointer u
|
||||||
|
|
||||||
gtk_widget_queue_draw(drawingArea);
|
gtk_widget_queue_draw(drawingArea);
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
|
||||||
return FALSE;
|
return TRUE;
|
||||||
|
default:
|
||||||
|
return FALSE;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
gboolean crossingNotifyEvent(GtkWidget *widget, GdkEventCrossing *event, gpointer user_data) {
|
gboolean crossingNotifyEvent(GtkWidget *widget, GdkEventCrossing *event, gpointer user_data) {
|
||||||
|
@ -170,13 +175,18 @@ gboolean crossingNotifyEvent(GtkWidget *widget, GdkEventCrossing *event, gpointe
|
||||||
|
|
||||||
setHoveredVertex(&v);
|
setHoveredVertex(&v);
|
||||||
|
|
||||||
break;
|
gtk_widget_queue_draw(drawingArea);
|
||||||
|
|
||||||
|
return TRUE;
|
||||||
case GDK_LEAVE_NOTIFY:
|
case GDK_LEAVE_NOTIFY:
|
||||||
setHoveredVertex(NULL);
|
setHoveredVertex(NULL);
|
||||||
|
|
||||||
|
gtk_widget_queue_draw(drawingArea);
|
||||||
|
|
||||||
|
return TRUE;
|
||||||
|
default:
|
||||||
|
return FALSE;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
gtk_widget_queue_draw(drawingArea);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
gboolean motionNotifyEvent(GtkWidget *widget, GdkEventMotion *event, gpointer user_data) {
|
gboolean motionNotifyEvent(GtkWidget *widget, GdkEventMotion *event, gpointer user_data) {
|
||||||
|
@ -189,6 +199,8 @@ gboolean motionNotifyEvent(GtkWidget *widget, GdkEventMotion *event, gpointer us
|
||||||
|
|
||||||
if(getHoveredRoom() != last || getEditMode() == EDIT_MODE_ADD)
|
if(getHoveredRoom() != last || getEditMode() == EDIT_MODE_ADD)
|
||||||
gtk_widget_queue_draw(drawingArea);
|
gtk_widget_queue_draw(drawingArea);
|
||||||
|
|
||||||
|
return TRUE;
|
||||||
}
|
}
|
||||||
|
|
||||||
static void destroy(GtkWidget *widget, gpointer data) {
|
static void destroy(GtkWidget *widget, gpointer data) {
|
||||||
|
@ -290,7 +302,6 @@ static GtkWidget* createSidebar() {
|
||||||
|
|
||||||
GtkWidget* createMainWindow(GdkGLConfig *glconfig) {
|
GtkWidget* createMainWindow(GdkGLConfig *glconfig) {
|
||||||
GtkWidget *window, *hPaned, *vbox, *table, *vScroll, *hScroll, *sidebar;
|
GtkWidget *window, *hPaned, *vbox, *table, *vScroll, *hScroll, *sidebar;
|
||||||
GdkColor color = {0, 0, 0, 0};
|
|
||||||
|
|
||||||
|
|
||||||
window = gtk_window_new(GTK_WINDOW_TOPLEVEL);
|
window = gtk_window_new(GTK_WINDOW_TOPLEVEL);
|
||||||
|
|
Reference in a new issue