Browse Source

Fleshed out Line class

Martin Edlund 5 years ago
parent
commit
6ae9bcee5e
1 changed files with 29 additions and 3 deletions
  1. 29 3
      SketchAssistant/SketchAssistant/Line.cs

+ 29 - 3
SketchAssistant/SketchAssistant/Line.cs

@@ -9,12 +9,38 @@ namespace SketchAssistant
 {
     class Line
     {
-        private Point Start { get; set; }
-        private Point End { get; set; }
+        private List<Point> linePoints;
 
-        public Line(int[] points)
+        public Line(List<Point> points)
         {
+            linePoints = new List<Point>(points);
+        }
+
+        public Point GetStartPoint()
+        {
+            return linePoints.First();
+        }
 
+        public Point GetEndPoint()
+        {
+            return linePoints.Last();
+        }
+
+        /// <summary>
+        /// A function that takes a Graphics element and returns it with
+        /// the line drawn on it.
+        /// </summary>
+        /// <param name="canvas">The Graphics element on which the line shall be drawn</param>
+        /// <returns>The given Graphics element with the additional line</returns>
+        public Graphics DrawLine(Graphics canvas)
+        {
+            Pen thePen = new Pen(Color.Black);
+            for(int i = 0; i < linePoints.Count; i++)
+            {
+                canvas.DrawLine(thePen, linePoints[i], linePoints[i + 1]);
+            }
+            canvas.DrawLine(thePen, linePoints[linePoints.Count-1], linePoints[linePoints.Count]);
+            return canvas;
         }
     }
 }