Exemplo n.º 1
0
        private void addCap(LineCap cap, 
            IList<ICoordinate> vertexList, 
            CapLocation capLocation, 
            double x1, 
            double y1, 
            double x2, 
            double y2)
        {
            double angle = getSegmentAngle(x1, y1, x2, y2);

            ICoordinate startPoint = PlanimetryEnvironment.NewCoordinate(0, 0);
            switch (capLocation)
            { 
                case CapLocation.Start:
                    angle += Math.PI / 2;
                    startPoint.X = x1;
                    startPoint.Y = y1;
                    break;
                case CapLocation.End:
                    angle -= Math.PI / 2;
                    startPoint.X = x2;
                    startPoint.Y = y2;
                    break;
            }

            switch (cap)
            { 
                case LineCap.Flat:
                    ICoordinate[] points = getCirclePoints(startPoint, angle, angle + Math.PI, _width / 2, 2);
                    foreach (ICoordinate p in points)
                        vertexList.Add(p);
                    break;
                case LineCap.Round:
                    int pointsPerCircle = (int)(Math.Round(Width * Math.PI) / 2);
                    points = getCirclePoints(startPoint, angle, angle + Math.PI, _width / 2, pointsPerCircle);
                    foreach (ICoordinate p in points)
                        vertexList.Add(p);
                    break;
                case LineCap.Square:
                    double r = _width * _sqrt2 / 2;
                    vertexList.Add(PlanimetryEnvironment.NewCoordinate(startPoint.X + r * Math.Cos(angle + _squareCapAngle),
                                              startPoint.Y + r * Math.Sin(angle + _squareCapAngle)));
                    vertexList.Add(PlanimetryEnvironment.NewCoordinate(startPoint.X + r * Math.Cos(angle - _squareCapAngle + Math.PI),
                                              startPoint.Y + r * Math.Sin(angle - _squareCapAngle + Math.PI)));
                    break;
                case LineCap.Triangle:
                    double halfWidth = _width / 2;
                    vertexList.Add(PlanimetryEnvironment.NewCoordinate(startPoint.X + halfWidth * Math.Cos(angle),
                          startPoint.Y + halfWidth * Math.Sin(angle)));

                    vertexList.Add(PlanimetryEnvironment.NewCoordinate(startPoint.X + halfWidth * Math.Cos(angle + _halfPI),
                          startPoint.Y + halfWidth * Math.Sin(angle + _halfPI)));

                    vertexList.Add(PlanimetryEnvironment.NewCoordinate(startPoint.X + halfWidth * Math.Cos(angle + Math.PI),
                          startPoint.Y + halfWidth * Math.Sin(angle + Math.PI)));
                    break;
            }
        }
Exemplo n.º 2
0
        private void addCap(LineCap cap,
                            IList <ICoordinate> vertexList,
                            CapLocation capLocation,
                            double x1,
                            double y1,
                            double x2,
                            double y2)
        {
            double angle = getSegmentAngle(x1, y1, x2, y2);

            ICoordinate startPoint = PlanimetryEnvironment.NewCoordinate(0, 0);

            switch (capLocation)
            {
            case CapLocation.Start:
                angle       += Math.PI / 2;
                startPoint.X = x1;
                startPoint.Y = y1;
                break;

            case CapLocation.End:
                angle       -= Math.PI / 2;
                startPoint.X = x2;
                startPoint.Y = y2;
                break;
            }

            switch (cap)
            {
            case LineCap.Flat:
                ICoordinate[] points = getCirclePoints(startPoint, angle, angle + Math.PI, _width / 2, 2);
                foreach (ICoordinate p in points)
                {
                    vertexList.Add(p);
                }
                break;

            case LineCap.Round:
                int pointsPerCircle = (int)(Math.Round(Width * Math.PI) / 2);
                points = getCirclePoints(startPoint, angle, angle + Math.PI, _width / 2, pointsPerCircle);
                foreach (ICoordinate p in points)
                {
                    vertexList.Add(p);
                }
                break;

            case LineCap.Square:
                double r = _width * _sqrt2 / 2;
                vertexList.Add(PlanimetryEnvironment.NewCoordinate(startPoint.X + r * Math.Cos(angle + _squareCapAngle),
                                                                   startPoint.Y + r * Math.Sin(angle + _squareCapAngle)));
                vertexList.Add(PlanimetryEnvironment.NewCoordinate(startPoint.X + r * Math.Cos(angle - _squareCapAngle + Math.PI),
                                                                   startPoint.Y + r * Math.Sin(angle - _squareCapAngle + Math.PI)));
                break;

            case LineCap.Triangle:
                double halfWidth = _width / 2;
                vertexList.Add(PlanimetryEnvironment.NewCoordinate(startPoint.X + halfWidth * Math.Cos(angle),
                                                                   startPoint.Y + halfWidth * Math.Sin(angle)));

                vertexList.Add(PlanimetryEnvironment.NewCoordinate(startPoint.X + halfWidth * Math.Cos(angle + _halfPI),
                                                                   startPoint.Y + halfWidth * Math.Sin(angle + _halfPI)));

                vertexList.Add(PlanimetryEnvironment.NewCoordinate(startPoint.X + halfWidth * Math.Cos(angle + Math.PI),
                                                                   startPoint.Y + halfWidth * Math.Sin(angle + Math.PI)));
                break;
            }
        }