private static Vector2 ConvertVector(Vector2 input, PointAlignment alignment) { switch (alignment) { case PointAlignment.BottomRight: input.x = 1f - input.x; break; case PointAlignment.TopLeft: input.y = 1f - input.y; break; case PointAlignment.TopRight: input.y = 1f - input.y; input.x = 1f - input.x; break; case PointAlignment.BottomLeft: break; default: throw new ArgumentOutOfRangeException(nameof(alignment), alignment, null); } return(input); }
private List <NetTopologySuite.Geometries.Point> GetSymbolizerPoints(PointAlignment mode) { var pts = new List <NetTopologySuite.Geometries.Point>(); switch (mode) { case PointAlignment.Horizontal: pts.Add(new NetTopologySuite.Geometries.Point(99, 7)); pts.Add(new NetTopologySuite.Geometries.Point(100, 7)); pts.Add(new NetTopologySuite.Geometries.Point(101, 7)); break; case PointAlignment.Vertical: pts.Add(new NetTopologySuite.Geometries.Point(99, 7)); pts.Add(new NetTopologySuite.Geometries.Point(99, 8)); pts.Add(new NetTopologySuite.Geometries.Point(99, 9)); break; case PointAlignment.Diagonal: pts.Add(new NetTopologySuite.Geometries.Point(99, 7)); pts.Add(new NetTopologySuite.Geometries.Point(100, 8)); pts.Add(new NetTopologySuite.Geometries.Point(101, 9)); break; } return(pts); }
private void AddListPointSymbolizerLayers(Map map, PointAlignment mode) { var pts = GetSymbolizerPoints(mode); var vLyr = new VectorLayer("ListPoint with Pps and Cps", new GeometryFeatureProvider(pts.AsEnumerable())); var pps = SharpMap.Rendering.Symbolizer.PathPointSymbolizer.CreateSquare(new System.Drawing.Pen(System.Drawing.Color.Red, 2), new System.Drawing.SolidBrush( System.Drawing.Color.DodgerBlue), 20); var cps = new SharpMap.Rendering.Symbolizer.CharacterPointSymbolizer { Halo = 1, HaloBrush = new System.Drawing.SolidBrush(System.Drawing.Color.WhiteSmoke), Foreground = new System.Drawing.SolidBrush(System.Drawing.Color.Black), Font = new System.Drawing.Font("Arial", 12), CharacterIndex = 65 }; var lps = new SharpMap.Rendering.Symbolizer.ListPointSymbolizer { pps, cps }; vLyr.Style.PointSymbolizer = lps; map.Layers.Add(vLyr); vLyr = new VectorLayer("ReferencePoint", new GeometryFeatureProvider(pts.AsEnumerable())); vLyr.Style.PointSize = 4f; vLyr.Style.PointColor = Brushes.Yellow; map.Layers.Add(vLyr); }
public void Line_AffectedArea(float width, float offset, PointAlignment alignMode, bool testRotations) { using (var map = new Map()) { ConfigureMap(map); AddLineLayers(map, alignMode, width, offset); var extents = map.GetExtents(); extents.ExpandBy(0.2); foreach (var rot in _rotations) { SetMapTransform(map, rot); map.ZoomToBox(extents, true); var affectedArea = GetAffectedArea(map, (Layer)map.Layers[0]); AddAffectedAreaLayer(map, affectedArea); using (var img = map.GetMap()) img.Save( Path.Combine(UnitTestsFixture.GetImageDirectory(this), $"Line_W-{width}_O-{offset}_{alignMode}_{rot:000}.png"), System.Drawing.Imaging.ImageFormat.Png); // remove affected area layer map.Layers.RemoveAt(2); if (!testRotations) { break; } } } }
public void PointSymbolizer_AffectedArea(SymbolizerMode symMode, PointAlignment alignMode, bool testRotations) { using (var map = new Map()) { ConfigureMap(map); switch (symMode) { case SymbolizerMode.Rps: AddRasterPointSymbolizerLayers(map, alignMode); break; case SymbolizerMode.Cps: AddCharacterPointSymbolizerLayers(map, alignMode); break; case SymbolizerMode.Pps: AddPathPointSymbolizerLayers(map, alignMode); break; case SymbolizerMode.Lps: AddListPointSymbolizerLayers(map, alignMode); break; } var extents = map.GetExtents(); extents.ExpandBy(0.2); foreach (var rot in _rotations) { SetMapTransform(map, rot); map.ZoomToBox(extents, true); var affectedArea = GetAffectedArea(map, (Layer)map.Layers[0]); AddAffectedAreaLayer(map, affectedArea); using (var img = map.GetMap()) img.Save( Path.Combine(UnitTestsFixture.GetImageDirectory(this), $"{symMode}_{alignMode}_{rot:000}.png"), System.Drawing.Imaging.ImageFormat.Png); // remove affected area layer map.Layers.RemoveAt(2); if (!testRotations) { break; } } } }
private void AddLineLayers(Map map, PointAlignment mode, float width, float offset) { var pts = GetSymbolizerPoints(mode); var line = new LineString(GetSymbolizerPoints(mode).Select(p => new Coordinate(p.X, p.Y)).ToArray()); var vLyr = new VectorLayer("Line", new GeometryFeatureProvider(line)); vLyr.Style.Line = new Pen(Color.Green, width); vLyr.Style.LineOffset = offset; map.Layers.Add(vLyr); vLyr = new VectorLayer("ReferencePoint", new GeometryFeatureProvider(pts.AsEnumerable())); vLyr.Style.PointSize = 10f; map.Layers.Add(vLyr); }
private void AddRasterPointSymbolizerLayers(Map map, PointAlignment mode) { var pts = GetSymbolizerPoints(mode); var vLyr = new VectorLayer("RasterPoint", new GeometryFeatureProvider(pts.AsEnumerable())); var rps = new SharpMap.Rendering.Symbolizer.RasterPointSymbolizer(); rps.Symbol = GetRasterSymbol(); rps.Rotation = 30f; vLyr.Style.PointSymbolizer = rps; map.Layers.Add(vLyr); vLyr = new VectorLayer("ReferencePoint", new GeometryFeatureProvider(pts.AsEnumerable())); vLyr.Style.PointSize = 2f; //vLyr.Enabled = false; map.Layers.Add(vLyr); }
private void AddPathPointSymbolizerLayers(Map map, PointAlignment mode) { var pts = GetSymbolizerPoints(mode); var vLyr = new VectorLayer("PathPoint with 2 parts", new GeometryFeatureProvider(pts.AsEnumerable())); var gpTriangle1 = new System.Drawing.Drawing2D.GraphicsPath(); gpTriangle1.AddPolygon(new [] { new System.Drawing.Point(0, 0), new System.Drawing.Point(5, 10), new System.Drawing.Point(10, 0), new System.Drawing.Point(0, 0), }); var gpTriangle2 = new System.Drawing.Drawing2D.GraphicsPath(); gpTriangle2.AddPolygon(new[] { new System.Drawing.Point(0, 0), new System.Drawing.Point(-5, -10), new System.Drawing.Point(-10, 0), new System.Drawing.Point(0, 0), }); var pps = new SharpMap.Rendering.Symbolizer.PathPointSymbolizer(new[] { new SharpMap.Rendering.Symbolizer.PathPointSymbolizer.PathDefinition { Path = gpTriangle1, Line = new System.Drawing.Pen( System.Drawing.Color.Red, 2), Fill = new System.Drawing.SolidBrush( System.Drawing.Color.DodgerBlue) }, new SharpMap.Rendering.Symbolizer.PathPointSymbolizer.PathDefinition { Path = gpTriangle2, Line = new System.Drawing.Pen( System.Drawing.Color.DodgerBlue, 2), Fill = new System.Drawing.SolidBrush( System.Drawing.Color.Red) } }); vLyr.Style.PointSymbolizer = pps; map.Layers.Add(vLyr); vLyr = new VectorLayer("ReferencePoint", new GeometryFeatureProvider(pts.AsEnumerable())); vLyr.Style.PointSize = 4f; vLyr.Style.PointColor = Brushes.Yellow; map.Layers.Add(vLyr); }
private void AddLinePointSymbolizerLayers(Map map, PointAlignment mode) { var pts = GetSymbolizerPoints(mode); var vLyr = new VectorLayer("LinePoint", new GeometryFeatureProvider(pts.AsEnumerable())); var cps = new SharpMap.Rendering.Symbolizer.CharacterPointSymbolizer { Halo = 1, HaloBrush = new System.Drawing.SolidBrush(System.Drawing.Color.Wheat), Text = "xYz", }; vLyr.Style.PointSymbolizer = cps; map.Layers.Add(vLyr); vLyr = new VectorLayer("ReferencePoint", new GeometryFeatureProvider(pts.AsEnumerable())); vLyr.Style.PointSize = 4f; map.Layers.Add(vLyr); }
private static Vector2 ConvertVector(Vector2 input, PointAlignment alignment) { switch (alignment) { case PointAlignment.BottomRight: input.x = 1f - input.x; break; case PointAlignment.TopLeft: input.y = 1f - input.y; break; case PointAlignment.TopRight: input.y = 1f - input.y; input.x = 1f - input.x; break; } return(input); }
private AM.StreamGeometry CreateCurveGeometry(A.Point p0, A.Point p1, double curvature, CurveOrientation orientation, PointAlignment pt0a, PointAlignment pt1a) { var curveGeometry = new AM.StreamGeometry(); using (var geometryContext = curveGeometry.Open()) { geometryContext.BeginFigure(new A.Point(p0.X, p0.Y), false); double p0x = p0.X; double p0y = p0.Y; double p1x = p1.X; double p1y = p1.Y; LineShapeExtensions.GetCurvedLineBezierControlPoints(orientation, curvature, pt0a, pt1a, ref p0x, ref p0y, ref p1x, ref p1y); var point1 = new A.Point(p0x, p0y); var point2 = new A.Point(p1x, p1y); var point3 = new A.Point(p1.X, p1.Y); geometryContext.CubicBezierTo(point1, point2, point3); geometryContext.EndFigure(false); } return(curveGeometry); }
/// <summary> /// Creates a new <see cref="XPoint"/> instance. /// </summary> /// <param name="x">The X coordinate of point.</param> /// <param name="y">The Y coordinate of point.</param> /// <param name="shape">The point template.</param> /// <param name="alignment">The point alignment.</param> /// <param name="name">The shape name.</param> /// <returns>The new instance of the <see cref="XPoint"/> class.</returns> public static XPoint Create(double x = 0.0, double y = 0.0, BaseShape shape = null, PointAlignment alignment = PointAlignment.None, string name = "") { return(new XPoint() { Name = name, Style = default(ShapeStyle), X = x, Y = y, Alignment = alignment, Shape = shape }); }
/// <summary> /// Get curved line bezier curve control points. /// </summary> /// <param name="orientation">The curved line orientation.</param> /// <param name="offset">The curved line offset.</param> /// <param name="p1a">The line start point alignment.</param> /// <param name="p2a">The line end point alignment.</param> /// <param name="p1x">The adjusted X coordinate for curve start control point.</param> /// <param name="p1y">The adjusted Y coordinate for curve start control point.</param> /// <param name="p2x">The adjusted X coordinate for curve end control point.</param> /// <param name="p2y">The adjusted Y coordinate for curve end control point.</param> public static void GetCurvedLineBezierControlPoints(CurveOrientation orientation, double offset, PointAlignment p1a, PointAlignment p2a, ref double p1x, ref double p1y, ref double p2x, ref double p2y) { if (orientation == CurveOrientation.Auto) { switch (p1a) { case PointAlignment.None: { switch (p2a) { case PointAlignment.None: break; case PointAlignment.Left: p2x -= offset; p1x += offset; break; case PointAlignment.Right: p2x += offset; p1x -= offset; break; case PointAlignment.Top: p2y -= offset; p1y += offset; break; case PointAlignment.Bottom: p2y += offset; p1y -= offset; break; } } break; case PointAlignment.Left: { switch (p2a) { case PointAlignment.None: p1x -= offset; p2x += offset; break; case PointAlignment.Left: p1x -= offset; p2x -= offset; break; case PointAlignment.Right: p1x -= offset; p2x += offset; break; case PointAlignment.Top: p1x -= offset; break; case PointAlignment.Bottom: p2y += offset; break; } } break; case PointAlignment.Right: { switch (p2a) { case PointAlignment.None: p1x += offset; p2x -= offset; break; case PointAlignment.Left: p1x += offset; p2x -= offset; break; case PointAlignment.Right: p1x += offset; p2x += offset; break; case PointAlignment.Top: p1x += offset; break; case PointAlignment.Bottom: p2y += offset; break; } } break; case PointAlignment.Top: { switch (p2a) { case PointAlignment.None: p1y -= offset; p2y += offset; break; case PointAlignment.Left: p2x -= offset; break; case PointAlignment.Right: p2x += offset; break; case PointAlignment.Top: p1y -= offset; p2y -= offset; break; case PointAlignment.Bottom: p1y -= offset; p2y += offset; break; } } break; case PointAlignment.Bottom: { switch (p2a) { case PointAlignment.None: p1y += offset; p2y -= offset; break; case PointAlignment.Left: p1y += offset; break; case PointAlignment.Right: p1y += offset; break; case PointAlignment.Top: p1y += offset; p2y -= offset; break; case PointAlignment.Bottom: p1y += offset; p2y += offset; break; } } break; } } else if (orientation == CurveOrientation.Horizontal) { p1x += offset; p2x -= offset; } else if (orientation == CurveOrientation.Vertical) { p1y += offset; p2y -= offset; } }
private void DrawLineCurveInternal(SKCanvas canvas, SKPaint pen, bool isStroked, ref SKPoint pt1, ref SKPoint pt2, double curvature, CurveOrientation orientation, PointAlignment pt1a, PointAlignment pt2a) { if (isStroked) { using (var path = new SKPath()) { path.MoveTo(pt1.X, pt1.Y); double p1x = pt1.X; double p1y = pt1.Y; double p2x = pt2.X; double p2y = pt2.Y; XLineExtensions.GetCurvedLineBezierControlPoints(orientation, curvature, pt1a, pt2a, ref p1x, ref p1y, ref p2x, ref p2y); path.CubicTo( (float)p1x, (float)p1y, (float)p2x, (float)p2y, pt2.X, pt2.Y); canvas.DrawPath(path, pen); } } }
private static void DrawLineCurveInternal(AM.DrawingContext _dc, AM.Pen pen, bool isStroked, ref A.Point pt1, ref A.Point pt2, double curvature, CurveOrientation orientation, PointAlignment pt1a, PointAlignment pt2a) { if (isStroked) { var sg = new AM.StreamGeometry(); using (var sgc = sg.Open()) { sgc.BeginFigure(new A.Point(pt1.X, pt1.Y), false); double p1x = pt1.X; double p1y = pt1.Y; double p2x = pt2.X; double p2y = pt2.Y; XLineExtensions.GetCurvedLineBezierControlPoints(orientation, curvature, pt1a, pt2a, ref p1x, ref p1y, ref p2x, ref p2y); sgc.CubicBezierTo( new A.Point(p1x, p1y), new A.Point(p2x, p2y), new A.Point(pt2.X, pt2.Y)); sgc.EndFigure(false); } _dc.DrawGeometry(null, pen, sg); } }
private static void DrawLineCurveInternal(Graphics gfx, Pen pen, bool isStroked, ref PointF pt1, ref PointF pt2, double curvature, CurveOrientation orientation, PointAlignment pt1a, PointAlignment pt2a) { if (isStroked) { double p1x = pt1.X; double p1y = pt1.Y; double p2x = pt2.X; double p2y = pt2.Y; XLineExtensions.GetCurvedLineBezierControlPoints(orientation, curvature, pt1a, pt2a, ref p1x, ref p1y, ref p2x, ref p2y); gfx.DrawBezier( pen, pt1.X, pt1.Y, (float)p1x, (float)p1y, (float)p2x, (float)p2y, pt2.X, pt2.Y); } }
private SKPath CreateCurveGeometry(SKPoint p0, SKPoint p1, double curvature, CurveOrientation orientation, PointAlignment pt0a, PointAlignment pt1a) { var curveGeometry = new SKPath(); curveGeometry.MoveTo(new SKPoint((float)p0.X, (float)p0.Y)); double p0x = p0.X; double p0y = p0.Y; double p1x = p1.X; double p1y = p1.Y; LineShapeExtensions.GetCurvedLineBezierControlPoints(orientation, curvature, pt0a, pt1a, ref p0x, ref p0y, ref p1x, ref p1y); var point1 = new SKPoint((float)p0x, (float)p0y); var point2 = new SKPoint((float)p1x, (float)p1y); var point3 = new SKPoint(p1.X, p1.Y); curveGeometry.CubicTo(point1, point2, point3); return(curveGeometry); }
private static void DrawLineCurveInternal(AM.DrawingContext _dc, AM.Pen pen, bool isStroked, ref A.Point pt1, ref A.Point pt2, double curvature, CurveOrientation orientation, PointAlignment pt1a, PointAlignment pt2a) { if (isStroked) { var sg = new AM.StreamGeometry(); using (var sgc = sg.Open()) { sgc.BeginFigure(new A.Point(pt1.X, pt1.Y), false); double p1x = pt1.X; double p1y = pt1.Y; double p2x = pt2.X; double p2y = pt2.Y; LineShapeExtensions.GetCurvedLineBezierControlPoints(orientation, curvature, pt1a, pt2a, ref p1x, ref p1y, ref p2x, ref p2y); sgc.CubicBezierTo( new A.Point(p1x, p1y), new A.Point(p2x, p2y), new A.Point(pt2.X, pt2.Y)); sgc.EndFigure(false); } _dc.DrawGeometry(null, pen, sg); } }
/// <summary> /// Creates a new <see cref="XPoint"/> instance. /// </summary> /// <param name="x">The X coordinate of point.</param> /// <param name="y">The Y coordinate of point.</param> /// <param name="shape">The point template.</param> /// <param name="alignment">The point alignment.</param> /// <param name="name">The shape name.</param> /// <returns>The new instance of the <see cref="XPoint"/> class.</returns> public static XPoint Create(double x = 0.0, double y = 0.0, BaseShape shape = null, PointAlignment alignment = PointAlignment.None, string name = "") { return new XPoint() { Name = name, Style = default(ShapeStyle), X = x, Y = y, Alignment = alignment, Shape = shape }; }