fix bugs that fail judgement of path's containment
This commit is contained in:
parent
244fcaa534
commit
ca23fbd953
8 changed files with 9021 additions and 14 deletions
|
|
@ -51,12 +51,13 @@ def _intersections_of_line_and_circle(start, end, center, radius, error_range):
|
|||
dr = sqrt(dx * dx + dy * dy)
|
||||
D = x1 * y2 - x2 * y1
|
||||
|
||||
distance = abs(dy * x1 - dx * y1) / dr
|
||||
|
||||
D2 = D * D
|
||||
dr2 = dr * dr
|
||||
r2 = radius * radius
|
||||
delta = r2 * dr2 - D2
|
||||
e4 = error_range * error_range * error_range * error_range * 10
|
||||
if delta > - e4 and delta < e4:
|
||||
if distance > radius - error_range and distance < radius + error_range:
|
||||
delta = 0
|
||||
if delta < 0:
|
||||
return None
|
||||
|
|
@ -198,7 +199,7 @@ class DxfLineStatement(DxfStatement):
|
|||
denominator = (self.end[0] - self.start[0]) * (point_to[1] - point_from[1]) - \
|
||||
(self.end[1] - self.start[1]) * (point_to[0] - point_from[0])
|
||||
de = error_range * error_range
|
||||
if denominator > -de and denominator < de:
|
||||
if denominator >= -de and denominator <= de:
|
||||
return []
|
||||
from_dx = point_from[0] - self.start[0]
|
||||
from_dy = point_from[1] - self.start[1]
|
||||
|
|
@ -356,16 +357,25 @@ class DxfArcStatement(DxfStatement):
|
|||
elif p2 is not None and is_equal_point(p2, self.start, error_range):
|
||||
p2 = None
|
||||
|
||||
def is_contained(angle, region, error):
|
||||
if angle >= region[0] - error and angle <= region[1] + error:
|
||||
return True
|
||||
if angle < 0 and region[1] > 0:
|
||||
angle = angle + 2 * pi
|
||||
elif angle > 0 and region[0] < 0:
|
||||
angle = angle - 2 * pi
|
||||
return angle >= region[0] - error and angle <= region[1] + error
|
||||
|
||||
aerror = error_range * self.radius
|
||||
pts = []
|
||||
if p1 is not None and p1_t >= 0 and not is_equal_point(p1, self.start, error_range):
|
||||
for region in self.angle_regions:
|
||||
if p1_angle >= region[0] - aerror and p1_angle <= region[1] + aerror:
|
||||
if is_contained(p1_angle, region, aerror):
|
||||
pts.append(p1)
|
||||
break
|
||||
if p2 is not None and p2_t >= 0 and not is_equal_point(p2, self.start, error_range):
|
||||
for region in self.angle_regions:
|
||||
if p2_angle >= region[0] - aerror and p2_angle <= region[1] + aerror:
|
||||
if is_contained(p2_angle, region, aerror):
|
||||
pts.append(p2)
|
||||
break
|
||||
|
||||
|
|
|
|||
|
|
@ -301,7 +301,7 @@ class DxfPath(object):
|
|||
|
||||
def _judge_cross(self, from_pt, to_pt, index, error_range):
|
||||
standard = normalize_vec2d((to_pt[0] - from_pt[0], to_pt[1] - from_pt[1]))
|
||||
normal = (standard[1], standard[0])
|
||||
normal = (standard[1], -standard[0])
|
||||
def statements():
|
||||
for i in range(index, len(self.statements)):
|
||||
yield self.statements[i]
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue