def GetOuterCirclePoint(self, p, p1): """ Offset point by radius of connector circle """ l = industryUIConst.RADIUS_CENTERCIRCLE_OUTER - industryUIConst.RADIUS_CENTERCIRCLE_INNER t = 1.0 - (l - industryUIConst.RADIUS_CONNECTOR_SMALL) / l return geo2.Vec2Lerp(p, p1, t)
def GetNewLineStartPos(self, node, childNode): pos = self._GetLinePosition(node) childPos = self._GetLinePosition(childNode) if node.nodeType == NODETYPE_GROUP: if childPos[1] == pos[1]: offset = node.GetGroupWidth() + 24 s = offset / geo2.Vec2Length(geo2.Vec2Subtract(childPos, pos)) pos = geo2.Vec2Lerp(pos, childPos, s) return (int(pos[0]), int(pos[1]))
def __init__(self, parent, tileFrom, tileTo): self.tileFrom = tileFrom self.tileTo = tileTo self.parent = parent k = hackingUIConst.TILE_SIZE / 2.0 self.p0 = (self.tileFrom.left + k, self.tileFrom.top + k) self.p1 = (self.tileTo.left + k, self.tileTo.top + k) self.offset = geo2.Vec2Subtract(self.p1, self.p0) self.offset = geo2.Vec2Normalize(self.offset) self.center = geo2.Vec2Lerp(self.p0, self.p1, 0.5) self.lineType = self.GetLineType() self.line = uicls.VectorLine(parent=parent, align=uiconst.TOPLEFT) self.bleedSprite = None self.UpdateState()
def intersect_line_segments(seg1, seg2): A, B = seg1 C, D = seg2 if seg1 == seg2: return geo2.Vec2Lerp(A, B, 0.5) cV = segment_circle(A, B, C) cL = geo2.Vec2Length(cV) dV = segment_circle(A, B, D) dL = geo2.Vec2Length(dV) aV = segment_circle(C, D, A) aL = geo2.Vec2Length(aV) bV = segment_circle(C, D, B) bL = geo2.Vec2Length(bV) Ax, Ay = A Bx, By = B Cx, Cy = C Dx, Dy = D X = Y = 0.0 if Ax == Bx and Ay == By or Cx == Dx and Cy == Dy: print 'False1' return False if Ax == Cx and Ay == Cy or Bx == Cx and By == Cy or Ax == Dx and Ay == Dy or Bx == Dx and By == Dy: return False Bx -= Ax By -= Ay Cx -= Ax Cy -= Ay Dx -= Ax Dy -= Ay distAB = math.sqrt(Bx * Bx + By * By) theCos = Bx / distAB theSin = By / distAB newX = Cx * theCos + Cy * theSin Cy = Cy * theCos - Cx * theSin Cx = newX newX = Dx * theCos + Dy * theSin Dy = Dy * theCos - Dx * theSin Dx = newX if Cy < 0 and Dy < 0 or Cy >= 0 and Dy >= 0: return False ABpos = Dx + (Cx - Dx) * Dy / (Dy - Cy) if ABpos < 0 or ABpos > distAB: return False X = Ax + ABpos * theCos Y = Ay + ABpos * theSin return (X, Y)
def GetOuterCirclePoint(self, p, p1): l = industryUIConst.RADIUS_CENTERCIRCLE_OUTER - industryUIConst.RADIUS_CENTERCIRCLE_INNER t = 1.0 - (l - industryUIConst.RADIUS_CONNECTOR_SMALL) / l return geo2.Vec2Lerp(p, p1, t)