提交 44ad012a 编写于 作者: H Hixie

Convert everything in the Sky API from degrees to radians.

Radians are the one true angle unit.

R=abarth@chromium.org

Review URL: https://codereview.chromium.org/1164393002
上级 c4b64d74
......@@ -2,6 +2,8 @@
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
#include "math.h"
#include "sky/engine/config.h"
#include "sky/engine/core/painting/Canvas.h"
......@@ -67,12 +69,12 @@ void Canvas::scale(float sx, float sy)
m_canvas->scale(sx, sy);
}
void Canvas::rotateDegrees(float degrees)
void Canvas::rotate(float radians)
{
if (!m_canvas)
return;
ASSERT(m_displayList->isRecording());
m_canvas->rotate(degrees);
m_canvas->rotate(radians * 180.0/M_PI);
}
void Canvas::skew(float sx, float sy)
......
......@@ -37,7 +37,7 @@ public:
void translate(float dx, float dy);
void scale(float sx, float sy);
void rotateDegrees(float degrees);
void rotate(float radians);
void skew(float sx, float sy);
void concat(const Float32List& matrix4);
......
......@@ -15,7 +15,7 @@ interface Canvas {
void translate(float dx, float dy);
void scale(float sx, float sy);
void rotateDegrees(float degrees);
void rotate(float radians);
void skew(float sx, float sy);
void concat(Float32List matrix4);
......
......@@ -5,6 +5,8 @@
#ifndef SKY_ENGINE_CORE_PAINTING_PATH_H_
#define SKY_ENGINE_CORE_PAINTING_PATH_H_
#include "math.h"
#include "sky/engine/core/painting/Rect.h"
#include "sky/engine/tonic/dart_wrappable.h"
#include "sky/engine/wtf/PassRefPtr.h"
......@@ -38,7 +40,7 @@ public:
void arcTo(const Rect& rect, float startAngle, float sweepAngle, bool forceMoveTo)
{
m_path.arcTo(rect.sk_rect, startAngle, sweepAngle, forceMoveTo);
m_path.arcTo(rect.sk_rect, startAngle*180.0/M_PI, sweepAngle*180.0/M_PI, forceMoveTo);
}
void close()
......
......@@ -8,6 +8,6 @@
] interface Path {
void moveTo(float x, float y);
void lineTo(float x, float y);
void arcTo(Rect rect, float startAngle, float sweepAngle, boolean forceMoveTo);
void arcTo(Rect rect, float startAngle, float sweepAngle, boolean forceMoveTo); // angles in radians
void close();
};
......@@ -123,7 +123,7 @@ class TransformNode {
canvas.save();
canvas.translate(_position[0], _position[1]);
canvas.rotateDegrees(_rotation);
canvas.rotate(degrees2radians(_rotation));
canvas.translate(-_width*_pivot[0], -_height*_pivot[1]);
// TODO: Use transformation matrix instead of individual calls
......@@ -147,4 +147,4 @@ class TransformNode {
void update(double dt) {
}
}
\ No newline at end of file
}
......@@ -24,7 +24,7 @@ void main() {
context.translate(mid.x, mid.y);
paint.color = const Color.fromARGB(128, 255, 0, 255);
context.rotateDegrees(45.0);
context.rotate(math.PI/4.0);
Gradient yellowBlue = new Gradient.Linear(
[new Point(-radius, -radius), new Point(0.0, 0.0)],
......
......@@ -10,8 +10,6 @@ import 'package:sky/framework/rendering/object.dart';
const double kTwoPi = 2 * math.PI;
double deg(double radians) => radians * 180.0 / math.PI;
class SectorConstraints {
const SectorConstraints({
this.minDeltaRadius: 0.0,
......@@ -128,10 +126,10 @@ class RenderDecoratedSector extends RenderSector {
Path path = new Path();
double outerRadius = (parentData.radius + deltaRadius);
Rect outerBounds = new Rect.fromLTRB(-outerRadius, -outerRadius, outerRadius, outerRadius);
path.arcTo(outerBounds, deg(parentData.theta), deg(deltaTheta), true);
path.arcTo(outerBounds, parentData.theta, deltaTheta, true);
double innerRadius = parentData.radius;
Rect innerBounds = new Rect.fromLTRB(-innerRadius, -innerRadius, innerRadius, innerRadius);
path.arcTo(innerBounds, deg(parentData.theta + deltaTheta), deg(-deltaTheta), false);
path.arcTo(innerBounds, parentData.theta + deltaTheta, -deltaTheta, false);
path.close();
canvas.drawPath(path, paint);
}
......
......@@ -2,6 +2,7 @@
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
import 'dart:math' as math;
import 'dart:sky';
import 'package:sky/framework/net/image_cache.dart' as image_cache;
......@@ -16,7 +17,7 @@ void beginFrame(double timeStamp) {
double delta = timeStamp - timeBase;
PictureRecorder canvas = new PictureRecorder(view.width, view.height);
canvas.translate(view.width / 2.0, view.height / 2.0);
canvas.rotateDegrees(delta / 10);
canvas.rotate(math.PI * delta / 1800);
canvas.scale(0.2, 0.2);
Paint paint = new Paint()..setARGB(255, 0, 255, 0);
if (image != null)
......
......@@ -3,6 +3,7 @@
// found in the LICENSE file.
import 'dart:sky';
import 'dart:math' as math;
double timeBase = null;
......@@ -13,7 +14,7 @@ void beginFrame(double timeStamp) {
double delta = timeStamp - timeBase;
PictureRecorder canvas = new PictureRecorder(view.width, view.height);
canvas.translate(view.width / 2.0, view.height / 2.0);
canvas.rotateDegrees(delta / 10);
canvas.rotate(math.PI * delta / 1800);
canvas.drawRect(new Rect.fromLTRB(-100.0, -100.0, 100.0, 100.0),
new Paint()..setARGB(255, 0, 255, 0));
view.picture = canvas.endRecording();
......
......@@ -14,7 +14,7 @@ void beginFrame(double timeStamp) {
double delta = timeStamp - timeBase;
PictureRecorder canvas = new PictureRecorder(view.width, view.height);
canvas.translate(view.width / 2.0, view.height / 2.0);
canvas.rotateDegrees(delta / 10);
canvas.rotate(math.PI * delta / 1800);
canvas.drawRect(new Rect.fromLTRB(-100.0, -100.0, 100.0, 100.0),
new Paint()..setARGB(255, 0, 255, 0));
......
......@@ -46,8 +46,8 @@ class TestDisplayList extends RenderObjectDisplayList {
log("scale($sx, $sy)");
}
void rotateDegrees(double degrees) {
log("rotateDegrees($degrees)");
void rotate(double radians) {
log("rotate($radians)");
}
void skew(double sx, double sy) {
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册