Flutter Engine
The Flutter Engine
Loading...
Searching...
No Matches
Point_normalize_2.cpp
Go to the documentation of this file.
1// Copyright 2019 Google LLC.
2// Use of this source code is governed by a BSD-style license that can be found in the LICENSE file.
4// HASH=d84fce292d86c7d9ef37ae2d179c03c7
5REG_FIDDLE(Point_normalize_2, 256, 256, false, 0) {
6void draw(SkCanvas* canvas) {
8 paint.setAntiAlias(true);
9 const SkPoint lines[][2] = { {{ 30, 110 }, { 190, 30 }},
10 {{ 120, 140 }, { 30, 220 }}};
11 for (auto line : lines) {
12 canvas->drawLine(line[0], line[1], paint);
13 SkVector vector = line[1] - line[0];
14 if (vector.normalize()) {
15 SkVector rotate90 = { -vector.fY, vector.fX };
16 rotate90 *= 10.f;
17 canvas->drawLine(line[0] - rotate90, line[0] + rotate90, paint);
18 canvas->drawLine(line[1] - rotate90, line[1] + rotate90, paint);
19 }
20 }
21}
22} // END FIDDLE
static void draw(SkCanvas *canvas, SkRect &target, int x, int y)
Definition aaclip.cpp:27
void drawLine(SkScalar x0, SkScalar y0, SkScalar x1, SkScalar y1, const SkPaint &paint)
const Paint & paint
#define REG_FIDDLE(NAME, W, H, TEXT, I)
Definition examples.h:60
float fX
x-axis value
float fY
y-axis value
bool normalize()
Definition SkPoint.cpp:22