\chapter{Methods and Design}

{\bf TODO} Write most of this section. I suspect I will have to be very selective about what to fit in considering the word limit.

\section{Collaborative Process}
\begin{itemize}
	\item Collaborated with David Gow on the design and implementation of the SVG viewer
	\item Individual work: Applying GMP Rationals (Sam), Quadtree (David)
	\item Used git to collaborate \url{https://git.ucc.asn.au}
	\item Used preprocessor defines to not interfere with each other's code too much
	\item David used a \verb/goto/ letting the team down
\end{itemize}

\section{Structure of Software}
\begin{itemize}
	\item CPU and GPU renderer supported
	\item Rendering of Cubic B\'{e}ziers (no antialiasing)
	\item Partial implementation of shading Paths on CPU (abandoned)
	\item Ability to move the view around the document with the mouse
	\item Ability to insert an SVG into the view location
	\item \verb/typedef/ for number representations
	\item Ability to control program through scripts or stdio
	\item Hacky python scripts to produce plots by abusing this
\end{itemize}

\section{Approaches to Arbitrary Precision}
\begin{itemize}
	\item Replace \emph{all} operations with arbitrary precision (ie: Rationals) - Horrendously slow
	\item Change approach to applying coordinate transform \eqref{view-transformation}
	\item Apply view transformations directly to objects as the view is transformed, rather than just before rendering
	\begin{itemize}
		\item Allows much better precision and range with just regular IEEE-754 floats
		\item But there is an accumulated rounding error, particularly when zooming out and back in, which is bad
	\end{itemize}
	\item As above, but introduce intermediate coordinate system; use the Path elements
	\begin{itemize}
		\item Rendering of individual paths is consistent but overall they drift apart
	\end{itemize}
	\item As above, but specify Path coordinates with arbitrary precision rationals
	\begin{itemize}
		\item Works well, rationals slow down though
	\end{itemize}
\end{itemize}

\section{Number Representations Trialed}
\begin{itemize}
	\item IEEE-754 single, double, extended
	\item Custom implementation of Rationals with \verb/int64_t/
	\begin{itemize}
		\item Very limited since the integers grow exponentially and overflow
	\end{itemize}
	\item Custom implementation of Rationals with custom Arbitrary precision integers
	\begin{itemize}
		\item Actually works
		\item Implementation of division is too slow to be feasible
	\end{itemize}
	\item Custom rationals but with GMP arbitrary precision integers
	\begin{itemize}
		\item Our implementation of GCD is not feasible
	\end{itemize}
	\item Paranoid Numbers; store a operation tree of IEEE-754 floats and simplify the tree wherever \verb/FE_INEXACT/ is \emph{not} raised
	\begin{itemize}
		\item This was a really, really, really, bad idea
	\end{itemize}
	\item Just use GMP rationals already
	\begin{itemize}
		\item Works
	\end{itemize}
	
	\item MPFR floats
	\begin{itemize}
		\item They work, but they don't truly give arbitrary precision
		\item Because you have to specify the maximum precision
		\item However, this can be changed at runtime
		\item Future work: Trial MPFR floats changing the precision as needed
	\end{itemize}
	
\end{itemize}

\section{Libraries Used}
\begin{itemize}
	\item SDL2 - Simple Direct media Library
	\begin{itemize}
		\item Used for window management and to obtain an OpenGL context
		\item Also provides BMP handling which is useful
	\end{itemize}
	\item Qt4 (optional)
	\begin{itemize}
		\item Open source toolkit for Dialog based applications
		\item We can optionally compile with a Qt4 based control panel
		\item This is useful for interacting with the document
		\item Has way more features than we actually use it for
	\end{itemize}
	\item OpenGL - Standard API for rendering on GPUs
	\begin{itemize}
		\item Using GLSL shaders
		\item B\'{e}ziers are rendered using a Geometry shader which produces line segments
	\end{itemize}
	\item PugiXML - Open source XML parsing library
	\begin{itemize}
		\item Used to parse SVGs
	\end{itemize}
	\item GNU Multiple Precision (GMP)
	\begin{itemize}
		\item Implements arbitrary precision integers, floats, and rationals
		\item We can use the arbitrary precision integers with a custom rational type
		\item Or just use the GMP rational type (much better)
		\item We don't use the floats, because they are hardware dependent
	\end{itemize}
	\item MPFR
	\begin{itemize}
		\item MPFR is built on GMP but ensures IEEE-754 consistent rounding behaviour
		\item (Not hardware dependent)
		\item We can compile with MPFR floats but the precision is currently fixed at compile time
	\end{itemize}
\end{itemize}


\section{Design of Performance Tests}
\begin{itemize}
	\item This is mostly covered in the Results chapter
	\item Control the program through stdin using a python script	
\end{itemize}

