/usr/share/perl5/Math/NumSeq/PlanePathTurn.pm is in libmath-planepath-perl 122-1.
This file is owned by root:root, with mode 0o644.
The actual contents of the file can be viewed below.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 519 520 521 522 523 524 525 526 527 528 529 530 531 532 533 534 535 536 537 538 539 540 541 542 543 544 545 546 547 548 549 550 551 552 553 554 555 556 557 558 559 560 561 562 563 564 565 566 567 568 569 570 571 572 573 574 575 576 577 578 579 580 581 582 583 584 585 586 587 588 589 590 591 592 593 594 595 596 597 598 599 600 601 602 603 604 605 606 607 608 609 610 611 612 613 614 615 616 617 618 619 620 621 622 623 624 625 626 627 628 629 630 631 632 633 634 635 636 637 638 639 640 641 642 643 644 645 646 647 648 649 650 651 652 653 654 655 656 657 658 659 660 661 662 663 664 665 666 667 668 669 670 671 672 673 674 675 676 677 678 679 680 681 682 683 684 685 686 687 688 689 690 691 692 693 694 695 696 697 698 699 700 701 702 703 704 705 706 707 708 709 710 711 712 713 714 715 716 717 718 719 720 721 722 723 724 725 726 727 728 729 730 731 732 733 734 735 736 737 738 739 740 741 742 743 744 745 746 747 748 749 750 751 752 753 754 755 756 757 758 759 760 761 762 763 764 765 766 767 768 769 770 771 772 773 774 775 776 777 778 779 780 781 782 783 784 785 786 787 788 789 790 791 792 793 794 795 796 797 798 799 800 801 802 803 804 805 806 807 808 809 810 811 812 813 814 815 816 817 818 819 820 821 822 823 824 825 826 827 828 829 830 831 832 833 834 835 836 837 838 839 840 841 842 843 844 845 846 847 848 849 850 851 852 853 854 855 856 857 858 859 860 861 862 863 864 865 866 867 868 869 870 871 872 873 874 875 876 877 878 879 880 881 882 883 884 885 886 887 888 889 890 891 892 893 894 895 896 897 898 899 900 901 902 903 904 905 906 907 908 909 910 911 912 913 914 915 916 917 918 919 920 921 922 923 924 925 926 927 928 929 930 931 932 933 934 935 936 937 938 939 940 941 942 943 944 945 946 947 948 949 950 951 952 953 954 955 956 957 958 959 960 961 962 963 964 965 966 967 968 969 970 971 972 973 974 975 976 977 978 979 980 981 982 983 984 985 986 987 988 989 990 991 992 993 994 995 996 997 998 999 1000 1001 1002 1003 1004 1005 1006 1007 1008 1009 1010 1011 1012 1013 1014 1015 1016 1017 1018 1019 1020 1021 1022 1023 1024 1025 1026 1027 1028 1029 1030 1031 1032 1033 1034 1035 1036 1037 1038 1039 1040 1041 1042 1043 1044 1045 1046 1047 1048 1049 1050 1051 1052 1053 1054 1055 1056 1057 1058 1059 1060 1061 1062 1063 1064 1065 1066 1067 1068 1069 1070 1071 1072 1073 1074 1075 1076 1077 1078 1079 1080 1081 1082 1083 1084 1085 1086 1087 1088 1089 1090 1091 1092 1093 1094 1095 1096 1097 1098 1099 1100 1101 1102 1103 1104 1105 1106 1107 1108 1109 1110 1111 1112 1113 1114 1115 1116 1117 1118 1119 1120 1121 1122 1123 1124 1125 1126 1127 1128 1129 1130 1131 1132 1133 1134 1135 1136 1137 1138 1139 1140 1141 1142 1143 1144 1145 1146 1147 1148 1149 1150 1151 1152 1153 1154 1155 1156 1157 1158 1159 1160 1161 1162 1163 1164 1165 1166 1167 1168 1169 1170 1171 1172 1173 1174 1175 1176 1177 1178 1179 1180 1181 1182 1183 1184 1185 1186 1187 1188 1189 1190 1191 1192 1193 1194 1195 1196 1197 1198 1199 1200 1201 1202 1203 1204 1205 1206 1207 1208 1209 1210 1211 1212 1213 1214 1215 1216 1217 1218 1219 1220 1221 1222 1223 1224 1225 1226 1227 1228 1229 1230 1231 1232 1233 1234 1235 1236 1237 1238 1239 1240 1241 1242 1243 1244 1245 1246 1247 1248 1249 1250 1251 1252 1253 1254 1255 1256 1257 1258 1259 1260 1261 1262 1263 1264 1265 1266 1267 1268 1269 1270 1271 1272 1273 1274 1275 1276 1277 1278 1279 1280 1281 1282 1283 1284 1285 1286 1287 1288 1289 1290 1291 1292 1293 1294 1295 1296 1297 1298 1299 1300 1301 1302 1303 1304 1305 1306 1307 1308 1309 1310 1311 1312 1313 1314 1315 1316 1317 1318 1319 1320 1321 1322 1323 1324 1325 1326 1327 1328 1329 1330 1331 1332 1333 1334 1335 1336 1337 1338 1339 1340 1341 1342 1343 1344 1345 1346 1347 1348 1349 1350 1351 1352 1353 1354 1355 1356 1357 1358 1359 1360 1361 1362 1363 1364 1365 1366 1367 1368 1369 1370 1371 1372 1373 1374 1375 1376 1377 1378 1379 1380 1381 1382 1383 1384 1385 1386 1387 1388 1389 1390 1391 1392 1393 1394 1395 1396 1397 1398 1399 1400 1401 1402 1403 1404 1405 1406 1407 1408 1409 1410 1411 1412 1413 1414 1415 1416 1417 1418 1419 1420 1421 1422 1423 1424 1425 1426 1427 1428 1429 1430 1431 1432 1433 1434 1435 1436 1437 1438 1439 1440 1441 1442 1443 1444 1445 1446 1447 1448 1449 1450 1451 1452 1453 1454 1455 1456 1457 1458 1459 1460 1461 1462 1463 1464 1465 1466 1467 1468 1469 1470 1471 1472 1473 1474 1475 1476 1477 1478 1479 1480 1481 1482 1483 1484 1485 1486 1487 1488 1489 1490 1491 1492 1493 1494 1495 1496 1497 1498 1499 1500 1501 1502 1503 1504 1505 1506 1507 1508 1509 1510 1511 1512 1513 1514 1515 1516 1517 1518 1519 1520 1521 1522 1523 1524 1525 1526 1527 1528 1529 1530 1531 1532 1533 1534 1535 1536 1537 1538 1539 1540 1541 1542 1543 1544 1545 1546 1547 1548 1549 1550 1551 1552 1553 1554 1555 1556 1557 1558 1559 1560 1561 1562 1563 1564 1565 1566 1567 1568 1569 1570 1571 1572 1573 1574 1575 1576 1577 1578 1579 1580 1581 1582 1583 1584 1585 1586 1587 1588 1589 1590 1591 1592 1593 1594 1595 1596 1597 1598 1599 1600 1601 1602 1603 1604 1605 1606 1607 1608 1609 1610 1611 1612 1613 1614 1615 1616 1617 1618 1619 1620 1621 1622 1623 1624 1625 1626 1627 1628 1629 1630 1631 1632 1633 1634 1635 1636 1637 1638 1639 1640 1641 1642 1643 1644 1645 1646 1647 1648 1649 1650 1651 1652 1653 1654 1655 1656 1657 1658 1659 1660 1661 1662 1663 1664 1665 1666 1667 1668 1669 1670 1671 1672 1673 1674 1675 1676 1677 1678 1679 1680 1681 1682 1683 1684 1685 1686 1687 1688 1689 1690 1691 1692 1693 1694 1695 1696 1697 1698 1699 1700 1701 1702 1703 1704 1705 1706 1707 1708 1709 1710 1711 1712 1713 1714 1715 1716 1717 1718 1719 1720 1721 1722 1723 1724 1725 1726 1727 1728 1729 1730 1731 1732 1733 1734 1735 1736 1737 1738 1739 1740 1741 1742 1743 1744 1745 1746 1747 1748 1749 1750 1751 1752 1753 1754 1755 1756 1757 1758 1759 1760 1761 1762 1763 1764 1765 1766 1767 1768 1769 1770 1771 1772 1773 1774 1775 1776 1777 1778 1779 1780 1781 1782 1783 1784 1785 1786 1787 1788 1789 1790 1791 1792 1793 1794 1795 1796 1797 1798 1799 1800 1801 1802 1803 1804 1805 1806 1807 1808 1809 1810 1811 1812 1813 1814 1815 1816 1817 1818 1819 1820 1821 1822 1823 1824 1825 1826 1827 1828 1829 1830 1831 1832 1833 1834 1835 1836 1837 1838 1839 1840 1841 1842 1843 1844 1845 1846 | # Copyright 2011, 2012, 2013, 2014, 2015 Kevin Ryde
# This file is part of Math-PlanePath.
#
# Math-PlanePath is free software; you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by the
# Free Software Foundation; either version 3, or (at your option) any later
# version.
#
# Math-PlanePath is distributed in the hope that it will be useful, but
# WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
# or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
# for more details.
#
# You should have received a copy of the GNU General Public License along
# with Math-PlanePath. If not, see <http://www.gnu.org/licenses/>.
# math-image --values=PlanePathTurn
#
# maybe:
# Turn4 0,1,2,3 and fractional
# Turn4n 0,1,2,-1 negatives Turn4mid Turn4n Turn4s
# TTurn6n 0,1,2,3, -1,-2, eg. flowsnake TTurn6s
# TTurn6 0,1,2,3,4,5
package Math::NumSeq::PlanePathTurn;
use 5.004;
use strict;
use Carp 'croak';
use vars '$VERSION','@ISA';
$VERSION = 122;
use Math::NumSeq;
@ISA = ('Math::NumSeq');
use Math::NumSeq::PlanePathCoord;
use Math::PlanePath;
use Math::PlanePath::Base::Generic
'is_infinite';
use Math::NumSeq::PlanePathDelta;
# uncomment this to run the ### lines
# use Smart::Comments;
use constant characteristic_smaller => 1;
sub description {
my ($self) = @_;
if (ref $self) {
return "Turn values $self->{'turn_type'} from path $self->{'planepath'}";
} else {
# class method
return 'Turns from a PlanePath';
}
}
use constant::defer parameter_info_array =>
sub {
return [
Math::NumSeq::PlanePathCoord::_parameter_info_planepath(),
{
name => 'turn_type',
display => 'Turn Type',
type => 'enum',
default => 'Left',
choices => ['Left','Right','Straight',
'LSR','SLR','SRL',
# 'NotStraight',
# 'Straight',
# 'RSL',
# 'Turn4', # Turn4 is 0<=value<4.
# 'Turn4n',
# 'TTurn6',
],
description => 'Left is 1=left, 0=right or straight.
Right is 1=right, 0=left or straight.
LSR is 1=left,0=straight,-1=right.
SLR is 0=straight,1=left,2=right.
SRL is 0=straight,1=right,2=left.',
},
];
};
sub characteristic_integer {
my ($self) = @_;
my $planepath_object = $self->{'planepath_object'};
if (my $func = $planepath_object->can("_NumSeq_Turn_$self->{'turn_type'}_integer")) {
return $planepath_object->$func();
}
return undef;
}
#------------------------------------------------------------------------------
sub oeis_anum {
my ($self) = @_;
### PlanePathTurn oeis_anum() ...
my $planepath = $self->{'planepath_object'};
my $key = Math::NumSeq::PlanePathCoord::_planepath_oeis_anum_key($self->{'planepath_object'});
### planepath: ref $planepath
### $key
### whole table: $planepath->_NumSeq_Turn_oeis_anum
### key href: $planepath->_NumSeq_Turn_oeis_anum->{$key}
return $planepath->_NumSeq_Turn_oeis_anum->{$key}->{$self->{'turn_type'}};
}
#------------------------------------------------------------------------------
sub new {
### PlanePathTurn new(): @_
my $self = shift->SUPER::new(@_);
### self from SUPER: $self
$self->{'planepath_object'}
||= Math::NumSeq::PlanePathCoord::_planepath_name_to_object($self->{'planepath'});
### turn_func: "_turn_func_$self->{'turn_type'}", $self->{'turn_func'}
$self->{'turn_func'} = $self->can('_turn_func_'.$self->{'turn_type'})
|| croak "Unrecognised turn_type: ",$self->{'turn_type'};
$self->rewind;
### $self
return $self;
}
sub i_start {
my ($self) = @_;
my $planepath_object = $self->{'planepath_object'} || return 0;
return $planepath_object->n_start + $planepath_object->arms_count;
}
sub rewind {
my ($self) = @_;
my $planepath_object = $self->{'planepath_object'} || return;
$self->{'i'} = $self->i_start;
$self->{'arms'} = $planepath_object->arms_count;
undef $self->{'prev_dx'};
}
sub next {
my ($self) = @_;
### NumSeq-PlanePathTurn next(): "i=$self->{'i'}"
my $planepath_object = $self->{'planepath_object'};
my $i = $self->{'i'}++;
my $arms = $self->{'arms'};
my $prev_dx = $self->{'prev_dx'};
my $prev_dy;
if (defined $prev_dx) {
$prev_dy = $self->{'prev_dy'};
### use prev dxdy: "$prev_dx,$prev_dy"
} else {
($prev_dx, $prev_dy) = $planepath_object->n_to_dxdy($i-$arms)
or do {
### nothing in path at n: $i
return;
};
### calc prev dxdy: "at i=".($i-$arms)." $prev_dx,$prev_dy"
}
my ($dx, $dy) = $planepath_object->n_to_dxdy($i)
or do {
### nothing in path at previous n: $i-$arms
return;
};
### calc dxdy: "at i=$i $dx,$dy"
if ($arms == 1) {
$self->{'prev_dx'} = $dx;
$self->{'prev_dy'} = $dy;
}
return ($i, $self->{'turn_func'}->($prev_dx,$prev_dy, $dx,$dy));
}
sub ith {
my ($self, $i) = @_;
### PlanePathTurn ith(): $i
if (is_infinite($i)) {
return undef;
}
my $planepath_object = $self->{'planepath_object'};
my $arms = $self->{'arms'};
my ($prev_dx, $prev_dy) = $planepath_object->n_to_dxdy($i - $arms)
or return undef;
my ($dx, $dy) = $planepath_object->n_to_dxdy($i)
or return undef;
return $self->{'turn_func'}->($prev_dx,$prev_dy, $dx,$dy);
}
# dx1,dy1
# dx2,dy2 /
# * /
# /
# /
# /
# /
# O
#
# cmpy = dx2 * dy1/dx1
# left if dy2 > cmpy
# dy2 > dx2 * dy1/dx1
# dy2 * dx1 > dx2 * dy1
#
# if dx1=0, dy1 > 0 then left if dx2 < 0
# dy2 * 0 > dx2 * dy1
# 0 > dx2*dy1 good
#
sub _turn_func_Left {
my ($dx,$dy, $next_dx,$next_dy) = @_;
### _turn_func_Left() ...
return ($next_dy * $dx > $next_dx * $dy ? 1 : 0);
}
sub _turn_func_Right {
my ($dx,$dy, $next_dx,$next_dy) = @_;
### _turn_func_Right() ...
return ($next_dy * $dx < $next_dx * $dy ? 1 : 0);
}
sub _turn_func_LSR {
my ($dx,$dy, $next_dx,$next_dy) = @_;
### _turn_func_LSR() ...
return (($next_dy * $dx <=> $next_dx * $dy) || 0); # 1,0,-1
}
sub _turn_func_RSL {
return - _turn_func_LSR(@_);
}
{
my @LSR_to_SLR = (0, # LSR=0 straight -> SLR=0
1, # LSR=1 left -> SLR=1
2); # LSR=-1 right -> SLR=2
sub _turn_func_SLR {
return $LSR_to_SLR[_turn_func_LSR(@_)];
}
}
{
my @LSR_to_SRL = (0, # LSR=0 straight -> SRL=0
2, # LSR=1 left -> SRL=2
1); # LSR=-1 right -> SRL=1
sub _turn_func_SRL {
return $LSR_to_SRL[_turn_func_LSR(@_)];
}
}
sub _turn_func_Straight {
my ($dx,$dy, $next_dx,$next_dy) = @_;
### _turn_func_Left() ...
return ($next_dy * $dx == $next_dx * $dy ? 1 : 0);
}
sub _turn_func_NotStraight {
my ($dx,$dy, $next_dx,$next_dy) = @_;
### _turn_func_Left() ...
return ($next_dy * $dx == $next_dx * $dy ? 0 : 1);
}
# sub _turn_func_LR_01 {
# my ($dx,$dy, $next_dx,$next_dy) = @_;
# ### _turn_func_LR_01() ...
# return ($next_dy * $dx >= $next_dx * $dy || 0);
# }
sub _turn_func_Turn4 {
my ($dx,$dy, $next_dx,$next_dy) = @_;
### _turn_func_Turn4(): "$dx,$dy $next_dx,$next_dy"
return
(((Math::NumSeq::PlanePathDelta::_delta_func_Dir360($next_dx,$next_dy)
- Math::NumSeq::PlanePathDelta::_delta_func_Dir360($dx,$dy)) % 360)
/ 90);
}
sub _turn_func_Turn4n {
my ($dx,$dy, $next_dx,$next_dy) = @_;
require Math::NumSeq::PlanePathDelta;
my $ret
= (((Math::NumSeq::PlanePathDelta::_delta_func_Dir360($next_dx,$next_dy)
- Math::NumSeq::PlanePathDelta::_delta_func_Dir360($dx,$dy)) % 360)
/ 90);
if ($ret > 2) { $ret -= 4; }
return $ret;
}
sub _turn_func_TTurn6 {
my ($dx,$dy, $next_dx,$next_dy) = @_;
require Math::NumSeq::PlanePathDelta;
return
(((Math::NumSeq::PlanePathDelta::_delta_func_TDir360($next_dx,$next_dy)
- Math::NumSeq::PlanePathDelta::_delta_func_TDir360($dx,$dy)) % 360)
/ 60);
}
sub pred {
my ($self, $value) = @_;
### PlanePathTurn pred(): $value
my $planepath_object = $self->{'planepath_object'};
if (defined (my $values_min = $self->values_min)) {
if ($value < $values_min) {
return 0;
}
}
if (defined (my $values_max = $self->values_max)) {
if ($value > $values_max) {
return 0;
}
}
my $turn_type = $self->{'turn_type'};
if ($turn_type eq 'Left' || $turn_type eq 'Right' || $turn_type eq 'Straight') {
unless ($value == 0 || $value == 1) {
return 0;
}
} elsif ($turn_type eq 'LSR' || $turn_type eq 'RSL') {
unless ($value == 1 || $value == 0 || $value == -1) {
return 0;
}
} else { # ($turn_type eq 'SLR' || $turn_type eq 'SRL') {
unless ($value == 0 || $value == 1 || $value == 2) {
return 0;
}
}
if (my $func = $planepath_object->can('_NumSeq_Turn_'.$self->{'turn_type'}.'_pred_hash')) {
my $href = $self->$func();
unless ($href->{$value}) {
return 0;
}
}
return 1;
}
#------------------------------------------------------------------------------
sub values_min {
my ($self) = @_;
my $method = '_NumSeq_Turn_' . $self->{'turn_type'} . '_min';
return $self->{'planepath_object'}->can($method)
? $self->{'planepath_object'}->$method()
: undef;
}
sub values_max {
my ($self) = @_;
my $method = '_NumSeq_Turn_' . $self->{'turn_type'} . '_max';
return $self->{'planepath_object'}->can($method)
? $self->{'planepath_object'}->$method()
: undef;
}
sub characteristic_increasing {
my ($self) = @_;
my $planepath_object = $self->{'planepath_object'};
if (my $func = $planepath_object->can("_NumSeq_Turn_$self->{'turn_type'}_increasing")) {
return $planepath_object->$func();
}
return undef; # unknown
}
sub characteristic_non_decreasing {
my ($self) = @_;
my $planepath_object = $self->{'planepath_object'};
if (my $func = $planepath_object->can("_NumSeq_Turn_$self->{'turn_type'}_non_decreasing")) {
return $planepath_object->$func();
}
if (defined (my $values_min = $self->values_min)) {
if (defined (my $values_max = $self->values_max)) {
if ($values_min == $values_max) {
# constant seq is non-decreasing
return 1;
}
}
}
# increasing means non_decreasing too
return $self->characteristic_increasing;
}
# my $all_Left_predhash = { 0=>1, 1=>1 };
# my $all_LSR_predhash = { 0=>1, 1=>1, -1=>1 };
# my $straight_Left_predhash = { 0=>1 };
# my $straight_LSR_predhash = { 0=>1 };
{ package Math::PlanePath;
use constant 1.02; # for leading underscore
sub _NumSeq_Turn_Left_min {
my ($self) = @_;
return ($self->turn_any_right
|| $self->turn_any_straight ? 0 : 1);
}
sub _NumSeq_Turn_Left_max {
my ($self) = @_;
return ($self->turn_any_left ? 1 : 0);
}
use constant _NumSeq_Turn_Left_integer => 1;
sub _NumSeq_Turn_Right_min {
my ($self) = @_;
return ($self->turn_any_left
|| $self->turn_any_straight ? 0 : 1);
}
sub _NumSeq_Turn_Right_max {
my ($self) = @_;
return ($self->turn_any_right ? 1 : 0);
}
use constant _NumSeq_Turn_Right_integer => 1;
sub _NumSeq_Turn_Straight_min {
my ($self) = @_;
return ($self->turn_any_left
|| $self->turn_any_right ? 0 : 1);
}
sub _NumSeq_Turn_Straight_max {
my ($self) = @_;
return ($self->turn_any_straight ? 1 : 0);
}
use constant _NumSeq_Turn_Straight_integer => 1;
sub _NumSeq_Turn_LSR_min {
my ($self) = @_;
return ($self->turn_any_right ? -1
: $self->turn_any_straight ? 0
: 1); # only ever Left
}
sub _NumSeq_Turn_LSR_max {
my ($self) = @_;
return ($self->turn_any_left ? 1
: $self->turn_any_straight ? 0
: -1); # only ever Right
}
use constant _NumSeq_Turn_LSR_integer => 1;
sub _NumSeq_Turn_SLR_min {
my ($self) = @_;
return ($self->turn_any_straight ? 0
: $self->turn_any_left ? 1
: 2); # only ever Right
}
sub _NumSeq_Turn_SLR_max {
my ($self) = @_;
return ($self->turn_any_right ? 2
: $self->_NumSeq_Turn_Left_max); # 1 if any Left
}
use constant _NumSeq_Turn_SLR_integer => 1;
sub _NumSeq_Turn_SRL_min {
my ($self) = @_;
return ($self->turn_any_straight ? 0
: $self->turn_any_right ? 1
: 2); # only ever Left
}
sub _NumSeq_Turn_SRL_max {
my ($self) = @_;
return ($self->turn_any_left ? 2
: $self->_NumSeq_Turn_Right_max); # 1 if any Right
}
use constant _NumSeq_Turn_SRL_integer => 1;
use constant _NumSeq_Turn_Turn4_min => 0;
sub _NumSeq_Turn_Turn4_integer {
my ($self) = @_;
return $self->_NumSeq_Delta_Dir4_integer;
}
sub _NumSeq_Turn_Turn4_max {
my ($self) = @_;
return ($self->_NumSeq_Turn_Turn4_integer ? 3 : 4);
}
use constant _NumSeq_Turn_oeis_anum => {};
}
# { package Math::PlanePath::SquareSpiral;
# # SquareSpiral
# # abs(A167752)==Left=LSR=Turn4 if that really is the quarter-squares
# # abs(A167753)==Left=LSR=Turn4 of wider=1 if that really is the ceil(n+1)^2
# }
{ package Math::PlanePath::GreekKeySpiral;
sub _NumSeq_Turn_Turn4_max {
my ($self) = @_;
return ($self->{'turns'} == 0
? 1 # SquareSpiral, left or straight only
: 3); # otherwise turn right too
}
}
{ package Math::PlanePath::PyramidSpiral;
use constant _NumSeq_Turn_Turn4_max => 1.5;
}
{ package Math::PlanePath::TriangleSpiral;
use constant _NumSeq_Turn_Turn4_max => 1.5;
use constant _NumSeq_Turn_oeis_anum =>
{ 'n_start=-1' =>
{ Left => 'A023531', # 1 at k*(k+3)/2
LSR => 'A023531',
Straight => 'A023532', # 0 at k*(k+3)/2, 1 otherwise
# OEIS-Other: A023531 planepath=TriangleSpiral,n_start=-1
# OEIS-Other: A023531 planepath=TriangleSpiral,n_start=-1 turn_type=LSR
# OEIS-Other: A023532 planepath=TriangleSpiral,n_start=-1 turn_type=Straight
},
# PlanePathTurn planepath=TriangleSpiral,n_start=1, turn_type=TTurn6
# A089799 Expansion of Jacobi theta function theta_2(q^(1/2))/q^(1/8)
# is this 2s with runs of 0s ?
};
}
{ package Math::PlanePath::TriangleSpiralSkewed;
use constant _NumSeq_Turn_Turn4_max => 1.5;
use constant _NumSeq_Turn_oeis_anum =>
{
do {
my $href = { Left => 'A023531', # 1 at k*(k+3)/2
LSR => 'A023531',
Straight => 'A023532', # 0 at k*(k+3)/2, 1 otherwise
};
('skew=left,n_start=-1' => $href,
'skew=right,n_start=-1' => $href,
'skew=up,n_start=-1' => $href,
'skew=down,n_start=-1' => $href)
# OEIS-Other: A023531 planepath=TriangleSpiralSkewed,n_start=-1
# OEIS-Other: A023531 planepath=TriangleSpiralSkewed,n_start=-1 turn_type=LSR
# OEIS-Other: A023532 planepath=TriangleSpiralSkewed,n_start=-1 turn_type=Straight
# OEIS-Other: A023531 planepath=TriangleSpiralSkewed,n_start=-1,skew=right
# OEIS-Other: A023531 planepath=TriangleSpiralSkewed,n_start=-1,skew=up
# OEIS-Other: A023531 planepath=TriangleSpiralSkewed,n_start=-1,skew=down
},
};
}
{ package Math::PlanePath::DiamondSpiral;
use constant _NumSeq_Turn_Turn4_max => 1.5;
}
{ package Math::PlanePath::AztecDiamondRings;
use constant _NumSeq_Turn_Turn4_max => 1; # left or straight
}
{ package Math::PlanePath::PentSpiral;
use constant _NumSeq_Turn_Turn4_max =>
Math::NumSeq::PlanePathTurn::_turn_func_Turn4(2,0, -2,1);
}
{ package Math::PlanePath::PentSpiralSkewed;
use constant _NumSeq_Turn_Turn4_max => 1.5;
}
{ package Math::PlanePath::HexSpiral;
use constant _NumSeq_Turn_Turn4_max => 1.5;
}
{ package Math::PlanePath::HexSpiralSkewed;
use constant _NumSeq_Turn_Turn4_max => 1.5;
}
{ package Math::PlanePath::HeptSpiralSkewed;
use constant _NumSeq_Turn_Turn4_max => 1.5; # at N=2 turn +135
}
{ package Math::PlanePath::AnvilSpiral;
use constant _NumSeq_Turn_Turn4_max => 3;
}
{ package Math::PlanePath::OctagramSpiral;
use constant _NumSeq_Turn_Turn4_max => 3; # +90 right
}
{ package Math::PlanePath::KnightSpiral;
# use constant _NumSeq_Turn_Turn4_min => ...; # 2,1
}
# { package Math::PlanePath::CretanLabyrinth;
# }
{ package Math::PlanePath::SquareArms;
use constant _NumSeq_Turn_Turn4_max => 1; # left or straight
}
{ package Math::PlanePath::DiamondArms;
use constant _NumSeq_Turn_Turn4_max => 1; # left or straight
use constant _NumSeq_Turn_Turn4_integer => 1;
}
{ package Math::PlanePath::HexArms;
use constant _NumSeq_Turn_Turn4_max => 1; # at N=8
}
{ package Math::PlanePath::SacksSpiral;
sub _NumSeq_Turn_Turn4_max {
my ($self) = @_;
# at N=1 is maximum turn
return Math::NumSeq::PlanePathTurn::_turn_func_Turn4(1,0,
$self->n_to_dxdy(1));
}
use constant _NumSeq_Turn4_min_is_infimum => 1;
use constant _NumSeq_Turn_oeis_anum =>
{ '' =>
{ 'Left' => 'A000012', # left always, all ones
'LSR' => 'A000012',
# OEIS-Other: A000012 planepath=SacksSpiral
# OEIS-Other: A000012 planepath=SacksSpiral turn_type=LSR
},
};
}
# { package Math::PlanePath::VogelFloret;
# }
{ package Math::PlanePath::TheodorusSpiral;
use constant _NumSeq_Turn4_min_is_infimum => 1; # approaches straight
use constant _NumSeq_Turn_Turn4_max => 1; # initial 90deg
use constant _NumSeq_Turn_oeis_anum =>
{ '' =>
{ 'Left' => 'A000012', # left always, all ones
'LSR' => 'A000012',
# OEIS-Other: A000012 planepath=TheodorusSpiral
# OEIS-Other: A000012 planepath=TheodorusSpiral turn_type=LSR
},
};
}
{ package Math::PlanePath::ArchimedeanChords;
sub _NumSeq_Turn_Turn4_max {
my ($self) = @_;
# at N=1 is maximum turn
return Math::NumSeq::PlanePathTurn::_turn_func_Turn4(1,0,
$self->n_to_dxdy(1));
}
use constant _NumSeq_Turn4_min_is_infimum => 1; # approaches straight ahead
use constant _NumSeq_Turn_oeis_anum =>
{ '' =>
{ 'Left' => 'A000012', # left always, all ones
'LSR' => 'A000012',
# OEIS-Other: A000012 planepath=ArchimedeanChords
# OEIS-Other: A000012 planepath=ArchimedeanChords turn_type=LSR
},
};
}
{ package Math::PlanePath::MultipleRings;
# step=1 and step=2 are mostly 1 for left, but after a while each ring
# endpoint is to the right
sub _NumSeq_Turn_Left_non_decreasing {
my ($self) = @_;
# step=0 always straight
# step=1 straight,straight, then always left
return ($self->{'step'} <= 1);
}
*_NumSeq_Turn_Right_non_decreasing = \&_NumSeq_Turn_Left_non_decreasing;
*_NumSeq_Turn_LSR_non_decreasing = \&_NumSeq_Turn_Left_non_decreasing;
*_NumSeq_Turn_SLR_non_decreasing = \&_NumSeq_Turn_Left_non_decreasing;
*_NumSeq_Turn_SRL_non_decreasing = \&_NumSeq_Turn_Left_non_decreasing;
sub _NumSeq_Turn_Turn4_max {
my ($self) = @_;
my $step = $self->{'step'};
return ($step == 0
? 0 # step == 0 is always straight ahead
: 4/$step);
}
use constant _NumSeq_Turn_oeis_anum =>
{
# MultipleRings step=0 is trivial X=N,Y=0
'step=0,ring_shape=circle' =>
{ Left => 'A000004', # all-zeros
LSR => 'A000004', # all zeros, straight
# OEIS-Other: A000004 planepath=MultipleRings,step=0
# OEIS-Other: A000004 planepath=MultipleRings,step=0 turn_type=LSR
},
'step=0,ring_shape=polygon' =>
{ Left => 'A000004', # all-zeros
LSR => 'A000004', # all zeros, straight
# OEIS-Other: A000004 planepath=MultipleRings,step=0,ring_shape=polygon
# OEIS-Other: A000004 planepath=MultipleRings,step=0,ring_shape=polygon turn_type=LSR
},
};
}
{ package Math::PlanePath::PixelRings;
# has right turns between rings
use constant _NumSeq_Turn_Turn4_max => 3.5;
}
{ package Math::PlanePath::FilledRings;
use constant _NumSeq_Turn_Turn4_max => 3.5;
}
{ package Math::PlanePath::Hypot;
sub _NumSeq_Turn4_min_is_infimum {
my ($self) = @_;
return ($self->{'points'} eq 'all');
}
{
my %_NumSeq_Turn_Turn4_max
= (all => 1.5, # at N=2, apparent maximum
even => 1.5, # at N=2, apparent maximum
odd => Math::NumSeq::PlanePathTurn::_turn_func_Turn4(3,-3, 3,5),
);
sub _NumSeq_Turn_Turn4_max {
my ($self) = @_;
return ($_NumSeq_Turn_Turn4_max{$self->{'points'}} || 0);
}
}
}
{ package Math::PlanePath::HypotOctant;
# apparently approaches +360 degrees
use constant _NumSeq_Turn4_max_is_supremum => 1;
}
{ package Math::PlanePath::TriangularHypot;
# points=even Turn4=0 at N=31
#
# points=all apparently approaches 0
# min i=473890[1303230202] 0.00000 px=-11,py=1 dx=-13,dy=1 -13.000
#
# points=odd apparently approaches 0
# min i=95618[113112002] 0.01111 px=-14,py=4 dx=-16,dy=4 -4.000
#
# points=hex apparently approaches 0
# min i=44243[22303103] 0.01111 px=-15,py=3 dx=-12,dy=2 -6.000
#
# points=hex_rotated Turn4=0 at N=58
# points=hex_centred Turn4=0 at N=24
{
my %_NumSeq_Turn4_min_is_infimum = (all => 1,
odd => 1,
hex => 1,
);
sub _NumSeq_Turn4_min_is_infimum {
my ($self) = @_;
return ($_NumSeq_Turn4_min_is_infimum{$self->{'points'}} || 0);
}
}
{
my %_NumSeq_Turn_Turn4_max
= (even => 1.5, # at N=2
odd => Math::NumSeq::PlanePathTurn::_turn_func_Turn4(5,3, 0,-6),
all => Math::NumSeq::PlanePathTurn::_turn_func_Turn4(5,3, 0,-6),
hex => Math::NumSeq::PlanePathTurn::_turn_func_Turn4(2,0, -3,1),
hex_rotated => Math::NumSeq::PlanePathTurn::_turn_func_Turn4(1,1, -3,-1),
hex_centred => Math::NumSeq::PlanePathTurn::_turn_func_Turn4(3,1, -2,2),
);
sub _NumSeq_Turn_Turn4_max {
my ($self) = @_;
return ($_NumSeq_Turn_Turn4_max{$self->{'points'}} || 0);
}
}
}
# { package Math::PlanePath::PythagoreanTree;
# # A000004 all-zeros and A000012 all-ones are OFFSET=0 which doesn't match
# # start N=1 here for always turn left or right in UAD.
# }
# { package Math::PlanePath::RationalsTree;
# # SB turn cf A021913 0,0,1,1
# # A133872 1,1,0,0
# # A057077 1,1,-1,-1
# # A087960 1,-1,-1,1
# # HCS turn left close to A010059 thue-morse or A092436
# # right A010060
# # LSR => 'A106400', # thue-morse +/-1
# # CfracDigits radix=1 likewise
# }
# { package Math::PlanePath::FractionsTree;
# }
# { package Math::PlanePath::ChanTree;
# # FIXME: k=4,5,6 are Right-only, maybe
# # sub _NumSeq_Turn_Left_max {
# # my ($self) = @_;
# # return ($self->{'k'} >= 4
# # ? 0 # never Left
# # : 1);
# # }
# # sub _NumSeq_Turn_Right_min {
# # my ($self) = @_;
# # return ($self->{'k'} >= 4
# # ? 1 # always Right
# # : 0);
# # }
# # sub _NumSeq_Turn_LSR_max {
# # my ($self) = @_;
# # return ($self->{'k'} >= 4
# # ? -1 # always Right
# # : 1);
# # }
# }
{ package Math::PlanePath::DiagonalRationals;
sub _NumSeq_Turn_Turn4_max {
my ($self) = @_;
return ($self->{'direction'} eq 'down'
? 2.5 # N=2
: Math::NumSeq::PlanePathTurn::_turn_func_Turn4(-1,1, 2,-1)); # N=3
}
}
# { package Math::PlanePath::FactorRationals;
# # revbinary
# # max i=296[10220] 3.98889 px=-258,py=1 dx=-26,dy=1[-122,1] -26.000
# N=295=5*59 X=5*59 Y=1 N=297
# N=296=2^3*37 X=37 Y=2 -26,+1 \ N=296 <-------- N=295
# N=297=3^3*11 X=11 Y=3 -258,+1
# }
{ package Math::PlanePath::GcdRationals;
# Turn4 minimum
# pairs_order=rows
# min=0 at N=12
# max i=216[3120] 3.98889 px=11,py=-14 dx=3,dy=-4[3,-10] -0.750
#
# pairs_order=rows_reverse
# min i=13[31] 0.00000 px=-1,py=0 dx=-1,dy=0 0.000
# max i=611[21203] 3.98889 px=-1,py=2 dx=-13,dy=28[-31,130] -0.464
#
# pairs_order=diagonals_down
# min i=2[2] 0.00000 px=0,py=1 dx=0,dy=1 0.000
# max i=561[20301] 3.98889 px=-7,py=8 dx=-5,dy=6[-11,12] -0.833
#
# pairs_order=diagonals_up
# min i=11[23] 0.00000 px=-1,py=1 dx=-1,dy=1 -1.000
# max i=4886[1030112] 3.98889 px=6,py=-6 dx=15,dy=-16[33,-100] -0.938
#
# Are these exact maximums or more when bigger N?
}
# { package Math::PlanePath::CfracDigits;
# }
{ package Math::PlanePath::AR2W2Curve; # NSEW+diag
use constant _NumSeq_Turn_Turn4_max => 3.5;
}
{ package Math::PlanePath::PeanoCurve;
use constant _NumSeq_Turn_oeis_anum =>
{ 'radix=3' =>
{
# 2---0---0---0---0---2
# | |
# 2---0---1 1---0---2
# | |
# .---0---1 1---0---0-...
SLR => 'A163536', # turn 0=ahead,1=left,2=right, OFFSET=1
SRL => 'A163537',
# OEIS-Catalogue: A163536 planepath=PeanoCurve turn_type=SLR
# OEIS-Catalogue: A163537 planepath=PeanoCurve turn_type=SRL
# Not quite, A039963 is OFFSET=0 vs first turn N=1 here
# Straight => 'A039963',
},
};
}
# { package Math::PlanePath::WunderlichSerpentine;
# }
{ package Math::PlanePath::HilbertCurve;
use constant _NumSeq_Turn_oeis_anum =>
{ '' =>
{ SLR => 'A163542', # relative direction ahead=0,left=1,right=2 OFFSET=1
SRL => 'A163543', # relative direction transpose
# OEIS-Catalogue: A163542 planepath=HilbertCurve turn_type=SLR
# OEIS-Catalogue: A163543 planepath=HilbertCurve turn_type=SRL
},
};
}
{ package Math::PlanePath::HilbertSides;
use constant _NumSeq_Turn_oeis_anum =>
{ '' =>
{ NotStraight => 'A035263', # morphism
# OEIS-Other: A035263 planepath=HilbertSides turn_type=NotStraight
# Not quite, OFFSET=0 but first turn here N=1.
# # OEIS-Other: A096268 planepath=HilbertSides turn_type=Straight
# Straight => 'A096268', # odd/even trailing 0 bits
},
};
}
{ package Math::PlanePath::ZOrderCurve;
sub _NumSeq_Turn_Turn4_min {
my ($self) = @_;
return ($self->{'radix'} == 2
? 0.5
: 0); # includes straight
}
# radix max at
# ----- ------
# 2 3 *---* Y=radix-1
# 3 8 \
# 4 15 \
# 5 24 * Y=0
sub _NumSeq_Turn_Turn4_max {
my ($self) = @_;
return (Math::NumSeq::PlanePathTurn::_turn_func_Turn4
(1,0, 1,1-$self->{'radix'}));
}
}
{ package Math::PlanePath::GrayCode;
# ENHANCE-ME: check this is true
# PlanePathTurn planepath=GrayCode,apply_type=TsF,gray_type=reflected,radix=2, turn_type=SLR
# PlanePathTurn planepath=GrayCode,apply_type=Fs,gray_type=reflected,radix=2, turn_type=SLR
# match 1,1,0,0,1,1,1,1,1,1,0,0,1,1,0,0,1,1,0,0,1,1,1,1,1,1
# A039963 The period-doubling sequence A035263 repeated.
# A039963 ,1,1,0,0,1,1,1,1,1,1,0,0,1,1,0,0,1,1,0,0,1,1,1,1,1,1
# Not quite, A039963 is OFFSET=0 vs first turn at N=1 here
# 'Math::PlanePath::GrayCode' =>
# {
# Left => 'A039963', # duplicated KochCurve
# LSR => 'A039963',
# },
# Koch characteristic of A003159 ending even zeros
# 'Math::PlanePath::GrayCode' =>
use constant _NumSeq_Turn_oeis_anum =>
{
do {
my $peano = Math::PlanePath::PeanoCurve
-> _NumSeq_Turn_oeis_anum -> {'radix=3'};
('apply_type=TsF,gray_type=reflected,radix=3' => $peano,
'apply_type=FsT,gray_type=reflected,radix=3' => $peano,
),
# OEIS-Other: A163536 planepath=GrayCode,apply_type=TsF,radix=3 turn_type=SLR
# OEIS-Other: A163536 planepath=GrayCode,apply_type=FsT,radix=3 turn_type=SLR
# OEIS-Other: A163537 planepath=GrayCode,apply_type=TsF,radix=3 turn_type=SRL
# OEIS-Other: A163537 planepath=GrayCode,apply_type=FsT,radix=3 turn_type=SRL
},
};
}
# { package Math::PlanePath::ImaginaryBase;
# }
# { package Math::PlanePath::ImaginaryHalf;
# }
# { package Math::PlanePath::CubicBase;
# }
# { package Math::PlanePath::Flowsnake;
# # inherit from FlowsnakeCentres
# }
{ package Math::PlanePath::FlowsnakeCentres;
use constant _NumSeq_Turn_Turn4_max => 3.5;
}
# { package Math::PlanePath::GosperIslands;
# }
{ package Math::PlanePath::KochCurve;
use constant _NumSeq_Turn_oeis_anum =>
{ '' =>
{ Left => 'A035263', # OFFSET=1 matches N=1
# OEIS-Catalogue: A035263 planepath=KochCurve
SLR => 'A056832',
# OEIS-Catalogue: A056832 planepath=KochCurve turn_type=SLR
# A056832 All a(n) = 1 or 2; a(1) = 1; get next 2^k terms by repeating first 2^k terms and changing last element so sum of first 2^(k+1) terms is odd.
# A056832 ,1,2,1,1,1,2,1,2,1,2,1,1,1,2,1
# Not quite, A096268 OFFSET=0 values 0,1,0,0,0,1
# whereas here N=1 first turn values 0,1,0,0,0,1
# Right => 'A096268', # morphism
},
};
}
# { package Math::PlanePath::KochPeaks;
# }
# { package Math::PlanePath::KochSnowflakes;
# }
# { package Math::PlanePath::KochSquareflakes;
# }
# { package Math::PlanePath::QuadricCurve;
# }
# { package Math::PlanePath::QuadricIslands;
# }
{ package Math::PlanePath::SierpinskiTriangle;
{
my %_NumSeq_Turn_Turn4_max = (triangular => 2.5,
left => 2.5,
right => 3,
diagonal => 2.5,
);
sub _NumSeq_Turn_Turn4_max {
my ($self) = @_;
return $_NumSeq_Turn_Turn4_max{$self->{'align'}};
}
}
}
{ package Math::PlanePath::SierpinskiArrowhead;
use constant _NumSeq_Turn_Turn4_min => 0.5; # North-East diagonal
use constant _NumSeq_Turn_Turn4_max => 3.5; # South-East diagonal
}
{ package Math::PlanePath::SierpinskiArrowheadCentres;
use constant _NumSeq_Turn_Turn4_max => 3.5; # South-East diagonal
}
# { package Math::PlanePath::SierpinskiCurve;
# # use constant _NumSeq_Turn_oeis_anum =>
# # { 'arms=1' =>
# # {
# # # Not quite, A039963 numbered OFFSET=0 whereas first turn at N=1 here
# # Right => 'A039963', # duplicated KochCurve turns
# # },
# # },
# # }
# }
{ package Math::PlanePath::SierpinskiCurveStair;
use constant _NumSeq_Turn_Turn4_min => 1; # never straight
}
{ package Math::PlanePath::DragonCurve;
use constant _NumSeq_Turn_Turn4_min => 1; # left or right only
use constant _NumSeq_Turn_oeis_anum =>
{ 'arms=1' =>
{
'LSR' => 'A034947', # Jacobi symbol (-1/n)
# OEIS-Catalogue: A034947 planepath=DragonCurve turn_type=LSR
Turn4 => 'A099545', # (odd part of n) mod 4
# OEIS-Catalogue: A099545 planepath=DragonCurve turn_type=Turn4
# 'L1R0' => 'A014577', # left=1,right=0 OFFSET=0
# 'L0R1' => 'A014707', # left=0,right=1 OFFSET=0
# 'L1R2' => 'A014709', # left=1,right=2 OFFSET=0
# 'L1R3' => 'A099545', # left=1,right=3 OFFSET=1
# # Not quite, A014707 has OFFSET=0 cf first elem for N=1
# Left => 'A014707', # turn, 1=left,0=right
# # OEIS-Catalogue: A014707 planepath=DragonCurve
# # Not quite, A014577 has OFFSET=0 cf first elem for N=1
# Right => 'A014577', # turn, 0=left,1=right
# # OEIS-Catalogue: A014577 planepath=DragonCurve turn_type=Right
# Not quite A014709 OFFSET=0 vs first turn at N=1 here
# SLR => 'A014709'
# SRL => 'A014710',
},
};
}
{ package Math::PlanePath::DragonRounded;
use constant _NumSeq_Turn_Turn4_min => 0.5;
use constant _NumSeq_Turn_Turn4_max => 3.5;
}
# { package Math::PlanePath::DragonMidpoint;
# }
{ package Math::PlanePath::AlternatePaper;
use constant _NumSeq_Turn_Turn4_min => 1; # left or right only
# A209615 is (-1)^e for each p^e prime=4k+3 or prime=2
# 3*3 mod 4 = 1 mod 4
# so picks out bit above lowest 1-bit, and factor -1 if an odd power-of-2
# which is the AlternatePaper turn formula
#
use constant _NumSeq_Turn_oeis_anum =>
{ 'arms=1' =>
{ LSR => 'A209615',
# OEIS-Catalogue: A209615 planepath=AlternatePaper turn_type=LSR
# # Not quite, A106665 has OFFSET=0 cf first here i=1
# 'Left' => 'A106665', # turn, 1=left,0=right
# # OEIS-Catalogue: A106665 planepath=AlternatePaper i_offset=1
},
};
}
{ package Math::PlanePath::GosperSide;
# Suspect not in OEIS:
# Left or Right according to lowest non-zero ternary digit 1 or 2
#
use constant _NumSeq_Turn_oeis_anum =>
{ '' =>
{ Left => 'A137893', # turn, 1=left,0=right, OFFSET=1
SLR => 'A060236', # base-3 lowest non-zero digit 1=left,2=right
# OEIS-Catalogue: A137893 planepath=GosperSide
# OEIS-Other: A137893 planepath=TerdragonCurve
# OEIS-Catalogue: A060236 planepath=GosperSide turn_type=SLR
# OEIS-Other: A060236 planepath=TerdragonCurve turn_type=SLR
# A060236 would also be a "TTurn3"
# cf A136442 - a(3n)=1, a(3n-1)=0, a(3n+1)=a(n)
# ternary lowest non-1 0->1 2->0
# Not quite, A080846 OFFSET=0 values 0,1,0,0,1 which are N=1 here
# Right => 'A080846',
# # OEIS-Catalogue: A080846 planepath=GosperSide turn_type=Right
# # OEIS-Other: A080846 planepath=TerdragonCurve turn_type=Right
# Or A189640 has extra initial 0.
},
};
}
{ package Math::PlanePath::TerdragonCurve;
# GosperSide and TerdragonCurve same turn sequence, by diff angles
use constant _NumSeq_Turn_Turn4_min => 1;
use constant _NumSeq_Turn_Turn4_max => 3;
use constant _NumSeq_Turn_oeis_anum =>
{ 'arms=1' => Math::PlanePath::GosperSide->_NumSeq_Turn_oeis_anum->{''} };
}
{ package Math::PlanePath::TerdragonRounded;
use constant _NumSeq_Turn_Turn4_min => 0.5;
use constant _NumSeq_Turn_Turn4_max => 3.5;
}
{ package Math::PlanePath::TerdragonMidpoint;
use constant _NumSeq_Turn_Turn4_max => 3;
}
{ package Math::PlanePath::R5DragonCurve;
use constant _NumSeq_Turn_Turn4_min => 1; # right or left turn always
# # Not quite, OFFSET=0 values 0,0,1,1,0
# # cf first turn here N=1 values 0,0,1,1,0
# # 'Math::PlanePath::R5DragonCurve' =>
# # { Right => 'A175337',
# # # OEIS-Catalogue: A175337 planepath=R5DragonCurve turn_type=Right
# # },
}
# { package Math::PlanePath::R5DragonMidpoint;
# }
{ package Math::PlanePath::CCurve;
# Not quite, A096268 OFFSET=1 vs first turn N=1 here
# Straight => 'A096268'
}
# { package Math::PlanePath::ComplexPlus;
# }
# { package Math::PlanePath::ComplexMinus;
# }
# { package Math::PlanePath::ComplexRevolving;
# }
{ package Math::PlanePath::Rows;
# 3---4 width=2
# \ N=2 turn4=1.5
# 1---2 N=3 turn4=2.5
sub _NumSeq_Turn_Turn4_min {
my ($self) = @_;
return ($self->{'width'} == 2
? 1.5 # at N=2
: 0); # otherwise has straight points
}
# *--------
# \---\
# *---------*
sub _NumSeq_Turn_Turn4_max {
my ($self) = @_;
return ($self->{'width'} <= 1
? 0 # width=1 always straight
: (Math::NumSeq::PlanePathTurn::_turn_func_Turn4
(1-$self->{'width'},1, 1,0))); # at row start
}
use constant _NumSeq_Turn_oeis_anum =>
{
'n_start=1,width=0' => # Rows width=0 is trivial X=N,Y=0
{ Left => 'A000004', # all-zeros
LSR => 'A000004', # all zeros, straight
# OEIS-Other: A000004 planepath=Rows,width=0
# OEIS-Other: A000004 planepath=Rows,width=0 turn_type=LSR
},
# 4 N=1 turn=2
# \ N=2 turn=4
# 2---3
# \
# 0---1
'n_start=-1,width=2' =>
{ TTurn6 => 'A010694', # repeat 2,4 with OFFSET=0
# OEIS-Other: A010694 planepath=Rows,width=2,n_start=-1 turn_type=TTurn6
},
};
}
{ package Math::PlanePath::Columns;
# 2 4 height=2
# | \ | N=2 turn4=2.5
# 1 3 N=3 turn4=1.5
sub _NumSeq_Turn_Turn4_min {
my ($self) = @_;
return ($self->{'height'} == 2
? 1.5 # at N=3
: 0); # otherwise has straight points
}
# *
# | \
# | |
# * *
sub _NumSeq_Turn_Turn4_max {
my ($self) = @_;
return ($self->{'height'} <= 1
? 0 # height=1 always straight
: (Math::NumSeq::PlanePathTurn::_turn_func_Turn4
(0,1, 1,1-$self->{'height'}))); # at column top
}
use constant _NumSeq_Turn_oeis_anum =>
{
'n_start=1,height=0' => # Columns height=0 is trivial X=N,Y=0
{ Left => 'A000004', # all-zeros
LSR => 'A000004', # all zeros, straight
# OEIS-Other: A000004 planepath=Columns,height=0
# OEIS-Other: A000004 planepath=Columns,height=0 turn_type=LSR
},
# 'n_start=-1,height=4' =>
# { Straight => 'A133872', # repeat 1,1,0,0 OFFSET=0
# NotStraight => 'A021913', # repeat 0,0,1,1 OFFSET=0
# # OEIS-Other: A133872 planepath=Columns,n_start=-1,height=4 turn_type=Straight
# # OEIS-Other: A021913 planepath=Columns,n_start=-1,height=4 turn_type=NotStraight
# },
};
}
{ package Math::PlanePath::Diagonals;
{
my %_NumSeq_Turn_Turn4_max
= (down => 2.5,
# at N=3 dx=-1,dy=+1 then dx=2,dy=-1
up => Math::NumSeq::PlanePathTurn::_turn_func_Turn4(-1,1, 2,-1));
sub _NumSeq_Turn_Turn4_max {
my ($self) = @_;
return $_NumSeq_Turn_Turn4_max{$self->{'direction'}};
}
}
use constant _NumSeq_Turn_oeis_anum =>
{ 'direction=down,n_start=0,x_start=0,y_start=0' =>
{ Left => 'A129184', # shift of triangle
SRL => 'A156319', # triangle 1, 2, 0, 0, 0, ... in each row OFFSET=1
# OEIS-Catalogue: A129184 planepath=Diagonals,n_start=0
# OEIS-Catalogue: A156319 planepath=Diagonals,n_start=0 turn_type=SRL
},
'direction=down,n_start=-1,x_start=0,y_start=0' =>
{ Right => 'A023531', # 1 at m(m+3)/2
# OEIS-Other: A023531 planepath=Diagonals,n_start=-1 turn_type=Right
},
'direction=up,n_start=0,x_start=0,y_start=0' =>
{ Right => 'A129184', # shift of triangle
SLR => 'A156319', # triangle 1, 2, 0, 0, 0, ... in each row OFFSET=1
# OEIS-Other: A129184 planepath=Diagonals,direction=up,n_start=0 turn_type=Right
# OEIS-Other: A156319 planepath=Diagonals,direction=up,n_start=0 turn_type=SLR
},
'direction=up,n_start=-1,x_start=0,y_start=0' =>
{ Left => 'A023531', # 1 at m(m+3)/2
# OEIS-Other: A023531 planepath=Diagonals,direction=up,n_start=-1
},
};
}
{ package Math::PlanePath::DiagonalsAlternating;
use constant _NumSeq_Turn_Turn4_max => 3.5;
}
{ package Math::PlanePath::DiagonalsOctant;
sub _NumSeq_Turn_Turn4_max {
my ($self) = @_;
return ($self->{'direction'} eq 'down'
? 2.5 # N=3
: 3); # N=2
}
# # down is left or straight, but also right at N=2,3,4
# # up is straight or right, but also left at N=2,3,4
# 'Math::PlanePath::DiagonalsOctant,direction=down' =>
# { Left => square or pronic starting from 1
# },
# 'Math::PlanePath::DiagonalsOctant,direction=up' =>
# { Left => square or pronic starting from 1
# },
}
{ package Math::PlanePath::Staircase;
use constant _NumSeq_Turn_Turn4_min => 1;
use constant _NumSeq_Turn_Turn4_max => 3;
}
# { package Math::PlanePath::StaircaseAlternating;
# }
{ package Math::PlanePath::MPeaks;
use constant _NumSeq_Turn_Turn4_max => 3;
}
{ package Math::PlanePath::Corner;
use constant _NumSeq_Turn_Turn4_max => 3;
use constant _NumSeq_Turn_oeis_anum =>
{ 'wider=1,n_start=-1' =>
{ Left => 'A000007', # turn Left=1 at N=0 only
# catalogued only unless/until a better implementation
# OEIS-Catalogue: A000007 planepath=Corner,wider=1,n_start=-1
},
'wider=2,n_start=-1' =>
{ Left => 'A063524', # turn Left=1 at N=1 only
# catalogued only unless/until a better implementation
# OEIS-Catalogue: A063524 planepath=Corner,wider=2,n_start=-1
},
'wider=3,n_start=-1' =>
{ Left => 'A185012', # turn Left=1 at N=2 only
# catalogued only unless/until a better implementation
# OEIS-Catalogue: A185012 planepath=Corner,wider=3,n_start=-1
},
# A185013 Characteristic function of three.
# A185014 Characteristic function of four.
# A185015 Characteristic function of 5.
# A185016 Characteristic function of 6.
# A185017 Characteristic function of 7.
};
}
{ package Math::PlanePath::PyramidRows;
# if step==0 then always straight ahead
# *--* *---*
# | step=1 \ step=3
# * *
sub _NumSeq_Turn_Turn4_max {
my ($self) = @_;
return ($self->{'step'} == 0
? 0 # straight vertical only
# at N=2
: (Math::NumSeq::PlanePathTurn::_turn_func_Turn4
(- $self->{'left_slope'},1, 1,0)));
}
use constant _NumSeq_Turn_oeis_anum =>
{
# PyramidRows step=0 is trivial X=N,Y=0
do {
my $href= { Left => 'A000004', # all-zeros, OFFSET=0
LSR => 'A000004', # all zeros straight
};
('step=0,align=centre,n_start=1' => $href,
'step=0,align=right,n_start=1' => $href,
'step=0,align=left,n_start=1' => $href,
);
# OEIS-Other: A000004 planepath=PyramidRows,step=0
# OEIS-Other: A000004 planepath=PyramidRows,step=0 turn_type=LSR
# OEIS-Other: A000004 planepath=PyramidRows,step=0,align=right
# OEIS-Other: A000004 planepath=PyramidRows,step=0,align=left turn_type=LSR
},
# PyramidRows step=1
do {
my $href= { Left => 'A129184', # triangle 1s shift right
};
('step=1,align=centre,n_start=0' => $href,
'step=1,align=right,n_start=0' => $href,
'step=1,align=left,n_start=0' => $href,
);
# OEIS-Other: A129184 planepath=PyramidRows,step=1,n_start=0
# OEIS-Other: A129184 planepath=PyramidRows,step=1,align=right,n_start=0
# OEIS-Other: A129184 planepath=PyramidRows,step=1,align=left,n_start=0
},
do {
my $href= { Right => 'A023531', # 1 at n==m*(m+3)/2
};
('step=1,align=centre,n_start=-1' => $href,
'step=1,align=right,n_start=-1' => $href,
);
# OEIS-Other: A023531 planepath=PyramidRows,step=1,n_start=-1 turn_type=Right
# OEIS-Other: A023531 planepath=PyramidRows,step=1,align=right,n_start=-1 turn_type=Right
},
};
}
{ package Math::PlanePath::PyramidSides;
use constant _NumSeq_Turn_Turn4_max => 3; # at N=3
}
{ package Math::PlanePath::CellularRule;
sub _NumSeq_Turn_Left_increasing {
my ($self) = @_;
return (defined $self->{'rule'}
&& ($self->{'rule'} & 0x17) == 0 # single cell only
? 1
: 0);
}
*_NumSeq_Turn_Right_increasing = \&_NumSeq_Turn_Left_increasing;
sub _NumSeq_Turn_LSR_increasing {
my ($self) = @_;
return (defined $self->{'rule'}
&& ($self->{'rule'} & 0x17) == 0 # single cell only
? 1
: 0);
}
}
{ package Math::PlanePath::CellularRule::Line;
use constant _NumSeq_Turn_Turn4_max => 0;
use constant _NumSeq_Turn_Turn4_integer => 1;
}
{ package Math::PlanePath::CellularRule::OneTwo;
# 5-6 5--6
# \ |
# 4 left rule=6 4 right rule=20
# ^----. N=2 turn4=2.5 / N=2 turn4=0.5
# 2--3 N=3 turn4=3.5 2--3 N=3 turn4=3
# \ N=4 turn4= |
# 1 1
sub _NumSeq_Turn_Turn4_min {
my ($self) = @_;
return ($self->{'align'} eq 'left'
? Math::NumSeq::PlanePathTurn::_turn_func_Turn4(1,0, -2,1) # N=3
: 0.5);
}
sub _NumSeq_Turn_Turn4_max {
my ($self) = @_;
return ($self->{'align'} eq 'left'
? Math::NumSeq::PlanePathTurn::_turn_func_Turn4(-2,1, -1,1) # N=4
: 3);
}
use constant _NumSeq_Turn_oeis_anum =>
{ 'align=left,n_start=-1' =>
{ SRL => 'A131534', # repeat 1,2,1, 1,2,1, ... OFFSET=0
# OEIS-Catalogue: A131534 planepath=CellularRule,rule=6,n_start=-1 turn_type=SRL
# OEIS-Other: A131534 planepath=CellularRule,rule=38,n_start=-1 turn_type=SRL
# OEIS-Other: A131534 planepath=CellularRule,rule=134,n_start=-1 turn_type=SRL
# OEIS-Other: A131534 planepath=CellularRule,rule=166,n_start=-1 turn_type=SRL
},
'align=right,n_start=-1' =>
{ SRL => 'A130196', # repeat 1,2,2, 1,2,2, ... OFFSET=0
# OEIS-Catalogue: A130196 planepath=CellularRule,rule=20,n_start=-1 turn_type=SRL
# OEIS-Other: A130196 planepath=CellularRule,rule=52,n_start=-1 turn_type=SRL
# OEIS-Other: A130196 planepath=CellularRule,rule=148,n_start=-1 turn_type=SRL
# OEIS-Other: A130196 planepath=CellularRule,rule=180,n_start=-1 turn_type=SRL
},
};
}
{ package Math::PlanePath::CellularRule::Two;
# 5--6 6--7
# ^---. |
# 4--5 left rule=6 4--5 right rule=84
# ^----. N=2 turn4=2.5 | N=2 turn4=1
# 2--3 N=3 turn4= 2--3 N=3 turn4=3
# \ |
# 1 1
sub _NumSeq_Turn_Turn4_min {
my ($self) = @_;
return ($self->{'align'} eq 'left'
? Math::NumSeq::PlanePathTurn::_turn_func_Turn4(1,0, -2,1) # N=3
: 1);
}
sub _NumSeq_Turn_Turn4_max {
my ($self) = @_;
return ($self->{'align'} eq 'left'
? 2.5
: 3);
}
use constant _NumSeq_Turn_oeis_anum =>
{ 'align=right,n_start=-1' =>
{
# right line 2, stair step
# |
# 3--1
# |
# 3--1 Turn4 amounts
# |
# *
Turn4 => 'A176040', # 3,1 repeating OFFSET=0
},
# OEIS-Catalogue: A176040 planepath=CellularRule,rule=84,n_start=-1 turn_type=Turn4
# OEIS-Other: A176040 planepath=CellularRule,rule=116,n_start=-1 turn_type=Turn4
# OEIS-Other: A176040 planepath=CellularRule,rule=212,n_start=-1 turn_type=Turn4
# OEIS-Other: A176040 planepath=CellularRule,rule=244,n_start=-1 turn_type=Turn4
};
}
{ package Math::PlanePath::CellularRule::OddSolid;
use constant _NumSeq_Turn_Turn4_max => 2.5; # at N=2
# R 0 0 L 1 0 0 2
# R 0 L 1 0 2
# R L 1 2
# . .
use constant _NumSeq_Turn_oeis_anum =>
{ 'n_start=0' =>
{ SRL => 'A156319', # triangle rows 1,2,0,0,0,0,...
# OEIS-Other: A156319 planepath=CellularRule,rule=50,n_start=0 turn_type=SRL
# OEIS-Other: A156319 planepath=CellularRule,rule=58,n_start=0 turn_type=SRL
# OEIS-Other: A156319 planepath=CellularRule,rule=250,n_start=0 turn_type=SRL
# OEIS-Other: A156319 planepath=CellularRule,rule=179,n_start=0 turn_type=SRL
},
};
}
{ package Math::PlanePath::CellularRule54;
use constant _NumSeq_Turn_Turn4_max => 2.5;
}
{ package Math::PlanePath::CellularRule57;
sub _NumSeq_Turn_Turn4_max {
my ($self) = @_;
return ($self->{'mirror'}
? 3.5
: Math::NumSeq::PlanePathTurn::_turn_func_Turn4(-2,1, 2,0)); # N=2
}
}
{ package Math::PlanePath::CellularRule190;
use constant _NumSeq_Turn_Turn4_max => 2.5;
}
# { package Math::PlanePath::CoprimeColumns;
# }
# { package Math::PlanePath::DivisibleColumns;
# }
# { package Math::PlanePath::File;
# # File points from a disk file
# # FIXME: analyze points for min/max etc
# }
{ package Math::PlanePath::QuintetCurve;
use constant _NumSeq_Turn_Turn4_max => 3;
}
{ package Math::PlanePath::QuintetCentres;
use constant _NumSeq_Turn_Turn4_max => 3.5;
}
# { package Math::PlanePath::QuintetSide;
# PlanePathTurn planepath=QuintetSide, turn_type=SLR
# match 1,2,1,1,2,2,1,2,1,1,2,1,1,2,2,1,2,2,1,2,1,1,2,2,1,2
# A060236 If n mod 3 = 0 then a(n)=a(n/3), otherwise a(n)=n mod 3.
# A060236 ,1,2,1,1,2,2,1,2,1,1,2,1,1,2,2,1,2,2,1,2,1,1,2,2,1,2,1,1,2,1,1,2,2,1,2,1,1,2,1,1,2,2,1,2,2,1,2,1,1,2,2,1,2,2,1,2,1,1,2,2,1,2,1,1,2,1,1,2,2,1,2,2,1,2,1,1,2,2,1,2,1,1,2,1,1,2,2,1,2,1,1,2,1,1,2,2,1,2,2,1,2,1,1,2,2,
# }
# { package Math::PlanePath::DekkingCurve;
# }
# { package Math::PlanePath::DekkingCentres;
# }
# { package Math::PlanePath::CincoCurve;
# }
{ package Math::PlanePath::CornerReplicate;
use constant _NumSeq_Turn_Turn4_min => # apparent minimum
Math::NumSeq::PlanePathTurn::_turn_func_Turn4(-1,0, -2,-1); # at N=11
use constant _NumSeq_Turn_Turn4_max => 3; # apparent maximum
}
{ package Math::PlanePath::SquareReplicate;
use constant _NumSeq_Turn_Turn4_max =>
Math::NumSeq::PlanePathTurn::_turn_func_Turn4(2,1, 0,1); # at N=9
}
{ package Math::PlanePath::DigitGroups;
# radix=3 "11110222222" len many 1s, 2*len-2 many 2s gives ever-increasing
# radix=4 "1303333...3333" ever-increasing
}
{ package Math::PlanePath::FibonacciWordFractal;
use constant _NumSeq_Turn_oeis_anum =>
{ '' =>
{ SRL => 'A156596', # turns 0=straight,1=right,2=left
# OEIS-Catalogue: A156596 planepath=FibonacciWordFractal turn_type=SRL
# Not quite, A003849 OFFSET=0 vs first turn N=1 here
# Straight => 'A003849'
},
};
}
# { package Math::PlanePath::LTiling;
# }
{ package Math::PlanePath::WythoffArray;
use constant _NumSeq_Turn_Turn4_max => # apparent maximum
Math::NumSeq::PlanePathTurn::_turn_func_Turn4(-2,3, 5,-4); # at N=12
}
{ package Math::PlanePath::WythoffPreliminaryTriangle;
# apparent maximum, searched through to N=10_000_000
# turn4 = 3.17777777777778
use constant _NumSeq_Turn_Turn4_max =>
Math::NumSeq::PlanePathTurn::_turn_func_Turn4(-54,-16, -8,13); # at N=1344
}
{ package Math::PlanePath::PowerArray;
# Turn4 ...
#
# radix=2
# min i=2[10] 1.50000 px=1,py=0 dx=-1,dy=1 -1.000
# max i=3[11] 2.20000 px=-1,py=1 dx=2,dy=-1[10,-1] -2.000
#
# radix=3
# min i=130[11211] 0.00000 px=-1,py=58 dx=0,dy=1 0.000
# max i=67[2111] 3.98889 px=-1,py=30 dx=0,dy=1[0,1] 0.000
#
# radix=4
# min i=2[2] 0.00000 px=0,py=1 dx=0,dy=1 0.000
# max i=53[311] 3.98889 px=-1,py=30 dx=0,dy=1[0,1] 0.000
#
# radix=5
# min i=2[2] 0.00000 px=0,py=1 dx=0,dy=1 0.000
# max i=46[141] 3.98889 px=-1,py=29 dx=0,dy=1[0,1] 0.000
#
# radix=6
# min i=2[2] 0.00000 px=0,py=1 dx=0,dy=1 0.000
# max i=43[111] 3.98889 px=-1,py=30 dx=0,dy=1[0,1] 0.000
#
# radix=7
# min i=2[2] 0.00000 px=0,py=1 dx=0,dy=1 0.000
# max i=43[61] 3.98889 px=-1,py=31 dx=0,dy=1[0,1] 0.000
#
# radix=8
# min i=2[2] 0.00000 px=0,py=1 dx=0,dy=1 0.000
# max i=41[51] 3.98889 px=-1,py=31 dx=0,dy=1[0,1] 0.000
#
# radix=9
# min i=2[2] 0.00000 px=0,py=1 dx=0,dy=1 0.000
# max i=37[41] 3.98889 px=-1,py=29 dx=0,dy=1[0,1] 0.000
#
# radix=10
# min i=2[2] 0.00000 px=0,py=1 dx=0,dy=1 0.000
# max i=41[41] 3.98889 px=-1,py=33 dx=0,dy=1[0,1] 0.000
#
# radix=16
# min i=2[2] 0.00000 px=0,py=1 dx=0,dy=1 0.000
# max i=33[21] 3.98889 px=-1,py=29 dx=0,dy=1[0,1] 0.000
#
# radix=29
# min i=2[2] 0.00000 px=0,py=1 dx=0,dy=1 0.000
# max i=59[21] 3.98889 px=-1,py=55 dx=0,dy=1[0,1] 0.000
# use constant _NumSeq_oeis_anum =>
# # Not quite, A011765 0,0,0,1 repeating has OFFSET=1
# # cf n_start=1 is first turn at N=2
# # Left => 'A011765',
# # Right => 'A011765',
#
# # Not quite, A131534 has OFFSET=1 vs first turn at N=2 here
# # 'radix=3' =>
# # { SRL => 'A131534', # repeat 1,2,1, OFFSET=0
# # }
#
# # Not quite, A007877 has OFFSET=1 vs first turn at N=2 here
# # 'radix=4' =>
# # { SRL => 'A007877', # repeat 0,1,2,1
# # }
#
# # Not quite, 0,0,2,1,2 here vs A053796 0,2,1,2,0
# # 'radix=5' =>
# # { SRL => 'A053796', # repeat 0,2,1,2,0
# # }
# };
}
{ package Math::PlanePath::ToothpickTree;
{
my %_NumSeq_Turn_Turn4_max
= (wedge => 3, # at N=1 turn right
);
sub _NumSeq_Turn_Turn4_max {
my ($self) = @_;
return $_NumSeq_Turn_Turn4_max{$self->{'parts'}} || 4;
}
}
{
my %_NumSeq_Turn4_max_is_supremum
= (wedge => 0,
);
sub _NumSeq_Turn4_max_is_supremum {
my ($self) = @_;
my $ret = $_NumSeq_Turn4_max_is_supremum{$self->{'parts'}};
return (defined $ret ? $ret : 1);
}
}
}
{ package Math::PlanePath::ToothpickReplicate;
{
my %_NumSeq_Turn_Turn4_max
= ( # at N=16
'3' => Math::NumSeq::PlanePathTurn::_turn_func_Turn4(-1,3, 0,1),
);
sub _NumSeq_Turn_Turn4_max {
my ($self) = @_;
return $_NumSeq_Turn_Turn4_max{$self->{'parts'}} || 3.5;
}
}
}
{ package Math::PlanePath::ToothpickUpist;
use constant _NumSeq_Turn_Turn4_max =>
Math::NumSeq::PlanePathTurn::_turn_func_Turn4(-2,1, 2,0); # at N=4
}
{ package Math::PlanePath::ToothpickSpiral;
use constant _NumSeq_Turn_Turn4_min => 1; # left or right always
}
{ package Math::PlanePath::LCornerReplicate;
# min i=63[333] 0.25556 px=1,py=0 dx=7,dy=3 2.333
use constant _NumSeq_Turn_Turn4_min =>
Math::NumSeq::PlanePathTurn::_turn_func_Turn4(1,0, 7,3); # at N=63
# higher N=1333..3333[base4] loop 3.8, 2.8, 1.7888, 0.7888
# max i=8191[1333333] 3.80000 px=-1,py=0 dx=-38,dy=13[-212,31] -2.923
use constant _NumSeq_Turn_Turn4_max =>
Math::NumSeq::PlanePathTurn::_turn_func_Turn4(-1,0, -38,13); # at N=8191
}
{ package Math::PlanePath::LCornerTree;
# parts=3 maybe maximum
# max i=3107[300203] 3.98889 px=1,py=0 dx=66,dy=-1[1002,-1] -66.000
# LCornerTree,parts=diagonal-1 Turn4 values_max=4 vs saw_values_max=3 at i=27 (to i_end=801)
{
my %_NumSeq_Turn_Turn4_max
= (wedge => 3, # at N=14
'wedge+1' => 3, # at N=19
diagonal => 3, # at N=21
'diagonal-1' => 3, # at N=27
);
sub _NumSeq_Turn_Turn4_max {
my ($self) = @_;
return $_NumSeq_Turn_Turn4_max{$self->{'parts'}} || 4;
}
}
{
my %_NumSeq_Turn4_max_is_supremum
= (4 => 0, # apparently
);
sub _NumSeq_Turn4_max_is_supremum {
my ($self) = @_;
return $_NumSeq_Turn4_max_is_supremum{$self->{'parts'}};
}
}
}
1;
__END__
=for stopwords Ryde Math-PlanePath NumSeq PlanePath SquareSpiral ie LSR dX,dY dx1,dy1 dx2,dy2 dx1 dx2 SRL dX
=head1 NAME
Math::NumSeq::PlanePathTurn -- turn sequence from PlanePath module
=head1 SYNOPSIS
use Math::NumSeq::PlanePathTurn;
my $seq = Math::NumSeq::PlanePathTurn->new (planepath => 'DragonCurve',
turn_type => 'Left');
my ($i, $value) = $seq->next;
=head1 DESCRIPTION
This is a tie-in to present turns from a C<Math::PlanePath> module in the
form of a NumSeq sequence.
The C<turn_type> choices are
"Left" 1=left 0=right or straight
"Right" 1=right 0=left or straight
"Straight" 1=straight, 0=left or right
"LSR" 1=left 0=straight -1=right
"SLR" 0=straight 1=left 2=right
"SRL" 0=straight 1=right 2=left
In each case the value at i is the turn which occurs at N=i,
i+1
^
|
|
i-1 ---> i turn at i
first turn at i = n_start + 1
For multiple "arms" the turn follows that particular arm so it's i-arms, i,
i+arms. i values start C<n_start()+arms_count()> so i-arms is C<n_start()>,
the first N on the path. A single arm path beginning N=0 has its first turn
at i=1.
For "Straight", "LSR", "SLR" and "SRL", straight means either straight ahead
or 180-degree reversal, ie. the direction N to N+1 is along the same line as
N-1 to N was.
"Left" means to the left side of the N-1 to N line, so not straight or
right. Similarly "Right" means to the right side of the N-1 to N line, so
not straight or left.
=head1 FUNCTIONS
See L<Math::NumSeq/FUNCTIONS> for behaviour common to all sequence classes.
=over 4
=item C<$seq = Math::NumSeq::PlanePathTurn-E<gt>new (key=E<gt>value,...)>
Create and return a new sequence object. The options are
planepath string, name of a PlanePath module
planepath_object PlanePath object
turn_type string, as described above
C<planepath> can be either the module part such as "SquareSpiral" or a
full class name "Math::PlanePath::SquareSpiral".
=item C<$value = $seq-E<gt>ith($i)>
Return the turn at N=$i in the PlanePath.
=item C<$bool = $seq-E<gt>pred($value)>
Return true if C<$value> occurs as a turn. Often this is merely the
possible turn values 1,0,-1, etc, but some spiral paths for example only go
left or straight in which case only 1 and 0 occur and C<pred()> reflects
that.
=item C<$i = $seq-E<gt>i_start()>
Return the first index C<$i> in the sequence. This is the position
C<rewind()> returns to.
This is C<$path-E<gt>n_start() - $path-E<gt>arms_count()> from the
PlanePath object.
=back
=head1 FORMULAS
=head2 Turn Left or Right
A turn left or right is identified by considering the dX,dY at N-1 and at N.
N+1 *
|
|
| dx2,dy2
|
N *
/
/
/ dx1,dy1
N-1 *
With the two vectors dx1,dy1 and dx2,dy2 at a common origin, if the dx2,dy2
is above the dx1,dy1 line then it's a turn to the left, or below is a turn
to the right
dx2,dy2
*
| * dx1,dy1
| /
| /
|/
o
At dx2 the Y value of the dx1,dy1 vector is
cmpY = dx2 * dy1/dx1 if dx1 != 0
left if dy2 > cmpY
dy2 > dx2 * dy1/dx1
so dy2 * dx1 > dx2 * dy1
This cross-product comparison dy2*dx1 E<gt> dx2*dy1 works when dx1=0 too,
ie. when dx1,dy1 is vertical
left if dy2 * 0 > dx2 * dy1
0 > dx2*dy1
good, left if dx2 and dy1 opposite signs
So
dy2*dx1 > dx2*dy1 left
dy2*dx1 < dx2*dy1 right
dy2*dx1 = dx2*dy1 straight, including 180 degree reverse
=head1 SEE ALSO
L<Math::NumSeq>,
L<Math::NumSeq::PlanePathCoord>,
L<Math::NumSeq::PlanePathDelta>,
L<Math::NumSeq::PlanePathN>
L<Math::NumberCruncher> has a C<Clockwise()> turn calculator
=head1 HOME PAGE
L<http://user42.tuxfamily.org/math-planepath/index.html>
=head1 LICENSE
Copyright 2011, 2012, 2013, 2014, 2015 Kevin Ryde
This file is part of Math-PlanePath.
Math-PlanePath is free software; you can redistribute it and/or modify it
under the terms of the GNU General Public License as published by the Free
Software Foundation; either version 3, or (at your option) any later
version.
Math-PlanePath is distributed in the hope that it will be useful, but
WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
more details.
You should have received a copy of the GNU General Public License along with
Math-PlanePath. If not, see <http://www.gnu.org/licenses/>.
=cut
|