Browse Source

Started userstory 13

Martin Edlund 5 years ago
parent
commit
951eede671

+ 17 - 0
SketchAssistant/SketchAssistantWPF/Angle.cs

@@ -0,0 +1,17 @@
+using System;
+using System.Collections.Generic;
+using System.Linq;
+using System.Text;
+using System.Threading.Tasks;
+using System.Windows;
+
+namespace SketchAssistantWPF
+{
+    public class Angle
+    {
+        public Angle(Point p0, Point p1)
+        {
+            //TODO: Add angle calculations
+        }
+    }
+}

+ 1 - 0
SketchAssistant/SketchAssistantWPF/MVP_Model.cs

@@ -231,6 +231,7 @@ namespace SketchAssistantWPF
         {
             leftImageSize = new ImageDimension(width, height);
             rightImageSize = new ImageDimension(width, height);
+            new RedrawManager(listOfLines);
             leftLineList = listOfLines;
             graphicLoaded = true;
             programPresenter.UpdateLeftLines(leftLineList);

+ 71 - 0
SketchAssistant/SketchAssistantWPF/RedrawLine.cs

@@ -0,0 +1,71 @@
+using System;
+using System.Collections.Generic;
+using System.Linq;
+using System.Text;
+using System.Threading;
+using System.Threading.Tasks;
+using System.Windows;
+
+namespace SketchAssistantWPF
+{
+    public class RedrawLine
+    {
+        InternalLine LineToRedraw;
+
+        Point[] points;
+
+        private int radius;
+
+        private HashSet<Point>[] detectionZones;
+
+        /// <summary>
+        /// Constructor of the RedrawLine.
+        /// </summary>
+        /// <param name="rad">The radius around each point of the line input will be accepted.</param>
+        public RedrawLine(int rad)
+        {
+            radius = rad;
+        }
+
+        /// <summary>
+        /// A function to intialize the redraw line.
+        /// </summary>
+        /// <param name="line"></param>
+        /// <returns></returns>
+        public bool Init(InternalLine line)
+        {
+            HashSet<Point> initialZone = GeometryCalculator.FilledCircleAlgorithm(new Point(0, 0), radius);
+            LineToRedraw = line;
+            points = line.GetPoints().ToArray();
+
+            List<HashSet<Point>> dZones = new List<HashSet<Point>>();
+
+            foreach(Point p in points)
+            {
+                HashSet<Point> newZone = new HashSet<Point>();
+                foreach(Point i_p in initialZone)
+                {
+                    newZone.Add(new Point(i_p.X + p.X, i_p.Y + p.Y));
+                }
+                dZones.Add(newZone);
+            }
+            detectionZones = dZones.ToArray();
+
+            Console.WriteLine("This line has {0} points ", line.GetPoints().Count());
+            return false;
+        }
+
+        public Point GetOverlayPosition()
+        {
+            return points[0];
+        }
+
+        public Angle GetDirection(Point p)
+        {
+            //TODO: Calculate angles between p and the next n points of the line
+            // Take average and return it.
+            return null;
+        }
+
+    }
+}

+ 62 - 0
SketchAssistant/SketchAssistantWPF/RedrawManager.cs

@@ -0,0 +1,62 @@
+using System;
+using System.Collections.Generic;
+using System.Linq;
+using System.Text;
+using System.Threading;
+using System.Threading.Tasks;
+using System.Windows;
+
+namespace SketchAssistantWPF
+{
+    public class RedrawManager
+    {
+        public int radius { get; private set; }
+
+        private RedrawLine[] redrawLines;
+
+        public int currentLine { get; private set; }
+
+        public RedrawManager(List<InternalLine> linesToRedraw)
+        {
+            radius = 5;
+            redrawLines = new RedrawLine[linesToRedraw.Count];
+            Task[] taskPool = new Task[linesToRedraw.Count];
+            Console.WriteLine("STARTED THREAD CREATION");
+            Console.WriteLine("Processor Count {0}", Environment.ProcessorCount);
+
+            for(int i = 0; i < linesToRedraw.Count; i++)
+            {
+                InternalLine line = linesToRedraw[i];
+                redrawLines[i] = (new RedrawLine(radius));
+
+                object arg = new Tuple<RedrawLine, InternalLine> (redrawLines[i], line);
+                taskPool[i] = Task.Factory.StartNew(new Action<object>((x) =>
+                {
+                    ((Tuple<RedrawLine, InternalLine>)arg).Item1.Init(((Tuple<RedrawLine, InternalLine>)arg).Item2);
+                }),arg);
+            }
+            Console.WriteLine("STARTED {0} THREADS", linesToRedraw.Count);
+            Task.WaitAll(taskPool);
+            Console.WriteLine("FINISHED ALL THREADS");
+
+            currentLine = 0;
+        }
+
+        public Tuple<bool, Point> GetOverlayPosition()
+        {
+            if(currentLine < 0)
+            {
+                return new Tuple<bool, Point>(false, new Point(0, 0));
+            }
+            else
+            {
+                return new Tuple<bool, Point>(true, redrawLines[currentLine].GetOverlayPosition());
+            }
+        }
+
+        public Angle GetDirection(Point p)
+        {
+            return redrawLines[currentLine].GetDirection(p);
+        }
+    }
+}

+ 2 - 0
SketchAssistant/SketchAssistantWPF/SketchAssistantWPF.csproj

@@ -81,6 +81,8 @@
     <Compile Include="FileImporterException.cs" />
     <Compile Include="GeometryCalculator.cs" />
     <Compile Include="ImageDimension.cs" />
+    <Compile Include="RedrawLine.cs" />
+    <Compile Include="RedrawManager.cs" />
     <Compile Include="SketchAction.cs" />
     <Page Include="MainWindow.xaml">
       <Generator>MSBuild:Compile</Generator>

+ 13 - 0
userstory13.md

@@ -0,0 +1,13 @@
+# Userstory 13 
+ 
+|**ID**|13|  
+|-|-|
+|**Name**|Start und Endpunkt anzeigen|
+|**Beschreibung**|Als Nutzer möchte ich, dass beim Nachzeichnen, der Start- & Endpunkt einer nachzuzeichnenden Linie angzeigt werden, um die eingene Zeichnung exakt umzusetzten.|
+|**Akzeptanzkriterium**|Sofern auf der linken Seite eine nachzeichenbare Grafik dargestellt wird, wird der Start- und Endpunkt der ersten Linie der linken Grafik an der richtigen Stelle auf der rechten Seite angezeigt.|
+|Geschätzter Aufwand (Story Points)|2|
+|Entwickler|Martin Edlund|
+|Umgesetzt in Iteration|keine|
+|Tatsächlicher Aufwand (Std.)|keine|
+|Velocity (Std./Story Point)|keine|
+|Bemerkungen|Keine|