Mariusz Muszyński 8 vuotta sitten
vanhempi
commit
bbc4d937c9
2 muutettua tiedostoa jossa 25 lisäystä ja 14 poistoa
  1. 1 3
      SE/se-lib/Geometry.php
  2. 24 11
      SE/se-lib/Route/ViewTableAjax.php

+ 1 - 3
SE/se-lib/Geometry.php

@@ -219,9 +219,7 @@ class Geometry {
 		switch (get_class($p)) {
 			case 'GeometryPoint':
 				if (self::distance($p, $A) == 0 && self::distance($p, $B) == 0) return [$p];
-//				if ($p->x >= min($A->a->x, $A->b->x) && $p->x <= max($A->a->x, $A->b->x) && $p->y >= min($A->a->y, $A->b->y) && $p->y <= max($A->a->y, $A->b->y) &&
-//					$p->x >= min($B->a->x, $B->b->x) && $p->x <= max($B->a->x, $B->b->x) && $p->y >= min($B->a->y, $B->b->y) && $p->y <= max($B->a->y, $B->b->y)) return [$p];
-				break;
+				return null;
 			case 'GeometryLinearFunction':
 				if ($A->a->x > $A->b->x) {
 					$tmp = $A->a; $A->a = $A->b; $A->b = $tmp;

+ 24 - 11
SE/se-lib/Route/ViewTableAjax.php

@@ -668,7 +668,7 @@ class Route_ViewTableAjax extends RouteBase {
 
 			$ki = 1;
 			$lastNear = null;
-			$mergedNears = [];
+			$nearsOnLine = [];
 			foreach ($nears as $near) {
 				if ($crossPoints = Geometry::crossPoint($line, $near)) {
 					switch (count($crossPoints)) {
@@ -682,20 +682,32 @@ class Route_ViewTableAjax extends RouteBase {
 						default:
 							throw new Exception(__CLASS__ . "::" . __FUNCTION__ . ' - unknown error');
 					}
+				} else $crossPoints = [];
+
+				$nearOnLine = Geometry::line(Geometry::closedPointOnLine($near->a, $line), Geometry::closedPointOnLine($near->b, $line));
+
+				if ($nearOnLine->length() < 1) {
+					$break = false;
+					foreach ($crossPoints as $crossPoint) {
+						if (Geometry::distance($crossPoint, $nearOnLine) == 0) {
+							$break = true;
+							break;
+						}
+					}
+					if ($break) continue;
 				}
-				if ($lastNear) {
-					if (Geometry::samePoint($lastNear->b, $near->a)) $lastNear->b = $near->b;
-					else $mergedNears[] = $lastNear;
+
+				if ($lastNearOnLine) {
+					if (Geometry::distance($lastNearOnLine->b, $nearOnLine->a) < 1) $lastNearOnLine->b = $nearOnLine->b;
+					else $nearsOnLine[] = $lastNearOnLine;
 				}
-				$lastNear = $near;
+				$lastNearOnLine = $nearOnLine;
 			}
-			if ($lastNear) $mergedNears[] = $lastNear;
+			if ($lastNearOnLine) $nearsOnLine[] = $lastNearOnLine;
 
-			foreach ($mergedNears as $near) {
-				$a = Geometry::closedPointOnLine($near->a, $line);
-				$b = Geometry::closedPointOnLine($near->b, $line);
-				$array[] = ['i' => ($i - 1) . '.k' . $ki . 'a', 'x' => $a->x, 'y' => $a->y, 'desc' => 'Kolizja (II) start'];
-				$array[] = ['i' => ($i - 1) . '.k' . $ki++ . 'b', 'x' => $b->x, 'y' => $b->y, 'desc' => 'Kolizja (II) stop'];
+			foreach ($nearsOnLine as $nearOnLine) {
+				$array[] = ['i' => ($i - 1) . '.k' . $ki . 'a', 'x' => $nearOnLine->a->x, 'y' => $nearOnLine->a->y, 'desc' => 'Kolizja (II) start'];
+				$array[] = ['i' => ($i - 1) . '.k' . $ki++ . 'b', 'x' => $nearOnLine->b->x, 'y' => $nearOnLine->b->y, 'desc' => 'Kolizja (II) stop'];
 			}
 
 			if (($distance = $line->length()) > $minDistance) {
@@ -720,6 +732,7 @@ class Route_ViewTableAjax extends RouteBase {
 			return $item['i'] . "," . round($item['y'], 3) . "," . round($item['x'], 3) . "," . round($z, 3) . "," . $item['desc'];
 		}, $array));
 
+//		echo "<pre>{$csv}</pre>";
 		Response::sendCsv($csv, "{$table}.{$id}");
 	}