PointsData.cs 1.2 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849
  1. using PixiEditor.DrawingApi.Core.Surfaces;
  2. using PixiEditor.DrawingApi.Core.Surfaces.PaintImpl;
  3. using PixiEditor.Numerics;
  4. namespace PixiEditor.ChangeableDocument.Changeables.Graph.Nodes.Shapes.Data;
  5. public class PointsData : ShapeData
  6. {
  7. public List<VecD> Points { get; set; } = new();
  8. public PointsData(IEnumerable<VecD> points)
  9. {
  10. Points = new List<VecD>(points);
  11. }
  12. public override void Rasterize(DrawingSurface drawingSurface)
  13. {
  14. using Paint paint = new Paint();
  15. paint.Color = FillColor;
  16. paint.StrokeWidth = StrokeWidth;
  17. drawingSurface.Canvas.DrawPoints(PointMode.Points, Points.Select(p => new Point((int)p.X, (int)p.Y)).ToArray(), paint);
  18. }
  19. public override bool IsValid()
  20. {
  21. return Points.Count > 0;
  22. }
  23. public override int GetCacheHash()
  24. {
  25. return CalculateHash();
  26. }
  27. public override int CalculateHash()
  28. {
  29. return Points.GetHashCode();
  30. }
  31. public override object Clone()
  32. {
  33. return new PointsData(Points)
  34. {
  35. StrokeColor = StrokeColor,
  36. FillColor = FillColor,
  37. StrokeWidth = StrokeWidth
  38. };
  39. }
  40. }