_takumi

addCmd

Dec 9th, 2019
366
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 1.00 KB | None | 0 0
  1.     public sealed class AddVertexCmd : ICommand
  2.     {
  3.         private Vertex _vertex;
  4.         private List<Vertex> _deleted;
  5.         private Polygon _polygon;
  6.  
  7.         public AddVertexCmd(Vertex vertex, Polygon polygon)
  8.         {
  9.             _vertex = vertex;
  10.             _polygon = polygon;
  11.             _deleted = new List<Vertex>();
  12.             if (_polygon.Count >= 3)
  13.             {
  14.                 Polygon clone = _polygon;
  15.                 clone.Add(vertex);
  16.                 clone.MakeConvex();
  17.                 _deleted = _polygon.Except(clone).ToList();
  18.             }
  19.         }
  20.  
  21.         public void Execute()
  22.         {
  23.             _polygon.Add(_vertex);
  24.             if (_polygon.Count >= 3)
  25.                 _polygon.MakeConvex();
  26.         }
  27.  
  28.         public void Undo()
  29.         {
  30.             _polygon.Remove(_vertex);
  31.             if (_polygon.Count >= 3)
  32.             {
  33.                 _polygon.AddRange(_deleted);
  34.                 _polygon.MakeConvex();
  35.             }
  36.         }
  37.     }
Advertisement
Add Comment
Please, Sign In to add comment