PolyCollider.IsConvex C# (CSharp) Method

IsConvex() public method

public IsConvex ( ) : bool
return bool
	public bool IsConvex() 
	{
		if(_points.Count < 3)
		{
			return false;
		}

		Vector2 p;
		Vector2 v;
		Vector2 u;
		float res = 0.0f;
		for(int i = 0; i < _points.Count; ++i) 
		{
			p = _points[i];
			Vector2 temp = _points[(i+1) % _points.Count];

			v = temp - p;

			u = _points[(i+2) % _points.Count];

			if(i == 0) // In the first loop the direction is unkown..
			{
				res = (u.x * v.y) - (u.y * v.x) + (v.x * p.y)  - (v.y * p.x);
			}
			else
			{
				float newRes = (u.x * v.y) - (u.y * v.x) + (v.x * p.y) - (v.y * p.x);
				if((newRes > 0 && res < 0) || (newRes < 0 && res > 0))
				{
					return false;
				}
			}
		}
		return true;
	}