~ubuntu-branches/ubuntu/utopic/slic3r/utopic

« back to all changes in this revision

Viewing changes to xs/t/03_point.t

  • Committer: Package Import Robot
  • Author(s): Chow Loong Jin
  • Date: 2014-06-17 01:27:26 UTC
  • Revision ID: package-import@ubuntu.com-20140617012726-2wrs4zdo251nr4vg
Tags: upstream-1.1.4+dfsg
ImportĀ upstreamĀ versionĀ 1.1.4+dfsg

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
#!/usr/bin/perl
 
2
 
 
3
use strict;
 
4
use warnings;
 
5
 
 
6
use Slic3r::XS;
 
7
use Test::More tests => 15;
 
8
 
 
9
my $point = Slic3r::Point->new(10, 15);
 
10
is_deeply [ @$point ], [10, 15], 'point roundtrip';
 
11
 
 
12
my $point2 = $point->clone;
 
13
$point2->scale(2);
 
14
is_deeply [ @$point2 ], [20, 30], 'scale';
 
15
 
 
16
$point2->translate(10, -15);
 
17
is_deeply [ @$point2 ], [30, 15], 'translate';
 
18
 
 
19
ok $point->coincides_with($point->clone), 'coincides_with';
 
20
ok !$point->coincides_with($point2), 'coincides_with';
 
21
 
 
22
{
 
23
    my $point3 = Slic3r::Point->new(4300000, -9880845);
 
24
    is $point->[0], $point->x, 'x accessor';
 
25
    is $point->[1], $point->y, 'y accessor';  #,,
 
26
}
 
27
 
 
28
{
 
29
    my $nearest = $point->nearest_point([ $point2, Slic3r::Point->new(100, 200) ]);
 
30
    ok $nearest->coincides_with($point2), 'nearest_point';
 
31
}
 
32
 
 
33
{
 
34
    my $line = Slic3r::Line->new(
 
35
        [18335846,18335845],
 
36
        [18335846,1664160],
 
37
    );
 
38
    $point = Slic3r::Point->new(1664161,18335848);
 
39
    is $point->distance_to_line($line), 16671685, 'distance_to_line() does not overflow';
 
40
}
 
41
 
 
42
{
 
43
    my $p0 = Slic3r::Point->new(76975850,89989996);
 
44
    my $p1 = Slic3r::Point->new(76989990,109989991);
 
45
    my $p2 = Slic3r::Point->new(76989987,89989994);
 
46
    ok $p0->ccw($p1, $p2) < 0, 'ccw() does not overflow';
 
47
}
 
48
 
 
49
{
 
50
    my $point = Slic3r::Point->new(15,15);
 
51
    my $line = Slic3r::Line->new([10,10], [20,10]);
 
52
    is_deeply $point->projection_onto_line($line)->pp, [15,10], 'project_onto_line';
 
53
    
 
54
    $point = Slic3r::Point->new(0, 15);
 
55
    is_deeply $point->projection_onto_line($line)->pp, [10,10], 'project_onto_line';
 
56
    
 
57
    $point = Slic3r::Point->new(25, 15);
 
58
    is_deeply $point->projection_onto_line($line)->pp, [20,10], 'project_onto_line';
 
59
    
 
60
    $point = Slic3r::Point->new(10,10);
 
61
    is_deeply $point->projection_onto_line($line)->pp, [10,10], 'project_onto_line';
 
62
    
 
63
    $point = Slic3r::Point->new(12, 10);
 
64
    is_deeply $point->projection_onto_line($line)->pp, [12,10], 'project_onto_line';
 
65
}
 
66
 
 
67
__END__