Commit 97224254 authored by sumpfralle's avatar sumpfralle

unify function names for "inside" tests


git-svn-id: https://pycam.svn.sourceforge.net/svnroot/pycam/trunk@693 bbaffbd6-741e-11dd-a85d-61de82d9cad9
parent 8377faba
...@@ -123,7 +123,7 @@ class BaseCutter(object): ...@@ -123,7 +123,7 @@ class BaseCutter(object):
def intersect_circle_triangle(self, direction, triangle): def intersect_circle_triangle(self, direction, triangle):
(cl, ccp, cp, d) = self.intersect_circle_plane(direction, triangle) (cl, ccp, cp, d) = self.intersect_circle_plane(direction, triangle)
if cp and triangle.point_inside(cp): if cp and triangle.is_point_inside(cp):
return (cl, d, cp) return (cl, d, cp)
return (None, INFINITE, None) return (None, INFINITE, None)
......
...@@ -152,7 +152,7 @@ class SphericalCutter(BaseCutter): ...@@ -152,7 +152,7 @@ class SphericalCutter(BaseCutter):
def intersect_sphere_triangle(self, direction, triangle): def intersect_sphere_triangle(self, direction, triangle):
(cl, ccp, cp, d) = self.intersect_sphere_plane(direction, triangle) (cl, ccp, cp, d) = self.intersect_sphere_plane(direction, triangle)
if cp and triangle.point_inside(cp): if cp and triangle.is_point_inside(cp):
return (cl, d, cp) return (cl, d, cp)
return (None, INFINITE, None) return (None, INFINITE, None)
......
...@@ -126,7 +126,7 @@ class ToroidalCutter(BaseCutter): ...@@ -126,7 +126,7 @@ class ToroidalCutter(BaseCutter):
def intersect_torus_triangle(self, direction, triangle): def intersect_torus_triangle(self, direction, triangle):
(cl, ccp, cp, d) = self.intersect_torus_plane(direction, triangle) (cl, ccp, cp, d) = self.intersect_torus_plane(direction, triangle)
if cp and triangle.point_inside(cp): if cp and triangle.is_point_inside(cp):
return (cl, d, cp) return (cl, d, cp)
return (None, INFINITE, None) return (None, INFINITE, None)
......
...@@ -83,6 +83,9 @@ class Line(TransformableContainer): ...@@ -83,6 +83,9 @@ class Line(TransformableContainer):
self.maxy = max(self.p1.y, self.p2.y) self.maxy = max(self.p1.y, self.p2.y)
self.maxz = max(self.p1.z, self.p2.z) self.maxz = max(self.p1.z, self.p2.z)
def get_points(self):
return (self.p1, self.p2)
def point_with_length_multiply(self, l): def point_with_length_multiply(self, l):
return self.p1.add(self.dir.mul(l*self.len)) return self.p1.add(self.dir.mul(l*self.len))
...@@ -102,7 +105,10 @@ class Line(TransformableContainer): ...@@ -102,7 +105,10 @@ class Line(TransformableContainer):
def dist_to_point(self, p): def dist_to_point(self, p):
return sqrt(self.dist_to_point_sq(p)) return sqrt(self.dist_to_point_sq(p))
def is_point_in_line(self, p): def is_point_inside(self, p):
if (p == self.p1) or (p == self.p2):
# these conditions are not covered by the code below
return True
dir1 = p.sub(self.p1).normalized() dir1 = p.sub(self.p1).normalized()
dir2 = self.p2.sub(p).normalized() dir2 = self.p2.sub(p).normalized()
# True if the two parts of the line have the same direction or if the # True if the two parts of the line have the same direction or if the
...@@ -162,13 +168,13 @@ class Line(TransformableContainer): ...@@ -162,13 +168,13 @@ class Line(TransformableContainer):
return None, None return None, None
# the lines are on one straight # the lines are on one straight
candidates = [] candidates = []
if self.is_point_in_line(x3): if self.is_point_inside(x3):
candidates.append((x3, c.norm / a.norm)) candidates.append((x3, c.norm / a.norm))
elif self.is_point_in_line(x4): elif self.is_point_inside(x4):
candidates.append((x4, line.p2.sub(self.p1).norm / a.norm)) candidates.append((x4, line.p2.sub(self.p1).norm / a.norm))
elif line.is_point_in_line(x1): elif line.is_point_inside(x1):
candidates.append((x1, 0)) candidates.append((x1, 0))
elif line.is_point_in_line(x2): elif line.is_point_inside(x2):
candidates.append((x2, 1)) candidates.append((x2, 1))
else: else:
return None, None return None, None
......
...@@ -196,7 +196,7 @@ class Polygon(TransformableContainer): ...@@ -196,7 +196,7 @@ class Polygon(TransformableContainer):
def is_point_on_outline(self, p): def is_point_on_outline(self, p):
for line in self.get_lines(): for line in self.get_lines():
if line.is_point_in_line(p): if line.is_point_inside(p):
return True return True
return False return False
...@@ -761,7 +761,7 @@ class Polygon(TransformableContainer): ...@@ -761,7 +761,7 @@ class Polygon(TransformableContainer):
line1 = lines[-1] line1 = lines[-1]
line2 = lines[0] line2 = lines[0]
if (line1.dir == line2.dir) \ if (line1.dir == line2.dir) \
and (line1.is_point_in_line(line2.p1)): and (line1.is_point_inside(line2.p1)):
# remove the last point and define the polygon as closed # remove the last point and define the polygon as closed
poly._points.pop(-1) poly._points.pop(-1)
poly._is_closed = True poly._is_closed = True
......
...@@ -97,6 +97,9 @@ class Triangle(TransformableContainer): ...@@ -97,6 +97,9 @@ class Triangle(TransformableContainer):
yield self.e3 yield self.e3
yield self.normal yield self.normal
def get_points(self):
return (self.p1, self.p2, self.p3)
def get_children_count(self): def get_children_count(self):
# tree points per triangle # tree points per triangle
return 7 return 7
...@@ -143,11 +146,12 @@ class Triangle(TransformableContainer): ...@@ -143,11 +146,12 @@ class Triangle(TransformableContainer):
GL.glTranslatef(n.x, n.y, n.z) GL.glTranslatef(n.x, n.y, n.z)
GL.glScalef(0.003, 0.003, 0.003) GL.glScalef(0.003, 0.003, 0.003)
w = 0 w = 0
for ch in str(self.id): id_string = "%s." % str(self.id)
for ch in id_string:
w += GLUT.glutStrokeWidth(GLUT.GLUT_STROKE_ROMAN, ord(ch)) w += GLUT.glutStrokeWidth(GLUT.GLUT_STROKE_ROMAN, ord(ch))
GL.glTranslate(-w/2, 0, 0) GL.glTranslate(-w/2, 0, 0)
GL.glColor4f(1, 1, 1, 1) GL.glColor4f(1, 1, 1, 1)
for ch in str(self.id): for ch in id_string:
GLUT.glutStrokeCharacter(GLUT.GLUT_STROKE_ROMAN, ord(ch)) GLUT.glutStrokeCharacter(GLUT.GLUT_STROKE_ROMAN, ord(ch))
GL.glPopMatrix() GL.glPopMatrix()
GL.glColor4f(cc[0], cc[1], cc[2], cc[3]) GL.glColor4f(cc[0], cc[1], cc[2], cc[3])
...@@ -177,7 +181,7 @@ class Triangle(TransformableContainer): ...@@ -177,7 +181,7 @@ class Triangle(TransformableContainer):
GL.glPopMatrix() GL.glPopMatrix()
GL.glColor4f(cc[0], cc[1], cc[2], cc[3]) GL.glColor4f(cc[0], cc[1], cc[2], cc[3])
def point_inside(self, p): def is_point_inside(self, p):
# http://www.blackpawn.com/texts/pointinpoly/default.html # http://www.blackpawn.com/texts/pointinpoly/default.html
# Compute vectors # Compute vectors
v0 = self.p3.sub(self.p1) v0 = self.p3.sub(self.p1)
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment