Welcome, Guest. Please login or register. Did you miss your activation email?

Show Posts

This section allows you to view all posts made by this member. Note that you can only see posts made in areas you currently have access to.


Messages - TedLyngmo

Pages: [1]
1
I think it could make sense to add something like this.

Great! I just made my first PR https://github.com/SFML/SFML/pull/2536 and hope I didn't miss anything.

  • Due to the complexity, we'd probably need to cache the calculation

Yes, either that or document the complexity and suggest only calling it once after a Shape has been defined. A user wanting to call it many times could then cache the result.

  • The result should probably be in local coordinate space

Yes. It would use the data in std::vector<Vector2f> ConvexShape::m_points; as-is and return the untransformed value.

  • I personally would prefer getGeometricCenter() over Centroid

I'm perfectly fine with that too  :)

2
> How do you define this in the general case for all polygons?

My plan was to do it using the code I shared in the link. For some (most) sf::Shape decendants I'm assuming shortcuts can be made.

 The actual algorithms used in the different classes is perhaps less important than if the function would be a nice addition to the library or not.

3
Hi! I wonder if there would be any interest to add

virtual Vector2f sf::Shape::getCentroid() const = 0;

I found myself wanting this function when I created polygons using sf::ConvexShape and I wanted the rotation point to be "in the middle" of the polygon so to speak.

I've now inherited sf::ConvexShape, as shown here https://stackoverflow.com/a/76079129/7582247, to do it automatically, but I think it would be useful to support it out of the box.

I can implement it and do a pull request if the idea isn't rejected.

Pages: [1]