package gg type Liner interface { Line() Line } type LinerPointContainer interface { Liner PointContainer } // The type represents the cross of 2 Liners. type LineCross struct { Pair [2]Line Point Point } // Check if two LinerPointContainers do cross and return the // crossing point. func LinersCross(lp1, lp2 LinerPointContainer) (LineCross, bool) { l1 := lp1.Line() l2 := lp2.Line() crossPt, doCross := l1.crossesLine(l2) if !doCross || len(lp1.ContainedPoints([]Point{crossPt}))==0 || len(lp2.ContainedPoints([]Point{crossPt}))==0 { return LineCross{}, false } return LineCross{ Pair: [2]Line{l1, l2}, Point: crossPt, }, true } // Check whether the liner is parallel to the other liner. func LinersParallel(first, second Liner) bool { l1 := first.Line() l2 := second.Line() return l1.K == l2.K } // Returns angle between liners in radians. // The value fits the -Pi < Value < Pi condition. func LinersAngle(first, second Liner) Float { l1 := first.Line() l2 := second.Line() if l1.K == l2.K { return 0 } return Atan(l1.K/l2.K) }