def _findSegmentUnderMouse(self, pos, action=None): scale = self.parent().inverseScale() for contour in self._glyph: for index, point in enumerate(contour): if point.segmentType == "line": prev = contour.getPoint(index-1) dist = bezierMath.lineDistance( prev.x, prev.y, point.x, point.y, pos.x(), pos.y()) # TODO: somewhat arbitrary if dist <= 3 * scale: return [prev, point], contour elif point.segmentType in ("curve", "qcurve"): if action == "insert": continue if point.segmentType == "curve": bez = [contour.getPoint(index-3+i) for i in range(4)] else: bez = [point] i = 1 while i < 2 or point.segmentType is None: point = contour.getPoint(index-i) bez.append(point) i += 1 bez.reverse() if _pointWithinThreshold(pos.x(), pos.y(), bez, 5 * scale): return bez, contour return None
def _findSegmentUnderMouse(self, pos, action=None): scale = self.parent().inverseScale() for contour in self._glyph: for index, point in enumerate(contour): if point.segmentType == "line": prev = contour.getPoint(index - 1) dist = bezierMath.lineDistance(prev.x, prev.y, point.x, point.y, pos.x(), pos.y()) # TODO: somewhat arbitrary if dist <= 3 * scale: return [prev, point], contour elif point.segmentType in ("curve", "qcurve"): if action == "insert": continue if point.segmentType == "curve": bez = [ contour.getPoint(index - 3 + i) for i in range(4) ] else: bez = [point] i = 1 while i < 2 or point.segmentType is None: point = contour.getPoint(index - i) bez.append(point) i += 1 bez.reverse() if _pointWithinThreshold(pos.x(), pos.y(), bez, 5 * scale): return bez, contour return None
def _computeLineClick(self, pos, insert=False): scale = self.parent().inverseScale() for contour in self._glyph: for index, point in enumerate(contour): if point.segmentType == "line": prev = contour.getPoint(index-1) dist = bezierMath.lineDistance( prev.x, prev.y, point.x, point.y, pos.x(), pos.y()) # TODO: somewhat arbitrary if dist < 5 * scale: if insert: self._glyph.prepareUndo() contour.holdNotifications() for i, t in enumerate((.35, .65)): xt = prev.x + t * (point.x - prev.x) yt = prev.y + t * (point.y - prev.y) contour.insertPoint( index+i, point.__class__((xt, yt))) point.segmentType = "curve" contour.releaseHeldNotifications() else: prev.selected = point.selected = True contour.postNotification( notification="Contour.SelectionChanged") self._shouldMove = self._shouldPrepareUndo = True return