Straws::Straws( const std::deque<CGPoint> &i_path, int W )
{
	_straws.resize( i_path.size() );
	auto straw = _straws.begin();
	auto p1 = i_path.end() - W;
	auto p2 = i_path.begin() + W;
	for ( int i = 0; i < W; ++i )
	{
		*straw = squareLength( *p1 - *p2 );
		++straw;
		++p1;
		++p2;
	}
	p1 = i_path.begin();
	for ( ; p2 != i_path.end(); ++p1, ++p2 )
	{
		*straw = squareLength( *p1 - *p2 );
		++straw;
	}
	p2 = i_path.begin();
	for ( int i = 0; i < W; ++i )
	{
		*straw = squareLength( *p1 - *p2 );
		++straw;
		++p1;
		++p2;
	}
}
Example #2
0
bool isStraightLine( T first, T last, CGFloat i_error2 )
{
	CGPoint	v = *first;
	CGPoint	w = *(last-1);
	
	CGPoint wMinusV = w - v;
	const CGFloat l2 = squareLength( wMinusV ); // i.e. |w-v|^2 -  avoid a sqrt
	if ( l2 == 0 )
	{
		// v == w
		assert( false );
	}
	else
	{
		for ( auto it = first + 1; it != (last-1); ++it )
		{
			const CGPoint &p( *it );
			CGFloat t = ((p - v) * wMinusV) / l2;
			if ( t < 0.0 )
			{
				// Beyond the 'v' end of the segment
				if ( squareLength( v - p ) > i_error2 )
					return false;
			}
			else if ( t > 1.0 )
			{
				// Beyond the 'w' end of the segment
				if ( squareLength( w - p ) > i_error2 )
					return false;
			}
			else
			{
				CGPoint projection = v + (t * wMinusV);  // Projection falls on the segment
				if ( squareLength( projection - p ) > i_error2 )
					return false;
			}
		}
	}
	return true;
}
Example #3
0
 //------------------------------------------------------------------------------
 /// 値の表すベクトル (x, y) の長さを計算します。
 ///
 /// @return ベクトルの長さ。
 float Vec2::length()const
 {
     return Math::Sqrt(squareLength());
 }
Example #4
0
float ofxVec4f::lengthSquared() const {
	return squareLength();
}
Example #5
0
 float
 length(const Vector<N, T>& vect)
 {
     return std::sqrt(squareLength(vect));
 }