apprenda take home assessment
Derek McQuay 2b69fc7511
2017-01-24 18:25:53 -08:00
2016-08-27 22:28:15 -07:00
2017-01-24 18:25:53 -08:00
2016-08-26 09:07:42 -07:00
2016-08-27 21:51:34 -07:00
2016-08-26 08:13:01 -07:00
2016-08-29 10:27:36 -07:00
2016-08-27 21:32:18 -07:00
2016-08-29 10:27:36 -07:00
2016-08-27 21:14:16 -07:00
2016-08-27 22:28:15 -07:00
2016-08-29 10:27:36 -07:00
2016-08-29 10:27:36 -07:00
2016-08-29 10:27:36 -07:00
2016-08-27 21:14:16 -07:00

# rect

Package rect implements rectangles and can determine when rectangles intersect, are contained, and when rectangles lie adjacent

## usage

in cmd/recty/main.go is an example of how one could use this package.

``````r := rect.Rectangle{
P1: rect.Point{1, 1},
P2: rect.Point{1, 2},
P3: rect.Point{2, 1},
P4: rect.Point{2, 2},
}
``````

defines a rectangle.

``````fmt.Println(r.IsRect())
``````

would varify that the rectangle provided is a valid rectangle.

``````r1 := rect.Rectangle{
P1: rect.Point{1, 1},
P2: rect.Point{1, 2},
P3: rect.Point{2, 1},
P4: rect.Point{2, 2},
}
r2 := rect.Rectangle{
P1: rect.Point{1, 1},
P2: rect.Point{1, 2},
P3: rect.Point{2, 1},
P4: rect.Point{2, 2},
}

fmt.Println(rect.Intersection(r1, r2))
``````

Running the above code would print out all intersection points of the two rectangles.

``````r3 := rect.Rectangle{
P1: rect.Point{0, 0},
P2: rect.Point{0, 3},
P3: rect.Point{3, 0},
P4: rect.Point{3, 3},
}
r4 := rect.Rectangle{
P1: rect.Point{2, 2},
P2: rect.Point{2, 3},
P3: rect.Point{3, 2},
P4: rect.Point{3, 3},
}

``````

This would return a boolean for whether r3 and r4 have an adjacent side.

``````r5 := rect.Rectangle{
P1: rect.Point{0, 0},
P2: rect.Point{0, 3},
P3: rect.Point{3, 0},
P4: rect.Point{3, 3},
}
r6 := rect.Rectangle{
P1: rect.Point{1, 1},
P2: rect.Point{1, 2},
P3: rect.Point{2, 1},
P4: rect.Point{2, 2},
}

fmt.Println(rect.Containment(r5, r6))
``````

And finally, running `rect.Containment(r5, r6)` would return true because r6 is contained inside of r5