Flutter Engine
The Flutter Engine
Classes | Public Member Functions | Protected Member Functions | List of all members
SampleFitCubicToCircle Class Reference
Inheritance diagram for SampleFitCubicToCircle:
ClickHandlerSlide Slide SkRefCnt SkRefCntBase

Classes

class  Click
 

Public Member Functions

 SampleFitCubicToCircle ()
 
void load (SkScalar w, SkScalar h) override
 
void draw (SkCanvas *) override
 
bool onChar (SkUnichar) override
 
- Public Member Functions inherited from ClickHandlerSlide
bool onMouse (SkScalar x, SkScalar y, skui::InputState clickState, skui::ModifierKey modifierKeys) final
 
- Public Member Functions inherited from Slide
virtual SkISize getDimensions () const
 
virtual void gpuTeardown ()
 
virtual void draw (SkCanvas *canvas)=0
 
virtual bool animate (double nanos)
 
virtual void load (SkScalar winWidth, SkScalar winHeight)
 
virtual void resize (SkScalar winWidth, SkScalar winHeight)
 
virtual void unload ()
 
virtual bool onChar (SkUnichar c)
 
virtual bool onMouse (SkScalar x, SkScalar y, skui::InputState state, skui::ModifierKey modifiers)
 
virtual bool onGetControls (SkMetaData *)
 
virtual void onSetControls (const SkMetaData &)
 
const SkStringgetName ()
 
- Public Member Functions inherited from SkRefCntBase
 SkRefCntBase ()
 
virtual ~SkRefCntBase ()
 
bool unique () const
 
void ref () const
 
void unref () const
 

Protected Member Functions

ClickonFindClickHandler (SkScalar x, SkScalar y, skui::ModifierKey) override
 
bool onClick (Click *) override
 
- Protected Member Functions inherited from ClickHandlerSlide
virtual ClickonFindClickHandler (SkScalar x, SkScalar y, skui::ModifierKey modi)=0
 
virtual bool onClick (Click *)=0
 

Additional Inherited Members

- Protected Attributes inherited from Slide
SkString fName
 

Detailed Description

Definition at line 39 of file FitCubicToCircleSlide.cpp.

Constructor & Destructor Documentation

◆ SampleFitCubicToCircle()

SampleFitCubicToCircle::SampleFitCubicToCircle ( )
inline

Definition at line 41 of file FitCubicToCircleSlide.cpp.

41{ fName = "FitCubicToCircle"; }
SkString fName
Definition: Slide.h:54

Member Function Documentation

◆ draw()

void SampleFitCubicToCircle::draw ( SkCanvas canvas)
overridevirtual

Implements Slide.

Definition at line 157 of file FitCubicToCircleSlide.cpp.

157 {
158 canvas->clear(SK_ColorBLACK);
159
160 SkPaint circlePaint;
161 circlePaint.setColor(0x80ffffff);
162 circlePaint.setStyle(SkPaint::kStroke_Style);
163 circlePaint.setStrokeWidth(0);
164 circlePaint.setAntiAlias(true);
166 kRadius * 2), 0, 360, false, circlePaint);
167
168 SkPaint cubicPaint;
169 cubicPaint.setColor(SK_ColorGREEN);
171 cubicPaint.setStrokeWidth(10);
172 cubicPaint.setAntiAlias(true);
173 SkPath cubicPath;
174 cubicPath.moveTo(fCubicX[0], fCubicY[0]);
175 cubicPath.cubicTo(fCubicX[1], fCubicY[1], fCubicX[2], fCubicY[2], fCubicX[3], fCubicY[3]);
176 canvas->drawPath(cubicPath, cubicPaint);
177
178 SkPaint endpointsPaint;
179 endpointsPaint.setColor(SK_ColorBLUE);
180 endpointsPaint.setStrokeWidth(8);
181 endpointsPaint.setAntiAlias(true);
182 SkPoint points[2] = {{(float)fCubicX[0], (float)fCubicY[0]},
183 {(float)fCubicX[3], (float)fCubicY[3]}};
184 canvas->drawPoints(SkCanvas::kPoints_PointMode, 2, points, endpointsPaint);
185
186 SkPaint textPaint;
187 textPaint.setColor(SK_ColorWHITE);
188 constexpr static float kInfoTextSize = 16;
189 SkFont font(ToolUtils::DefaultTypeface(), kInfoTextSize);
190 int infoY = 10 + kInfoTextSize;
191 for (const SkString& infoString : fInfoStrings) {
192 canvas->drawString(infoString.c_str(), 10, infoY, font, textPaint);
193 infoY += kInfoTextSize * 3/2;
194 }
195}
static constexpr int kCenterX
static constexpr int kCenterY
static constexpr int kRadius
static const int points[]
constexpr SkColor SK_ColorBLUE
Definition: SkColor.h:135
constexpr SkColor SK_ColorBLACK
Definition: SkColor.h:103
constexpr SkColor SK_ColorGREEN
Definition: SkColor.h:131
constexpr SkColor SK_ColorWHITE
Definition: SkColor.h:122
void drawPoints(PointMode mode, size_t count, const SkPoint pts[], const SkPaint &paint)
Definition: SkCanvas.cpp:1710
void clear(SkColor color)
Definition: SkCanvas.h:1199
void drawArc(const SkRect &oval, SkScalar startAngle, SkScalar sweepAngle, bool useCenter, const SkPaint &paint)
Definition: SkCanvas.cpp:2728
void drawPath(const SkPath &path, const SkPaint &paint)
Definition: SkCanvas.cpp:1747
void drawString(const char str[], SkScalar x, SkScalar y, const SkFont &font, const SkPaint &paint)
Definition: SkCanvas.h:1803
@ kPoints_PointMode
draw each point separately
Definition: SkCanvas.h:1241
Definition: SkFont.h:35
void setStyle(Style style)
Definition: SkPaint.cpp:105
void setColor(SkColor color)
Definition: SkPaint.cpp:119
void setAntiAlias(bool aa)
Definition: SkPaint.h:170
@ kStroke_Style
set to stroke geometry
Definition: SkPaint.h:194
void setStrokeWidth(SkScalar width)
Definition: SkPaint.cpp:159
Definition: SkPath.h:59
SkPath & moveTo(SkScalar x, SkScalar y)
Definition: SkPath.cpp:688
SkPath & cubicTo(SkScalar x1, SkScalar y1, SkScalar x2, SkScalar y2, SkScalar x3, SkScalar y3)
Definition: SkPath.cpp:799
sk_sp< SkTypeface > DefaultTypeface()
font
Font Metadata and Metrics.
static constexpr SkRect MakeXYWH(float x, float y, float w, float h)
Definition: SkRect.h:659

◆ load()

void SampleFitCubicToCircle::load ( SkScalar  w,
SkScalar  h 
)
inlineoverridevirtual

Reimplemented from Slide.

Definition at line 42 of file FitCubicToCircleSlide.cpp.

42{ this->fitCubic(); }

◆ onChar()

bool SampleFitCubicToCircle::onChar ( SkUnichar  unichar)
overridevirtual

Reimplemented from Slide.

Definition at line 238 of file FitCubicToCircleSlide.cpp.

238 {
239 if (unichar == 'E') {
240 constexpr static double kMaxErrorT = 0.21132486540519; // Always the same.
241 // Split the arc in half until error =~0, and report the improvement after each halving.
242 double lastError = -1;
243 for (double theta = fTheta; lastError != 0; theta /= 2) {
244 double rads = theta * M_PI/180;
245 std::array<double, 4> X, Y;
246 fit_cubic_to_unit_circle(1, 0, std::cos(rads), std::sin(rads), &X, &Y);
247 auto [x, dx, ddx] = eval_cubic(X.data(), kMaxErrorT);
248 auto [y, dy, ddy] = eval_cubic(Y.data(), kMaxErrorT);
249 double error = std::sqrt(x*x + y*y) * kRadius - kRadius;
250 if ((float)error <= 0) {
251 error = 0;
252 }
253 SkDebugf("%6.2f degrees: error= %10.5gpx", theta, error);
254 if (lastError > 0) {
255 SkDebugf(" (%17.14fx improvement)", lastError / error);
256 }
257 SkDebugf("\n");
258 lastError = error;
259 }
260 return true;
261 }
262 return false;
263}
#define M_PI
static float fit_cubic_to_unit_circle(double x0, double y0, double x1, double y1, std::array< double, 4 > *X, std::array< double, 4 > *Y)
static std::tuple< double, double, double > eval_cubic(double x[], double T)
void SK_SPI SkDebugf(const char format[],...) SK_PRINTF_LIKE(1
static const SkScalar Y
Definition: StrokeBench.cpp:55
static const SkScalar X
Definition: StrokeBench.cpp:54
const uint8_t uint32_t uint32_t GError ** error
double y
double x
skia_private::AutoTArray< sk_sp< SkImageFilter > > filters TypedMatrix matrix TypedMatrix matrix SkScalar dx
Definition: SkRecords.h:208
SIN Vec< N, float > sqrt(const Vec< N, float > &x)
Definition: SkVx.h:706

◆ onClick()

bool SampleFitCubicToCircle::onClick ( Click )
overrideprotected

Definition at line 232 of file FitCubicToCircleSlide.cpp.

232 {
233 Click* myClick = (Click*)click;
234 myClick->doClick(this);
235 return true;
236}

◆ onFindClickHandler()

ClickHandlerSlide::Click * SampleFitCubicToCircle::onFindClickHandler ( SkScalar  x,
SkScalar  y,
skui::ModifierKey  modi 
)
overrideprotectedvirtual

Return a Click object to handle the click. onClick will be called repeatedly with the latest mouse state tracked on the Click object until it returns false.

Implements ClickHandlerSlide.

Definition at line 219 of file FitCubicToCircleSlide.cpp.

220 {
221 double dx0 = x - fCubicX[0];
222 double dy0 = y - fCubicY[0];
223 double dx3 = x - fCubicX[3];
224 double dy3 = y - fCubicY[3];
225 if (dx0*dx0 + dy0*dy0 < dx3*dx3 + dy3*dy3) {
226 return new Click(0);
227 } else {
228 return new Click(1);
229 }
230}

The documentation for this class was generated from the following file: