How to make Perimeter line join automatically to its first point when pulled near to it same as area tool

I want to make a AnnotationCreatePerimeterMeasurement tool to join automatically while drawing annotation. It should work same as AnnotationCreateAreaMeasurement tool. Last point gets joined to first point in area tool. This should happen to perimeter tool also but only when last point comes close to the first point, it gets joined completely.