Hi,
I am working on the 3rd assignment form the stanford class. It is asking me to implement a Class method +(). this method finds points of a rectangle and stores them for later retrieval and use in drawing a View.
First, I am confused as to why the method is performed on the Class and not the instance of the class.
Second, would this method be called from the ObjectView Class or the Object class. I would think that if its called by the Object class it would be on the instance not the Class itself. any explanation would be really helpful.
I am inserting the supplied code.
I am working on the 3rd assignment form the stanford class. It is asking me to implement a Class method +(). this method finds points of a rectangle and stores them for later retrieval and use in drawing a View.
First, I am confused as to why the method is performed on the Class and not the instance of the class.
Second, would this method be called from the ObjectView Class or the Object class. I would think that if its called by the Object class it would be on the instance not the Class itself. any explanation would be really helpful.
I am inserting the supplied code.
Code:
+ (NSArray *)pointsForPolygonInRect:(CGRect)rect numberOfSides:(int)numberOfSides {
CGPoint center = CGPointMake(rect.size.width / 2.0, rect.size.height / 2.0);
float radius = 0.9 * center.x;
NSMutableArray *result = [NSMutableArray array];
float angle = (2.0 * M_PI) / numberOfSides;
float exteriorAngle = M_PI - angle;
float rotationDelta = angle - (0.5 * exteriorAngle);
for (int currentAngle = 0; currentAngle < numberOfSides; currentAngle++) {
float newAngle = (angle * currentAngle) - rotationDelta;
float curX = cos(newAngle) * radius;
float curY = sin(newAngle) * radius;
[result addObject:[NSValue valueWithCGPoint:CGPointMake(center.x + curX,
center.y + curY)]];
}
return result;
}