Flutter Engine
The Flutter Engine
Functions
SkPoint.cpp File Reference
#include "include/core/SkPoint.h"
#include "include/core/SkTypes.h"
#include "include/private/base/SkFloatingPoint.h"
#include "src/core/SkPointPriv.h"
#include <cmath>

Go to the source code of this file.

Functions

template<bool use_rsqrt>
bool set_point_length (SkPoint *pt, float x, float y, float length, float *orig_length=nullptr)
 

Function Documentation

◆ set_point_length()

template<bool use_rsqrt>
bool set_point_length ( SkPoint pt,
float  x,
float  y,
float  length,
float *  orig_length = nullptr 
)

Definition at line 42 of file SkPoint.cpp.

43 {
44 SkASSERT(!use_rsqrt || (orig_length == nullptr));
45
46 // our mag2 step overflowed to infinity, so use doubles instead.
47 // much slower, but needed when x or y are very large, other wise we
48 // divide by inf. and return (0,0) vector.
49 double xx = x;
50 double yy = y;
51 double dmag = sqrt(xx * xx + yy * yy);
52 double dscale = sk_ieee_double_divide(length, dmag);
53 x *= dscale;
54 y *= dscale;
55 // check if we're not finite, or we're zero-length
56 if (!SkIsFinite(x, y) || (x == 0 && y == 0)) {
57 pt->set(0, 0);
58 return false;
59 }
60 float mag = 0;
61 if (orig_length) {
62 mag = sk_double_to_float(dmag);
63 }
64 pt->set(x, y);
65 if (orig_length) {
66 *orig_length = mag;
67 }
68 return true;
69}
#define SkASSERT(cond)
Definition: SkAssert.h:116
static constexpr float sk_double_to_float(double x)
static bool SkIsFinite(T x, Pack... values)
static constexpr double sk_ieee_double_divide(double numer, double denom)
size_t length
double y
double x
SIN Vec< N, float > sqrt(const Vec< N, float > &x)
Definition: SkVx.h:706
void set(float x, float y)
Definition: SkPoint_impl.h:200