Skip to content

Commit

Permalink
Reverting slab changes
Browse files Browse the repository at this point in the history
  • Loading branch information
200sc committed May 4, 2017
1 parent 548da6f commit 3fd7331
Show file tree
Hide file tree
Showing 10 changed files with 98 additions and 77 deletions.
2 changes: 0 additions & 2 deletions dcel/off/load.go
Original file line number Diff line number Diff line change
Expand Up @@ -291,7 +291,5 @@ func decode(dc *dcel.DCEL, edges []*dcel.Edge,
ei++
}

dc.CorrectDirectionalityAll()

return dc, nil
}
7 changes: 1 addition & 6 deletions dcel/pointLoc/bench/slab/compEdge.go
Original file line number Diff line number Diff line change
@@ -1,8 +1,6 @@
package slab

import (
"fmt"

"github.com/200sc/go-compgeo/dcel"
"github.com/200sc/go-compgeo/geom"
"github.com/200sc/go-compgeo/search"
Expand Down Expand Up @@ -48,10 +46,7 @@ func (ce compEdge) Compare(i interface{}) search.CompareResult {
geom.F64eq(ce.Twin.X(), c.Twin.X()) && geom.F64eq(ce.Twin.Y(), c.Twin.Y()) {
return search.Equal
}
compX, err := ce.FindSharedPoint(c.Edge, 0)
if err != nil {
fmt.Println("Edges share no point on x axis", ce, c)
}
compX, _ := ce.FindSharedPoint(c.Edge, 0)
p1, _ := ce.PointAt(0, compX)
p2, _ := c.PointAt(0, compX)
if p1[1] < p2[1] {
Expand Down
13 changes: 6 additions & 7 deletions dcel/pointLoc/bench/slab/slabDecomp.go
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ func Decompose(dc *dcel.DCEL, bstType tree.Type) (pointLoc.LocatesPoints, error)
faceEdgeMap[e] = f
}
for e = e.Next; e != f.Outer; e = e.Next {
// This edge points right, in an outer face.
// This edge points right,
// Then this face lies beneath e.
if e.Origin.X() < e.Twin.Origin.X() {
faceEdgeMap[e] = f
Expand All @@ -50,11 +50,13 @@ func Decompose(dc *dcel.DCEL, bstType tree.Type) (pointLoc.LocatesPoints, error)
}
e = f.Inner
if e != nil {
if e.Origin.X() > e.Twin.Origin.X() {
if e.Origin.X() < e.Twin.Origin.X() {
faceEdgeMap[e] = f
}
for e = e.Next; e != f.Inner; e = e.Next {
if e.Origin.X() > e.Twin.Origin.X() {
// This edge points right,
// Then this face lies beneath e.
if e.Origin.X() < e.Twin.Origin.X() {
faceEdgeMap[e] = f
}
}
Expand Down Expand Up @@ -95,10 +97,7 @@ func Decompose(dc *dcel.DCEL, bstType tree.Type) (pointLoc.LocatesPoints, error)
// Remove all edges from the PersistentBST connecting to the left
// of the points
for _, e := range le {
err := ct.Delete(shellNode{compEdge{e.Twin}, search.Nil{}})
if err != nil {
fmt.Println(err, e.Twin)
}
ct.Delete(shellNode{compEdge{e.Twin}, search.Nil{}})
}
// Add all edges to the PersistentBST connecting to the right
// of the point
Expand Down
12 changes: 12 additions & 0 deletions dcel/pointLoc/slab/compEdge.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,18 @@ func (f face) Equals(e search.Equalable) bool {
return false
}

type faces struct {
f1, f2 *dcel.Face
}

func (fs faces) Equals(e search.Equalable) bool {
switch fs2 := e.(type) {
case faces:
return fs2.f1 == fs.f1 && fs2.f2 == fs.f2
}
return false
}

type shellNode struct {
k compEdge
v search.Equalable
Expand Down
71 changes: 36 additions & 35 deletions dcel/pointLoc/slab/slabDecomp.go
Original file line number Diff line number Diff line change
Expand Up @@ -31,37 +31,6 @@ func Decompose(dc *dcel.DCEL, bstType tree.Type) (pointLoc.LocatesPoints, error)
t := tree.New(bstType).ToPersistent()
pts := dc.VerticesSorted(0)

// For each edge, we need to know which face lies beneath it in its two
// faces.
faceEdgeMap := make(map[*dcel.Edge]*dcel.Face)
for _, f := range dc.Faces {
// walk each face
e := f.Outer
if e != nil {
if e.Origin.X() < e.Twin.Origin.X() {
faceEdgeMap[e] = f
}
for e = e.Next; e != f.Outer; e = e.Next {
// This edge points right, in an outer face.
// Then this face lies beneath e.
if e.Origin.X() < e.Twin.Origin.X() {
faceEdgeMap[e] = f
}
}
}
e = f.Inner
if e != nil {
if e.Origin.X() > e.Twin.Origin.X() {
faceEdgeMap[e] = f
}
for e = e.Next; e != f.Inner; e = e.Next {
if e.Origin.X() > e.Twin.Origin.X() {
faceEdgeMap[e] = f
}
}
}
}

i := 0
for i < len(pts) {
p := pts[i]
Expand Down Expand Up @@ -117,7 +86,7 @@ func Decompose(dc *dcel.DCEL, bstType tree.Type) (pointLoc.LocatesPoints, error)
// edge for a query represents that the query is below
// the edge,
fmt.Println("Adding", e)
ct.Insert(shellNode{compEdge{e}, face{faceEdgeMap[e]}})
ct.Insert(shellNode{compEdge{e}, faces{e.Face, e.Twin.Face}})
fmt.Println(ct)
}

Expand Down Expand Up @@ -148,10 +117,42 @@ func (spl *PointLocator) PointLocate(vs ...float64) (*dcel.Face, error) {
tree := spl.dp.AtInstant(vs[0])
fmt.Println("Tree found:")
fmt.Println(tree)

p := geom.Point{vs[0], vs[1], 0}

_, f2 := tree.SearchUp(p, 0)
e, f := tree.SearchDown(p, 0)
if e == nil {
fmt.Println("Location on empty tree")
return nil, nil
}
e2, f2 := tree.SearchUp(p, 0)
fmt.Println("Edges found", e, e2)
if geom.VerticalCompare(p, e.(compEdge)) == search.Greater {
fmt.Println(p, "is above edge", e)
return nil, nil
}

if geom.VerticalCompare(p, e2.(compEdge)) == search.Less {
fmt.Println(p, "is below edge", e2)
return nil, nil
}

// We then do PIP on each face, and return
// whichever is true, if any.
f3 := f.(faces)
f4 := f2.(faces)
faces := []*dcel.Face{f3.f1, f3.f2, f4.f1, f4.f2}

for _, f5 := range faces {
if f5 != spl.outerFace {
fmt.Println("Checking if face contains", p)
visualize.HighlightColor = visualize.CheckFaceColor
visualize.DrawFace(f5)
if f5.Contains(p) {
fmt.Println("P was contained")
return f5, nil
}
}
}

return f2.(face).Face, nil
return nil, nil
}
14 changes: 12 additions & 2 deletions dcel/pointLoc/test/point-loc_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ import (
var (
inputSize = 25
inputRange = 10000.0
testCt = 500
testCt = 10000
slabErrors = 0
trapErrors = 0
rtreeErrors = 0
Expand Down Expand Up @@ -62,7 +62,7 @@ func TestRandomDCELSlab(t *testing.T) {

func TestDCELSlabErrors(t *testing.T) {
errCt := 0
subTestCt := 50
subTestCt := 100
for i := 0; i < testCt; i++ {
inputSize = 2
dc := dcel.Random2DDCEL(inputRange, inputSize)
Expand Down Expand Up @@ -291,3 +291,13 @@ func BenchmarkAdditional(b *testing.B) {
b.Run("TrapSetup", BenchmarkRandomSetupTrapezoid)
}
}

func BenchmarkSlab(b *testing.B) {
for i := 0; i < 1000; i += 16 {
inputSize = i
seed = time.Now().UnixNano()
fmt.Println("InputSize:", i)
b.Run("SlabSetup", BenchmarkRandomSetupSlab)
b.Run("Slab", BenchmarkRandomDCELSlab)
}
}
2 changes: 0 additions & 2 deletions demo/demo/addFace.go
Original file line number Diff line number Diff line change
Expand Up @@ -103,7 +103,6 @@ func addFace(cID int, ev interface{}) int {
if consumedEdge.Face != phd.Faces[dcel.OUTER_FACE] {
consumedEdge = consumedEdge.Twin
check = consumedEdge.Prev
fmt.Println("Sawp")
}
consumedEdge.Face = addedFace

Expand All @@ -115,7 +114,6 @@ func addFace(cID int, ev interface{}) int {
// doesn't, because we're defining the points clockwise,
// we'll loop forever down the line.
consumedEdge.SetPrev(prevEdge)
fmt.Println("T case")
}

prevEdge = consumedEdge
Expand Down
12 changes: 12 additions & 0 deletions demo/demo2.off
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
OFF
6 4 18
0 101.5 843.42
168 179.5 843.42
124 28.5 843.42
260 0 843.42
414 44.75 843.42
419 177.75 843.42
3 0 1 2
3 3 2 1
3 4 3 1
3 5 4 1
8 changes: 8 additions & 0 deletions demo/demo3.off
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
OFF
4 2 10
0 1.3477 19.595
120.36 53.845 19.595
124.89 0 19.595
240.28 40.826 19.595
3 0 1 2
3 3 2 1
34 changes: 11 additions & 23 deletions demo/test11.off
Original file line number Diff line number Diff line change
@@ -1,25 +1,13 @@
OFF
16 7 44
8 3 20
0 0 0
0 385.07 0
385.07 385.07 0
385.07 0 0
0 38.507 0
385.07 346.56 0
38.507 69.312 0
385.07 381.21 0
73.162 97.037 0
73.162 100.5 0
0 3.8507 0
385.07 311.9 0
38.507 385.07 0
0 73.162 0
41.972 72.431 0
73.162 385.07 0
4 10 11 3 0
4 8 9 7 5
3 12 13 1
4 9 8 6 14
6 11 10 4 6 8 5
5 14 15 2 7 9
6 15 14 6 4 13 12
0 10000 0
10000 10000 0
10000 0 0
10000 1215 0
0 2682.3 0
0 777.34 0
2183.1 2362 0
5 7 5 1 2 4
5 6 7 4 3 0
3 7 6 5

0 comments on commit 3fd7331

Please sign in to comment.