本文整理汇总了Python中PyQt5.QtCore.QLineF.length方法的典型用法代码示例。如果您正苦于以下问题:Python QLineF.length方法的具体用法?Python QLineF.length怎么用?Python QLineF.length使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类PyQt5.QtCore.QLineF
的用法示例。
在下文中一共展示了QLineF.length方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: paint
# 需要导入模块: from PyQt5.QtCore import QLineF [as 别名]
# 或者: from PyQt5.QtCore.QLineF import length [as 别名]
def paint(self, painter, option, widget):
if not self.source or not self.dest:
return
# Draw the line itself.
line = QLineF(self.sourcePoint, self.destPoint)
if line.length() == 0.0:
return
painter.setPen(QPen(Qt.black, 1, Qt.SolidLine, Qt.RoundCap,
Qt.RoundJoin))
painter.drawLine(line)
# Draw the arrows if there's enough room.
angle = math.acos(line.dx() / line.length())
if line.dy() >= 0:
angle = Edge.TwoPi - angle
sourceArrowP1 = self.sourcePoint + QPointF(math.sin(angle + Edge.Pi / 3) * self.arrowSize,
math.cos(angle + Edge.Pi / 3) * self.arrowSize)
sourceArrowP2 = self.sourcePoint + QPointF(math.sin(angle + Edge.Pi - Edge.Pi / 3) * self.arrowSize,
math.cos(angle + Edge.Pi - Edge.Pi / 3) * self.arrowSize);
destArrowP1 = self.destPoint + QPointF(math.sin(angle - Edge.Pi / 3) * self.arrowSize,
math.cos(angle - Edge.Pi / 3) * self.arrowSize)
destArrowP2 = self.destPoint + QPointF(math.sin(angle - Edge.Pi + Edge.Pi / 3) * self.arrowSize,
math.cos(angle - Edge.Pi + Edge.Pi / 3) * self.arrowSize)
painter.setBrush(Qt.black)
painter.drawPolygon(QPolygonF([line.p1(), sourceArrowP1, sourceArrowP2]))
painter.drawPolygon(QPolygonF([line.p2(), destArrowP1, destArrowP2]))
示例2: paint
# 需要导入模块: from PyQt5.QtCore import QLineF [as 别名]
# 或者: from PyQt5.QtCore.QLineF import length [as 别名]
def paint(self, painter, option, widget):
assert self.fromSquare is not None
assert self.toSquare is not None
line = QLineF(self.sourcePoint, self.destPoint)
assert(line.length() != 0.0)
# Draw the arrows if there's enough room.
angle = math.acos(line.dx() / line.length())
if line.dy() >= 0:
angle = (math.pi*2.0) - angle
destArrowP1 = self.destPoint + QPointF(
math.sin(angle - math.pi / 3) * self.arrowSize,
math.cos(angle - math.pi / 3) * self.arrowSize
)
destArrowP2 = self.destPoint + QPointF(
math.sin(angle - math.pi + math.pi / 3) * self.arrowSize,
math.cos(angle - math.pi + math.pi / 3) * self.arrowSize
)
painter.setPen(self.pen)
painter.setBrush(self.brush)
# arrowhead1 = QPolygonF([line.p1(), sourceArrowP1, sourceArrowP2])
arrowhead2 = QPolygonF([line.p2(), destArrowP1, destArrowP2])
painter.drawPolygon(arrowhead2)
painter.setPen(self.pen)
painter.drawLine(line)
示例3: timerEvent
# 需要导入模块: from PyQt5.QtCore import QLineF [as 别名]
# 或者: from PyQt5.QtCore.QLineF import length [as 别名]
def timerEvent(self):
# Don't move too far away.
lineToCenter = QLineF(QPointF(0, 0), self.mapFromScene(0, 0))
if lineToCenter.length() > 150:
angleToCenter = math.acos(lineToCenter.dx() / lineToCenter.length())
if lineToCenter.dy() < 0:
angleToCenter = Mouse.TwoPi - angleToCenter;
angleToCenter = Mouse.normalizeAngle((Mouse.Pi - angleToCenter) + Mouse.Pi / 2)
if angleToCenter < Mouse.Pi and angleToCenter > Mouse.Pi / 4:
# Rotate left.
self.angle += [-0.25, 0.25][self.angle < -Mouse.Pi / 2]
elif angleToCenter >= Mouse.Pi and angleToCenter < (Mouse.Pi + Mouse.Pi / 2 + Mouse.Pi / 4):
# Rotate right.
self.angle += [-0.25, 0.25][self.angle < Mouse.Pi / 2]
elif math.sin(self.angle) < 0:
self.angle += 0.25
elif math.sin(self.angle) > 0:
self.angle -= 0.25
# Try not to crash with any other mice.
dangerMice = self.scene().items(QPolygonF([self.mapToScene(0, 0),
self.mapToScene(-30, -50),
self.mapToScene(30, -50)]))
for item in dangerMice:
if item is self:
continue
lineToMouse = QLineF(QPointF(0, 0), self.mapFromItem(item, 0, 0))
angleToMouse = math.acos(lineToMouse.dx() / lineToMouse.length())
if lineToMouse.dy() < 0:
angleToMouse = Mouse.TwoPi - angleToMouse
angleToMouse = Mouse.normalizeAngle((Mouse.Pi - angleToMouse) + Mouse.Pi / 2)
if angleToMouse >= 0 and angleToMouse < Mouse.Pi / 2:
# Rotate right.
self.angle += 0.5
elif angleToMouse <= Mouse.TwoPi and angleToMouse > (Mouse.TwoPi - Mouse.Pi / 2):
# Rotate left.
self.angle -= 0.5
# Add some random movement.
if len(dangerMice) > 1 and (qrand() % 10) == 0:
if qrand() % 1:
self.angle += (qrand() % 100) / 500.0
else:
self.angle -= (qrand() % 100) / 500.0
self.speed += (-50 + qrand() % 100) / 100.0
dx = math.sin(self.angle) * 10
self.mouseEyeDirection = 0.0 if qAbs(dx / 5) < 1 else dx / 5
self.setRotation(self.rotation() + dx)
self.setPos(self.mapToParent(0, -(3 + math.sin(self.speed) * 3)))
示例4: moveUIPoint
# 需要导入模块: from PyQt5.QtCore import QLineF [as 别名]
# 或者: from PyQt5.QtCore.QLineF import length [as 别名]
def moveUIPoint(contour, point, delta):
if point.segmentType is None:
# point is an offCurve. Get its sibling onCurve and the other
# offCurve.
onCurve, otherPoint = _getOffCurveSiblingPoints(contour, point)
# if the onCurve is selected, the offCurve will move along with it
if onCurve.selected:
return
point.move(delta)
if not onCurve.smooth:
contour.dirty = True
return
# if the onCurve is smooth, we need to either...
if otherPoint.segmentType is None and not otherPoint.selected:
# keep the other offCurve inline
line = QLineF(point.x, point.y, onCurve.x, onCurve.y)
otherLine = QLineF(
onCurve.x, onCurve.y, otherPoint.x, otherPoint.y)
line.setLength(line.length() + otherLine.length())
otherPoint.x = line.x2()
otherPoint.y = line.y2()
else:
# keep point in tangency with onCurve -> otherPoint segment,
# ie. do an orthogonal projection
line = QLineF(otherPoint.x, otherPoint.y, onCurve.x, onCurve.y)
n = line.normalVector()
n.translate(QPointF(point.x, point.y) - n.p1())
targetPoint = QPointF()
n.intersect(line, targetPoint)
# check that targetPoint is beyond its neighbor onCurve
# we do this by calculating position of the offCurve and second
# onCurve relative to the first onCurve. If there is no symmetry
# in at least one of the axis, then we need to clamp
onCurvePoint = line.p2()
onDistance = line.p1() - onCurvePoint
newDistance = targetPoint - onCurvePoint
if (onDistance.x() >= 0) != (newDistance.x() <= 0) or \
(onDistance.y() >= 0) != (newDistance.y() <= 0):
targetPoint = onCurvePoint
# ok, now set pos
point.x, point.y = targetPoint.x(), targetPoint.y()
else:
# point is an onCurve. Move its offCurves along with it.
index = contour.index(point)
point.move(delta)
for d in (-1, 1):
# edge-case: contour open, trailing offCurve and moving first
# onCurve in contour
if contour.open and index == 0 and d == -1:
continue
pt = contour.getPoint(index + d)
if pt.segmentType is None:
pt.move(delta)
contour.dirty = True
示例5: paint
# 需要导入模块: from PyQt5.QtCore import QLineF [as 别名]
# 或者: from PyQt5.QtCore.QLineF import length [as 别名]
def paint(self, painter, option, widget):
"""
Customize line adding an arrow head
:param QPainter painter: Painter instance of the item
:param option: Painter option of the item
:param widget: Widget instance
"""
if not self.source or not self.destination:
return
line = QLineF(self.source_point, self.destination_point)
if qFuzzyCompare(line.length(), 0):
return
# Draw the line itself
color = QColor()
color.setHsv(120 - 60 / self.steps_max * self.steps,
180 + 50 / self.steps_max * self.steps,
150 + 80 / self.steps_max * self.steps)
if self.highlighted:
color.setHsv(0, 0, 0)
style = self.line_style
painter.setPen(QPen(color, 1, style, Qt.RoundCap, Qt.RoundJoin))
painter.drawLine(line)
painter.setPen(QPen(color, 1, Qt.SolidLine, Qt.RoundCap, Qt.RoundJoin))
# Draw the arrows
angle = math.acos(line.dx() / line.length())
if line.dy() >= 0:
angle = (2.0 * math.pi) - angle
# arrow in the middle of the arc
hpx = line.p1().x() + (line.dx() / 2.0)
hpy = line.p1().y() + (line.dy() / 2.0)
head_point = QPointF(hpx, hpy)
painter.setPen(QPen(color, 1, Qt.SolidLine, Qt.RoundCap, Qt.RoundJoin))
destination_arrow_p1 = head_point + QPointF(
math.sin(angle - math.pi / 3) * self.arrow_size,
math.cos(angle - math.pi / 3) * self.arrow_size)
destination_arrow_p2 = head_point + QPointF(
math.sin(angle - math.pi + math.pi / 3) * self.arrow_size,
math.cos(angle - math.pi + math.pi / 3) * self.arrow_size)
painter.setBrush(color)
painter.drawPolygon(QPolygonF([head_point, destination_arrow_p1, destination_arrow_p2]))
if self.metadata["confirmation_text"]:
painter.drawText(head_point, self.metadata["confirmation_text"])
示例6: rotateUIPointAroundRefLine
# 需要导入模块: from PyQt5.QtCore import QLineF [as 别名]
# 或者: from PyQt5.QtCore.QLineF import length [as 别名]
def rotateUIPointAroundRefLine(x1, y1, x2, y2, pt):
"""
Given three points p1, p2, pt this rotates pt around p2 such that p1,p2 and
p1,pt are collinear.
"""
line = QLineF(pt.x, pt.y, x2, y2)
p2p_l = line.length()
line.setP1(QPointF(x1, y1))
p1p2_l = line.length()
if not p1p2_l:
return
line.setLength(p1p2_l + p2p_l)
pt.x = line.x2()
pt.y = line.y2()
示例7: paint
# 需要导入模块: from PyQt5.QtCore import QLineF [as 别名]
# 或者: from PyQt5.QtCore.QLineF import length [as 别名]
def paint(self, painter, option, widget):
"""
Customize line adding an arrow head
:param QPainter painter: Painter instance of the item
:param option: Painter option of the item
:param widget: Widget instance
"""
if not self.source or not self.destination:
return
line = QLineF(self.source_point, self.destination_point)
if qFuzzyCompare(line.length(), 0):
return
# Draw the line itself
color = QColor()
style = Qt.SolidLine
if self.status == ARC_STATUS_STRONG:
color.setNamedColor('blue')
if self.status == ARC_STATUS_WEAK:
color.setNamedColor('salmon')
style = Qt.DashLine
painter.setPen(QPen(color, 1, style, Qt.RoundCap, Qt.RoundJoin))
painter.drawLine(line)
painter.setPen(QPen(color, 1, Qt.SolidLine, Qt.RoundCap, Qt.RoundJoin))
# Draw the arrows
angle = math.acos(line.dx() / line.length())
if line.dy() >= 0:
angle = (2.0 * math.pi) - angle
# arrow in the middle of the arc
hpx = line.p1().x() + (line.dx() / 2.0)
hpy = line.p1().y() + (line.dy() / 2.0)
head_point = QPointF(hpx, hpy)
painter.setPen(QPen(color, 1, Qt.SolidLine, Qt.RoundCap, Qt.RoundJoin))
destination_arrow_p1 = head_point + QPointF(
math.sin(angle - math.pi / 3) * self.arrow_size,
math.cos(angle - math.pi / 3) * self.arrow_size)
destination_arrow_p2 = head_point + QPointF(
math.sin(angle - math.pi + math.pi / 3) * self.arrow_size,
math.cos(angle - math.pi + math.pi / 3) * self.arrow_size)
painter.setBrush(color)
painter.drawPolygon(QPolygonF([head_point, destination_arrow_p1, destination_arrow_p2]))
if self.metadata["confirmation_text"]:
painter.drawText(head_point, self.metadata["confirmation_text"])
示例8: move
# 需要导入模块: from PyQt5.QtCore import QLineF [as 别名]
# 或者: from PyQt5.QtCore.QLineF import length [as 别名]
def move(self, item, dest, moveSpeed):
walkLine = QLineF(item.getGuidedPos(), dest)
if moveSpeed >= 0 and walkLine.length() > moveSpeed:
# The item is too far away from it's destination point so we move
# it towards it instead.
dx = walkLine.dx()
dy = walkLine.dy()
if abs(dx) > abs(dy):
# Walk along x-axis.
if dx != 0:
d = moveSpeed * dy / abs(dx)
if dx > 0:
s = moveSpeed
else:
s = -moveSpeed
dest.setX(item.getGuidedPos().x() + s)
dest.setY(item.getGuidedPos().y() + d)
else:
# Walk along y-axis.
if dy != 0:
d = moveSpeed * dx / abs(dy)
if dy > 0:
s = moveSpeed
else:
s = -moveSpeed
dest.setX(item.getGuidedPos().x() + d)
dest.setY(item.getGuidedPos().y() + s)
item.setGuidedPos(dest)
示例9: GuideLine
# 需要导入模块: from PyQt5.QtCore import QLineF [as 别名]
# 或者: from PyQt5.QtCore.QLineF import length [as 别名]
class GuideLine(Guide):
def __init__(self, line_or_point, follows=None):
super(GuideLine, self).__init__(follows)
if isinstance(line_or_point, QLineF):
self.line = line_or_point
elif follows is not None:
self.line = QLineF(self.prevGuide.endPos(), line_or_point)
else:
self.line = QLineF(QPointF(0, 0), line_or_point)
def length(self):
return self.line.length()
def startPos(self):
return QPointF(self.line.p1().x() * self.scaleX,
self.line.p1().y() * self.scaleY)
def endPos(self):
return QPointF(self.line.p2().x() * self.scaleX,
self.line.p2().y() * self.scaleY)
def guide(self, item, moveSpeed):
frame = item.guideFrame - self.startLength
endX = (self.line.p1().x() + (frame * self.line.dx() / self.length())) * self.scaleX
endY = (self.line.p1().y() + (frame * self.line.dy() / self.length())) * self.scaleY
pos = QPointF(endX, endY)
self.move(item, pos, moveSpeed)
示例10: setWedgeGizmo
# 需要导入模块: from PyQt5.QtCore import QLineF [as 别名]
# 或者: from PyQt5.QtCore.QLineF import length [as 别名]
def setWedgeGizmo(self, neighbor_virtual_helix: int,
neighbor_virtual_helix_item: GridVirtualHelixItemT):
"""Adds a WedgeGizmo to oriented toward the specified neighbor vhi.
Called by NucleicAcidPartItem _refreshVirtualHelixItemGizmos, in between
with beginAddWedgeGizmos and endAddWedgeGizmos.
Args:
neighbor_virtual_helix: the id_num of neighboring virtual helix
neighbor_virtual_helix_item:
the neighboring virtual helix item
"""
wg_dict = self.wedge_gizmos
nvhi = neighbor_virtual_helix_item
nvhi_name = nvhi.getProperty('name')
pos = self.scenePos()
line = QLineF(pos, nvhi.scenePos())
line.translate(_RADIUS, _RADIUS)
if line.length() > (_RADIUS*1.99):
color = '#5a8bff'
else:
color = '#cc0000'
nvhi_name = nvhi_name + '*' # mark as invalid
line.setLength(_RADIUS)
if neighbor_virtual_helix in wg_dict:
wedge_item = wg_dict[neighbor_virtual_helix]
else:
wedge_item = WedgeGizmo(_RADIUS, WEDGE_RECT, self)
wg_dict[neighbor_virtual_helix] = wedge_item
wedge_item.showWedge(line.angle(), color, outline_only=False)
self._added_wedge_gizmos.add(neighbor_virtual_helix)
示例11: findNearestPoint
# 需要导入模块: from PyQt5.QtCore import QLineF [as 别名]
# 或者: from PyQt5.QtCore.QLineF import length [as 别名]
def findNearestPoint(self, part_item, target_scenepos):
"""
Args:
part_item (TYPE): Description
target_scenepos (TYPE): Description
"""
li = self._line_item
pos = li.mapFromScene(target_scenepos)
line = li.line()
mouse_point_vec = QLineF(self._CENTER_OF_HELIX, pos)
# Check if the click happened on the origin VH
if mouse_point_vec.length() < self._RADIUS:
# return part_item.mapFromScene(target_scenepos)
return None
angle_min = 9999
direction_min = None
for vector in self.vectors:
angle_new = mouse_point_vec.angleTo(vector)
if angle_new < angle_min:
direction_min = vector
angle_min = angle_new
if direction_min is not None:
li.setLine(direction_min)
return part_item.mapFromItem(li, direction_min.p2())
else:
print("default point")
line.setP2(pos)
li.setLine(line)
return part_item.mapFromItem(li, pos)
示例12: moveUIPoint
# 需要导入模块: from PyQt5.QtCore import QLineF [as 别名]
# 或者: from PyQt5.QtCore.QLineF import length [as 别名]
def moveUIPoint(contour, point, delta):
if point.segmentType is None:
# point is an offCurve. Get its sibling onCurve and the other
# offCurve.
siblings = _getOffCurveSiblingPoints(contour, point)
# if an onCurve is selected, the offCurve will move along with it
if not siblings:
return
point.move(delta)
for onCurve, otherPoint in siblings:
if not onCurve.smooth:
continue
# if the onCurve is smooth, we need to either...
if otherPoint.segmentType is None and not otherPoint.selected:
# keep the other offCurve inline
line = QLineF(point.x, point.y, onCurve.x, onCurve.y)
otherLine = QLineF(
onCurve.x, onCurve.y, otherPoint.x, otherPoint.y)
line.setLength(line.length() + otherLine.length())
otherPoint.x = line.x2()
otherPoint.y = line.y2()
else:
# keep point in tangency with onCurve -> otherPoint segment,
# i.e. do an orthogonal projection
point.x, point.y, _ = bezierMath.lineProjection(
onCurve.x, onCurve.y, otherPoint.x, otherPoint.y,
point.x, point.y, False)
else:
# point is an onCurve. Move its offCurves along with it.
index = contour.index(point)
point.move(delta)
for d in (-1, 1):
# edge-case: contour open, trailing offCurve and moving first
# onCurve in contour
if contour.open and index == 0 and d == -1:
continue
pt = contour.getPoint(index + d)
if pt.segmentType is None:
# avoid double move for qCurve with single offCurve
if d > 0:
otherPt = contour.getPoint(index + 2 * d)
if otherPt.segmentType is not None and \
otherPt.segmentType != "move" and otherPt.selected:
continue
pt.move(delta)
maybeProjectUISmoothPointOffcurve(contour, point)
contour.dirty = True
示例13: mouseMoveEvent
# 需要导入模块: from PyQt5.QtCore import QLineF [as 别名]
# 或者: from PyQt5.QtCore.QLineF import length [as 别名]
def mouseMoveEvent(self, event):
path, text = self._rulerObject
baseElem = path.elementAt(0)
canvasPos = event.localPos()
if event.modifiers() & Qt.ShiftModifier:
basePos = QPointF(baseElem.x, baseElem.y)
canvasPos = self.clampToOrigin(canvasPos, basePos)
canvasPos = self.magnetPos(canvasPos)
x, y = canvasPos.x(), canvasPos.y()
path.setElementPositionAt(1, x, baseElem.y)
path.setElementPositionAt(2, x, y)
path.setElementPositionAt(3, baseElem.x, baseElem.y)
line = QLineF(baseElem.x, baseElem.y, x, y)
l = line.length()
# angle() doesnt go by trigonometric direction. Weird.
# TODO: maybe split in positive/negative 180s (ff)
a = 360 - line.angle()
line.setP2(QPointF(x, baseElem.y))
h = line.length()
line.setP1(QPointF(x, y))
v = line.length()
text = "%d\n↔ %d\n↕ %d\nα %dº" % (l, h, v, a)
self._rulerObject = (path, text)
self.parent().update()
示例14: adjust
# 需要导入模块: from PyQt5.QtCore import QLineF [as 别名]
# 或者: from PyQt5.QtCore.QLineF import length [as 别名]
def adjust(self):
if not self.source or not self.dest:
return
line = QLineF(self.mapFromItem(self.source, 0, 0),
self.mapFromItem(self.dest, 0, 0))
length = line.length()
self.prepareGeometryChange()
if length > 20.0:
edgeOffset = QPointF((line.dx() * 10) / length,
(line.dy() * 10) / length)
self.sourcePoint = line.p1() + edgeOffset
self.destPoint = line.p2() - edgeOffset
else:
self.sourcePoint = line.p1()
self.destPoint = line.p1()
示例15: angle_arrow
# 需要导入模块: from PyQt5.QtCore import QLineF [as 别名]
# 或者: from PyQt5.QtCore.QLineF import length [as 别名]
def angle_arrow(self, path, origin='head'):
''' Compute the two points of the arrow head with the right angle '''
if origin == 'tail':
path = path.toReversed()
length = path.length()
percent = path.percentAtLength(length - 10.0)
src = path.pointAtPercent(percent)
#path.moveTo(path.pointAtPercent(1))
end_point = path.pointAtPercent(1)
#end_point = path.currentPosition()
line = QLineF(src, end_point)
angle = math.acos(line.dx() / (line.length() or 1))
if line.dy() >= 0:
angle = math.pi * 2 - angle
arrow_size = 10.0
arrow_p1 = end_point + QPointF(
math.sin(angle - math.pi / 3) * arrow_size,
math.cos(angle - math.pi / 3) * arrow_size)
arrow_p2 = end_point + QPointF(
math.sin(angle - math.pi + math.pi / 3) * arrow_size,
math.cos(angle - math.pi + math.pi / 3) * arrow_size)
return (arrow_p1, arrow_p2)