}
@Override
public PVector projectionVector(HRectangle other) {
//Get the center of this circle
PVector worldCenter = PVector.add(_center, _position);
//Figure out what voronoi region of the rectangle the circle is in
PVector min = PVector.add(other._position, other.getMin());
PVector max = PVector.add(other._position, other.getMax());
if(min.x <= worldCenter.x) {
if(worldCenter.x <= max.x) {
//In regions above or below rectangle,
//compare y projections
float minProject = worldCenter.y - _radius;
float maxProject = worldCenter.y + _radius;
if(min.y <= maxProject && minProject <= max.y) {
float topCollide = max.y - minProject;
float bottomCollide = maxProject - min.y;
return (topCollide >= bottomCollide ?
new PVector(0,bottomCollide):
new PVector(0,-topCollide));
}
}
else if(min.y <= worldCenter.y) {
if(worldCenter.y <= max.y) {
//In region directly to right of rectangle
//Compare x projections
float minProject = worldCenter.x - _radius;
if(minProject <= max.x) {
return new PVector(minProject - max.x,0);
}
}
else {
//In region to the right&up of rectangle
//Get projection of both along up-right vertex (max)
return getOverlap(worldCenter,max);
}
}
else {
//In region to the right&down of rectangle
//Get projection of both along bottom-right vertex
PVector brVertex = new PVector(max.x, min.y);
return getOverlap(worldCenter, brVertex);
}
}
else if(min.y <= worldCenter.y) {
if(worldCenter.y <= max.y) {
//In region directly to the left of rectangle
//Compare x projections
float maxProject = worldCenter.x + _radius;
if(min.x <= maxProject) {
return new PVector(maxProject - min.x,0);
}
}
else {
//In region to the left&up of rectangle
//Get projection of both along top-left vertex
PVector tlVertex = new PVector(min.x, max.y);
return getOverlap(worldCenter, tlVertex);
}
}
else {
//In region to the left&down of rectangle