[Boards: 3 / a / aco / adv / an / asp / b / biz / c / cgl / ck / cm / co / d / diy / e / fa / fit / g / gd / gif / h / hc / his / hm / hr / i / ic / int / jp / k / lgbt / lit / m / mlp / mu / n / news / o / out / p / po / pol / qa / qst / r / r9k / s / s4s / sci / soc / sp / t / tg / toy / trash / trv / tv / u / v / vg / vp / vr / w / wg / wsg / wsr / x / y ] [Search | Home]
ITT: Solutions for the circle-ellipse problem
Images are sometimes not shown due to bandwidth/network limitations. Refreshing the page usually helps.

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).

Superellipse <|-- Rectangle
Rectangle <|-- Square
Superellipse <|-- Ellipse
Ellipse <|-- Circle
>>
>>52627882
Holy shit it works.
>>
>>
>>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 (9 KB, 218x360) Image search: [iqdb] [SauceNao] [Google]
9 KB, 218x360
>>
>>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 (12 KB, 320x396) Image search: [iqdb] [SauceNao] [Google]
12 KB, 320x396
>>52628086
>>
>>52628109
>>
File: 1451484827169.jpg (74 KB, 640x640) Image search: [iqdb] [SauceNao] [Google]
74 KB, 640x640
>>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
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.