Changeset View
Changeset View
Standalone View
Standalone View
source/blender/blenlib/BLI_float2.hh
| Show First 20 Lines • Show All 78 Lines • ▼ Show 20 Lines | struct float2 { | ||||
| float2 &operator-=(const float2 &other) | float2 &operator-=(const float2 &other) | ||||
| { | { | ||||
| x -= other.x; | x -= other.x; | ||||
| y -= other.y; | y -= other.y; | ||||
| return *this; | return *this; | ||||
| } | } | ||||
| float2 &operator*=(const float2 &other) | |||||
| { | |||||
| x *= other.x; | |||||
| y *= other.y; | |||||
| return *this; | |||||
| } | |||||
| float2 &operator*=(float factor) | float2 &operator*=(float factor) | ||||
| { | { | ||||
| x *= factor; | x *= factor; | ||||
| y *= factor; | y *= factor; | ||||
| return *this; | return *this; | ||||
| } | } | ||||
| float2 &operator-=(float factor) | |||||
| { | |||||
| x -= factor; | |||||
| y -= factor; | |||||
| return *this; | |||||
| } | |||||
| float2 &operator/=(float divisor) | float2 &operator/=(float divisor) | ||||
| { | { | ||||
| x /= divisor; | x /= divisor; | ||||
| y /= divisor; | y /= divisor; | ||||
| return *this; | return *this; | ||||
| } | } | ||||
| uint64_t hash() const | uint64_t hash() const | ||||
| { | { | ||||
| uint64_t x1 = *reinterpret_cast<const uint32_t *>(&x); | uint64_t x1 = *reinterpret_cast<const uint32_t *>(&x); | ||||
| uint64_t x2 = *reinterpret_cast<const uint32_t *>(&y); | uint64_t x2 = *reinterpret_cast<const uint32_t *>(&y); | ||||
| return (x1 * 812519) ^ (x2 * 707951); | return (x1 * 812519) ^ (x2 * 707951); | ||||
| } | } | ||||
| friend float2 operator+(const float2 &a, const float2 &b) | friend float2 operator+(const float2 &a, const float2 &b) | ||||
| { | { | ||||
| return {a.x + b.x, a.y + b.y}; | return {a.x + b.x, a.y + b.y}; | ||||
| } | } | ||||
| friend float2 operator+(const float2 &a, const float &b) | |||||
| { | |||||
| return {a.x + b, a.y + b}; | |||||
| } | |||||
| friend float2 operator-(const float2 &a, const float2 &b) | friend float2 operator-(const float2 &a, const float2 &b) | ||||
| { | { | ||||
| return {a.x - b.x, a.y - b.y}; | return {a.x - b.x, a.y - b.y}; | ||||
| } | } | ||||
| friend float2 operator-(const float2 &a, const float &b) | |||||
| { | |||||
| return {a.x - b, a.y - b}; | |||||
| } | |||||
| friend float2 operator-(const float2 &a) | |||||
| { | |||||
| return {-a.x, -a.y}; | |||||
| } | |||||
| friend float2 operator*(const float2 &a, const float2 &b) | |||||
| { | |||||
| return {a.x * b.x, a.y * b.y}; | |||||
| } | |||||
| friend float2 operator*(const float2 &a, float b) | friend float2 operator*(const float2 &a, float b) | ||||
| { | { | ||||
| return {a.x * b, a.y * b}; | return {a.x * b, a.y * b}; | ||||
| } | } | ||||
| friend float2 operator/(const float2 &a, const float2 &b) | |||||
| { | |||||
| BLI_assert(b.x != 0.0f && b.y != 0.0f); | |||||
| return {a.x / b.x, a.y / b.y}; | |||||
| } | |||||
| friend float2 operator/(const float2 &a, float b) | friend float2 operator/(const float2 &a, float b) | ||||
| { | { | ||||
| BLI_assert(b != 0.0f); | BLI_assert(b != 0.0f); | ||||
| return {a.x / b, a.y / b}; | return {a.x / b, a.y / b}; | ||||
| } | } | ||||
| friend float2 operator*(float a, const float2 &b) | friend float2 operator*(float a, const float2 &b) | ||||
| { | { | ||||
| Show All 16 Lines | static float2 interpolate(const float2 &a, const float2 &b, float t) | ||||
| return a * (1 - t) + b * t; | return a * (1 - t) + b * t; | ||||
| } | } | ||||
| static float2 abs(const float2 &a) | static float2 abs(const float2 &a) | ||||
| { | { | ||||
| return float2(fabsf(a.x), fabsf(a.y)); | return float2(fabsf(a.x), fabsf(a.y)); | ||||
| } | } | ||||
| static float2 floor(const float2 &a) | |||||
| { | |||||
| return float2(floorf(a.x), floorf(a.y)); | |||||
| } | |||||
| static float distance(const float2 &a, const float2 &b) | static float distance(const float2 &a, const float2 &b) | ||||
| { | { | ||||
| return (a - b).length(); | return (a - b).length(); | ||||
| } | } | ||||
| static float distance_squared(const float2 &a, const float2 &b) | static float distance_squared(const float2 &a, const float2 &b) | ||||
| { | { | ||||
| float2 diff = a - b; | float2 diff = a - b; | ||||
| return float2::dot(diff, diff); | return float2::dot(diff, diff); | ||||
| } | } | ||||
| static float2 safe_divide(const float2 &a, const float2 &b) | |||||
| { | |||||
| float2 result; | |||||
| result.x = (b.x == 0.0f) ? 0.0f : a.x / b.x; | |||||
| result.y = (b.y == 0.0f) ? 0.0f : a.y / b.y; | |||||
| return result; | |||||
| } | |||||
| struct isect_result { | struct isect_result { | ||||
| enum { | enum { | ||||
| LINE_LINE_COLINEAR = -1, | LINE_LINE_COLINEAR = -1, | ||||
| LINE_LINE_NONE = 0, | LINE_LINE_NONE = 0, | ||||
| LINE_LINE_EXACT = 1, | LINE_LINE_EXACT = 1, | ||||
| LINE_LINE_CROSS = 2, | LINE_LINE_CROSS = 2, | ||||
| } kind; | } kind; | ||||
| float lambda; | float lambda; | ||||
| Show All 20 Lines | |||||