cmp/internal/diff/diff.go
func (p *path) connect(dst point, f EqualFunc) {
	if p.dir > 0 {
		// Connect in forward direction.
		for dst.X > p.X && dst.Y > p.Y {
			switch r := f(p.X, p.Y); {
			case r.Equal():
				p.append(Identity)
			case r.Similar():
				p.append(Modified)
			case dst.X-p.X >= dst.Y-p.Y:
				p.append(UniqueX)
			default:
				p.append(UniqueY)
			}
		}
		for dst.X > p.X {
			p.append(UniqueX)
		}
		for dst.Y > p.Y {
			p.append(UniqueY)
		}
	} else {
		// Connect in reverse direction.
		for p.X > dst.X && p.Y > dst.Y {
			switch r := f(p.X-1, p.Y-1); {
			case r.Equal():
				p.append(Identity)
			case r.Similar():
				p.append(Modified)
			case p.Y-dst.Y >= p.X-dst.X:
				p.append(UniqueY)
			default:
				p.append(UniqueX)
			}
		}
		for p.X > dst.X {
			p.append(UniqueX)
		}
		for p.Y > dst.Y {
			p.append(UniqueY)
		}
	}
}
func (p *path) connect(dst point, f EqualFunc) {
	if p.dir > 0 {
		// Connect in forward direction.
		for dst.X > p.X && dst.Y > p.Y {
			switch r := f(p.X, p.Y); {
			case r.Equal():
				p.append(Identity)
			case r.Similar():
				p.append(Modified)
			case dst.X-p.X >= dst.Y-p.Y:
				p.append(UniqueX)
			default:
				p.append(UniqueY)
			}
		}
		for dst.X > p.X {
			p.append(UniqueX)
		}
		for dst.Y > p.Y {
			p.append(UniqueY)
		}
	} else {
		// Connect in reverse direction.
		for p.X > dst.X && p.Y > dst.Y {
			switch r := f(p.X-1, p.Y-1); {
			case r.Equal():
				p.append(Identity)
			case r.Similar():
				p.append(Modified)
			case p.Y-dst.Y >= p.X-dst.X:
				p.append(UniqueY)
			default:
				p.append(UniqueX)
			}
		}
		for p.X > dst.X {
			p.append(UniqueX)
		}
		for p.Y > dst.Y {
			p.append(UniqueY)
		}
	}
}
func ( p * path ) connect ( dst point , f EqualFunc ) { if p . dir > 0 { // Connect in forward direction. for dst . X > p . X && dst . Y > p . Y { switch r := f ( p . X , p . Y ) ; { case r . Equal ( ) : p . append ( Identity ) case r . Similar ( ) : p . append ( Modified ) case dst . X - p . X >= dst . Y - p . Y : p . append ( UniqueX ) default : p . append ( UniqueY ) } } for dst . X > p . X { p . append ( UniqueX ) } for dst . Y > p . Y { p . append ( UniqueY ) } } else { // Connect in reverse direction. for p . X > dst . X && p . Y > dst . Y { switch r := f ( p . X - 1 , p . Y - 1 ) ; { case r . Equal ( ) : p . append ( Identity ) case r . Similar ( ) : p . append ( Modified ) case p . Y - dst . Y >= p . X - dst . X : p . append ( UniqueY ) default : p . append ( UniqueX ) } } for p . X > dst . X { p . append ( UniqueX ) } for p . Y > dst . Y { p . append ( UniqueY ) } } }
// connect appends any necessary Identity, Modified, UniqueX, or UniqueY types
// to the edit-script to connect p.point to dst.
connect appends any necessary Identity Modified UniqueX or UniqueY types to the edit - script to connect p . point to dst .