Beispiel #1
0
Vector<T, N> getNearestPoint(const LineSegment<T, N>& line,
                             const Vector<T, N>& point)
{
    double divisor = getLengthSquared(line.getVector());
    double t = (point - line.getStart()) * line.getVector() / divisor;
    return line.getPointAtT(getClamped(t, 0.0, 1.0));
}
Beispiel #2
0
Vector<T, 2> getRelativePosition(const LineSegment<T, 2>& line,
                                 const Vector<T, 2>& point)
{
    auto lv = line.getVector();
    double len = getLengthSquared(lv);
    auto pv = point - line.getStart();
    return vector2<T>(lv * pv / len, getNormal(lv) * pv / len);
}
Beispiel #3
0
// Calculates the square of the Euclidian distance to (dx,dy) and stores it in
// *lengthSquared.  Returns true if the distance is judged to be "nearly zero".
//
// This logic is encapsulated in a helper method to make it explicit that we
// always perform this check in the same manner, to avoid inconsistencies
// (see http://code.google.com/p/skia/issues/detail?id=560 ).
static inline bool isLengthNearlyZero(SkScalar dx, SkScalar dy,
                                      Sk64 *lengthSquared) {
    Sk64 tolSqr;
    getLengthSquared(dx, dy, lengthSquared);

    // we want nearlyzero^2, but to compute it fast we want to just do a
    // 32bit multiply, so we require that it not exceed 31bits. That is true
    // if nearlyzero is <= 0xB504, which should be trivial, since usually
    // nearlyzero is a very small fixed-point value.
    SkASSERT(SK_ScalarNearlyZero <= 0xB504);

    tolSqr.set(0, SK_ScalarNearlyZero * SK_ScalarNearlyZero);
    return *lengthSquared <= tolSqr;
}
float Vector2D::getLength() const
{
	float lengthSquared = getLengthSquared();
	return sqrt(lengthSquared);
}
Beispiel #5
0
	float vector4::getLength() const
	{	
		return sqrt(getLengthSquared());
	}
Beispiel #6
0
float
xpcc::Vector<T, 4>::getLength() const
{
	return std::sqrt(getLengthSquared());
}
Beispiel #7
0
SkScalar SkPoint::Length(SkScalar dx, SkScalar dy) {
    Sk64    tmp;
    getLengthSquared(dx, dy, &tmp);
    return tmp.getSqrt();
}
Beispiel #8
0
SkScalar SkPoint::Length(SkScalar dx, SkScalar dy) {
    return sk_float_sqrt(getLengthSquared(dx, dy));
}
Beispiel #9
0
// Calculates the square of the Euclidian distance to (dx,dy) and stores it in
// *lengthSquared.  Returns true if the distance is judged to be "nearly zero".
//
// This logic is encapsulated in a helper method to make it explicit that we
// always perform this check in the same manner, to avoid inconsistencies
// (see http://code.google.com/p/skia/issues/detail?id=560 ).
static inline bool isLengthNearlyZero(float dx, float dy,
                                      float *lengthSquared) {
    *lengthSquared = getLengthSquared(dx, dy);
    return *lengthSquared <= (SK_ScalarNearlyZero * SK_ScalarNearlyZero);
}