コード例 #1
0
        internal static double smethod_4(Polyline2D polyline, Point2D point)
        {
            int count = polyline.Count;

            switch (count)
            {
            case 0:
                return(double.MaxValue);

            case 1:
                return((polyline[0] - point).GetLengthSquared());

            default:
                double  num1  = double.MaxValue;
                int     num2  = count + (polyline.Closed ? 1 : 0);
                int     num3  = count;
                Point2D start = polyline[0];
                for (int index = 1; index < num2; ++index)
                {
                    Point2D end             = polyline[index % num3];
                    double  distanceSquared = new Segment2D(start, end).GetDistanceSquared(point);
                    if (distanceSquared < num1)
                    {
                        num1 = distanceSquared;
                    }
                    start = end;
                }
                return(num1);
            }
        }
コード例 #2
0
ファイル: ShapeTool.cs プロジェクト: 15831944/WW
        private static void smethod_7(
            Polyline2D polyline,
            Point2D p0,
            Point2D p1,
            Point2D p2,
            double epsilonSquared)
        {
            Vector2D dp02 = p2 - p0;
            Vector2D dp01 = p1 - p0;
            Vector2D dp12 = p2 - p1;

            if (ShapeTool.smethod_9(dp01, dp12, dp02, epsilonSquared))
            {
                polyline.Add(p1);
                polyline.Add(p2);
            }
            else
            {
                Point2D  p1_1     = p0 + 0.5 * dp01;
                Point2D  p1_2     = p1 + 0.5 * dp12;
                Vector2D vector2D = p1_2 - p1_1;
                Point2D  point2D  = p1_1 + 0.5 * vector2D;
                ShapeTool.smethod_7(polyline, p0, p1_1, point2D, epsilonSquared);
                ShapeTool.smethod_7(polyline, point2D, p1_2, p2, epsilonSquared);
            }
        }
コード例 #3
0
ファイル: DxfPolyline2DSpline.cs プロジェクト: 15831944/WW
        private Polyline2D method_24(DxfVertex2DCollection points)
        {
            bool       closed     = this.Closed;
            int        count      = points.Count;
            Polyline2D polyline2D = new Polyline2D(count, closed);

            if (count > 0)
            {
                DxfVertex2D dxfVertex2D = points[0];
                polyline2D.Add(dxfVertex2D.Position);
                for (int index = 1; index < count; ++index)
                {
                    DxfVertex2D point = points[index];
                    if (!(dxfVertex2D.Position == point.Position))
                    {
                        polyline2D.Add(point.Position);
                        dxfVertex2D = point;
                    }
                }
                if (closed && count > 1 && polyline2D[0] == polyline2D[polyline2D.Count - 1])
                {
                    polyline2D.RemoveAt(polyline2D.Count - 1);
                }
            }
            return(polyline2D);
        }
コード例 #4
0
ファイル: ShapeTool.cs プロジェクト: 15831944/WW
        private static void smethod_11(
            Polyline2D polyline,
            Point2D p0,
            Point2D p1,
            Point2D p2,
            Point2D p3,
            double epsilonSquared)
        {
            Vector2D dp01 = p1 - p0;
            Vector2D dp12 = p2 - p1;
            Vector2D dp23 = p3 - p2;

            if (ShapeTool.smethod_10(dp01, dp12, dp23, p3 - p0, epsilonSquared))
            {
                polyline.Add(p1);
                polyline.Add(p2);
                polyline.Add(p3);
            }
            else
            {
                Point2D  p1_1      = p0 + 0.5 * dp01;
                Point2D  point2D1  = p1 + 0.5 * dp12;
                Point2D  p2_1      = p2 + 0.5 * dp23;
                Vector2D vector2D1 = point2D1 - p1_1;
                Vector2D vector2D2 = p2_1 - point2D1;
                Point2D  p2_2      = p1_1 + 0.5 * vector2D1;
                Point2D  p1_2      = point2D1 + 0.5 * vector2D2;
                Vector2D vector2D3 = p1_2 - p2_2;
                Point2D  point2D2  = p2_2 + 0.5 * vector2D3;
                ShapeTool.smethod_11(polyline, p0, p1_1, p2_2, point2D2, epsilonSquared);
                ShapeTool.smethod_11(polyline, point2D2, p1_2, p2_1, p3, epsilonSquared);
            }
        }
コード例 #5
0
        internal void Add(IEnumerable <Edge> edges, Face onThisFace, double arrowsize, System.Drawing.Color clr, int debugHint)
        {
            Random rnd = new Random();

            foreach (Edge edg in edges)
            {
                if (edg.Curve2D(onThisFace) == null)
                {
                    continue;
                }
                int dbgh = debugHint;
                if (debugHint == -1)
                {
                    dbgh = edg.GetHashCode();
                }
                Add(edg.Curve2D(onThisFace), clr, dbgh);
                // noch einen Richtungspfeil zufügen
                GeoPoint2D[] arrowpnts = new GeoPoint2D[3];
                double       pos       = 0.3 + rnd.NextDouble() * 0.4; // to have different positions when the same curve is displayed twice
                GeoVector2D  dir       = edg.Curve2D(onThisFace).DirectionAt(pos).Normalized;
                arrowpnts[1] = edg.Curve2D(onThisFace).PointAt(pos);
                arrowpnts[0] = arrowpnts[1] - arrowsize * dir + arrowsize * dir.ToLeft();
                arrowpnts[2] = arrowpnts[1] - arrowsize * dir + arrowsize * dir.ToRight();
                Polyline2D pl2d = new Polyline2D(arrowpnts);
                Add(pl2d, clr, edg.GetHashCode());
            }
        }
コード例 #6
0
        private static List <Polyline2D> smethod_7(
            Polyline2D[] borders,
            Point2D reference,
            Vector2D offset,
            Vector2D direction,
            double[] dashPattern,
            bool fillInterior)
        {
            IList <Segment2D[]> segment2DArrayList = (IList <Segment2D[]>)Class811.smethod_8(borders, reference, offset, direction, dashPattern, fillInterior);
            List <Polyline2D>   polyline2DList     = new List <Polyline2D>();

            foreach (Segment2D[] segment2DArray in (IEnumerable <Segment2D[]>)segment2DArrayList)
            {
                foreach (Segment2D segment2D in segment2DArray)
                {
                    Polyline2D polyline2D = new Polyline2D();
                    polyline2D.Add(new Point2D(segment2D.Start.X, segment2D.Start.Y));
                    if (segment2D.Start != segment2D.End)
                    {
                        polyline2D.Add(new Point2D(segment2D.End.X, segment2D.End.Y));
                    }
                    polyline2DList.Add(polyline2D);
                }
            }
            return(polyline2DList);
        }
コード例 #7
0
        public static DebuggerContainer Show(GeoPoint2D[] points)
        {
            DebuggerContainer res  = new CADability.DebuggerContainer();
            Polyline2D        pl2d = new Polyline2D(points);

            res.Add(pl2d);
            return(res);
        }
コード例 #8
0
 internal static bool IsInside(Point2D p, Polyline2D polyline)
 {
     if (polyline == null || polyline.Count < 1)
     {
         return(false);
     }
     return((0 + Class749.smethod_0(new Ray2D(p, Vector2D.XAxis), polyline)) % 2 == 1);
 }
コード例 #9
0
ファイル: Polyline3D.cs プロジェクト: 15831944/WW
 public Polyline3D(Polyline2D polyline)
     : this(polyline.Count, polyline.Closed)
 {
     for (int index = 0; index < polyline.Count; ++index)
     {
         this.Add((Point3D)polyline[index]);
     }
 }
コード例 #10
0
        public Polyline2D ToPolyline2D()
        {
            Polyline2D polyline2D = new Polyline2D(this.Count, this.Closed);

            foreach (Vector4D vector4D in (List <Vector4D>) this)
            {
                polyline2D.Add(vector4D.ToPoint2D());
            }
            return(polyline2D);
        }
コード例 #11
0
 private static bool smethod_14(Point2D v, Polyline2D[] borders, Polyline2D exclude)
 {
     foreach (Polyline2D border in borders)
     {
         if (border != exclude && Class749.IsInside(v, border))
         {
             return(true);
         }
     }
     return(false);
 }
コード例 #12
0
            public static PolylineInt FromPolyline2D(Polyline2D polyline2D, Point2d origin, double unit)
            {
                var intPoints = polyline2D.Select(o => new IntPoint((o.X - origin.X) / unit, (o.Y - origin.Y) / unit));

                var result = new PolylineInt(intPoints)
                {
                    Closed = polyline2D.Closed
                };

                return(result);
            }
コード例 #13
0
ファイル: Class194.cs プロジェクト: 15831944/WW
        protected override Polyline2D vmethod_1(ns9.Class107 edge)
        {
            Point3D     location1        = edge.StartVertex.Point.Location;
            Point3D     location2        = edge.EndVertex.Point.Location;
            Polyline2D  polyline2D       = new Polyline2D(2);
            Interface26 pointParamMapper = this.PointParamMapper;

            polyline2D.Add(pointParamMapper.imethod_0(location1));
            polyline2D.Add(pointParamMapper.imethod_0(location2));
            return(polyline2D);
        }
コード例 #14
0
ファイル: CanvasRenderer2D.cs プロジェクト: jboneng/OsmSharp
        /// <summary>
        /// Draws text along a given line.
        /// </summary>
        /// <param name="target"></param>
        /// <param name="x"></param>
        /// <param name="y"></param>
        /// <param name="color"></param>
        /// <param name="size"></param>
        /// <param name="text">Text.</param>
        protected override void DrawLineText(Target2DWrapper <global::Android.Graphics.Canvas> target, double[] xa, double[] ya, string text, int color,
                                             double size, int?haloColor, int?haloRadius, string fontName)
        {
            if (xa.Length > 1)
            {
                float sizeInPixels = this.ToPixels(size);
                _paint.SubpixelText = true;
                _paint.TextSize     = (float)sizeInPixels;
                _paint.AntiAlias    = true;

                // transform first.
                double[] xTransformed = new double[xa.Length];
                double[] yTransformed = new double[ya.Length];
                for (int idx = 0; idx < xa.Length; idx++)
                {
                    double[] transformed = this.Tranform(xa[idx], ya[idx]);
                    xTransformed [idx] = transformed [0];
                    yTransformed [idx] = transformed [1];
                }

                // get some metrics on the texts.
                float[] characterWidths = new float[text.Length];
                _paint.GetTextWidths(text, characterWidths);
//				for (int idx = 0; idx < characterWidths.Length; idx++)
//				{
//					characterWidths[idx] = _target, _view, characterWidths[idx];
//				}
                var characterHeight = (float)sizeInPixels;
                var textLength      = characterWidths.Sum();

                // calculate line length.
                var lineLength = Polyline2D.Length(xTransformed, yTransformed);
                if (lineLength > textLength * 1.2f)
                {
                    // calculate the number of labels.
                    int labelCount = (int)System.Math.Floor(lineLength / (textLength * 10)) + 1;

                    // calculate positions of label(s).
                    double positionGap = lineLength / (labelCount + 1);

                    // draw each label.
                    for (double position = positionGap; position < lineLength; position = position + positionGap)
                    {
                        this.DrawLineTextSegment(target, xTransformed, yTransformed, text, color, size, haloColor, haloRadius, position, characterWidths,
                                                 textLength, characterHeight);
                    }
                }
            }
        }
コード例 #15
0
        public IShape2D ToShape2D(Matrix4D matrix)
        {
            Polyline2DCollection polyline2Dcollection = new Polyline2DCollection(this.ilist_0.Count);

            foreach (Polyline4D polyline4D in (IEnumerable <Polyline4D>) this.ilist_0)
            {
                Polyline2D polyline2D = new Polyline2D(polyline4D.Count, polyline4D.Closed);
                foreach (Vector4D vector in (List <Vector4D>)polyline4D)
                {
                    polyline2D.Add(matrix.TransformToPoint2D(vector));
                }
                polyline2Dcollection.Add(polyline2D);
            }
            return((IShape2D)polyline2Dcollection);
        }
コード例 #16
0
        private FlatShape4D method_0(Matrix4D transform, Matrix4D inverse)
        {
            GeneralShape2D generalShape2D = new GeneralShape2D();

            foreach (Polyline4D polyline4D in (IEnumerable <Polyline4D>) this.ilist_0)
            {
                Polyline2D polyline2D = new Polyline2D(polyline4D.Closed);
                foreach (Vector4D point in (List <Vector4D>)polyline4D)
                {
                    polyline2D.Add(inverse.TransformTo2D(point));
                }
                generalShape2D.Append((IShape2D)polyline2D, false);
            }
            return(new FlatShape4D((IShape2D)generalShape2D, transform, this.IsFilled));
        }
コード例 #17
0
        internal void Add(IEnumerable <ICurve2D> crvs, double arrowsize, System.Drawing.Color clr, int debugHint)
        {
            int i = 0;

            foreach (ICurve2D crv in crvs)
            {
                Add(crv, clr, debugHint);
                // noch einen Richtungspfeil zufügen
                GeoPoint2D[] arrowpnts = new GeoPoint2D[3];
                GeoVector2D  dir       = crv.DirectionAt(0.5).Normalized;
                arrowpnts[1] = crv.PointAt(0.5);
                arrowpnts[0] = arrowpnts[1] - arrowsize * dir + arrowsize * dir.ToLeft();
                arrowpnts[2] = arrowpnts[1] - arrowsize * dir + arrowsize * dir.ToRight();
                Polyline2D pl2d = new Polyline2D(arrowpnts);
                Add(pl2d, clr, debugHint * 100 + i);
                ++i;
            }
        }
コード例 #18
0
        /// <summary>
        /// Draws text along a line.
        /// </summary>
        /// <param name="target"></param>
        /// <param name="x"></param>
        /// <param name="y"></param>
        /// <param name="text"></param>
        /// <param name="color"></param>
        /// <param name="size"></param>
        /// <param name="haloColor"></param>
        /// <param name="haloRadius"></param>
        /// <param name="fontName"></param>
        protected override void DrawLineText(Target2DWrapper <Graphics> target, double[] x, double[] y, string text, int color,
                                             double size, int?haloColor, int?haloRadius, string fontName)
        {
            if (x.Length > 1)
            {
                float sizeInPixels = this.ToPixels(size);
                Color textColor    = Color.FromArgb(color);
                Brush brush        = new SolidBrush(textColor);
                Brush haloBrush    = null;
                if (haloColor.HasValue && haloRadius.HasValue && haloRadius.Value > 0)
                {
                    haloBrush = new SolidBrush(Color.FromArgb(haloColor.Value));
                }
                Font font = new Font(FontFamily.GenericSansSerif, sizeInPixels);

                // get some metrics on the texts.
                var characterWidths = GetCharacterWidths(target.Target, text, font);
                for (int idx = 0; idx < characterWidths.Length; idx++)
                {
                    characterWidths[idx] = (float)this.FromPixels(_target, _view, characterWidths[idx]);
                }
                var characterHeight = target.Target.MeasureString(text, font).Height;
                var textLength      = characterWidths.Sum();
//                var avgCharacterWidth = textLength / characterWidths.Length;

                // calculate line length.
                var lineLength = Polyline2D.Length(x, y);
                if (lineLength > textLength * 1.1f)
                {
                    // calculate the number of labels.
                    int labelCount = (int)System.Math.Floor(lineLength / (textLength * 10)) + 1;

                    // calculate positions of label(s).
                    double positionGap = lineLength / (labelCount + 1);

                    // draw each label.
                    for (double position = positionGap; position < lineLength; position = position + positionGap)
                    {
                        this.DrawLineTextSegment(target, x, y, text, color, size, haloColor, haloRadius, position, characterWidths,
                                                 textLength, font, characterHeight, haloBrush, brush);
                    }
                }
            }
        }
コード例 #19
0
        internal static void smethod_13(
            DxfEntity entity,
            DrawContext.Surface context,
            WW.Cad.Drawing.Surface.Geometry geometry,
            IList <Polyline2D> polylinesA,
            IList <Polyline2D> polylinesB,
            Matrix4D transform,
            Vector3D normal,
            bool areSurfaces)
        {
            int count = polylinesA.Count;

            for (int index = 0; index < count; ++index)
            {
                Polyline2D polylineA = polylinesA[index];
                Polyline2D polylineB = polylinesB[index];
                Class940.smethod_14(entity, context, geometry, polylineA, polylineB, transform, normal, areSurfaces);
            }
        }
コード例 #20
0
        internal static int smethod_0(Ray2D ray, Polyline2D polyline)
        {
            int     num1  = 0;
            int     num2  = polyline.Count + (polyline.Closed ? 1 : 0);
            int     count = polyline.Count;
            Point2D start = polyline[0];

            for (int index = 1; index < num2; ++index)
            {
                Point2D   end = polyline[index % count];
                Segment2D b   = new Segment2D(start, end);
                if (Ray2D.Intersects(ray, b))
                {
                    ++num1;
                }
                start = end;
            }
            return(num1);
        }
コード例 #21
0
        public static double GetLength(Polyline2D polyline, ILineTypeScaler lineTypeScaler)
        {
            double num = 0.0;

            if (polyline.Count > 1)
            {
                Point2D point2D1 = polyline[0];
                for (int index = 1; index < polyline.Count; ++index)
                {
                    Point2D point2D2 = polyline[index];
                    num     += lineTypeScaler.GetScaledLength(point2D2 - point2D1);
                    point2D1 = point2D2;
                }
                if (polyline.Closed)
                {
                    num += lineTypeScaler.GetScaledLength(polyline[0] - point2D1);
                }
            }
            return(num);
        }
コード例 #22
0
        protected override Polyline2D vmethod_1(ns9.Class107 edge)
        {
            Point3D    location1  = edge.StartVertex.Point.Location;
            Point3D    location2  = edge.EndVertex.Point.Location;
            Polyline2D polyline2D = new Polyline2D(2);

            if (location1 == location2 && this.double_2 != 0.0)
            {
                Point3D  point3D1 = new Point3D(this.class247_0.Position);
                double   length   = this.class247_0.MajorAxis.GetLength();
                Vector3D normal   = this.class247_0.Normal;
                normal.Normalize();
                Point3D point3D2 = point3D1 - normal * (length / System.Math.Tan(this.double_2));
                if ((point3D2 - location1).GetLength() < 0.0001 * length)
                {
                    double x1 = Vector3D.DotProduct(point3D2 - point3D1, normal) / System.Math.Cos(this.double_2);
                    if (this.class690_0.Value)
                    {
                        double x2 = -x1;
                        polyline2D.Add(new Point2D(x2, 2.0 * System.Math.PI));
                        polyline2D.Add(new Point2D(x2, 4.0 * System.Math.PI / 3.0));
                        polyline2D.Add(new Point2D(x2, 2.0 * System.Math.PI / 3.0));
                        polyline2D.Add(new Point2D(x2, 0.0));
                    }
                    else
                    {
                        polyline2D.Add(new Point2D(x1, 0.0));
                        polyline2D.Add(new Point2D(x1, 2.0 * System.Math.PI / 3.0));
                        polyline2D.Add(new Point2D(x1, 4.0 * System.Math.PI / 3.0));
                        polyline2D.Add(new Point2D(x1, 2.0 * System.Math.PI));
                    }
                    return(polyline2D);
                }
            }
            Interface26 pointParamMapper = this.PointParamMapper;

            polyline2D.Add(pointParamMapper.imethod_0(location1));
            polyline2D.Add(pointParamMapper.imethod_0(location2));
            return(polyline2D);
        }
コード例 #23
0
            public static Polyline2D FromCurve(Rhino.Geometry.Curve curve, Plane plane)
            {
                Polyline polyline;

                if (!curve.TryGetPolyline(out polyline))
                {
                    return(null);
                }

                var points = polyline.Select(o => o.Map2D(plane));

                if (curve.ClosedCurveOrientation(plane.ZAxis) == CurveOrientation.Clockwise)
                {
                    points = points.Reverse();
                }

                var result = new Polyline2D(points)
                {
                    Closed = curve.IsClosed
                };

                return(result);
            }
コード例 #24
0
        public static IEnumerable <Rhino.Geometry.Curve> Offset(IEnumerable <Rhino.Geometry.Curve> curves, double distance, JoinType joinType, EndType endType, double miter, double arcTolerance, Plane?plane)
        {
            var curveList = curves as IList <Rhino.Geometry.Curve> ?? curves.ToList();

            plane = GetPlane(curveList, plane);


            var polylines2D = curveList.Select(o => Polyline2D.FromCurve(o, plane.Value))
                              .Where(o => o != null)
                              .ToList();


            double  unit;
            Point2d center;

            CalculateUnit(polylines2D, miter * distance, out unit, out center);


            var polylinesInt = polylines2D.Select(o => PolylineInt.FromPolyline2D(o, center, unit))
                               .ToList();


            var clipper = new ClipperOffset(miter, arcTolerance / unit);

            foreach (var polygon in polylinesInt)
            {
                clipper.AddPath(polygon, joinType, polygon.Closed ? EndType.etClosedPolygon : endType);
            }


            var solution = new List <List <IntPoint> >();

            clipper.Execute(ref solution, distance / unit);


            return(solution.Select(o => o.ToCurve(plane.Value, center, unit)));
        }
コード例 #25
0
ファイル: CanvasRenderer2D.cs プロジェクト: jboneng/OsmSharp
        public void DrawLineTextSegment(Target2DWrapper <global::Android.Graphics.Canvas> target, double[] xTransformed, double[] yTransformed, string text, int color,
                                        double size, int?haloColor, int?haloRadius, double middlePosition, float[] characterWidths, double textLength,
                                        float characterHeight)
        {
            _paint.Color = new global::Android.Graphics.Color(color);
            _paint.SetStyle(global::Android.Graphics.Paint.Style.Fill);

            // see if the text is 'upside down'.
            double   averageAngle = 0;
            double   first        = middlePosition - (textLength / 2.0);
            PointF2D current      = Polyline2D.PositionAtPosition(xTransformed, yTransformed, first);

            for (int idx = 0; idx < text.Length; idx++)
            {
                double   nextPosition = middlePosition - (textLength / 2.0) + ((textLength / (text.Length)) * (idx + 1));
                PointF2D next         = Polyline2D.PositionAtPosition(xTransformed, yTransformed, nextPosition);

                // Translate to the final position, the center of line-segment between 'current' and 'next'
                //PointF2D position = current + ((next - current) / 2.0);

                // calculate the angle.
                VectorF2D vector       = next - current;
                VectorF2D horizontal   = new VectorF2D(1, 0);
                double    angleDegrees = ((Degree)horizontal.Angle(vector)).Value;
                averageAngle = averageAngle + angleDegrees;
                current      = next;
            }
            averageAngle = averageAngle / text.Length;

            // reverse if 'upside down'.
            double[] xText = xTransformed;
            double[] yText = yTransformed;
            if (averageAngle > 90 && averageAngle < 180 + 90)
            {             // the average angle is > PI => means upside down.
                xText = xTransformed.Reverse <double>().ToArray <double>();
                yText = yTransformed.Reverse <double>().ToArray <double>();
            }

            // calculate a central position along the line.
            first   = middlePosition - (textLength / 2.0);
            current = Polyline2D.PositionAtPosition(xText, yText, first);
            double nextPosition2 = first;

            for (int idx = 0; idx < text.Length; idx++)
            {
                nextPosition2 = nextPosition2 + characterWidths[idx];
                //double nextPosition = middle - (textLength / 2.0) + ((textLength / (text.Length)) * (idx + 1));
                PointF2D next        = Polyline2D.PositionAtPosition(xText, yText, nextPosition2);
                char     currentChar = text[idx];
                global::Android.Graphics.Path characterPath = new global::Android.Graphics.Path();
                _paint.GetTextPath(text, idx, idx + 1, 0, 0, characterPath);
                using (characterPath)
                {
                    // Transformation matrix to move the character to the correct location.
                    // Note that all actions on the Matrix class are prepended, so we apply them in reverse.
                    var transform = new Matrix();

                    // Translate to the final position, the center of line-segment between 'current' and 'next'
                    PointF2D position = current;
                    //PointF2D position = current + ((next - current) / 2.0);
                    //double[] transformed = this.Tranform(position[0], position[1]);
                    transform.SetTranslate((float)position[0], (float)position[1]);

                    // calculate the angle.
                    VectorF2D vector       = next - current;
                    VectorF2D horizontal   = new VectorF2D(1, 0);
                    double    angleDegrees = ((Degree)horizontal.Angle(vector)).Value;

                    // Rotate the character
                    transform.PreRotate((float)angleDegrees);

                    // Translate the character so the centre of its base is over the origin
                    transform.PreTranslate(0, characterHeight / 2.5f);

                    //transform.Scale((float)this.FromPixels(_target, _view, 1),
                    //    (float)this.FromPixels(_target, _view, 1));
                    characterPath.Transform(transform);

                    if (haloColor.HasValue && haloRadius.HasValue && haloRadius.Value > 0)
                    {
                        _paint.SetStyle(global::Android.Graphics.Paint.Style.FillAndStroke);
                        _paint.StrokeWidth = haloRadius.Value;
                        _paint.Color       = new global::Android.Graphics.Color(haloColor.Value);
                        using (global::Android.Graphics.Path haloPath = new global::Android.Graphics.Path())
                        {
                            _paint.GetFillPath(characterPath, haloPath);
                            // Draw the character
                            target.Target.DrawPath(haloPath, _paint);
                        }
                    }

                    // Draw the character
                    _paint.SetStyle(global::Android.Graphics.Paint.Style.Fill);
                    _paint.StrokeWidth = 0;
                    _paint.Color       = new global::Android.Graphics.Color(color);
                    target.Target.DrawPath(characterPath, _paint);
                }
                current = next;
            }
        }
コード例 #26
0
ファイル: DxfPolyline2DSpline.cs プロジェクト: 15831944/WW
        private Polyline2D method_30(int degree, GraphicsConfig config)
        {
            int count1 = this.dxfVertex2DCollection_0.Count;

            if (count1 <= degree)
            {
                return(this.method_18());
            }
            BSplineCurve2D bsplineCurve2D = new BSplineCurve2D(degree);

            bsplineCurve2D.AddKnots(BSplineD.CreateDefaultKnotValues(degree, count1, this.Closed));
            foreach (DxfVertex2D dxfVertex2D in (DxfHandledObjectCollection <DxfVertex2D>) this.dxfVertex2DCollection_0)
            {
                bsplineCurve2D.ControlPoints.AddLast(dxfVertex2D.Position);
            }
            if (this.Closed)
            {
                for (int index = 0; index < degree; ++index)
                {
                    bsplineCurve2D.ControlPoints.AddLast(this.dxfVertex2DCollection_0[index].Position);
                }
                double u = 0.0;
                LinkedListNode <double>          previousKnot1  = bsplineCurve2D.Knots.First;
                LinkedListNode <WW.Math.Point2D> previousPoint1 = bsplineCurve2D.ControlPoints.First;
                for (int index = 0; index < degree; ++index)
                {
                    previousKnot1 = previousKnot1.Next;
                }
                for (int index = 0; index < degree; ++index)
                {
                    bsplineCurve2D.InsertKnot(previousKnot1, previousPoint1, u);
                    previousKnot1  = previousKnot1.Next;
                    previousPoint1 = previousPoint1.Next;
                }
                double count2 = (double)this.dxfVertex2DCollection_0.Count;
                LinkedListNode <double>          previousKnot2  = bsplineCurve2D.Knots.Last.Previous;
                LinkedListNode <WW.Math.Point2D> previousPoint2 = bsplineCurve2D.ControlPoints.Last;
                for (int index = 0; index < degree; ++index)
                {
                    previousKnot2  = previousKnot2.Previous;
                    previousPoint2 = previousPoint2.Previous;
                }
                for (int index = 0; index < degree; ++index)
                {
                    bsplineCurve2D.InsertKnot(previousKnot2, previousPoint2, count2);
                    previousKnot2  = previousKnot2.Next;
                    previousPoint2 = previousPoint2.Next;
                }
                for (int index = 0; index < degree; ++index)
                {
                    bsplineCurve2D.ControlPoints.RemoveFirst();
                    bsplineCurve2D.Knots.RemoveFirst();
                    bsplineCurve2D.ControlPoints.RemoveLast();
                    bsplineCurve2D.Knots.RemoveLast();
                }
            }
            double epsilon = config.ShapeFlattenEpsilon;

            if (epsilon < 0.0)
            {
                Bounds2D bounds2D = new Bounds2D();
                foreach (DxfVertex2D dxfVertex2D in (DxfHandledObjectCollection <DxfVertex2D>) this.dxfVertex2DCollection_0)
                {
                    bounds2D.Update(dxfVertex2D.Position);
                }
                epsilon = !bounds2D.Initialized ? 0.01 : -epsilon *bounds2D.Delta.GetLength();
            }
            bsplineCurve2D.RefineKnots(epsilon, 20);
            Polyline2D polyline2D = new Polyline2D(this.Closed);

            foreach (WW.Math.Point2D controlPoint in bsplineCurve2D.ControlPoints)
            {
                polyline2D.Add(controlPoint);
            }
            return(polyline2D);
        }
コード例 #27
0
ファイル: DxfPolyline2DSpline.cs プロジェクト: 15831944/WW
        internal override void GetPolylines(
            DrawContext context,
            ILineTypeScaler lineTypeScaler,
            out IList <IList <Polyline2D> > polylinesList1,
            out IList <IList <Polyline2D> > polylinesList2,
            out IList <FlatShape4D> shapes,
            out bool fill)
        {
            DxfHeader      header = context.Model.Header;
            GraphicsConfig config = context.Config;

            polylinesList1 = (IList <IList <Polyline2D> >) new List <IList <Polyline2D> >();
            polylinesList2 = (IList <IList <Polyline2D> >) new List <IList <Polyline2D> >();
            shapes         = (IList <FlatShape4D>)null;
            if (config.ShowSplineControlPoints)
            {
                polylinesList1.Add((IList <Polyline2D>) new Polyline2D[1]
                {
                    this.method_16()
                });
                polylinesList2.Add((IList <Polyline2D>)null);
            }
            if (config.ShowSplineApproximationPoints)
            {
                polylinesList1.Add((IList <Polyline2D>) new Polyline2D[1]
                {
                    this.method_18()
                });
                polylinesList2.Add((IList <Polyline2D>)null);
            }
            if (this.method_32(this.dxfVertex2DCollection_0))
            {
                Polyline2D polyline = (Polyline2D)null;
                if (config.ShowSplineInterpolatedPoints)
                {
                    switch (this.splineType_0)
                    {
                    case SplineType.None:
                        if (!config.ShowSplineApproximationPoints)
                        {
                            polyline = this.method_18();
                            break;
                        }
                        break;

                    case SplineType.QuadraticBSpline:
                        polyline = this.method_30(2, context.Config);
                        break;

                    case SplineType.CubicBSpline:
                        polyline = this.method_30(3, context.Config);
                        break;
                    }
                }
                fill = false;
                if (polyline != null)
                {
                    IList <Polyline2D> resultLines = (IList <Polyline2D>) new List <Polyline2D>();
                    shapes = (IList <FlatShape4D>) new List <FlatShape4D>();
                    DxfUtil.smethod_0(context.Config, resultLines, shapes, polyline, context.Config.ApplyLineType ? this.GetLineType(context) : (DxfLineType)null, context.TotalLineTypeScale * this.LineTypeScale, lineTypeScaler);
                    polylinesList1.Add(resultLines);
                    polylinesList2.Add((IList <Polyline2D>)null);
                    if (shapes != null && shapes.Count == 0)
                    {
                        shapes = (IList <FlatShape4D>)null;
                    }
                }
            }
            else
            {
                WW.Cad.Drawing.Polyline2D2WN polyline = (WW.Cad.Drawing.Polyline2D2WN)null;
                if (config.ShowSplineInterpolatedPoints)
                {
                    switch (this.splineType_0)
                    {
                    case SplineType.None:
                        if (!config.ShowSplineApproximationPoints)
                        {
                            polyline = this.method_23();
                            break;
                        }
                        break;

                    case SplineType.QuadraticBSpline:
                        polyline = this.method_31(2, (int)context.Config.NoOfSplineLineSegments);
                        break;

                    case SplineType.CubicBSpline:
                        polyline = this.method_31(3, (int)context.Config.NoOfSplineLineSegments);
                        break;
                    }
                }
                fill = false;
                if (polyline != null)
                {
                    IList <Polyline2D> resultPolylines1;
                    IList <Polyline2D> resultPolylines2;
                    DxfUtil.smethod_25(context.Config, polyline, context.Config.ApplyLineType ? this.GetLineType(context) : (DxfLineType)null, context.TotalLineTypeScale * this.LineTypeScale, lineTypeScaler, false, out resultPolylines1, out resultPolylines2, out shapes, out fill);
                    polylinesList1.Add(resultPolylines1);
                    polylinesList2.Add(resultPolylines2);
                }
            }
            if (shapes != null && shapes.Count == 0)
            {
                shapes = (IList <FlatShape4D>)null;
            }
            fill &= context.Model.Header.FillMode;
        }
コード例 #28
0
ファイル: CGContextRenderer.cs プロジェクト: detlevn/OsmSharp
        /// <summary>
        /// Draws text along a given line.
        /// </summary>
        /// <param name="target"></param>
        /// <param name="x"></param>
        /// <param name="y"></param>
        /// <param name="color"></param>
        /// <param name="size"></param>
        /// <param name="text">Text.</param>
        protected override void DrawLineText(Target2DWrapper <CGContextWrapper> target, double[] xa, double[] ya, string text, int color,
                                             double size, int?haloColor, int?haloRadius, string fontName)
        {
            float textSize = this.ToPixels(size) * _scaleFactor;

            // transform first.
            double[] xTransformed = new double[xa.Length];
            double[] yTransformed = new double[ya.Length];
            for (int idx = 0; idx < xa.Length; idx++)
            {
                double[] transformed = this.Transform(xa[idx], ya[idx]);
                xTransformed[idx] = transformed[0];
                yTransformed[idx] = transformed[1];
            }

            // set the fill color as the regular text-color.
            target.Target.CGContext.InterpolationQuality = CGInterpolationQuality.High;
            target.Target.CGContext.SetAllowsFontSubpixelQuantization(true);
            target.Target.CGContext.SetAllowsFontSmoothing(true);
            target.Target.CGContext.SetAllowsAntialiasing(true);
            target.Target.CGContext.SetAllowsSubpixelPositioning(true);
            target.Target.CGContext.SetShouldAntialias(true);

            // get the glyhps/paths from the font.
            CTFont             font             = this.GetFont(fontName, textSize);
            CTStringAttributes stringAttributes = new CTStringAttributes
            {
                ForegroundColorFromContext = true,
                Font = font
            };
            NSAttributedString attributedString = new NSAttributedString(text, stringAttributes);
            CTLine             line             = new CTLine(attributedString);
            RectangleF         textBounds       = line.GetBounds(CTLineBoundsOptions.UseOpticalBounds);

            CTRun[] runs       = line.GetGlyphRuns();
            var     lineLength = Polyline2D.Length(xTransformed, yTransformed);

            // set the correct tranformations to draw the resulting paths.
            target.Target.CGContext.SaveState();
            //target.Target.CGContext.TranslateCTM (xPixels, yPixels);
            //target.Target.CGContext.ConcatCTM (new CGAffineTransform (1.0f, 0.0f, 0.0f, -1.0f, 0.0f, 0.0f));
            foreach (CTRun run in runs)
            {
                ushort[] glyphs          = run.GetGlyphs();
                PointF[] positions       = run.GetPositions();
                float[]  characterWidths = new float[glyphs.Length];
                float    previous        = 0;
                float    textLength      = (float)positions[positions.Length - 1].X;
                //float textLength = (float)this.FromPixels(_target, _view, positions [positions.Length - 1].X);
                if (lineLength > textLength * 1.2f)
                {
                    for (int idx = 0; idx < characterWidths.Length - 1; idx++)
                    {
                        //characterWidths [idx] = (float)this.FromPixels(_target, _view, positions [idx + 1].X - previous);
                        characterWidths[idx] = (float)(positions[idx + 1].X - previous);
                        previous             = positions[idx + 1].X;
                    }
                    characterWidths[characterWidths.Length - 1] = characterWidths[characterWidths.Length - 2];
                    float characterHeight = textBounds.Height;

                    this.DrawLineTextSegment(target, xTransformed, yTransformed, glyphs, color, haloColor, haloRadius,
                                             lineLength / 2f, characterWidths, textLength, characterHeight, font);
                }
            }

            target.Target.CGContext.RestoreState();
        }
コード例 #29
0
ファイル: BoundingRect.cs プロジェクト: SOFAgh/CADability
        /// <summary>
        /// Returns a <see cref="Border"/> that consists of the four lines of this ractangle.
        /// </summary>
        /// <returns>The border</returns>
        public Border ToBorder()
        {
            Polyline2D p2d = new Polyline2D(new GeoPoint2D[] { new GeoPoint2D(Left, Bottom), new GeoPoint2D(Right, Bottom), new GeoPoint2D(Right, Top), new GeoPoint2D(Left, Top), new GeoPoint2D(Left, Bottom) });

            return(new Border(p2d));
        }
コード例 #30
0
ファイル: CGContextRenderer.cs プロジェクト: detlevn/OsmSharp
        private void DrawLineTextSegment(Target2DWrapper <CGContextWrapper> target, double[] xTransformed, double[] yTransformed, ushort[] glyphs, int color,
                                         int?haloColor, int?haloRadius, double middlePosition, float[] characterWidths,
                                         double textLength, float charachterHeight, CTFont font)
        {
            // see if text is 'upside down'
            double   averageAngle = 0;
            double   first        = middlePosition - (textLength / 2.0);
            PointF2D current      = Polyline2D.PositionAtPosition(xTransformed, yTransformed, first);

            for (int idx = 0; idx < glyphs.Length; idx++)
            {
                double   nextPosition = middlePosition - (textLength / 2.0) + ((textLength / (glyphs.Length)) * (idx + 1));
                PointF2D next         = Polyline2D.PositionAtPosition(xTransformed, yTransformed, nextPosition);

                // translate to the final position, the center of the line segment between 'current' and 'next'.
                //PointF2D position = current + ((next - current) / 2.0);

                // calculate the angle.
                VectorF2D vector       = next - current;
                VectorF2D horizontal   = new VectorF2D(1, 0);
                double    angleDegrees = ((Degree)horizontal.Angle(vector)).Value;
                averageAngle = averageAngle + angleDegrees;
                current      = next;
            }
            averageAngle = averageAngle / glyphs.Length;


            // revers if 'upside down'
            double[] xText = xTransformed;
            double[] yText = yTransformed;
            if (averageAngle > 90 && averageAngle < 180 + 90)
            {
                xText = xTransformed.Reverse().ToArray();
                yText = yTransformed.Reverse().ToArray();
            }
            first   = middlePosition - (textLength / 2.0);
            current = Polyline2D.PositionAtPosition(xText, yText, first);

            double nextPosition2 = first;

            for (int idx = 0; idx < glyphs.Length; idx++)
            {
                nextPosition2 = nextPosition2 + characterWidths[idx];
                PointF2D next = Polyline2D.PositionAtPosition(xText, yText, nextPosition2);
                //ushort currentChar = glyphs [idx];

                PointF2D position = current;

                target.Target.CGContext.SaveState();

                // translate to the final position, the center of the line segment between 'current' and 'next'.
//                double[] transformed = this.Tranform(position[0], position[1]);
//				target.Target.CGContext.TranslateCTM (
//					(float)transformed [0],
//					(float)transformed [1]);
                target.Target.CGContext.TranslateCTM((float)position[0], (float)position[1]);

                // calculate the angle.
                VectorF2D vector       = next - current;
                VectorF2D horizontal   = new VectorF2D(1, 0);
                double    angleDegrees = (horizontal.Angle(vector)).Value;

                // rotate the character.
                target.Target.CGContext.RotateCTM((float)angleDegrees);

                // rotate the text to point down no matter what the map tilt is.
                //target.Target.CGContext.RotateCTM ((float)_view.Angle.Value);

                // translate the character so the center of its base is over the origin.
                target.Target.CGContext.TranslateCTM(0, charachterHeight / 3.0f);

                // rotate 'upside down'
                target.Target.CGContext.ConcatCTM(new CGAffineTransform(1.0f, 0.0f, 0.0f, -1.0f, 0.0f, 0.0f));

                target.Target.CGContext.BeginPath();

                CGPath path = font.GetPathForGlyph(glyphs[idx]);

                if (haloRadius.HasValue && haloColor.HasValue)
                {                 // also draw the halo.
                    using (CGPath haloPath = path.CopyByStrokingPath(
                               haloRadius.Value * 2, CGLineCap.Round, CGLineJoin.Round, 0))
                    {
                        SimpleColor haloSimpleColor = SimpleColor.FromArgb(haloColor.Value);
                        target.Target.CGContext.SetFillColor(haloSimpleColor.R / 256.0f, haloSimpleColor.G / 256.0f, haloSimpleColor.B / 256.0f,
                                                             haloSimpleColor.A / 256.0f);
                        target.Target.CGContext.BeginPath();
                        target.Target.CGContext.AddPath(haloPath);
                        target.Target.CGContext.DrawPath(CGPathDrawingMode.Fill);
                    }
                }

                // set the fill color as the regular text-color.
                SimpleColor simpleColor = SimpleColor.FromArgb(color);
                target.Target.CGContext.SetFillColor(simpleColor.R / 256.0f, simpleColor.G / 256.0f, simpleColor.B / 256.0f,
                                                     simpleColor.A / 256.0f);

                // draw the text paths.
                target.Target.CGContext.BeginPath();
                target.Target.CGContext.AddPath(path);
                target.Target.CGContext.DrawPath(CGPathDrawingMode.Fill);

//				target.Target.CGContext.AddPath (path);
//				if (haloRadius.HasValue && haloColor.HasValue) { // also draw the halo.
//					target.Target.CGContext.DrawPath (CGPathDrawingMode.FillStroke);
//				} else {
//					target.Target.CGContext.DrawPath (CGPathDrawingMode.Fill);
//				}
                //target.Target.CGContext.ClosePath ();
                target.Target.CGContext.RestoreState();

                current = next;
            }
        }