code
stringlengths
24
2.07M
docstring
stringlengths
25
85.3k
func_name
stringlengths
1
92
language
stringclasses
1 value
repo
stringlengths
5
64
path
stringlengths
4
172
url
stringlengths
44
218
license
stringclasses
7 values
_drawColumnDragHighlight(painter, col) { if (this._highlightedSlot !== undefined && this._highlightedSlot.col === col && this._highlightedSlot.row === undefined) { let rect = this.gateRect(0, col, 1, this._groundedWireCount()).paddedBy(3); painter.fillRect(rect, '...
@param {!Painter} painter @param {!GateColumn} gateColumn @param {!int} col @param {!CircuitStats} stats @private
_drawColumnDragHighlight
javascript
Strilanc/Quirk
src/ui/DisplayedCircuit.js
https://github.com/Strilanc/Quirk/blob/master/src/ui/DisplayedCircuit.js
Apache-2.0
_drawColumnControlWires(painter, columnIndex) { let x = Math.round(this.opRect(columnIndex).center().x - 0.5) + 0.5; // Dashed line indicates effects from non-unitary gates may affect, or appear to affect, other wires. if (this.circuitDefinition.columns[columnIndex].hasGatesWithGlobalEffects())...
@param {!Painter} painter @param {!int} columnIndex @private
_drawColumnControlWires
javascript
Strilanc/Quirk
src/ui/DisplayedCircuit.js
https://github.com/Strilanc/Quirk/blob/master/src/ui/DisplayedCircuit.js
Apache-2.0
_previewDropMovedRow(hand) { if (hand.pos === undefined) { return this; } let handWire = this.wireIndexAt(hand.pos.y); if (handWire < 0 || handWire >= this.circuitDefinition.numWires) { // Dragged the row out of the circuit. return this; } ...
@param {!Hand} hand @returns {!DisplayedCircuit} @private
_previewDropMovedRow
javascript
Strilanc/Quirk
src/ui/DisplayedCircuit.js
https://github.com/Strilanc/Quirk/blob/master/src/ui/DisplayedCircuit.js
Apache-2.0
_previewDropMovedGateColumn(hand) { if (hand.pos === undefined) { return this; } let handWire = this.wireIndexAt(hand.pos.y); if (handWire < 0 || handWire >= Config.MAX_WIRE_COUNT || hand.pos.x <= 1) { // Dragged the gate column out of the circuit. ret...
@param {!Hand} hand @returns {!DisplayedCircuit} @private
_previewDropMovedGateColumn
javascript
Strilanc/Quirk
src/ui/DisplayedCircuit.js
https://github.com/Strilanc/Quirk/blob/master/src/ui/DisplayedCircuit.js
Apache-2.0
_shiftAndSpliceColumn(rowShift, gatesOfCol, insertCol, isInsert) { // Move gates upward. while (rowShift < 0 && gatesOfCol[0] === undefined) { gatesOfCol.shift(); gatesOfCol.push(undefined); rowShift += 1; } // Shift gates downward. while (row...
@param {!Hand} hand @returns {!DisplayedCircuit} @private
_shiftAndSpliceColumn
javascript
Strilanc/Quirk
src/ui/DisplayedCircuit.js
https://github.com/Strilanc/Quirk/blob/master/src/ui/DisplayedCircuit.js
Apache-2.0
_previewDropMovedGate(hand) { let modificationPoint = this.findModificationIndex(hand); if (modificationPoint === undefined) { return this; } // Use the grab offset instead of the gate height so that tall gates are 'sticky' when dragging downward: they // aren't remo...
@param {!Hand} hand @returns {!DisplayedCircuit} @private
_previewDropMovedGate
javascript
Strilanc/Quirk
src/ui/DisplayedCircuit.js
https://github.com/Strilanc/Quirk/blob/master/src/ui/DisplayedCircuit.js
Apache-2.0
_previewResizedGate(hand) { if (hand.resizingGateSlot === undefined || hand.pos === undefined) { return this; } let gate = this.circuitDefinition.gateInSlot(hand.resizingGateSlot.x, hand.resizingGateSlot.y); if (gate === undefined) { return this; } ...
@param {!Hand} hand @returns {!DisplayedCircuit} @private
_previewResizedGate
javascript
Strilanc/Quirk
src/ui/DisplayedCircuit.js
https://github.com/Strilanc/Quirk/blob/master/src/ui/DisplayedCircuit.js
Apache-2.0
_withCompressedColumnIndex(compressedColumnIndex) { return new DisplayedCircuit( this.top, this.circuitDefinition, compressedColumnIndex, this._highlightedSlot, this._extraWireStartIndex); }
@param {undefined|!int} compressedColumnIndex @returns {!DisplayedCircuit} @private
_withCompressedColumnIndex
javascript
Strilanc/Quirk
src/ui/DisplayedCircuit.js
https://github.com/Strilanc/Quirk/blob/master/src/ui/DisplayedCircuit.js
Apache-2.0
_withHighlightedSlot(slot) { return new DisplayedCircuit( this.top, this.circuitDefinition, this._compressedColumnIndex, slot, this._extraWireStartIndex); }
@param {undefined|!{col: undefined|!int, row: undefined|!int, resizeStyle: !boolean}} slot @returns {!DisplayedCircuit} @private
_withHighlightedSlot
javascript
Strilanc/Quirk
src/ui/DisplayedCircuit.js
https://github.com/Strilanc/Quirk/blob/master/src/ui/DisplayedCircuit.js
Apache-2.0
_withExtraWireStartIndex(extraWireStartIndex) { return new DisplayedCircuit( this.top, this.circuitDefinition, this._compressedColumnIndex, this._highlightedSlot, extraWireStartIndex); }
@param {undefined|!int} extraWireStartIndex @returns {!DisplayedCircuit} @private
_withExtraWireStartIndex
javascript
Strilanc/Quirk
src/ui/DisplayedCircuit.js
https://github.com/Strilanc/Quirk/blob/master/src/ui/DisplayedCircuit.js
Apache-2.0
_withFallbackExtraWireStartIndex(fallbackExtraWireStartIndex) { return this._withExtraWireStartIndex(this._extraWireStartIndex || fallbackExtraWireStartIndex); }
@param {undefined|!int} fallbackExtraWireStartIndex @returns {!DisplayedCircuit} @private
_withFallbackExtraWireStartIndex
javascript
Strilanc/Quirk
src/ui/DisplayedCircuit.js
https://github.com/Strilanc/Quirk/blob/master/src/ui/DisplayedCircuit.js
Apache-2.0
withJustEnoughWires(hand, extraWireCount) { let neededWireCountForPlacement = hand.heldGate !== undefined ? hand.heldGate.height : 0; let desiredWireCount = this.circuitDefinition.minimumRequiredWireCount(); let clampedWireCount = Math.min( Config.MAX_WIRE_COUNT, Math.max...
@param {!Hand} hand @param {!int} extraWireCount @returns {!DisplayedCircuit}
withJustEnoughWires
javascript
Strilanc/Quirk
src/ui/DisplayedCircuit.js
https://github.com/Strilanc/Quirk/blob/master/src/ui/DisplayedCircuit.js
Apache-2.0
findGateOverlappingPos(pos) { let col = this.indexOfDisplayedColumnAt(pos.x); let row = this.indexOfDisplayedRowAt(pos.y); if (col === undefined || row === undefined) { return undefined; } let target = this.circuitDefinition.findGateCoveringSlot(col, row); if...
@param {!Point} pos @returns {undefined|!{col: !int, row: !int, offset: !Point}}
findGateOverlappingPos
javascript
Strilanc/Quirk
src/ui/DisplayedCircuit.js
https://github.com/Strilanc/Quirk/blob/master/src/ui/DisplayedCircuit.js
Apache-2.0
findGateWithButtonContaining(pos) { let foundPt = this.findGateOverlappingPos(pos); if (foundPt === undefined) { return undefined; } let gate = this.circuitDefinition.gateInSlot(foundPt.col, foundPt.row); if (gate.onClickGateFunc === undefined) { return u...
@param {!Point} pos @returns {undefined|!{col: !int, row: !int, gate: !Gate}}
findGateWithButtonContaining
javascript
Strilanc/Quirk
src/ui/DisplayedCircuit.js
https://github.com/Strilanc/Quirk/blob/master/src/ui/DisplayedCircuit.js
Apache-2.0
_wireInitialStateClickableRect(wire) { let r = this.wireRect(wire); r.x = 0; r.y += 5; r.w = 30; r.h -= 10; return r; }
@param {!int} wire @returns {!Rect} @private
_wireInitialStateClickableRect
javascript
Strilanc/Quirk
src/ui/DisplayedCircuit.js
https://github.com/Strilanc/Quirk/blob/master/src/ui/DisplayedCircuit.js
Apache-2.0
findWireWithInitialStateAreaContaining(pt) { // Is it in the right vertical band; the one at the start of the circuit? if (pt.x < 0 || pt.x > 30) { return undefined; } // Which wire is it? Is it one that's actually in the circuit? let wire = this.wireIndexAt(pt.y); ...
@param {!Point} pt @returns {undefined|!int}
findWireWithInitialStateAreaContaining
javascript
Strilanc/Quirk
src/ui/DisplayedCircuit.js
https://github.com/Strilanc/Quirk/blob/master/src/ui/DisplayedCircuit.js
Apache-2.0
tryClick(hand) { if (hand.pos === undefined || hand.heldGate !== undefined) { return undefined; } let clickedInitialStateWire = this.findWireWithInitialStateAreaContaining(hand.pos); if (clickedInitialStateWire !== undefined) { return this.withCircuit(this.circui...
@param {!Hand} hand @returns {undefined|!DisplayedCircuit}
tryClick
javascript
Strilanc/Quirk
src/ui/DisplayedCircuit.js
https://github.com/Strilanc/Quirk/blob/master/src/ui/DisplayedCircuit.js
Apache-2.0
tryGrab(hand, duplicate=false, wholeColumn=false, ignoreResizeTabs=false, alt=false) { if (wholeColumn) { let grabRowResult = this._tryGrabRow(hand, alt); if (grabRowResult !== undefined) { return grabRowResult; } return this._tryGrabWholeColumn(ha...
@param {!Hand} hand @param {!boolean=false} duplicate @param {!boolean=false} wholeColumn @param {!boolean=false} ignoreResizeTabs @param {!boolean=false} alt Whether or not to replace grabbed gates with their alternates. @returns {!{newCircuit: !DisplayedCircuit, newHand: !Hand}}
tryGrab
javascript
Strilanc/Quirk
src/ui/DisplayedCircuit.js
https://github.com/Strilanc/Quirk/blob/master/src/ui/DisplayedCircuit.js
Apache-2.0
_tryGrabRow(hand, alt) { if (hand.pos === undefined) { return undefined; } // Which wire is it? Is it one that's actually in the circuit? let wire = this.wireIndexAt(hand.pos.y); if (wire < 0 || wire >= this.circuitDefinition.numWires) { return undefined;...
@param {!Hand} hand @param {!boolean} alt @returns {undefined|!{newCircuit: !DisplayedCircuit, newHand: !Hand}}
_tryGrabRow
javascript
Strilanc/Quirk
src/ui/DisplayedCircuit.js
https://github.com/Strilanc/Quirk/blob/master/src/ui/DisplayedCircuit.js
Apache-2.0
_cutRow(row) { let row_gates = []; let cols = []; for (let i = 0; i < this.circuitDefinition.columns.length; i++) { let col_gates = [...this.circuitDefinition.columns[i].gates]; row_gates.push(col_gates[row]); col_gates.splice(row, 1); col_gates.pu...
@param {!int} row @returns {!{newCircuit: !CircuitDefinition, rowGates: !Array.<undefined|!Gate>, initialState: *}} @private
_cutRow
javascript
Strilanc/Quirk
src/ui/DisplayedCircuit.js
https://github.com/Strilanc/Quirk/blob/master/src/ui/DisplayedCircuit.js
Apache-2.0
_tryGrabGate(hand, duplicate, alt) { if (hand.isBusy() || hand.pos === undefined) { return undefined; } let foundPt = this.findGateOverlappingPos(hand.pos); if (foundPt === undefined) { return undefined; } let {col, row, offset} = foundPt; ...
@param {!Hand} hand @param {!boolean} duplicate @param {!boolean} alt @returns {undefined|!{newCircuit: !DisplayedCircuit, newHand: !Hand}}
_tryGrabGate
javascript
Strilanc/Quirk
src/ui/DisplayedCircuit.js
https://github.com/Strilanc/Quirk/blob/master/src/ui/DisplayedCircuit.js
Apache-2.0
_tryGrabResizeTab(hand) { if (hand.isBusy() || hand.pos === undefined) { return undefined; } for (let col = 0; col < this.circuitDefinition.columns.length; col++) { for (let row = 0; row < this.circuitDefinition.numWires; row++) { let gate = this.circuitD...
@param {!Hand} hand @returns {!{newCircuit: !DisplayedCircuit, newHand: !Hand}}
_tryGrabResizeTab
javascript
Strilanc/Quirk
src/ui/DisplayedCircuit.js
https://github.com/Strilanc/Quirk/blob/master/src/ui/DisplayedCircuit.js
Apache-2.0
_tryGrabWholeColumn(hand, duplicate, alt) { if (hand.isBusy() || hand.pos === undefined) { return undefined; } let col = Math.round(this.toColumnSpaceCoordinate(hand.pos.x)); if (col < 0 || col >= this.circuitDefinition.columns.length || this.circuitDefinition.columns[col].i...
@param {!Hand} hand @param {!boolean} duplicate @param {!boolean} alt Whether or not to replace grabbed gates with their alternates. @returns {undefined|!{newCircuit: !DisplayedCircuit, newHand: !Hand}} @private
_tryGrabWholeColumn
javascript
Strilanc/Quirk
src/ui/DisplayedCircuit.js
https://github.com/Strilanc/Quirk/blob/master/src/ui/DisplayedCircuit.js
Apache-2.0
_drawOutputDisplays(painter, stats, hand) { let chanceCol = this.clampedCircuitColCount() + 1; let blochCol = chanceCol + 1; let numWire = this.importantWireCount(); for (let i = 0; i < numWire; i++) { let p = stats.controlledWireProbabilityJustAfter(i, Infinity); ...
Draws a peek gate on each wire at the right-hand side of the circuit. @param {!Painter} painter @param {!CircuitStats} stats @param {!Hand} hand @private
_drawOutputDisplays
javascript
Strilanc/Quirk
src/ui/DisplayedCircuit.js
https://github.com/Strilanc/Quirk/blob/master/src/ui/DisplayedCircuit.js
Apache-2.0
clampedCircuitColCount() { return Math.max( this.circuitDefinition.columns.length, Config.MIN_COL_COUNT + (this._compressedColumnIndex !== undefined ? 1 : 0)); }
@returns {!number} The number of columns used for drawing the circuit, before the output display.
clampedCircuitColCount
javascript
Strilanc/Quirk
src/ui/DisplayedCircuit.js
https://github.com/Strilanc/Quirk/blob/master/src/ui/DisplayedCircuit.js
Apache-2.0
_outputStateAsMatrix(stats) { let numWire = this.importantWireCount(); let buf = stats.finalState.rawBuffer(); if (stats.circuitDefinition.numWires !== numWire) { let r = new Float32Array(2 << numWire); r.set(buf.slice(0, r.length)); buf = r; } ...
@param {!CircuitStats} stats @returns {!Matrix} @private
_outputStateAsMatrix
javascript
Strilanc/Quirk
src/ui/DisplayedCircuit.js
https://github.com/Strilanc/Quirk/blob/master/src/ui/DisplayedCircuit.js
Apache-2.0
_drawHintLabels(painter, stats) { let gridRect = this._rectForSuperpositionDisplay(); // Amplitude hint. painter.print( 'Final amplitudes', gridRect.right() + 3, gridRect.bottom() + 3, 'left', 'top', 'gray', '12...
Draws a peek gate on each wire at the right-hand side of the circuit. @param {!Painter} painter @param {!CircuitStats} stats @private
_drawHintLabels
javascript
Strilanc/Quirk
src/ui/DisplayedCircuit.js
https://github.com/Strilanc/Quirk/blob/master/src/ui/DisplayedCircuit.js
Apache-2.0
static fromTextDiagram(gateMap, diagramText) { let lines = diagramText.split('\n').map(e => { let p = e.split('|'); if (p.length !== 2) { throw new DetailedError('Bad diagram', {diagramText, gateMap}); } return p[1]; }); let circuit...
Parses a text diagram of a circuit, with positions marked by numbers, into a displayed circuit and a list of the positions of the marked points. Note: All lines should start with a pipe (|). Note: Follow a number with a carat (^) to indicate a position above the carat. Note: Separate wires with blank lines. Also start...
fromTextDiagram
javascript
Strilanc/Quirk
src/ui/DisplayedCircuit.js
https://github.com/Strilanc/Quirk/blob/master/src/ui/DisplayedCircuit.js
Apache-2.0
function drawCircuitTooltip(painter, circuitDefinition, rect, showWires, time) { let displayed = new DisplayedCircuit( 0, circuitDefinition, undefined, undefined, undefined); let neededWidth = displayed.desiredWidth(true); let neededHeight = displayed.desiredHeight(tr...
@param {!Painter} painter @param {!CircuitDefinition} circuitDefinition @param {!Rect} rect @param {!boolean} showWires @param {!number} time @returns {!{maxW: !number, maxH: !number}}
drawCircuitTooltip
javascript
Strilanc/Quirk
src/ui/DisplayedCircuit.js
https://github.com/Strilanc/Quirk/blob/master/src/ui/DisplayedCircuit.js
Apache-2.0
function _drawLabelsReasonablyFast(painter, dy, n, labeller, boundingWidth) { let ctx = painter.ctx; ctx.save(); ctx.textAlign = 'left'; ctx.textBaseline = 'middle'; painter.ctx.font = '12px monospace'; let w = Math.max( painter.ctx.measureText(labeller(0)).width, painter.ctx.mea...
@param {!Painter} painter @param {!number} dy @param {!int} n @param {!function(!int) : !String} labeller @param {!number} boundingWidth @private
_drawLabelsReasonablyFast
javascript
Strilanc/Quirk
src/ui/DisplayedCircuit.js
https://github.com/Strilanc/Quirk/blob/master/src/ui/DisplayedCircuit.js
Apache-2.0
constructor(drawArea, circuitWidget, displayedToolboxTop, displayedToolboxBottom, hand) { /** @type {!DisplayedCircuit} */ this.displayedCircuit = circuitWidget; /** @type {!DisplayedToolbox} */ this.displayedToolboxTop = displayedToolboxTop; /** @type {!DisplayedToolbox} */ ...
@param {!Rect} drawArea @param {!DisplayedCircuit} circuitWidget @param {!DisplayedToolbox} displayedToolboxTop @param {!DisplayedToolbox} displayedToolboxBottom @param {!Hand} hand
constructor
javascript
Strilanc/Quirk
src/ui/DisplayedInspector.js
https://github.com/Strilanc/Quirk/blob/master/src/ui/DisplayedInspector.js
Apache-2.0
paint(painter, stats) { painter.fillRect(this.drawArea, Config.BACKGROUND_COLOR); this.displayedToolboxTop.paint(painter, stats, this.hand); this.displayedToolboxBottom.paint(painter, stats, this.hand); this.displayedCircuit.paint(painter, this.hand, stats); this._paintHand(pain...
@param {!Painter} painter @param {!CircuitStats} stats
paint
javascript
Strilanc/Quirk
src/ui/DisplayedInspector.js
https://github.com/Strilanc/Quirk/blob/master/src/ui/DisplayedInspector.js
Apache-2.0
_paintHand(painter, stats) { if (this.hand.pos === undefined || this.hand.heldGate === undefined) { return; } let gate = this.hand.heldGate; let pos = this.hand.pos.minus(this.hand.holdOffset); let rect = new Rect( Math.round(pos.x - 0.5) + 0.5, ...
@param {!Painter} painter @param {!CircuitStats} stats @private
_paintHand
javascript
Strilanc/Quirk
src/ui/DisplayedInspector.js
https://github.com/Strilanc/Quirk/blob/master/src/ui/DisplayedInspector.js
Apache-2.0
afterGrabbing(duplicate=false, wholeCol=false, ignoreResizeTabs=false, alt=false) { let hand = this.hand; let circuit = this.displayedCircuit; hand = this.displayedToolboxTop.tryGrab(hand); hand = this.displayedToolboxBottom.tryGrab(hand); let obj = circuit.tryGrab(hand, duplica...
@param {!boolean=false} duplicate @param {!boolean=false} wholeCol @param {!boolean=false} ignoreResizeTabs @param {!boolean=false} alt @returns {!DisplayedInspector}
afterGrabbing
javascript
Strilanc/Quirk
src/ui/DisplayedInspector.js
https://github.com/Strilanc/Quirk/blob/master/src/ui/DisplayedInspector.js
Apache-2.0
withJustEnoughWires(hand, extraWires) { return this.withDisplayedCircuit(this.displayedCircuit.withJustEnoughWires(hand, extraWires)); }
@param {!Hand} hand @param {!int} extraWires @returns {!DisplayedInspector}
withJustEnoughWires
javascript
Strilanc/Quirk
src/ui/DisplayedInspector.js
https://github.com/Strilanc/Quirk/blob/master/src/ui/DisplayedInspector.js
Apache-2.0
constructor( name, top, toolboxGroups, labelsOnTop, originalGroups=undefined, standardAppearance=undefined) { /** @type {!String} */ this.name = name; /** @type {!number} */ this.top = top; /** @type {!Array<...
That thing showing gates you can grab. @param {!string} name @param {!number} top @param {!Array<!{hint: !string, gates: !Array<undefined|!Gate>}>} toolboxGroups @param {!boolean} labelsOnTop @param {undefined|!Array<!{hint: !string, gates: !Array<undefined|!Gate>}>=} originalGroups @param {undefined|!CachablePainting=...
constructor
javascript
Strilanc/Quirk
src/ui/DisplayedToolbox.js
https://github.com/Strilanc/Quirk/blob/master/src/ui/DisplayedToolbox.js
Apache-2.0
gateDrawRect(groupIndex, gateIndex) { let dx = gateIndex % 2; let dy = Math.floor(gateIndex / 2); let x = Config.TOOLBOX_MARGIN_X + dx * Config.TOOLBOX_GATE_SPAN + groupIndex * Config.TOOLBOX_GROUP_SPAN; let y = this.top + (this.labelsOnTop ? Config.T...
@param {!int} groupIndex @param {!int} gateIndex @returns {!Rect} @private
gateDrawRect
javascript
Strilanc/Quirk
src/ui/DisplayedToolbox.js
https://github.com/Strilanc/Quirk/blob/master/src/ui/DisplayedToolbox.js
Apache-2.0
groupLabelRect(groupIndex) { if (this.labelsOnTop) { let r = this.gateDrawRect(groupIndex, 0); let c = new Point(r.x + Config.TOOLBOX_GATE_SPAN - Config.TOOLBOX_GATE_SPACING / 2, r.y - 18); return new Rect(c.x - Config.TOOLBOX_GATE_SPAN, c.y, Config.TOOLBOX_GATE_SPAN * 2, 20)...
@param {!int} groupIndex @returns {!Rect} @private
groupLabelRect
javascript
Strilanc/Quirk
src/ui/DisplayedToolbox.js
https://github.com/Strilanc/Quirk/blob/master/src/ui/DisplayedToolbox.js
Apache-2.0
findGateAt(pt) { if (pt === undefined) { return undefined; } for (let groupIndex = 0; groupIndex < this.toolboxGroups.length; groupIndex++) { let group = this.toolboxGroups[groupIndex]; for (let gateIndex = 0; gateIndex < group.gates.length; gateIndex++) { ...
@param {undefined|!Point} pt @returns {undefined|!{groupIndex: !int, gateIndex: !int, gate: !Gate, rect: !Rect}}
findGateAt
javascript
Strilanc/Quirk
src/ui/DisplayedToolbox.js
https://github.com/Strilanc/Quirk/blob/master/src/ui/DisplayedToolbox.js
Apache-2.0
paint(painter, stats, hand) { painter.fillRect(this.curArea(painter.canvas.width), Config.BACKGROUND_COLOR_TOOLBOX); this._standardApperance.paint(0, this.top, painter); this._paintDeviations(painter, stats, hand); }
@param {!Painter} painter @param {!CircuitStats} stats @param {!Hand} hand
paint
javascript
Strilanc/Quirk
src/ui/DisplayedToolbox.js
https://github.com/Strilanc/Quirk/blob/master/src/ui/DisplayedToolbox.js
Apache-2.0
_paintDeviations(painter, stats, hand) { for (let groupIndex = 0; groupIndex < this.toolboxGroups.length; groupIndex++) { // Custom gates. if (groupIndex >= this._originalGroups.length) { this._paintGatesInGroup(painter, hand, groupIndex); } // Ke...
@param {!Painter} painter @param {!CircuitStats} stats @param {!Hand} hand
_paintDeviations
javascript
Strilanc/Quirk
src/ui/DisplayedToolbox.js
https://github.com/Strilanc/Quirk/blob/master/src/ui/DisplayedToolbox.js
Apache-2.0
_paintGatesInGroup(painter, hand, groupIndex) { let group = this.toolboxGroups[groupIndex]; let r = this.groupLabelRect(groupIndex); painter.print( group.hint, r.x + r.w/2, r.y + r.h/2, 'center', 'middle', 'black', ...
@param {!Painter} painter @param {!Hand} hand @param {!int} groupIndex @private
_paintGatesInGroup
javascript
Strilanc/Quirk
src/ui/DisplayedToolbox.js
https://github.com/Strilanc/Quirk/blob/master/src/ui/DisplayedToolbox.js
Apache-2.0
static _paintGate(painter, hand, gate, rect, isHighlighted, stats) { let drawer = gate.customDrawer || GatePainting.DEFAULT_DRAWER; painter.startIgnoringIncomingTouchBlockers(); drawer(new GateDrawParams( painter, hand, true, // inToolbox isHighlig...
@param {!Painter} painter @param {!Hand} hand @param {!Gate} gate @param {!Rect} rect @param {!boolean} isHighlighted @param {!CircuitStats} stats @private
_paintGate
javascript
Strilanc/Quirk
src/ui/DisplayedToolbox.js
https://github.com/Strilanc/Quirk/blob/master/src/ui/DisplayedToolbox.js
Apache-2.0
_paintFocus(painter, stats, hand) { // Focus when hovering, but also when dragging a gate over its own toolbox spot. let f = this.findGateAt(hand.pos); if (f === undefined || (hand.heldGate !== undefined && f.gate.symbol !== hand.heldGate.symbol)) { return; } // Draw...
@param {!Painter} painter @param {!CircuitStats} stats @param {!Hand} hand @private
_paintFocus
javascript
Strilanc/Quirk
src/ui/DisplayedToolbox.js
https://github.com/Strilanc/Quirk/blob/master/src/ui/DisplayedToolbox.js
Apache-2.0
tryGrab(hand) { if (hand.pos === undefined || hand.isBusy()) { return hand; } let f = this.findGateAt(hand.pos); if (f === undefined) { return hand; } if (f.gate.symbol === MysteryGateSymbol) { setTimeout(() => { this.toolboxGroups[f....
@param {!Hand} hand @returns {!Hand} newHand
tryGrab
javascript
Strilanc/Quirk
src/ui/DisplayedToolbox.js
https://github.com/Strilanc/Quirk/blob/master/src/ui/DisplayedToolbox.js
Apache-2.0
stableDuration(hand) { return seq(hand.hoverPoints()). map(p => this.findGateAt(p)). filter(e => e !== undefined). map(e => e.gate.stableDuration()). min(Infinity); }
@param {!Hand} hand @returns {Infinity|!number}
stableDuration
javascript
Strilanc/Quirk
src/ui/DisplayedToolbox.js
https://github.com/Strilanc/Quirk/blob/master/src/ui/DisplayedToolbox.js
Apache-2.0
function initExports(revision, mostRecentStats, obsIsAnyOverlayShowing) { // Show/hide exports overlay. (() => { const exportButton = /** @type {!HTMLButtonElement} */ document.getElementById('export-button'); const exportOverlay = /** @type {!HTMLDivElement} */ document.getElementById('export-o...
@param {!Revision} revision @param {!ObservableValue.<!CircuitStats>} mostRecentStats @param {!Observable.<!boolean>} obsIsAnyOverlayShowing
initExports
javascript
Strilanc/Quirk
src/ui/exports.js
https://github.com/Strilanc/Quirk/blob/master/src/ui/exports.js
Apache-2.0
setupButtonElementCopyToClipboard = (button, contentElement, resultElement, contentMaker=undefined) => button.addEventListener('click', () => { if (contentMaker !== undefined) { contentElement.innerText = contentMaker(); } //noinspection UnusedCatchParameterJ...
@param {!HTMLButtonElement} button @param {!HTMLElement} contentElement @param {!HTMLElement} resultElement @param {undefined|!function(): !string} contentMaker
setupButtonElementCopyToClipboard
javascript
Strilanc/Quirk
src/ui/exports.js
https://github.com/Strilanc/Quirk/blob/master/src/ui/exports.js
Apache-2.0
setupButtonElementCopyToClipboard = (button, contentElement, resultElement, contentMaker=undefined) => button.addEventListener('click', () => { if (contentMaker !== undefined) { contentElement.innerText = contentMaker(); } //noinspection UnusedCatchParameterJ...
@param {!HTMLButtonElement} button @param {!HTMLElement} contentElement @param {!HTMLElement} resultElement @param {undefined|!function(): !string} contentMaker
setupButtonElementCopyToClipboard
javascript
Strilanc/Quirk
src/ui/exports.js
https://github.com/Strilanc/Quirk/blob/master/src/ui/exports.js
Apache-2.0
function initForge(revision, obsIsAnyOverlayShowing) { const obsOnShown = obsForgeIsShowing.filter(e => e === true); /** @type {!String} */ let latestInspectorText; revision.latestActiveCommit().subscribe(e => { latestInspectorText = e; }); // Show/hide forge overlay. (() => { const for...
@param {!Revision} revision @param {!Observable.<!boolean>} obsIsAnyOverlayShowing
initForge
javascript
Strilanc/Quirk
src/ui/forge.js
https://github.com/Strilanc/Quirk/blob/master/src/ui/forge.js
Apache-2.0
function createCustomGateAndClose(gate, circuitDef=undefined) { let c = circuitDef || fromJsonText_CircuitDefinition(latestInspectorText); revision.commit(JSON.stringify(Serializer.toJson(c.withCustomGate(gate)), null, 0)); forgeIsVisible.set(false); }
@param {!Gate} gate @param {undefined|!CircuitDefinition=undefined} circuitDef
createCustomGateAndClose
javascript
Strilanc/Quirk
src/ui/forge.js
https://github.com/Strilanc/Quirk/blob/master/src/ui/forge.js
Apache-2.0
function parseUserRotation(angleText, phaseText, axisText) { let w = parseUserAngle(angleText); let phase = parseUserAngle(phaseText); let {x, y, z} = Axis.parse(axisText); let len = Math.sqrt(x*x + y*y + z*z); x /= len; y /= len; z /= len; let [I, X, Y, Z] = [Matrix.identity(2), Matri...
@param {!string} angleText @param {!string} phaseText @param {!string} axisText @returns {!Matrix}
parseUserRotation
javascript
Strilanc/Quirk
src/ui/forge.js
https://github.com/Strilanc/Quirk/blob/master/src/ui/forge.js
Apache-2.0
function parseUserMatrix(text, ensureUnitary) { let op = parseUserGateMatrix_noCorrection(text); if (op.width() !== op.height() || op.width() < 2 || op.width() > 16 || !Util.isPowerOf2(op.width())) { throw Error("Matrix must be 2x2, 4x4, 8x8, or 16x16.") } if (ensureUnitary && !op.hasNaN()) { ...
@param {!string} text @param {!boolean} ensureUnitary @returns {!Matrix}
parseUserMatrix
javascript
Strilanc/Quirk
src/ui/forge.js
https://github.com/Strilanc/Quirk/blob/master/src/ui/forge.js
Apache-2.0
function parseUserGateFromCircuitRange(circuit, colRangeText, wireRangeText, nameText) { let colRange = parseRange(colRangeText, circuit.columns.length); let rowRange = parseRange(wireRangeText, circuit.numWires); if (rowRange.end === rowRange.start) { throw new Error("Empty wire range.") } ...
@param {!CircuitDefinition} circuit @param {!string} colRangeText @param {!string} wireRangeText @param {!string} nameText @returns {!Gate}
parseUserGateFromCircuitRange
javascript
Strilanc/Quirk
src/ui/forge.js
https://github.com/Strilanc/Quirk/blob/master/src/ui/forge.js
Apache-2.0
constructor(pos, heldGate, holdOffset, heldColumn, heldRow, resizingGateSlot) { let args = {pos, heldGate, holdOffset, heldColumn, heldRow, resizingGateSlot}; if (pos !== undefined && !(pos instanceof Point)) { throw new DetailedError("Bad pos", args); } if (heldGate !== unde...
@param {undefined|!Point} pos @param {undefined|!Gate} heldGate @param {undefined|!Point} holdOffset @param {undefined|!GateColumn} heldColumn @param {undefined|!{initialState: *, gates: !Array.<undefined|!Gate>}} heldRow @param {undefined|!Point} resizingGateSlot
constructor
javascript
Strilanc/Quirk
src/ui/Hand.js
https://github.com/Strilanc/Quirk/blob/master/src/ui/Hand.js
Apache-2.0
withPos(newPos) { return new Hand(newPos, this.heldGate, this.holdOffset, this.heldColumn, this.heldRow, this.resizingGateSlot); }
@param {undefined|!Point} newPos @returns {!Hand}
withPos
javascript
Strilanc/Quirk
src/ui/Hand.js
https://github.com/Strilanc/Quirk/blob/master/src/ui/Hand.js
Apache-2.0
withHeldGate(heldGate, heldGateOffset) { return new Hand(this.pos, heldGate, heldGateOffset, undefined, undefined, undefined); }
@param {!Gate} heldGate @param {!Point} heldGateOffset @returns {!Hand}
withHeldGate
javascript
Strilanc/Quirk
src/ui/Hand.js
https://github.com/Strilanc/Quirk/blob/master/src/ui/Hand.js
Apache-2.0
withHeldGateColumn(heldGateColumn, heldGateOffset) { return new Hand(this.pos, undefined, heldGateOffset, heldGateColumn, undefined, undefined); }
@param {!GateColumn} heldGateColumn @param {!Point} heldGateOffset @returns {!Hand}
withHeldGateColumn
javascript
Strilanc/Quirk
src/ui/Hand.js
https://github.com/Strilanc/Quirk/blob/master/src/ui/Hand.js
Apache-2.0
withHeldRow(heldRow, heldGateOffset) { return new Hand(this.pos, undefined, heldGateOffset, undefined, heldRow, undefined); }
@param {!{initialState: *, gates: !Array.<undefined|!Gate>}} heldRow @param {!Point} heldGateOffset @returns {!Hand}
withHeldRow
javascript
Strilanc/Quirk
src/ui/Hand.js
https://github.com/Strilanc/Quirk/blob/master/src/ui/Hand.js
Apache-2.0
withResizeSlot(resizeSlot, resizeTabOffset) { return new Hand(this.pos, undefined, resizeTabOffset, undefined, undefined, resizeSlot); }
@param {!Point} resizeSlot @param {!Point} resizeTabOffset @returns {!Hand}
withResizeSlot
javascript
Strilanc/Quirk
src/ui/Hand.js
https://github.com/Strilanc/Quirk/blob/master/src/ui/Hand.js
Apache-2.0
function initUndoRedo(revision, obsIsAnyOverlayShowing) { const overlay_divs = [ document.getElementById('gate-forge-div'), document.getElementById('export-div') ]; const undoButton = /** @type {!HTMLButtonElement} */ document.getElementById('undo-button'); const redoButton = /** @type ...
@param {!Revision} revision @param {!Observable.<boolean>} obsIsAnyOverlayShowing
initUndoRedo
javascript
Strilanc/Quirk
src/ui/undo.js
https://github.com/Strilanc/Quirk/blob/master/src/ui/undo.js
Apache-2.0
constructor(partMaker, description) { /** * @type {!(function(!ShaderCoder): !ShaderPart)} * @private */ this._partMaker = partMaker; /** * @type {!string} */ this.description = description; }
@param {!function(!ShaderCoder) : !ShaderPart} partMaker @param {!string} description
constructor
javascript
Strilanc/Quirk
src/webgl/ShaderCoders.js
https://github.com/Strilanc/Quirk/blob/master/src/webgl/ShaderCoders.js
Apache-2.0
function combinedShaderPartsWithCode(shaderPartsOrDescs, bodyCode) { let shaderPartDescs = shaderPartsOrDescs.map(partOrDesc => partOrDesc instanceof ShaderPart ? new ShaderPartDescription(_ => partOrDesc, 'fixed') : partOrDesc); let sourceMaker = () => { let libs = new Set(); fo...
@param {!Array.<!ShaderPartDescription|!ShaderPart>} shaderPartsOrDescs @param {!string} bodyCode @returns {!WglShader}
combinedShaderPartsWithCode
javascript
Strilanc/Quirk
src/webgl/ShaderCoders.js
https://github.com/Strilanc/Quirk/blob/master/src/webgl/ShaderCoders.js
Apache-2.0
sourceMaker = () => { let libs = new Set(); for (let part of shaderPartDescs) { for (let lib of part.toConcretePart().libs) { libs.add(lib); } } let libCode = [...libs, ...shaderPartDescs.map(e => e.toConcretePart().code)].join(''); let aft...
@param {!Array.<!ShaderPartDescription|!ShaderPart>} shaderPartsOrDescs @param {!string} bodyCode @returns {!WglShader}
sourceMaker
javascript
Strilanc/Quirk
src/webgl/ShaderCoders.js
https://github.com/Strilanc/Quirk/blob/master/src/webgl/ShaderCoders.js
Apache-2.0
sourceMaker = () => { let libs = new Set(); for (let part of shaderPartDescs) { for (let lib of part.toConcretePart().libs) { libs.add(lib); } } let libCode = [...libs, ...shaderPartDescs.map(e => e.toConcretePart().code)].join(''); let aft...
@param {!Array.<!ShaderPartDescription|!ShaderPart>} shaderPartsOrDescs @param {!string} bodyCode @returns {!WglShader}
sourceMaker
javascript
Strilanc/Quirk
src/webgl/ShaderCoders.js
https://github.com/Strilanc/Quirk/blob/master/src/webgl/ShaderCoders.js
Apache-2.0
function makePseudoShaderWithInputsAndOutputAndCode(inputs, output, bodyCode) { let shader = combinedShaderPartsWithCode([...inputs, output], bodyCode); return (...inputsAndArgs) => { let args = []; for (let i = 0; i < inputs.length; i++) { args.push(...inputs[i].toConcretePart().arg...
@param {!Array.<ShaderPartDescription>} inputs @param {!ShaderPartDescription} output @param {!string} bodyCode @returns {!function(args: ...(!!WglTexture|!WglArg)) : !WglConfiguredShader}
makePseudoShaderWithInputsAndOutputAndCode
javascript
Strilanc/Quirk
src/webgl/ShaderCoders.js
https://github.com/Strilanc/Quirk/blob/master/src/webgl/ShaderCoders.js
Apache-2.0
function shaderWithOutputPartAndArgs(shader, outputShaderPart, args) { return new WglConfiguredShader(destinationTexture => shader.withArgs(...args, ...outputShaderPart.argsFor(destinationTexture)).renderTo(destinationTexture)); }
@param {!ShaderPart} outputShaderPart @param {!WglShader} shader @param {!Array.<!WglArg>} args @returns {!WglConfiguredShader} @private
shaderWithOutputPartAndArgs
javascript
Strilanc/Quirk
src/webgl/ShaderCoders.js
https://github.com/Strilanc/Quirk/blob/master/src/webgl/ShaderCoders.js
Apache-2.0
constructor(code, libs, argsFor) { /** @type {!string} */ this.code = code; /** @type {!Array.<!string>} */ this.libs = libs; /** @type {!function(!WglTexture) : !Array.!<WglArg>} */ this.argsFor = argsFor; }
@param {!string} code @param {!Array.<!string>} libs @param {!function(!WglTexture) : !Array.!<WglArg>} argsFor
constructor
javascript
Strilanc/Quirk
src/webgl/ShaderCoders_Base.js
https://github.com/Strilanc/Quirk/blob/master/src/webgl/ShaderCoders_Base.js
Apache-2.0
constructor(inputPartGetter, outputPart, powerSizeOverhead, pixelType, dataToPixels, pixelsToData, needRearrangingToBeInVec4Format) { /** @type {!function(name: !string) : !ShaderPart} */ this.inputPartGetter...
@param {!function(name: !string) : !ShaderPart} inputPartGetter Determines how values are decoded from the various given input textures while rendering. @param {!ShaderPart} outputPart Determines how computed values are encoded into the next texture while rendering. @param {!int} powerSizeOverhead This value is the...
constructor
javascript
Strilanc/Quirk
src/webgl/ShaderCoders_Base.js
https://github.com/Strilanc/Quirk/blob/master/src/webgl/ShaderCoders_Base.js
Apache-2.0
constructor(bool, float, vec2, vec4) { /** @type {!SingleTypeCoder} */ this.bool = bool; /** @type {!SingleTypeCoder} */ this.float = float; /** @type {!SingleTypeCoder} */ this.vec2 = vec2; /** @type {!SingleTypeCoder} */ this.vec4 = vec4; }
@param {!SingleTypeCoder} bool @param {!SingleTypeCoder} float @param {!SingleTypeCoder} vec2 @param {!SingleTypeCoder} vec4
constructor
javascript
Strilanc/Quirk
src/webgl/ShaderCoders_Base.js
https://github.com/Strilanc/Quirk/blob/master/src/webgl/ShaderCoders_Base.js
Apache-2.0
function floatsAsBytes(floats) { if (floats instanceof Float64Array) { return new Uint8Array(new Float32Array(floats).buffer, 0, floats.length << 2); } if (floats instanceof Float32Array) { return new Uint8Array(floats.buffer, 0, floats.length << 2); } throw new DetailedError("Not a ...
Exposes an array of single-precision floats as an array of bytes. @param {!Float64Array|!Float32Array} floats @returns {!Uint8Array}
floatsAsBytes
javascript
Strilanc/Quirk
src/webgl/ShaderCoders_intoBytes.js
https://github.com/Strilanc/Quirk/blob/master/src/webgl/ShaderCoders_intoBytes.js
Apache-2.0
function bytesAsFloats(bytes) { if (!(bytes instanceof Uint8Array)) { throw new DetailedError("Not a Uint8Array", {type: typeof bytes, bytes}); } return new Float32Array(bytes.buffer, 0, bytes.length >> 2); }
Exposes an array of bytes as an array of single-precision floats. @param {!Uint8Array} bytes @returns {!Float32Array}
bytesAsFloats
javascript
Strilanc/Quirk
src/webgl/ShaderCoders_intoBytes.js
https://github.com/Strilanc/Quirk/blob/master/src/webgl/ShaderCoders_intoBytes.js
Apache-2.0
function makeByteCoderInput(vecSize, name) { let type = ['float', 'vec2', 'vec3', 'vec4'][vecSize - 1]; let pre = `_gen_${name}`; return new ShaderPart(` ///////////// makeByteCoderInput(${vecSize}, ${name}) //////////// uniform sampler2D ${pre}_tex; uniform vec2 ${pre}_size; ...
@param {!int} vecSize @param {!string} name @returns {!ShaderPart}
makeByteCoderInput
javascript
Strilanc/Quirk
src/webgl/ShaderCoders_intoBytes.js
https://github.com/Strilanc/Quirk/blob/master/src/webgl/ShaderCoders_intoBytes.js
Apache-2.0
function makeFloatCoderInput(vecSize, name) { let type = ['float', 'vec2', 'vec3', 'vec4'][vecSize - 1]; let pre = `_gen_${name}`; return new ShaderPart(` ///////////// makeFloatCoderInput(${vecSize}, ${name}) //////////// uniform sampler2D ${pre}_tex; uniform vec2 ${pre}_size; ...
@param {!int} vecSize @param {!string} name @returns {!ShaderPart}
makeFloatCoderInput
javascript
Strilanc/Quirk
src/webgl/ShaderCoders_intoFloats.js
https://github.com/Strilanc/Quirk/blob/master/src/webgl/ShaderCoders_intoFloats.js
Apache-2.0
constructor(type, name, value) { /** @type {!Symbol} */ this.type = type; /** @type {!string} */ this.name = name; /** @type {*} */ this.value = value; }
@param {!string} type @param {!string} name @param {*} value
constructor
javascript
Strilanc/Quirk
src/webgl/WglArg.js
https://github.com/Strilanc/Quirk/blob/master/src/webgl/WglArg.js
Apache-2.0
static bool(name, value) { return new WglArg(WglArg.BOOL_TYPE, name, value); }
@param {!string} name @param {!boolean} value @returns {!WglArg}
bool
javascript
Strilanc/Quirk
src/webgl/WglArg.js
https://github.com/Strilanc/Quirk/blob/master/src/webgl/WglArg.js
Apache-2.0
static float(name, value) { return new WglArg(WglArg.FLOAT_TYPE, name, value); }
@param {!string} name @param {!number} value @returns {!WglArg}
float
javascript
Strilanc/Quirk
src/webgl/WglArg.js
https://github.com/Strilanc/Quirk/blob/master/src/webgl/WglArg.js
Apache-2.0
static int(name, value) { return new WglArg(WglArg.INT_TYPE, name, value); }
@param {!string} name @param {!int} value @returns {!WglArg}
int
javascript
Strilanc/Quirk
src/webgl/WglArg.js
https://github.com/Strilanc/Quirk/blob/master/src/webgl/WglArg.js
Apache-2.0
static vec2(name, x, y) { return new WglArg(WglArg.VEC2_TYPE, name, [x, y]); }
@param {!string} name @param {!number} x @param {!number} y @returns {!WglArg}
vec2
javascript
Strilanc/Quirk
src/webgl/WglArg.js
https://github.com/Strilanc/Quirk/blob/master/src/webgl/WglArg.js
Apache-2.0
static float_array(name, buf) { if (buf instanceof Float64Array) { buf = new Float32Array(buf); } return new WglArg(WglArg.FLOAT_ARRAY_TYPE, name, buf); }
@param {!string} name @param {!Float32Array|!Float64Array} buf @returns {!WglArg}
float_array
javascript
Strilanc/Quirk
src/webgl/WglArg.js
https://github.com/Strilanc/Quirk/blob/master/src/webgl/WglArg.js
Apache-2.0
static vec2_array(name, buf) { if (buf instanceof Float64Array) { buf = new Float32Array(buf); } return new WglArg(WglArg.VEC2_ARRAY_TYPE, name, buf); }
@param {!string} name @param {!Float32Array|!Float64Array} buf @returns {!WglArg}
vec2_array
javascript
Strilanc/Quirk
src/webgl/WglArg.js
https://github.com/Strilanc/Quirk/blob/master/src/webgl/WglArg.js
Apache-2.0
static vec4_array(name, buf) { if (buf instanceof Float64Array) { buf = new Float32Array(buf); } return new WglArg(WglArg.VEC4_ARRAY_TYPE, name, buf); }
@param {!string} name @param {!Float32Array|!Float64Array} buf @returns {!WglArg}
vec4_array
javascript
Strilanc/Quirk
src/webgl/WglArg.js
https://github.com/Strilanc/Quirk/blob/master/src/webgl/WglArg.js
Apache-2.0
static mat4_array(name, buf) { if (buf instanceof Float64Array) { buf = new Float32Array(buf); } return new WglArg(WglArg.MAT4_ARRAY_TYPE, name, buf); }
@param {!string} name @param {!Float32Array|!Float64Array} buf @returns {!WglArg}
mat4_array
javascript
Strilanc/Quirk
src/webgl/WglArg.js
https://github.com/Strilanc/Quirk/blob/master/src/webgl/WglArg.js
Apache-2.0
static vec4(name, x, y, z, t) { return new WglArg(WglArg.VEC4_TYPE, name, [x, y, z, t]); }
@param {!string} name @param {!number} x @param {!number} y @param {!number} z @param {!number} t @returns {!WglArg}
vec4
javascript
Strilanc/Quirk
src/webgl/WglArg.js
https://github.com/Strilanc/Quirk/blob/master/src/webgl/WglArg.js
Apache-2.0
static mat4(name, cellsRowByRow) { return new WglArg(WglArg.MAT4_TYPE, name, cellsRowByRow); }
@param {!string} name @param {!Float32Array|!Array.<!number>} cellsRowByRow @returns {!WglArg}
mat4
javascript
Strilanc/Quirk
src/webgl/WglArg.js
https://github.com/Strilanc/Quirk/blob/master/src/webgl/WglArg.js
Apache-2.0
static texture(name, wglTexture) { return new WglArg(WglArg.WGL_TEXTURE_TYPE, name, wglTexture); }
@param {!string} name @param {!WglTexture} wglTexture @returns {!WglArg}
texture
javascript
Strilanc/Quirk
src/webgl/WglArg.js
https://github.com/Strilanc/Quirk/blob/master/src/webgl/WglArg.js
Apache-2.0
static webGlTexture(name, webGlTexture) { return new WglArg(WglArg.WEB_GL_TEXTURE_TYPE, name, webGlTexture); }
@param {!string} name @param {!WebGLTexture} webGlTexture @returns {!WglArg}
webGlTexture
javascript
Strilanc/Quirk
src/webgl/WglArg.js
https://github.com/Strilanc/Quirk/blob/master/src/webgl/WglArg.js
Apache-2.0
toString() { return `${this.type} ${this.name} = ${JSON.stringify(this.value)}`; }
@param {!string} name @param {!WebGLTexture} webGlTexture @returns {!WglArg}
toString
javascript
Strilanc/Quirk
src/webgl/WglArg.js
https://github.com/Strilanc/Quirk/blob/master/src/webgl/WglArg.js
Apache-2.0
renderTo(texture) { let shouldBeUndefined = this.renderToFunc(texture); if (shouldBeUndefined instanceof WglConfiguredShader) { throw new Error("Returned a WglConfiguredShader instead of calling renderTo on it."); } }
Runs the configured renderer, placing its outputs into the given texture. @param {!WglTexture} texture
renderTo
javascript
Strilanc/Quirk
src/webgl/WglConfiguredShader.js
https://github.com/Strilanc/Quirk/blob/master/src/webgl/WglConfiguredShader.js
Apache-2.0
toRawByteTexture(sizePower) { let texture = WglTexturePool.takeRawByteTex(sizePower); this._renderToElseDealloc(texture); return texture; }
Renders into a new byte texture of the given size, and returns the texture. @param {!int} sizePower @returns {!WglTexture}
toRawByteTexture
javascript
Strilanc/Quirk
src/webgl/WglConfiguredShader.js
https://github.com/Strilanc/Quirk/blob/master/src/webgl/WglConfiguredShader.js
Apache-2.0
toRawFloatTexture(sizePower) { let texture = WglTexturePool.takeRawFloatTex(sizePower); this._renderToElseDealloc(texture); return texture; }
Renders into a new float texture of the given size, and returns the texture. @param {!int} sizePower @returns {!WglTexture}
toRawFloatTexture
javascript
Strilanc/Quirk
src/webgl/WglConfiguredShader.js
https://github.com/Strilanc/Quirk/blob/master/src/webgl/WglConfiguredShader.js
Apache-2.0
readRawFloatOutputs(sizePower) { return this._renderReadDealloc(WglTexturePool.takeRawFloatTex(sizePower)); }
Renders the result into a float texture, reads the pixels, and returns the result. This method is slow (because it uses readPixels) and mainly exists for easy testing. @param {!int} sizePower @returns {!Float32Array}
readRawFloatOutputs
javascript
Strilanc/Quirk
src/webgl/WglConfiguredShader.js
https://github.com/Strilanc/Quirk/blob/master/src/webgl/WglConfiguredShader.js
Apache-2.0
readRawByteOutputs(sizePower) { return this._renderReadDealloc(WglTexturePool.takeRawByteTex(sizePower)); }
Renders the result into a float texture, reads the pixels, and returns the result. This method is slow (because it uses readPixels) and mainly exists for easy testing. @param {!int} sizePower @returns {!Uint8Array}
readRawByteOutputs
javascript
Strilanc/Quirk
src/webgl/WglConfiguredShader.js
https://github.com/Strilanc/Quirk/blob/master/src/webgl/WglConfiguredShader.js
Apache-2.0
readBoolOutputs(sizePower) { let pixels = this._renderReadDealloc(WglTexturePool.takeBoolTex(sizePower)); let result = new Uint8Array(pixels.length >> 2); for (let i = 0; i < result.length; i++) { result[i] = pixels[i << 2] & 1; } return result; }
@param {!int} sizePower @returns {!Uint8Array} Each entry represents one of the booleans: 1 for true, 0 for false.
readBoolOutputs
javascript
Strilanc/Quirk
src/webgl/WglConfiguredShader.js
https://github.com/Strilanc/Quirk/blob/master/src/webgl/WglConfiguredShader.js
Apache-2.0
constructor(canvas=undefined, context=undefined) { if (canvas === undefined) { canvas = /** @type {!HTMLCanvasElement} */ document.createElement('canvas'); context = undefined; } if (context === undefined) { context = canvas.getContext('webgl') || canvas.getCo...
Creates and wraps a WebGLRenderingContext. @param {!HTMLCanvasElement} canvas @param {!WebGLRenderingContext} context
constructor
javascript
Strilanc/Quirk
src/webgl/WglContext.js
https://github.com/Strilanc/Quirk/blob/master/src/webgl/WglContext.js
Apache-2.0
constructor(initializer, deinitializer) { /** * @type {!(function(): T)} * @template T */ this.initializer = initializer; /** * @type {!(function(T): void)} * @template T */ this.deinitializer = deinitializer; /** * @...
@param {!function() : T} initializer @param {!function(T) : void} deinitializer @template T
constructor
javascript
Strilanc/Quirk
src/webgl/WglMortalValueSlot.js
https://github.com/Strilanc/Quirk/blob/master/src/webgl/WglMortalValueSlot.js
Apache-2.0
initializedValue(lifetimeCounter) { if (this.lifetimeId !== lifetimeCounter) { this.ensureDeinitialized(); this.mortalValue = this.initializer(); this.lifetimeId = lifetimeCounter; } return this.mortalValue; }
Returns the mortal value stored in the slot, initializing or re-initializing it if necessary. @param {!int} lifetimeCounter @returns T
initializedValue
javascript
Strilanc/Quirk
src/webgl/WglMortalValueSlot.js
https://github.com/Strilanc/Quirk/blob/master/src/webgl/WglMortalValueSlot.js
Apache-2.0
ensureDeinitialized() { if (this.lifetimeId !== undefined) { let val = this.mortalValue; this.lifetimeId = undefined; this.mortalValue = undefined; this.deinitializer(val); } }
Cleans up the stored mortal value, if necessary.
ensureDeinitialized
javascript
Strilanc/Quirk
src/webgl/WglMortalValueSlot.js
https://github.com/Strilanc/Quirk/blob/master/src/webgl/WglMortalValueSlot.js
Apache-2.0
withArgs(...uniformArguments) { // Learn the parameter names. if (this._compiledShaderSlot === undefined) { let parameterNames = uniformArguments.map(e => e.name); this._compiledShaderSlot = new WglMortalValueSlot( () => new WglCompiledShader(this.fragmentShaderSo...
Returns the same shader, but parameterized by the given arguments. Call renderTo on the result to render to a destination texture. @param {!WglArg} uniformArguments @returns {!WglConfiguredShader}
withArgs
javascript
Strilanc/Quirk
src/webgl/WglShader.js
https://github.com/Strilanc/Quirk/blob/master/src/webgl/WglShader.js
Apache-2.0
ensureDeinitialized() { if (this._compiledShaderSlot !== undefined) { this._compiledShaderSlot.ensureDeinitialized(); } }
Returns the same shader, but parameterized by the given arguments. Call renderTo on the result to render to a destination texture. @param {!WglArg} uniformArguments @returns {!WglConfiguredShader}
ensureDeinitialized
javascript
Strilanc/Quirk
src/webgl/WglShader.js
https://github.com/Strilanc/Quirk/blob/master/src/webgl/WglShader.js
Apache-2.0