ofPolyline::getArea() returns negative value

I just figured out calling ofPolyline::getArea() returns a negative value if the polyline is set in CCW order.

Here’s my test code.

//--------------------------------------------------------------
void ofApp::setup(){
    
    polyline.addVertex(0, -58);
    polyline.addVertex(-50, 29);
    polyline.addVertex(50, 29);
    polyline.close();
    
    cout << polyline.getArea() << endl;
}

//--------------------------------------------------------------
void ofApp::update(){
    
}

//--------------------------------------------------------------
void ofApp::draw(){
    
    ofTranslate(ofGetWidth()/2, ofGetHeight()/2);
    polyline.draw();
}

Result:

-4350

Shouldn’t it always return positive values or is it intensionally designed this way?

yeah this is pretty standard, you can always abs the result and it tells you the winding.

2 Likes