package d2scenebuild

import (
	
	

	
	
	
	
)

func ( *builder) ( d2target.Connection,  d2scene.Path) (d2scene.Path, error) {
	 := fmt.Sprintf("connection %q route", .ID)
	,  := d2sketch.ConnectionDrawable(.ctx, , .remainingSketchSceneLimits())
	if  != nil {
		return d2scene.Path{}, fmt.Errorf("scene: %s sketch geometry: %w", , )
	}
	,  := .compileSketchDrawable(, )
	if  != nil {
		return d2scene.Path{}, 
	}
	// A connection uses one paint role even when rough-go emits multiple
	// operation sets. Retaining them as subpaths in the existing route primitive
	// preserves its stable ID, mask ownership, and z-order relative to markers.
	 := d2scene.Path{FillRule: .FillRule, Fill: .Fill, Stroke: .Stroke}
	for ,  := range  {
		.Commands = append(.Commands, .Path.Commands...)
	}
	if len(.Commands) == 0 {
		return d2scene.Path{}, fmt.Errorf("scene: %s sketch geometry is empty", )
	}
	return , nil
}

func ( *builder) ( d2target.Connection,  d2target.Arrowhead,  bool,  d2scene.Point,  geo.Vector) (*d2scene.Node, error) {
	 := "src"
	if  {
		 = "dst"
	}
	 := fmt.Sprintf("%s:%s-arrowhead", .ID, )
	,  := d2sketch.ArrowheadDrawables(, .Stroke, .StrokeWidth)
	if ! {
		return nil, unsupported(fmt.Sprintf("connection %q", .ID), "sketch arrowhead "+string())
	}

	 := d2scene.NewNode(nil)
	.ID = 
	 := 0
	for ,  := range  {
		 := fmt.Sprintf("connection %q %s arrowhead drawable %d", .ID, , )
		,  := .compileSketchDrawable(, )
		if  != nil {
			return nil, 
		}
		for ,  := range  {
			,  := .sketchScenePath(, )
			if  != nil {
				return nil, 
			}
			if  == 0 {
				.Primitive = 
			} else {
				 := d2scene.NewNode()
				.ID = fmt.Sprintf("%s:rough:%d", , )
				.Children = append(.Children, )
			}
			++
		}
	}
	if  == 0 {
		return nil, fmt.Errorf("scene: connection %q %s sketch arrowhead is empty", .ID, )
	}

	 := math.Atan2([1], [0])
	if ! {
		 += math.Pi
	}
	.Transform = d2scene.Translate(.X, .Y).Mul(d2scene.Rotate())
	return , nil
}