public void SplitPoly(Polygon p) { foreach (Coord c in p.coords) { this.listX.Add(c.X); this.listY.Add(c.Y); } }
public void ExtremeCoordCalc_ExtremePoly_SimpleDiamond() { // Create a simple diamond poly around the axis Polygon p = new Polygon(); p.AddCoord(0,1); // North p.AddCoord(2,0); // East p.AddCoord(0,-3); // South p.AddCoord(-4,0); // West ExtremeCoordCalc calc = new ExtremeCoordCalc(p); Polygon extreme = calc.GetExtremeBounds(); // Grab coords off extreme poly Coord a = (Coord)extreme.coords[0]; Coord b = (Coord)extreme.coords[1]; Coord c = (Coord)extreme.coords[2]; Coord d = (Coord)extreme.coords[3]; // Assert Assert.AreEqual(-54, a.X); Assert.AreEqual(51, a.Y); Assert.AreEqual(52, b.X); Assert.AreEqual(51, b.Y); Assert.AreEqual(52, c.X); Assert.AreEqual(-53, c.Y); Assert.AreEqual(-54, d.X); Assert.AreEqual(-53, d.Y); }
public void FindMinMax(Polygon p) { // Check if there are no points to the poly if (p.coords.Count == 0) { throw new System.Exception("Polygon has no points."); } // Loop through the coords and test each against the max/min conditions foreach (Coord c in p.coords) { // Test min X if (c.X < this.minX) { this.minX = c.X; } // Test max X if (c.X > this.maxX) { this.maxX = c.X; } // Test min Y if (c.Y < this.minY) { this.minY = c.Y; } // Test max Y if (c.Y > this.maxY) { this.maxY = c.Y; } } }
public virtual void SetExtreme(Polygon p) { if (p.coords.Count < 3) { throw new Exception("Polygon requires 3 or more vertacies"); } else { this.exteme = p; } }
private void SetPolygon(Polygon p) { if (p.coords.Count < 3) { Console.WriteLine("Derp"); throw new Exception("Polygon must have atleast 3 vertacies."); } else { this.poly = p; } }
public NearestNeighbour(Polygon e, Polygon a, double r) { try { this.SetArea(a); this.SetExtreme(e); this.SetResolution(r); } catch (Exception ex) { throw ex; } }
public PointInPolygon(Polygon p, double x, double y) { try { this.SetPolygon(p); this.testX = x; this.testY = y; } catch (Exception e) { Console.WriteLine("Derp"); throw e; } }
public void RayCasting_SimpleDiamond_Pass() { Polygon p = new Polygon(); p.AddCoord(0,1); p.AddCoord(1,0); p.AddCoord(-1,0); p.AddCoord(0,-1); Console.WriteLine("w---t"); try { PointInPolygon pip = new PointInPolygon(p, 0, 0); bool result = pip.Verify(); Assert.AreEqual(true, result); } catch (Exception e) { Console.WriteLine("Exception: " + e.Message); Assert.Fail("No exception expected"); } }
public void Polygon_Add3Coords() { // Create Coords to add to Polygon Coord a = new Coord(1,2); Coord b = new Coord(3,4); Coord c = new Coord(5,6); // Create poly and add coords Polygon poly = new Polygon(); poly.AddCoord(a); poly.AddCoord(b); poly.AddCoord(c); // Check coords Assert.AreEqual(a,poly.coords[0]); Assert.AreEqual(b,poly.coords[1]); Assert.AreEqual(c,poly.coords[2]); }
public void Polygon_Add3Points() { // Create poly and add points Polygon poly = new Polygon(); poly.AddCoord(1,2); poly.AddCoord(3,4); poly.AddCoord(5,6); // Create coords from poly Coord a = (Coord)poly.coords[0]; Coord b = (Coord)poly.coords[1]; Coord c = (Coord)poly.coords[2]; // Examine coords and assert Assert.AreEqual(1, a.X); Assert.AreEqual(2, a.Y); Assert.AreEqual(3, b.X); Assert.AreEqual(4, b.Y); Assert.AreEqual(5, c.X); Assert.AreEqual(6, c.Y); }
public void ExtremeCoordCalc_Constructor_A() { // Create simple poly Polygon p = new Polygon(); p.AddCoord(1,2); p.AddCoord(3,4); // Create ExtremeCoordcalc ExtremeCoordCalc calc = new ExtremeCoordCalc(p); // Grab the coords from the original poly Coord a = (Coord)calc.original.coords[0]; Coord b = (Coord)calc.original.coords[1]; // Assert Assert.AreEqual(1,a.X); Assert.AreEqual(2,a.Y); Assert.AreEqual(3,b.X); Assert.AreEqual(4,b.Y); Assert.AreEqual(50, calc.bound); }
public ExtremeCoordCalc(Polygon p, double bound) { this.bound = bound; this.original = p; }
public ExtremeCoordCalc(Polygon p) { this.original = p; }
public void ExtremeCoordCalc_FindMinMax_SimpleDiamond() { // Create a simple diamond poly around the axis Polygon p = new Polygon(); p.AddCoord(0,1); // North p.AddCoord(2,0); // East p.AddCoord(0,-3); // South p.AddCoord(-4,0); // West ExtremeCoordCalc calc = new ExtremeCoordCalc(p); calc.FindMinMax(calc.original); // Assert Assert.AreEqual(1, calc.maxY); Assert.AreEqual(2, calc.maxX); Assert.AreEqual(-3, calc.minY); Assert.AreEqual(-4, calc.minX); }
public ArrayList GetMetStation(Polygon extreme) { // Set X/Y Min/Max based on extreme coords poly // Loop through for more redundancy double maxX = 0; double minX = 200; double maxY = 0; double minY = 200; // TODO: Refactor this statement foreach (Coord c in extreme.coords) { // Test min X if (c.X < minX) { minX = c.X; } // Test max X if (c.X > maxX) { maxX = c.X; } // Test min Y if (c.Y < minY) { minY = c.Y; } // Test max Y if (c.Y > maxY) { maxY = c.Y; } } // Set up Query string query = "SELECT * FROM stations WHERE (longitude BETWEEN " + minY + " AND " + maxY + ") AND (latitude BETWEEN " + minX + " AND " + maxX + ");"; ArrayList list = new ArrayList(); MetStation station = null; try { this.OpenConnection(); SqliteDataReader reader = this.ExecuteQuery(query); while (reader.Read()) { station = new MetStation(reader.GetInt32(0), reader.GetString(1), reader.GetString(2), reader.GetString(3), reader.GetString(4), reader.GetDouble(5), reader.GetDouble(6), reader.GetDouble(7)); list.Add(station); } // Close reader and connection reader.Close(); reader = null; this.CloseConnection(); // No rows returned if (station == null) { throw new Exception("No MetSations match those parameters."); } else { // Add weather data to each station foreach (MetStation ms in list) { ms.weatherData = this.GetWeatherData(ms.rowid); } } return list; } catch (Exception e) { throw e; } }
public override ArrayList GenerateCells(Polygon a, double r) { ArrayList cells = new ArrayList(); return cells; }
public abstract ArrayList GenerateCells(Polygon a, double r);
public Polygon GetExtremeBounds() { // Max X, Min X, Max Y and Min Y in the original poly. try { this.FindMinMax(this.original); } catch (Exception e) { // If poly has no points, throw it up the stack throw e; } // Expand bounds this.minX += -bound; this.maxX += bound; this.minY += -bound; this.maxY += bound; // Create new poly Polygon extreme = new Polygon(); extreme.AddCoord(minX,maxY); extreme.AddCoord(maxX,maxY); extreme.AddCoord(maxX,minY); extreme.AddCoord(minX,minY); return extreme; }
public void ExtremeCoordCalc_NoPointPoly() { // Create a poly and add no points Polygon poly = new Polygon(); ExtremeCoordCalc calc = new ExtremeCoordCalc(poly); try { calc.GetExtremeBounds(); Assert.Fail("Exception expected"); } catch (Exception e) { } }