Rectangle: please add withCentreY and withCentreX

It’d be very useful for layout :slight_smile:
Thank you!


withHeightKeepingCentre and withWidthKeepingCentre would be useful too.

1 Like

Yes 100%. Do those too!

Would be nice to have these sorts of things as free functions IMO, then they could be overloaded to work with other types like Component and Path.

1 Like

That free function is called juce::jmap :wink:

I agree with each of the requested ones they are good to have. At the same time the Rectangle interface becomes quite huge.

// withCentreX
rect.withCentre ({x, rect.getCentreY()});

I don’t know if the rect.getCentreY() call gets optimised away, there is a fair chance. But there might be a case of optimisation to add the individual ones…

1 Like

The interface already is quite huge. But the only shitty bits are trying to work out which functions keep the size the same, and which ones keep the other edge in the same position. I think these two additions would be really handy.

Free functions sound like a good idea, but don’t play nicely with autocomplete when you want to dig around in the IDE to find the operation on the rectangle :slight_smile:

1 Like

good suggestions. i also often think in terms of the center of components. one thing i often do there is getting the max cuboid of some rectangle to set the bounds of a component, because that also creates a component that aligns in the center of the defined area, but just with smaller bounds if possible

What on earth is that? :slight_smile:

quadratic rectangle (green) inside of some rectangle (black)

Yeah - that looks like something we do. Although still not sure what a cuboid is :slight_smile: But finding the max square centred in a rectangle is a regular thing!

i’m not sure if cuboid is the right term actually. in germany we call it quader and said that’s called a cuboid lol

Well, Quader is just like a cuboid a three dimensional thing though…

oh, thought that was 2d. but then… what’s a 2d cuboid? (in german as well as english lol)

Hehe, how about rectangle (Rechteck)? As in like a quadrat (same word as in German) but with different lengths…
I think you were looking for enclosed quadrat with the common centre as the original…

Quadrat - square. ok that makes sense, yes

1 Like

And I didn’t find square lol. I was checking and they say quadrat exists in English too, but it felt wrong to me… thanks… sometimes the brain doesn’t work :slight_smile:

Yeah, I’ve never heard anyone use quadrat, apparently it means…


each of a number of small areas of habitat, typically of one square metre, selected at random to act as samples for assessing the local distribution of plants or animals.


(in letterpress printing) a small block of metal, lower than the face of the type, inserted to fill up short lines or adjust spacing.

The common terms we got taught at school are here :slight_smile: