<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:wfw="http://wellformedweb.org/CommentAPI/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	xmlns:atom="http://www.w3.org/2005/Atom"
	xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
	xmlns:slash="http://purl.org/rss/1.0/modules/slash/"
	>

<channel>
	<title>boyfarrell.com &#187; Code</title>
	<atom:link href="http://www.boyfarrell.com/category/code/feed" rel="self" type="application/rss+xml" />
	<link>http://www.boyfarrell.com</link>
	<description>Just another WordPress weblog</description>
	<lastBuildDate>Mon, 10 Aug 2009 22:52:12 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.0</generator>
		<item>
		<title>ChocPlot: First Results</title>
		<link>http://www.boyfarrell.com/learning-curve/chocplot-first-results</link>
		<comments>http://www.boyfarrell.com/learning-curve/chocplot-first-results#comments</comments>
		<pubDate>Mon, 14 Jan 2008 22:01:39 +0000</pubDate>
		<dc:creator>boyfarrell</dc:creator>
				<category><![CDATA[Code]]></category>
		<category><![CDATA[Learning Curve]]></category>

		<guid isPermaLink="false">http://www.boyfarrell.com/code/chocplot-first-results</guid>
		<description><![CDATA[It has been quite slow going with the plotting framework as of late; the trouble with being in the fourth year of a three year PhD! I have decided to rely on Cocoa for as much as possible for the plot above (under the advice of Wil Shipley). I am using NSBezierPath to draw the [...]]]></description>
			<content:encoded><![CDATA[<p><img id="image79" src="http://www.boyfarrell.com/wordpress/wp-content/uploads/2008/01/cocoa-plot-view.jpg" alt="Cocoa Plot View" /></p>
<p>It has been quite slow going with the plotting framework as of late; the trouble with being in the fourth year of a three year PhD! I have decided to rely on Cocoa for as much as possible for the plot above (<a href="http://www.wilshipley.com/blog/2007/05/pimp-my-code-part-14-be-inflexible.html">under the advice of Wil Shipley</a>). I am using NSBezierPath to draw the red dashed line and the filled the circles. NSAffineTransform is used to convert data points from data to screen/view coordinates.</p>
<h2>A lot for free</h2>
<p>Using NSAffineTransform makes it very easy to position and also alter the points (which themselves are drawn with NSBezierPath) in the view, e.g. rotation of the data points by 23 degrees in the example below. One just needs to specify a &#8216;data&#8217; coordinate rectangle which is made from the min, max and range of the experimental data set in x and y. A NSAffineTransform is made such that the &#8216;data&#8217; rectangle is first translated and then scaled to fit into the view bounds. Hmmm I lke &#8216;tiny code&#8217; &#8230;</p>
<p><img id="image81" src="http://www.boyfarrell.com/wordpress/wp-content/uploads/2008/01/cocoa-plot-view-crosses.jpg" alt="Cocoa Plot View with crosses" /></p>
<p>Drawing lines is made very easy, using NSBezierPath&#8217;s <code>setLineDash:count:phase:</code> method. Also, drawing oval/circles comes for free with <code>bezierPathWithOvalInRect:</code> method. So the only really work I have actually done is added <code>bezierPathWithCrossInRect:</code> extension to aid drawing of crosses (shown above)!</p>
<h2>Next step&#8230;</h2>
<p>Next I will add a points-lines plotting style. This will be similar to drawing a dashed lines but will have ovals or crosses, and regular points along it&#8217;s length. A nice touch would be to have the rotation of the points follow the gradient of the line; think of the way loops in chain would rotate as of a chain changes direction. </p>
<p>Also, we will implement the code from the <a href="http://www.boyfarrell.com/learning-curve/chocplot-mutable-axis-model">first few chocplot plots</a> and have nicley spaced axis labels on the plot.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.boyfarrell.com/learning-curve/chocplot-first-results/feed</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>syntax error before &#8216;AT_NAME&#8217; token</title>
		<link>http://www.boyfarrell.com/code/syntax-error-before-at_name-token</link>
		<comments>http://www.boyfarrell.com/code/syntax-error-before-at_name-token#comments</comments>
		<pubDate>Mon, 29 Oct 2007 11:10:27 +0000</pubDate>
		<dc:creator>boyfarrell</dc:creator>
				<category><![CDATA[Code]]></category>
		<category><![CDATA[Micro Post]]></category>

		<guid isPermaLink="false">http://www.boyfarrell.com/code/syntax-error-before-at_name-token</guid>
		<description><![CDATA[This means you have some junk in one of your header file that shouldn&#8217;t be there. Tip of the hat to Infurious Blog for pointing out one possible meaning of this error; a missing @end in an Objective-C class header file. Another possibility for this (this took me an hour to find!) is that you [...]]]></description>
			<content:encoded><![CDATA[<p>This means you have some junk in one of your header file that shouldn&#8217;t be there.</p>
<p>Tip of the hat to <a href="http://blog.infurious.com/2007/10/22/syntax-error-before-‘at_name’-token/">Infurious Blog</a> for pointing out one possible meaning of this error; a missing @end in  an Objective-C class header file.</p>
<p>Another possibility for this (<bold>this took me an hour to find!</bold>) is that you have a curly bracket somewhere in you header file. For example, from cut and pasting your method definition from the implementation file into your header file.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.boyfarrell.com/code/syntax-error-before-at_name-token/feed</wfw:commentRss>
		<slash:comments>4</slash:comments>
		</item>
		<item>
		<title>ChocPlot: Mutable Axis Model</title>
		<link>http://www.boyfarrell.com/learning-curve/chocplot-mutable-axis-model</link>
		<comments>http://www.boyfarrell.com/learning-curve/chocplot-mutable-axis-model#comments</comments>
		<pubDate>Tue, 04 Sep 2007 21:33:17 +0000</pubDate>
		<dc:creator>boyfarrell</dc:creator>
				<category><![CDATA[Code]]></category>
		<category><![CDATA[Learning Curve]]></category>

		<guid isPermaLink="false">http://www.boyfarrell.com/learning-curve/chocplot-mutable-axis-model</guid>
		<description><![CDATA[The original AxisModel was quite limited in it&#8217;s abilities; it just did everything automatically. Here I introduce the mutable subclass of AxisModel; MutableAxisModel As this is a subclass it still responds to the same methods defined in AxisModel; -interval, -spacing, -start, -stop, -representation, -description MutableAxisModel adds additional methods designed to give the user some control [...]]]></description>
			<content:encoded><![CDATA[<p>The original <a href="http://www.boyfarrell.com/code/chocplot/doc/v1-1/interface_axis_model.html">AxisModel</a> was quite limited in it&#8217;s abilities; it just did everything automatically. Here I introduce the mutable subclass of <a href="http://www.boyfarrell.com/code/chocplot/doc/v1-1/interface_axis_model.html">AxisModel</a>; <a href="http://www.boyfarrell.com/code/chocplot/doc/v1-1/interface_mutable_axis_model.html">MutableAxisModel</a></p>
<p>As this is a subclass it still responds to the same methods defined in <a href="http://www.boyfarrell.com/code/chocplot/doc/v1-1/interface_axis_model.html">AxisModel</a>; <code>-interval, -spacing, -start, -stop, -representation, -description</code></p>
<p><a href="http://www.boyfarrell.com/code/chocplot/doc/v1-1/interface_mutable_axis_model.html">MutableAxisModel</a> adds additional methods designed to give the user some control over the axis properties. These new methods are: <code>-setStart:, -setStop:, -moreIntervals, -fewerIntervals</code></p>
<p>As one might expect these allow the start and stop to be set exactly; these values will not be rounded like the -initWithStart:stop: values are with <a href="http://www.boyfarrell.com/code/chocplot/doc/v1-1/interface_axis_model.html">AxisModel</a>. The interval positions are still placed at nice rounded intervals but <b>inside</b> these end-points. Using the last two methods in the list allows the number of axis interval (tic marks) can be increased or decreased. </p>
<p>The actual number of intervals afterwards is determined by <a href="http://www.boyfarrell.com/code/chocplot/doc/v1-1/interface_mutable_axis_model.html">MutableAxisModel</a>, if it thinks that you have too many (such that adding more would just looked cluttered), it won&#8217;t add anymore! The same is true for the opposite case; having to fewer intervals.</p>
<p>There are a few more model classes left before moving on to the Graphical objects. The next post will be about <b>LinkedAxisModel</b>; a subclass of mutable axis model that uses a transform to display the same data but it different units.</p>
<p><a href="http://www.boyfarrell.com/code/chocplot/src/AxisModel-1.1.tar.gz">Source Code with Documentation (104kB)</a></p>
]]></content:encoded>
			<wfw:commentRss>http://www.boyfarrell.com/learning-curve/chocplot-mutable-axis-model/feed</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
		<item>
		<title>Overview of axis rounding</title>
		<link>http://www.boyfarrell.com/learning-curve/overview-of-axis-rounding</link>
		<comments>http://www.boyfarrell.com/learning-curve/overview-of-axis-rounding#comments</comments>
		<pubDate>Mon, 03 Sep 2007 20:00:41 +0000</pubDate>
		<dc:creator>boyfarrell</dc:creator>
				<category><![CDATA[Code]]></category>
		<category><![CDATA[Learning Curve]]></category>

		<guid isPermaLink="false">http://www.boyfarrell.com/learning-curve/overview-of-axis-rounding</guid>
		<description><![CDATA[(A pdf version of this discussion with equations, and source code with documentation are available. Alternatively, just the documentation is available on-line.) Update There were some problems with the original code, but they are all solved now. There were just silly bugs: one variable was a unsigned and should have been an int etc. I [...]]]></description>
			<content:encoded><![CDATA[<p>(A <a id="p69" href="http://www.boyfarrell.com/wordpress/wp-content/uploads/2007/09/rounding-algorithms.pdf" title="Rounding Algorithm Discussion">pdf version of this discussion</a> with equations, and <a id="p70" href="http://www.boyfarrell.com/wordpress/download-manager.php?id=9"> source code with documentation</a> are available. Alternatively, just the <a href="http://www.boyfarrell.com/code/axis-rounding/Documentation/html/_axis_rounding_8c.html">documentation is available on-line</a>.)</p>
<p><b>Update</b> There were some problems with the original code, but they are all solved now. There were just silly bugs: one variable was a unsigned and should have been an int etc.</p>
<p>I have been quite bored recently so in a search for something to do that was potential useful I &#8216;wrote up&#8217; some of my recent experiments with rounding axis values. The main problem to solve is how to place tic marks at nice interval along the axis, if your axis doesn&#8217;t start with nice rounded numbers. The solution, I hear you say, is to round the the axis start and top values. However this can only be done once the axis spacing is known! Moreover, we cannot find out how to round the axis start and stop values with out knowledge of how we have rounded them!</p>
<h2>Axis Definitions</h2>
<p>Before we continue let&#8217;s make some definitions:</p>
<p><img id="image64" src="http://www.boyfarrell.com/wordpress/wp-content/uploads/2007/09/axis-defintions-3.jpg" alt="Axis Definitions" /></p>
<p>The range is clearly the end minus the start value, <b>NB</b> this is assumed to always be positive, so start must always be less than stop. The spacing is the separation, in axis units, between tic marks. The interval is the number of tic marks placed along the axis.</p>
<p>We can then generate equations which describe; the axis spacing as a function of the range and interval number; and the number of intervals as a function of range and spacing. This is the interdependency that I refereed to previously.</p>
<h2>Rounding</h2>
<p>The example axis above is fortunate because we started with rounded values. However, what happens if the start value was 0.2 and the stop value was 3.7? We would still want exactly the same spacing. That is, we would want 0.2 to rounded down to 0 and 3.7 to be rounded up to 4.</p>
<p>This can be achieved using ceil() and floor() functions from math.h, along with a guess value for the axis spacing.</p>
<h2>Algorithm to find spacing</h2>
<p>The number of axis intervals should be some manageable mount, a number less than 4 is too few, while more than 11 is overkill. The basis for finding the rounded axis spacing is to try a few guess spacing and see which one produce intervals in the desired range. There are also a few clues that we can use to quickly find the spacing, and when this is done it takes no more than 6 iteration to acquire the result.</p>
<h2>AxisRounding Source Code</h2>
<p>The above algorithm is used below in the function <a href="http://www.boyfarrell.com/code/axis-rounding/Documentation/html/_axis_rounding_8c.html">MakeSpacing()</a>. Here we get clues for the guess value from looking at the decade of the axis range,</p>
<p><img id="image66" src="http://www.boyfarrell.com/wordpress/wp-content/uploads/2007/09/picture-1.png" alt="MakeSpacing Function" /></p>
<p>Now we set the guess values. The trick is to scale the guess values to the same range as the axis. The axis decade has been rounded down using floor() and as such we start our search in the lower decade and then more through to the higher one. This range will cover all possible solutions that fall into our tic mark range.</p>
<p><img id="image67" src="http://www.boyfarrell.com/wordpress/wp-content/uploads/2007/09/picture-2.png" alt="MakeSpacing Functions" /></p>
<p>Finally, calculate the number of intervals for the current guess spacing. If this falls into the our desired range for the number of intervals, we return the value.</p>
<p><img id="image68" src="http://www.boyfarrell.com/wordpress/wp-content/uploads/2007/09/picture-3.png" alt="MakeSpacing Function" /></p>
<p>Please find the source code and documentation of how to use the axis spacing functions in the links above.</p>
<h3>Example Use</h3>
<p><code>double start = 400;<br />
  double stop = 800;<br />
  double spacing  = MakeSpacing(start, stop);<br />
  unsigned interval = MakeInterval(start, stop);<br />
  PrintDescription(start, stop, spacing, interval);</p>
<p>  /*<br />
  Axis Description:<br />
  start = 400<br />
  stop  = 800<br />
  spacing   = 50<br />
  interval = 9<br />
  (400, 450, 500, 550, 600, 650, 700, 750, 800)<br />
 */<br />
</code></p>
]]></content:encoded>
			<wfw:commentRss>http://www.boyfarrell.com/learning-curve/overview-of-axis-rounding/feed</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>ChocPlot 1: Axis Model</title>
		<link>http://www.boyfarrell.com/learning-curve/chocplot-1-axis-model</link>
		<comments>http://www.boyfarrell.com/learning-curve/chocplot-1-axis-model#comments</comments>
		<pubDate>Thu, 16 Aug 2007 17:45:33 +0000</pubDate>
		<dc:creator>boyfarrell</dc:creator>
				<category><![CDATA[Code]]></category>
		<category><![CDATA[Learning Curve]]></category>

		<guid isPermaLink="false">http://www.boyfarrell.com/learning-curve/chocplot-1-axis-model</guid>
		<description><![CDATA[ChocPlot is my very poorly named framework/application for plotting using Cocoa. It is still very much a work in progress, so far I have written a class called AxisModel. It can be used to generate nicely spacing axis tic marks from just two variables; the start and stop values of the axis. Please read the [...]]]></description>
			<content:encoded><![CDATA[<p>ChocPlot is my very poorly named framework/application for plotting using Cocoa. It is still very much a work in progress, so far I have written a class called AxisModel. It can be used to generate nicely spacing axis tic marks from just two variables; the start and stop values of the axis.</p>
<p>Please read the <a href="http://www.boyfarrell.com/code/chocplot/doc/v1-1/index.html">on-line documentation</a> and get the <a href="http://www.boyfarrell.com/code/chocplot/src/AxisModel.1.0.tar.gz">source </a>. Alternatively, download the whole <a href="http://www.boyfarrell.com/code/chocplot/src/ChocPlot-1.0.zip">XCode Project</a>.</p>
<h2>Example</h2>
<p><code lang="objc"><br />
/*<br />
axis with automatically positioned tic marks but with the number supplied by the user<br />
*/<br />
CPAxisModel *axis = [CPAxisModel axisWithStart:1 stop:10];<br />
NSLog([axis description]);<br />
// (0, 2, 4, 6, 8, 10)<br />
</code></p>
]]></content:encoded>
			<wfw:commentRss>http://www.boyfarrell.com/learning-curve/chocplot-1-axis-model/feed</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
	</channel>
</rss>
