kopia lustrzana https://github.com/backface/turtlestitch
experimental "width of _" reporter relabelling option for "length of _"
rodzic
9ee7c9287b
commit
62a9ea8770
|
@ -6,6 +6,7 @@
|
|||
* hyperized image attribute reporter primitive (monadic)
|
||||
* when constructing a costume from a pixel list handle single values as greyscale
|
||||
* experimental "column _ of _" reporter relabelling option for "item _ of _"
|
||||
* experimental "width of _" reporter relabelling option for "length of _"
|
||||
* **Notable Fixes:**
|
||||
* fixed a glitch in the animation library's "sine in-out" easing function
|
||||
* fixed a postMessage glitch in the API, thanks, Bernat!
|
||||
|
@ -15,6 +16,7 @@
|
|||
### 2021-01-26
|
||||
* threads: handle single values as greyscale when constructing a costume from a pixel list
|
||||
* threads, objects experimental "column _ of _" reporter relabelling option for "item _ of _"
|
||||
* threads, objects experimental "width of _" reporter relabelling option for "length of _"
|
||||
|
||||
### 2021-01-25
|
||||
* threads: hyperized image attribute reporter primitive (monadic)
|
||||
|
|
|
@ -1334,6 +1334,11 @@ SpriteMorph.prototype.initBlocks = function () {
|
|||
category: 'lists',
|
||||
spec: 'length of %l'
|
||||
},
|
||||
reportTableWidth: {
|
||||
type: 'reporter',
|
||||
category: 'lists',
|
||||
spec: 'width of %l'
|
||||
},
|
||||
reportListContainsItem: {
|
||||
type: 'predicate',
|
||||
category: 'lists',
|
||||
|
@ -1719,6 +1724,8 @@ SpriteMorph.prototype.blockAlternatives = {
|
|||
// lists
|
||||
reportListItem: ['reportTableColumn'],
|
||||
reportTableColumn: ['reportListItem'],
|
||||
reportListLength: ['reportTableWidth'],
|
||||
reportTableWidth: ['reportListLength'],
|
||||
|
||||
// HOFs
|
||||
reportMap: ['reportKeep', 'reportFindFirst'],
|
||||
|
|
|
@ -2006,19 +2006,20 @@ Process.prototype.reportItems = function (indices, list) {
|
|||
}
|
||||
};
|
||||
|
||||
// Process - other basic list accessors
|
||||
// Process - experimental tabular list accessors
|
||||
|
||||
Process.prototype.reportTableWidth = function (list) {
|
||||
// experimental - answer the length of the longest sub-list
|
||||
this.assertType(list, 'list');
|
||||
return Math.max(...list.itemsArray().map(row =>
|
||||
row instanceof List ? row.length() : 0)
|
||||
);
|
||||
};
|
||||
|
||||
Process.prototype.reportTableColumn = function (index, list) {
|
||||
// experimental and probably controversial as a primitive,
|
||||
// because it's so nice and easy to write in Snap!
|
||||
var col;
|
||||
|
||||
function columns() {
|
||||
return Math.max(...list.itemsArray().map(row =>
|
||||
row instanceof List ? row.length() : 0)
|
||||
);
|
||||
}
|
||||
|
||||
if (!this.isMatrix(list)) {
|
||||
throw new Error(
|
||||
'expecting ' + 'table' + ' but getting ' + this.reportTypeOf(list)
|
||||
|
@ -2028,15 +2029,17 @@ Process.prototype.reportTableColumn = function (index, list) {
|
|||
return new List(new Array(list.length()));
|
||||
}
|
||||
if (this.inputOption(index) === 'any') {
|
||||
col = this.reportBasicRandom(1, columns());
|
||||
col = this.reportBasicRandom(1, this.reportTableWidth(list));
|
||||
return list.map(row => row.at(col));
|
||||
}
|
||||
if (this.inputOption(index) === 'last') {
|
||||
return list.map(row => row.at(columns()));
|
||||
return list.map(row => row.at(this.reportTableWidth(list)));
|
||||
}
|
||||
return list.map(row => row.at(index));
|
||||
};
|
||||
|
||||
// Process - other basic list accessors
|
||||
|
||||
Process.prototype.reportListLength = function (list) {
|
||||
this.assertType(list, 'list');
|
||||
return list.length();
|
||||
|
|
Ładowanie…
Reference in New Issue