polygon.cpp
bool Polygon::eval(double x, double y) {
	//init as inside
	bool inside = true;
	vec2 v1, v2;
	float d1;
	//must at least be a triangle (assuming closed polygon not line)
	assert(theVerts.size() >=3);

	std::vector<vec2>::iterator nxt = theVerts.begin();
	vec2 start = theVerts.at(0);

	v1 = start;
	//use iterator loop
	for (std::vector<vec2>::iterator it = theVerts.begin() ; 
		it != theVerts.end(); ++it) {

		//advance to the next vertex
		nxt++;
		//if it is valid process the line
		if (nxt != theVerts.end()){
			v2 = *nxt;
			//if point falls outside any line
			d1 = implicitLine(v1, v2, vec2(x, y));
			//cout << "dist: " << d1 << endl;
			if ( d1 < 0) {
				inside = false;
			}
		} 
		//if valid set up for the next line
		v1 = v2;
	}
	//do final line
	//cout << "final line: (v2, s): " << v2 << "  " << start << endl;
	d1 = implicitLine(v2, start, vec2(x, y));
	//cout << "dist: " << d1 << endl;
	if (d1 < 0) {
		inside = false;
	}
	
	return inside;
}
/* polygon evaluation forms lines out of vertices around the shape and tests
   that the input point is on the same 'side' of all the lines = inside 
   vertices should be passed in counter clockwise CCW! */
polygon evaluation forms lines out of vertices around the shape and tests
that the input point is on the same 'side' of all the lines = inside
vertices should be passed in counter clockwise CCW!
polygon evaluation forms lines out of vertices around the shape and tests that the input point is on the same ' side ' of all the lines = inside vertices should be passed in counter clockwise CCW!
bool Polygon::eval(double x, double y) {
	bool inside = true;
	vec2 v1, v2;
	float d1;
	assert(theVerts.size() >=3);
	std::vector<vec2>::iterator nxt = theVerts.begin();
	vec2 start = theVerts.at(0);
	v1 = start;
	for (std::vector<vec2>::iterator it = theVerts.begin() ; 
		it != theVerts.end(); ++it) {
		nxt++;
		if (nxt != theVerts.end()){
			v2 = *nxt;
			d1 = implicitLine(v1, v2, vec2(x, y));
			if ( d1 < 0) {
				inside = false;
			}
		} 
		v1 = v2;
	}
	d1 = implicitLine(v2, start, vec2(x, y));
	if (d1 < 0) {
		inside = false;
	}
	return inside;
}
bool Polygon :: eval ( double x , double y ) { bool inside = true ; vec2 v1 , v2 ; float d1 ; assert ( theVerts . size ( ) >= 3 ) ; std :: vector < vec2 > :: iterator nxt = theVerts . begin ( ) ; vec2 start = theVerts . at ( 0 ) ; v1 = start ; for ( std :: vector < vec2 > :: iterator it = theVerts . begin ( ) ; it != theVerts . end ( ) ; ++ it ) { nxt ++ ; if ( nxt != theVerts . end ( ) ) { v2 = * nxt ; d1 = implicitLine ( v1 , v2 , vec2 ( x , y ) ) ; if ( d1 < 0 ) { inside = false ; } } v1 = v2 ; } d1 = implicitLine ( v2 , start , vec2 ( x , y ) ) ; if ( d1 < 0 ) { inside = false ; } return inside ; }
polygon evaluation forms lines out of vertices around the shape and tests
that the input point is on the same 'side' of all the lines = inside
vertices should be passed in counter clockwise CCW!
polygon evaluation forms lines out of vertices around the shape and tests that the input point is on the same ' side ' of all the lines = inside vertices should be passed in counter clockwise CCW!
//init as inside //must at least be a triangle (assuming closed polygon not line) //use iterator loop //advance to the next vertex //if it is valid process the line //if point falls outside any line //cout << "dist: " << d1 << endl; //if valid set up for the next line //do final line //cout << "final line: (v2, s): " << v2 << "  " << start << endl; //cout << "dist: " << d1 << endl;