@@ -3,84 +3,86 @@ import 'dart:math' as math;
3
3
/// Data represenation of point located on map instance
4
4
/// where [x] is horizontal and [y] is vertical pixel value
5
5
class CustomPoint <T extends num > extends math.Point <T > {
6
- const CustomPoint (num x, num y) : super (x as T , y as T );
6
+ const CustomPoint (super .x, super .y );
7
7
8
- /// Create new [CustomPoint] whose [x] and [y] values are divided by [factor]
9
- CustomPoint <T > operator / (num /*T|int*/ factor) {
10
- return CustomPoint <T >(x / factor, y / factor);
8
+ /// Create new [CustomPoint] where [x] and [y] values are added to [other]
9
+ /// point [x] and [y] values
10
+ @override
11
+ CustomPoint <T > operator + (math.Point other) {
12
+ return CustomPoint <T >((x + other.x) as T , (y + other.y) as T );
11
13
}
12
14
13
- /// Create new [CustomPoint] whose [x] and [y] values are rounded up
14
- /// to int
15
- CustomPoint <T > ceil () {
16
- return CustomPoint (x.ceil (), y.ceil ());
15
+ /// Create new [CustomPoint] where [x] and [y] values are subtracted from
16
+ /// [other] point [x] and [y] values
17
+ @override
18
+ CustomPoint <T > operator - (math.Point other) {
19
+ return CustomPoint <T >((x - other.x) as T , (y - other.y) as T );
17
20
}
18
21
19
- /// Create new [CustomPoint] whose [x] and [y] values are rounded down
20
- /// to int
21
- CustomPoint <T > floor ( ) {
22
- return CustomPoint <T >(x. floor (), y. floor () );
22
+ /// Create new [CustomPoint] where [x] and [y] values are scaled by [point]
23
+ /// values
24
+ CustomPoint <T > scaleBy ( CustomPoint < T > point ) {
25
+ return CustomPoint <T >((x * point.x) as T , (y * point.y) as T );
23
26
}
24
27
25
- /// Create new [CustomPoint] whose [x] and [y] values are divided by
26
- /// other [point] values
27
- CustomPoint <T > unscaleBy (CustomPoint <T > point) {
28
- return CustomPoint <T >(x / point.x, y / point.y);
28
+ /// Create new [CustomPoint] whose [x] and [y] values are divided by other
29
+ /// [point] values
30
+ CustomPoint <double > unscaleBy (CustomPoint <T > point) {
31
+ return CustomPoint <double >(x / point.x, y / point.y);
29
32
}
30
33
31
- /// Create new [CustomPoint] where [other] point values [x] and [y] are added
34
+ /// Create new [CustomPoint] where [x] and [y] values are multiplied by
35
+ /// [factor]
32
36
@override
33
- CustomPoint <T > operator + (math. Point < T > other ) {
34
- return CustomPoint <T >(x + other.x, y + other.y );
37
+ CustomPoint <T > operator * ( num factor ) {
38
+ return CustomPoint <T >((x * factor) as T , (y * factor) as T );
35
39
}
36
40
37
- /// Create new [CustomPoint] where [x] and [y] values are subtracted from
38
- /// [other] point [x] and [y] values
39
- @override
40
- CustomPoint <T > operator - (math.Point <T > other) {
41
- return CustomPoint <T >(x - other.x, y - other.y);
41
+ /// Create new [CustomPoint] where [x] and [y] values are divided by [factor]
42
+ CustomPoint <T > operator / (num factor) {
43
+ return CustomPoint <T >((x / factor) as T , (y / factor) as T );
42
44
}
43
45
44
- /// Create new [CustomPoint] where [x] and [y] are multiplied by [factor]
45
- @override
46
- CustomPoint <T > operator * (num /*T|int*/ factor) {
47
- return CustomPoint <T >((x * factor), (y * factor));
48
- }
49
-
50
- /// Create new [CustomPoint] where [x] and [y] are scaled by [point] values
51
- CustomPoint scaleBy (CustomPoint point) {
52
- return CustomPoint (x * point.x, y * point.y);
46
+ /// Create new [CustomPoint] where [x] and [y] is rounded to int
47
+ CustomPoint <int > round () {
48
+ return CustomPoint <int >(x.round (), y.round ());
53
49
}
54
50
55
- /// Create new [CustomPoint] where [x] and [y] is rounded to int
56
- CustomPoint round () {
57
- final x = this .x is double ? this .x.round () : this .x;
58
- final y = this .y is double ? this .y.round () : this .y;
59
- return CustomPoint (x, y);
51
+ /// Create new [CustomPoint] where [x] and [y] values are rounded up to int
52
+ CustomPoint <int > ceil () {
53
+ return CustomPoint <int >(x.ceil (), y.ceil ());
60
54
}
61
55
62
- /// Create new [CustomPoint] with [x] and [y] multiplied by [n]
63
- CustomPoint multiplyBy ( num n ) {
64
- return CustomPoint (x * n , y * n );
56
+ /// Create new [CustomPoint] where [x] and [y] values are rounded down to int
57
+ CustomPoint < int > floor ( ) {
58
+ return CustomPoint < int >(x. floor () , y. floor () );
65
59
}
66
60
67
61
/// Create new [CustomPoint] whose [x] and [y] values are rotated by [radians]
68
62
/// in clockwise fashion
69
- CustomPoint rotate (num radians) {
63
+ CustomPoint < double > rotate (num radians) {
70
64
if (radians != 0.0 ) {
71
65
final cos = math.cos (radians);
72
66
final sin = math.sin (radians);
73
67
final nx = (cos * x) + (sin * y);
74
68
final ny = (cos * y) - (sin * x);
75
69
76
- return CustomPoint (nx, ny);
70
+ return CustomPoint < double > (nx, ny);
77
71
}
78
72
79
- return this ;
73
+ return CustomPoint (x. toDouble (), y. toDouble ()) ;
80
74
}
81
75
82
- CustomPoint <U > cast <U extends num >() => CustomPoint <U >(x as U , y as U );
76
+ CustomPoint <int > toIntPoint () => CustomPoint <int >(x.toInt (), y.toInt ());
77
+
78
+ CustomPoint <double > toDoublePoint () =>
79
+ CustomPoint <double >(x.toDouble (), y.toDouble ());
83
80
84
81
@override
85
82
String toString () => 'CustomPoint ($x , $y )' ;
83
+
84
+ /// Create new [CustomPoint] with [x] and [y] multiplied by [n]
85
+ CustomPoint <T > multiplyBy (num n) {
86
+ return this * n;
87
+ }
86
88
}
0 commit comments