def onStrokeAdded( self, stroke ): "Watches for Strokes with Circularity > threshold to Annotate" # need at least 6 points to be a circle if stroke.length()<6: return strokeLen = GeomUtils.strokeLength(stroke) distCutoff = NodeMarker.CLOSED_DIST_THRESH * (strokeLen ** 2) #s_norm = GeomUtils.strokeNormalizeSpacing( stroke, 20 ) ep1 = stroke.Points[0] ep2 = stroke.Points[-1] epDist = GeomUtils.pointDistanceSquared(ep1.X, ep1.Y, ep2.X, ep2.Y) if epDist <= distCutoff: avgDist = GeomUtils.averageDistance( stroke.Center, stroke.Points ) self.getBoard().AnnotateStrokes([stroke], DiGraphNodeAnnotation(0, stroke.Center, avgDist)) else: node_log.debug("Not a node: endpoint distance %s > %s" % (epDist, distCutoff))
def onStrokeAdded( self, stroke ): "Watches for Strokes with Circularity > threshold to Annotate" # need at least 6 points to be a circle if stroke.length()<6: return s_norm = GeomUtils.strokeNormalizeSpacing( stroke, 20 ) s_chop = GeomUtils.strokeChopEnds( s_norm, 0.20 ) circ_norm = GeomUtils.strokeCircularity( s_norm ) circ_chop = GeomUtils.strokeCircularity( s_chop ) logger.debug( "stroke: %s", [str(p) for p in s_norm.Points] ) logger.debug( "potential circles (%f,%f) <> %f", circ_norm, circ_chop, self.threshold ) if( circ_norm>self.threshold or circ_chop>self.threshold): cen = stroke.Center avgDist = GeomUtils.averageDistance( cen, stroke.Points ) anno = CircleAnnotation( circ_norm, cen, avgDist ) BoardSingleton().AnnotateStrokes( [stroke], anno)