@@ -8,32 +8,32 @@ import 'package:vector_math/vector_math.dart';
88
99import 'models/models.dart' ;
1010
11- /// Calculates the cosine of [degrees] in degrees
11+ /// Calculates the cosine of [degrees] in degrees.
1212double cosDeg (int degrees) => cos (degrees * pi / 180 );
1313
14- /// Calculates the cosine of [radians] in radians
14+ /// Calculates the cosine of [radians] in radians.
1515double cosRad (double radians) => cos (radians);
1616
17- ///calculates the sine of [degrees] in degrees
17+ /// Calculates the sine of [degrees] in degrees.
1818double sinDeg (int degrees) => sin (degrees * pi / 180 );
1919
20- ///calculates the sine of [radians] in radians
20+ /// Calculates the sine of [radians] in radians.
2121double sinRad (double radians) => sin (radians);
2222
23- /// Convert [a] degrees to radians.
23+ /// Converts [a] degrees to radians.
2424double deg2rad (double a) => a * pi / 180 ;
2525
26- /// Normalize [value] between [start] and [end] .
26+ /// Normalizes [value] between [start] and [end] .
2727num normalizeToInterval (num value, num start, num end) {
2828 final width = end - start;
2929 final offset = value - start;
3030 final res = (offset - (offset / width).floor () * width) + start;
31- // Since 180 and -180 is the same, we prefer to use 180.
31+ // Since 180 and -180 is the same, 180 is preferred over - 180.
3232 if (res == - 180 ) return 180 ;
3333 return res;
3434}
3535
36- /// Returns an Vec unrotated by [radians] around the center of a rectangle
36+ /// Returns a [ Vec] unrotated by [radians] around the center of a rectangle
3737/// described by [x, y, width, height] .
3838Vec calculateUnrotatedVecFromRotatedVec ({
3939 required double x,
@@ -56,12 +56,8 @@ Vec calculateUnrotatedVecFromRotatedVec({
5656 return Vec (unrotated[0 ], unrotated[1 ]);
5757}
5858
59- /// Returns an Vec rotated by [radians] around the center of a rectangle
60- /// described by [x1, y1, x2, y2] .
61- /// Returns the rotated top left corner of this box.
62- ///
63- /// The returned box is NOT translated inside the parent boxes. It only
64- /// rotates the given box around it's own center point.
59+ /// Returns the top-left corner of a rectangle rotated by [radians] around the
60+ /// center.
6561Vec calculateRotatedBoxTopLeftAroundSelf ({
6662 required double radians,
6763 required double x2,
@@ -87,7 +83,7 @@ Vec calculateRotatedBoxTopLeftAroundSelf({
8783 return Vec (rotated[0 ], rotated[1 ]);
8884}
8985
90- /// Rotates all points in [vector3] by [radians] around [origin]
86+ /// Rotates all points in [vector3] by [radians] around [origin] .
9187/// [vector3] is a flat list of one or more x,y,z triplets.
9288List <double > rotatePointAroundOrigin (
9389 double originX, double originY, double radians, List <double > vector3) {
@@ -100,8 +96,8 @@ List<double> rotatePointAroundOrigin(
10096 return transform.applyToVector3Array (vector3);
10197}
10298
103- /// Rotates a point [point] around [origin] by the given [radians]
104- /// and returns the new coordinates as a [Vec] object
99+ /// Rotates a point [point] around [origin] by the given [radians] and returns
100+ /// the new coordinates as a [Vec] .
105101Vec rotatePointAroundVec (Vec origin, double radians, Vec point) {
106102 final transform = Matrix4 .translationValues (origin.x, origin.y, 0 )
107103 ..rotateZ (radians)
@@ -111,8 +107,8 @@ Vec rotatePointAroundVec(Vec origin, double radians, Vec point) {
111107 return Vec (rotated[0 ], rotated[1 ]);
112108}
113109
114- /// Converts a [global] offset to [parentContext] 's local system, where [parentContext] is
115- /// rotated by [radians] angle.
110+ /// Converts a [global] offset to [parentContext] 's local system, where
111+ /// [parentContext] is rotated by [radians] angle.
116112Vec globalToRotatedLocalVec ({
117113 required double globalX,
118114 required double globalY,
@@ -136,8 +132,8 @@ Vec globalToRotatedLocalVec({
136132 );
137133}
138134
139- /// Converts a [local] offset in [parentContext] 's system, where [parentContext] is
140- /// rotated by [radians] angle, to a global offset.
135+ /// Converts a [local] offset in [parentContext] 's system, where [parentContext]
136+ /// is rotated by [radians] angle, to a global offset.
141137Vec localRotatedVecToGlobalVec ({
142138 required double localX,
143139 required double localY,
@@ -154,8 +150,8 @@ Vec localRotatedVecToGlobalVec({
154150 );
155151}
156152
157- /// Returns the size of the bounding box for a box sized
158- /// [width] , [height] that is rotated by [rotationDegrees] degrees.
153+ /// Returns the size of the bounding box for a box sized [width] , [height] that
154+ /// is rotated by [rotationDegrees] degrees.
159155SizeC getBoundsSizeAfterRotation (
160156 double width, double height, double rotationRad) {
161157 if (rotationRad == 0 ) return SizeC (width, height);
@@ -168,11 +164,12 @@ SizeC getBoundsSizeAfterRotation(
168164 );
169165}
170166
171- /// For a box of size [width] and [height] , rotated by [rotationDegrees] degrees,
172- /// this returns it's bounding box, with top, left offset to [y] and [x] .
167+ /// For a box of size [width] and [height] , rotated by [rotationDegrees]
168+ /// degrees, this returns it's bounding box, with top, left offset to [y] and
169+ /// [x] .
173170///
174- /// The returned box is NOT translated inside the parent boxes. It only
175- /// rotates the given box around it's own center point.
171+ /// The returned box is not translated inside the parent boxes. It only rotates
172+ /// the given box around it's own center point.
176173RectC getRotatedBoundingBoxAroundSelf (
177174 double x,
178175 double y,
@@ -205,8 +202,8 @@ Vec projectPointToLine(Vec p1, Vec p2, Vec toProject) {
205202/// First two vectors [p1] and [p2] are the first line, and the second two
206203/// vectors [p3] and [p4] are the second line.
207204///
208- /// [returns] The point of intersection. IF there is no intersection, then
209- /// the function returns null .
205+ /// Returns the point of intersection. Returns [null] in case of no
206+ /// intersection .
210207Vec ? intersectionBetweenTwoLines (Vec p1, Vec p2, Vec p3, Vec p4) {
211208 final double t =
212209 ((p1.x - p3.x) * (p3.y - p4.y) - (p1.y - p3.y) * (p3.x - p4.x)) /
@@ -228,8 +225,8 @@ Vec? intersectionBetweenTwoLines(Vec p1, Vec p2, Vec p3, Vec p4) {
228225/// The line is denoted by [inner] and [outer] vectors, and the rectangle
229226/// is denoted by [rect] .
230227///
231- /// [returns] The point of intersection. IF there is no intersection, then
232- /// the function returns null .
228+ /// Returns the point of intersection. Returns [null] in case of no
229+ /// intersection .
233230Vec ? intersectionBetweenLineAndRect (Vec inner, Vec outer, RectC rect) {
234231 final Vec topLeft = rect.topLeft;
235232 final Vec topRight = rect.topRight;
0 commit comments