Ejemplo n.º 1
0
        public float[] ToDashPattern(float[] pattern, PointF startPoint, PointF endPoint)
        {
            float[] dashPattern = null;
            if (Marker == null)
            {
                dashPattern = pattern;
            }
            else
            {
                if (pattern != null)
                {
                    switch (pattern.Length)
                    {
                    case 0:
                        dashPattern = pattern;
                        break;

                    case 1:
                    default:
                        SizeF size      = Marker.Size;
                        int   imgWidth  = (int)Math.Ceiling(size.Width);
                        int   imgHeight = (int)Math.Ceiling(size.Height);
                        switch (pattern.Length)
                        {
                        case 1:
                            float angle        = DrawingHelper.GetAngle(startPoint, endPoint, false);
                            float totalLength  = Convert.ToSingle(DrawingHelper.Distance(startPoint.X, startPoint.Y, endPoint.X, endPoint.Y));
                            float centerX      = (startPoint.X + endPoint.X) / 2;
                            float centerY      = (startPoint.Y + endPoint.Y) / 2;
                            float dy           = Convert.ToSingle(imgWidth / 2.0 * Math.Sin(angle));
                            float dx           = Convert.ToSingle(-imgWidth / 2.0 * Math.Cos(angle));
                            float x            = centerX - dx;
                            float y            = centerY - dy;
                            float firstLength  = Convert.ToSingle(DrawingHelper.Distance(startPoint.X, startPoint.Y, x, y));
                            float secondLength = imgWidth;
                            float thirdLength  = totalLength - firstLength - secondLength;
                            if (thirdLength > 0)
                            {
                                dashPattern = new float[]
                                {
                                    0, firstLength, secondLength, thirdLength
                                };
                            }
                            break;

                        default:
                            dashPattern = new float[pattern.Length];
                            for (int i = 0; i < pattern.Length; i++)
                            {
                                if (i % 2 == 0)
                                {
                                    dashPattern[i] = pattern[i] * imgWidth;
                                }
                                else
                                {
                                    dashPattern[i] = pattern[i];
                                }
                                float item = pattern[i];
                            }
                            break;
                        }
                        break;
                    }
                }
            }
            return(dashPattern);
        }