public Face Search(Vertex vertex) { if (!Root.Face.Inside(vertex)) return null; return Search(Root, vertex).Face; }
public void Add(Vertex vertex, params Face[] faces ) { Node node = Search(Root, vertex); foreach (Face face in faces) { node.Children.Add(new Node(face)); } }
private Node Search(Node node, Vertex vertex) { foreach (Node childNode in node.Children) { if (childNode.Face.Inside(vertex)) { return Search(childNode, vertex); } } return node; }
public bool Inside(Vertex p) { int i, j = Vertices.Count - 1; bool oddNodes = false; for (i = 0; i < Vertices.Count; i++) { if (((Vertices[i].Y < p.Y && Vertices[j].Y >= p.Y) || (Vertices[j].Y < p.Y && Vertices[i].Y >= p.Y)) && (Vertices[i].X <= p.X || Vertices[j].X <= p.X)) oddNodes ^= Vertices[i].X + (p.Y - Vertices[i].Y)/(Vertices[j].Y - Vertices[i].Y)*(Vertices[j].X - Vertices[i].X) < p.X; j = i; } return oddNodes; }
public float Cross(Vertex v) { return X*v.Y - Y*v.X; }
public float DistanceSquared(Vertex vertex) { float dx = X - vertex.X; float dy = Y - vertex.Y; return dx*dx + dy*dy; }
public float ManhattanDistance(Vertex vertex) => Convert.ToSingle(Math.Abs(X - vertex.X) + Math.Abs(Y - vertex.Y));
public float Distance(Vertex vertex) => Convert.ToSingle(Math.Sqrt(DistanceSquared(vertex)));
public bool Equals(Vertex v) { return this.X == v.X && this.Y == v.Y; }
public Vertex(Vertex v) { X = v.X; Y = v.Y; }
public static float Distance(Vertex v1, Vertex v2) { return Convert.ToSingle(Math.Sqrt((v2.X - v1.X)*(v2.X - v1.X) + (v2.Y - v1.Y)*(v2.Y - v1.Y))); }
public static float Slope(Vertex v1, Vertex v2) { float value = (v2.Y - v1.Y)/(v2.X - v1.X); return value; }
public static Vertex Midpoint(Vertex v1, Vertex v2) { float mx = v1.X/2 + v2.X/2; float my = v1.Y/2 + v2.Y/2; return new Vertex(mx, my); }
public bool Contains(Vertex vertex) { return Vertices.Contains(vertex); }
public Edge(Vertex v1, Vertex v2) { V1 = v1; V2 = v2; }