# Rectangle: please add withCentreY and withCentreX

**URL:** <https://forum.juce.com/t/rectangle-please-add-withcentrey-and-withcentrex/48281>\
**Category:** General JUCE discussion\
**Created:** [October 16, 2021, 8:56pm UTC](https://forum.juce.com/t/rectangle-please-add-withcentrey-and-withcentrex/48281 "2021-10-16T20:56:31Z")\
**Posts on this page:** 18\
**Page:** 1

<div class="post-metadata">

**Author:** ![jimc](https://sea2.discourse-cdn.com/flex026/user_avatar/forum.juce.com/jimc/32/16067_2.png) [@jimc](https://forum.juce.com/u/jimc)\
**Post date:** [October 16, 2021, 8:56pm UTC](https://forum.juce.com/t/rectangle-please-add-withcentrey-and-withcentrex/48281/1 "2021-10-16T20:56:31Z")

</div>

It’d be very useful for layout 🙂  
Thank you!

---

<div class="post-metadata">

**Author:** ![lalala](https://sea2.discourse-cdn.com/flex026/user_avatar/forum.juce.com/lalala/32/8577_2.png) [@lalala](https://forum.juce.com/u/lalala)\
**Post date:** [October 17, 2021, 7:35am UTC](https://forum.juce.com/t/rectangle-please-add-withcentrey-and-withcentrex/48281/2 "2021-10-17T07:35:03Z")

</div>

`withHeightKeepingCentre` and `withWidthKeepingCentre` would be useful too.

---

<div class="post-metadata">

**Author:** ![jimc](https://sea2.discourse-cdn.com/flex026/user_avatar/forum.juce.com/jimc/32/16067_2.png) [@jimc](https://forum.juce.com/u/jimc)\
**Post date:** [October 17, 2021, 7:52am UTC](https://forum.juce.com/t/rectangle-please-add-withcentrey-and-withcentrex/48281/3 "2021-10-17T07:52:44Z")

</div>

Yes 100%. Do those too!

---

<div class="post-metadata">

**Author:** ![ImJimmi](https://sea2.discourse-cdn.com/flex026/user_avatar/forum.juce.com/imjimmi/32/10843_2.png) [@ImJimmi](https://forum.juce.com/u/ImJimmi)\
**Post date:** [October 17, 2021, 11:23am UTC](https://forum.juce.com/t/rectangle-please-add-withcentrey-and-withcentrex/48281/4 "2021-10-17T11:23:37Z")

</div>

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.

---

<div class="post-metadata">

**Author:** ![daniel](https://sea2.discourse-cdn.com/flex026/user_avatar/forum.juce.com/daniel/32/790_2.png) [@daniel](https://forum.juce.com/u/daniel)\
**Post date:** [October 17, 2021, 1:28pm UTC](https://forum.juce.com/t/rectangle-please-add-withcentrey-and-withcentrex/48281/5 "2021-10-17T13:28:05Z")

</div>

That free function is called juce::jmap 😉

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

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

```

etc.  
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…

---

<div class="post-metadata">

**Author:** ![jimc](https://sea2.discourse-cdn.com/flex026/user_avatar/forum.juce.com/jimc/32/16067_2.png) [@jimc](https://forum.juce.com/u/jimc)\
**Post date:** [October 17, 2021, 4:15pm UTC](https://forum.juce.com/t/rectangle-please-add-withcentrey-and-withcentrex/48281/6 "2021-10-17T16:15:09Z")

</div>

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 🙂

---

<div class="post-metadata">

**Author:** ![Mrugalla](https://sea2.discourse-cdn.com/flex026/user_avatar/forum.juce.com/mrugalla/32/13092_2.png) [@Mrugalla](https://forum.juce.com/u/Mrugalla)\
**Post date:** [October 17, 2021, 4:34pm UTC](https://forum.juce.com/t/rectangle-please-add-withcentrey-and-withcentrex/48281/7 "2021-10-17T16:34:51Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![jimc](https://sea2.discourse-cdn.com/flex026/user_avatar/forum.juce.com/jimc/32/16067_2.png) [@jimc](https://forum.juce.com/u/jimc)\
**Post date:** [October 17, 2021, 4:45pm UTC](https://forum.juce.com/t/rectangle-please-add-withcentrey-and-withcentrex/48281/8 "2021-10-17T16:45:08Z")

</div>

> [@Mrugalla](#):
>
> max cuboid

What on earth is that? 🙂

---

<div class="post-metadata">

**Author:** ![Mrugalla](https://sea2.discourse-cdn.com/flex026/user_avatar/forum.juce.com/mrugalla/32/13092_2.png) [@Mrugalla](https://forum.juce.com/u/Mrugalla)\
**Post date:** [October 17, 2021, 5:40pm UTC](https://forum.juce.com/t/rectangle-please-add-withcentrey-and-withcentrex/48281/9 "2021-10-17T17:40:51Z")

</div>

![image](https://us1.discourse-cdn.com/flex026/uploads/juce/original/2X/2/24b09145af125498d9d9d6d6bb6ec3631a9fa3b0.png)  
quadratic rectangle (green) inside of some rectangle (black)

---

<div class="post-metadata">

**Author:** ![jimc](https://sea2.discourse-cdn.com/flex026/user_avatar/forum.juce.com/jimc/32/16067_2.png) [@jimc](https://forum.juce.com/u/jimc)\
**Post date:** [October 17, 2021, 6:25pm UTC](https://forum.juce.com/t/rectangle-please-add-withcentrey-and-withcentrex/48281/10 "2021-10-17T18:25:57Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![Mrugalla](https://sea2.discourse-cdn.com/flex026/user_avatar/forum.juce.com/mrugalla/32/13092_2.png) [@Mrugalla](https://forum.juce.com/u/Mrugalla)\
**Post date:** [October 17, 2021, 6:45pm UTC](https://forum.juce.com/t/rectangle-please-add-withcentrey-and-withcentrex/48281/11 "2021-10-17T18:45:24Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![daniel](https://sea2.discourse-cdn.com/flex026/user_avatar/forum.juce.com/daniel/32/790_2.png) [@daniel](https://forum.juce.com/u/daniel)\
**Post date:** [October 17, 2021, 6:52pm UTC](https://forum.juce.com/t/rectangle-please-add-withcentrey-and-withcentrex/48281/12 "2021-10-17T18:52:54Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![Mrugalla](https://sea2.discourse-cdn.com/flex026/user_avatar/forum.juce.com/mrugalla/32/13092_2.png) [@Mrugalla](https://forum.juce.com/u/Mrugalla)\
**Post date:** [October 17, 2021, 6:59pm UTC](https://forum.juce.com/t/rectangle-please-add-withcentrey-and-withcentrex/48281/13 "2021-10-17T18:59:20Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![daniel](https://sea2.discourse-cdn.com/flex026/user_avatar/forum.juce.com/daniel/32/790_2.png) [@daniel](https://forum.juce.com/u/daniel)\
**Post date:** [October 17, 2021, 7:03pm UTC](https://forum.juce.com/t/rectangle-please-add-withcentrey-and-withcentrex/48281/14 "2021-10-17T19:03:03Z")

</div>

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…

---

<div class="post-metadata">

**Author:** ![Mrugalla](https://sea2.discourse-cdn.com/flex026/user_avatar/forum.juce.com/mrugalla/32/13092_2.png) [@Mrugalla](https://forum.juce.com/u/Mrugalla)\
**Post date:** [October 17, 2021, 7:06pm UTC](https://forum.juce.com/t/rectangle-please-add-withcentrey-and-withcentrex/48281/15 "2021-10-17T19:06:08Z")

</div>

Quadrat - square. ok that makes sense, yes

---

<div class="post-metadata">

**Author:** ![daniel](https://sea2.discourse-cdn.com/flex026/user_avatar/forum.juce.com/daniel/32/790_2.png) [@daniel](https://forum.juce.com/u/daniel)\
**Post date:** [October 17, 2021, 7:07pm UTC](https://forum.juce.com/t/rectangle-please-add-withcentrey-and-withcentrex/48281/16 "2021-10-17T19:07:45Z")

</div>

And I didn’t find square lol. I was checking [dict.leo.org](http://dict.leo.org) and they say quadrat exists in English too, but it felt wrong to me… thanks… sometimes the brain doesn’t work 🙂

---

<div class="post-metadata">

**Author:** ![jimc](https://sea2.discourse-cdn.com/flex026/user_avatar/forum.juce.com/jimc/32/16067_2.png) [@jimc](https://forum.juce.com/u/jimc)\
**Post date:** [October 18, 2021, 9:10am UTC](https://forum.juce.com/t/rectangle-please-add-withcentrey-and-withcentrex/48281/17 "2021-10-18T09:10:35Z")

</div>

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

> 1. ECOLOGY
> 
> 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.
> 
> 1. 
> 1. 
> 
> PRINTING
> 
> (in letterpress printing) a small block of metal, lower than the face of the type, inserted to fill up short lines or adjust spacing.

---

<div class="post-metadata">

**Author:** ![jimc](https://sea2.discourse-cdn.com/flex026/user_avatar/forum.juce.com/jimc/32/16067_2.png) [@jimc](https://forum.juce.com/u/jimc)\
**Post date:** [October 18, 2021, 9:12am UTC](https://forum.juce.com/t/rectangle-please-add-withcentrey-and-withcentrex/48281/18 "2021-10-18T09:12:43Z")

</div>

The common terms we got taught at school are here 🙂

[https://www.mathsisfun.com/quadrilaterals.html](https://www.mathsisfun.com/quadrilaterals.html)
