it would be great to be able to multiply an ofRectangle by and int or float, as in GLSL or glm.
example:
float scale = 2.0;
fbo.draw(rect * scale);
and be able to access position or dimensions of a rectangle directly as a glm::vec2
example:
ofRectangle rect = ofRectangle(10,10,240,20);
rect.xy += glm::vec2(50,50);
glm::vec2 dimensions = rect.wh;
For scale, it seems reasonable that we would use operator*() for scale, but I think at some point we couldn't decide between scaling from the corner or scaling from the center, so we just left the named methods.
For position, we already have
ofRectangle rect;
rect += glm::vec3(50, 50, 0);
For some reason that has been discussed in the past and is probably lost to history (or github issue trackers, ofRectangle is still kind of 3d ... We should add an operator+(glm::vec2).
I still believe we should remove the z-component because most methods (like getArea(), isInside(), etc only make sense for a 2-d rectangle. Also, there is just width and height :|)
I would definitely support a glm::vec2 getSize() const method. We already have a setSize(float x, float, y) method. So why not a getSize(). Largely because for some reason we have resisted a dedicated ofSize typedef as it seems most people just use a glm::vec2/3 for sizes.
super. just as a curiosity @bakercp do you know if ofPoint will be phased out?
Just solving some problems today I've wondered about an ofColor glm::vec3 constructor too.
A rectangle is 2D! However it can exist in 3D space. (Eg rotated on a 3D axis. Maybe add ofCuboid and ofCuboid.fromRectangle?
I suspect that ofPoint will continue to be an alias for ofVec3f for a while. I've personally never used it or taught it because it's ambiguous (IMHO). I teach glm::vec2 / glm::vec3.
Also, just noticed that we already have both:
/// \brief Returns a new ofRectangle where the x and y positions of the
/// rectangle are offset by the (x, y) coordinates of the glm::vec3.
/// \param p The point to translate.
/// \returns The translated ofRectangle.
ofRectangle operator + (const glm::vec3& p);
ofRectangle operator + (const glm::vec2& p);
/// \brief Returns a new ofRectangle where the x and y-positions of the
/// rectangle are offset by the (x, y) coordinates of the glm::vec3.
/// \param p The point to translate.
/// \returns The translated ofRectangle.
ofRectangle operator - (const glm::vec3& p);
ofRectangle operator - (const glm::vec2& p);
There are already warnings all over the place in ofRectangle about position being glm::vec3 rather than glm::vec2.
So you can actually already do
ofRectangle rect = ofRectangle(10,10,240,20);
rect.position += glm::vec2(50,50);
// or
rect += glm::vec2(50,50);
I am a fairly new user and was using ofPoint. Can I assume OF has the swizzling implemented to get vec2.x or is that something you need to do yourself?
you also can do rect.pos += v.
I'm going to close this since it's not going to be implemented but feel free to keep discussing about it if you think there's any other issues with the current implementation. for questions regarding other topics please use the forum
Most helpful comment
I suspect that
ofPointwill continue to be an alias forofVec3ffor a while. I've personally never used it or taught it because it's ambiguous (IMHO). I teachglm::vec2/glm::vec3.Also, just noticed that we already have both:
There are already warnings all over the place in ofRectangle about position being
glm::vec3rather thanglm::vec2.So you can actually already do