Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <assert.h>
- #include <stdio.h>
- #include "rectangle.h"
- ///////////////////////////
- // INTEGRITY INSTRUCTIONS
- // Explicitly state the level of collaboration on this question
- // Examples:
- // * I discussed ideas with classmate(s) [include name(s)]
- // * I worked together with classmate(s) in the lab [include name(s)]
- // * Classmate [include name] helped me debug my code
- // * I consulted website [include url]
- // * None
- // A "None" indicates you completed this question entirely by yourself
- // (or with assistance from course staff)
- ///////////////////////////
- // INTEGRITY STATEMENT:
- // I received help from the following sources:
- // None
- // Name: Jamie Kilburn
- // login ID: jkkilbur
- ///////////////////////////
- bool point_equal(struct point a, struct point b) {
- return (a.x == b.x) && (a.y == b.y);
- }
- bool valid_rectangle(struct rectangle r) {
- return !point_equal(r.top_left, r.bottom_right) &&
- (r.top_left.x < r.bottom_right.x) &&
- (r.top_left.y > r.bottom_right.y);
- }
- bool rectangle_equal(struct rectangle a, struct rectangle b) {
- return point_equal(a.top_left, b.top_left) &&
- point_equal(a.bottom_right, b.bottom_right);
- }
- int rectangle_area(struct rectangle r) {
- return (r.bottom_right.x - r.top_left.x) * (r.top_left.y -
- r.bottom_right.y);
- }
- bool rectangle_inside(struct rectangle r, struct point p) {
- return (p.x >= r.top_left.x) && (p.x <= r.bottom_right.x) &&
- (p.y >= r.bottom_right.y) && (p.y <= r.top_left.y);
- }
- struct rectangle rectangle_rotate(struct rectangle r) {
- struct point r_tl = {r.top_left.y, (-1 * r.top_left.x)};
- struct point r_br = {r.bottom_right.y, (-1 * r.bottom_right.x)};
- struct rectangle raw = {r_tl, r_br};
- return raw;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement