/// <summary>Record Constructor</summary>
 /// <param name="posVector"><see cref="PosVector"/></param>
 /// <param name="lineWidth"><see cref="LineWidth"/></param>
 /// <param name="color"><see cref="Color"/></param>
 public DrawingVector
     (PosVector posVector
     , float lineWidth
     , Color color
     )
 {
     PosVector          = posVector;
     LineWidth          = lineWidth;
     Color              = color;
     Rotated            = null;
     posVector.Rotated += PosVectorRotated;
 }
Beispiel #2
0
        public static List <DrawingVector> CentreDrawing
            (this IEnumerable <DrawingVector> drawingVectorList
            , PointF topLeft
            , PointF bottomRight
            )
        {
            PointF drawingCentre =
                drawingVectorList
                .DrawingCentre
                    ((min, size) =>
            {
                $@"Min  {min.ToFormatString()}".Print();
                $@"Size {size.ToFormatString()}".Print();
            }
                    )
            ;
            float  imageWidth  = (topLeft.X - bottomRight.X);
            float  imageHeight = (topLeft.Y - bottomRight.Y);
            PointF imageCentre =
                new PointF
                    (bottomRight.X + imageWidth / 2
                    , bottomRight.Y + imageHeight / 2
                    )
            ;
            float differenceX = imageCentre.X - drawingCentre.X;
            float differenceY = imageCentre.Y - drawingCentre.Y;
            List <DrawingVector> centredList = new List <DrawingVector>();

            "Loop drawingVectorList CentreDrawing".Print();
            foreach (DrawingVector drawingVector in drawingVectorList)
            {
                //$@"before {drawingVector}".Print();
                PointF start = drawingVector.PosVector.Start;
                start =
                    new PointF
                        (start.X + differenceX
                        , start.Y + differenceY
                        )
                ;
                DrawingVector newVector =
                    new DrawingVector
                        (new PosVector
                            (start
                            , drawingVector.PosVector.Length
                            , drawingVector.PosVector.AngleRadians
                            )
                        , drawingVector.LineWidth
                        , drawingVector.Color
                        )
                ;
                centredList.Add(newVector);
                //$@"middle {newVector}".Print();
            }
            //centredList.Print();
            PointF drawingMin  = new PointF();
            SizeF  drawingSize = new SizeF();

            drawingCentre =
                centredList
                .DrawingCentre
                    ((min, size) =>
            {
                $@"Min  {min.ToFormatString()}".Print();
                $@"Size {size.ToFormatString()}".Print();
                drawingMin  = min;
                drawingSize = size;
            }
                    )
            ;
            float drawingWidthRatio  = drawingSize.Width / imageWidth;
            float drawingHeightRatio = drawingSize.Height / imageHeight;
            float drawingRatio       =
                drawingWidthRatio > drawingHeightRatio
                                ? drawingWidthRatio
                                : drawingHeightRatio
            ;

            $@"ratio w {drawingWidthRatio} h {drawingHeightRatio} r {drawingRatio}".Print();
            List <DrawingVector> resizedList = new List <DrawingVector>();

            "Loop centredList CentreDrawing".Print();
            foreach (DrawingVector drawingVector in centredList)
            {
                PosVector     posVector     = drawingVector.PosVector;
                DrawingVector resizedVector =
                    new DrawingVector
                        (new PosVector
                            (posVector.Start
                            , posVector.Length / drawingRatio
                            , posVector.AngleRadians
                            )
                        , drawingVector.LineWidth
                        , drawingVector.Color
                        )
                ;
                //$@"after  {resizedVector}".Print();
                resizedList.Add(resizedVector);
            }
            return(resizedList.ToList());
        }
 public override int GetHashCode()
 =>
 PosVector.GetHashCode()
 & LineWidth.GetHashCode()
 & Color.GetHashCode()
 ;