#!/usr/bin/perl -w

use Test;
use strict;

BEGIN
  {
  unshift @INC, '../..';
  plan tests => 17;
  }

use CoW::Angle;
use CoW::Thing;

my $coord_rx = new CoW::Angle ( rel => 'rz', val => 25 );
my $coord_ry = new CoW::Angle ( rel => '', val => 20 );
my $coord_w = new CoW::Coord ( rel => 'l', val => 20 );
my $one = new CoW::Thing ( rx => $coord_rx, rz => 10, ry => $coord_ry,
	x => 0, y => 0, z => 0, w => $coord_w, l => 0, h => 0, );

# test stringify and absolute of coord

ok ( "$coord_rx", "35" );
ok ( "$coord_ry", "20" );
ok ( "$one->{rz}", "10" );
ok ( $one->{rx}, "35" );
ok ( $one->{rx}, 35 );
ok ( $one->{ry}, "20" );

# test wether absolute works recursively
my $two = new CoW::Thing ( rx => $coord_rx, rz => $coord_ry, ry => 9 );
ok ( "$two->{rx}", "45" );

$coord_ry = CoW::Angle->new ( rel => 'ry', val => 20 );

$two = new CoW::Thing ( rx => $coord_rx, rz => $coord_ry, ry => 9 );
ok ( "$two->{rx}", "54" );

# test wether rotating thing makes the angles follow
ok ( "$one->{rx}", "35" );
$one->{rz} = 20;
ok ( "$one->{rx}", $one->{rz} + 25 );
ok ( "$one->{rx}", 45 );

# check that rotate() works:
$one->{rz} = 20;
$one->rotate(0,0,10);			# rotate around z by 10
ok ( "$one->{rz}", 30 );
ok ( "$one->{rx}", $one->{rz} + 25 );
ok ( "$one->{rx}", 55 );

$one->rotate(-10,0,0);			# rotate around x by -10
ok ( "$one->{rx}", $one->{rz} + 15 );

# check min/max

$a = new CoW::Angle ( min => 10, max => 300, rel => '', val => 5);

ok ("$a",10);
$a->val(310);
ok ("$a",300);

