public void AssertThat_FromWorld_ToWorld_AreIdentityFunction() { //Generate a random load of points var rand = new Random(); var points = new List <Vector2>(); for (int i = 0; i < 20; i++) { points.Add(rand.RandomNormalVector().XZ() * (float)rand.NextDouble() * 50); } //Calculate OABR var oabr = OABR.Fit(points); //Draw it var svg = new SvgBuilder(2); var hull = points.ConvexHull().ToArray(); svg.Outline(hull, "green"); svg.Outline((IReadOnlyList <Vector2>)oabr.Points(new Vector2[4])); foreach (var vector2 in points) { svg.Circle(vector2, 1, oabr.Contains(vector2) ? "red" : "blue"); } Console.WriteLine(svg.ToString()); //Assert that every point lies within the bounds foreach (var vector2 in points) { var trans = oabr.FromWorld(vector2); var world = oabr.ToWorld(trans); Assert.IsTrue(vector2.TolerantEquals(world, 0.001f), string.Format("Expected {0} and {1} to be equal", vector2, world)); } }
public void AssertThat_AllPointsLiesInBounds_WithRandomShape() { //Generate a random load of points var rand = new Random(); var points = new List <Vector2>(); for (int i = 0; i < 20; i++) { points.Add(rand.RandomNormalVector().XZ() * (float)rand.NextDouble() * 50); } //Calculate OABR var oabr = OABR.Fit(points); //Draw it var svg = new SvgBuilder(2); var hull = points.ConvexHull().ToArray(); svg.Outline(hull, "green"); svg.Outline((IReadOnlyList <Vector2>)oabr.Points(new Vector2[4])); foreach (var vector2 in points) { svg.Circle(vector2, 1, oabr.Contains(vector2) ? "red" : "blue"); } Console.WriteLine(svg.ToString()); //Assert that every point lies within the bounds Assert.IsTrue(points.All(p => oabr.Contains(p))); }
private static void DrawArmature(Armature2D armature, IReadOnlyList <float> solution, Vector2 target) { var builder = new SvgBuilder(10); builder.Outline(new[] { new Vector2(-50, -50), new Vector2(50, -50), new Vector2(50, 50), new Vector2(-50, 50), }); var index = 0; var pos = Vector2.Zero; var parentTransform = Matrix4x4.Identity; foreach (var bone in armature.Bones) { builder.Circle(pos, 0.5f, "yellow"); var localTransform = TriangulationSolver2D.CalculateLocalTransform(bone, ToRadians(solution[index])); parentTransform = localTransform * parentTransform; var end = Vector2.Transform(new Vector2(0, 0), parentTransform); index++; builder.Line(pos, end, 2, "red"); pos = end; } builder.Circle(target, 0.5f, "blue"); var str = Regex.Replace(builder.ToString(), "g transform=\"translate\\((.+?), (.+?)\\)\"", "g transform=\"translate(${1}, 100) scale(1, -1)\""); Console.WriteLine(str); }
private static void DrawTreemap <T>(Node <T> root) where T : ITreemapNode { var svg = new SvgBuilder(50); RecursiveAssert(root, p => { svg.Outline(p.Bounds.GetCorners()); }); Console.WriteLine(svg.ToString()); }
public static string FloorplanToSvg(IFloorPlanBuilder plan, float scalePosition = 1, bool basic = false) { var builder = new SvgBuilder(scalePosition); builder.Outline(plan.ExternalFootprint, "black", "rgba(10, 10, 10, 0.25)"); foreach (var room in plan.Rooms) { builder.Outline(room.OuterFootprint, fill: "cornflowerblue"); } foreach (var room in plan.Rooms) { if (basic) { builder.Outline(room.InnerFootprint, fill: "lightsteelblue"); } else { var walls = room.GetWalls(); foreach (var facade in walls) { builder.Outline(new[] { facade.Section.Inner1, facade.Section.Inner2, facade.Section.Outer1, facade.Section.Outer2 }, facade.IsExternal ? "yellow" : "blue", "dimgray"); } var corners = room.GetCorners(); foreach (var corner in corners) { builder.Outline(corner, "royalblue", "navyblue"); } } } return(builder.ToString()); }