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.

javascript programming
exercise: methods 11

x
 
1
<html>
2
<script> 
3
4
function Vector2(x,y) {
5
  this.x = x;
6
  this.y = y;
7
}
8
9
// Your code goes here
10
11
12
13
14
// Code test
15
16
var ul = new Vector2(10,10);
17
var lr = new Vector2(100,90);
18
var rect = new Rectangle(ul,lr);
19
var testPoint1 = new Vector2(20,1);
20
var testPoint2 = new Vector2(20,20);
21
var testResult1 = rect.isInside(testPoint1);
22
var testResult2 = rect.isInside(testPoint2);
23
24
function testProperty(name,actual,correct) {
25
  document.write("property "+name+" is: "+actual+" and should be: "+correct+"<br>");
26
  test(actual === correct);
27
}
28
29
function test(x) {
30
  if (x)
31
    document.write("pass<br>");
32
  else
33
    document.write("FAIL<br>");  
34
}
35
36
document.write("Test Results<br>");