Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

v0.006004 #16

Merged
merged 1 commit into from
Jun 5, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions CHANGES
Original file line number Diff line number Diff line change
@@ -1,5 +1,10 @@
Revision history for Perl distribution Win32-Mechanize-NotepadPlusPlus

v0.006004 2024-Jun-05
- Update test suite for "20-math.t":
only test the results within certain precision
(thus preventing quadmath failures) (#15)

v0.006003 2024-May-12
- Update test suite for "formatstl_load.t":
The non-seekable test doesn't work on netbsd,
Expand Down
2 changes: 1 addition & 1 deletion lib/CAD/Mesh3D.pm
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ use Carp;
use 5.010; # M::V::R requires 5.010, so might as well make use of the defined-or // notation :-)
use Math::Vector::Real 0.18;
use CAD::Format::STL qw//;
our $VERSION = '0.006003';
our $VERSION = '0.006004';

=head1 NAME

Expand Down
2 changes: 1 addition & 1 deletion lib/CAD/Mesh3D/STL.pm
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ use Carp;
use 5.010; # M::V::R requires 5.010, so might as well make use of the defined-or // notation :-)
use CAD::Format::STL qw//;
use CAD::Mesh3D qw/:create/;
our $VERSION = '0.006003'; # auto-populated from CAD::Mesh3D
our $VERSION = '0.006004'; # auto-populated from CAD::Mesh3D

# start by deciding which formatter to use
our $STL_FORMATTER;
Expand Down
33 changes: 20 additions & 13 deletions t/20-math.t
Original file line number Diff line number Diff line change
Expand Up @@ -20,25 +20,32 @@ my $flft = createFacet( $mid, $lft, $top );

my $m = createMesh( $fbot, $ffrn, $frgt, $flft );

is_deeply( unitDelta([ +1, +1, +1], [ +1, +1, +1]), [ 0, 0, 0], 'unitDelta(< +1, +1, +1>, < +1, +1, +1>)');
is_deeply( unitDelta([ +1, +1, +1], [ +3, +3, +3]), [+sqrt(1/3),+sqrt(1/3),+sqrt(1/3)], 'unitDelta(< +1, +1, +1>, < +3, +3, +3>)');
is_deeply( $vthr->unitDelta( [ +1, +1, +1]), [-sqrt(1/3),-sqrt(1/3),-sqrt(1/3)], 'v(< +3, +3, +3>)->unitDelta(< +1, +1, +1>)');
is_array_to_precision( unitDelta([ +1, +1, +1], [ +1, +1, +1]), [ 0, 0, 0], 7, 'unitDelta(< +1, +1, +1>, < +1, +1, +1>)');
is_array_to_precision( unitDelta([ +1, +1, +1], [ +3, +3, +3]), [+sqrt(1/3),+sqrt(1/3),+sqrt(1/3)], 7, 'unitDelta(< +1, +1, +1>, < +3, +3, +3>)');
is_array_to_precision( $vthr->unitDelta( [ +1, +1, +1]), [-sqrt(1/3),-sqrt(1/3),-sqrt(1/3)], 7, 'v(< +3, +3, +3>)->unitDelta(< +1, +1, +1>)');

is_deeply( unitCross([ +1, +1, +1], [ +3, +3, +3]), [ 0, 0, 0], 'unitCross(< +1, +1, +1>, < +3, +3, +3>)');
is_deeply( unitCross([ -4, +1, +1], [ -6, +1, +2]), [ 1/3, 2/3, 2/3], 'unitCross(< -4, +1, +1>, < -6, +1, +2>)');
is_deeply( unitCross([ -6, +1, +2], [ -4, +1, +1]), [ -1/3, -2/3, -2/3], 'unitCross(< -6, +1, +2>, < -4, +1, +1>)');
is_deeply( unitCross([ +12,-149,-132], [ +12, +31, +12]), [ 0.64, -0.48, 0.60], 'unitCross(< +12,-149,-132>, < +12, +31, +12>)');
is_deeply( $va->unitCross( [ +12,-149,-132]), [ -0.64, +0.48, -0.60], 'v(< +12, +31, +12>)->unitCross(< +12,-149,-132>)');
is_array_to_precision( unitCross([ +1, +1, +1], [ +3, +3, +3]), [ 0, 0, 0], 7, 'unitCross(< +1, +1, +1>, < +3, +3, +3>)');
is_array_to_precision( unitCross([ -4, +1, +1], [ -6, +1, +2]), [ 1/3, 2/3, 2/3], 7, 'unitCross(< -4, +1, +1>, < -6, +1, +2>)');
is_array_to_precision( unitCross([ -6, +1, +2], [ -4, +1, +1]), [ -1/3, -2/3, -2/3], 7, 'unitCross(< -6, +1, +2>, < -4, +1, +1>)');
is_array_to_precision( unitCross([ +12,-149,-132], [ +12, +31, +12]), [ 0.64, -0.48, 0.60], 7, 'unitCross(< +12,-149,-132>, < +12, +31, +12>)');
is_array_to_precision( $va->unitCross( [ +12,-149,-132]), [ -0.64, +0.48, -0.60], 7, 'v(< +12, +31, +12>)->unitCross(< +12,-149,-132>)');

is_deeply( unitNormal( @$fbot ), [+sqrt(0/9),+sqrt(0/9),-sqrt(9/9)], 'unitNormal(lft, mid, rgt)' );
is_deeply( facetNormal( $ffrn ), [+sqrt(0/9),-sqrt(8/9),+sqrt(1/9)], 'facetNormal(front)' );
is_deeply( facetNormal( $frgt ), [+sqrt(6/9),+sqrt(2/9),+sqrt(1/9)], 'facetNormal(right)' );
is_deeply( $flft->normal(), [-sqrt(6/9),+sqrt(2/9),+sqrt(1/9)], 'facet->normal(left)' );
is_array_to_precision( unitNormal( @$fbot ), [+sqrt(0/9),+sqrt(0/9),-sqrt(9/9)], 7, 'unitNormal(lft, mid, rgt)' );
is_array_to_precision( facetNormal( $ffrn ), [+sqrt(0/9),-sqrt(8/9),+sqrt(1/9)], 7, 'facetNormal(front)' );
is_array_to_precision( facetNormal( $frgt ), [+sqrt(6/9),+sqrt(2/9),+sqrt(1/9)], 7, 'facetNormal(right)' );
is_array_to_precision( $flft->normal(), [-sqrt(6/9),+sqrt(2/9),+sqrt(1/9)], 7, 'facet->normal(left)' );

# error handling:
throws_ok { $m->unitDelta($top,$mid) } qr/\Qusage: unitDelta\E/, 'Error Handling: m->unitDelta(...): no mesh method calls to :math';
throws_ok { $m->unitCross($top,$mid) } qr/\Qusage: unitCross\E/, 'Error Handling: m->unitCross(...): no mesh method calls to :math';
throws_ok { $m->facetNormal( $frgt ) } qr/\Qusage: facetNormal\E/, 'Error Handling: m->facetNormal(...): no mesh method calls to :math';
throws_ok { $m->unitNormal( @$frgt ) } qr/\Qusage: unitNormal\E/, 'Error Handling: m->unitNormal(...): no mesh method calls to :math';

done_testing();
done_testing();

sub is_array_to_precision {
my ($got, $expected, $precision, $name) = @_;
my $pgot = [ map { sprintf '%.*f', $precision, $_ } @$got ];
my $pexp = [ map { sprintf '%.*f', $precision, $_ } @$expected ];
return is_deeply $pgot, $pexp, $name;
}
Loading