Adding a rotate method to Position and a drawWhere method to utils

This commit is contained in:
Luan Nico
2017-12-30 21:59:45 -02:00
parent fbaec30724
commit 5eee726d92
2 changed files with 16 additions and 0 deletions

View File

@ -22,4 +22,12 @@ class Position {
double length() {
return math.sqrt(math.pow(this.x, 2) + math.pow(this.y, 2));
}
Position rotate(double angle) {
double nx = math.cos(angle) * this.x - math.sin(angle) * this.y;
double ny = math.sin(angle) * this.x + math.cos(angle) * this.y;
this.x = nx;
this.y = ny;
return this;
}
}

View File

@ -5,6 +5,8 @@ import 'package:flutter/gestures.dart';
import 'package:flutter/material.dart' as material;
import 'package:flutter/services.dart';
import 'position.dart';
class Util {
void fullScreen() {
SystemChrome.setEnabledSystemUIOverlays([]);
@ -46,4 +48,10 @@ class Util {
}
});
}
void drawWhere(Canvas c, Position p, void Function(Canvas) fn) {
c.translate(p.x, p.y);
fn(c);
c.translate(-p.x, -p.y);
}
}