void zoneManager::repellNode(ofPtr<clamourNode> n, ofPtr<zone> z) {

//    cout << "repell \n";
    //finding centroid is not solved here so this method only works if zones drawn from the center
    ofVec2f v = n->getMeanPos_abs() - n->getIntersect();
    ofPoint p = clamourUtils::getInsideIntersect(z->getOuterEdge(), z->getPos_abs(), n->getIntersect());
    p = p + v;
    n->setRawPos_abs(p);
    n->modifyHistory();

}
void nodeManager::checkForCollisions(ofPtr<clamourNode> n) {

    bool collisionFound = false;

    for(int  i = 0; i < mCollisionMapBounds.size(); i ++) {

        if(mCollisionMapBounds[i].inside(n->getMeanPos_abs())) {

            vector <ofPtr<clamourNode> >::iterator target;

            target = mCollisionMap[i].begin();

            while(target != mCollisionMap[i].end()) {

                if(*target != n) {

                    if((*target)->getBounds().inside(n->getMeanPos_abs())) {
                        bool isCollision = clamourUtils::pointInPath((*target)->getOuterEdge(), n->getMeanPos_abs());
                        if(isCollision) {
                            if(!n->getIsColliding() && !(*target)->getIsColliding())implementReactions(n , *target);
                            n->setIsColliding(true);
                            (*target)->setIsColliding(true);
                            collisionFound = true;
                        }
                    }

                }

                ++target;
            }


        }

    }

    n->setIsColliding(collisionFound);

}
void zoneManager::containNode(ofPtr<clamourNode> n, ofPtr<zone> z) {

    ofPoint intersect;
    bool isOutside = clamourUtils::pathOutPath( n->getOuterEdge(), z->getOuterEdge(), intersect);

    if(isOutside) {
        ofVec2f v = n->getMeanPos_abs() - intersect;
        ofVec2f vi(intersect - z->getPos_abs());

        ofPoint p = clamourUtils::getInsideIntersect(z->getOuterEdge(), z->getPos_abs(), intersect);
        ofVec2f d = (p - z->getPos_abs());
        p -= d * 0.05; //move it slightly inside
        p = p + v;

        if(d.length() * 0.95 < vi.length()) { //only if necessary
            n->setRawPos_abs(p);
            n->modifyHistory();
        }

    }

}