-
Notifications
You must be signed in to change notification settings - Fork 3
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Feat: Angle parsing #6
base: main
Are you sure you want to change the base?
Conversation
Upgrade min dart sdk version to `2.17.0` for convenient use of enum Add `AngleType` enum to handle angle properly Update `README.md` with usage of parse angles Add unit test for angle parsing
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks for your contribution! I added a few comments, but all in all this looks good.
Remove unnecessary file `angle_format.dart`
Reformat `Angle.parse` constructor
After locally checking out the code, I have some more issues with your code.
|
Thanks to your comment. To be honest, I agree with you. But I couldn't think of a better way than the current implementation. It's certainly possible to implement it using a switch statement, but I felt like The Also, at the time I wrote it, I thought it would be nice to specify the units via the second argument to In conclusion, I think it would be better to do it as a conditional statement as you suggest. If I were to write it, I think it would look something like below. But I am not certain that below code is concise and clean. Could you tell me if you have a better idea? factory Angle.parse(String string) {
int type = 0; // 0=degrees, 1=radians, 2=gradians
if (string.contains(r"RegExp for degrees")) {
type = 0;
} else if (string.contains(r"RegExp for radians")) {
type = 1;
} // ...
switch(type) {
case 0:
// Parse string as degrees
return Angle.degrees(value);
// ... other cases
}
} After I modifed the Thank you for reading this. |
Could you explain why Or is there anything that I missed? |
if ( /* Try to match regex for degrees */ ) {
// Parse and return degrees
}
else if ( /* Try to match regex for multiples of PI */ ) {
// Parse and return
}
// ...
|
# Conflicts: # lib/angle_unit.dart
I understand. I changed I also modified it to not parse cases like In the unit tests, I added cases like Is there anything else that I need to work on or that I still missed? |
Thank you for your convenient package.
I added feature about parse strings to
Angle
instance.It parses degrees, radians, and gradians using RegExp. For example,
Angle.parse("360°")
would be parsed toAngle
that_storage
is0
. You can find more examples inREADME.md
on my PR.And I upgraded min dart sdk version to
2.17
for conveninent use of enums. (previously2.12
) It's because these features usesenum
to parse strings easilty.Also, I created unit test about parsing strings.
Could you merge this PR and release new version of package?
Thanks,