public void ComplexDatatypeCreate() { var points = new NamedPoint[10]; for (int i = 0; i < 10; i++) { var p = new NamedPoint {point = {x = i*2, y = i*3}}; var name = Encoding.ASCII.GetBytes(i.ToString()); unsafe { Marshal.Copy(name, 0, (IntPtr)p.name, name.Length); } points[i] = p; } using (var file = new H5File(TEST_FILE)) { var stringType = file.CreateDatatype("STRING", H5T.H5TClass.STRING, 40); var pointType = file.CreateDatatype("POINT", new[] {"x", "y"}, new[] { new H5Datatype(H5T.H5Type.NATIVE_DOUBLE), new H5Datatype(H5T.H5Type.NATIVE_DOUBLE) }); var type = file.CreateDatatype("NAMED_POINT", new[] {"name", "point"}, new[] {stringType, pointType}); var dataset = file.AddDataset("points", type, points); Assert.AreEqual(points, dataset.GetData<NamedPoint>()); } }
public static void Main() { var p1 = new NamedPoint("A", 0, 0); Console.WriteLine($"{nameof(p1)}: {p1}"); // output: p1: NamedPoint { Name = A, X = 0, Y = 0 } var p2 = p1 with { Name = "B", X = 5 }; Console.WriteLine($"{nameof(p2)}: {p2}"); // output: p2: NamedPoint { Name = B, X = 5, Y = 0 } var p3 = p1 with { Name = "C", Y = 4 }; Console.WriteLine($"{nameof(p3)}: {p3}"); // output: p3: NamedPoint { Name = C, X = 0, Y = 4 } Console.WriteLine($"{nameof(p1)}: {p1}"); // output: p1: NamedPoint { Name = A, X = 0, Y = 0 } var apples = new { Item = "Apples", Price = "1.19" }; Console.WriteLine($"original apples: {apples}"); var saleApples = apples with { Price = "0.79" }; Console.WriteLine($"sale apples: {saleApples}"); } }
public static bool PointWithinRectangle(int x, int y, int width, int height, NamedPoint point) { if (point == null) { return(false); } var pointX = point.X; var pointY = point.Y; if (pointX < x) { return(false); } if (pointY < y) { return(false); } var outerX = x + width; if (pointX > outerX) { return(false); } var outerY = y + height; if (pointY > outerY) { return(false); } return(true); }
public void TestMagnitude() { // we use a 5-12-13 triangle because that gives us a whole number answer NamedPoint p1 = new NamedPoint("p1", 5, 12); Assert.AreEqual(13, p1.GetMagnitude()); }
public void TestFromString_ExtraSpace() { NamedPoint c = NamedPoint.Parse(" random , 10 , 20 "); Assert.AreEqual("random", c.GetName()); Assert.AreEqual(10, c.GetX()); Assert.AreEqual(20, c.GetY()); }
public void TestGetXYZ() { NamedPoint p1 = new NamedPoint("p1", 10, 20); Assert.AreEqual("p1", p1.GetName()); Assert.AreEqual(10, p1.GetX()); Assert.AreEqual(20, p1.GetY()); }
public bool Insert(NamedPoint point) { var pointInBounds = PointWithinSquare(point); if (pointInBounds == false) { return(false); } // If not point has been added yet if (this.Point == null && this.NorthWest == null) { this.Point = point; return(true); } Stack <NamedPoint> stack = new Stack <NamedPoint>(); stack.Push(point); // Otherwise subdivide if (this.NorthWest == null) { stack.Push(this.Point); this.Point = null; SubDivide(); } // Redistribute points while (stack.Count > 0) { NamedPoint nextPoint = stack.Pop(); if (this.NorthWest.Insert(nextPoint) == true) { continue; } if (this.NorthEast.Insert(nextPoint) == true) { continue; } if (this.SouthWest.Insert(nextPoint) == true) { continue; } if (this.SouthEast.Insert(nextPoint) == true) { continue; } // An error has occured throw new InvalidOperationException(); //return false; } return(true); }
private void ProcessLine(string line) { try { db.AddItem(NamedPoint.Parse(line)); } catch (Exception ex) { Console.Error.WriteLine("Error: {0}", ex); } }
public static void Main() { Point p1 = new NamedPoint("A", 0, 0); Point p2 = p1 with { X = 5, Y = 3 }; Console.WriteLine(p2 is NamedPoint); // output: True Console.WriteLine(p2); // output: NamedPoint { X = 5, Y = 3, Name = A } } }
public void DrawQuadTree(int length, int totalPoints) { Display.Width = length; Display.Height = length; //List<NamedPoint> points = new List<NamedPoint>(); //points.Add(new NamedPoint("A", 40, 45)); //points.Add(new NamedPoint("B", 15, 70)); //points.Add(new NamedPoint("C", 70, 10)); //points.Add(new NamedPoint("D", 69, 50)); //points.Add(new NamedPoint("E", 55, 80)); //points.Add(new NamedPoint("F", 80, 90)); quadTree = new QuadTree(0, 0, length); //string initial = quadTree.ToString(); int seed = 100; Random random = new Random(seed); //Random random = new Random(); char nextChar = 'A'; for (int i = 0; i < totalPoints; i++) { int x = random.Next(0, length); int y = random.Next(0, length); NamedPoint point = new NamedPoint(nextChar.ToString(), x, y); quadTree.Insert(point); nextChar = (char)(Convert.ToUInt16(nextChar) + 1); } //foreach (NamedPoint point in points) //{ // quadTree.Insert(point); //} //string final = quadTree.ToString(); //Console.Write(final); if (Display.Image == null) { Display.Image = new Bitmap(length, length); } Graphics graphics = Graphics.FromImage(Display.Image); quadTree.Draw(graphics); }
public static bool IsValid(string candidate) { string[] candidateParts = candidate.Split('/'); if (candidateParts.Length != 2) { return(false); } var pointPart = candidateParts[0]; var speedLevelPart = candidateParts[1]; // Check point part for each category and check speed level part. return(SpeedLevel.IsValid(speedLevelPart) && (NavaidPoint.IsValid(pointPart) || CoordinatePoint.IsValid(pointPart) || NamedPoint.IsValid(pointPart))); }
public static void Main() { var p1 = new NamedPoint("A", 0, 0); Console.WriteLine($"{nameof(p1)}: {p1}"); // output: p1: NamedPoint { Name = A, X = 0, Y = 0 } var p2 = p1 with { Name = "B", X = 5 }; Console.WriteLine($"{nameof(p2)}: {p2}"); // output: p2: NamedPoint { Name = B, X = 5, Y = 0 } var p3 = p1 with { Name = "C", Y = 4 }; Console.WriteLine($"{nameof(p3)}: {p3}"); // output: p3: NamedPoint { Name = C, X = 0, Y = 4 } Console.WriteLine($"{nameof(p1)}: {p1}"); // output: p1: NamedPoint { Name = A, X = 0, Y = 0 } } }
public void TestFromString_BadRecord() { NamedPoint c = NamedPoint.Parse("// this is not a valid record"); }
public void TestToString() { NamedPoint p1 = new NamedPoint("p1", 1, 2); Assert.AreEqual("p1,1,2", p1.ToCsv()); }
public bool PointWithinSquare(NamedPoint point) { return(Program.PointWithinRectangle(this.Bounds.X, this.Bounds.Y, this.Bounds.Width, this.Bounds.Height, point)); }
public static bool PointWithinSquare(Rectangle bounds, NamedPoint point) { return(Program.PointWithinRectangle(bounds.X, bounds.Y, bounds.Width, bounds.Height, point)); }