protected BasicPrimitiveTessellator() { Positions = new Point3DCollection(); Normals = new Vector3DCollection(); Indices = new Int32Collection(); TextureCoordinates = new Point2DCollection(); }
internal GeoRegion ToGeoRegion() { if (this.Parts != null) { List<Point2DCollection> pss = new List<Point2DCollection>(); Point2DCollection copy = new Point2DCollection(); foreach (Point2D item in this.Points) { copy.Add(item); } for (int i = 0; i < this.Parts.Count; i++) { Point2DCollection temp = new Point2DCollection(); for (int j = 0; j < this.Parts[i]; j++) { temp.Add(copy[j]); } pss.Add(temp); copy.RemoveRange(0, this.Parts[i]); } GeoRegion region = new GeoRegion(); foreach (Point2DCollection item in pss) { region.Parts.Add(item); } return region; } return null; }
/// <summary>${core_GeoRegion_method_clone_D}</summary> public override Geometry Clone() { GeoRegion region = new GeoRegion(); if (this.Parts != null) { foreach (Point2DCollection points in this.Parts) { if (points != null) { Point2DCollection item = new Point2DCollection(); foreach (Point2D point in points) { if (point != null) { item.Add(point.Clone()); } } region.Parts.Add(item); continue; } region.Parts.Add(null); } } return region; }
private void Activate(Point2D firstPoint) { if (Map == null || Map.Layers == null) { return; } polyline = new PolylineElement(); polyline.Stroke = Stroke; polyline.StrokeThickness = StrokeThickness; polyline.Opacity = Opacity; polyline.StrokeMiterLimit = StrokeMiterLimit; polyline.StrokeDashOffset = StrokeDashOffset; polyline.StrokeDashArray = StrokeDashArray; polyline.StrokeDashCap = StrokeDashCap; polyline.StrokeEndLineCap = StrokeEndLineCap; polyline.StrokeLineJoin = StrokeLineJoin; polyline.StrokeStartLineCap = StrokeStartLineCap; polyline.Fill = Fill; polyline.FillRule = FillRule; points = new Point2DCollection(); polyline.Point2Ds = points; points.Add(firstPoint); DrawLayer = new ElementsLayer(); Map.Layers.Add(DrawLayer); DrawLayer.Children.Add(polyline); isActivated = true; isDrawing = true; }
private static Point2DCollection ClipRing(Point2DCollection ring, Edge edge) { if ((ring == null) || (ring.Count < 2)) { return null; } Point2DCollection points = new Point2DCollection(); Point2D lastPoint = ring[ring.Count - 1]; for (int i = 0; i < ring.Count; i++) { Point2D point = ring[i]; if (Inside(point, edge)) { if (Inside(lastPoint, edge)) { points.Add(point); } else { Point2D item = EdgeIntersection(lastPoint, point, edge); points.Add(item); points.Add(point); } } else if (Inside(lastPoint, edge)) { Point2D item = EdgeIntersection(lastPoint, point, edge); points.Add(item); } lastPoint = point; } return points; }
private void Activate() { if (Map == null || Map.Layers == null) { return; } polygon = new PolygonElement(); #region 所有风格的控制 polygon.Stroke = Stroke; polygon.StrokeThickness = StrokeThickness; polygon.StrokeMiterLimit = StrokeMiterLimit; polygon.StrokeDashOffset = StrokeDashOffset; polygon.StrokeDashArray = StrokeDashArray; polygon.StrokeDashCap = StrokeDashCap; polygon.StrokeEndLineCap = StrokeEndLineCap; polygon.StrokeLineJoin = StrokeLineJoin; polygon.StrokeStartLineCap = StrokeStartLineCap; polygon.Opacity = Opacity; polygon.Fill = Fill; polygon.FillRule = FillRule; #endregion points = new Point2DCollection(); polygon.Point2Ds = points; points.Add(startPt); DrawLayer = new ElementsLayer(); Map.Layers.Add(DrawLayer); DrawLayer.Children.Add(polygon); isActivated = true; isDrawing = true; }
/// <summary>${core_Point2DCollectionConverter_method_ConvertFrom_D}</summary> /// <param name="value">${core_Point2DCollectionConverter_method_ConvertFrom_param_value}</param> /// <param name="context">${core_Point2DCollectionConverter_method_ConvertFrom_param_context}</param> /// <param name="culture">${core_Point2DCollectionConverter_method_ConvertFrom_param_culture}</param> /// <returns>${core_Point2DCollectionConverter_method_ConvertFrom_return}</returns> public override object ConvertFrom(ITypeDescriptorContext context, CultureInfo culture, object value) { string str = value as string; if (str == null) { throw new NotSupportedException(); } Point2DCollection points = new Point2DCollection(); Point2DConverter converter = new Point2DConverter(); int num = -1; for (int i = 0; i < (str.Length + 1); i++) { if ((i >= str.Length) || char.IsWhiteSpace(str[i])) { int startIndex = num + 1; int length = i - startIndex; if (length >= 1) { string str2 = str.Substring(startIndex, length); points.Add((Point2D)converter.ConvertFrom(str2)); } num = i; } } return points; }
void Start() { Point2DCollection <Boolean> candidates = new Point2DCollection <Boolean>(); int readjusted_x = Mathf.RoundToInt(Constants.EXTENT.x / Constants.BALL_DIAMETER), readjusted_y = Mathf.RoundToInt(Constants.EXTENT.y / Constants.BALL_DIAMETER); for (int i = 0; i < readjusted_x; i++) { for (int j = 0; j < readjusted_y; j++) { candidates.put(new Vector2(i, j), true); } } points_per_level.Add(candidates); SemiSigmoid weighter = new SemiSigmoid(); int level = 0; Vector2 up = new Vector2(0, 1), across = new Vector2(1, 1), right = new Vector2(1, 0); float y_sep = Mathf.Pow(2.0f, -0.5f); while (candidates.count > 0) { float thresh = weighter.eval(UnityEngine.Random.value); // stability conditions candidates = candidates.filter_to_new_by_point((Vector2 v) => (System.Convert.ToInt32(candidates.has(v + up)) + System.Convert.ToInt32(candidates.has(v + across)) + System.Convert.ToInt32(candidates.has(v + right)) >= 2) && UnityEngine.Random.value < thresh && v.x < readjusted_x && v.y < readjusted_y); Debug.Log(candidates); Debug.Log(candidates.count); points_per_level.Add(candidates); } for (int i = 0; i < points_per_level.Count; i++) { points_per_level[i].pointed_iterate((Vector2 vec, Boolean v) => Instantiate(this.ball, (new Vector3(vec.x + 0.5f * i, vec.y + 0.5f * i, Constants.BALL_Z_OFFSET - i * y_sep)) * Constants.BALL_DIAMETER, Quaternion.identity)); } }
private Dictionary<string, string> GetParameters(MeasureParameters parameters) { Dictionary<string, string> dictionary = new Dictionary<string, string>(); Point2DCollection ps = new Point2DCollection(); ObservableCollection<Point2DCollection> og = new ObservableCollection<Point2DCollection>(); if (parameters.Geometry is GeoLine) { og = (parameters.Geometry as GeoLine).Parts; } else if (parameters.Geometry is GeoRegion) { og = (parameters.Geometry as GeoRegion).Parts; } else { dictionary.Add("point2Ds", "[]"); dictionary.Add("unit", parameters.Unit.ToString().ToUpper()); return dictionary; } foreach (Point2DCollection g in og) { for (int i = 0; i < g.Count; i++) { ps.Add(g[i]); } } dictionary.Add("point2Ds", JsonHelper.FromPoint2DCollection(ps)); dictionary.Add("unit", parameters.Unit.ToString().ToUpper()); return dictionary; }
public Mesh() { Positions = new Point3DCollection(); Normals = new Vector3DCollection(); TextureCoordinates = new Point2DCollection(); Indices = new IndexCollection(); Material = new Material(); }
public Polygon2D(Polygon2D polygon) { Vertices = new Point2DCollection(); Vertices.Clone(polygon.Vertices); SetStatus(); }
//4条边依次Clip private Point2DCollection Clip(Point2DCollection ring) { foreach (Edge edge in this.Edges) { ring = ClipRing(ring, edge); } return ring; }
public void Write(Point2DCollection value) { Write(value.Count); foreach (Point2D point in value) { Write(point); } }
public Polygon2DDiviser(Polygon2D parent) { Parent = parent; SubDivision = new Polygon2DCollection(); Divisers = new LineSegment2DCollection(); InnerPoints = new Point2DCollection(); SubDivision.Add(Parent); }
public Point2DCollection ReadPoint2DCollection() { Point2DCollection points = new Point2DCollection(); int count = ReadInt(); for (int i = 0; i < count; i++) { points.Add(ReadPoint2D()); } return(points); }
/// <summary> /// Divide a polygon by a path.(point2DCollection) /// </summary> /// <param name="path">the path.</param> /// <param name="polygon">the polygon to divide.</param> public void DividedBy(Point2DCollection path, Polygon2D polygon) { int a = polygon.HasVertex(path.FirstPoint); int b = polygon.HasVertex(path.LastPoint); if (a == Polygon2D.NoSuchPoint || b == Polygon2D.NoSuchPoint) { throw (new ArgumentException()); } if (a > b) { int tmp = a; a = b; b = tmp; } Point2DCollection p2 = new Point2DCollection(); Point2DCollection p1 = new Point2DCollection(); for (int i = 0; i < polygon.VertexCount; i++) { if (i <= a || i >= b) { p1.Add(polygon.GetPoint(i)); } if (i >= a && i <= b) { p2.Add(polygon.GetPoint(i)); } } for (int i = 1; i < path.Count - 1; i++) { p1.Add(path[i], a + i); p2.Add(path[i], 0); Parent.AddInner(path[i]); } if (p1.Count > p2.Count) { SubDivision.Add(new Polygon2D(p1)); SubDivision.Add(new Polygon2D(p2)); } else { SubDivision.Add(new Polygon2D(p2)); SubDivision.Add(new Polygon2D(p1)); } }
public override bool Split(float[] @params, out Curve[] subCurves) { @params = ValidateParams(@params); if (!Closed) { if (@params.Length == 0) { subCurves = new Curve[0]; return(false); } subCurves = new Curve[@params.Length + 1]; for (int i = 0; i < @params.Length + 1; i++) { float ps = (i == 0 ? StartParam : @params[i - 1]); float pe = (i == @params.Length ? EndParam : @params[i]); Point2DCollection newPoints = new Point2DCollection(); foreach (float p in ParamIterator(ps, pe)) { newPoints.Add(GetPointAtParam(p)); } subCurves[i] = new Polyline(newPoints); } return(true); } else { if (@params.Length < 2) { subCurves = new Curve[0]; return(false); } subCurves = new Curve[@params.Length]; for (int i = 0; i < @params.Length; i++) { float ps = @params[i]; float pe = (i == @params.Length - 1 ? @params[0] : @params[i + 1]); Point2DCollection newPoints = new Point2DCollection(); foreach (float p in ParamIterator(ps, pe)) { newPoints.Add(GetPointAtParam(p)); } subCurves[i] = new Polyline(newPoints); } return(true); } }
public Polygon2DLinkMaker(Polygon2D polygon, int a, int b) : base(polygon) { if (!polygon.isRegular) { throw (new ArgumentException()); } FirstPoint = polygon.GetPoint(a); LastPoint = polygon.GetPoint(b); LinkDivisers = new Point2DCollection(); //Partitions = new Polygon2DCollection(); //Partitions.Add(polygon); }
internal Point2DCollection Clip(Point2DCollection pts) { Point2DCollection newPoints ; newPoints = pts; if (pts.GetBounds().IntersectsWith(this.boundary)) { foreach (Edge edge in this.Edges) { newPoints = ClipRing(newPoints, edge); } } return newPoints; }
//计算parts private void caculateParts() { double unitsAngle = 360 / 72; double startAngle = 0; double unitsPI = Math.PI / 180; this.parts.Clear(); Point2DCollection item = new Point2DCollection(); for (int i = 0; i < 72; i++) { Point2D p = new Point2D(Math.Cos(startAngle * unitsPI) * this.radius + center.X, Math.Sin(startAngle * unitsPI) * this.radius + center.Y); item.Add(p); startAngle += unitsAngle; } this.parts.Add(item); }
private void CreateRectangle(Point2D p1, Point2D p2) { double xmin = Math.Min(p1.X, p2.X); double xmax = Math.Max(p1.X, p2.X); double ymin = Math.Min(p1.Y, p2.Y); double ymax = Math.Max(p1.Y, p2.Y); Point2DCollection ps = new Point2DCollection(); ps.Add(new Point2D(xmin, ymin)); ps.Add(new Point2D(xmin, ymax)); ps.Add(new Point2D(xmax, ymax)); ps.Add(new Point2D(xmax, ymin)); ps.Add(new Point2D(xmin, ymin)); this.Parts.Add(ps); }
private static string GetCoorStr(Point2DCollection ps) { string str = string.Empty; List<string> strCol = new List<string>(); if (ps != null) { foreach (Point2D item in ps) { strCol.Add(item.ToString(CultureInfo.InvariantCulture)); } str = string.Join(" ", strCol); } return str; }
public Point2DCollection <T> filter_to_new_by_point(Func <Vector2, bool> F) { Point2DCollection <T> ret = new Point2DCollection <T>(); foreach (KeyValuePair <float, Dictionary <float, T> > x_y_T in this.M) { foreach (KeyValuePair <float, T> y_T in x_y_T.Value) { Vector2 maybe_vec = new Vector2(x_y_T.Key, y_T.Key); if (F(maybe_vec)) { ret.put(maybe_vec, y_T.Value); } } } return(ret); }
internal Point2DCollection Clip(Point2DCollection line) { Point2DCollection newLine = new Point2DCollection(); IList<Point2DCollection> list = this.ClipPointCollection(line, this.boundary); if ((list != null) && (list.Count > 0)) { foreach (Point2DCollection points in list) { foreach (Point2D item in points) { newLine.Add(item); } } } return newLine; }
// public void follow_until(Func<Vector2, Vector2?, T> F, Vector2 k) { // if(this.M.ContainsKey(v.x) && this.M[v.x].ContainsKey(v.y)) { // Vector2 maybe_vec2 = F(this.M[v.x][v.y]); // if(maybe_T != null) { // this.follow_until(F, maybe_vec2); // } // } // } public Point2DCollection <T> intersect_to_new(Point2DCollection <T> incoming) { Point2DCollection <T> ret = new Point2DCollection <T>(); foreach (KeyValuePair <float, Dictionary <float, T> > x_y_T in this.M) { foreach (KeyValuePair <float, T> y_T in x_y_T.Value) { Vector2 pt = new Vector2(x_y_T.Key, y_T.Key); if (incoming.has(pt)) { ret.put(pt, incoming.get(pt)); } } } return(ret); }
/// <summary>${utility_JsonHelper_method_FromPoint2DCollection_D}</summary> public static string FromPoint2DCollection(Point2DCollection points) { if (points == null || points.Count < 1) { return "[{}]"; } StringBuilder stringBuilder = new StringBuilder("["); for (int i = 0; i < points.Count - 1; i++) { stringBuilder.Append(FromPoint2D(points[i])); stringBuilder.Append(","); } stringBuilder.Append(FromPoint2D(points[points.Count - 1])); stringBuilder.Append("]"); return stringBuilder.ToString(); }
private Polygon2D FlipArea(GhostTriangle2D a, GhostTriangle2D b, Polygon2D poly) { if (!isNeighbor(a, b)) { throw (new ArgumentException()); } Map(a, b); Point2DCollection points = new Point2DCollection(4); points.Add(poly.GetPoint(a.C)); points.Add(poly.GetPoint(a.A)); points.Add(poly.GetPoint(b.C)); points.Add(poly.GetPoint(b.B)); Polygon2D polygon = new Polygon2D(points); return(polygon); }
private void CreateRing() { this.Parts.Clear(); if (!double.IsNaN(Radius) && Radius > 0 && Center != null && PointCount > 2) { Point2DCollection pnts = new Point2DCollection(); for (int i = 0; i < PointCount; i++) { double rad = 2 * Math.PI / PointCount * i; double x = Math.Cos(rad) * radius + Center.X; double y = Math.Sin(rad) * radius + Center.Y; pnts.Add(new Point2D(x, y)); } double x0 = radius + Center.X; double y0 = Center.Y; pnts.Add(new Point2D(x0, y0)); this.Parts.Add(pnts); } }
/// <summary> /// Convert this line segment to a path. Instert some new points. /// </summary> /// <param name="ExtraPoints">the number of extra points to insert.</param> /// <returns>the path.</returns> public Point2DCollection ToPath(int ExtraPoints) { if (ExtraPoints < 0) { throw (new ArgumentException()); } Point2DCollection points = new Point2DCollection(); points.Add(this.FirstPoint); for (int i = 1; i <= ExtraPoints; i++) { double d = (double)i / (double)(ExtraPoints + 1); points.Add(this.GetPoint(d)); } points.Add(this.LastPoint); return(points); }
private void GeometryThiessenAnalyst_Click(object sender, RoutedEventArgs e) { Point2DCollection points = new Point2DCollection(); points.Add(new Point2D(5472.712382, -2189.15344)); points.Add(new Point2D(4707.299652, -1229.476725)); points.Add(new Point2D(5450.34263, -2070.794081)); points.Add(new Point2D(5447.671615, -2255.928819)); points.Add(new Point2D(5357.895026, -1965.022579)); points.Add(new Point2D(5317.70775, -2521.162355)); GeometryThiessenAnalystParameters thiessenParams = new GeometryThiessenAnalystParameters(); thiessenParams.Points = points; thiessenParams.CreateResultDataset = true; thiessenParams.ResultDatasetName = ""; thiessenParams.ResultDatasourceName = "Changchun"; thiessenParams.ReturnResultRegion = true; thiessenParams.ClipRegion = null; ThiessenAnalystService thiessenService = new ThiessenAnalystService(url2); thiessenService.ProcessAsync(thiessenParams); thiessenService.ProcessCompleted += new EventHandler<ThiessenAnalystEventArgs>(ThiessenAnalyst_ProcessCompleted); thiessenService.Failed += new EventHandler<ServiceFailedEventArgs>(ThiessenAnalyst_Failed); }
private void Activate(Point2D firstPoint) { if (Map == null || Map.Layers == null) { return; } DrawLayer = new ElementsLayer(); Map.Layers.Add(DrawLayer); _startPoint = firstPoint; _polygon = new PolygonElement(); #region 所有风格的控制 _polygon.Stroke = this.Stroke; _polygon.StrokeThickness = this.StrokeThickness; _polygon.StrokeMiterLimit = this.StrokeMiterLimit; _polygon.StrokeDashOffset = this.StrokeDashOffset; _polygon.StrokeDashArray = this.StrokeDashArray; _polygon.StrokeDashCap = this.StrokeDashCap; _polygon.StrokeEndLineCap = this.StrokeEndLineCap; _polygon.StrokeLineJoin = this.StrokeLineJoin; _polygon.StrokeStartLineCap = this.StrokeStartLineCap; _polygon.Opacity = this.Opacity; _polygon.Fill = this.Fill; _polygon.FillRule = this.FillRule; #endregion _points = new Point2DCollection(); _polygon.Point2Ds = _points; _points.Add(firstPoint); _pointsCount++; _points.Add(firstPoint.Clone()); _pointsCount++; DrawLayer.Children.Add(_polygon); _isActivated = true; }
public override void Deactivate() { isActivated = false; isDrawing = false; oldPentagrams = null; pentagram = null; points = null; if (DrawLayer != null) { DrawLayer.Children.Clear(); } if (Map != null) { Map.Layers.Remove(DrawLayer); } }
public Polygon2D() { Vertices = new Point2DCollection(); }
/// <summary>${ui_action_MapAction_method_deactivate_D}</summary> public override void Deactivate() { isActivated = false; isDrawing = false; polygon = null; points = null; if (DrawLayer != null) { DrawLayer.Children.Clear(); } if (Map != null && Map.Layers != null) { Map.Layers.Remove(DrawLayer); } }
public Polygon(Point2DCollection pts) : base(pts) { }
internal void SetClip(Point2DCollection clippedPoint2Ds, Rectangle2D clipbox) { this.ClippedPoint2Ds = clippedPoint2Ds; this.ClipBox = clipbox; this.InvalidatePath(this.Resolution, this.OriginX, this.OriginY); }
public Polyline() { Points = new Point2DCollection(); Points.CollectionChanged += Points_CollectionChanged; }
void Start() { Mesh M = new Mesh(); SemiSigmoid weighter = new SemiSigmoid(); int terrain_points = (int)(weighter.eval(Random.value) * Constants.MAX_POINTS); List <Vector3> vertices = new List <Vector3>(); Point2DCollection <int> vec2_vertices = new Point2DCollection <int>(); List <uint> colors = new List <uint>(); // vertices.Add(new Vector3(0.6626031f, 0.05119444f, 0.0f) * 10.0f); // vertices.Add(new Vector3(0.6618521f, 0.2226332f, 0.0f) * 10.0f); // vertices.Add(new Vector3(0.3871413f, 0.5442802f, 0.0f) * 10.0f); // vertices.Add(new Vector3(0.6093425f, 0.3753652f, 0.0f) * 10.0f); // vertices.Add(new Vector3(0.7540823f, 0.5187992f, 0.0f) * 10.0f); // for(int i=0; i<vertices.Count; i++) { // vec2_vertices.put(vertices[i], i); // colors.Add(0); // } for (int i = 0; i < terrain_points; i++) { float x = Random.value, y = Random.value; Vector3 vec = new Vector3(x * Constants.EXTENT.x, y * Constants.EXTENT.y, Mathf.PerlinNoise(x * Constants.PERLIN_SCALE, y * Constants.PERLIN_SCALE) * Constants.MAX_ELEVATION - Constants.MAX_ELEVATION / 2); Debug.Log(System.String.Format("{0}, {1}", vec.x, vec.y)); vertices.Add(vec); vec2_vertices.put(vec, i); colors.Add(0); } M.vertices = vertices.ToArray(); Debug.Log(vec2_vertices.M.Count); List <LineSegment> triangle_line_segments = new Delaunay.Voronoi(vec2_vertices.rezip(), colors, new Rect(0, 0, Constants.EXTENT.x, Constants.EXTENT.y)).DelaunayTriangulation(); Point2DCollection <Point2DCollection <bool> > adjs = new Point2DCollection <Point2DCollection <bool> >(); // second parameters of Point2DCollection not really all that useful anymore, because we're storing the index to the original array now anyways for (int i = 0; i < triangle_line_segments.Count; i++) { // Debug.Log(System.String.Format("{0}, {1}", triangle_line_segments[i].p0, triangle_line_segments[i].p1)); Vector2 src, dst; src = (Vector2)triangle_line_segments[i].p0; dst = (Vector2)triangle_line_segments[i].p1; if (adjs.get(src) == null) { Point2DCollection <bool> new_adj = new Point2DCollection <bool>(); new_adj.put(dst, true); adjs.put(src, new_adj); } else { adjs.get(src).put(dst, true); } if (adjs.get(dst) == null) { Point2DCollection <bool> new_adj = new Point2DCollection <bool>(); new_adj.put(src, true); adjs.put(dst, new_adj); } else { adjs.get(dst).put(src, true); } Debug.Log(System.String.Format("({0}, {1}) <-> ({2}, {3})", dst.x, dst.y, src.x, src.y)); Point2DCollection <bool> maybe_intersect = adjs.get(src).intersect_to_new(adjs.get(dst)); if (maybe_intersect.count > 0) { Debug.Log(System.String.Format("({0}, {1}), ({2}, {3}), ({4}, {5})", src.x, src.y, dst.x, dst.y, maybe_intersect.rezip()[0].x, maybe_intersect.rezip()[0].y)); int A = vec2_vertices.get(src), B = vec2_vertices.get(dst), C = vec2_vertices.get(maybe_intersect.rezip()[0]); if (this._is_clockwise(vertices[A], vertices[B], vertices[C])) { int[] triangle = { A, B, C }; this.triangles.AddRange(triangle); } else { int[] triangle = { A, C, B }; this.triangles.AddRange(triangle); } } } M.triangles = this.triangles.ToArray(); M.RecalculateNormals(); // M.Optimize(); GetComponent <MeshFilter>().mesh = M; MeshCollider collider = GetComponent <MeshCollider>(); collider.convex = false; collider.enabled = true; collider.sharedMesh = M; StringBuilder str_vertices = new StringBuilder(); for (int i = 0; i < this.triangles.Count; i++) { str_vertices.Append(System.String.Format(this.triangles[i].ToString())); } Debug.Log(str_vertices.ToString()); }
private double GetArea(Point2DCollection point2DCollection) { #region 法1: double tempArea = 0; double x1, x2, y1, y2; for (int i = 0; i < point2DCollection.Count - 1; i++) { x1 = point2DCollection[i].X; x2 = point2DCollection[i + 1].X; y1 = point2DCollection[i].Y; y2 = point2DCollection[i + 1].Y; //tempArea += x1 * yDiff - y1 * xDiff; tempArea += x1 * y2 - x2 * y1; } tempArea += point2DCollection[point2DCollection.Count - 1].X * point2DCollection[0].Y - point2DCollection[point2DCollection.Count - 1].Y * point2DCollection[0].X; return Math.Abs(tempArea) / 2000000; #endregion #region 法2: //int i, j; //double ar = 0; //for (i = 0; i < point2DCollection.Count; i++) //{ // j = (i + 1) % point2DCollection.Count; // ar += point2DCollection[i].X * point2DCollection[j].Y; // ar -= point2DCollection[i].Y * point2DCollection[j].X; //} //ar /= 2; //return (ar < 0 ? -ar : ar); #endregion }
private void Complete() { _points = null; _isActivated = false; _pointsCount = 0; _polyline = null; _textBlockContainer = null; _distances = null; }
public Polygon2D(Point2DCollection points) { Vertices = points; SetStatus(); }
public Hatch(Point2DCollection pts) : base(pts) { ; }
/// <summary> /// Divide a sub polygon by a line segment. /// </summary> /// <param name="lineSegment">the line segment.</param> /// <param name="poly">the polygon to divide.</param> /// <returns>one of the sub polygon divided from the polygon.</returns> internal Polygon2D DividedBy(LineSegment2D lineSegment, Polygon2D poly) { if (poly.isDiagonal(lineSegment)) { int a = poly.HasVertex(lineSegment.FirstPoint); int b = poly.HasVertex(lineSegment.LastPoint); if (a > b) { int tmp = a; a = b; b = tmp; } Point2DCollection p2 = new Point2DCollection(b - a + 1); Point2DCollection p1 = new Point2DCollection(poly.VertexCount - p2.Size + 2); for (int i = 0; i < poly.VertexCount; i++) { if (i <= a || i >= b) { p1.Add(poly.GetPoint(i)); } if (i >= a && i <= b) { p2.Add(poly.GetPoint(i)); } } if (p1.Count > p2.Count) { SubDivision.Add(new Polygon2D(p1)); return(new Polygon2D(p2)); } else { SubDivision.Add(new Polygon2D(p2)); return(new Polygon2D(p1)); } } else if (lineSegment.Intersects(poly)) { Point2DCollection Points = new Point2DCollection(2); for (int i = 0; i < poly.VertexCount; i++) { LineSegment2D border = poly.GetEdge(i); Point2D p = lineSegment.GetIntersectPoint(border); if (p.isRegular) { Points.DistinctAdd(p); } } Debug.Assert(Points.Count == 2); if (poly.HasVertex(Points[0]) == Polygon2D.NoSuchPoint) { poly.Add(Points[0], poly.OnEdge(Points[0])); Parent.AddInner(Points[0]); this.InnerPoints.DistinctAdd(Points[0]); } if (poly.HasVertex(Points[1]) == Polygon2D.NoSuchPoint) { poly.Add(Points[1], poly.OnEdge(Points[1])); Parent.AddInner(Points[1]); this.InnerPoints.DistinctAdd(Points[1]); } LineSegment2D line = new LineSegment2D(Points[0], Points[1]); return(DividedBy(line, poly)); } else { return(poly); } }
public void Divide() { UpdateStatus(this, "Dividing..."); targetDiviser.UpdateStatus += new Microsoft.VS.Akira.Triangulations.TargetDiviser.ShowStatus(UpdateStatus); targetDiviser.Divide(); Polygon2D poly = this.firstPolygon; this.firstPolygonCollection.Add(this.firstPolygon); this.secondPolygonCollection.Add(this.secondPolygon); UpdateStatus(this, "Mapping..."); for (int i = 0; i < targetDiviser.Divisers.Count; i++) { int first_index = this.secondPolygon.GetPointIndex(targetDiviser.Divisers[i].FirstPoint); int second_index = this.secondPolygon.GetPointIndex(targetDiviser.Divisers[i].LastPoint); LineSegment2D line = new LineSegment2D(this.firstPolygon.GetPoint(first_index), this.firstPolygon.GetPoint(second_index)); for (int j = 0; j < this.firstPolygonCollection.Count; j++) { if (this.firstPolygonCollection[j].HasVertex(line.FirstPoint) != Polygon2D.NoSuchPoint && this.firstPolygonCollection[j].HasVertex(line.LastPoint) != Polygon2D.NoSuchPoint) { poly = this.firstPolygonCollection[j]; this.firstPolygonCollection.Remove(j); break; } } int from = 0; int to = 0; from = poly.GetPointIndex(line.FirstPoint); to = poly.GetPointIndex(line.LastPoint); linkMaker = new Polygon2DLinkMaker(poly, from, to); linkMaker.Divide(); int extraPoints = linkMaker.LinkDistance - 1; linkMaker.BuildPath(); Polygon2DDiviser pd = new Polygon2DDiviser(poly); pd.DividedBy(linkMaker.LinkDivisers, poly); this.firstPolygonCollection.Add(pd.SubDivision[1]); this.firstPolygonCollection.Add(pd.SubDivision[2]); //divide target polygon line = targetDiviser.Divisers[i]; for (int j = 0; j < this.secondPolygonCollection.Count; j++) { if (this.secondPolygonCollection[j].HasVertex(line.FirstPoint) != Polygon2D.NoSuchPoint && this.secondPolygonCollection[j].HasVertex(line.LastPoint) != Polygon2D.NoSuchPoint) { poly = this.secondPolygonCollection[j]; this.secondPolygonCollection.Remove(j); break; } } from = poly.GetPointIndex(line.FirstPoint); to = poly.GetPointIndex(line.LastPoint); Point2DCollection path = line.ToPath(extraPoints); pd = new Polygon2DDiviser(poly); pd.DividedBy(path, poly); this.secondPolygonCollection.Add(pd.SubDivision[1]); this.secondPolygonCollection.Add(pd.SubDivision[2]); } }
public override void Load(DocumentReader reader) { base.Load(reader); Points = reader.ReadPoint2DCollection(); Points.CollectionChanged += Points_CollectionChanged; }
private void Activate() { pentagram = new PolygonElement(); #region 所有风格的控制 pentagram.Stroke = this.Stroke; pentagram.StrokeThickness = this.StrokeThickness; pentagram.Fill = this.Fill; pentagram.FillRule = this.FillRule; pentagram.Opacity = this.Opacity; pentagram.StrokeMiterLimit = this.StrokeMiterLimit; pentagram.StrokeDashOffset = this.StrokeDashOffset; pentagram.StrokeDashArray = this.StrokeDashArray; pentagram.StrokeDashCap = this.StrokeDashCap; pentagram.StrokeEndLineCap = this.StrokeEndLineCap; pentagram.StrokeLineJoin = this.StrokeLineJoin; pentagram.StrokeStartLineCap = this.StrokeStartLineCap; #endregion a0 = new Point2D(); a1 = new Point2D(); a2 = new Point2D(); a3 = new Point2D(); a4 = new Point2D(); points = new Point2DCollection(); pentagram.Point2Ds = points; oldPentagrams = new List<PolygonElement>(); DrawLayer = new ElementsLayer(); Map.Layers.Add(DrawLayer); isActivated = true; isDrawing = true; }
private void Activate(Point2D firstPoint) { _polygon = new PolygonElement(); _textBlockContainer = new List<TextBlock>(); #region 所有风格的控制 _polygon.Stroke = Stroke; _polygon.StrokeThickness = StrokeThickness; _polygon.StrokeMiterLimit = StrokeMiterLimit; _polygon.StrokeDashOffset = StrokeDashOffset; _polygon.StrokeDashArray = StrokeDashArray; _polygon.StrokeDashCap = StrokeDashCap; _polygon.StrokeEndLineCap = StrokeEndLineCap; _polygon.StrokeLineJoin = StrokeLineJoin; _polygon.StrokeStartLineCap = StrokeStartLineCap; _polygon.Opacity = Opacity; _polygon.Fill = Fill; _polygon.FillRule = FillRule; #endregion _points = new Point2DCollection(); _polygon.Point2Ds = _points; _points.Add(firstPoint); _pointsCount++; _points.Add(firstPoint.Clone()); _pointsCount++; DrawLayer.Children.Add(_polygon); TextBlock textBlock = new TextBlock(); textBlock.FontWeight = FontWeights.ExtraBlack; textBlock.Foreground = new SolidColorBrush(Colors.White); textBlock.Text = "起点"; _textBlockContainer.Add(textBlock); DrawLayer.AddChild(textBlock, firstPoint); _isActivated = true; }
public MeasureDistance(Map map, ElementsLayer elementsLayer, FeaturesLayer featuresLayer) { _map = map; _eLayer = elementsLayer; _fLayer = featuresLayer; _isInited = false; _distanceList = new List<TextBlock>(); _points = new Point2DCollection(); _distances = new List<double>(); }
public Polyline(PointF[] pts) { Points = new Point2DCollection(pts); Points.CollectionChanged += Points_CollectionChanged; }
private void MyMap_Loaded(object sender, RoutedEventArgs e) { #region 使用预定义点符号 Feature featurePoint = new Feature(); GeoPoint point = new GeoPoint(); point.X = 116.2; point.Y = 39.6; PredefinedMarkerStyle simpleMarkerStyle = new PredefinedMarkerStyle(); simpleMarkerStyle.Color = new SolidColorBrush(Colors.Red); simpleMarkerStyle.Size = 20; simpleMarkerStyle.Symbol = SuperMap.Web.Core.PredefinedMarkerStyle.MarkerSymbol.Star; featurePoint.Style = simpleMarkerStyle; featurePoint.Geometry = point; featuresLayer.Features.Add(featurePoint); #endregion #region 使用预定义线符号 Feature featureLine = new Feature(); Point2DCollection points = new Point2DCollection(); points.Add(new Point2D(116.2, 39.6)); points.Add(new Point2D(90, 50)); points.Add(new Point2D(50, 25)); points.Add(new Point2D(-80, 45)); points.Add(new Point2D(-100, 38)); ObservableCollection<Point2DCollection> path = new ObservableCollection<Point2DCollection>(); path.Add(points); GeoLine geoLine = new GeoLine(); geoLine.Parts = path; PredefinedLineStyle simpleLineStyle = new PredefinedLineStyle(); simpleLineStyle.Stroke = new SolidColorBrush(Colors.Black); simpleLineStyle.StrokeThickness = 1; simpleLineStyle.StrokeDashArray = new DoubleCollection { 3, 1 }; featureLine.Geometry = geoLine; featureLine.Style = simpleLineStyle; featuresLayer.Features.Add(featureLine); #endregion #region 使用预定义面符号 Feature featureRegion = new Feature(); Point2DCollection pointsRegion = new Point2DCollection(); pointsRegion.Add(new Point2D(-8, 61)); pointsRegion.Add(new Point2D(-6, 55)); pointsRegion.Add(new Point2D(-8, 50)); pointsRegion.Add(new Point2D(2, 50)); pointsRegion.Add(new Point2D(1, 61)); pointsRegion.Add(new Point2D(-8, 61)); ObservableCollection<Point2DCollection> pRegion = new ObservableCollection<Point2DCollection>(); pRegion.Add(pointsRegion); GeoRegion geoRegion = new GeoRegion(); geoRegion.Parts = pRegion; PredefinedFillStyle simpleFillStyle = new PredefinedFillStyle(); simpleFillStyle.StrokeThickness = 1; simpleFillStyle.Stroke = new SolidColorBrush(Colors.Black); simpleFillStyle.Fill = new SolidColorBrush(Colors.Yellow); featureRegion.Geometry = geoRegion; featureRegion.Style = simpleFillStyle; featuresLayer.Features.Add(featureRegion); #endregion #region 添加文本 Feature featureText = new Feature(); GeoPoint text = new GeoPoint(); text.X = 5; text.Y = 10; TextStyle textStyle = new TextStyle(); textStyle.Text = "Africa"; textStyle.FontSize = 40; textStyle.Foreground = new SolidColorBrush(Colors.Blue); featureText.Geometry = text; featureText.Style = textStyle; featuresLayer.Features.Add(featureText); #endregion }
private void Activate(Point2D firstPoint) { if (DrawLayer != null) { DrawLayer.Children.Clear(); } if (Map != null) { Map.Layers.Remove(DrawLayer); } DrawLayer = new ElementsLayer(); Map.Layers.Add(DrawLayer); Map.Layers.Add(tempLayer); polyline = new PolylineElement(); #region 所有风格的控制 polyline.Stroke = Stroke; polyline.StrokeThickness = StrokeThickness; polyline.StrokeMiterLimit = StrokeMiterLimit; polyline.StrokeDashOffset = StrokeDashOffset; polyline.StrokeDashArray = StrokeDashArray; polyline.StrokeDashCap = StrokeDashCap; polyline.StrokeEndLineCap = StrokeEndLineCap; polyline.StrokeLineJoin = StrokeLineJoin; polyline.StrokeStartLineCap = StrokeStartLineCap; polyline.Opacity = Opacity; polyline.Fill = Fill; polyline.FillRule = FillRule; #endregion points = new Point2DCollection(); polyline.Point2Ds = points; points.Add(firstPoint); points.Add(firstPoint); DrawLayer.Children.Add(polyline); isDrawing = true; isActivated = true; }
/// <summary>${iServer2_Utility_method_GeometryToServerGeometry_D}</summary> /// <param name="geo">${iServer2_Utility_method_GeometryToServerGeometry_param_geo}</param> /// <returns>${iServer2_Utility_method_GeometryToServerGeometry_return}</returns> public static ServerGeometry ToServerGeometry(this Geometry geo) { if (geo == null) { return null; } ServerGeometry sg = new ServerGeometry(); Point2DCollection list = new Point2DCollection(); List<int> parts = new List<int>(); if (geo is GeoRegion) { for (int i = 0; i < ((GeoRegion)geo).Parts.Count; i++) { for (int j = 0; j < ((GeoRegion)geo).Parts[i].Count; j++) { list.Add(new Point2D(((GeoRegion)geo).Parts[i][j].X, ((GeoRegion)geo).Parts[i][j].Y)); } parts.Add(((GeoRegion)geo).Parts[i].Count); } sg.Feature = ServerFeatureType.Polygon; } if (geo is GeoCircle) { for (int i = 0; i < ((GeoCircle)geo).Parts.Count; i++) { for (int j = 0; j < ((GeoCircle)geo).Parts[i].Count; j++) { list.Add(new Point2D(((GeoCircle)geo).Parts[i][j].X, ((GeoCircle)geo).Parts[i][j].Y)); } parts.Add(((GeoCircle)geo).Parts[i].Count); } sg.Feature = ServerFeatureType.Polygon; } if (geo is GeoLine) { for (int i = 0; i < ((GeoLine)geo).Parts.Count; i++) { for (int j = 0; j < ((GeoLine)geo).Parts[i].Count; j++) { list.Add(new Point2D(((GeoLine)geo).Parts[i][j].X, ((GeoLine)geo).Parts[i][j].Y)); } parts.Add(((GeoLine)geo).Parts[i].Count); } sg.Feature = ServerFeatureType.Line; } if (geo is GeoPoint) { list.Add(new Point2D(((GeoPoint)geo).X, ((GeoPoint)geo).Y)); parts.Add(list.Count); sg.Feature = ServerFeatureType.Point; } sg.Point2Ds = list; sg.Parts = parts; sg.Id = -1; return sg; }
public override async Task Apply(CADDocument doc, params string[] args) { Editor ed = doc.Editor; ed.PickedSelection.Clear(); var p1 = await ed.GetPoint("First point: "); if (p1.Result != ResultMode.OK) { return; } Point2D pt = p1.Value; Polyline consPoly = new Polyline(new Point2D[] { pt, pt }); consPoly.Closed = true; doc.Jigged.Add(consPoly); Point2DCollection points = new Point2DCollection(); points.Add(pt); bool done = false; while (!done) { PointOptions options = new PointOptions("Next point: ", pt, (p) => consPoly.Points[consPoly.Points.Count - 1] = p); options.AddKeyword("End", true); var pNext = await ed.GetPoint(options); if (pNext.Result == ResultMode.OK) { pt = pNext.Value; consPoly.Points.Add(pt); points.Add(pt); } else if (pNext.Result == ResultMode.Cancel) { doc.Jigged.Remove(consPoly); return; } else if (pNext.Result == ResultMode.Keyword) { if (points.Count < 2) { doc.Jigged.Remove(consPoly); return; } if (pNext.Keyword == "End") { done = true; } } } doc.Jigged.Remove(consPoly); Hatch newItem = new Hatch(points); doc.Model.Add(newItem); }