[Boards: 3 / a / aco / adv / an / asp / b / bant / biz / c / can / cgl / ck / cm / co / cock / d / diy / e / fa / fap / fit / fitlit / g / gd / gif / h / hc / his / hm / hr / i / ic / int / jp / k / lgbt / lit / m / mlp / mlpol / mo / mtv / mu / n / news / o / out / outsoc / p / po / pol / qa / qst / r / r9k / s / s4s / sci / soc / sp / spa / t / tg / toy / trash / trv / tv / u / v / vg / vint / vip / vp / vr / w / wg / wsg / wsr / x / y ] [Search | Free Show | Home]

ITT: Solutions for the circle-ellipse problem

This is a blue board which means that it's for everybody (Safe For Work content only). If you see any adult content, please report it.

Thread replies: 22
Thread images: 5

I say we make circle and ellipse a specialized subclass of squares, but with bendy edges.
>>
>>52627739
https://en.wikipedia.org/wiki/Superellipse
>A superellipse, also known as a Lamé curve after Gabriel Lamé, is a geometric figure defined in the Cartesian coordinate system as the set of all points (x y) with (+ (expt (/ x a) n) (expt (/ y b) n)) where n, a and b are positive numbers
>[...]
>For n = 1 The curve is a rhombus with corners (±a, 0) and (0, ±b).
>[...]
>For n = 2 the curve is an ordinary ellipse (in particular, a circle if a = b).
[note by me] For n -> inf the curve tends to a rectangle with corners (±a, ±b) (in particular, a square if a = b).


Your new hierarchy would have:
Superellipse <|-- Rectangle
Rectangle <|-- Square
Superellipse <|-- Ellipse
Ellipse <|-- Circle
>>
>>52627882
Holy shit it works.
>>
what the actual fuck are you lads on about
>>
>>52627932
The circle-ellipse problem is a problem with OOP systems where a superclass has lass strict invariants than a subclass.

For example:
If you make circle a subclass of ellipse, how is setWidth and set height on the ellipse class applied to the circle class?
If you make ellipse a subclass of circle, how does the ellipse handle the circle invariant that height is always the same as width?
>>
>>52627739
Just don't have circles or squares.

In general just have it set so if you include 2 arguments draw a circle and if it includes 3 draw an ellipse.
>>
>>52627975
Setting the width sets the height too and vice versa. Boom.
>>
File: figures.png (9KB, 218x360px) Image search: [Google]
figures.png
9KB, 218x360px
>>
>>52628006
This is disgusting. Any methods written to handle ellipses that assume the invariant hold suddenly break.
>>
>>52628041
All solutions are inherently disgusting in some way or another. Deal with it.
>>
>>52628052
The whole point of the problem is that is a fanning example of why inheritance is shit. Using the "fuck it ship it" approach and ignoring the problem is missing the point.
>>
>>52628086
Whole procedure:
>fuck it
>ship it
>invoice it
>charge it
>dev it
>make(1) it
>sudo(8) it
>make(1)s us
>harder
>better
>faster
>stronger
>>
File: figures.png (12KB, 320x396px) Image search: [Google]
figures.png
12KB, 320x396px
>>52628086
>>
File: 1444689135270-tech.jpg (27KB, 404x400px) Image search: [Google]
1444689135270-tech.jpg
27KB, 404x400px
>>52628109
>>
File: 1451484827169.jpg (74KB, 640x640px) Image search: [Google]
1451484827169.jpg
74KB, 640x640px
>>52628109
manigga
>>
>>52628134
Purists cry about rectangles and squares too. Circle-ellipse is just the common example.
>>
why don't people just do what you are supposed to do and not use inheritance?
>>
>>52628374
Better solution:
https://en.wikipedia.org/wiki/Circle-ellipse_problem#Change_the_programming_language
>literally using Common Lisp master race
>>
>>52628531
CLOS is God tier.
>>
>>52627739
>use private/protected inheritance
>implement set_radius(a:double):void using ellipse's methods
Done. You shouldn't use public inheritance here.
>>
>>52627739
>drop dynamic dispatch
>use type traits
done
>>
>>52628374
I use inheritance because I want to make use of specialization and generalization. Inheritance makes this very easy.
Thread posts: 22
Thread images: 5


[Boards: 3 / a / aco / adv / an / asp / b / bant / biz / c / can / cgl / ck / cm / co / cock / d / diy / e / fa / fap / fit / fitlit / g / gd / gif / h / hc / his / hm / hr / i / ic / int / jp / k / lgbt / lit / m / mlp / mlpol / mo / mtv / mu / n / news / o / out / outsoc / p / po / pol / qa / qst / r / r9k / s / s4s / sci / soc / sp / spa / t / tg / toy / trash / trv / tv / u / v / vg / vint / vip / vp / vr / w / wg / wsg / wsr / x / y] [Search | Top | Home]

I'm aware that Imgur.com will stop allowing adult images since 15th of May. I'm taking actions to backup as much data as possible.
Read more on this topic here - https://archived.moe/talk/thread/1694/


If you need a post removed click on it's [Report] button and follow the instruction.
DMCA Content Takedown via dmca.com
All images are hosted on imgur.com.
If you like this website please support us by donating with Bitcoins at 16mKtbZiwW52BLkibtCr8jUg2KVUMTxVQ5
All trademarks and copyrights on this page are owned by their respective parties.
Images uploaded are the responsibility of the Poster. Comments are owned by the Poster.
This is a 4chan archive - all of the content originated from that site.
This means that RandomArchive shows their content, archived.
If you need information for a Poster - contact them.