Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
center = self.getCenter()
orientation = self.getOrientation()
if self._radius[1] > self._radius[0]:
# _handleAxis1 is the major axis
orientation -= numpy.pi/2
point0 = numpy.array([center[0] + self._radius[0] * numpy.cos(orientation),
center[1] + self._radius[0] * numpy.sin(orientation)])
point1 = numpy.array([center[0] - self._radius[1] * numpy.sin(orientation),
center[1] + self._radius[1] * numpy.cos(orientation)])
with utils.blockSignals(self._handleAxis0):
self._handleAxis0.setPosition(*point0)
with utils.blockSignals(self._handleAxis1):
self._handleAxis1.setPosition(*point1)
with utils.blockSignals(self._handleLabel):
self._handleLabel.setPosition(*center)
nbpoints = 27
angles = numpy.arange(nbpoints) * 2.0 * numpy.pi / nbpoints
X = (self._radius[0] * numpy.cos(angles) * numpy.cos(orientation)
- self._radius[1] * numpy.sin(angles) * numpy.sin(orientation))
Y = (self._radius[0] * numpy.cos(angles) * numpy.sin(orientation)
+ self._radius[1] * numpy.sin(angles) * numpy.cos(orientation))
ellipseShape = numpy.array((X, Y)).T
ellipseShape += center
self.__shape.setPoints(ellipseShape)
self.sigRegionChanged.emit()
origin = numpy.array(origin)
size = numpy.array(size)
points = numpy.array([origin, origin + size])
center = origin + size * 0.5
elif center is not None:
center = numpy.array(center)
size = numpy.array(size)
points = numpy.array([center - size * 0.5, center + size * 0.5])
else:
raise ValueError("Origin or center expected")
with utils.blockSignals(self._handleBottomLeft):
self._handleBottomLeft.setPosition(points[0, 0], points[0, 1])
with utils.blockSignals(self._handleBottomRight):
self._handleBottomRight.setPosition(points[1, 0], points[0, 1])
with utils.blockSignals(self._handleTopLeft):
self._handleTopLeft.setPosition(points[0, 0], points[1, 1])
with utils.blockSignals(self._handleTopRight):
self._handleTopRight.setPosition(points[1, 0], points[1, 1])
with utils.blockSignals(self._handleCenter):
self._handleCenter.setPosition(center[0], center[1])
with utils.blockSignals(self._handleLabel):
self._handleLabel.setPosition(points[0, 0], points[0, 1])
self.__shape.setPoints(points)
self.sigRegionChanged.emit()
def _updateShape(self):
geometry = self._geometry
points = self._createShapeFromGeometry(geometry)
self.__shape.setPoints(points)
index = numpy.nanargmin(points[:, 1])
pos = points[index]
with utils.blockSignals(self._handleLabel):
self._handleLabel.setPosition(pos[0], pos[1])
if geometry.center is None:
movePos = geometry.startPoint * 0.34 + geometry.endPoint * 0.66
elif (geometry.isClosed()
or abs(geometry.endAngle - geometry.startAngle) > numpy.pi * 0.7):
movePos = geometry.center
else:
moveAngle = geometry.startAngle * 0.34 + geometry.endAngle * 0.66
vector = numpy.array([numpy.cos(moveAngle), numpy.sin(moveAngle)])
movePos = geometry.center + geometry.radius * vector
with utils.blockSignals(self._handleMove):
self._handleMove.setPosition(*movePos)
self.sigRegionChanged.emit()
elif center is not None:
center = numpy.array(center)
size = numpy.array(size)
points = numpy.array([center - size * 0.5, center + size * 0.5])
else:
raise ValueError("Origin or center expected")
with utils.blockSignals(self._handleBottomLeft):
self._handleBottomLeft.setPosition(points[0, 0], points[0, 1])
with utils.blockSignals(self._handleBottomRight):
self._handleBottomRight.setPosition(points[1, 0], points[0, 1])
with utils.blockSignals(self._handleTopLeft):
self._handleTopLeft.setPosition(points[0, 0], points[1, 1])
with utils.blockSignals(self._handleTopRight):
self._handleTopRight.setPosition(points[1, 0], points[1, 1])
with utils.blockSignals(self._handleCenter):
self._handleCenter.setPosition(center[0], center[1])
with utils.blockSignals(self._handleLabel):
self._handleLabel.setPosition(points[0, 0], points[0, 1])
self.__shape.setPoints(points)
self.sigRegionChanged.emit()
def __updateEndPoints(self, startPoint, endPoint):
"""Update marker and shape to match given end points
:param numpy.ndarray startPoint: Staring bounding point of the line
:param numpy.ndarray endPoint: Ending bounding point of the line
"""
startPoint = numpy.array(startPoint)
endPoint = numpy.array(endPoint)
center = (startPoint + endPoint) * 0.5
with utils.blockSignals(self._handleStart):
self._handleStart.setPosition(startPoint[0], startPoint[1])
with utils.blockSignals(self._handleEnd):
self._handleEnd.setPosition(endPoint[0], endPoint[1])
with utils.blockSignals(self._handleCenter):
self._handleCenter.setPosition(center[0], center[1])
with utils.blockSignals(self._handleLabel):
self._handleLabel.setPosition(center[0], center[1])
line = numpy.array((startPoint, endPoint))
self.__shape.setPoints(line)
self.sigRegionChanged.emit()
def _updateHandles(self):
geometry = self._geometry
with utils.blockSignals(self._handleStart):
self._handleStart.setPosition(*geometry.startPoint)
with utils.blockSignals(self._handleEnd):
self._handleEnd.setPosition(*geometry.endPoint)
self._updateMidHandle()
self._updateWeightHandle()
self._updateShape()
def __updateNumpySelectionAxis(self):
"""
Update the numpy-selector according to the needed axis names
"""
with blockSignals(self.__numpySelection):
previousPermutation = self.__numpySelection.permutation()
previousSelection = self.__numpySelection.selection()
self.__numpySelection.clear()
info = self._getInfo()
axisNames = self.__currentView.axesNames(self.__data, info)
if (info.isArray and info.size != 0 and
self.__data is not None and axisNames is not None):
self.__useAxisSelection = True
self.__numpySelection.setAxisNames(axisNames)
self.__numpySelection.setCustomAxis(
self.__currentView.customAxisNames())
data = self.normalizeData(self.__data)
self.__numpySelection.setData(data)
def _updateCurvature(self, start, mid, end, updateCurveHandles, checkClosed=False):
"""Update the curvature using 3 control points in the curve
:param bool updateCurveHandles: If False curve handles are already at
the right location
"""
if updateCurveHandles:
with utils.blockSignals(self._handleStart):
self._handleStart.setPosition(*start)
with utils.blockSignals(self._handleMid):
self._handleMid.setPosition(*mid)
with utils.blockSignals(self._handleEnd):
self._handleEnd.setPosition(*end)
if checkClosed:
closed = self._isCloseInPixel(start, end)
else:
closed = self._geometry.isClosed()
weight = self._geometry.weight
geometry = self._createGeometryFromControlPoints(start, mid, end, weight, closed=closed)
self._geometry = geometry
self._updateWeightHandle()
self._updateShape()
def _updateMidHandle(self):
"""Keep the same geometry, but update the location of the control
points.
So calling this function do not trigger sigRegionChanged.
"""
geometry = self._geometry
if geometry.isClosed():
start = numpy.array(self._handleStart.getPosition())
geometry.endPoint = start
with utils.blockSignals(self._handleEnd):
self._handleEnd.setPosition(*start)
midPos = geometry.center + geometry.center - start
else:
if geometry.center is None:
midPos = geometry.startPoint * 0.66 + geometry.endPoint * 0.34
else:
midAngle = geometry.startAngle * 0.66 + geometry.endAngle * 0.34
vector = numpy.array([numpy.cos(midAngle), numpy.sin(midAngle)])
midPos = geometry.center + geometry.radius * vector
with utils.blockSignals(self._handleMid):
self._handleMid.setPosition(*midPos)