leftiness / hex_math

MIT License
4 stars 1 forks source link

Consider making some newtype structs #77

Open leftiness opened 7 years ago

leftiness commented 7 years ago

For example:

rotate(Point(1, 2, 5), Point(0, 0, 0), 2);
travel(Point(1, 2, 5), Direction::East, 5);

With newtypes:

rotate(Point(1, 2, 5), Point(0, 0, 0), Rotations(2));
travel(Point(1, 2, 5), Direction::East, Distance(5));

It gets rid of the magic number problem. I mean... I've already kind of made it better by accepting a Point struct and a Direction enum. It could be better.

You can take it further. Not sure if it's necessarily good:

rotate(Point(1, 2, 5), Around(Point(0, 0, 0)), Rotations(2));

It gives those magic numbers context in exchange for making them more verbose. You explicitly don't want to impl from()/etc because you want it to keep that verbosity.

leftiness commented 7 years ago

Related #66, #67. Kind of got tedious as a result of using Wall::Strength(u32) instead of just Prism(point, 1, 0, 0, 0).

leftiness commented 7 years ago

Thoughts. Ties into #9.

Point(1, 2, 5).rotate(Point(0, 0, 0), 2);
Point(1, 2, 5).rotate(Around(Point(0, 0, 0), Rotations(2));
Point(1, 2, 5).rotate_around(Point(0, 0, 0)).times(2);