Flutter Engine
The Flutter Engine
SkPointPriv.h
Go to the documentation of this file.
1/*
2 * Copyright 2006 The Android Open Source Project
3 *
4 * Use of this source code is governed by a BSD-style license that can be
5 * found in the LICENSE file.
6 */
7
8#ifndef SkPointPriv_DEFINED
9#define SkPointPriv_DEFINED
10
12#include "include/core/SkRect.h"
13
15public:
16 enum Side {
20 };
21
22 static bool AreFinite(const SkPoint array[], int count) {
23 return SkIsFinite(&array[0].fX, count << 1);
24 }
25
26 static const SkScalar* AsScalars(const SkPoint& pt) { return &pt.fX; }
27
28 static bool CanNormalize(SkScalar dx, SkScalar dy) {
29 return SkIsFinite(dx, dy) && (dx || dy);
30 }
31
32 static SkScalar DistanceToLineBetweenSqd(const SkPoint& pt, const SkPoint& a,
33 const SkPoint& b, Side* side = nullptr);
34
36 const SkPoint& b, Side* side = nullptr) {
38 }
39
41 const SkPoint& b);
42
44 const SkPoint& b) {
46 }
47
48 static SkScalar DistanceToSqd(const SkPoint& pt, const SkPoint& a) {
49 SkScalar dx = pt.fX - a.fX;
50 SkScalar dy = pt.fY - a.fY;
51 return dx * dx + dy * dy;
52 }
53
54 static bool EqualsWithinTolerance(const SkPoint& p1, const SkPoint& p2) {
55 return !CanNormalize(p1.fX - p2.fX, p1.fY - p2.fY);
56 }
57
58 static bool EqualsWithinTolerance(const SkPoint& pt, const SkPoint& p, SkScalar tol) {
59 return SkScalarNearlyZero(pt.fX - p.fX, tol)
60 && SkScalarNearlyZero(pt.fY - p.fY, tol);
61 }
62
63 static SkScalar LengthSqd(const SkPoint& pt) {
64 return SkPoint::DotProduct(pt, pt);
65 }
66
67 static void Negate(SkIPoint& pt) {
68 pt.fX = -pt.fX;
69 pt.fY = -pt.fY;
70 }
71
72 static void RotateCCW(const SkPoint& src, SkPoint* dst) {
73 // use a tmp in case src == dst
74 SkScalar tmp = src.fX;
75 dst->fX = src.fY;
76 dst->fY = -tmp;
77 }
78
79 static void RotateCCW(SkPoint* pt) {
80 RotateCCW(*pt, pt);
81 }
82
83 static void RotateCW(const SkPoint& src, SkPoint* dst) {
84 // use a tmp in case src == dst
85 SkScalar tmp = src.fX;
86 dst->fX = -src.fY;
87 dst->fY = tmp;
88 }
89
90 static void RotateCW(SkPoint* pt) {
91 RotateCW(*pt, pt);
92 }
93
94 static bool SetLengthFast(SkPoint* pt, float length);
95
96 static SkPoint MakeOrthog(const SkPoint& vec, Side side = kLeft_Side) {
98 return (side == kRight_Side) ? SkPoint{-vec.fY, vec.fX} : SkPoint{vec.fY, -vec.fX};
99 }
100
101 // counter-clockwise fan
103 size_t stride) {
104 SkASSERT(stride >= sizeof(SkPoint));
105
106 ((SkPoint*)((intptr_t)v + 0 * stride))->set(l, t);
107 ((SkPoint*)((intptr_t)v + 1 * stride))->set(l, b);
108 ((SkPoint*)((intptr_t)v + 2 * stride))->set(r, b);
109 ((SkPoint*)((intptr_t)v + 3 * stride))->set(r, t);
110 }
111
112 // tri strip with two counter-clockwise triangles
114 size_t stride) {
115 SkASSERT(stride >= sizeof(SkPoint));
116
117 ((SkPoint*)((intptr_t)v + 0 * stride))->set(l, t);
118 ((SkPoint*)((intptr_t)v + 1 * stride))->set(l, b);
119 ((SkPoint*)((intptr_t)v + 2 * stride))->set(r, t);
120 ((SkPoint*)((intptr_t)v + 3 * stride))->set(r, b);
121 }
122 static void SetRectTriStrip(SkPoint v[], const SkRect& rect, size_t stride) {
123 SetRectTriStrip(v, rect.fLeft, rect.fTop, rect.fRight, rect.fBottom, stride);
124 }
125};
126
127#endif
int count
Definition: FontMgrTest.cpp:50
#define SkASSERT(cond)
Definition: SkAssert.h:116
static bool SkIsFinite(T x, Pack... values)
static int side(double x)
static bool SkScalarNearlyZero(SkScalar x, SkScalar tolerance=SK_ScalarNearlyZero)
Definition: SkScalar.h:101
#define SkScalarSqrt(x)
Definition: SkScalar.h:42
static void SetRectTriStrip(SkPoint v[], const SkRect &rect, size_t stride)
Definition: SkPointPriv.h:122
static void SetRectFan(SkPoint v[], SkScalar l, SkScalar t, SkScalar r, SkScalar b, size_t stride)
Definition: SkPointPriv.h:102
static const SkScalar * AsScalars(const SkPoint &pt)
Definition: SkPointPriv.h:26
static void SetRectTriStrip(SkPoint v[], SkScalar l, SkScalar t, SkScalar r, SkScalar b, size_t stride)
Definition: SkPointPriv.h:113
static SkPoint MakeOrthog(const SkPoint &vec, Side side=kLeft_Side)
Definition: SkPointPriv.h:96
static void RotateCCW(const SkPoint &src, SkPoint *dst)
Definition: SkPointPriv.h:72
static void RotateCW(const SkPoint &src, SkPoint *dst)
Definition: SkPointPriv.h:83
static SkScalar DistanceToLineBetween(const SkPoint &pt, const SkPoint &a, const SkPoint &b, Side *side=nullptr)
Definition: SkPointPriv.h:35
static bool SetLengthFast(SkPoint *pt, float length)
Definition: SkPoint.cpp:94
static bool CanNormalize(SkScalar dx, SkScalar dy)
Definition: SkPointPriv.h:28
static void RotateCCW(SkPoint *pt)
Definition: SkPointPriv.h:79
static SkScalar DistanceToLineSegmentBetween(const SkPoint &pt, const SkPoint &a, const SkPoint &b)
Definition: SkPointPriv.h:43
static SkScalar LengthSqd(const SkPoint &pt)
Definition: SkPointPriv.h:63
static void RotateCW(SkPoint *pt)
Definition: SkPointPriv.h:90
static SkScalar DistanceToLineSegmentBetweenSqd(const SkPoint &pt, const SkPoint &a, const SkPoint &b)
Definition: SkPoint.cpp:126
static bool AreFinite(const SkPoint array[], int count)
Definition: SkPointPriv.h:22
static bool EqualsWithinTolerance(const SkPoint &pt, const SkPoint &p, SkScalar tol)
Definition: SkPointPriv.h:58
static void Negate(SkIPoint &pt)
Definition: SkPointPriv.h:67
static bool EqualsWithinTolerance(const SkPoint &p1, const SkPoint &p2)
Definition: SkPointPriv.h:54
static SkScalar DistanceToLineBetweenSqd(const SkPoint &pt, const SkPoint &a, const SkPoint &b, Side *side=nullptr)
Definition: SkPoint.cpp:101
static SkScalar DistanceToSqd(const SkPoint &pt, const SkPoint &a)
Definition: SkPointPriv.h:48
float SkScalar
Definition: extension.cpp:12
static bool b
struct MyStruct a[10]
size_t length
sk_sp< SkBlender > blender SkRect rect
Definition: SkRecords.h:350
skia_private::AutoTArray< sk_sp< SkImageFilter > > filters TypedMatrix matrix TypedMatrix matrix SkScalar dx
Definition: SkRecords.h:208
dst
Definition: cp.py:12
int32_t fX
x-axis value
Definition: SkPoint_impl.h:29
int32_t fY
y-axis value
Definition: SkPoint_impl.h:30
float fX
x-axis value
Definition: SkPoint_impl.h:164
static float DotProduct(const SkVector &a, const SkVector &b)
Definition: SkPoint_impl.h:518
float fY
y-axis value
Definition: SkPoint_impl.h:165