previousPoint and nextPoint for a point



  • Hi!
    Would it break all the rules to have previousPoint and nextPoint methods or properties for RPoint class? I would find them super handy.

    Implementation demo:

    def previousPoint(self):
        if self.contour is None:
            return None
        if self.contour.open and self.index == 0:
            return None
        return self.contour.points[self.index - 1]
    
    def nextPoint(self):
        if self.contour is None:
            return None
        length = len(self.contour.points)
        if self.contour.open and self.index == length - 1:
            return None
        return self.contour.points[self.index - (length - 1)]
    

  • admin

    oh yeah, sure contour.points it is in a fontParts world

    thanks!



  • That's roughly what I've been doing, and I use them frequently enough to think something similar would be useful as a built-in. Maybe in fontParts then.

    btw. The length in nextPoint should not be len(contour) but len(contour.points).

    Thanks!


  • admin

    Cool! there are a few thing you can do to add new methods to existing classes and objects:

    # set this script as a start up script
    
    from fontParts.fontshell import RPoint
    
    
    def previousPoint(self):
        contour = self.contour
        if contour is None:
            return None
        index = self.index
        if contour.open and index == 0:
            return None
        return contour.points[index - 1]
        
    def nextPoint(self):
        contour = self.contour
        if contour is None:
            return None
        length = len(contour.points)
        index = self.index
        if contour.open and index == length - 1:
            return None
        return contour.points[index - (length - 1)]
        
        
        
    # to make it available everywhere!    
    Rpoint.previousPoint = previousPoint
    RPoint.nextPoint = nextPoint
    

    or you could make an issue in the fontParts repo + a PR after having it discussed with other maintainers.


Log in to reply