def test_contour_circle(self): def draw_contour(pen): pen.moveTo((0, 100)) pen.curveTo((-55, 100), (-100, 55), (-100, 0)) pen.curveTo((-100, -55), (-55, -100), (0, -100)) pen.curveTo((55, -100), (100, -55), (100, 0)) pen.curveTo((100, 55), (55, 100), (0, 100)) piPen = PointInsidePen(None, (50, 50)) # this point is inside draw_contour(piPen) self.assertEqual(piPen.getResult(), True) piPen = PointInsidePen(None, (50, -50)) # this point is inside draw_contour(piPen) self.assertEqual(piPen.getResult(), True)
def test_contour_circle(self): def draw_contour(pen): pen.moveTo( (0, 100) ) pen.curveTo( (-55, 100) , (-100, 55) , (-100, 0) ) pen.curveTo( (-100, -55) , (-55, -100) , (0, -100) ) pen.curveTo( (55, -100) , (100, -55) , (100, 0) ) pen.curveTo( (100, 55) , (55, 100) , (0, 100) ) piPen = PointInsidePen(None, (50, 50)) # this point is inside draw_contour(piPen) self.assertEqual(piPen.getResult(), True) piPen = PointInsidePen(None, (50, -50)) # this point is inside draw_contour(piPen) self.assertEqual(piPen.getResult(), True)
def _pointInside(self, point): """ Subclasses may override this method. """ from fontTools.pens.pointInsidePen import PointInsidePen pen = PointInsidePen(glyphSet=None, testPoint=point, evenOdd=False) self.draw(pen) return pen.getResult()
def test_contour_no_solutions(self): def draw_contour(pen): pen.moveTo((969, 230)) pen.curveTo((825, 348), (715, 184), (614, 202)) pen.lineTo((614, 160)) pen.lineTo((969, 160)) pen.closePath() piPen = PointInsidePen(None, (750, 295)) # this point is outside draw_contour(piPen) self.assertEqual(piPen.getWinding(), 0) self.assertEqual(piPen.getResult(), False) piPen = PointInsidePen(None, (835, 190)) # this point is inside draw_contour(piPen) self.assertEqual(piPen.getWinding(), 1) self.assertEqual(piPen.getResult(), True)
def test_contour_no_solutions(self): def draw_contour(pen): pen.moveTo( (969, 230) ) pen.curveTo( (825, 348) , (715, 184) , (614, 202) ) pen.lineTo( (614, 160) ) pen.lineTo( (969, 160) ) pen.closePath() piPen = PointInsidePen(None, (750, 295)) # this point is outside draw_contour(piPen) self.assertEqual(piPen.getWinding(), 0) self.assertEqual(piPen.getResult(), False) piPen = PointInsidePen(None, (835, 190)) # this point is inside draw_contour(piPen) self.assertEqual(piPen.getWinding(), 1) self.assertEqual(piPen.getResult(), True)
def pointInside(self, coordinates, evenOdd=False): """ Returns a boolean indicating if **(x, y)** is in the "black" area of the contour. """ (x, y) = coordinates from fontTools.pens.pointInsidePen import PointInsidePen pen = PointInsidePen(glyphSet=None, testPoint=(x, y), evenOdd=evenOdd) self.draw(pen) return pen.getResult()
def pointInside(self, coordinates, evenOdd=False): """ Returns a boolean indicating if **(x, y)** is in the "black" area of the glyph. """ (x, y) = coordinates from fontTools.pens.pointInsidePen import PointInsidePen pen = PointInsidePen(glyphSet=None, testPoint=(x, y), evenOdd=evenOdd) self.draw(pen) return pen.getResult()
def render(draw_function, even_odd): result = StringIO() for y in range(5): for x in range(10): pen = PointInsidePen(None, (x + 0.5, y + 0.5), even_odd) draw_function(pen) if pen.getResult(): result.write("*") else: result.write(" ") return result.getvalue()
def render(draw_function, even_odd): result = BytesIO() for y in range(5): for x in range(10): pen = PointInsidePen(None, (x + 0.5, y + 0.5), even_odd) draw_function(pen) if pen.getResult(): result.write(b"*") else: result.write(b" ") return tounicode(result.getvalue())
def test_contour_square_opened(self): def draw_contour(pen): pen.moveTo((100, 100)) pen.lineTo((-100, 100)) pen.lineTo((-100, -100)) pen.lineTo((100, -100)) # contour not explicitly closed piPen = PointInsidePen(None, (0, 0)) # this point is inside draw_contour(piPen) self.assertEqual(piPen.getWinding(), 1) self.assertEqual(piPen.getResult(), True)
def test_contour_square_opened(self): def draw_contour(pen): pen.moveTo( (100, 100) ) pen.lineTo( (-100, 100) ) pen.lineTo( (-100, -100) ) pen.lineTo( (100, -100) ) # contour not explicitly closed piPen = PointInsidePen(None, (0, 0)) # this point is inside draw_contour(piPen) self.assertEqual(piPen.getWinding(), 1) self.assertEqual(piPen.getResult(), True)
def pointInside(self, coordinates, evenOdd=False): """ Returns a boolean indicating if **(x, y)** is in the "black" area of the component. """ (x, y) = coordinates from fontTools.pens.pointInsidePen import PointInsidePen glyph = self.glyph if glyph is None: return False font = self.font if font is None: return False pen = PointInsidePen(glyphSet=font, testPoint=(x, y), evenOdd=evenOdd) self.draw(pen) return pen.getResult()
def isInside(self, cursor): pen = PointInsidePen(None, cursor) for i, point in enumerate(self.activeAreaRect): if i == len(self.activeAreaRect) - 1: pen.lineTo(point) pen.closePath() break elif i == 0: pen.moveTo(point) else: pen.lineTo(point) result = pen.getResult() if result: self.bcColor = 0, 0, 1, .3 else: self.bcColor = 1, 0, 0, .3 return result
def pixellate(self, rect, increment=50, inset=0): """WIP""" x = -200 y = -200 dp = DATPen() while x < 1000: while y < 1000: #print(x, y) pen = PointInsidePen(None, (x, y)) self.replay(pen) isInside = pen.getResult() if isInside: dp.rect(Rect(x, y, increment, increment).inset(inset)) y += increment x += increment y = -200 self.value = dp.value return self
self.enableNotifications(observer=self) self.dirty = True # ------------ # Point Inside # ------------ def pointInside(self, (x, y), evenOdd=False): """ Returns a boolean indicating if **(x, y)** is in the "black" area of the contour. """ from fontTools.pens.pointInsidePen import PointInsidePen pen = PointInsidePen(glyphSet=None, testPoint=(x, y), evenOdd=evenOdd) self.draw(pen) return pen.getResult() # --------- # Splitting # --------- def positionForProspectivePointInsertionAtSegmentAndT(self, segmentIndex, t): """ Get the precise coordinates and a boolean indicating if the point will be smooth for the given **segmentIndex** and **t**. """ return self._splitAndInsertAtSegmentAndT(segmentIndex, t, False) def splitAndInsertPointAtSegmentAndT(self, segmentIndex, t): """