Write a constructor function called Rectangle
with arguments upperLeft
and lowerRight
, in that order, which are both Vector2
objects (see code for definition). Assume that positive y is down, as is typical in computer graphics. Rectangle
objects should have an isInside(v)
method that takes a Vector2
argument and returns true if point v
is in the rectangle and false otherwise.
<html>
<script>
function Vector2(x,y) {
this.x = x;
this.y = y;
}
// Your code goes here
// Code test
var ul = new Vector2(10,10);
var lr = new Vector2(100,90);
var rect = new Rectangle(ul,lr);
var testPoint1 = new Vector2(20,1);
var testPoint2 = new Vector2(20,20);
var testResult1 = rect.isInside(testPoint1);
var testResult2 = rect.isInside(testPoint2);
function testProperty(name,actual,correct) {
document.write("property "+name+" is: "+actual+" and should be: "+correct+"<br>");
test(actual === correct);
}
function test(x) {
if (x)
document.write("pass<br>");
else
document.write("FAIL<br>");
}
document.write("Test Results<br>");