Skip to content

Commit 9459760

Browse files
committed
Documentation Review #2
* Review, edit and rewrite documentation for all the nodes and remaining files of the API.
1 parent eeb53aa commit 9459760

39 files changed

+585
-820
lines changed

lib/src/api/custom_component.dart

Lines changed: 11 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -12,20 +12,19 @@ import 'utils.dart';
1212
part 'custom_component.g.dart';
1313

1414
/// A model to hold custom component data.
15-
/// [width] and [height] represents the containing rect size.
1615
@JsonSerializable()
1716
class CustomComponent with EquatableMixin, SerializableMixin {
1817
/// Unique identifier for the component.
1918
final String id;
2019

21-
/// Name of the component visible in the editor.
20+
/// Name of the component.
2221
final String name;
2322

24-
/// Node data of the component. This is the data that will be used to
25-
/// render the component.
23+
/// Node data of the component. This is the data that is used to render the
24+
/// component.
2625
final ComponentData data;
2726

28-
/// Date & time when the component was created.
27+
/// Date and time when the component was created.
2928
@JsonKey(fromJson: jsonToDate, toJson: dateToJson)
3029
final DateTime createdAt;
3130

@@ -55,8 +54,7 @@ class CustomComponent with EquatableMixin, SerializableMixin {
5554
blurhash,
5655
];
5756

58-
/// Allows to create a new instance of this class from existing one with
59-
/// some fields changed.
57+
/// Duplicate this [CustomComponent] instance with the given data overrides.
6058
CustomComponent copyWith({
6159
String? id,
6260
String? name,
@@ -83,7 +81,7 @@ class CustomComponent with EquatableMixin, SerializableMixin {
8381
Map toJson() => _$CustomComponentToJson(this);
8482
}
8583

86-
/// Holds node data and containing rect size data for a component.
84+
/// Holds component's node data and containing rect size data.
8785
@JsonSerializable()
8886
class ComponentData with EquatableMixin, SerializableMixin {
8987
/// Width of the containing rect for [nodes].
@@ -92,12 +90,12 @@ class ComponentData with EquatableMixin, SerializableMixin {
9290
/// Height of the containing rect for [nodes].
9391
final double height;
9492

95-
/// JSON data of all the nodes for the component where key is the ID of the
96-
/// node and value is actual node JSON that can be used to recreate a
97-
/// [BaseNode] instance using fromJson constructors.
93+
/// JSON data of all the nodes of the component where key is the ID of the
94+
/// node and value is actual node JSON that is used to recreate a [BaseNode]
95+
/// instance.
9896
final Map<String, dynamic> nodes;
9997

100-
/// Returns containing rect for the component.
98+
/// Returns containing rect of the component.
10199
RectC get rect => RectC.fromLTWH(0, 0, width, height);
102100

103101
/// Default constructor to create new instances.
@@ -119,8 +117,7 @@ class ComponentData with EquatableMixin, SerializableMixin {
119117
factory ComponentData.fromJson(Map<String, dynamic> json) =>
120118
_$ComponentDataFromJson(json);
121119

122-
/// Allows to create a new instance of this class from existing one with
123-
/// some fields changed.
120+
/// Duplicate this [ComponentData] instance with the given data overrides.
124121
ComponentData copyWith({
125122
double? width,
126123
double? height,

lib/src/api/math_helper.dart

Lines changed: 28 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -8,32 +8,32 @@ import 'package:vector_math/vector_math.dart';
88

99
import 'models/models.dart';
1010

11-
/// Calculates the cosine of [degrees] in degrees
11+
/// Calculates the cosine of [degrees] in degrees.
1212
double cosDeg(int degrees) => cos(degrees * pi / 180);
1313

14-
/// Calculates the cosine of [radians] in radians
14+
/// Calculates the cosine of [radians] in radians.
1515
double cosRad(double radians) => cos(radians);
1616

17-
///calculates the sine of [degrees] in degrees
17+
/// Calculates the sine of [degrees] in degrees.
1818
double sinDeg(int degrees) => sin(degrees * pi / 180);
1919

20-
///calculates the sine of [radians] in radians
20+
/// Calculates the sine of [radians] in radians.
2121
double sinRad(double radians) => sin(radians);
2222

23-
/// Convert [a] degrees to radians.
23+
/// Converts [a] degrees to radians.
2424
double deg2rad(double a) => a * pi / 180;
2525

26-
/// Normalize [value] between [start] and [end].
26+
/// Normalizes [value] between [start] and [end].
2727
num 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].
3838
Vec 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.
6561
Vec 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.
9288
List<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].
105101
Vec 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.
116112
Vec 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.
141137
Vec 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.
159155
SizeC 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.
176173
RectC 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.
210207
Vec? 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.
233230
Vec? intersectionBetweenLineAndRect(Vec inner, Vec outer, RectC rect) {
234231
final Vec topLeft = rect.topLeft;
235232
final Vec topRight = rect.topRight;

0 commit comments

Comments
 (0)