MCPcopy Index your code
hub / github.com/tdewolff/canvas / addIntersections

Function addIntersections

path_intersection.go:1137–1230  ·  view source on GitHub ↗

type SweepPointPair [2]*SweepPoint func (pair SweepPointPair) Swapped() SweepPointPair { return SweepPointPair{pair[1], pair[0]} }

(zs []Point, queue *SweepEvents, event, a, b *SweepPoint)

Source from the content-addressed store, hash-verified

1135//}
1136
1137func addIntersections(zs []Point, queue *SweepEvents, event, a, b *SweepPoint) bool {
1138 // a and b are always left-endpoints and a is below b
1139 //pair := SweepPointPair{a, b}
1140 //if _, ok := handled[pair]; ok {
1141 // return
1142 //} else if _, ok := handled[pair.Swapped()]; ok {
1143 // return
1144 //}
1145 //handled[pair] = struct{}{}
1146
1147 //var a, b *SweepPoint
1148 //if prev == nil {
1149 // a, b = event, next.SweepPoint
1150 //} else if next == nil {
1151 // a, b = prev.SweepPoint, event
1152 //} else {
1153 // a, b = prev.SweepPoint, next.SweepPoint
1154 //}
1155
1156 // find all intersections between segment pair
1157 // this returns either no intersections, or one or more secant/tangent intersections,
1158 // or exactly two endpoint intersections which occurs when the segments overlap.
1159 zs = intersectionLineLineBentleyOttmann(zs[:0], a.Point, a.other.Point, b.Point, b.other.Point)
1160
1161 // no (valid) intersections
1162 if len(zs) == 0 {
1163 return false
1164 }
1165
1166 // Non-vertical but downwards-sloped segments may become vertical upon intersection due to
1167 // floating-point rounding and limited precision. Only the first segment of b can ever become
1168 // vertical, never the first segment of a:
1169 // - a and b may be segments in status when processing a right-endpoint. The left-endpoints of
1170 // both thus must be to the left of this right-endpoint (unless vertical) and can never
1171 // become vertical in their first segment.
1172 // - a is the segment of the currently processed left-endpoint and b is in status and above it.
1173 // a's left-endpoint is to the right of b's left-endpoint and is below b, thus:
1174 // - a and b go upwards: a nor b may become vertical, no reversal
1175 // - a goes downwards and b upwards: no intersection
1176 // - a goes upwards and b downwards: only a may become vertical but no reversal
1177 // - a and b go downwards: b may pass a's left-endpoint to its left (no intersection),
1178 // through it (tangential intersection, no splitting), or to its right so that a never
1179 // becomes vertical and thus no reversal
1180 // - b is the segment of the currently processed left-endpoint and a is in status and below it.
1181 // a's left-endpoint is below or to the left of b's left-endpoint and a is below b, thus:
1182 // - a and b go upwards: only a may become vertical, no reversal
1183 // - a goes downwards and b upwards: no intersection
1184 // - a goes upwards and b downwards: both may become vertical where only b must be reversed
1185 // - a and b go downwards: if b passes through a's left-endpoint, it must become vertical and
1186 // be reversed, or it passed to the right of a's left-endpoint and a nor b become vertical
1187 // Conclusion: either may become vertical, but only b ever needs reversal of direction. And
1188 // note that b is the currently processed left-endpoint and thus isn't in status.
1189 // Note: handle overlapping segments immediately by checking up and down status for segments
1190 // that compare equally with weak ordering (ie. overlapping).
1191
1192 if !event.left {
1193 // intersection may be to the left (or below) the current event due to floating-point
1194 // precision which would interfere with the sequence in queue, this is a problem when

Callers 2

bentleyOttmannFunction · 0.85
relateFunction · 0.85

Calls 2

splitAtIntersectionsFunction · 0.85

Tested by

no test coverage detected