# $Id: Model.pm 2010-08-31 aj3 $

package Axonometrie::Model;

use strict;
use warnings;
use 5.007;

our $VERSION = 0.01;



sub new {
	my ($class, $modelDescription) = @_;
	
	my $self = {};
	bless $self, $class;
	
	$self->_init($modelDescription);
	
	return $self;
}



sub _init {
	my ($self, $description) = @_;
	
	$description =~ s/[\n\r]+/\n/g;
	my @objects = ();
	
	my @description = split m/\n/, $description;
	foreach my $line ( @description ) {
		if ($line =~ m/^#/) { next; }
		
		my ($x1, $y1, $z1, $instruction, $x2, $y2, $z2, $class) = split m/[ \t]/, $line;
		if (! $class || $class eq '-') {
			$class = '';
		}
		else {
			$class = join ' ', split m/[,|]/, $class;
		}
		
		if ($instruction ne 'lineto' && $instruction ne '-') {
			# :BUG: hard-coded format is very inflexible
			die 'Assertion failed: model line instruction not "lineto"';
		}
		
		my %line = ( x1 => $x1, y1 => $y1, z1 => $z1, x2 => $x2, y2 => $y2, z2 => $z2, class => $class );
		push @objects, \%line;
	}
	
	$self->{objects} = \@objects;
}



1;
