Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>In this case, you should use <code>-[CPPlotSpace scaleToFitPlots:]</code>. For more general calculations on array values, read on...</p> <p>This is an ideal use for Key-Value coding and associated <a href="http://developer.apple.com/mac/library/documentation/cocoa/conceptual/KeyValueCoding/Concepts/ArrayOperators.html#//apple_ref/doc/uid/20002176" rel="noreferrer">array operators</a>. In your example,</p> <pre><code>float maxX = [[contentArray valueForKeyPath:@"@max.x"] floatValue]; float minY = [[contentArray valueForKeyPath:@"@min.x"] floatValue]; float maxY = [[contentArray valueForKeyPath:@"@max.y"] floatValue]; float minY = [[contentArray valueForKeyPath:@"@min.y"] floatValue]; </code></pre> <p>The array operators call <code>valueForKeyPath:</code> on the <code>contentArray</code> which gives an array built by calling the same <code>valueForKeyPath:</code> on each member of the array with the key path to the right of the array operator (i.e. <code>@min</code> and <code>@max</code>). The orignal call then applies the given operator to the resulting array. You could easily define a category on <code>NSArray</code> to give you back a struct of min/max values:</p> <pre><code>typedef struct { float minX; float minY; float maxX; float maxY; } ArrayValueSpace; @implementation NSArray (PlotSpaceAdditions) - (ArrayValueSpace)psa_arrayValueSpace { ArrayValueSpace result; result.maxX = [[contentArray valueForKeyPath:@"@max.x"] floatValue]; result.minX = [[contentArray valueForKeyPath:@"@min.x"] floatValue]; result.maxY = [[contentArray valueForKeyPath:@"@max.y"] floatValue]; result.minY = [[contentArray valueForKeyPath:@"@min.y"] floatValue]; return result; } </code></pre>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. VO
      singulars
      1. This table or related slice is empty.
    2. VO
      singulars
      1. This table or related slice is empty.
    3. VO
      singulars
      1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload