Advertisement
Guest User

Untitled

a guest
Jan 24th, 2017
109
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.74 KB | None | 0 0
  1. #include <assert.h>
  2. #include <stdio.h>
  3. #include "rectangle.h"
  4.  
  5. ///////////////////////////
  6. // INTEGRITY INSTRUCTIONS
  7.  
  8. // Explicitly state the level of collaboration on this question
  9. // Examples:
  10. // * I discussed ideas with classmate(s) [include name(s)]
  11. // * I worked together with classmate(s) in the lab [include name(s)]
  12. // * Classmate [include name] helped me debug my code
  13. // * I consulted website [include url]
  14. // * None
  15. // A "None" indicates you completed this question entirely by yourself
  16. // (or with assistance from course staff)
  17. ///////////////////////////
  18. // INTEGRITY STATEMENT:
  19. // I received help from the following sources:
  20.  
  21. // None
  22.  
  23. // Name: Jamie Kilburn
  24. // login ID: jkkilbur
  25. ///////////////////////////
  26.  
  27.  
  28. bool point_equal(struct point a, struct point b) {
  29. return (a.x == b.x) && (a.y == b.y);
  30. }
  31.  
  32. bool valid_rectangle(struct rectangle r) {
  33. return !point_equal(r.top_left, r.bottom_right) &&
  34. (r.top_left.x < r.bottom_right.x) &&
  35. (r.top_left.y > r.bottom_right.y);
  36. }
  37.  
  38. bool rectangle_equal(struct rectangle a, struct rectangle b) {
  39. return point_equal(a.top_left, b.top_left) &&
  40. point_equal(a.bottom_right, b.bottom_right);
  41. }
  42.  
  43. int rectangle_area(struct rectangle r) {
  44. return (r.bottom_right.x - r.top_left.x) * (r.top_left.y -
  45. r.bottom_right.y);
  46. }
  47.  
  48. bool rectangle_inside(struct rectangle r, struct point p) {
  49. return (p.x >= r.top_left.x) && (p.x <= r.bottom_right.x) &&
  50. (p.y >= r.bottom_right.y) && (p.y <= r.top_left.y);
  51. }
  52.  
  53. struct rectangle rectangle_rotate(struct rectangle r) {
  54. struct point r_tl = {r.top_left.y, (-1 * r.top_left.x)};
  55. struct point r_br = {r.bottom_right.y, (-1 * r.bottom_right.x)};
  56. struct rectangle raw = {r_tl, r_br};
  57. return raw;
  58. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement