package qualityimport ()func countNonSharedCrossings( []*layoutgraph.Edge, *limits.WorkGuard) (int64, error) {varint64for , := range {if := .Step(); != nil {return0, }for := + 1; < len(); ++ {// Charge every pair even when one route has no segments. Iterating a // large collection of incomplete routes is still quadratic work.if := .Step(); != nil {return0, } , := countEdgeCrossings(, [], )if != nil {return0, } += } }return , nil}func countEdgeCrossings(, *layoutgraph.Edge, *limits.WorkGuard) (int64, error) {varint64for := 0; < len(.Points)-1; ++ {if := .Step(); != nil {return0, }for := 0; < len(.Points)-1; ++ {if := .Step(); != nil {return0, }ifisNonSharedCrossing(, , , ) { ++ } } }return , nil}func isNonSharedCrossing(, *layoutgraph.Edge, , int) bool {if !nonParallelIntersection( .Points[], .Points[+1], .Points[], .Points[+1], ) {returnfalse }// Skip intersections at the exact end of the segment to avoid counting // bends off shared edges. := .Points[].X := .Points[].Yif == .Points[+1].X && ( == .Points[].X || == .Points[+1].X) {returnfalse }if == .Points[+1].Y && ( == .Points[].Y || == .Points[+1].Y) {returnfalse }returntrue}// orientation returns a positive value for a clockwise turn, a negative value// for a counter-clockwise turn, and zero for collinear points.func orientation(, , *geo.Point) float64 { := .X - .X := .Y - .Y := .X - .X := .Y - .Yreturn * - *}func equalSigns(, float64) bool {return > 0 && > 0 || == 0 && == 0 || < 0 && < 0}// nonParallelIntersection reports whether segments ab and cd intersect at an// angle. Collinear overlap is intentionally not a crossing for layout scoring.func nonParallelIntersection(, , , *geo.Point) bool { := orientation(, , ) := orientation(, , )ifequalSigns(, ) {returnfalse } := orientation(, , ) := orientation(, , )return !equalSigns(, )}
The pages are generated with Goldsv0.8.7. (GOOS=linux GOARCH=amd64)
Golds is a Go 101 project developed by Tapir Liu.
PR and bug reports are welcome and can be submitted to the issue list.
Please follow @zigo_101 (reachable from the left QR code) to get the latest news of Golds.