private float ShowMidpointControls(Ferr2DPath aPath, int i, PathEditorUtil.Selection aSelection, Matrix4x4 aTransform, SerializedProperty aPathProp, float aCurrDistance)
    {
        EventType eType = Event.current.type;

        // calculate distance data for finding the midpoint
        float segmentDistance = aPath.GetDistanceBetween(i, PathUtil.WrapIndex(i + 1, aPath.Count, aPath.Closed));
        float nextDistance    = aCurrDistance + segmentDistance;
        float midDist         = aCurrDistance + (segmentDistance) / 2;

        // if we have no segment on the control vert, skip this midpoint
        if (aPath.Count <= 1 || (i == aPath.Count - 1 && !aPath.Closed))
        {
            return(nextDistance);
        }

        // find the midpoint of this line
        Vector2 midPoint       = aPath.GetPointAtDistance(midDist);
        Vector2 midNormal      = aPath.GetNormalAtDistance(midDist);
        Vector3 midWorldPoint  = aTransform.MultiplyPoint(midPoint);
        Vector3 midWorldNormal = aTransform.MultiplyVector(midNormal);
        float   midSize        = eType == EventType.Layout || eType == EventType.Repaint ? HandleUtility.GetHandleSize(midWorldPoint) : 0;

        // edge override button
        int direction = aPath.GetData(i).directionOverride;

        if (terrain.EdgeMode != Ferr2D_SectionMode.None && (i == activeSegment || aSelection.IsSegmentSelected(i, aPath.Count, aPath.Closed) || direction != (int)Ferr2DT_TerrainDirection.None))
        {
            if (Event.current.alt)
            {
                if (direction != (int)Ferr2DT_TerrainDirection.None && Handles.Button(midWorldPoint + midWorldNormal * midSize * sizeLargeHandle * 2, Quaternion.identity, midSize * sizeSmallHandle, midSize * sizeSmallHandle, Ferr2DT_Caps.CapDotReset))
                {
                    aSelection.EachSegment(i, aPath.Count, aPath.Closed, id => {
                        SerializedProperty overrideProp = aPathProp.FindPropertyRelative("_data").GetArrayElementAtIndex(id).FindPropertyRelative("directionOverride");
                        overrideProp.intValue           = (int)Ferr2DT_TerrainDirection.None;
                    });
                }
            }
            else
            {
                if (Handles.Button(midWorldPoint + midWorldNormal * midSize * sizeLargeHandle * 2, Quaternion.identity, midSize * sizeSmallHandle, midSize * sizeSmallHandle, Ferr2DT_Caps.GetEdgeCap(direction)))
                {
                    CycleEdgeOverride(aPathProp, i);
                    SerializedProperty cycledOverride = aPathProp.FindPropertyRelative("_data").GetArrayElementAtIndex(i).FindPropertyRelative("directionOverride");
                    aSelection.EachSegment(i, aPath.Count, aPath.Closed, id => {
                        SerializedProperty overrideProp = aPathProp.FindPropertyRelative("_data").GetArrayElementAtIndex(id).FindPropertyRelative("directionOverride");
                        overrideProp.intValue           = cycledOverride.intValue;
                    });
                }
            }
        }

        // new point button
        if (!Event.current.alt && i == activeSegment && Handles.Button(midWorldPoint, Quaternion.identity, midSize * sizeLargeHandle, midSize * sizeLargeHandle, Ferr2DT_Caps.CapDotPlus))
        {
            PathEditorUtil.AddPoint(aPathProp, midPoint, i + 1);
            ProcessNewPoint(aPathProp, i + 1);
        }

        return(nextDistance);
    }