From 5eee726d92abf6b60c70eebc3258e7253cb1d139 Mon Sep 17 00:00:00 2001 From: Luan Nico Date: Sat, 30 Dec 2017 21:59:45 -0200 Subject: [PATCH] Adding a rotate method to Position and a drawWhere method to utils --- lib/position.dart | 8 ++++++++ lib/util.dart | 8 ++++++++ 2 files changed, 16 insertions(+) diff --git a/lib/position.dart b/lib/position.dart index 4f3244426..482fd0d03 100644 --- a/lib/position.dart +++ b/lib/position.dart @@ -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; + } } diff --git a/lib/util.dart b/lib/util.dart index 40e750ccb..77523d780 100644 --- a/lib/util.dart +++ b/lib/util.dart @@ -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); + } }