Advertisement
Guest User

Untitled

a guest
Dec 12th, 2019
114
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.41 KB | None | 0 0
  1. #include <cstring>
  2. #include <cassert>
  3.  
  4. #include "Figure.hpp"
  5. #include "Scheme.hpp"
  6.  
  7. #define func_for for (int i = 0; i < this->size; i++)
  8.  
  9. Scheme::Scheme(int capacity) {
  10. this->figures_ = new Figure*[capacity];
  11. this->size = 0;
  12. }
  13.  
  14. Scheme::~Scheme() {
  15. func_for {
  16. delete this->figures_[i];
  17. }
  18. delete [] this->figures_;
  19. }
  20.  
  21. void Scheme::push_back_figure(Figure* fg) {
  22. this->figures_[size++] = fg;
  23. }
  24.  
  25. void Scheme::remove_figure(int id) {
  26. func_for {
  27. if (this->figures_[i]->figure_id() == id) {
  28. delete this->figures_[i];
  29. for (int j = i; j + 1 < size; ++j){
  30. this->figures_[i] = this->figures_[i + 1];
  31. }
  32. this->size--;
  33. return;
  34. }
  35. }
  36. }
  37.  
  38. void Scheme::print_all_figures() {
  39. func_for {
  40. assert(this->figures_[i] != nullptr);
  41. this->figures_[i]->print();
  42. }
  43. }
  44.  
  45. void Scheme::zoom_figure(int id, int factor) {
  46. func_for {
  47. if (this->figures_[i]->figure_id() == id) {
  48. this->figures_[i]->zoom(factor);
  49. }
  50. }
  51. }
  52.  
  53. Figure* Scheme::is_inside_figure(int x, int y) {
  54. func_for {
  55. if (this->figures_[i]->is_inside(x, y)) {
  56. return this->figures_[i];
  57. }
  58. }
  59. return nullptr;
  60. }
  61.  
  62. void Scheme::move(int id, int new_x, int new_y) {
  63. func_for {
  64. if (this->figures_[i]->figure_id() == id) {
  65. this->figures_[i]->move(new_x, new_y);
  66. return;
  67. }
  68. }
  69. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement