Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- public sealed class AddVertexCmd : ICommand
- {
- private Vertex _vertex;
- private List<Vertex> _deleted;
- private Polygon _polygon;
- public AddVertexCmd(Vertex vertex, Polygon polygon)
- {
- _vertex = vertex;
- _polygon = polygon;
- _deleted = new List<Vertex>();
- if (_polygon.Count >= 3)
- {
- Polygon clone = _polygon;
- clone.Add(vertex);
- clone.MakeConvex();
- _deleted = _polygon.Except(clone).ToList();
- }
- }
- public void Execute()
- {
- _polygon.Add(_vertex);
- if (_polygon.Count >= 3)
- _polygon.MakeConvex();
- }
- public void Undo()
- {
- _polygon.Remove(_vertex);
- if (_polygon.Count >= 3)
- {
- _polygon.AddRange(_deleted);
- _polygon.MakeConvex();
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment