#1229 Add some mathematical methods

Merged
herby merged 4 commits from stevenremot/add-math into amber/master 6 years ago

When I ported a game from Pharo to Amber, I lacked some features that I had to reimplement on my side. I'm merging back to upstream everything I can in this PR.

Every method I added has a sunit test associated.

A lot of methods are heavily inspired by Pharo, it's often the exact same implementation. I don't know if I did well or not because it's copy-pasting... Now I don't think Pharo license forbids it, and most of these implementations are straightforward, so...

Here is the list of methods I added:

  • Number

    • min:max:
    • degreesToRadians
    • radiansToDegrees
    • arcTan:
    • between:and:
  • Number class

    • radiansPerDegree (a constant for conversion)
  • Point

    • dotProduct:
    • normal
    • angle
    • normalized
    • r
    • corner:
    • extent:
    • rectangle:
  • Rectangle (new class)

    • corner
    • origin
    • containsPoint:
    • containsRect:
    • printOn:
  • Rectangle class

    • origin:corner:
    • origin:extent:
    • point:point:
When I ported a game from Pharo to Amber, I lacked some features that I had to reimplement on my side. I'm merging back to upstream everything I can in this PR. Every method I added has a sunit test associated. A lot of methods are heavily inspired by Pharo, it's often the exact same implementation. I don't know if I did well or not because it's copy-pasting... Now I don't think Pharo license forbids it, and most of these implementations are straightforward, so... Here is the list of methods I added: * Number + min:max: + degreesToRadians + radiansToDegrees + arcTan: + between:and: * Number class + radiansPerDegree (a constant for conversion) * Point + dotProduct: + normal + angle + normalized + r + corner: + extent: + rectangle: * Rectangle (new class) + corner + origin + containsPoint: + containsRect: + printOn: * Rectangle class + origin:corner: + origin:extent: + point:point:
Herby Vojčík commented 6 years ago
Owner

Also include the API in API-CHANGES, pls.

Also include the API in API-CHANGES, pls.
Herby Vojčík commented 6 years ago
Owner

Re Pharo copy-pasting: Pharo is reference implementation for Amber, there is lot of other who are copypasted from Pharo as well, it is basically the default way to add something (look if Pharo has it and take it).

Re Pharo copy-pasting: Pharo is reference implementation for Amber, there is lot of other who are copypasted from Pharo as well, it is basically the default way to add something (look if Pharo has it and take it).
Steven Rémot commented 6 years ago
Poster

API-CHANGES updated

API-CHANGES updated
Herby Vojčík commented 6 years ago
Owner

You have broken the formatting (your functions were without the space, while ones I got from recompiling do have one).

How did you manage to do that / could you prevent it in the future (I don't know what could cause that, maybe you are using old Amber)?

You have broken the formatting (your functions were without the space, while ones I got from recompiling do have one). How did you manage to do that / could you prevent it in the future (I don't know what could cause that, maybe you are using old Amber)?
Steven Rémot commented 6 years ago
Poster

Duh, sorry about that. It must be because I'm using the amber-cli from node... When I write amber -v it says Welcome to Amber CLI version 0.101.0 (Amber 0.18.5, NodeJS 6.11.0).. I tried to update it but apparently it's the last version. Am I supposed to directly use some command in the git repository?

Duh, sorry about that. It must be because I'm using the amber-cli from node... When I write `amber -v` it says `Welcome to Amber CLI version 0.101.0 (Amber 0.18.5, NodeJS 6.11.0).`. I tried to update it but apparently it's the last version. Am I supposed to directly use some command in the git repository?
Steven Rémot commented 6 years ago
Poster

I may have missed the last step of the contributing guide that says to run grunt before starting to dev...

I may have missed the last step of the contributing guide that says to run `grunt` before starting to dev...
Herby Vojčík commented 6 years ago
Owner

Mine shows the same (except different node version). But that should not matter at all. CLI is not using its internal Amber, it uses project's one.

This is actually strange, b/c the methods were definitely compiled by 0.19.0 compiler (hacing both self and $self in compiled .js), and the only instances of 'wrong' formatting was in the added methods, but not in ones there were there already.

Anyway, I do not use cli unless needed (which is only in edge cases when upgrading code format). But regardless, cli produces the same format as IDE. It is really mysterious to me how come your commits actually had those functions you added without space after fn: function piece...

Mine shows the same (except different node version). But that should not matter at all. CLI is not using its internal Amber, it uses project's one. This is actually strange, b/c the methods were definitely compiled by 0.19.0 compiler (hacing both `self` and `$self` in compiled .js), and the only instances of 'wrong' formatting was in the added methods, but not in ones there were there already. Anyway, I do not use cli unless needed (which is only in edge cases when upgrading code format). But regardless, cli produces the same format as IDE. It is really mysterious to me how come your commits actually had those functions you added without space after `fn: function` piece...
Herby Vojčík commented 6 years ago
Owner

Anyway, should you want to be sure, running Compiler recompileAll and then committing the package(s) you worked on and reloading; or running grunt from CLI, should recompile things (the former is better as it saves both .st and .js files in normalized format, the latter only produces .js from .st). Then, git diffing is your friend to see if something was messed up or everythihg is ok.

Anyway, should you want to be sure, running `Compiler recompileAll` and then committing the package(s) you worked on and reloading; or running `grunt` from CLI, should recompile things (the former is better as it saves both .st and .js files in normalized format, the latter only produces .js from .st). Then, git diffing is your friend to see if something was messed up or everythihg is ok.
Steven Rémot commented 6 years ago
Poster

Thanks for the explanation, I will be sure to recompile next time

Thanks for the explanation, I will be sure to recompile next time
Herby Vojčík commented 6 years ago
Owner

Strange thing is it should actually not be needed. It just compiles every method again, they should be correct when compiled the first time. I really don't know what happened that only the new methods were different. It's actually a mystery of a kind.

I tend to do it mainly as a test to see if I did not touch something when I do changes to deep Amber, like to the compiler.

But, yeah, it's good to have it in the toolset.

Strange thing is it should actually not be needed. It just compiles every method again, they should be correct when compiled the first time. I really don't know what happened that only the new methods were different. It's actually a mystery of a kind. I tend to do it mainly as a test to see if I did not touch something when I do changes to deep Amber, like to the compiler. But, yeah, it's good to have it in the toolset.
Herby Vojčík commented 6 years ago
Owner

@stevenremot Pls add yourself to the CONTRIBUTORS file in another PR. Thanks.

@stevenremot Pls add yourself to the CONTRIBUTORS file in another PR. Thanks.
Steven Rémot commented 6 years ago
Poster

Got it! I may not be able to do it before a few weeks but I keep it in my todo list

Got it! I may not be able to do it before a few weeks but I keep it in my todo list
This pull request has been merged successfully!
Sign in to join this conversation.
No Label
No Milestone
No assignee
2 Participants
Loading...
Cancel
Save
There is no content yet.