AnalogueLiteral.scala

package net.snowtiger.analogue

/**
 * The base class for analogue lines, rectangles and cuboids.
 * See http://snowtiger.net/scala/analogue for a complete article on the subject.
 *
 * The companion object must be imported (import AnalogueLiteral._) in order
 * to use the required constants and implicit type conversions.
 *
 * @author Mark B Davies
 */
abstract class AnalogueLiteral
{
	override def toString() = pictureString() + " = " + sizeString

	def pictureString(): String
	def sizeString(): String

	def floor(n:Int) = if (n<0) 0 else n
}

object AnalogueLiteral
{
	val O, I, L = new AnalogueLine(0)
	val OO, OI = new AnalogueLine(1)

	implicit def int2Line(i: Int) = new AnalogueLine(i)
	implicit def line2Square(line: AnalogueLine) = new AnalogueRectangle(line.size, 0)
	implicit def square2Cube(square: AnalogueRectangle) =
				new AnalogueCuboid(square.width, square.height, 0)
	implicit def line2Cube(line: AnalogueLine) = new AnalogueCuboid(line.size, 0, 0)

}