Skip to content

Conversation

pepbos
Copy link
Collaborator

@pepbos pepbos commented Jul 20, 2023

Refactors the cylinder wrapping math.

Still need to iron out some details, so it is more about the overall structure.

@pepbos pepbos requested a review from adamkewley July 20, 2023 07:46
double ATan2OnPositiveRange(const SimTK::Vec2 point)
{
const double angle = std::atan2(point[1], point[0]);
return angle < 0.? angle + c_TAU : angle;
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Reformat: expr ? true : false (space before ?)

return angle < 0.? angle + c_TAU : angle;
}

class Angle final {
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Design vs. usage vary.

  • If the intention is that getValue always returns a value in the range [0..2pi] then the double ctor should enforce the fmod-like behavior, or have a Unsafe_AngleAlreadyKnownToBeInRange tag argument to indicate to downstream code that the caller "knows what they're doing"
  • If the only reason to have the double argument is to facilitate operator+ then you should make the double constructor private and friend Angle operator+(Angle, Angle);, so that the operator is allowed to skip the invariant check (this is what has been done, but I'm guessing the ctor is public for another reason)
  • If any downstream code should be able to provide any value then the ctor should fmod the argument
  • NaN forms a 2nd form of the state (i.e. "bad state"). Ensure that's relevant (e.g. rather than "identity" - 0.0)


class Angle final {
// Construct from angle already on range [0...2pi].
Angle(double angleChecked): _value(angleChecked)
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

explicit

public:
Angle() = default;

Angle(const SimTK::Vec2& point) :
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

explicit (note: this ctor does enforce the [0..2pi] class invariant)

Angle(double angleChecked): _value(angleChecked)
{}

public:
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

public: indentation usually matches class, not the same level as the things under public scope

// wrapping path on a circle.
namespace {

// Struct for holding a generic pair, that differ in the wrapping direction.
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You had better have a very good reason to be using templating, std::function, rvalue semantics (&&), and varadaic templates in one class here.


// Computes for both positive and negative wrapping directions, the tangent
// line path segments.
PositiveAndNegativeRotatingPair<PathSegment<TangentLine>>
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The templating is getting a bit OTT here

const PathSegment<BothTangentLines> tangentLines(path, circleRadius);

// Get one of the possible paths by setting the rotation direction.
auto GetPathSegmentsGivenDirection = [&tangentLines](
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The payoff for std::function, forwarding, etc. did not justify this bit - just compute it and pass it into a simpler struct/class imo.

CircleWrap TakeBestPath(
PositiveAndNegativeRotatingPair<CircleWrap> possibleWrappings)
{
return TakeBestPath(possibleWrappings.positive,
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Formatting

possibleWrappings.negative);
}

// Computes the best wrapping path on a circle.
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Stoppped reading around here - no time

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants