Line.cs 1.2 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Linq;
  4. using System.Text;
  5. using System.Threading.Tasks;
  6. using System.Drawing;
  7. namespace SketchAssistant
  8. {
  9. class Line
  10. {
  11. private List<Point> linePoints;
  12. public Line(List<Point> points)
  13. {
  14. linePoints = new List<Point>(points);
  15. }
  16. public Point GetStartPoint()
  17. {
  18. return linePoints.First();
  19. }
  20. public Point GetEndPoint()
  21. {
  22. return linePoints.Last();
  23. }
  24. /// <summary>
  25. /// A function that takes a Graphics element and returns it with
  26. /// the line drawn on it.
  27. /// </summary>
  28. /// <param name="canvas">The Graphics element on which the line shall be drawn</param>
  29. /// <returns>The given Graphics element with the additional line</returns>
  30. public Graphics DrawLine(Graphics canvas)
  31. {
  32. Pen thePen = new Pen(Color.Black);
  33. for(int i = 0; i < linePoints.Count - 1 ; i++)
  34. {
  35. canvas.DrawLine(thePen, linePoints[i], linePoints[i + 1]);
  36. }
  37. //canvas.DrawLine(thePen, linePoints[linePoints.Count-1], linePoints[linePoints.Count]);
  38. return canvas;
  39. }
  40. }
  41. }