Make 2 contradictory methods work in drawRect

I'm writing an app building elements consisting of CGPoints. I have 2 buttons:

makeRectangle
and
makeTriangle
. For building/drawing stage I use three methods for rectangle and three methods for triangle inside
drawRect
.

I'm stuck with my code in

drawRect
. In
if-else-statement
each method swaps the building/drawing scheme for previous element every time a button pressed.

If I already have built rectangle and then I click

makeTriangle
button, I get new triangle but my rectangle turns into triangle with one unconnected point.

Is there a workaround or I shouldn't use

drawRect
method?


Here's a code and all the details:

http://stackoverflow.com/questions/39855349/make-2-contradictory-methods-work-in-drawrect

Well, if you look at the code, you'll see that a triangle will be missing its drawn third side if "array" only contains 3 Element values. If it has 4 Element values, the triangle will be drawn closed, but apparently the 4th point is drawn too.


However, the real diagnosis is impossible to discover, because you've posted a lot of code except the relevant parts (how "array" is constructed).


The deeper problem, though, is that your code is kind of a mess. You're trying to encapsulate behavior (e.g. in the Element type), but then you subvert encapsulation with a lot of global functions and variables, and invert the implementation behavior from private to public. On top of that, the most important objects (rectangle and triangle) don't even have types, but are loosely implemented by an array, apparently.


I think you should rethink your design a bit.

Make 2 contradictory methods work in drawRect
 
 
Q