public void GetLength() { XYPolyline xyPolyline = new XYPolyline(); xyPolyline.Points.Add(new XYPoint(6,2)); xyPolyline.Points.Add(new XYPoint(2,2)); xyPolyline.Points.Add(new XYPoint(8,2)); xyPolyline.Points.Add(new XYPoint(8,4)); xyPolyline.Points.Add(new XYPoint(5,4)); xyPolyline.Points.Add(new XYPoint(9,7)); Assert.AreEqual((double) 20, xyPolyline.GetLength()); }
private void panelViewer_MouseMove(object sender, System.Windows.Forms.MouseEventArgs e) { // write x and y coordinates double x = ((e.X - _margin) / _scale) + _minX; double y = _minY - (e.Y + _margin - panelViewer.ClientSize.Height) / _scale; if( _scale != double.MaxValue ) this.label3.Text = "(" + x.ToString("F3") +", " + y.ToString("F3") + ")"; else this.label3.Text = ""; // write elementSet ID and element index this.label4.Text = " "; this.label7.Text = " "; this.label8.Text = " "; this.label9.Text = " "; this.label10.Text = " "; this.label11.Text = " "; for (int elementSetNumber = 0; elementSetNumber < this._elementSets.Count; elementSetNumber++) { string elementID = " "; int elementIndex = -9; double distance = 10e30; IElementSet elementSet = (IElementSet) _elementSets[elementSetNumber]; if (elementSetNumber == 0) { this.label7.Text = elementSet.ID.Substring(0, Math.Min(20, elementSet.ID.Length)); } if (elementSetNumber == 1) { this.label9.Text = elementSet.ID.Substring(0, Math.Min(20, elementSet.ID.Length)); } for (int index = 0; index < elementSet.ElementCount; index++) { if (((IElementSet) _elementSets[elementSetNumber]).ElementType == ElementType.XYPolygon) { XYPolygon xyPolygon = new XYPolygon(); for (int i = 0; i < elementSet.GetVertexCount(index); i++) { xyPolygon.Points.Add(new XYPoint(elementSet.GetXCoordinate(index,i), elementSet.GetYCoordinate(index,i))); } if (XYGeometryTools.IsPointInPolygon(x,y,xyPolygon)) { elementID = elementSet.GetElementID(index); elementIndex = index; } } if (((IElementSet) _elementSets[elementSetNumber]).ElementType == ElementType.XYPolyLine) { XYPolyline xyPolyline = new XYPolyline(); for (int i = 0; i < elementSet.GetVertexCount(index); i++) { xyPolyline.Points.Add(new XYPoint(elementSet.GetXCoordinate(index,i), elementSet.GetYCoordinate(index,i))); } double xx = XYGeometryTools.CalculatePolylineToPointDistance(xyPolyline, new XYPoint(x,y)); if (xx < distance) { distance = xx; if (xx < 0.3 * xyPolyline.GetLength()) { elementIndex = index; elementID = elementSet.GetElementID(index); } } } if (elementSetNumber == 0 && elementIndex >= 0) { this.label4.Text = "Index: " + elementIndex.ToString(); this.label8.Text = "ID: " + elementID.Substring(0, Math.Min(17, elementID.Length)); } if (elementSetNumber == 1 && elementIndex >= 0) { this.label10.Text = "Index: " + elementIndex.ToString(); this.label11.Text = "ID: " + elementID.Substring(0, Math.Min(17, elementID.Length)); } } } }