# HG changeset patch # User Matti Hamalainen # Date 1412549201 -10800 # Node ID f099a7e4fa2e85079fa9d7e8b37ef09ed1b1802a # Parent baa6877ed0d3e970cf2a1eaa3c0a8856ee907caa Modularize slightly. diff -r baa6877ed0d3 -r f099a7e4fa2e src/objects.cc --- a/src/objects.cc Mon Oct 06 01:39:56 2014 +0300 +++ b/src/objects.cc Mon Oct 06 01:46:41 2014 +0300 @@ -40,6 +40,16 @@ #include "things.h" + +static void GetLDCoords(const int ld, int *xc, int *yc, int *dx, int *dy) +{ + *xc = Vertices[LineDefs[ld].start].x; + *yc = Vertices[LineDefs[ld].start].y; + *dx = Vertices[LineDefs[ld].end].x - *xc; + *dy = Vertices[LineDefs[ld].end].y - *yc; +} + + /* highlight the selected objects */ @@ -640,11 +650,8 @@ int ld2, dist; int bestld, bestdist, bestmdist; - x0 = Vertices[LineDefs[ld1].start].x; - y0 = Vertices[LineDefs[ld1].start].y; - dx0 = Vertices[LineDefs[ld1].end].x - x0; - dy0 = Vertices[LineDefs[ld1].end].y - y0; /* get the coords for this LineDef */ + GetLDCoords(ld1, &x0, &y0, &dx0, &dy0); /* find the normal vector for this LineDef */ x1 = (dx0 + x0 + x0) / 2; @@ -674,10 +681,7 @@ if (ld2 != ld1 && ((Vertices[LineDefs[ld2].start].x > x1) != (Vertices[LineDefs[ld2].end].x > x1))) { - x2 = Vertices[LineDefs[ld2].start].x; - y2 = Vertices[LineDefs[ld2].start].y; - dx2 = Vertices[LineDefs[ld2].end].x - x2; - dy2 = Vertices[LineDefs[ld2].end].y - y2; + GetLDCoords(ld2, &x2, &y2, &dx2, &dy2); dist = y2 + (int) ((x1 - x2) * dy2 / dx2); if (dist > y1 && (dist < bestdist || (dist == bestdist && (y2 + dy2 / 2) < bestmdist))) { @@ -696,10 +700,7 @@ if (ld2 != ld1 && ((Vertices[LineDefs[ld2].start].x > x1) != (Vertices[LineDefs[ld2].end].x > x1))) { - x2 = Vertices[LineDefs[ld2].start].x; - y2 = Vertices[LineDefs[ld2].start].y; - dx2 = Vertices[LineDefs[ld2].end].x - x2; - dy2 = Vertices[LineDefs[ld2].end].y - y2; + GetLDCoords(ld2, &x2, &y2, &dx2, &dy2); dist = y2 + (int) ((x1 - x2) * dy2 / dx2); if (dist < y1 && (dist > bestdist || (dist == bestdist && (y2 + dy2 / 2) > bestmdist))) { @@ -721,10 +722,7 @@ if (ld2 != ld1 && ((Vertices[LineDefs[ld2].start].y > y1) != (Vertices[LineDefs[ld2].end].y > y1))) { - x2 = Vertices[LineDefs[ld2].start].x; - y2 = Vertices[LineDefs[ld2].start].y; - dx2 = Vertices[LineDefs[ld2].end].x - x2; - dy2 = Vertices[LineDefs[ld2].end].y - y2; + GetLDCoords(ld2, &x2, &y2, &dx2, &dy2); dist = x2 + (int) ((y1 - y2) * dx2 / dy2); if (dist > x1 && (dist < bestdist || (dist == bestdist && (x2 + dx2 / 2) < bestmdist))) { @@ -743,10 +741,7 @@ if (ld2 != ld1 && ((Vertices[LineDefs[ld2].start].y > y1) != (Vertices[LineDefs[ld2].end].y > y1))) { - x2 = Vertices[LineDefs[ld2].start].x; - y2 = Vertices[LineDefs[ld2].start].y; - dx2 = Vertices[LineDefs[ld2].end].x - x2; - dy2 = Vertices[LineDefs[ld2].end].y - y2; + GetLDCoords(ld2, &x2, &y2, &dx2, &dy2); dist = x2 + (int) ((y1 - y2) * dx2 / dy2); if (dist < x1 && (dist > bestdist || (dist == bestdist && (x2 + dx2 / 2) > bestmdist))) {