Ejemplo n.º 1
0
        public void TestThatClipboardControllerSavesImageToClipboard()
        {
            Layer testLayer = new Layer("test layer", 10, 10);

            ClipboardController.CopyToClipboard(new [] { testLayer }, CoordinatesCalculator.RectangleToCoordinates(0, 0, 9, 9), 10, 10);
            Assert.True(ClipboardController.IsImageInClipboard());
        }
Ejemplo n.º 2
0
        public BitmapPixelChanges ChangeBrightness(Layer layer, Coordinates coordinates, int toolSize,
                                                   float correctionFactor)
        {
            DoubleCords centeredCoords = CoordinatesCalculator.CalculateThicknessCenter(coordinates, toolSize);

            Coordinates[] rectangleCoordinates = CoordinatesCalculator.RectangleToCoordinates(centeredCoords.Coords1.X,
                                                                                              centeredCoords.Coords1.Y,
                                                                                              centeredCoords.Coords2.X, centeredCoords.Coords2.Y);
            BitmapPixelChanges changes = new BitmapPixelChanges(new Dictionary <Coordinates, Color>());

            for (int i = 0; i < rectangleCoordinates.Length; i++)
            {
                if (Mode == BrightnessMode.Default)
                {
                    if (_pixelsVisited.Contains(rectangleCoordinates[i]))
                    {
                        continue;
                    }
                    _pixelsVisited.Add(rectangleCoordinates[i]);
                }

                Color pixel    = layer.GetPixelWithOffset(rectangleCoordinates[i].X, rectangleCoordinates[i].Y);
                Color newColor = ExColor.ChangeColorBrightness(Color.FromArgb(pixel.A, pixel.R, pixel.G, pixel.B),
                                                               correctionFactor);
                changes.ChangedPixels.Add(new Coordinates(rectangleCoordinates[i].X, rectangleCoordinates[i].Y),
                                          newColor);
            }

            return(changes);
        }
Ejemplo n.º 3
0
        /// <summary>
        ///     Gets points for rounded cap on specified position and thickness.
        /// </summary>
        /// <param name="position">Starting position of cap.</param>
        /// <param name="thickness">Thickness of cap.</param>
        private IEnumerable <Coordinates> GetRoundCap(Coordinates position, int thickness)
        {
            IEnumerable <Coordinates> rectangleCords = CoordinatesCalculator.RectangleToCoordinates(
                CoordinatesCalculator.CalculateThicknessCenter(position, thickness));

            return(circleTool.CreateEllipse(rectangleCords.First(), rectangleCords.Last(), 1, true));
        }
Ejemplo n.º 4
0
        public void CalculateSquareOddThicknessCenterTest()
        {
            DoubleCords cords = CoordinatesCalculator.CalculateThicknessCenter(new Coordinates(3, 3), 3);

            Assert.AreEqual(2, cords.Coords1.X);
            Assert.AreEqual(2, cords.Coords1.Y);
            Assert.AreEqual(4, cords.Coords2.X);
            Assert.AreEqual(4, cords.Coords2.Y);
        }
Ejemplo n.º 5
0
        public BitmapPixelChanges Draw(Coordinates startingCoords, Color color, int toolSize)
        {
            int         x1, y1, x2, y2;
            DoubleCords centeredCoords = CoordinatesCalculator.CalculateThicknessCenter(startingCoords, toolSize);

            x1 = centeredCoords.Coords1.X;
            y1 = centeredCoords.Coords1.Y;
            x2 = centeredCoords.Coords2.X;
            y2 = centeredCoords.Coords2.Y;
            return(new BitmapPixelChanges(CoordinatesCalculator.RectangleToCoordinates(x1, y1, x2, y2), color));
        }
Ejemplo n.º 6
0
        protected IEnumerable <Coordinates> GetThickShape(IEnumerable <Coordinates> shape, int thickness)
        {
            List <Coordinates> output = new List <Coordinates>();

            foreach (var item in shape)
            {
                output.AddRange(
                    CoordinatesCalculator.RectangleToCoordinates(
                        CoordinatesCalculator.CalculateThicknessCenter(item, thickness)));
            }
            return(output.Distinct());
        }
Ejemplo n.º 7
0
        protected Coordinates[] GetThickShape(Coordinates[] shape, int thickness)
        {
            List <Coordinates> output = new List <Coordinates>();

            for (int i = 0; i < shape.Length; i++)
            {
                output.AddRange(
                    CoordinatesCalculator.RectangleToCoordinates(
                        CoordinatesCalculator.CalculateThicknessCenter(shape[i], thickness)));
            }
            return(output.Distinct().ToArray());
        }
Ejemplo n.º 8
0
        public byte[] ImageMaker()
        {
            using (FormSL form = new FormSL()) {
                form.ShowDialog();
                CoordinatesCalculator calculator = form.Calculator;
                Rectangle             rectangle  = calculator.CalculatedInstance;

                using (Bitmap memoryImage = new Bitmap(rectangle.Width, rectangle.Height)) {
                    Size size = new Size(memoryImage.Width, memoryImage.Height);

                    using (Graphics memoryGraphics = Graphics.FromImage(memoryImage)) {
                        memoryGraphics.CopyFromScreen(rectangle.X, rectangle.Y, 0, 0, size);

                        using (MemoryStream stream = new MemoryStream()) {
                            memoryImage.Save(stream, ImageFormat.Png);
                            stream.Position = 0;
                            byte[] result = stream.ToArray();
                            return(result);
                        }
                    }
                }
            }
        }
Ejemplo n.º 9
0
 public int RectangleToCoordinatesAmountTest(int x1, int y1, int x2, int y2)
 {
     return(CoordinatesCalculator.RectangleToCoordinates(x1, y1, x2, y2).Length);
 }
Ejemplo n.º 10
0
        private void DoAnalize(FileButton <Profile> butt)
        {
            SectionReadWindow sectionReadWindow = new SectionReadWindow(butt.File.ProfSection, false);

            sectionReadWindow.ShowDialog();

            Kml file = (Kml)butt.File.ProfKmlFile.Root;
            List <Placemark> lineList = new List <Placemark>();

            ExtractPlacemarks(file.Feature, lineList);

            LineString line = new LineString();

            try
            {
                line = lineList.Single().Geometry as LineString;
            }
            catch
            {
                MessageBox.Show("Kml nie spełnia wymogów profilu. Należy wczytać plik zawierający jedną linię.");
            }

            List <Coord.Vector> points = new List <Coord.Vector>();

            foreach (Coord.Vector j in line.Coordinates)
            {
                points.Add(j);
            }

            Coord.Vector startCoord = points[0];
            Coord.Vector endCoord   = points[points.Count - 1];
            List <System.Windows.Point> secPoints = sectionReadWindow.Points;
            List <Coord.Vector>         vectors   = new List <Coord.Vector>();

            int    pointsAmount  = sectionReadWindow.Points.Count;
            double profLength    = CoordinatesCalculator.CalculateDistance(startCoord.Latitude, startCoord.Longitude, endCoord.Latitude, endCoord.Longitude);
            double sectionLength = sectionReadWindow.LastPoint.X - sectionReadWindow.ZeroPoint.X;
            double scale         = profLength / sectionLength;
            double maxDepth      = sectionReadWindow.LastPoint.Y - sectionReadWindow.ZeroPoint.Y;
            double azimuth       = CoordinatesCalculator.CalculateBearing(startCoord, endCoord);
            var    pp            = from t in secPoints
                                   orderby t.X ascending
                                   select t;

            secPoints = pp.ToList <System.Windows.Point>();

            List <byte> depths = new List <byte>();
            byte        depth  = new byte();

            for (int i = 0; i < pointsAmount; i++)
            {
                depth = (byte)(secPoints[i].Y / maxDepth * 255);
                double dist;

                if (i == 0)
                {
                    dist = secPoints[i].X * scale;
                    vectors.Add(startCoord);
                    depths.Add((byte)(sectionReadWindow.ZeroPoint.Y / maxDepth * 255));
                }
                else
                {
                    dist = (secPoints[i].X - secPoints[i - 1].X) * scale;
                }

                Coord.Vector vector = CoordinatesCalculator.CalculatePoint(vectors[vectors.Count - 1], dist, azimuth);
                vectors.Add(vector);
                depths.Add(depth);
            }

            vectors.RemoveAt(vectors.Count - 1);
            depths.RemoveAt(depths.Count - 1);
            vectors.RemoveAt(vectors.Count - 1);
            depths.RemoveAt(depths.Count - 1);

            vectors.Add(endCoord);
            depths.Add(depths[depths.Count - 1]);

            Document document = new Document();

            document.Name = butt.File.Name + ".kml";

            for (int i = 1; i < vectors.Count; i++)
            {
                AddSingleLineToContainer(vectors[i - 1], vectors[i], (byte)((depths[i] + depths[i - 1]) / 2), document, i);
            }

            List <Coord.Vector> markers = new List <Coord.Vector>();

            foreach (var point in sectionReadWindow.Markers)
            {
                double       dist   = point.X * scale;
                Coord.Vector vector = CoordinatesCalculator.CalculatePoint(startCoord, dist, azimuth);
                markers.Add(vector);
            }

            int n = 1;

            foreach (var coord in markers)
            {
                AddMarkerToContainer(coord, document, n);
                n++;
            }

            Kml kml = new Kml();

            kml.Feature = document;
            KmlFile kmlFile = KmlFile.Create(kml, true);

            AddToList(kmlFile);
            SaveKmls(kmlFile);
            FileButton <KmlFile> button = new FileButton <KmlFile>(kmlFile)
            {
                Height  = 40,
                Margin  = new Thickness(10, 5, 5, 10),
                Content = document.Name
            };

            button.Click += OnOutFileButtonClick;

            OutStack.Children.Add(button);
        }
Ejemplo n.º 11
0
        public void TestGetCenter(int x1, int y1, int x2, int y2, int expectedX, int expectedY)
        {
            Coordinates center = CoordinatesCalculator.GetCenterPoint(new Coordinates(x1, y1), new Coordinates(x2, y2));

            Assert.Equal(new Coordinates(expectedX, expectedY), center);
        }
Ejemplo n.º 12
0
 public void TestThatRectangleToCoordinatesReturnsSameAmount(int x1, int y1, int x2, int y2, int expectedResult)
 {
     Assert.Equal(CoordinatesCalculator.RectangleToCoordinates(x1, y1, x2, y2).Length, expectedResult);
 }
Ejemplo n.º 13
0
        protected static void ThickenShape(Layer layer, SKColor color, Coordinates coords, int thickness)
        {
            var dcords = CoordinatesCalculator.CalculateThicknessCenter(coords, thickness);

            CoordinatesCalculator.DrawRectangle(layer, color, dcords.Coords1.X, dcords.Coords1.Y, dcords.Coords2.X, dcords.Coords2.Y);
        }