set_koords.py: manuelle Abstandsformeln durch math.dist ersetzt
Die wiederholten (dx**2 + dy**2 [+ dz**2]) ** 0.5-Formeln fuer den euklidischen Abstand zweier Punkte (K1-K4-Positionsbestimmung fuer Boegen/Weichen/Weichenkoerper) sind jetzt math.dist(p1, p2) - gleiches Ergebnis, aber weniger Code und keine Gefahr, beim manuellen Quadrieren ein Vorzeichen/Exponenten zu vertippen. Co-Authored-By: Claude Sonnet 5 <noreply@anthropic.com>
This commit is contained in:
+12
-12
@@ -154,7 +154,7 @@ def read_ks(doc, name):
|
||||
dx = end[0] - point[0]
|
||||
dy = end[1] - point[1]
|
||||
dz = end[2] - point[2]
|
||||
length = (dx**2 + dy**2 + dz**2) ** 0.5
|
||||
length = math.dist(point, (end[0], end[1], end[2]))
|
||||
axes[line.dxf.color] = (dx / length, dy / length, dz / length)
|
||||
|
||||
x_axis = axes.get(1, (1, 0, 0))
|
||||
@@ -355,11 +355,11 @@ def k2_point_bogen(doc):
|
||||
continue
|
||||
s = (e.dxf.start[0], e.dxf.start[1])
|
||||
end = (e.dxf.end[0], e.dxf.end[1])
|
||||
ds = ((s[0] - k2_junction[0])**2 + (s[1] - k2_junction[1])**2) ** 0.5
|
||||
de = ((end[0] - k2_junction[0])**2 + (end[1] - k2_junction[1])**2) ** 0.5
|
||||
ds = math.dist(s, k2_junction)
|
||||
de = math.dist(end, k2_junction)
|
||||
if ds > tol and de > tol:
|
||||
continue
|
||||
ln = ((end[0] - s[0])**2 + (end[1] - s[1])**2) ** 0.5
|
||||
ln = math.dist(end, s)
|
||||
if ln > best_line_len:
|
||||
best_line_len = ln
|
||||
if ds < tol:
|
||||
@@ -428,8 +428,8 @@ def _find_weiche_arc_branches(doc):
|
||||
cy + r * math.sin(math.radians(ea)))
|
||||
|
||||
# K1-Seite = naeher an K1
|
||||
d_start = ((arc_start[0] - k1_x)**2 + (arc_start[1] - k1_y)**2) ** 0.5
|
||||
d_end = ((arc_end[0] - k1_x)**2 + (arc_end[1] - k1_y)**2) ** 0.5
|
||||
d_start = math.dist(arc_start, (k1_x, k1_y))
|
||||
d_end = math.dist(arc_end, (k1_x, k1_y))
|
||||
|
||||
if d_start < d_end:
|
||||
k2_junction = arc_end
|
||||
@@ -445,11 +445,11 @@ def _find_weiche_arc_branches(doc):
|
||||
continue
|
||||
ls = (ent.dxf.start[0], ent.dxf.start[1])
|
||||
le = (ent.dxf.end[0], ent.dxf.end[1])
|
||||
ds = ((ls[0] - k2_junction[0])**2 + (ls[1] - k2_junction[1])**2) ** 0.5
|
||||
de = ((le[0] - k2_junction[0])**2 + (le[1] - k2_junction[1])**2) ** 0.5
|
||||
ds = math.dist(ls, k2_junction)
|
||||
de = math.dist(le, k2_junction)
|
||||
if ds > tol and de > tol:
|
||||
continue
|
||||
ln = ((le[0] - ls[0])**2 + (le[1] - ls[1])**2) ** 0.5
|
||||
ln = math.dist(le, ls)
|
||||
if ln > best_len:
|
||||
best_len = ln
|
||||
if ds < tol:
|
||||
@@ -541,13 +541,13 @@ def _find_weichenkoerper_diag_branches(doc):
|
||||
dy = abs(le[1] - ls[1])
|
||||
if dx < 0.01 or dy < 0.01:
|
||||
continue
|
||||
ln = (dx**2 + dy**2) ** 0.5
|
||||
ln = math.dist(ls, le)
|
||||
if ln < 100:
|
||||
continue
|
||||
|
||||
# Das Ende naeher an K1 ist die Junction, das andere ist der K2/K3-Punkt
|
||||
d_start = ((ls[0] - k1_x)**2 + (ls[1] - k1_y)**2) ** 0.5
|
||||
d_end = ((le[0] - k1_x)**2 + (le[1] - k1_y)**2) ** 0.5
|
||||
d_start = math.dist(ls, (k1_x, k1_y))
|
||||
d_end = math.dist(le, (k1_x, k1_y))
|
||||
if d_start < d_end:
|
||||
candidates.append((le, ls))
|
||||
else:
|
||||
|
||||
Reference in New Issue
Block a user