How to make rectangle from 4 points? I'm creating resizable rectangle by the corners.
I can make it with two points like this:
NSMakeRect( MIN(point1.x, point3.x),
MIN(point1.y, point3.y),
fabs(point1.x - point3.x),
fabs(point1.y - point3.y));
It's working good if I move 1 (left bottom) or 3 (right top) corner, but if 2 (left top) or 4 (right bottom) - not. How to make it with 4 NSPoints - corners?
The previous answers have produced you rectangles, but you say they don't do what you want but not why they are wrong... So I'll have a guess, just in case I guess right:
I'm guessing that you have a rectangle and you wish to move one of its corners as you might when click-dragging in a graphical program. I further assume based on your sample code that the rectangle sides are parallel to the axes.
In this scenario the point diagonally opposite the one you move is the anchor - it stays put. The one you move obviously moves, and the other two move to keep the shape rectangular.
If this is the case then you calculate the rectangle based solely on the point you move and its diagonally opposite point. The code you give in your question handles the case if point1 or point3 is moved. You just need a code for the case point2 or point4 is moved, which you get by simple substitution:
NSMakeRect( MIN(point2.x, point4.x),
MIN(point2.y, point4.y),
fabs(point2.x - point4.x),
fabs(point2.y - point4.y));
You now just need to know which point you moved and select the appropriate code.