summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--Line.cpp45
-rw-r--r--Polygon.cpp20
-rw-r--r--Triangle.cpp4
-rw-r--r--edit.cpp2
-rw-r--r--window.cpp27
5 files changed, 55 insertions, 43 deletions
diff --git a/Line.cpp b/Line.cpp
index 463a6ab..aa7bcad 100644
--- a/Line.cpp
+++ b/Line.cpp
@@ -3,31 +3,31 @@
bool Line::contains(const Vertex &v) const {
- if(fabs(v1.getX() - v2.getX()) < 1E-6 && fabs(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() - v2.getX()) < 1E-6 && fabsf(v1.getY() - v2.getY()) < 1E-6) {
+ if(fabsf(v1.getX() - v.getX()) < 1E-6 && fabsf(v1.getY() - v.getY()) < 1E-6)
return true;
else
return false;
}
- if(fabs(v1.getX() - v2.getX()) < 1E-6) {
- if(fabs(v1.getX() - v.getX()) >= 1E-6)
+ if(fabsf(v1.getX() - v2.getX()) < 1E-6) {
+ if(fabsf(v1.getX() - v.getX()) >= 1E-6)
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;
else
return false;
}
- if(fabs(v1.getY() - v2.getY()) < 1E-6) {
- if(fabs(v1.getY() - v.getY()) >= 1E-6)
+ if(fabsf(v1.getY() - v2.getY()) < 1E-6) {
+ if(fabsf(v1.getY() - v.getY()) >= 1E-6)
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;
else
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;
else
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 xb2 = l.v2.getX(), yb2 = l.v2.getY();
float temp;
- int switched = 0;
+ bool switched = false;
Vertex v2;
if(!v) v = &v2;
- if(fabs(xa1 - xa2) < 1E-6 && fabs(ya1 - ya2) < 1E-6) return INTERSECTION_ERROR;
- if(fabs(xb1 - xb2) < 1E-6 && fabs(yb1 - yb2) < 1E-6) return INTERSECTION_ERROR;
+ if(fabsf(xa1 - xa2) < 1E-6 && fabsf(ya1 - ya2) < 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 = xa2; xa2 = ya2; ya2 = temp;
temp = xb1; xb1 = yb1; yb1 = temp;
temp = xb2; xb2 = yb2; yb2 = temp;
- switched = 1;
+ switched = true;
}
- if(fabs(xa1 - xa2) < 1E-6 && fabs(xb1 - xb2) < 1E-6)
- return (fabs(xa1 - xb1) < 1E-6) ? INTERSECTION_IDENTICAL : INTERSECTION_NONE;
+ if(fabsf(xa1 - xa2) < 1E-6 && fabsf(xb1 - xb2) < 1E-6)
+ 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->setY(yb1);
}
- else if(fabs(xb1 - xb2) < 1E-6) {
+ else if(fabsf(xb1 - xb2) < 1E-6) {
v->setX(xb1);
v->setY(ya1);
}
@@ -74,7 +74,7 @@ int Line::intersects(const Line &l, Vertex *v) const {
float ba = ya1 - ma*xa1;
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->setY(ma*v->getX() + ba);
@@ -90,14 +90,15 @@ int Line::intersects(const Line &l, Vertex *v) const {
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() < fmin(xb1,xb2) || v->getX() > fmax(xb1, xb2) || v->getY() < fmin(yb1,yb2) || v->getY() > fmax(yb1, yb2))
+ if(v->getX() < fminf(xa1,xa2) || v->getX() > fmaxf(xa1, xa2) || v->getY() < fminf(ya1,ya2) || v->getY() > fmaxf(ya1, ya2)) {
+ 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;
else
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;
else
return INTERSECTION_SEGMENT_SEGMENT;
}
+
diff --git a/Polygon.cpp b/Polygon.cpp
index eb63a61..7eaeaa9 100644
--- a/Polygon.cpp
+++ b/Polygon.cpp
@@ -24,7 +24,7 @@ Polygon::Direction Polygon::getDirection() const {
}
float Polygon::area() const {
- return fabs(signedArea());
+ return fabsf(signedArea());
}
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());
case Triangle::CCW:
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 {
@@ -180,10 +180,10 @@ bool Polygon::simplify(std::list<Polygon> &polygons) const {
if(!intersections(&ins)) return false;
- int s = size();
- int start = 0;
+ size_t s = size();
+ 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())
start = i;
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 i2 = start;
+ size_t i2 = start;
const Vertex *v2 = &at(i2);
bool intersected;
@@ -201,7 +201,7 @@ bool Polygon::simplify(std::list<Polygon> &polygons) const {
do {
intersected = false;
- int i = i2;
+ size_t i = i2;
if(dir == Triangle::CW)
i2 = (i2+1)%s;
@@ -216,7 +216,7 @@ bool Polygon::simplify(std::list<Polygon> &polygons) const {
Intersection *intr = NULL;
Vertex *v = NULL;
float dv = 0;
- int v3, v4;
+ size_t v3 = 0, v4 = 0;
for(std::vector<Intersection>::iterator in = ins.begin(); in != ins.end(); ++in) {
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.front().pop_back();
- if(v->distanceSq(polygons.back().back()) < 1E-6)
+ if(v->distanceSq(polygons.back().back()) < 1E-12)
break;
}
}
diff --git a/Triangle.cpp b/Triangle.cpp
index 30bceb7..124d16c 100644
--- a/Triangle.cpp
+++ b/Triangle.cpp
@@ -32,9 +32,9 @@ bool Triangle::contains(const Vertex &v) const {
return ((a < 1E-6) && (b < 1E-6) && (c < 1E-6));
case CCW:
return ((a > -1E-6) && (b > -1E-6) && (c > -1E-6));
+ default:
+ return false;
}
-
- return false;
}
bool Triangle::onEdge(const Vertex &v) const {
diff --git a/edit.cpp b/edit.cpp
index 3023dc5..7d18186 100644
--- a/edit.cpp
+++ b/edit.cpp
@@ -86,7 +86,7 @@ static bool isLineOk(Line *l) {
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.setVertex2(activeRoom->at(i+1));
diff --git a/window.cpp b/window.cpp
index 881a96f..1deff6d 100644
--- a/window.cpp
+++ b/window.cpp
@@ -124,9 +124,12 @@ static gboolean scrollEvent(GtkWidget *widget, GdkEventScroll *event, gpointer u
switch(event->direction) {
case GDK_SCROLL_UP:
zoomIn(1.1f, x, y);
- break;
+ return TRUE;
case GDK_SCROLL_DOWN:
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);
}
+
+ return TRUE;
+ default:
+ return FALSE;
}
-
- return FALSE;
}
gboolean crossingNotifyEvent(GtkWidget *widget, GdkEventCrossing *event, gpointer user_data) {
@@ -170,13 +175,18 @@ gboolean crossingNotifyEvent(GtkWidget *widget, GdkEventCrossing *event, gpointe
setHoveredVertex(&v);
- break;
+ gtk_widget_queue_draw(drawingArea);
+
+ return TRUE;
case GDK_LEAVE_NOTIFY:
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) {
@@ -189,6 +199,8 @@ gboolean motionNotifyEvent(GtkWidget *widget, GdkEventMotion *event, gpointer us
if(getHoveredRoom() != last || getEditMode() == EDIT_MODE_ADD)
gtk_widget_queue_draw(drawingArea);
+
+ return TRUE;
}
static void destroy(GtkWidget *widget, gpointer data) {
@@ -290,7 +302,6 @@ static GtkWidget* createSidebar() {
GtkWidget* createMainWindow(GdkGLConfig *glconfig) {
GtkWidget *window, *hPaned, *vbox, *table, *vScroll, *hScroll, *sidebar;
- GdkColor color = {0, 0, 0, 0};
window = gtk_window_new(GTK_WINDOW_TOPLEVEL);