def sortTriangles(self, left, right): i = 0 j = 0 z = 0.0 if right > left: z = u3dsupport.KfTriangle(self.triangles.Items[right]).zForSorting i = left - 1 j = right while true: while 1: i = i + 1 if not (u3dsupport.KfTriangle( self.triangles.Items[i]).zForSorting < z): break while 1: j = j - 1 if (j < i) or (not (u3dsupport.KfTriangle( self.triangles.Items[j]).zForSorting > z)): break if i >= j: break self.triangles.Exchange(i, j) self.triangles.Exchange(i, right) self.sortTriangles(left, j) self.sortTriangles(i + 1, right)
def newTriangleTriangle(self, aPointIndex, bPointIndex, cPointIndex): result = u3dsupport.KfTriangle() # PDF MAYBE WANT TO COPY? result.points[0] = self.recordedPoints[aPointIndex] result.points[1] = self.recordedPoints[bPointIndex] result.points[2] = self.recordedPoints[cPointIndex] return result
def plantPartIDForPoint(self, point): result = 0L i = 0L triangle = KfTriangle() points = [0] * (range(0, 2 + 1) + 1) widenedPoints = [0] * (range(0, 2 + 1) + 1) width = 0 thisDistance = 0.0 closestDistanceSoFar = 0.0 closestPartID = 0L centerX = 0.0 centerY = 0.0 x = 0.0 y = 0.0 x = Point.x y = Point.y result = -1 closestDistanceSoFar = 0 closestPartID = -1 for i in range(0, self.triangles.Count): triangle = u3dsupport.KfTriangle(self.triangles.Items[i]) if triangle.isLine: centerX = (triangle.points[0].x + triangle.points[1].x) / 2.0 centerY = (triangle.points[0].y + triangle.points[1].y) / 2.0 thisDistance = (centerX - x) * (centerX - x) + ( centerY - y) * (centerY - y) if (closestPartID == -1) or (thisDistance < closestDistanceSoFar): closestDistanceSoFar = thisDistance closestPartID = triangle.plantPartID else: points[0].X = intround(triangle.points[0].x) points[0].Y = intround(triangle.points[0].y) points[1].X = intround(triangle.points[1].x) points[1].Y = intround(triangle.points[1].y) points[2].X = intround(triangle.points[2].x) points[2].Y = intround(triangle.points[2].y) if u3dsupport.pointInTriangle(Point, points): result = triangle.plantPartID return result result = closestPartID return result
def __init__(self): self.drawingContext = None self.lineContrastIndex = 0 self.drawingLines = False self.circlingPoints = False self.foreColor = delphi_compatability.EmptyColor self.backColor = delphi_compatability.EmptyColor self.lineColor = delphi_compatability.EmptyColor self.circleColor = delphi_compatability.EmptyColor self.triangles = [] self.recording = False self.lineWidth = 0.0 self.circlePointRadius = 0 self.sortTdosAsOneItem = False self.triangles = [] self.fillingTriangles = True self.initialize() # start with a bunch of triangles for i in range(0, kInitialDrawingSurfaceTriangles + 1): self.triangles.append(u3dsupport.KfTriangle())
def sortTrianglesConsideringTdos(self): i = 0L triangle = KfTriangle() oldValue = 0.0 if self.numTrianglesUsed <= 1: return if self.sortTdosAsOneItem: for i in range(0, self.numTrianglesUsed): triangle = u3dsupport.KfTriangle(self.triangles.Items[i]) if not triangle.isLine: oldValue = triangle.zForSorting if triangle.tdo != None: try: # the 0.01 is to keep the polygons inside the tdo in order but still (usually) separate from other tdos # could produce errors if the z value is really small already triangle.zForSorting = triangle.tdo.zForSorting + triangle.zForSorting * 0.01 except: triangle.zForSorting = oldValue # have to clear out tdo pointer afterward because triangles are reused triangle.tdo = None self.sortTriangles(0, self.numTrianglesUsed - 1)
def allocateTriangle(self): result = u3dsupport.KfTriangle() self.triangles.append(result) return result
def clearTriangles(self): i = 0L for i in range(0, self.numTrianglesUsed): u3dsupport.KfTriangle(self.triangles.Items[i]).tdo = None self.numTrianglesUsed = 0