修正单元测试失败代码

This commit is contained in:
2026-05-25 17:51:45 +08:00
parent 2317f4d527
commit 88be97ddeb
6 changed files with 171 additions and 160 deletions
+10 -30
View File
@@ -1,8 +1,8 @@
import ctypes
import platform
import os
import math
from typing import Any
import pyclipper
from .s0_base import get_node_links, get_link_nodes, is_pipe
from .s5_pipes import get_pipe
from .database import read, try_read, read_all, write
@@ -414,40 +414,20 @@ def inflate_boundary(name: str, boundary: list[tuple[float, float]], delta: floa
if boundary[0] == boundary[-1]:
del(boundary[-1])
lib = ctypes.CDLL(os.path.join(os.getcwd(), 'api', 'CClipper2.dll'))
precision = 2
scale = 10 ** precision
path = [(round(x * scale), round(y * scale)) for x, y in boundary]
c_size = ctypes.c_size_t(len(boundary) * 2)
c_path = (ctypes.c_double * c_size.value)()
i = 0
for xy in boundary:
c_path[i] = xy[0]
i += 1
c_path[i] = xy[1]
i += 1
c_delta = ctypes.c_double(delta)
JoinType_Square, JoinType_Round, JoinType_Miter = 0, 1, 2
c_jt = ctypes.c_int(JoinType_Square)
EndType_Polygon, EndType_Joined, EndType_Butt, EndType_Square, EndType_Round = 0, 1, 2, 3, 4
c_et = ctypes.c_int(EndType_Polygon)
c_miter_limit = ctypes.c_double(2.0)
c_precision = ctypes.c_int(2)
c_arc_tolerance = ctypes.c_double(0.0)
c_out_path = ctypes.POINTER(ctypes.c_double)()
c_out_size = ctypes.c_size_t(0)
lib.inflate_paths(c_path, c_size, c_delta, c_jt, c_et, c_miter_limit, c_precision, c_arc_tolerance, ctypes.byref(c_out_path), ctypes.byref(c_out_size))
if c_out_size.value == 0:
lib.free_paths(ctypes.byref(c_out_path))
offset = pyclipper.PyclipperOffset(miter_limit=2.0)
offset.AddPath(path, pyclipper.JT_SQUARE, pyclipper.ET_CLOSEDPOLYGON)
solutions = offset.Execute(round(delta * scale))
if len(solutions) == 0:
return []
# TODO: simplify_paths :)
result: list[tuple[float, float]] = []
for i in range(0, c_out_size.value, 2):
result.append((c_out_path[i], c_out_path[i + 1]))
for x, y in solutions[0]:
result.append((x / scale, y / scale))
result.append(result[0])
lib.free_paths(ctypes.byref(c_out_path))
return result