export function dogbone()

in packages/maker.js/src/core/fillet.ts [308:364]


    export function dogbone(lineA: IPathLine, lineB: IPathLine, filletRadius: number, options?: IPointMatchOptions): IPathArc {
        //TODO: allow arcs in dogbone

        if (isPathLine(lineA) && isPathLine(lineB) && filletRadius && filletRadius > 0) {

            var opts: IPointMatchOptions = {
                pointMatchingDistance: .005
            };
            extendObject(opts, options);

            //first find the common point
            var commonProperty = getMatchingPointProperties(lineA, lineB, options);
            if (commonProperty) {

                //get the ratio comparison of the two lines
                var ratio = getLineRatio([lineA, lineB]);

                //draw a line between the two endpoints, and get the bisection point at the ratio
                var span = new paths.Line(commonProperty[0].oppositePoint, commonProperty[1].oppositePoint);
                var midRatioPoint = point.middle(span, ratio);

                //use the bisection theorem to get the angle bisecting the lines
                var bisectionAngle = angle.ofPointInDegrees(commonProperty[0].point, midRatioPoint);

                var center = point.add(commonProperty[0].point, point.fromPolar(angle.toRadians(bisectionAngle), filletRadius));

                if (!populateShardPointsFromReferenceCircle(filletRadius, center, commonProperty, opts)) {
                    return null;
                }

                //get the angles of the fillet and a function which clips the path to the fillet.
                var results: IFilletResult[] = [];
                for (var i = 0; i < 2; i++) {
                    var result = getDogboneResult(commonProperty[i], center);
                    if (!result) {
                        return null;
                    }
                    results.push(result);
                }

                var filletArc = new paths.Arc(center, filletRadius, results[0].filletAngle, results[1].filletAngle);

                //make sure midpoint of fillet is outside of the angle
                if (round(angle.noRevolutions(angle.ofArcMiddle(filletArc))) == round(bisectionAngle)) {
                    filletArc.startAngle = results[1].filletAngle;
                    filletArc.endAngle = results[0].filletAngle;
                }

                //clip the paths and return the fillet arc.
                results[0].clipPath();
                results[1].clipPath();

                return filletArc;
            }
        }
        return null;
    }