<div dir="ltr">I agree.<div><br><div>The limitations of possible workarounds should be discussed instead in separate threads. Like for example that you aren&#39;t able to add a setter to an existing read-only property by extension which would allow to apply the desired changes in your own modules instead of in CoreGraphics directly.</div></div></div><div class="gmail_extra"><br><div class="gmail_quote">On Wed, Dec 16, 2015 at 6:31 PM, Dave Abrahams via swift-evolution <span dir="ltr">&lt;<a href="mailto:swift-evolution@swift.org" target="_blank">swift-evolution@swift.org</a>&gt;</span> wrote:<br><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"><div style="word-wrap:break-word">I don&#39;t want to shut down a productive conversation, but since this is all about changing the CoreGraphics framework I think this whole discussion may be out-of-scope for swift-evolution.  What does everybody else think?<div><br><div><blockquote type="cite"><div><div class="h5"><div>On Dec 16, 2015, at 6:41 AM, ilya via swift-evolution &lt;<a href="mailto:swift-evolution@swift.org" target="_blank">swift-evolution@swift.org</a>&gt; wrote:</div><br></div></div><div><div><div class="h5"><div style="white-space:pre-wrap">-1 on scale. Basic scale() is not clear whether center or origin is a fixed point. Other scale(...) functions presented here seem too complicated. <br><br>Ditto centerOn()<br><br>aspect is a bad idea as it naturally leads one to comparing floats to each other. Which is very error prone. <br><br>How about we define a getter and setter for center and leave it at that? </div><br><div class="gmail_quote"><div dir="ltr">On Wed, Dec 16, 2015 at 07:28 Kenny Leung via swift-evolution &lt;<a href="mailto:swift-evolution@swift.org" target="_blank">swift-evolution@swift.org</a>&gt; wrote:<br></div><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">I also think that keeping with non-mutable versions of these methods is a lot better at keeping you out of trouble. Here’s the set that I’ve been using for a while:<br>
<br>
extension CGRect {<br>
    public var aspect :CGFloat {get{return width/height}}<br>
    public var isPortrait :Bool {get{return aspect &lt; 1}}<br>
    public var isLandscape :Bool {get{return aspect &gt; 1}}<br>
    public var isSquare :Bool {get{return aspect == 1}}<br>
    public var center :CGPoint {get{return CGPointMake(midX,midY)}}<br>
<br>
    public init(size s:CGSize) {self=CGRectMake(0,0,s.width,s.height)}<br>
    public init(size s:CGSize, centeredOn p:CGPoint) {self=CGRect(size:s).centerOn(p)}<br>
    public init(square s:CGFloat, centeredOn p:CGPoint) {self=CGRectMake(p.x-s/2,p.y-s/2,s,s)}<br>
<br>
    public func centerOn(p :CGPoint) -&gt; CGRect {return CGRectMake(p.x-width/2,p.y-height/2,width,height)}<br>
    public func centerOn(r :CGRect) -&gt; CGRect {return centerOn(r.center)}<br>
    public func scale(s :CGFloat) -&gt; CGRect {return CGRectMake(origin.x,origin.y,width*s,height*s)}<br>
    public func scaleAround(r :CGRect) -&gt; CGFloat {return r.aspect&lt;=self.aspect ? r.height/height : r.width/width}<br>
    public func scaleAndCenterAround(r :CGRect) -&gt; CGRect {return self.scale(self.scaleAround(r)).centerOn(r)}<br>
    public func scaleIn(r :CGRect) -&gt; CGFloat {return r.aspect&lt;=self.aspect ? r.width/width : r.height/height}<br>
    public func scaleAndCenterIn(r :CGRect) -&gt; CGRect {return self.scale(self.scaleIn(r)).centerOn(r)}<br>
}<br>
<br>
-Kenny<br>
<br>
<br>
&gt; On Dec 15, 2015, at 3:11 AM, D. Felipe Torres via swift-evolution &lt;<a href="mailto:swift-evolution@swift.org" target="_blank">swift-evolution@swift.org</a>&gt; wrote:<br>
&gt;<br>
&gt; The problem with making those settable is the ambiguity of it.<br>
&gt;<br>
&gt; Say you increase the value at maxY, should the length or origin.y be increased? should they share the modification and increase both buy half?<br>
&gt;<br>
&gt; It is not clear the intention here.<br>
&gt;<br>
&gt; And then, as David said, this is CoreGraphics API which has to be suggested through Radars and we all know how likely our chances are there.<br>
&gt;<br>
&gt; On Sun, Dec 13, 2015 at 10:55 PM, Jacob Bandes-Storch &lt;<a href="mailto:jtbandes@gmail.com" target="_blank">jtbandes@gmail.com</a>&gt; wrote:<br>
&gt; I still think it might be valuable to pursue setters for all of the currently-read-only convenience properties (minX, midX, maxX, minY, midY, maxY).<br>
&gt;<br>
&gt; Jacob<br>
&gt;<br>
&gt; On Fri, Dec 11, 2015 at 1:17 PM, D. Felipe Torres &lt;<a href="mailto:warorface@gmail.com" target="_blank">warorface@gmail.com</a>&gt; wrote:<br>
&gt; Using the mid properties wouldn&#39;t help much as they are the middle of the bounds (origin + length/2) and because it&#39;s a derived value from two different structures, its not clear which structure you want to modify.<br>
&gt;<br>
&gt; Either way, after thinking more about it, there is too much ambiguity to the details of this. The intent is not always clear and looking into the other functions, they all stand on their own. A CGRect doesn&#39;t have any sense of hierarchy.<br>
&gt;<br>
&gt; It only appears when you have layers/views (and those do have a way of setting the center because the relationship/hierarchy is well defined).<br>
&gt;<br>
&gt; I don&#39;t see any more reason to pursue this proposal.<br>
&gt;<br>
&gt;<br>
&gt; On Fri, Dec 11, 2015 at 7:29 AM, Jacob Bandes-Storch &lt;<a href="mailto:jtbandes@gmail.com" target="_blank">jtbandes@gmail.com</a>&gt; wrote:<br>
&gt; Would it make sense to achieve the same thing by giving midX and midY setters (they currently only have getters)?<br>
&gt;<br>
&gt; I&#39;m don&#39;t think I like the idea of tying down any CGRect extensions to a &quot;parent&quot; rect, but saying &quot;rect.midX = parent.midX&quot; is pretty simple &amp; clear.<br>
&gt;<br>
&gt; Jacob<br>
&gt;<br>
&gt; On Thu, Dec 10, 2015 at 6:17 AM, D. Felipe Torres via swift-evolution &lt;<a href="mailto:swift-evolution@swift.org" target="_blank">swift-evolution@swift.org</a>&gt; wrote:<br>
&gt; One of the task that is performed often is center a frame with respect to it&#39;s parent.<br>
&gt; The code for this is short and simple:<br>
&gt;<br>
&gt; rect.origin.x = (rect.width-parent.width)/2 // or...<br>
&gt; rect.origin.y = (rect.height-parent.height)/2<br>
&gt;<br>
&gt; ## Current Problems<br>
&gt;<br>
&gt; - It is very easy to get it wrong and confuse X or Y and their length associations.<br>
&gt; - Because this code is often found in a layout method, several other rect variables may be defined in the scope which makes it easier to mistake one variable with another if their names are close (and you are used to autocomplete)<br>
&gt; - And finally but most importantly, while the equation here is simple, one must parse it and understand it and is not a very swifty approach.<br>
&gt;<br>
&gt; ##Proposed Additions<br>
&gt;<br>
&gt; 2 (actually 4) extensions in CGGeometry to CGRect:<br>
&gt;<br>
&gt; extension CGRect {<br>
&gt;       public func centerX(parentRect: CGRect) -&gt; CGRect<br>
&gt;       public mutating func centerXInPlace(parentRect: CGRect)<br>
&gt;       public fun centerY(parentRect: CGRect) -&gt; CGRect<br>
&gt;       public mutating func centerYInPlace(parentRect: CGRect)<br>
&gt; }<br>
&gt;<br>
&gt; This extension allows very easily (and verbally) center a rect in respect to a parent.<br>
&gt;<br>
&gt; I&#39;m pretty sure there are other pretty useful extensions that can be added to CGGeometry as well but this one I think is basic and pretty important.<br>
&gt;<br>
&gt; --<br>
&gt; ++++++++++++++++++++++++++<br>
&gt; Diego Torres.<br>
&gt; Web: <a href="http://dtorres.me/" rel="noreferrer" target="_blank">dtorres.me</a><br>
&gt;<br>
&gt; _______________________________________________<br>
&gt; swift-evolution mailing list<br>
&gt; <a href="mailto:swift-evolution@swift.org" target="_blank">swift-evolution@swift.org</a><br>
&gt; <a href="https://lists.swift.org/mailman/listinfo/swift-evolution" rel="noreferrer" target="_blank">https://lists.swift.org/mailman/listinfo/swift-evolution</a><br>
&gt;<br>
&gt;<br>
&gt;<br>
&gt;<br>
&gt;<br>
&gt; --<br>
&gt; ++++++++++++++++++++++++++<br>
&gt; Diego Torres.<br>
&gt; Phone (Mobile Germany): <a href="tel:%2B49%20157%2030070985" value="+4915730070985" target="_blank">+49 157 30070985</a><br>
&gt; Phone (Landline Chile): <a href="tel:%2B56%202%2029790978" value="+56229790978" target="_blank">+56 2 29790978</a><br>
&gt; Web: <a href="http://dtorres.me/" rel="noreferrer" target="_blank">dtorres.me</a><br>
&gt;<br>
&gt;<br>
&gt;<br>
&gt;<br>
&gt; --<br>
&gt; ++++++++++++++++++++++++++<br>
&gt; Diego Torres.<br>
&gt; Phone (Mobile Germany): <a href="tel:%2B49%20157%2030070985" value="+4915730070985" target="_blank">+49 157 30070985</a><br>
&gt; Phone (Landline Chile): <a href="tel:%2B56%202%2029790978" value="+56229790978" target="_blank">+56 2 29790978</a><br>
&gt; Web: <a href="http://dtorres.me/" rel="noreferrer" target="_blank">dtorres.me</a><br>
&gt;  _______________________________________________<br>
&gt; swift-evolution mailing list<br>
&gt; <a href="mailto:swift-evolution@swift.org" target="_blank">swift-evolution@swift.org</a><br>
&gt; <a href="https://lists.swift.org/mailman/listinfo/swift-evolution" rel="noreferrer" target="_blank">https://lists.swift.org/mailman/listinfo/swift-evolution</a><br>
<br>
_______________________________________________<br>
swift-evolution mailing list<br>
<a href="mailto:swift-evolution@swift.org" target="_blank">swift-evolution@swift.org</a><br>
<a href="https://lists.swift.org/mailman/listinfo/swift-evolution" rel="noreferrer" target="_blank">https://lists.swift.org/mailman/listinfo/swift-evolution</a><br>
</blockquote></div>
</div></div><img src="https://u2002410.ct.sendgrid.net/wf/open?upn=JfMPa-2F7wwZPzsZ3QKA8NjtONIYX4SjbWuUxtpfsTY2glhbLXc3eUh4FWidjSS6FBzAMbDC3-2BVfgW0HgrD3OgCy9rLp07ari6DWmhvne-2BRw0ZJa-2F2XqCF3xKpyt13CvaQjqH06k15Yv1JP3BZzLUOkztAtAZAYtg7MFz6vv36WqCEzLVtXcdhCsV2aPqZBEUrJZblPjbi7zV9qzfF9gpOeTOykWCj6RAeouhygcXKL5w-3D" alt="" width="1" height="1" border="0" style="min-height:1px!important;width:1px!important;border-width:0!important;margin-top:0!important;margin-bottom:0!important;margin-right:0!important;margin-left:0!important;padding-top:0!important;padding-bottom:0!important;padding-right:0!important;padding-left:0!important">
_______________________________________________<span class=""><br>swift-evolution mailing list<br><a href="mailto:swift-evolution@swift.org" target="_blank">swift-evolution@swift.org</a><br><a href="https://lists.swift.org/mailman/listinfo/swift-evolution" target="_blank">https://lists.swift.org/mailman/listinfo/swift-evolution</a><br></span></div></blockquote></div><br><div>
-Dave<div><br></div><br>

</div>
<br></div>
<img src="https://u2002410.ct.sendgrid.net/wf/open?upn=6ZGE61OxINd5lLe2xYh9Ku-2BXbixWNr2nvfzp2IB1sZjoVilVsxO8JDHt95ctYOKx9sUKr2u6VUXvyzLnVDNkUmRqMHj04SEWNn6CME7E7-2B2Zyv82V1wyKuGUdJFZXGia8Ha8ZOxfcC9q-2FtceZVp-2BqSMPbGdn74w10-2FEFgcYUnoghA-2FgW-2BBOR9iAhvvtkR5GWd2Jrwr17c9il7lczvGRaJpRoqBXnhcGGltdrXZSmlCk-3D" alt="" width="1" height="1" border="0" style="min-height:1px!important;width:1px!important;border-width:0!important;margin-top:0!important;margin-bottom:0!important;margin-right:0!important;margin-left:0!important;padding-top:0!important;padding-bottom:0!important;padding-right:0!important;padding-left:0!important">
</div>
<br>_______________________________________________<br>
swift-evolution mailing list<br>
<a href="mailto:swift-evolution@swift.org">swift-evolution@swift.org</a><br>
<a href="https://lists.swift.org/mailman/listinfo/swift-evolution" rel="noreferrer" target="_blank">https://lists.swift.org/mailman/listinfo/swift-evolution</a><br>
<br></blockquote></div><br></div>