#!/usr/bin/perl
# Author: Dan Jacobson https://www.jidanni.org/
# Copyright: https://www.gnu.org/licenses/gpl.html
# Created: 2024-04-25T21:54:41+0000
# Last-Updated: 2024-05-13T20:26:06+0000
#     Update #: 105
#

=head1 NAME

Dotrow - Make rows of address grid ticls

=head1 DESCRIPTION

Make rows of grid ticks, dealing only at the address level,
We don't have anything to do with PLSS ids or lon/lat in this module.

=cut

use strict;
use warnings q(all);

package Dotrow;

=head1 drp

Output is even more complicated than input... stay away!

my %spec = (
    xy => [

        #For these house number ranges, one column every jump numbers, with a point every freq along them.
        { low => -1600, high => 800,  jump => 800, freq => 100 },
        { low => 2400,  high => 3600, jump => 800, freq => 100 },
    ],
    scales => [ 1, 2 ],    #for these inverse map zoom-like scales
    axes   => [ 0, 1 ]     #and rarely sometimes only for one axis.
);

drp( \%spec );

#prints:
-1500, 2400, 2400 - 1500, 2600, 2600 - 1500, 2800, 2800 ...

=cut

use Data::Dumper;

sub drp {
    my @m = roz(@_);
    for (@m) {
        print join ",", @$_;
        print $/;
    }
}

=head1 roz

roz returns just the data, without printing it. See above.

=cut

sub roz {
    my %n = (@_);
    my @o;
    for my $scale ( @{ $n{scales} } ) {
        for my $c ( 0, 1 ) {
            for (qw/jump freq/) {
                $n{xy}[$c]{$_} *= $scale;
            }
        }
    }

    for ( @{ $n{axes} }[0] || ( 0, 1 ) ) {
        my %x = %{ $n{xy}[$_] };
        my %y = %{ $n{xy}[ !$_ ] };
        for ( my $x = $x{low} ; $x <= $x{high} ; $x += $x{jump} ) {
            for ( my $y = $y{low} ; $y <= $y{high} ; $y += $y{freq} ) {

                #                push @o, [ $x + $x{freq} / 2, $y, $_ ? $x : $y ];
                push @o,
                  [
                    $x + $x{freq} / 2,
                    $y, NSEW( ( $_ ? $x : $y ) . ( $_ ? "E" : "N" ) )
                  ];
            }
        }
    }
    return @o;
}

sub NSEW {    #quick way to keep what we show making sense
    my $s = $_[0];
    for ($s) {
        s/-(.*)E/$1W/
          || s/-(.*)N/$1S/;
    }
    return $s;
}

1;
