changeset 95:f099a7e4fa2e

Modularize slightly.
author Matti Hamalainen <ccr@tnsp.org>
date Mon, 06 Oct 2014 01:46:41 +0300
parents baa6877ed0d3
children 091ec1d89876
files src/objects.cc
diffstat 1 files changed, 15 insertions(+), 20 deletions(-) [+]
line wrap: on
line diff
--- 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)))
                     {