Reputation: 1
I´m taking the CS 193p course from stanford (in iTunesU) and i'm trying to understand the AxesDrawer class they provide for the Assigment 3, specially these lines part of the drawHashMarksInRect method
#define HASH_MARK_SIZE 3
#define MIN_PIXELS_PER_HASHMARK 25
+ (void)drawHashMarksInRect:(CGRect)bounds originAtPoint:(CGPoint)axisOrigin scale: (CGFloat)pointsPerUnit
{
.....
int unitsPerHashmark = MIN_PIXELS_PER_HASHMARK * 2 / pointsPerUnit;
if (!unitsPerHashmark) unitsPerHashmark = 1;
CGFloat pixelsPerHashmark = pointsPerUnit * unitsPerHashmark;
....
}
How is that they say to be working with pixels and not using the contentScaleFactor property? are they actually using pixels or just points just and misusing the term?. Here es the AxesDrawer code
Upvotes: 0
Views: 694
Reputation: 406
But contentScaleFactor is number of pixels per point. So in case of high-res it will have more pixels per point. However, since we are dealing at points range shouldn't the system take care of itself without involving us ?
Upvotes: 0
Reputation: 137
The class is correctly treating a point as a point - which means your bounds.size.width and bounds.size.height are the same dimensions as an iPhone 3GS screen's size in pixels...
If you are compiling to an attached 3Gs the content scale factor is 1.
If you are attached to an iPhone 4 or 4s the content scale factor is 2.
However AxesDrawer considers scale as pointsPerUnit, which on an iPhone 4 is 0.5, so the scale you're passing to it is 0.5
You get this by placing the following in the UIView class for the graphing view;
CGFloat screenScale = self.contentScaleFactor;
CGFloat scaleForAxesDrawer = 1 / screenScale;
[[self.axes class] drawAxesInRect:graphArea originAtPoint:axisPoint scale:scaleForAxesDrawer];
// where graphArea is a CGRect and axisPoint is a CGPoint
for example.
AxesDrawer will put a hash mark and number along the axis no less than every 25 pixels.
Upvotes: 0