Skip to content

Commit

Permalink
Fix #3. Hope it doesn't break anything else...
Browse files Browse the repository at this point in the history
  • Loading branch information
akavel committed Oct 9, 2014
1 parent 56adf40 commit 6940d51
Showing 1 changed file with 28 additions and 18 deletions.
46 changes: 28 additions & 18 deletions clipper.go
Original file line number Diff line number Diff line change
Expand Up @@ -108,30 +108,40 @@ func (c *clipper) compute(operation Op) Polygon {

MINMAX_X := math.Min(subjectbb.Max.X, clippingbb.Max.X)

_DBG(func() {
e := c.eventQueue.dequeue()
c.eventQueue.enqueue(e)
fmt.Print("\nInitial queue:\n")
for i, e := range c.eventQueue.elements {
fmt.Println(i, "=", *e)
}
})

for !c.eventQueue.IsEmpty() {
var prev, next *endpoint
e := c.eventQueue.dequeue()
_DBG(func() { fmt.Print("\nProcess event:\n", *e, "\n") })
_DBG(func() { fmt.Printf("\nProcess event: (of %d)\n%v\n", len(c.eventQueue.elements)+1, *e) })

// optimization 1
switch {
case operation == INTERSECTION && e.p.X > MINMAX_X:
fallthrough
case operation == DIFFERENCE && e.p.X > subjectbb.Max.X:
return connector.toPolygon()
case operation == UNION && e.p.X > MINMAX_X:
// add all the non-processed line segments to the result
if !e.left {
connector.add(e.segment())
}

for !c.eventQueue.IsEmpty() {
e = c.eventQueue.dequeue()
if !e.left {
connector.add(e.segment())
}
}
return connector.toPolygon()
//case operation == UNION && e.p.X > MINMAX_X:
// _DBG(func() { fmt.Print("\nUNION optimization, fast quit\n") })
// // add all the non-processed line segments to the result
// if !e.left {
// connector.add(e.segment())
// }
//
// for !c.eventQueue.IsEmpty() {
// e = c.eventQueue.dequeue()
// if !e.left {
// connector.add(e.segment())
// }
// }
// return connector.toPolygon()
}

if e.left { // the line segment must be inserted into S
Expand Down Expand Up @@ -376,10 +386,10 @@ func (c *clipper) possibleIntersection(e1, e2 *endpoint) {
return // the line segments intersect at an endpoint of both line segments
}

//if numIntersections == 2 && e1.p.Equals(e2.p) {
if numIntersections == 2 && e1.polygonType == e2.polygonType {
return // the line segments overlap, but they belong to the same polygon
}
////if numIntersections == 2 && e1.p.Equals(e2.p) {
//if numIntersections == 2 && e1.polygonType == e2.polygonType {
// return // the line segments overlap, but they belong to the same polygon
//}

if numIntersections == 1 {
if !e1.p.Equals(ip1) && !e1.other.p.Equals(ip1) {
Expand Down

0 comments on commit 6940d51

Please sign in to comment.