[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 / r / r9k / s / s4s / sci / soc / sp / t / tg / toy / trash / trv / tv / u / v / vg / vp / vr / w / wg / wsg / wsr / x / y ] [Home]
4chanarchives logo
ITT: Solutions for the circle-ellipse problem
Images are sometimes not shown due to bandwidth/network limitations. Refreshing the page usually helps.

You are currently reading a thread in /g/ - Technology

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 (9 KB, 218x360) Image search: [Google]
figures.png
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: [Google]
figures.png
12 KB, 320x396
>>52628086
>>
File: 1444689135270-tech.jpg (27 KB, 404x400) Image search: [Google]
1444689135270-tech.jpg
27 KB, 404x400
>>52628109
>>
File: 1451484827169.jpg (74 KB, 640x640) Image search: [Google]
1451484827169.jpg
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
>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 replies: 22
Thread images: 5

banner
banner
[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 / r / r9k / s / s4s / sci / soc / sp / t / tg / toy / trash / trv / tv / u / v / vg / vp / vr / w / wg / wsg / wsr / x / y] [Home]

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.
If a post contains personal/copyrighted/illegal content you can contact me at [email protected] with that post and thread number and it will be removed as soon as possible.
DMCA Content Takedown via dmca.com
All images are hosted on imgur.com, send takedown notices to them.
This is a 4chan archive - all of the content originated from them. If you need IP information for a Poster - you need to contact them. This website shows only archived content.