From 3fd73313b30799abc4bee89106a78f507ba6747e Mon Sep 17 00:00:00 2001 From: StephenPatrick Date: Wed, 3 May 2017 20:14:18 -0500 Subject: [PATCH] Reverting slab changes --- dcel/off/load.go | 2 - dcel/pointLoc/bench/slab/compEdge.go | 7 +-- dcel/pointLoc/bench/slab/slabDecomp.go | 13 +++-- dcel/pointLoc/slab/compEdge.go | 12 +++++ dcel/pointLoc/slab/slabDecomp.go | 71 +++++++++++++------------- dcel/pointLoc/test/point-loc_test.go | 14 ++++- demo/demo/addFace.go | 2 - demo/demo2.off | 12 +++++ demo/demo3.off | 8 +++ demo/test11.off | 34 ++++-------- 10 files changed, 98 insertions(+), 77 deletions(-) create mode 100644 demo/demo2.off create mode 100644 demo/demo3.off diff --git a/dcel/off/load.go b/dcel/off/load.go index f864bc0..70ca9ee 100644 --- a/dcel/off/load.go +++ b/dcel/off/load.go @@ -291,7 +291,5 @@ func decode(dc *dcel.DCEL, edges []*dcel.Edge, ei++ } - dc.CorrectDirectionalityAll() - return dc, nil } diff --git a/dcel/pointLoc/bench/slab/compEdge.go b/dcel/pointLoc/bench/slab/compEdge.go index 79e42b9..21635fa 100644 --- a/dcel/pointLoc/bench/slab/compEdge.go +++ b/dcel/pointLoc/bench/slab/compEdge.go @@ -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" @@ -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] { diff --git a/dcel/pointLoc/bench/slab/slabDecomp.go b/dcel/pointLoc/bench/slab/slabDecomp.go index 9836311..63a9f04 100644 --- a/dcel/pointLoc/bench/slab/slabDecomp.go +++ b/dcel/pointLoc/bench/slab/slabDecomp.go @@ -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 @@ -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 } } @@ -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 diff --git a/dcel/pointLoc/slab/compEdge.go b/dcel/pointLoc/slab/compEdge.go index fece976..9e59987 100644 --- a/dcel/pointLoc/slab/compEdge.go +++ b/dcel/pointLoc/slab/compEdge.go @@ -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 diff --git a/dcel/pointLoc/slab/slabDecomp.go b/dcel/pointLoc/slab/slabDecomp.go index 0baacd5..dd41f3b 100644 --- a/dcel/pointLoc/slab/slabDecomp.go +++ b/dcel/pointLoc/slab/slabDecomp.go @@ -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] @@ -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) } @@ -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 } diff --git a/dcel/pointLoc/test/point-loc_test.go b/dcel/pointLoc/test/point-loc_test.go index bfd30cc..fd28ff3 100644 --- a/dcel/pointLoc/test/point-loc_test.go +++ b/dcel/pointLoc/test/point-loc_test.go @@ -22,7 +22,7 @@ import ( var ( inputSize = 25 inputRange = 10000.0 - testCt = 500 + testCt = 10000 slabErrors = 0 trapErrors = 0 rtreeErrors = 0 @@ -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) @@ -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) + } +} diff --git a/demo/demo/addFace.go b/demo/demo/addFace.go index 07653f3..5ff328b 100644 --- a/demo/demo/addFace.go +++ b/demo/demo/addFace.go @@ -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 @@ -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 diff --git a/demo/demo2.off b/demo/demo2.off new file mode 100644 index 0000000..6463b74 --- /dev/null +++ b/demo/demo2.off @@ -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 diff --git a/demo/demo3.off b/demo/demo3.off new file mode 100644 index 0000000..5ded604 --- /dev/null +++ b/demo/demo3.off @@ -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 diff --git a/demo/test11.off b/demo/test11.off index c163e3c..2172c78 100644 --- a/demo/test11.off +++ b/demo/test11.off @@ -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