## Testlimits – the code

```//  test if points or lines are in the limits (+-xRange,+-yRange)
void showRange(){
line(xRange,yRange,-xRange,yRange);
line(xRange,-yRange,-xRange,-yRange);
line(xRange,yRange,xRange,-yRange);
line(-xRange,yRange,-xRange,-yRange);
}

boolean inXRange(float x){
return (abs(x)<xRange+small);
}

boolean inYRange(float y){
return (abs(y)<yRange+small);
}

boolean inside(Vector v){
return (inXRange(v.x)&&inYRange(v.y));
}

boolean inside(Point p){
return inside(p.vec);
}

boolean intersectionWithBorder(Vector a,Vector b){
if (a.x<-xRange){                  //intersection with border x=-xRange and a.x < xRange, exchange a and b to get other possibility
if(b.x<-xRange) return false;
if(inYRange(a.y+(b.y-a.y)*(-xRange-a.x)/(b.x-a.x))) return true;
}
if (a.x>xRange){                  //intersection with border x=xRange
if(b.x>xRange) return false;
if(inYRange(a.y+(b.y-a.y)*(xRange-a.x)/(b.x-a.x))) return true;
}
if (a.y<-yRange){                  //intersection with border y=-yRange
if(b.y<-yRange) return false;
if(inXRange(a.x+(b.x-a.x)*(-yRange-a.y)/(b.y-a.y))) return true;
}
if (a.y>yRange){                  //intersection with border y=yRange
if(b.y>yRange) return false;
if(inXRange(a.x+(b.x-a.x)*(yRange-a.y)/(b.y-a.y))) return true;
}
return false;
}

//  test if some piece of the line between a and b is inside the range-rectangle

boolean inside(Vector a,Vector b){
return (inside(a)||inside(b)||intersectionWithBorder(a,b)||intersectionWithBorder(b,a));
}
```
This entry was posted in programming and tagged , , . Bookmark the permalink.