//----------------------------------------------------------
ofPolyline ofPolyline::fromRectangle(const ofRectangle& rect) {
    ofPolyline polyline;
    polyline.addVertex(rect.getMin());
    polyline.addVertex(rect.getMaxX(),rect.getMinY());
    polyline.addVertex(rect.getMax());
    polyline.addVertex(rect.getMinX(),rect.getMaxY());
    polyline.close();
    return polyline;
}
//----------------------------------------------------------
void ofRectangle::growToInclude(const ofRectangle& rect){
    float x0 = MIN(getMinX(),rect.getMinX());
    float x1 = MAX(getMaxX(),rect.getMaxX());
    float y0 = MIN(getMinY(),rect.getMinY());
    float y1 = MAX(getMaxY(),rect.getMaxY());
    float w = x1 - x0;
    float h = y1 - y0;
    set(x0,y0,w,h);
}
void KinectGrabber::setKinectROI(ofRectangle ROI){
    minX = static_cast<int>(ROI.getMinX());
    maxX = static_cast<int>(ROI.getMaxX());
    minY = static_cast<int>(ROI.getMinY());
    maxY = static_cast<int>(ROI.getMaxY());
    ROIwidth = maxX-minX;
    ROIheight = maxY-minY;
    resetBuffers();
}
Example #4
0
ofRectangle ofRectangleCrop(const ofRectangle & rect, const ofRectangle & rectCrop) {
    ofRectangle r;
    if(rect.intersects(rectCrop) == false) {
        return r;
    }
    r = rect;
    if(r.getMinX() < rectCrop.getMinX()) {
        r.x = rectCrop.getMinX();
    }
    if(r.getMaxX() > rectCrop.getMaxX()) {
        r.width = rectCrop.getMaxX() - r.x;
    }
    if(r.getMinY() < rectCrop.getMinY()) {
        r.y = rectCrop.getMinY();
    }
    if(r.getMaxY() > rectCrop.getMaxY()) {
        r.height = rectCrop.getMaxY() - r.y;
    }
    return r;
}
Example #5
0
void ofxParticleSystem::applyVectorField(float * field, int fieldWidth, int fieldHeight, int numComponents, ofRectangle areaOfInfluence, float force) {
    for(list<ofxParticle*>::iterator it = particles.begin(); it != particles.end(); it++){
        ofxParticle & p = (**it);
        ofVec2f pos(p.position.x,p.position.y);
        if(areaOfInfluence.inside(pos)){
            int x = (int)ofMap(pos.x, areaOfInfluence.getMinX(), areaOfInfluence.getMaxX(), 0, fieldWidth-1);
            int y = (int)ofMap(pos.y, areaOfInfluence.getMinY(), areaOfInfluence.getMaxY(), 0, fieldHeight-1);
            int index = (x+y*fieldWidth)*numComponents;
            ofVec2f dir(field[index],field[index+1]);
            dir.scale(force);
            //                                    cout << "(" << dir.x << "," << dir.y << ")\n";
            p.applyForce(dir);
        }
    }
}
//----------------------------------------------------------
ofRectangle ofRectangle::getIntersection(const ofRectangle& rect) const {

    float x0 = MAX(getMinX(),rect.getMinX());
    float x1 = MIN(getMaxX(),rect.getMaxX());
    
    float w = x1 - x0;
    if(w < 0.0f) return ofRectangle(0,0,0,0); // short circuit if needed
    
    float y0 = MAX(getMinY(),rect.getMinY());
    float y1 = MIN(getMaxY(),rect.getMaxY());
    
    float h = y1 - y0;
    if(h < 0.0f) return ofRectangle(0,0,0,0);  // short circuit if needed
    
    return ofRectangle(x0,y0,w,h);
}
//----------------------------------------------------------
bool ofRectangle::intersects(const ofRectangle& rect) const {
    return (getMinX() < rect.getMaxX() && getMaxX() > rect.getMinX() &&
            getMinY() < rect.getMaxY() && getMaxY() > rect.getMinY());
}
//----------------------------------------------------------
bool ofRectangle::inside(const ofRectangle& rect) const {
    return inside(rect.getMinX(),rect.getMinY()) &&
           inside(rect.getMaxX(),rect.getMaxY());
}
Example #9
0
bool testApp::joelInside(ofRectangle r, ofPoint p){
    return p.x >= r.getMinX() && p.y >= r.getMinY() && p.x <= r.getMaxX() && p.y <= r.getMaxY();
}
Example #10
0
ofRectangle ofRectangle::mapClamp(const ofRectangle & coeff) const {
    return ofRectangle(
       mapClamp(glm::vec2(coeff.getMinX(), coeff.getMinY())),
       mapClamp(glm::vec2(coeff.getMaxX(), coeff.getMaxY()))
       );
}