private static void RunAssertion <L>( int numPoints, int numMoves, int queryFrameSize, SupportQuadTreeConfig config, SupportQuadTreeToolNonUnique <L> tools) { var random = new Random(); L quadTree = tools.factory.Invoke(config); var points = tools.generator.Generate(random, numPoints, config.X, config.Y, config.Width, config.Height); foreach (var point in points) { tools.adderNonUnique.Invoke(quadTree, point); } for (var i = 0; i < numMoves; i++) { SupportRectangleWithId moved = points[(random.Next(points.Count))]; Move(moved, quadTree, random, config, tools); var startX = moved.X - queryFrameSize; var startY = moved.Y - queryFrameSize; double widthQ = queryFrameSize * 2; double heightQ = queryFrameSize * 2; ICollection <object> values = tools.querier.Invoke(quadTree, startX, startY, widthQ, heightQ); AssertIds(points, values, startX, startY, widthQ, heightQ, tools.pointInsideChecking); } }
private static void Move <L>( SupportRectangleWithId rectangle, L quadTree, Random random, SupportQuadTreeConfig config, SupportQuadTreeToolNonUnique <L> tools) { tools.remover.Invoke(quadTree, rectangle); double newX; double newY; while (true) { int direction = random.Next(4); newX = rectangle.X; newY = rectangle.Y; if (direction == 0) { newX--; } else if (direction == 1) { newY--; } else if (direction == 2) { newX++; } else if (direction == 3) { newY++; } if (tools.pointInsideChecking) { if (BoundingBox.ContainsPoint(config.X, config.Y, config.Width, config.Height, newX, newY)) { break; } } else { if (BoundingBox.IntersectsBoxIncludingEnd(config.X, config.Y, config.MaxX, config.MaxY, newX, newY, rectangle.W, rectangle.H)) { break; } } } // Comment-me-in: // log.info("Moving " + point.getId() + " from " + printPoint(point.getX(), point.getY()) + " to " + printPoint(newX, newY)); rectangle.X = newX; rectangle.Y = newY; tools.adderNonUnique.Invoke(quadTree, rectangle); }
private static void RunAssertion <L>( int numPoints, int numQueries, SupportQuadTreeConfig config, SupportQuadTreeToolUnique <L> tools) { L quadTree = tools.factory.Invoke(config); // generate var random = new Random(); var rectangles = tools.generator.Generate(random, numPoints, config.X, config.Y, config.Width, config.Height); // add foreach (var rectangle in rectangles) { tools.adderUnique.Invoke(quadTree, rectangle); } // query for (var i = 0; i < numQueries; i++) { SupportQuadTreeUtil.RandomQuery( quadTree, rectangles, random, config.X, config.Y, config.Width, config.Height, tools.querier, tools.pointInsideChecking); } // remove point-by-point while (!rectangles.IsEmpty()) { int removeIndex = random.Next(rectangles.Count); SupportRectangleWithId removed = rectangles.DeleteAt(removeIndex); tools.remover.Invoke(quadTree, removed); for (var i = 0; i < numQueries; i++) { SupportQuadTreeUtil.RandomQuery( quadTree, rectangles, random, config.X, config.Y, config.Width, config.Height, tools.querier, tools.pointInsideChecking); } } }