Mercurial > octave
changeset 32650:e02dc55325c4 bytecode-interpreter
maint: Merge default to bytecode-interpreter
author | Arun Giridhar <arungiridhar@gmail.com> |
---|---|
date | Tue, 26 Dec 2023 14:46:41 -0500 |
parents | 9faf6bc269a7 (current diff) 6ec0b7516c5b (diff) |
children | d9e260f57718 |
files | |
diffstat | 26 files changed, 968 insertions(+), 163 deletions(-) [+] |
line wrap: on
line diff
--- a/etc/NEWS.10.md Fri Dec 22 22:50:09 2023 +0100 +++ b/etc/NEWS.10.md Tue Dec 26 14:46:41 2023 -0500 @@ -16,6 +16,9 @@ - `height` and `width` are now aliases for the `rows` and `columns` functions. +- All colormaps now default to a size of 256 colors. (The previous default +size was 64. + ### Alphabetical list of new functions added in Octave 10 * `rticklabels`
--- a/libinterp/corefcn/graphics.cc Fri Dec 22 22:50:09 2023 +0100 +++ b/libinterp/corefcn/graphics.cc Tue Dec 26 14:46:41 2023 -0500 @@ -147,76 +147,268 @@ const double cmapv[] = { - 2.67004010000000e-01, 2.72651720952381e-01, 2.77106307619048e-01, - 2.80356151428571e-01, 2.82390045238095e-01, 2.83204606666667e-01, - 2.82809341428571e-01, 2.81230763333333e-01, 2.78516153333333e-01, - 2.74735528571429e-01, 2.69981791904762e-01, 2.64368580952381e-01, - 2.58026184285714e-01, 2.51098684761905e-01, 2.43732853333333e-01, - 2.36073294285714e-01, 2.28263191428571e-01, 2.20424955714286e-01, - 2.12666598571429e-01, 2.05079113809524e-01, 1.97721880952381e-01, - 1.90631350000000e-01, 1.83819438571429e-01, 1.77272360952381e-01, - 1.70957518571429e-01, 1.64832915714286e-01, 1.58845368095238e-01, - 1.52951235714286e-01, 1.47131626666667e-01, 1.41402210952381e-01, - 1.35832975714286e-01, 1.30582113809524e-01, 1.25898377619048e-01, - 1.22163105714286e-01, 1.19872409523810e-01, 1.19626570000000e-01, - 1.22045948571429e-01, 1.27667691904762e-01, 1.36834947142857e-01, - 1.49643331428571e-01, 1.65967274285714e-01, 1.85538397142857e-01, - 2.08030450000000e-01, 2.33127309523809e-01, 2.60531475238095e-01, - 2.90000730000000e-01, 3.21329971428571e-01, 3.54355250000000e-01, - 3.88930322857143e-01, 4.24933143333333e-01, 4.62246770476190e-01, - 5.00753620000000e-01, 5.40336957142857e-01, 5.80861172380952e-01, - 6.22170772857143e-01, 6.64087320476191e-01, 7.06403823333333e-01, - 7.48885251428571e-01, 7.91273132857143e-01, 8.33302102380952e-01, - 8.74717527142857e-01, 9.15296319047619e-01, 9.54839555238095e-01, - 9.93247890000000e-01, 4.87433000000000e-03, 2.58456800000000e-02, - 5.09139004761905e-02, 7.42014957142857e-02, 9.59536042857143e-02, - 1.16893314761905e-01, 1.37350195714286e-01, 1.57479940000000e-01, - 1.77347967619048e-01, 1.96969168571429e-01, 2.16330337619048e-01, - 2.35404660952381e-01, 2.54161735714286e-01, 2.72573219047619e-01, - 2.90619516666667e-01, 3.08291041428571e-01, 3.25586450952381e-01, - 3.42517215238095e-01, 3.59102207142857e-01, 3.75366067142857e-01, - 3.91340913333333e-01, 4.07061480000000e-01, 4.22563764285714e-01, - 4.37885543809524e-01, 4.53062984285714e-01, 4.68129543809524e-01, - 4.83117059523810e-01, 4.98052961428571e-01, 5.12959473333333e-01, - 5.27854311428571e-01, 5.42750087142857e-01, 5.57652481904762e-01, - 5.72563073333333e-01, 5.87476284285714e-01, 6.02382410952381e-01, - 6.17265840000000e-01, 6.32106955714286e-01, 6.46881817142857e-01, - 6.61562926190476e-01, 6.76119717142857e-01, 6.90518987142857e-01, - 7.04725181904762e-01, 7.18700950000000e-01, 7.32406441904762e-01, - 7.45802021904762e-01, 7.58846480000000e-01, 7.71497934761905e-01, - 7.83714033809524e-01, 7.95453081428571e-01, 8.06673890000000e-01, - 8.17337565714286e-01, 8.27409135714286e-01, 8.36858167619048e-01, - 8.45663399523809e-01, 8.53815582857143e-01, 8.61321019047619e-01, - 8.68206316666667e-01, 8.74522215714286e-01, 8.80346158571429e-01, - 8.85780083333333e-01, 8.90945338571429e-01, 8.95973498571429e-01, - 9.01005800000000e-01, 9.06156570000000e-01, 3.29415190000000e-01, - 3.53367293333333e-01, 3.76236064761905e-01, 3.97901482857143e-01, - 4.18250757142857e-01, 4.37178920000000e-01, 4.54595888571429e-01, - 4.70433883333333e-01, 4.84653865714286e-01, 4.97250492857143e-01, - 5.08254501428571e-01, 5.17731949047619e-01, 5.25780221428571e-01, - 5.32522206190476e-01, 5.38097133333333e-01, 5.42651800000000e-01, - 5.46335411904762e-01, 5.49287148571429e-01, 5.51635008571429e-01, - 5.53493173333333e-01, 5.54953478571429e-01, 5.56089070000000e-01, - 5.56952166666667e-01, 5.57576145714286e-01, 5.57974025714286e-01, - 5.58142745238095e-01, 5.58058673809524e-01, 5.57684744285714e-01, - 5.56973310000000e-01, 5.55864478571429e-01, 5.54288677142857e-01, - 5.52175699047619e-01, 5.49445382857143e-01, 5.46023368571429e-01, - 5.41830633809524e-01, 5.36795616666667e-01, 5.30847985714286e-01, - 5.23924198571429e-01, 5.15966779523810e-01, 5.06924262857143e-01, - 4.96751861428571e-01, 4.85412122857143e-01, 4.72873300000000e-01, - 4.59105875238095e-01, 4.44095883333333e-01, 4.27825852857143e-01, - 4.10292713809524e-01, 3.91487632857143e-01, 3.71420688571429e-01, - 3.50098750000000e-01, 3.27544678571429e-01, 3.03798967142857e-01, - 2.78916748571429e-01, 2.53000856190476e-01, 2.26223670000000e-01, - 1.98879439523810e-01, 1.71494930000000e-01, 1.45037631428572e-01, - 1.21291048571429e-01, 1.03326155238095e-01, 9.53507900000000e-02, - 1.00469958095238e-01, 1.17876387142857e-01, 1.43936200000000e-01 + 0.26700401, 0.00487433, 0.32941519, + 0.26851048, 0.00960483, 0.33542652, + 0.26994384, 0.01462494, 0.34137895, + 0.27130489, 0.01994186, 0.34726862, + 0.27259384, 0.02556309, 0.35309303, + 0.27380934, 0.03149748, 0.35885256, + 0.27495242, 0.03775181, 0.36454323, + 0.27602238, 0.04416723, 0.37016418, + 0.27701840, 0.05034437, 0.37571452, + 0.27794143, 0.05632444, 0.38119074, + 0.27879067, 0.06214536, 0.38659204, + 0.27956550, 0.06783587, 0.39191723, + 0.28026658, 0.07341724, 0.39716349, + 0.28089358, 0.07890703, 0.40232944, + 0.28144581, 0.08431970, 0.40741404, + 0.28192358, 0.08966622, 0.41241521, + 0.28232739, 0.09495545, 0.41733086, + 0.28265633, 0.10019576, 0.42216032, + 0.28291049, 0.10539345, 0.42690202, + 0.28309095, 0.11055307, 0.43155375, + 0.28319704, 0.11567966, 0.43611482, + 0.28322882, 0.12077701, 0.44058404, + 0.28318684, 0.12584799, 0.44496000, + 0.28307200, 0.13089477, 0.44924127, + 0.28288389, 0.13592005, 0.45342734, + 0.28262297, 0.14092556, 0.45751726, + 0.28229037, 0.14591233, 0.46150995, + 0.28188676, 0.15088147, 0.46540474, + 0.28141228, 0.15583425, 0.46920128, + 0.28086773, 0.16077132, 0.47289909, + 0.28025468, 0.16569272, 0.47649762, + 0.27957399, 0.17059884, 0.47999675, + 0.27882618, 0.17549020, 0.48339654, + 0.27801236, 0.18036684, 0.48669702, + 0.27713437, 0.18522836, 0.48989831, + 0.27619376, 0.19007447, 0.49300074, + 0.27519116, 0.19490540, 0.49600488, + 0.27412802, 0.19972086, 0.49891131, + 0.27300596, 0.20452049, 0.50172076, + 0.27182812, 0.20930306, 0.50443413, + 0.27059473, 0.21406899, 0.50705243, + 0.26930756, 0.21881782, 0.50957678, + 0.26796846, 0.22354911, 0.51200840, + 0.26657984, 0.22826210, 0.51434870, + 0.26514450, 0.23295593, 0.51659930, + 0.26366320, 0.23763078, 0.51876163, + 0.26213801, 0.24228619, 0.52083736, + 0.26057103, 0.24692170, 0.52282822, + 0.25896451, 0.25153685, 0.52473609, + 0.25732244, 0.25613040, 0.52656332, + 0.25564519, 0.26070284, 0.52831152, + 0.25393498, 0.26525384, 0.52998273, + 0.25219404, 0.26978306, 0.53157905, + 0.25042462, 0.27429024, 0.53310261, + 0.24862899, 0.27877509, 0.53455561, + 0.24681140, 0.28323662, 0.53594093, + 0.24497208, 0.28767547, 0.53726018, + 0.24311324, 0.29209154, 0.53851561, + 0.24123708, 0.29648471, 0.53970946, + 0.23934575, 0.30085494, 0.54084398, + 0.23744138, 0.30520222, 0.54192140, + 0.23552606, 0.30952657, 0.54294396, + 0.23360277, 0.31382773, 0.54391424, + 0.23167350, 0.31810580, 0.54483444, + 0.22973926, 0.32236127, 0.54570633, + 0.22780192, 0.32659432, 0.54653200, + 0.22586330, 0.33080515, 0.54731353, + 0.22392515, 0.33499400, 0.54805291, + 0.22198915, 0.33916114, 0.54875211, + 0.22005691, 0.34330688, 0.54941304, + 0.21812995, 0.34743154, 0.55003755, + 0.21620971, 0.35153548, 0.55062743, + 0.21429757, 0.35561907, 0.55118440, + 0.21239477, 0.35968273, 0.55171011, + 0.21050310, 0.36372671, 0.55220646, + 0.20862342, 0.36775151, 0.55267486, + 0.20675628, 0.37175775, 0.55311653, + 0.20490257, 0.37574589, 0.55353282, + 0.20306309, 0.37971644, 0.55392505, + 0.20123854, 0.38366989, 0.55429441, + 0.19942950, 0.38760678, 0.55464205, + 0.19763650, 0.39152762, 0.55496905, + 0.19585993, 0.39543297, 0.55527637, + 0.19410009, 0.39932336, 0.55556494, + 0.19235719, 0.40319934, 0.55583559, + 0.19063135, 0.40706148, 0.55608907, + 0.18892259, 0.41091033, 0.55632606, + 0.18723083, 0.41474645, 0.55654717, + 0.18555593, 0.41857040, 0.55675292, + 0.18389763, 0.42238275, 0.55694377, + 0.18225561, 0.42618405, 0.55712010, + 0.18062949, 0.42997486, 0.55728221, + 0.17901879, 0.43375572, 0.55743035, + 0.17742298, 0.43752720, 0.55756466, + 0.17584148, 0.44128981, 0.55768526, + 0.17427363, 0.44504410, 0.55779216, + 0.17271876, 0.44879060, 0.55788532, + 0.17117615, 0.45252980, 0.55796464, + 0.16964573, 0.45626209, 0.55803034, + 0.16812641, 0.45998802, 0.55808199, + 0.16661710, 0.46370813, 0.55811913, + 0.16511703, 0.46742290, 0.55814141, + 0.16362543, 0.47113278, 0.55814842, + 0.16214155, 0.47483821, 0.55813967, + 0.16066467, 0.47853961, 0.55811466, + 0.15919413, 0.48223740, 0.55807280, + 0.15772933, 0.48593197, 0.55801347, + 0.15626973, 0.48962370, 0.55793600, + 0.15481488, 0.49331293, 0.55783967, + 0.15336445, 0.49700003, 0.55772371, + 0.15191820, 0.50068529, 0.55758733, + 0.15047605, 0.50436904, 0.55742968, + 0.14903918, 0.50805136, 0.55725050, + 0.14760731, 0.51173263, 0.55704861, + 0.14618026, 0.51541316, 0.55682271, + 0.14475863, 0.51909319, 0.55657181, + 0.14334327, 0.52277292, 0.55629491, + 0.14193527, 0.52645254, 0.55599097, + 0.14053599, 0.53013219, 0.55565893, + 0.13914708, 0.53381201, 0.55529773, + 0.13777048, 0.53749213, 0.55490625, + 0.13640850, 0.54117264, 0.55448339, + 0.13506561, 0.54485335, 0.55402906, + 0.13374299, 0.54853458, 0.55354108, + 0.13244401, 0.55221637, 0.55301828, + 0.13117249, 0.55589872, 0.55245948, + 0.12993270, 0.55958162, 0.55186354, + 0.12872938, 0.56326503, 0.55122927, + 0.12756771, 0.56694891, 0.55055551, + 0.12645338, 0.57063316, 0.54984110, + 0.12539383, 0.57431754, 0.54908564, + 0.12439474, 0.57800205, 0.54828740, + 0.12346281, 0.58168661, 0.54744498, + 0.12260562, 0.58537105, 0.54655722, + 0.12183122, 0.58905521, 0.54562298, + 0.12114807, 0.59273889, 0.54464114, + 0.12056501, 0.59642187, 0.54361058, + 0.12009154, 0.60010387, 0.54253043, + 0.11973756, 0.60378459, 0.54139999, + 0.11951163, 0.60746388, 0.54021751, + 0.11942341, 0.61114146, 0.53898192, + 0.11948255, 0.61481702, 0.53769219, + 0.11969858, 0.61849025, 0.53634733, + 0.12008079, 0.62216081, 0.53494633, + 0.12063824, 0.62582833, 0.53348834, + 0.12137972, 0.62949242, 0.53197275, + 0.12231244, 0.63315277, 0.53039808, + 0.12344358, 0.63680899, 0.52876343, + 0.12477953, 0.64046069, 0.52706792, + 0.12632581, 0.64410744, 0.52531069, + 0.12808703, 0.64774881, 0.52349092, + 0.13006688, 0.65138436, 0.52160791, + 0.13226797, 0.65501363, 0.51966086, + 0.13469183, 0.65863619, 0.51764880, + 0.13733921, 0.66225157, 0.51557101, + 0.14020991, 0.66585927, 0.51342680, + 0.14330291, 0.66945881, 0.51121549, + 0.14661640, 0.67304968, 0.50893644, + 0.15014782, 0.67663139, 0.50658890, + 0.15389405, 0.68020343, 0.50417217, + 0.15785146, 0.68376525, 0.50168574, + 0.16201598, 0.68731632, 0.49912906, + 0.16638320, 0.69085611, 0.49650163, + 0.17094840, 0.69438405, 0.49380294, + 0.17570671, 0.69789960, 0.49103252, + 0.18065314, 0.70140222, 0.48818938, + 0.18578266, 0.70489133, 0.48527326, + 0.19109018, 0.70836635, 0.48228395, + 0.19657063, 0.71182668, 0.47922108, + 0.20221902, 0.71527175, 0.47608431, + 0.20803045, 0.71870095, 0.47287330, + 0.21400015, 0.72211371, 0.46958774, + 0.22012381, 0.72550945, 0.46622638, + 0.22639690, 0.72888753, 0.46278934, + 0.23281498, 0.73224735, 0.45927675, + 0.23937390, 0.73558828, 0.45568838, + 0.24606968, 0.73890972, 0.45202405, + 0.25289851, 0.74221104, 0.44828355, + 0.25985676, 0.74549162, 0.44446673, + 0.26694127, 0.74875084, 0.44057284, + 0.27414922, 0.75198807, 0.43660090, + 0.28147681, 0.75520266, 0.43255207, + 0.28892102, 0.75839399, 0.42842626, + 0.29647899, 0.76156142, 0.42422341, + 0.30414796, 0.76470433, 0.41994346, + 0.31192534, 0.76782207, 0.41558638, + 0.31980860, 0.77091403, 0.41115215, + 0.32779580, 0.77397953, 0.40664011, + 0.33588539, 0.77701790, 0.40204917, + 0.34407411, 0.78002855, 0.39738103, + 0.35235985, 0.78301086, 0.39263579, + 0.36074053, 0.78596419, 0.38781353, + 0.36921420, 0.78888793, 0.38291438, + 0.37777892, 0.79178146, 0.37793850, + 0.38643282, 0.79464415, 0.37288606, + 0.39517408, 0.79747541, 0.36775726, + 0.40400101, 0.80027461, 0.36255223, + 0.41291350, 0.80304099, 0.35726893, + 0.42190813, 0.80577412, 0.35191009, + 0.43098317, 0.80847343, 0.34647607, + 0.44013691, 0.81113836, 0.34096730, + 0.44936763, 0.81376835, 0.33538426, + 0.45867362, 0.81636288, 0.32972749, + 0.46805314, 0.81892143, 0.32399761, + 0.47750446, 0.82144351, 0.31819529, + 0.48702580, 0.82392862, 0.31232133, + 0.49661536, 0.82637633, 0.30637661, + 0.50627130, 0.82878621, 0.30036211, + 0.51599182, 0.83115784, 0.29427888, + 0.52577622, 0.83349064, 0.28812650, + 0.53562110, 0.83578452, 0.28190832, + 0.54552440, 0.83803918, 0.27562602, + 0.55548397, 0.84025437, 0.26928147, + 0.56549760, 0.84242990, 0.26287683, + 0.57556297, 0.84456561, 0.25641457, + 0.58567772, 0.84666139, 0.24989748, + 0.59583934, 0.84871722, 0.24332878, + 0.60604528, 0.85073310, 0.23671214, + 0.61629283, 0.85270912, 0.23005179, + 0.62657923, 0.85464543, 0.22335258, + 0.63690157, 0.85654226, 0.21662012, + 0.64725685, 0.85839991, 0.20986086, + 0.65764197, 0.86021878, 0.20308229, + 0.66805369, 0.86199932, 0.19629307, + 0.67848868, 0.86374211, 0.18950326, + 0.68894351, 0.86544779, 0.18272455, + 0.69941463, 0.86711711, 0.17597055, + 0.70989842, 0.86875092, 0.16925712, + 0.72039115, 0.87035015, 0.16260273, + 0.73088902, 0.87191584, 0.15602894, + 0.74138803, 0.87344918, 0.14956101, + 0.75188414, 0.87495143, 0.14322828, + 0.76237342, 0.87642392, 0.13706449, + 0.77285183, 0.87786808, 0.13110864, + 0.78331535, 0.87928545, 0.12540538, + 0.79375994, 0.88067763, 0.12000532, + 0.80418159, 0.88204632, 0.11496505, + 0.81457634, 0.88339329, 0.11034678, + 0.82494028, 0.88472036, 0.10621724, + 0.83526959, 0.88602943, 0.10264590, + 0.84556056, 0.88732243, 0.09970219, + 0.85580960, 0.88860134, 0.09745186, + 0.86601325, 0.88986815, 0.09595277, + 0.87616824, 0.89112487, 0.09525046, + 0.88627146, 0.89237353, 0.09537439, + 0.89632002, 0.89361614, 0.09633538, + 0.90631121, 0.89485467, 0.09812496, + 0.91624212, 0.89609127, 0.10071680, + 0.92610579, 0.89732977, 0.10407067, + 0.93590444, 0.89857040, 0.10813094, + 0.94563626, 0.89981500, 0.11283773, + 0.95529972, 0.90106534, 0.11812832, + 0.96489353, 0.90232311, 0.12394051, + 0.97441665, 0.90358991, 0.13021494, + 0.98386829, 0.90486726, 0.13689671, + 0.99324789, 0.90615657, 0.14393620 }; // It would be nice if Matrix had a ctor allowing to do the // following without a copy - Matrix cmap (64, 3, 0.0); - std::copy (cmapv, cmapv + (64*3), cmap.fortran_vec ()); + Matrix cmap (256, 3, 0.0); + std::copy (cmapv, cmapv + (256*3), cmap.fortran_vec ()); return cmap; }
--- a/scripts/image/autumn.m Fri Dec 22 22:50:09 2023 +0100 +++ b/scripts/image/autumn.m Tue Dec 26 14:46:41 2023 -0500 @@ -30,7 +30,8 @@ ## This colormap ranges from red through orange to yellow. ## ## The argument @var{n} must be a scalar. -## If unspecified, the length of the current colormap, or 64, is used. +## If @var{n} is not specified the length of the current colormap is used. If +## there is no current colormap the default value of 256 is used. ## @seealso{colormap} ## @end deftypefn @@ -46,7 +47,7 @@ if (! isempty (hf)) n = rows (get (hf, "colormap")); else - n = 64; + n = 256; endif endif @@ -71,3 +72,23 @@ %! rgbplot (cmap, "composite"); %! subplot (2, 1, 2); %! rgbplot (cmap); + + +%!assert (size (autumn ()), [256, 3]) +%!assert (size (autumn (16)), [16, 3]) + +%!assert (autumn (1), [1, 0, 0]) +%!assert (autumn (true), double ([1, 0, 0])) +%!assert (autumn (char (1)), double ([1, 0, 0])) +%!assert (autumn (int32 (1)), double ([1, 0, 0])) + +%!assert (autumn (0), zeros (0, 3)) +%!assert (autumn (-1), zeros (0, 3)) + +%!assert (autumn (11), [ones(1,11); [0:0.1:1]; zeros(1,11)]', eps) + +## Input validation +%!error <function called with too many inputs> autumn (1, 2) +%!error <N must be a scalar> autumn ("foo") +%!error <N must be a scalar> autumn ([1, 2, 3]) +%!error <N must be a scalar> autumn ({1, 2, 3})
--- a/scripts/image/bone.m Fri Dec 22 22:50:09 2023 +0100 +++ b/scripts/image/bone.m Tue Dec 26 14:46:41 2023 -0500 @@ -30,7 +30,8 @@ ## gray-blue shades. ## ## The argument @var{n} must be a scalar. -## If unspecified, the length of the current colormap, or 64, is used. +## If @var{n} is not specified the length of the current colormap is used. If +## there is no current colormap the default value of 256 is used. ## @seealso{colormap} ## @end deftypefn @@ -46,7 +47,7 @@ if (! isempty (hf)) n = rows (get (hf, "colormap")); else - n = 64; + n = 256; endif endif @@ -98,3 +99,30 @@ %! rgbplot (cmap, "composite"); %! subplot (2, 1, 2); %! rgbplot (cmap); + + +%!assert (size (bone ()), [256, 3]) +%!assert (size (bone (16)), [16, 3]) + +%!assert (bone (1), [1/8, 1/8, 1/8]) +%!assert (bone (true), double ([1/8, 1/8, 1/8])) +%!assert (bone (char (1)), double ([1/8, 1/8, 1/8])) +%!assert (bone (int32 (1)), double ([1/8, 1/8, 1/8])) +%!assert (bone (2), [1/16, 1/8, 1/8; 1 ,1, 1]) + +%!assert (bone (0), zeros (0, 3)) +%!assert (bone (-1), zeros (0, 3)) + +%!test +%! a = [ 0, 0, 1/8; +%! 7/32, 11/32, 11/32; +%! 23/48, 9/16, 9/16; +%! 71/96, 25/32, 25/32; +%! 1, 1, 1]; +%! assert (bone (5), a, eps) + +## Input validation +%!error <function called with too many inputs> bone (1, 2) +%!error <N must be a scalar> bone ("foo") +%!error <N must be a scalar> bone ([1, 2, 3]) +%!error <N must be a scalar> bone ({1, 2, 3})
--- a/scripts/image/colorcube.m Fri Dec 22 22:50:09 2023 +0100 +++ b/scripts/image/colorcube.m Tue Dec 26 14:46:41 2023 -0500 @@ -34,16 +34,25 @@ ## blue, and gray. ## ## The argument @var{n} must be a scalar. -## If unspecified, the length of the current colormap, or 64, is used. +## If @var{n} is not specified the length of the current colormap is used. If +## there is no current colormap the default value of 256 is used. ## @seealso{colormap} ## @end deftypefn function map = colorcube (n) - if (nargin == 0) - n = rows (colormap); - elseif (! isscalar (n)) - error ("colorcube: N must be a scalar"); + if (nargin == 1) + if (! isscalar (n)) + error ("colorcube: N must be a scalar"); + endif + n = double (n); + else + hf = get (0, "currentfigure"); + if (! isempty (hf)) + n = rows (get (hf, "colormap")); + else + n = 256; + endif endif if (n < 9) @@ -99,3 +108,38 @@ %! axis ([1, 64, 0, 1], "xy"); %! set (gca, "xtick", []); %! colormap (colorcube (64)); + + +%!assert (size (colorcube ()), [256, 3]) +%!assert (size (colorcube (16)), [16, 3]) + +%!assert (colorcube (1), [0, 0, 0]) +%!assert (colorcube (true), double ([0, 0, 0])) +%!assert (colorcube (char (1)), double ([0, 0, 0])) +%!assert (colorcube (int32 (1)), double ([0, 0, 0])) + +%!assert (colorcube (0), zeros (0, 3)) +%!assert (colorcube (-1), zeros (0, 3)) + +%!assert (colorcube (8), gray (8)) + +%!test +%! a = [1, 1, 0; +%! 0, 1, 1; +%! 1, 0, 1; +%! 0.5, 0, 0; +%! 1, 0, 0; +%! 0, 0.5, 0; +%! 0, 1, 0; +%! 0, 0, 0.5; +%! 0, 0, 1; +%! 0, 0, 0; +%! 0.5, 0.5, 0.5; +%! 1, 1, 1]; +%! assert (colorcube (12), a, eps) + +## Input validation +%!error <function called with too many inputs> colorcube (1, 2) +%!error <N must be a scalar> colorcube ("foo") +%!error <N must be a scalar> colorcube ([1, 2, 3]) +%!error <N must be a scalar> colorcube ({1, 2, 3})
--- a/scripts/image/colormap.m Fri Dec 22 22:50:09 2023 +0100 +++ b/scripts/image/colormap.m Tue Dec 26 14:46:41 2023 -0500 @@ -32,7 +32,9 @@ ## @deftypefnx {} {} colormap @var{map_name} ## Query or set the current colormap. ## -## With no input arguments, @code{colormap} returns the current color map. +## With no input arguments, @code{colormap} returns the current color map. If +## there is no current figure, a new figure will be opened and the default +## color map will be returned. ## ## @code{colormap (@var{map})} sets the current colormap to @var{map}. The ## colormap should be an @var{n} row by 3 column matrix. The columns @@ -40,7 +42,7 @@ ## must be between 0 and 1 inclusive. The new colormap is returned. ## ## @code{colormap (@qcode{"default"})} restores the default colormap (the -## @code{viridis} map with 64 entries). The default colormap is returned. +## @code{viridis} map with 256 entries). The default colormap is returned. ## ## The map may also be specified by a string, @var{map_name}, which ## is the name of a function that returns a colormap. @@ -108,7 +110,7 @@ if (ischar (map)) map = lower (map); if (strcmp (map, "default")) - map = viridis (64); + map = viridis (256); else try map = feval (map); @@ -169,9 +171,9 @@ %! cmap = (get (gcf, "colormap")); %! assert (cmap, cmaptst); %! colormap ("default"); -%! assert (colormap (), viridis (64)); +%! assert (colormap (), viridis (256)); %! colormap ("ocean"); -%! assert (colormap, ocean (64)); +%! assert (colormap, ocean (256)); %! unwind_protect_cleanup %! close (hf); %! end_unwind_protect
--- a/scripts/image/cool.m Fri Dec 22 22:50:09 2023 +0100 +++ b/scripts/image/cool.m Tue Dec 26 14:46:41 2023 -0500 @@ -29,7 +29,8 @@ ## Create color colormap. The colormap varies from cyan to magenta. ## ## The argument @var{n} must be a scalar. -## If unspecified, the length of the current colormap, or 64, is used. +## If @var{n} is not specified the length of the current colormap is used. If +## there is no current colormap the default value of 256 is used. ## @seealso{colormap} ## @end deftypefn @@ -45,7 +46,7 @@ if (! isempty (hf)) n = rows (get (hf, "colormap")); else - n = 64; + n = 256; endif endif @@ -70,3 +71,23 @@ %! rgbplot (cmap, "composite"); %! subplot (2, 1, 2); %! rgbplot (cmap); + + +%!assert (size (cool ()), [256, 3]) +%!assert (size (cool (16)), [16, 3]) + +%!assert (cool (1), [0, 1, 1]) +%!assert (cool (true), double ([0, 1, 1])) +%!assert (cool (char (1)), double ([0, 1, 1])) +%!assert (cool (int32 (1)), double ([0, 1, 1])) + +%!assert (cool (0), zeros (0, 3)) +%!assert (cool (-1), zeros (0, 3)) + +%!assert (cool (11), [[0:0.1:1]; [1:-0.1:0]; ones(1,11)]', eps) + +## Input validation +%!error <function called with too many inputs> cool (1, 2) +%!error <N must be a scalar> cool ("foo") +%!error <N must be a scalar> cool ([1, 2, 3]) +%!error <N must be a scalar> cool ({1, 2, 3})
--- a/scripts/image/copper.m Fri Dec 22 22:50:09 2023 +0100 +++ b/scripts/image/copper.m Tue Dec 26 14:46:41 2023 -0500 @@ -30,7 +30,8 @@ ## tone. ## ## The argument @var{n} must be a scalar. -## If unspecified, the length of the current colormap, or 64, is used. +## If @var{n} is not specified the length of the current colormap is used. If +## there is no current colormap the default value of 256 is used. ## @seealso{colormap} ## @end deftypefn @@ -46,7 +47,7 @@ if (! isempty (hf)) n = rows (get (hf, "colormap")); else - n = 64; + n = 256; endif endif @@ -73,3 +74,26 @@ %! rgbplot (cmap, "composite"); %! subplot (2, 1, 2); %! rgbplot (cmap); + + +%!assert (size (copper ()), [256, 3]) +%!assert (size (copper (16)), [16, 3]) + +%!assert (copper (1), [0, 0, 0]) +%!assert (copper (true), double ([0, 0, 0])) +%!assert (copper (char (1)), double ([0, 0, 0])) +%!assert (copper (int32 (1)), double ([0, 0, 0])) + +%!assert (copper (0), zeros (0, 3)) +%!assert (copper (-1), zeros (0, 3)) + +%!test +%! a = [0.25, 0.15624, 0.0995] .* [0:5]'; +%! a(6) = 1; +%! assert (copper (6), a, eps) + +## Input validation +%!error <function called with too many inputs> copper (1, 2) +%!error <N must be a scalar> copper ("foo") +%!error <N must be a scalar> copper ([1, 2, 3]) +%!error <N must be a scalar> copper ({1, 2, 3})
--- a/scripts/image/cubehelix.m Fri Dec 22 22:50:09 2023 +0100 +++ b/scripts/image/cubehelix.m Tue Dec 26 14:46:41 2023 -0500 @@ -40,7 +40,8 @@ ## @end example ## ## The argument @var{n} must be a scalar. -## If unspecified, the length of the current colormap, or 64, is used. +## If @var{n} is not specified the length of the current colormap is used. If +## there is no current colormap the default value of 256 is used. ## ## Reference: Green, D. A., 2011, ## @cite{A @nospell{colour} scheme for the display of astronomical intensity @@ -61,7 +62,7 @@ if (! isempty (hf)) n = rows (get (hf, "colormap")); else - n = 64; + n = 256; endif endif @@ -96,3 +97,34 @@ %! rgbplot (cmap, "composite"); %! subplot (2, 1, 2); %! rgbplot (cmap); + + +%!assert (size (cubehelix ()), [256, 3]) +%!assert (size (cubehelix (16)), [16, 3]) + +%!assert (cubehelix (1), [0,0,0]) +%!assert (cubehelix (true), double ([0,0,0])) +%!assert (cubehelix (char (1)), double ([0,0,0])) +%!assert (cubehelix (int32 (1)), double ([0,0,0])) + +%!assert (cubehelix (0), zeros (0, 3)) +%!assert (cubehelix (-1), zeros (0, 3)) + +%!assert (cubehelix (2), [0, 0, 0; 1, 1, 1]) +%!assert ([cubehelix]([1,end],:), [0, 0, 0; 1, 1, 1]) + +%!shared a +%! a = [0, 0, 0; +%! 0.17004232121057959, 0.43679759647517287, 0.22372555555555556; +%! 0.82995767878942041, 0.56320240352482713, 0.77627444444444445; +%! 1, 1, 1]; + +%!assert (cubehelix (4), a, eps) + +%!shared # Clear shared varibles to avoid echo on unrelated test errors. + +## Input validation +%!error <function called with too many inputs> cubehelix (1, 2, 3, 4 ,5 ,6) +%!error <N must be a scalar> cubehelix ("foo") +%!error <N must be a scalar> cubehelix ([1, 2, 3]) +%!error <N must be a scalar> cubehelix ({1, 2, 3})
--- a/scripts/image/flag.m Fri Dec 22 22:50:09 2023 +0100 +++ b/scripts/image/flag.m Tue Dec 26 14:46:41 2023 -0500 @@ -30,7 +30,8 @@ ## black with each index change. ## ## The argument @var{n} must be a scalar. -## If unspecified, the length of the current colormap, or 64, is used. +## If @var{n} is not specified the length of the current colormap is used. If +## there is no current colormap the default value of 256 is used. ## @seealso{colormap} ## @end deftypefn @@ -46,7 +47,7 @@ if (! isempty (hf)) n = rows (get (hf, "colormap")); else - n = 64; + n = 256; endif endif if (n == 1) @@ -68,3 +69,37 @@ %! rgbplot (cmap, "composite"); %! subplot (2, 1, 2); %! rgbplot (cmap); + + + +%!assert (size (flag ()), [256, 3]) +%!assert (size (flag (16)), [16, 3]) + +%!assert (flag (1), [1, 0, 0]) +%!assert (flag (true), double ([1, 0, 0])) +%!assert (flag (char (1)), double ([1, 0, 0])) +%!assert (flag (int32 (1)), double ([1, 0, 0])) + +%!assert (flag (0), zeros (0, 3)) +%!assert (flag (-1), zeros (0, 3)) + +%!test +%! a = [1, 0, 0; +%! 1, 1, 1; +%! 0, 0, 1; +%! 0, 0, 0; +%! 1, 0, 0; +%! 1, 1, 1; +%! 0, 0, 1; +%! 0, 0, 0; +%! 1, 0, 0; +%! 1, 1, 1; +%! 0, 0, 1; +%! 0, 0, 0]; +%! assert (flag (12), a, eps) + +## Input validation +%!error <function called with too many inputs> flag (1, 2) +%!error <N must be a scalar> flag ("foo") +%!error <N must be a scalar> flag ([1, 2, 3]) +%!error <N must be a scalar> flag ({1, 2, 3})
--- a/scripts/image/gray.m Fri Dec 22 22:50:09 2023 +0100 +++ b/scripts/image/gray.m Tue Dec 26 14:46:41 2023 -0500 @@ -30,7 +30,8 @@ ## of gray. ## ## The argument @var{n} must be a scalar. -## If unspecified, the length of the current colormap, or 64, is used. +## If @var{n} is not specified the length of the current colormap is used. If +## there is no current colormap the default value of 256 is used. ## @seealso{colormap} ## @end deftypefn @@ -46,7 +47,7 @@ if (! isempty (hf)) n = rows (get (hf, "colormap")); else - n = 64; + n = 256; endif endif @@ -69,3 +70,23 @@ %! rgbplot (cmap, "composite"); %! subplot (2, 1, 2); %! rgbplot (cmap); + + +%!assert (size (gray ()), [256, 3]) +%!assert (size (gray (16)), [16, 3]) + +%!assert (gray (1), [0, 0, 0]) +%!assert (gray (true), double ([0, 0, 0])) +%!assert (gray (char (1)), double ([0, 0, 0])) +%!assert (gray (int32 (1)), double ([0, 0, 0])) + +%!assert (gray (0), zeros (0, 3)) +%!assert (gray (-1), zeros (0, 3)) + +%!assert (gray (11), [0:.1:1]' .* [1, 1, 1], eps) + +## Input validation +%!error <function called with too many inputs> gray (1, 2) +%!error <N must be a scalar> gray ("foo") +%!error <N must be a scalar> gray ([1, 2, 3]) +%!error <N must be a scalar> gray ({1, 2, 3})
--- a/scripts/image/hot.m Fri Dec 22 22:50:09 2023 +0100 +++ b/scripts/image/hot.m Tue Dec 26 14:46:41 2023 -0500 @@ -30,7 +30,8 @@ ## red, orange, yellow, to white. ## ## The argument @var{n} must be a scalar. -## If unspecified, the length of the current colormap, or 64, is used. +## If @var{n} is not specified the length of the current colormap is used. If +## there is no current colormap the default value of 256 is used. ## @seealso{colormap} ## @end deftypefn @@ -46,7 +47,7 @@ if (! isempty (hf)) n = rows (get (hf, "colormap")); else - n = 64; + n = 256; endif endif if (n == 1) @@ -86,3 +87,36 @@ %! rgbplot (cmap, "composite"); %! subplot (2, 1, 2); %! rgbplot (cmap); + +%!assert (size (hot ()), [256, 3]) +%!assert (size (hot (16)), [16, 3]) + +%!assert (hot (1), [1, 1, 1]) +%!assert (hot (true), double ([1, 1, 1])) +%!assert (hot (char (1)), double ([1, 1, 1])) +%!assert (hot (int32 (1)), double ([1, 1, 1])) +%!assert (hot (2), [1, 1, 1/2; 1, 1, 1]) +%!assert (hot (3), [1, 0, 0; 1, 1, 0; 1 1 1]) + +%!assert (hot (0), zeros (0, 3)) +%!assert (hot (-1), zeros (0, 3)) + +%!test +%! a = [0.25, 0, 0; +%! 0.50, 0, 0; +%! 0.75, 0, 0; +%! 1, 0, 0; +%! 1, 0.25, 0; +%! 1, 0.50, 0; +%! 1, 0.75, 0; +%! 1, 1, 0; +%! 1, 1, 1/3; +%! 1, 1, 2/3; +%! 1, 1, 1]; +%! assert (hot (11), a, eps); + +## Input validation +%!error <function called with too many inputs> hot (1, 2) +%!error <N must be a scalar> hot ("foo") +%!error <N must be a scalar> hot ([1, 2, 3]) +%!error <N must be a scalar> hot ({1, 2, 3})
--- a/scripts/image/hsv.m Fri Dec 22 22:50:09 2023 +0100 +++ b/scripts/image/hsv.m Tue Dec 26 14:46:41 2023 -0500 @@ -35,7 +35,8 @@ ## @code{hsv2rgb ([(0:N-1)'/N, ones(N,2)])}. ## ## The argument @var{n} must be a scalar. -## If unspecified, the length of the current colormap, or 64, is used. +## If @var{n} is not specified the length of the current colormap is used. If +## there is no current colormap the default value of 256 is used. ## @seealso{colormap} ## @end deftypefn @@ -51,7 +52,7 @@ if (! isempty (hf)) n = rows (get (hf, "colormap")); else - n = 64; + n = 256; endif endif @@ -75,3 +76,22 @@ %! rgbplot (cmap, "composite"); %! subplot (2, 1, 2); %! rgbplot (cmap); + +%!assert (size (hsv ()), [256, 3]) +%!assert (size (hsv (16)), [16, 3]) + +%!assert (hsv (1), [1, 0, 0]) +%!assert (hsv (true), double ([1, 0, 0])) +%!assert (hsv (char (1)), double ([1, 0, 0])) +%!assert (hsv (int32 (1)), double ([1, 0, 0])) + +%!assert (hsv (0), zeros (0, 3)) +%!assert (hsv (-1), zeros (0, 3)) + +%!assert (hsv (6)(:), [1, 1, 0, 0, 0, 1, 0, 1, 1, 1, 0, 0, 0, 0, 0, 1, 1, 1]') + +## Input validation +%!error <function called with too many inputs> hsv (1, 2) +%!error <N must be a scalar> hsv ("foo") +%!error <N must be a scalar> hsv ([1, 2, 3]) +%!error <N must be a scalar> hsv ({1, 2, 3})
--- a/scripts/image/jet.m Fri Dec 22 22:50:09 2023 +0100 +++ b/scripts/image/jet.m Tue Dec 26 14:46:41 2023 -0500 @@ -30,7 +30,8 @@ ## cyan, green, yellow, red, to dark red. ## ## The argument @var{n} must be a scalar. -## If unspecified, the length of the current colormap, or 64, is used. +## If @var{n} is not specified the length of the current colormap is used. If +## there is no current colormap the default value of 256 is used. ## ## Programming Note: The @code{jet} colormap is not perceptually uniform. ## Try the @code{viridis} colormap if that is important. For a drop-in @@ -51,7 +52,7 @@ if (! isempty (hf)) n = rows (get (hf, "colormap")); else - n = 64; + n = 256; endif endif if (n == 1) @@ -110,3 +111,29 @@ %! rgbplot (cmap, "composite"); %! subplot (2, 1, 2); %! rgbplot (cmap); + + +%!assert (size (jet ()), [256, 3]) +%!assert (size (jet (16)), [16, 3]) + +%!assert (jet (1), [0, 1, 1]) +%!assert (jet (true), double ([0, 1, 1])) +%!assert (jet (char (1)), double ([0, 1, 1])) +%!assert (jet (int32 (1)), double ([0, 1, 1])) +%!assert (jet (2), [0, 0, 1; 0, 1, 1]) + +%!assert (jet (0), zeros (0, 3)) +%!assert (jet (-1), zeros (0, 3)) + +%!test +%! a = zeros(15, 3); +%! a([3:13],2) = [0.25, 0.5, 0.75, 1, 1, 1, 1, 1, 0.75, 0.5, 0.25]; +%! a([7:15], 1) = a([3:11], 2); +%! a(:,3) = flipud (a(:,1)); +%! assert (jet (15), a, eps) + +## Input validation +%!error <function called with too many inputs> jet (1, 2) +%!error <N must be a scalar> jet ("foo") +%!error <N must be a scalar> jet ([1, 2, 3]) +%!error <N must be a scalar> jet ({1, 2, 3})
--- a/scripts/image/lines.m Fri Dec 22 22:50:09 2023 +0100 +++ b/scripts/image/lines.m Tue Dec 26 14:46:41 2023 -0500 @@ -31,7 +31,8 @@ ## orange, yellow, purple, green, light blue, and dark red. ## ## The argument @var{n} must be a scalar. -## If unspecified, the length of the current colormap, or 64, is used. +## If @var{n} is not specified the length of the current colormap is used. If +## there is no current colormap the default value of 256 is used. ## @seealso{colormap} ## @end deftypefn @@ -47,7 +48,7 @@ if (! isempty (hf)) n = rows (get (hf, "colormap")); else - n = 64; + n = 256; endif endif @@ -76,3 +77,26 @@ %! rgbplot (cmap, "composite"); %! subplot (2, 1, 2); %! rgbplot (cmap); + + +%!assert (size (lines ()), [256, 3]) +%!assert (size (lines (16)), [16, 3]) + +%!assert (lines (1), [0, 0, 1]) +%!assert (lines (true), double ([0, 0, 1])) +%!assert (lines (char (1)), double ([0, 0, 1])) +%!assert (lines (int32 (1)), double ([0, 0, 1])) + +%!assert (lines (0), zeros (0, 3)) +%!assert (lines (-1), zeros (0, 3)) + +%!test +%! a = get (groot, "defaultaxescolororder"); +%! nr = rows (a); +%! assert (lines (3*nr), [a;a;a]); + +## Input validation +%!error <function called with too many inputs> lines (1, 2) +%!error <N must be a scalar> lines ("foo") +%!error <N must be a scalar> lines ([1, 2, 3]) +%!error <N must be a scalar> lines ({1, 2, 3})
--- a/scripts/image/ocean.m Fri Dec 22 22:50:09 2023 +0100 +++ b/scripts/image/ocean.m Tue Dec 26 14:46:41 2023 -0500 @@ -30,7 +30,8 @@ ## of blue. ## ## The argument @var{n} must be a scalar. -## If unspecified, the length of the current colormap, or 64, is used. +## If @var{n} is not specified the length of the current colormap is used. If +## there is no current colormap the default value of 256 is used. ## @seealso{colormap} ## @end deftypefn @@ -46,7 +47,7 @@ if (! isempty (hf)) n = rows (get (hf, "colormap")); else - n = 64; + n = 256; endif endif @@ -78,3 +79,31 @@ %! rgbplot (cmap, "composite"); %! subplot (2, 1, 2); %! rgbplot (cmap); + + +%!assert (size (ocean ()), [256, 3]) +%!assert (size (ocean (16)), [16, 3]) + +%!assert (ocean (1), [0, 0, 0]) +%!assert (ocean (true), double ([0, 0, 0])) +%!assert (ocean (char (1)), double ([0, 0, 0])) +%!assert (ocean (int32 (1)), double ([0, 0, 0])) + +%!assert (ocean (0), zeros (0, 3)) +%!assert (ocean (-1), zeros (0, 3)) + +%!assert (ocean()(1,:), [0, 0, 0]) +%!assert (ocean()(end,:), [1, 1, 1]) + +%!test +%! a = zeros (11, 3); +%! a([9:11],1) = [1/3, 2/3, 1]; +%! a([6:11], 2) = 1/6:1/6:1; +%! a(:, 3) = 0:.1:1; +%! assert (ocean (11), a, eps) + +## Input validation +%!error <function called with too many inputs> ocean (1, 2) +%!error <N must be a scalar> ocean ("foo") +%!error <N must be a scalar> ocean ([1, 2, 3]) +%!error <N must be a scalar> ocean ({1, 2, 3})
--- a/scripts/image/pink.m Fri Dec 22 22:50:09 2023 +0100 +++ b/scripts/image/pink.m Tue Dec 26 14:46:41 2023 -0500 @@ -32,7 +32,8 @@ ## This colormap gives a sepia tone when used on grayscale images. ## ## The argument @var{n} must be a scalar. -## If unspecified, the length of the current colormap, or 64, is used. +## If @var{n} is not specified the length of the current colormap is used. If +## there is no current colormap the default value of 256 is used. ## @seealso{colormap} ## @end deftypefn @@ -48,11 +49,13 @@ if (! isempty (hf)) n = rows (get (hf, "colormap")); else - n = 64; + n = 256; endif endif if (n == 1) map = sqrt ([1/3, 1/3, 1/3]); +%!assert (pink (-1), zeros (0, 3)) + elseif (n == 2) map = sqrt ([1/3, 1/3, 1/6 1 1 1 ]); @@ -88,3 +91,29 @@ %! rgbplot (cmap, "composite"); %! subplot (2, 1, 2); %! rgbplot (cmap); + + +%!assert (size (pink ()), [256, 3]) +%!assert (size (pink (16)), [16, 3]) + +%!assert (pink (1), sqrt ([1/3, 1/3, 1/3]), eps) +%!assert (pink (true), double (sqrt ([1/3, 1/3, 1/3])), eps) +%!assert (pink (char (1)), double (sqrt ([1/3, 1/3, 1/3])), eps) +%!assert (pink (int32 (1)), double (sqrt ([1/3, 1/3, 1/3])), eps) +%!assert (pink (2), sqrt ([1/3, 1/3, 1/6; 1, 1, 1])) + +%!assert (pink (0), zeros (0, 3)) +%!assert (pink()(end,:), [1 1 1], eps) + +%!test +%! a = sqrt ([1/3, 0, 0; +%! 5/9, 5/9, 2/9; +%! 7/9, 7/9, 11/18; +%! 1, 1, 1]); +%! assert (pink (4), a, eps) + +## Input validation +%!error <function called with too many inputs> pink (1, 2) +%!error <N must be a scalar> pink ("foo") +%!error <N must be a scalar> pink ([1, 2, 3]) +%!error <N must be a scalar> pink ({1, 2, 3})
--- a/scripts/image/prism.m Fri Dec 22 22:50:09 2023 +0100 +++ b/scripts/image/prism.m Tue Dec 26 14:46:41 2023 -0500 @@ -30,7 +30,8 @@ ## green, blue and violet with each index change. ## ## The argument @var{n} must be a scalar. -## If unspecified, the length of the current colormap, or 64, is used. +## If @var{n} is not specified the length of the current colormap is used. If +## there is no current colormap the default value of 256 is used. ## @seealso{colormap} ## @end deftypefn @@ -46,7 +47,7 @@ if (! isempty (hf)) n = rows (get (hf, "colormap")); else - n = 64; + n = 256; endif endif if (n == 1) @@ -68,3 +69,26 @@ %! rgbplot (cmap, "composite"); %! subplot (2, 1, 2); %! rgbplot (cmap); + + +%!assert (size (prism ()), [256, 3]) +%!assert (size (prism (16)), [16, 3]) + +%!assert (prism (1), [1, 0, 0]) +%!assert (prism (true), double ([1, 0, 0])) +%!assert (prism (char (1)), double ([1, 0, 0])) +%!assert (prism (int32 (1)), double ([1, 0, 0])) + +%!assert (prism (0), zeros (0, 3)) +%!assert (prism (-1), zeros (0, 3)) + +%!test +%! a = [1, 0, 0; 1, 1/2, 0; 1, 1, 0; 0, 1, 0; 0, 0, 1; 2/3, 0, 1]; +%! nr = rows (a); +%! assert (prism (3*nr), [a;a;a]); + +## Input validation +%!error <function called with too many inputs> prism (1, 2) +%!error <N must be a scalar> prism ("foo") +%!error <N must be a scalar> prism ([1, 2, 3]) +%!error <N must be a scalar> prism ({1, 2, 3})
--- a/scripts/image/rainbow.m Fri Dec 22 22:50:09 2023 +0100 +++ b/scripts/image/rainbow.m Tue Dec 26 14:46:41 2023 -0500 @@ -30,7 +30,8 @@ ## yellow, green, blue, to violet. ## ## The argument @var{n} must be a scalar. -## If unspecified, the length of the current colormap, or 64, is used. +## If @var{n} is not specified the length of the current colormap is used. If +## there is no current colormap the default value of 256 is used. ## @seealso{colormap} ## @end deftypefn @@ -49,7 +50,7 @@ if (! isempty (hf)) n = rows (get (hf, "colormap")); else - n = 64; + n = 256; endif endif @@ -84,3 +85,22 @@ %! rgbplot (cmap, "composite"); %! subplot (2, 1, 2); %! rgbplot (cmap); + +%!assert (size (rainbow ()), [256, 3]) +%!assert (size (rainbow (16)), [16, 3]) + +%!assert (rainbow (1), [1, 0, 0]) +%!assert (rainbow (true), double ([1, 0, 0])) +%!assert (rainbow (char (1)), double ([1, 0, 0])) +%!assert (rainbow (int32 (1)), double ([1, 0, 0])) + +%!assert (rainbow (0), zeros (0, 3)) +%!assert (rainbow (-1), zeros (0, 3)) + +%!assert (rainbow (6)(:), [1, 1, 1, 0, 0, 2/3, 0, 0.5, 1, 1, 0, 0, 0, 0, 0, 0, 1, 1]', 3*eps) + +## Input validation +%!error <function called with too many inputs> rainbow (1, 2) +%!error <N must be a scalar> rainbow ("foo") +%!error <N must be a scalar> rainbow ([1, 2, 3]) +%!error <N must be a scalar> rainbow ({1, 2, 3})
--- a/scripts/image/spring.m Fri Dec 22 22:50:09 2023 +0100 +++ b/scripts/image/spring.m Tue Dec 26 14:46:41 2023 -0500 @@ -29,7 +29,8 @@ ## Create color colormap. This colormap varies from magenta to yellow. ## ## The argument @var{n} must be a scalar. -## If unspecified, the length of the current colormap, or 64, is used. +## If @var{n} is not specified the length of the current colormap is used. If +## there is no current colormap the default value of 256 is used. ## @seealso{colormap} ## @end deftypefn @@ -45,7 +46,7 @@ if (! isempty (hf)) n = rows (get (hf, "colormap")); else - n = 64; + n = 256; endif endif @@ -70,3 +71,23 @@ %! rgbplot (cmap, "composite"); %! subplot (2, 1, 2); %! rgbplot (cmap); + + +%!assert (size (spring ()), [256, 3]) +%!assert (size (spring (16)), [16, 3]) +%!assert (all ((spring ()(:, 1)) == 1), true) +%!assert (spring (11)(:,2:3), [[0:0.1:1]; [1:-0.1:0]]', eps) + +%!assert (spring (1), [1, 0, 1]) +%!assert (spring (true), double ([1, 0, 1])) +%!assert (spring (char (1)), double ([1, 0, 1])) +%!assert (spring (int32 (1)), double ([1, 0, 1])) + +%!assert (spring (0), zeros (0, 3)) +%!assert (spring (-1), zeros (0, 3)) + +## Input validation +%!error <function called with too many inputs> spring (1, 2) +%!error <N must be a scalar> spring ("foo") +%!error <N must be a scalar> spring ([1, 2, 3]) +%!error <N must be a scalar> spring ({1, 2, 3})
--- a/scripts/image/summer.m Fri Dec 22 22:50:09 2023 +0100 +++ b/scripts/image/summer.m Tue Dec 26 14:46:41 2023 -0500 @@ -29,7 +29,8 @@ ## Create color colormap. This colormap varies from green to yellow. ## ## The argument @var{n} must be a scalar. -## If unspecified, the length of the current colormap, or 64, is used. +## If @var{n} is not specified the length of the current colormap is used. If +## there is no current colormap the default value of 256 is used. ## @seealso{colormap} ## @end deftypefn @@ -45,7 +46,7 @@ if (! isempty (hf)) n = rows (get (hf, "colormap")); else - n = 64; + n = 256; endif endif @@ -70,3 +71,23 @@ %! rgbplot (cmap, "composite"); %! subplot (2, 1, 2); %! rgbplot (cmap); + + +%!assert (size (summer ()), [256, 3]) +%!assert (size (summer (16)), [16, 3]) + +%!assert (summer (1), [0, 0.5, 0.4]) +%!assert (summer (true), double ([0, 0.5, 0.4])) +%!assert (summer (char (1)), double ([0, 0.5, 0.4])) +%!assert (summer (int32 (1)), double ([0, 0.5, 0.4])) + +%!assert (summer (0), zeros (0, 3)) +%!assert (summer (-1), zeros (0, 3)) + +%!assert (summer (11), [[0:0.1:1]; [0.5:0.05:1]; 0.4 * ones(1,11)]', eps) + +## Input validation +%!error <function called with too many inputs> summer (1, 2) +%!error <N must be a scalar> summer ("foo") +%!error <N must be a scalar> summer ([1, 2, 3]) +%!error <N must be a scalar> summer ({1, 2, 3})
--- a/scripts/image/turbo.m Fri Dec 22 22:50:09 2023 +0100 +++ b/scripts/image/turbo.m Tue Dec 26 14:46:41 2023 -0500 @@ -31,7 +31,8 @@ ## uniform. ## ## The argument @var{n} must be a scalar. -## If unspecified, the length of the current colormap, or 64, is used. +## If @var{n} is not specified the length of the current colormap is used. If +## there is no current colormap the default value of 256 is used. ## @seealso{colormap} ## @end deftypefn @@ -51,7 +52,7 @@ if (! isempty (hf)) n = rows (get (hf, "colormap")); else - n = 64; + n = 256; endif endif @@ -325,3 +326,30 @@ %! rgbplot (cmap, "composite"); %! subplot (2, 1, 2); %! rgbplot (cmap); + + +%!assert (size (turbo ()), [256, 3]) +%!assert (size (turbo (16)), [16, 3]) + +%!assert (turbo(0), zeros (0, 3)) +%!assert (turbo(-1), zeros (0, 3)) + +%!shared a +%! a = [0.18995, 0.07176, 0.23217; +%! 0.10342, 0.89600, 0.71500; +%! 0.98000, 0.73000, 0.22161; +%! 0.47960, 0.01583, 0.01055]; + +%!assert (turbo (1), a(4,:)) +%!assert (turbo (true), double (a(4,:))) +%!assert (turbo (char (1)), double (a(4,:))) +%!assert (turbo (int32 (1)), double (a(4,:))) +%!assert (turbo (4), a, eps) + +%!shared # Clear shared varibles to avoid echo on unrelated test errors. + +## Input validation +%!error <function called with too many inputs> turbo (1, 2) +%!error <N must be a scalar> turbo ("foo") +%!error <N must be a scalar> turbo ([1, 2, 3]) +%!error <N must be a scalar> turbo ({1, 2, 3})
--- a/scripts/image/viridis.m Fri Dec 22 22:50:09 2023 +0100 +++ b/scripts/image/viridis.m Tue Dec 26 14:46:41 2023 -0500 @@ -30,7 +30,8 @@ ## blue, green, to yellow. ## ## The argument @var{n} must be a scalar. -## If unspecified, the length of the current colormap, or 64, is used. +## If @var{n} is not specified the length of the current colormap is used. If +## there is no current colormap the default value of 256 is used. ## @seealso{colormap} ## @end deftypefn @@ -50,9 +51,10 @@ if (! isempty (hf)) n = rows (get (hf, "colormap")); else - n = 64; + n = 256; endif endif + ## FIXME: Is there no algorithmic definition of the viridis colormap? persistent viridi = [0.26700401 0.00487433 0.32941519 0.26851048 0.00960483 0.33542652 @@ -325,3 +327,29 @@ %! rgbplot (cmap, "composite"); %! subplot (2, 1, 2); %! rgbplot (cmap); + +%!assert (size (viridis ()), [256, 3]) +%!assert (size (viridis (16)), [16, 3]) + +%!assert (viridis (0), zeros (0, 3)) +%!assert (viridis (-1), zeros (0, 3)) + +%!shared a +%! a = [0.26700401, 0.00487433, 0.32941519; +%! 0.19063135, 0.40706148, 0.55608907; +%! 0.20803045, 0.71870095, 0.47287330; +%! 0.99324789, 0.90615657, 0.14393620]; + +%!assert (viridis (1), a(4,:)) +%!assert (viridis (true), double (a(4,:))) +%!assert (viridis (char (1)), double (a(4,:))) +%!assert (viridis (int32 (1)), double (a(4,:))) +%!assert (viridis (4), a, eps) + +%!shared # Clear shared varibles to avoid echo on unrelated test errors. + +## Input validation +%!error <function called with too many inputs> viridis (1, 2) +%!error <N must be a scalar> viridis ("foo") +%!error <N must be a scalar> viridis ([1, 2, 3]) +%!error <N must be a scalar> viridis ({1, 2, 3})
--- a/scripts/image/white.m Fri Dec 22 22:50:09 2023 +0100 +++ b/scripts/image/white.m Tue Dec 26 14:46:41 2023 -0500 @@ -29,7 +29,8 @@ ## Create color colormap. This colormap is completely white. ## ## The argument @var{n} must be a scalar. -## If unspecified, the length of the current colormap, or 64, is used. +## If @var{n} is not specified the length of the current colormap is used. If +## there is no current colormap the default value of 256 is used. ## @seealso{colormap} ## @end deftypefn @@ -45,7 +46,7 @@ if (! isempty (hf)) n = rows (get (hf, "colormap")); else - n = 64; + n = 256; endif endif map = ones (n, 3); @@ -60,3 +61,21 @@ %! rgbplot (cmap, "composite"); %! subplot (2, 1, 2); %! rgbplot (cmap); + +%!assert (size (white ()), [256, 3]) +%!assert (size (white (16)), [16, 3]) +%!assert (all ((white ()(:)) == 1), true) + +%!assert (white (1), [1, 1, 1]) +%!assert (white (true), double ([1, 1, 1])) +%!assert (white (char (1)), double ([1, 1, 1])) +%!assert (white (int32 (1)), double ([1, 1, 1])) +%!assert (white (0), zeros (0, 3)) +%!assert (white (-1), zeros (0, 3)) + + +## Input validation +%!error <function called with too many inputs> white (1, 2) +%!error <N must be a scalar> white ("foo") +%!error <N must be a scalar> white ([1, 2, 3]) +%!error <N must be a scalar> white ({1, 2, 3})
--- a/scripts/image/winter.m Fri Dec 22 22:50:09 2023 +0100 +++ b/scripts/image/winter.m Tue Dec 26 14:46:41 2023 -0500 @@ -29,7 +29,8 @@ ## Create color colormap. This colormap varies from blue to green. ## ## The argument @var{n} must be a scalar. -## If unspecified, the length of the current colormap, or 64, is used. +## If @var{n} is not specified the length of the current colormap is used. If +## there is no current colormap the default value of 256 is used. ## @seealso{colormap} ## @end deftypefn @@ -45,7 +46,7 @@ if (! isempty (hf)) n = rows (get (hf, "colormap")); else - n = 64; + n = 256; endif endif @@ -70,3 +71,23 @@ %! rgbplot (cmap, "composite"); %! subplot (2, 1, 2); %! rgbplot (cmap); + + +%!assert (size (winter ()), [256, 3]) +%!assert (size (winter (16)), [16, 3]) + +%!assert (winter (1), [0, 0, 1]) +%!assert (winter (true), double ([0, 0, 1])) +%!assert (winter (char (1)), double ([0, 0, 1])) +%!assert (winter (int32 (1)), double ([0, 0, 1])) + +%!assert (winter (0), zeros (0, 3)) +%!assert (winter (-1), zeros (0, 3)) + +%!assert (winter (11), [zeros(1,11); [0:0.1:1]; [1:-0.05:0.5]]', eps) + +## Input validation +%!error <function called with too many inputs> winter (1, 2) +%!error <N must be a scalar> winter ("foo") +%!error <N must be a scalar> winter ([1, 2, 3]) +%!error <N must be a scalar> winter ({1, 2, 3})
--- a/scripts/plot/draw/rose.m Fri Dec 22 22:50:09 2023 +0100 +++ b/scripts/plot/draw/rose.m Tue Dec 26 14:46:41 2023 -0500 @@ -24,12 +24,12 @@ ######################################################################## ## -*- texinfo -*- -## @deftypefn {} {} rose (@var{th}) -## @deftypefnx {} {} rose (@var{th}, @var{nbins}) -## @deftypefnx {} {} rose (@var{th}, @var{bins}) +## @deftypefn {} {} rose (@var{theta}) +## @deftypefnx {} {} rose (@var{theta}, @var{nbins}) +## @deftypefnx {} {} rose (@var{theta}, @var{bins}) ## @deftypefnx {} {} rose (@var{hax}, @dots{}) ## @deftypefnx {} {@var{h} =} rose (@dots{}) -## @deftypefnx {} {[@var{thout} @var{rout}] =} rose (@dots{}) +## @deftypefnx {} {[@var{th} @var{r}] =} rose (@dots{}) ## Plot an angular histogram. ## ## With one vector argument, @var{th}, plot the histogram with 20 angular bins. @@ -59,16 +59,19 @@ ## @end group ## @end example ## -## Programming Note: When specifying bin centers with the @var{bins} input, -## the edges for bins 2 to N-1 are spaced so that @code{@var{bins}(i)} is -## centered between the edges. The final edge is drawn halfway between bin N -## and bin 1. This guarantees that all input @var{th} will be placed into one -## of the bins, but also means that for some combinations bin 1 and bin N may -## not be centered on the user's given values. ## @seealso{hist, polar} ## @end deftypefn -function [thout, rout] = rose (varargin) +## Programming note: Ranges are calculated in degrees and then converted to +## radians because the use of integers prevents accumulation of small errors +## that result when using floating point directly. +## The histogram counts are calculated using histc(). See the documentation. +## The final count from histc() contains any values *exactly* equal to the +## last bin edge which is always 2*pi. Because the input mapping of +## "mod (th, 2*pi)" changes any 2*pi values to 0, this last bin should always +## be zero and can be safely deleted. + +function [th, r] = rose (varargin) [hax, varargin, nargin] = __plt_get_axis_arg__ ("rose", varargin{:}); @@ -76,49 +79,62 @@ print_usage (); endif - th = varargin{1}; - ## Force theta to [0,2*pi] range - th = atan2 (sin (th), cos (th)); - th(th < 0) += 2*pi; + ## Force theta to range [0,2*pi) + th = mod (varargin{1}, 2*pi); custom_bins = false; if (nargin == 1) - bins = [1/40 : 1/20 : 1] * 2*pi; + bins = [9 : 18 : 360] / 180 * pi; else bins = varargin{2}; if (isscalar (bins)) - bins = [0.5/bins : 1/bins : 1] * 2*pi; + bins = [180/bins : 360/bins : 360] / 180 * pi; else custom_bins = true; - ## Force angles to [0,2*pi] range - bins = atan2 (sin (bins), cos (bins)); - bins(bins < 0) += 2*pi; - bins = unique (bins); + ## Force custom bins to [0,2*pi) range + bins = mod (bins, 2*pi); + bins = unique (bins); # de-duplicate and sort bins + bins = bins(:).'; # Force row vector endif endif - if (numel (bins) < 3) - warning ("rose: bin sizes >= pi will not plot correctly"); + + binedge = bins(1:end-1) + diff (bins) / 2; # halfway between bin centers + if (! custom_bins) + counts = histc (th, [0, binedge, 2*pi]); # Add implicit edges at 0, 2*pi + if (isrow (counts)) + counts = counts(:); + endif + ## FIXME: Remove in Octave 11 if no bug reports filed + if (any (counts(end,:))) + error ("rose: internal error, histc returned count for theta == 2*pi, please file a bug report"); + endif + counts(end,:) = []; # remove temporary bin + else + last_binedge = bins(end) + diff ([bins(end), 2*pi+bins(1)]) / 2; + if (last_binedge >= 2*pi) + counts = histc (th, [0, last_binedge - 2*pi, binedge, 2*pi]); + else + counts = histc (th, [0, binedge, last_binedge, 2*pi]); + endif + if (isrow (counts)) + counts = counts(:); + endif + counts(end-1,:) += counts(1,:); # Combine counts for first, last bin + ## FIXME: Remove in Octave 11 if no bug reports filed + if (any (counts(end,:))) + error ("rose: internal error, histc returned count for theta == 2*pi, please file a bug report"); + endif + counts([1,end], :) = []; # remove temporary bins endif - [counts, binctr] = hist (th, bins); - binctr = binctr(:).'; # Force row vector - if (isvector (counts)) - counts = counts(:); - endif - - binedge = binctr(1:end-1) + diff (binctr) / 2; binedge = [binedge ; zeros(size(binedge)); zeros(size(binedge)); binedge]; binedge = binedge(:); if (! custom_bins) - ## Add in implicit edges at 0 and 2*pi + ## Add implicit edges at 0 and 2*pi th = [0; 0; binedge; 2*pi ; 0]; else - ## Add in final edge - last_bin_edge = binctr(end) + diff ([binctr(end), (2*pi+binctr(1))])/2; - if ((binedge(end) + last_bin_edge)/2 != binctr(end)) - warning ("rose: bin 1 and bin %d are not centered", numel (binctr)); - endif - th = [0; last_bin_edge; binedge; last_bin_edge; 0]; + ## Add final edge for custom bin + th = [0; last_binedge; binedge; last_binedge; 0]; endif r = zeros (4 * rows (counts), columns (counts)); @@ -126,6 +142,10 @@ r(3:4:end, :) = counts; if (nargout < 2) + if (any (diff (bins) >= pi)) + warning ("rose: bin sizes >= pi will not plot correctly"); + endif + oldfig = []; if (! isempty (hax)) oldfig = get (0, "currentfigure"); @@ -140,11 +160,8 @@ end_unwind_protect if (nargout > 0) - thout = htmp; + th = htmp; endif - else - thout = th; - rout = r; endif endfunction @@ -165,10 +182,30 @@ %! rose ([0, 2, 3, 5], [0, pi/2, pi, 3*pi/2]); %! title ("rose() angular histogram plot with specified bins"); +## Test mapping inputs to [0, 2*pi), 2*pi mapped to bin 1. +%!test +%! [t, r] = rose ([1:1:360]/180*pi + 2*pi); +%! assert (diff (t(2:4:end)), 2*pi/20 * ones (19, 1)); +%! assert (r(2:4:end), 18*ones (20, 1)); + +## Custom # of bins, values exactly at 0 and 2*pi go to bin 1 +%!test +%! [t,r] = rose ([0, 2*pi], 4); +%! assert (size (t), [16, 1]); +%! assert (size (r), [16, 1]); +%! assert ([t(2); t(3:4:end)], [0; pi/2; pi; 3*pi/2; 2*pi]); +%! assert (r(2:4:end), [2; 0; 0; 0]); + +## Custom bins, synthesized bin1 cut-off is exactly 36 degrees +%!test +%! [t,r] = rose (deg2rad ([35, 36]), pi * [1/2, 1, 1.5, 1.9]); +%! assert (r(2:4:end), [1; 0; 0; 1]); + +## Custom bins, synthesized bin1 cut-off is exactly -36 degrees +%!test +%! [t,r] = rose (deg2rad ([-36, -37, 360]), pi * [1/10, 1/2, 1, 1.5]); +%! assert (r(2:4:end), [0; 0; 1; 2]); + ## Test input validation %!error <Invalid call> rose () %!error <Invalid call> rose (1,2,3) -%!warning <bin sizes .= pi will not plot correctly> -%! [th, r] = rose ([1 2 2 4 4 4], 2); -%!warning <bin 1 and bin 3 are not centered> -%! [th, r] = rose ([1 2 2 4 4 4], [1 2 3]);