fix regex parse in sh/dx, add DXBearing::distance
authorDirk Koopman <djk@tobit.co.uk>
Wed, 3 Jun 2020 19:42:27 +0000 (20:42 +0100)
committerDirk Koopman <djk@tobit.co.uk>
Wed, 3 Jun 2020 19:42:27 +0000 (20:42 +0100)
cmd/show/dx.pl
perl/DXBearing.pm

index c0c43fa35c50b866a5f865aeca22dfa7109f32cf..655630ce798b24baee204c2899230095b2db3b90 100644 (file)
@@ -11,10 +11,20 @@ sub handle
 {
        my ($self, $line) = @_;
 
+       # disguise regexes
+       $line =~ s/\{(.*)\}/'{'. unpack('H*', $1) . '}'/eg;
+       dbg("sh/dx disguise any regex: '$line'") if isdbg('sh/dx');
+
+       # now space out brackets and !
        $line =~ s/([\(\!\)])/ $1 /g;
        
        my @list = split /[\s]+/, $line; # split the line up
 
+       # put back the regexes 
+       @list = map { my $l = $_; $l =~ s/\{([0-9a-fA-F]+)\}/'{' . pack('H*', $1) . '}'/eg; $l } @list;
+
+       dbg("sh/dx after regex return: " . join(' ', @list)) if isdbg('sh/dx');
+       
        my @out;
        my $f;
        my $call = $self->call;
index b98d746a5b5c88d4e2df409068ad43dd312aae2b..db6f4686d0a75ed89c32e0c32e28509ae233bb5a 100644 (file)
@@ -101,6 +101,20 @@ sub bdist
        return (rd($az), $dx);
 }
 
+# just the distance - parameters as above
+sub distance
+{
+       my $hn = dr(shift);
+       my $he = dr(shift);
+       my $n = dr(shift);
+       my $e = dr(shift);
+       return (0, 0) if $hn == $n && $he == $e;
+       my $co = cos($he-$e)*cos($hn)*cos($n)+sin($hn)*sin($n);
+       my $ca = $co ? atan(abs(sqrt(1-$co*$co)/$co)) : $pi;
+       $ca = $pi-$ca if $co < 0;
+       my $dx = 6367*$ca;
+}
+
 # turn a lat long string into floating point lat and long
 sub stoll
 {