public Example() { rw = new RenderWindow(new VideoMode(1600u, 900u), "Quadtree example", Styles.Close, new ContextSettings() { AntialiasingLevel = 8 }); rw.Closed += (s, a) => rw.Close(); //var view = rw.GetView(); //view.Move(new Vector2f(512f, 256f)); //rw.SetView(view); initQuadtree(); initInput(); position = getGUIPos(0.3f, 0.5f) - new Vector2f(quadtree.AABB.Width / 2f, quadtree.AABB.Height / 2f) * qtMultiplier; for (int i = 0; i < 1; i++) { // quadtree.ExpandFromCenter(); } lastRegions = quadtree.FindConnectedComponents(); lastRegions.Sort(new Comparison <List <RegionQuadtree <Color> > >((v1, v2) => v1.Count.CompareTo(v2.Count))); }
public void FindConnectedComponentsSmallerNeighborBotLeft() { var qt = new RegionQuadtree <int>(3); qt.Set(1); qt.Set(new Point2i(0, 0), 2); qt.Set(new Point2i(5, 0), 2); qt.Set(new Point2i(5, 5), 2); //qt.Set(new Point2i(1, 2), 1); var r = qt.FindConnectedComponents(); Assert.Equal(1, r.Count); }
public void FindConnectedComponentsTest() { var qt = new RegionQuadtree <int>(3); qt.Set(new Point2i(0, 0), 1); qt.Set(new Point2i(1, 0), 1); qt.Set(new Point2i(0, 2), 1); qt.Set(new Point2i(1, 2), 1); var r = qt.FindConnectedComponents(); Assert.Equal(2, r.Count); Assert.Equal(2, r[0].Count); Assert.Equal(2, r[1].Count); qt = new RegionQuadtree <int>(3); qt.Set(new Point2i(0, 0), 1); qt.Set(new Point2i(1, 0), 1); qt.Set(new Point2i(2, 0), 1); qt.Set(new Point2i(2, 1), 1); qt.Set(new Point2i(2, 2), 1); qt.Set(new Point2i(2, 3), 1); r = qt.FindConnectedComponents(); Assert.Equal(1, r.Count); Assert.Equal(6, r[0].Count); qt = new RegionQuadtree <int>(3); qt.Set(new Point2i(0, 0), 1); qt.Set(new Point2i(2, 0), 1); qt.Set(new Point2i(4, 0), 1); qt.Set(new Point2i(0, 2), 1); qt.Set(new Point2i(2, 2), 1); qt.Set(new Point2i(4, 2), 1); r = qt.FindConnectedComponents(); Assert.Equal(6, r.Count); for (int i = 0; i < 6; i++) { Assert.Equal(1, r[i].Count); } }