Skip to content

Commit

Permalink
fixes
Browse files Browse the repository at this point in the history
  • Loading branch information
fogleman committed May 12, 2016
1 parent 719ab44 commit 4e27c2f
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 6 deletions.
6 changes: 6 additions & 0 deletions queue.go
Original file line number Diff line number Diff line change
Expand Up @@ -36,3 +36,9 @@ func (pq *PriorityQueue) Pop() interface{} {
func (pq *PriorityQueue) Fix(p *Pair) {
heap.Fix(pq, p.Index)
}

func (pq *PriorityQueue) Remove(p *Pair) {
if p.Index >= 0 {
heap.Remove(pq, p.Index)
}
}
15 changes: 9 additions & 6 deletions simplify.go
Original file line number Diff line number Diff line change
Expand Up @@ -61,10 +61,6 @@ func Simplify(input *Mesh) *Mesh {
// pop best pair
p := heap.Pop(&queue).(*Pair)

if p.A == p.B {
continue
}

// move A to best position
p.A.Vector = p.Vector()

Expand Down Expand Up @@ -111,11 +107,11 @@ func Simplify(input *Mesh) *Mesh {
// update pairs and prune current pair
vertexPairs[p.A] = nil
delete(vertexPairs, p.B)
seenPairs := make(map[PairKey]bool)
for q := range distinctPairs {
if q == p {
continue
}
// TODO: this produces duplicate pairs
if q.A == p.B {
q.A = p.A
}
Expand All @@ -124,8 +120,15 @@ func Simplify(input *Mesh) *Mesh {
}
queue.Fix(q)
if q.A == q.B {
queue.Remove(q)
continue
}
key := MakePairKey(q.A, q.B)
if _, ok := seenPairs[key]; ok {
queue.Remove(q)
continue
}
seenPairs[key] = true
vertexPairs[p.A] = append(vertexPairs[p.A], q)
}
}
Expand All @@ -134,7 +137,7 @@ func Simplify(input *Mesh) *Mesh {
distinctFaces := make(map[*Face]bool)
for _, faces := range vertexFaces {
for _, f := range faces {
if !f.Degenerate() {
if !f.Degenerate() { // TODO: why does this happen?
distinctFaces[f] = true
}
}
Expand Down

0 comments on commit 4e27c2f

Please sign in to comment.