/// <summary> /// Get the vertices along the specified edge of a square topography. /// </summary> /// <param name="direction">The edge of vertices to return.</param> /// <returns>A collection of vertices.</returns> public Vertex[] GetEdgeVertices(Units.CardinalDirection direction) { var range = Enumerable.Range(0, this.RowWidth); var start = 0; var increment = 1; switch (direction) { case Units.CardinalDirection.North: start = this.Mesh.Vertices.Count - this.RowWidth; break; case Units.CardinalDirection.South: start = 0; break; case Units.CardinalDirection.East: start = this.RowWidth - 1; increment = this.RowWidth; break; case Units.CardinalDirection.West: start = 0; increment = this.RowWidth; break; default: return(null); } return(range.Select(i => this.Mesh.Vertices[start + i * increment]).ToArray()); }
/// <summary> /// Average the vertex placement along the specified edge /// of this topography with the vertex placement along the /// corresponding edge of a target topography. /// </summary> /// <param name="target"></param> /// <param name="edgeToAverage"></param> public void AverageEdges(Topography target, Units.CardinalDirection edgeToAverage) { if (this.RowWidth != target.RowWidth) { throw new ArgumentException("The specified topographies do not have the same number of vertices."); } Vertex[] e1 = null; Vertex[] e2 = null; switch (edgeToAverage) { case Units.CardinalDirection.North: e1 = this.GetEdgeVertices(Units.CardinalDirection.North); e2 = target.GetEdgeVertices(Units.CardinalDirection.South); break; case Units.CardinalDirection.South: e1 = this.GetEdgeVertices(Units.CardinalDirection.South); e2 = target.GetEdgeVertices(Units.CardinalDirection.North); break; case Units.CardinalDirection.East: e1 = this.GetEdgeVertices(Units.CardinalDirection.East); e2 = target.GetEdgeVertices(Units.CardinalDirection.West); break; case Units.CardinalDirection.West: e1 = this.GetEdgeVertices(Units.CardinalDirection.West); e2 = target.GetEdgeVertices(Units.CardinalDirection.East); break; } for (var i = 0; i < e1.Length; i++) { var pos = e1[i].Position.Average(e2[i].Position); e1[i].Position = pos; e2[i].Position = pos; } }