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
fromJson_Complex = json => { if (typeof json === "string") { return Complex.parse(json); } throw new Error("Not a packed complex string: " + json); }
@param {object} json @returns {!Complex} @throws {Error}
fromJson_Complex
javascript
Strilanc/Quirk
src/circuit/Serializer.js
https://github.com/Strilanc/Quirk/blob/master/src/circuit/Serializer.js
Apache-2.0
fromJson_Matrix = json => { if (typeof json !== "string") { throw new Error("Not a packed matrix string: " + json); } return Matrix.parse(/** @type {!string} */ json); }
@param {object} json @returns {!Matrix} @throws {Error}
fromJson_Matrix
javascript
Strilanc/Quirk
src/circuit/Serializer.js
https://github.com/Strilanc/Quirk/blob/master/src/circuit/Serializer.js
Apache-2.0
fromJson_Matrix = json => { if (typeof json !== "string") { throw new Error("Not a packed matrix string: " + json); } return Matrix.parse(/** @type {!string} */ json); }
@param {object} json @returns {!Matrix} @throws {Error}
fromJson_Matrix
javascript
Strilanc/Quirk
src/circuit/Serializer.js
https://github.com/Strilanc/Quirk/blob/master/src/circuit/Serializer.js
Apache-2.0
toJson_Gate = (gate, context=new CustomGateSet()) => { let found = Gates.findKnownGateById(gate.serializedId, context); if (found === gate) { return gate.serializedId; } if (found !== undefined && found.param !== undefined) { return {id: gate.serializedId, arg: gate.param}; } if...
@param {!Gate} gate @param {!CustomGateSet=} context @returns {!object}
toJson_Gate
javascript
Strilanc/Quirk
src/circuit/Serializer.js
https://github.com/Strilanc/Quirk/blob/master/src/circuit/Serializer.js
Apache-2.0
toJson_Gate = (gate, context=new CustomGateSet()) => { let found = Gates.findKnownGateById(gate.serializedId, context); if (found === gate) { return gate.serializedId; } if (found !== undefined && found.param !== undefined) { return {id: gate.serializedId, arg: gate.param}; } if...
@param {!Gate} gate @param {!CustomGateSet=} context @returns {!object}
toJson_Gate
javascript
Strilanc/Quirk
src/circuit/Serializer.js
https://github.com/Strilanc/Quirk/blob/master/src/circuit/Serializer.js
Apache-2.0
function _parseGateMatrix(matrixProp) { if (matrixProp === undefined) { throw new Error("Unrecognized gate id, but no matrix specified."); } let matrix = fromJson_Matrix(matrixProp); if (matrix.width() !== matrix.height()) { throw new Error("Gate matrix must be square."); } if (m...
@param {*} matrixProp @returns {!Matrix} @private @throws
_parseGateMatrix
javascript
Strilanc/Quirk
src/circuit/Serializer.js
https://github.com/Strilanc/Quirk/blob/master/src/circuit/Serializer.js
Apache-2.0
fromJson_Gate_props = json => { let id = _getGateId(json); let matrix = json["matrix"]; let circuit = json["circuit"]; let param = json["arg"]; let symbol = json.name !== undefined ? json.name : id.startsWith('~') ? '' : id; let name = id.startsWith('~') ? `${symbol || 'Custom'} ...
@param {object} json @returns {!{id: !String, matrix: *, circuit: *, symbol: *, name: *, param: *}}
fromJson_Gate_props
javascript
Strilanc/Quirk
src/circuit/Serializer.js
https://github.com/Strilanc/Quirk/blob/master/src/circuit/Serializer.js
Apache-2.0
fromJson_Gate_props = json => { let id = _getGateId(json); let matrix = json["matrix"]; let circuit = json["circuit"]; let param = json["arg"]; let symbol = json.name !== undefined ? json.name : id.startsWith('~') ? '' : id; let name = id.startsWith('~') ? `${symbol || 'Custom'} ...
@param {object} json @returns {!{id: !String, matrix: *, circuit: *, symbol: *, name: *, param: *}}
fromJson_Gate_props
javascript
Strilanc/Quirk
src/circuit/Serializer.js
https://github.com/Strilanc/Quirk/blob/master/src/circuit/Serializer.js
Apache-2.0
fromJson_Gate_Matrix = props => { let mat = _parseGateMatrix(props.matrix); // Special case the mystery gate. if (props.id === MysteryGateSymbol) { return MysteryGateMakerWithMatrix(mat); } let height = Math.round(Math.log2(mat.height())); let width = props.symbol === '' ? height : 1; ...
@param {!{id: !String, matrix: *, circuit: *, symbol: *, name: *, param: *}} props @returns {!Gate}
fromJson_Gate_Matrix
javascript
Strilanc/Quirk
src/circuit/Serializer.js
https://github.com/Strilanc/Quirk/blob/master/src/circuit/Serializer.js
Apache-2.0
fromJson_Gate_Matrix = props => { let mat = _parseGateMatrix(props.matrix); // Special case the mystery gate. if (props.id === MysteryGateSymbol) { return MysteryGateMakerWithMatrix(mat); } let height = Math.round(Math.log2(mat.height())); let width = props.symbol === '' ? height : 1; ...
@param {!{id: !String, matrix: *, circuit: *, symbol: *, name: *, param: *}} props @returns {!Gate}
fromJson_Gate_Matrix
javascript
Strilanc/Quirk
src/circuit/Serializer.js
https://github.com/Strilanc/Quirk/blob/master/src/circuit/Serializer.js
Apache-2.0
fromJson_Gate_Circuit = (props, context) => { let circuit = fromJson_CircuitDefinition(props.circuit, context).withMinimumWireCount(); return setGateBuilderEffectToCircuit(new GateBuilder(), circuit). setSerializedId(props.id). setSymbol(props.symbol). setTitle(props.name). setDr...
@param {!{id: !String, matrix: *, circuit: *, symbol: *, name: *, param: *}} props @param {undefined|!CustomGateSet} context @returns {!Gate}
fromJson_Gate_Circuit
javascript
Strilanc/Quirk
src/circuit/Serializer.js
https://github.com/Strilanc/Quirk/blob/master/src/circuit/Serializer.js
Apache-2.0
fromJson_Gate_Circuit = (props, context) => { let circuit = fromJson_CircuitDefinition(props.circuit, context).withMinimumWireCount(); return setGateBuilderEffectToCircuit(new GateBuilder(), circuit). setSerializedId(props.id). setSymbol(props.symbol). setTitle(props.name). setDr...
@param {!{id: !String, matrix: *, circuit: *, symbol: *, name: *, param: *}} props @param {undefined|!CustomGateSet} context @returns {!Gate}
fromJson_Gate_Circuit
javascript
Strilanc/Quirk
src/circuit/Serializer.js
https://github.com/Strilanc/Quirk/blob/master/src/circuit/Serializer.js
Apache-2.0
fromJson_Gate = (json, context=new CustomGateSet()) => { let props = fromJson_Gate_props(json); try { if (props.matrix !== undefined) { return fromJson_Gate_Matrix(props); } if (props.circuit !== undefined) { return fromJson_Gate_Circuit(props, context); ...
@param {!object} json @param {!CustomGateSet=} context @returns {!Gate} @throws {Error}
fromJson_Gate
javascript
Strilanc/Quirk
src/circuit/Serializer.js
https://github.com/Strilanc/Quirk/blob/master/src/circuit/Serializer.js
Apache-2.0
fromJson_Gate = (json, context=new CustomGateSet()) => { let props = fromJson_Gate_props(json); try { if (props.matrix !== undefined) { return fromJson_Gate_Matrix(props); } if (props.circuit !== undefined) { return fromJson_Gate_Circuit(props, context); ...
@param {!object} json @param {!CustomGateSet=} context @returns {!Gate} @throws {Error}
fromJson_Gate
javascript
Strilanc/Quirk
src/circuit/Serializer.js
https://github.com/Strilanc/Quirk/blob/master/src/circuit/Serializer.js
Apache-2.0
function toJson_GateColumn(v, context=new CustomGateSet()) { return v.gates.map(e => e === undefined ? 1 : toJson_Gate(e, context)); }
@param {!GateColumn} v @param {!CustomGateSet=} context @returns {!object}
toJson_GateColumn
javascript
Strilanc/Quirk
src/circuit/Serializer.js
https://github.com/Strilanc/Quirk/blob/master/src/circuit/Serializer.js
Apache-2.0
fromJson_GateColumn = (json, context=new CustomGateSet()) => { if (!Array.isArray(json)) { throw new Error(`GateColumn json should be an array. Json: ${describe(json)}`); } return new GateColumn(json.map(e => e === 1 || e === undefined ? undefined : fromJson_Gate(e, context))); }
@param {object} json @param {!CustomGateSet=} context @returns {!GateColumn} @throws
fromJson_GateColumn
javascript
Strilanc/Quirk
src/circuit/Serializer.js
https://github.com/Strilanc/Quirk/blob/master/src/circuit/Serializer.js
Apache-2.0
fromJson_GateColumn = (json, context=new CustomGateSet()) => { if (!Array.isArray(json)) { throw new Error(`GateColumn json should be an array. Json: ${describe(json)}`); } return new GateColumn(json.map(e => e === 1 || e === undefined ? undefined : fromJson_Gate(e, context))); }
@param {object} json @param {!CustomGateSet=} context @returns {!GateColumn} @throws
fromJson_GateColumn
javascript
Strilanc/Quirk
src/circuit/Serializer.js
https://github.com/Strilanc/Quirk/blob/master/src/circuit/Serializer.js
Apache-2.0
toJson_CircuitDefinition = (v, context) => { let result = { cols: v.trimEmptyColumnsAtEndIgnoringGateWidths().columns. map(e => toJson_GateColumn(e, context || v.customGateSet)). map(c => seq(c).skipTailWhile(e => e === 1).toArray()) }; if (context === undefined && v.customGa...
@param {!CircuitDefinition} v @param {undefined|!CustomGateSet} context @returns {!object}
toJson_CircuitDefinition
javascript
Strilanc/Quirk
src/circuit/Serializer.js
https://github.com/Strilanc/Quirk/blob/master/src/circuit/Serializer.js
Apache-2.0
toJson_CircuitDefinition = (v, context) => { let result = { cols: v.trimEmptyColumnsAtEndIgnoringGateWidths().columns. map(e => toJson_GateColumn(e, context || v.customGateSet)). map(c => seq(c).skipTailWhile(e => e === 1).toArray()) }; if (context === undefined && v.customGa...
@param {!CircuitDefinition} v @param {undefined|!CustomGateSet} context @returns {!object}
toJson_CircuitDefinition
javascript
Strilanc/Quirk
src/circuit/Serializer.js
https://github.com/Strilanc/Quirk/blob/master/src/circuit/Serializer.js
Apache-2.0
function fromJsonText_CircuitDefinition(jsonText) { if (_cachedCircuit_Arg === jsonText) { return _cachedCircuit; } _cachedCircuit_Arg = jsonText; _cachedCircuit = fromJson_CircuitDefinition(JSON.parse(jsonText), undefined); return _cachedCircuit; }
@param {!CircuitDefinition} v @param {undefined|!CustomGateSet} context @returns {!object}
fromJsonText_CircuitDefinition
javascript
Strilanc/Quirk
src/circuit/Serializer.js
https://github.com/Strilanc/Quirk/blob/master/src/circuit/Serializer.js
Apache-2.0
function _fromJson_InitialState(json) { let {init} = json; if (init === undefined) { return new Map(); } if (!Array.isArray(init)) { throw new DetailedError('Initial states must be an array.', {json}); } let result = new Map(); for (let i = 0; i < init.length; i++) { ...
@param {object} json @returns {!Map.<!int, !string>} @throws
_fromJson_InitialState
javascript
Strilanc/Quirk
src/circuit/Serializer.js
https://github.com/Strilanc/Quirk/blob/master/src/circuit/Serializer.js
Apache-2.0
function fromJson_CircuitDefinition(json, context=undefined) { let {cols} = json; let customGateSet = context || (json.gates === undefined ? new CustomGateSet() : fromJson_CustomGateSet(json.gates)); if (!Array.isArray(cols)) { throw new Error(`CircuitDefinition json should contain an array...
@param {object} json @param {undefined|!CustomGateSet} context @returns {!CircuitDefinition} @throws
fromJson_CircuitDefinition
javascript
Strilanc/Quirk
src/circuit/Serializer.js
https://github.com/Strilanc/Quirk/blob/master/src/circuit/Serializer.js
Apache-2.0
constructor(sizeFunc, drawingFunc) { /** @type {!function(key: *) : !{width: !int, height: !int}} */ this.sizeFunc = sizeFunc; /** * @type {!(function(!Painter): void) | !(function(!Painter, !string): void)} * @private */ this._drawingFunc = drawingFunc; ...
@param {!function(key: *) : !{width: !int, height: !int}} sizeFunc @param {!function(painter: !Painter | !(function(!Painter, !string): void)) : void} drawingFunc
constructor
javascript
Strilanc/Quirk
src/draw/CachablePainting.js
https://github.com/Strilanc/Quirk/blob/master/src/draw/CachablePainting.js
Apache-2.0
paint(x, y, painter, key=undefined) { if (!this._cachedCanvases.has(key)) { let canvas = /** @type {!HTMLCanvasElement} */ document.createElement('canvas'); let {width, height} = this.sizeFunc(key); canvas.width = width; canvas.height = height; this._d...
@param {!int} x @param {!int} y @param {!Painter} painter @param {!*=} key
paint
javascript
Strilanc/Quirk
src/draw/CachablePainting.js
https://github.com/Strilanc/Quirk/blob/master/src/draw/CachablePainting.js
Apache-2.0
constructor(painter, hand, isInToolbox, isHighlighted, isResizeShowing, isResizeHighlighted, rect, gate, stats, positionInCircuit, focusPoints, ...
@param {!Painter} painter @param {!Hand} hand @param {!boolean} isInToolbox @param {!boolean} isHighlighted @param {!boolean} isResizeShowing @param {!boolean} isResizeHighlighted @param {!Rect} rect @param {!Gate} gate @param {!CircuitStats} stats @param {undefined|!{row: !int, col: !int}} positionInCircuit @param {!A...
constructor
javascript
Strilanc/Quirk
src/draw/GateDrawParams.js
https://github.com/Strilanc/Quirk/blob/master/src/draw/GateDrawParams.js
Apache-2.0
function _paintSymbolHandleLines(painter, symbol, rect) { let lines = symbol.split('\n'); for (let i = 1; i < lines.length; i++) { painter.print( lines[i], rect.x + rect.w/2, rect.y + rect.h/2 + 9*i, 'center', 'hanging', 'black', ...
@param {!Painter} painter @param {!string} symbol @param {!Rect} rect @returns {!{symbol: !string, offsetY: !int}} The symbol without any extra lines. @private
_paintSymbolHandleLines
javascript
Strilanc/Quirk
src/draw/GatePainting.js
https://github.com/Strilanc/Quirk/blob/master/src/draw/GatePainting.js
Apache-2.0
function _wireY(args, offset) { return args.rect.center().y + (offset - args.gate.height/2 + 0.5) * Config.WIRE_SPACING; }
@param {!GateDrawParams} args @param {!int} offset @returns {!number}
_wireY
javascript
Strilanc/Quirk
src/draw/GatePainting.js
https://github.com/Strilanc/Quirk/blob/master/src/draw/GatePainting.js
Apache-2.0
static paintProbabilityBox(painter, probability, drawArea, focusPoints = [], backgroundColor = Config.DISPLAY_GATE_BACK_COLOR, fillColor = Config.DISPLAY_GATE_FORE_C...
@param {!Painter} painter @param {!number} probability @param {!Rect} drawArea @param {!Array.<!Point>=} focusPoints @param {!string=} backgroundColor @param {!string=} fillColor
paintProbabilityBox
javascript
Strilanc/Quirk
src/draw/MathPainter.js
https://github.com/Strilanc/Quirk/blob/master/src/draw/MathPainter.js
Apache-2.0
static paintMatrixTooltip( painter, matrix, drawArea, focusPoints, titleFunc, valueTextFunc1, valueTextFunc2 = () => undefined) { let numCols = matrix.width(); let numRows = matrix.height(); let {x, y} = drawArea...
@param {!Painter} painter @param {!Matrix} matrix The matrix to draw. @param {!Rect} drawArea The rectangle to draw the matrix within. @param {!Array.<!Point>} focusPoints @param {!function(!int, !int) : !string} titleFunc @param {!function(!int, !int, !Complex) : !string} valueTextFunc1 @param {(!function(!int, !int, ...
paintMatrixTooltip
javascript
Strilanc/Quirk
src/draw/MathPainter.js
https://github.com/Strilanc/Quirk/blob/master/src/draw/MathPainter.js
Apache-2.0
static _traceAmplitudeProbabilitySquare(trace, real, imag, x, y, d) { let p = real*real + imag*imag; if (p > 0.001) { trace.polygon([ x, y + d * (1 - p), x + d, y + d * (1 - p), x + d, y + d, x, y + d]); } }
@param {!Tracer} trace @param {!number} real @param {!number} imag @param {!number} x @param {!number} y @param {!number} d @private
_traceAmplitudeProbabilitySquare
javascript
Strilanc/Quirk
src/draw/MathPainter.js
https://github.com/Strilanc/Quirk/blob/master/src/draw/MathPainter.js
Apache-2.0
static _traceProbabilitySquare(trace, real, imag, x, y, d) { let p = real; if (d*p > 0.1) { trace.polygon([ x, y + d * (1 - p), x + d, y + d * (1 - p), x + d, y + d, x, y + d]); } }
@param {!Tracer} trace @param {!number} real @param {!number} imag @param {!number} x @param {!number} y @param {!number} d @private
_traceProbabilitySquare
javascript
Strilanc/Quirk
src/draw/MathPainter.js
https://github.com/Strilanc/Quirk/blob/master/src/draw/MathPainter.js
Apache-2.0
static _traceAmplitudeProbabilityCircle(trace, real, imag, x, y, d) { let mag = Math.sqrt(real*real + imag*imag); if (d*mag > 0.5) { trace.circle(x+d/2, y+d/2, mag*d/2); } }
@param {!Tracer} trace @param {!number} real @param {!number} imag @param {!number} x @param {!number} y @param {!number} d @private
_traceAmplitudeProbabilityCircle
javascript
Strilanc/Quirk
src/draw/MathPainter.js
https://github.com/Strilanc/Quirk/blob/master/src/draw/MathPainter.js
Apache-2.0
static _traceAmplitudeLogarithmCircle(trace, real, imag, x, y, d) { let g = 1 + Math.log(real*real + imag*imag)/15; if (g > 0) { trace.circle(x+d/2, y+d/2, g*d/2); } }
@param {!Tracer} trace @param {!number} real @param {!number} imag @param {!number} x @param {!number} y @param {!number} d @private
_traceAmplitudeLogarithmCircle
javascript
Strilanc/Quirk
src/draw/MathPainter.js
https://github.com/Strilanc/Quirk/blob/master/src/draw/MathPainter.js
Apache-2.0
static _traceAmplitudePhaseDirection(trace, real, imag, x, y, d) { let mag = Math.sqrt(real*real + imag*imag); let g = 1 + Math.log(mag)/10; let r = Math.max(1, g/mag)*Math.max(d/2, 5); if (r < 0.1) { return; } let cx = x + d/2; let cy = y + d/2; ...
@param {!Tracer} trace @param {!number} real @param {!number} imag @param {!number} x @param {!number} y @param {!number} d @private
_traceAmplitudePhaseDirection
javascript
Strilanc/Quirk
src/draw/MathPainter.js
https://github.com/Strilanc/Quirk/blob/master/src/draw/MathPainter.js
Apache-2.0
static paintMatrix(painter, matrix, drawArea, amplitudeCircleFillColor, amplitudeCircleStrokeColor, amplitudeProbabilityFillColor, backColor = Config.DISPLAY_GATE_BACK_COLOR, ...
Draws a visual representation of a complex matrix. @param {!Painter} painter @param {!Matrix} matrix The matrix to draw. @param {!Rect} drawArea The rectangle to draw the matrix within. @param {undefined|!string} amplitudeCircleFillColor @param {!string} amplitudeCircleStrokeColor @param {undefined|!string} amplitudePr...
paintMatrix
javascript
Strilanc/Quirk
src/draw/MathPainter.js
https://github.com/Strilanc/Quirk/blob/master/src/draw/MathPainter.js
Apache-2.0
traceCellsWith = cellTraceFunc => painter.trace(trace => { for (let row = 0; row < numRows; row++) { for (let col = 0; col < numCols; col++) { let k = (row * numCols + col) * 2; cellTraceFunc( trace, buf[...
Draws a visual representation of a complex matrix. @param {!Painter} painter @param {!Matrix} matrix The matrix to draw. @param {!Rect} drawArea The rectangle to draw the matrix within. @param {undefined|!string} amplitudeCircleFillColor @param {!string} amplitudeCircleStrokeColor @param {undefined|!string} amplitudePr...
traceCellsWith
javascript
Strilanc/Quirk
src/draw/MathPainter.js
https://github.com/Strilanc/Quirk/blob/master/src/draw/MathPainter.js
Apache-2.0
traceCellsWith = cellTraceFunc => painter.trace(trace => { for (let row = 0; row < numRows; row++) { for (let col = 0; col < numCols; col++) { let k = (row * numCols + col) * 2; cellTraceFunc( trace, buf[...
Draws a visual representation of a complex matrix. @param {!Painter} painter @param {!Matrix} matrix The matrix to draw. @param {!Rect} drawArea The rectangle to draw the matrix within. @param {undefined|!string} amplitudeCircleFillColor @param {!string} amplitudeCircleStrokeColor @param {undefined|!string} amplitudePr...
traceCellsWith
javascript
Strilanc/Quirk
src/draw/MathPainter.js
https://github.com/Strilanc/Quirk/blob/master/src/draw/MathPainter.js
Apache-2.0
static paintDeferredValueTooltip( painter, x, y, labelText, valueText, valueText2 = undefined, backColor = Config.DISPLAY_GATE_BACK_COLOR) { const labelFont = '12px sans-serif'; const valueFont = 'bold 12px monospace'; ...
@param {!Painter} painter @param {!number} x @param {!number} y @param {!string} labelText @param {!string} valueText @param {undefined|!string=} valueText2 @param {!string=} backColor
paintDeferredValueTooltip
javascript
Strilanc/Quirk
src/draw/MathPainter.js
https://github.com/Strilanc/Quirk/blob/master/src/draw/MathPainter.js
Apache-2.0
borderPainter = (w, h) => { let r = new Rect( boundingRect.x, boundingRect.bottom()-h, w, h).paddedBy(4); painter.trace(tracer => tracer.rect(r.x, r.y, r.w, r.h)). thenFill(backColor). ...
@param {!Painter} painter @param {!number} x @param {!number} y @param {!string} labelText @param {!string} valueText @param {undefined|!string=} valueText2 @param {!string=} backColor
borderPainter
javascript
Strilanc/Quirk
src/draw/MathPainter.js
https://github.com/Strilanc/Quirk/blob/master/src/draw/MathPainter.js
Apache-2.0
borderPainter = (w, h) => { let r = new Rect( boundingRect.x, boundingRect.bottom()-h, w, h).paddedBy(4); painter.trace(tracer => tracer.rect(r.x, r.y, r.w, r.h)). thenFill(backColor). ...
@param {!Painter} painter @param {!number} x @param {!number} y @param {!string} labelText @param {!string} valueText @param {undefined|!string=} valueText2 @param {!string=} backColor
borderPainter
javascript
Strilanc/Quirk
src/draw/MathPainter.js
https://github.com/Strilanc/Quirk/blob/master/src/draw/MathPainter.js
Apache-2.0
labelPainter = (w, h) => { painter.print( labelText, boundingRect.x, boundingRect.bottom()-h, 'left', 'bottom', 'black', labelFont, boundingRect...
@param {!Painter} painter @param {!number} x @param {!number} y @param {!string} labelText @param {!string} valueText @param {undefined|!string=} valueText2 @param {!string=} backColor
labelPainter
javascript
Strilanc/Quirk
src/draw/MathPainter.js
https://github.com/Strilanc/Quirk/blob/master/src/draw/MathPainter.js
Apache-2.0
labelPainter = (w, h) => { painter.print( labelText, boundingRect.x, boundingRect.bottom()-h, 'left', 'bottom', 'black', labelFont, boundingRect...
@param {!Painter} painter @param {!number} x @param {!number} y @param {!string} labelText @param {!string} valueText @param {undefined|!string=} valueText2 @param {!string=} backColor
labelPainter
javascript
Strilanc/Quirk
src/draw/MathPainter.js
https://github.com/Strilanc/Quirk/blob/master/src/draw/MathPainter.js
Apache-2.0
value1Painter = (w, h) => { painter.print( valueText, boundingRect.x, boundingRect.bottom()-h, 'left', 'bottom', 'black', valueFont, boundingRec...
@param {!Painter} painter @param {!number} x @param {!number} y @param {!string} labelText @param {!string} valueText @param {undefined|!string=} valueText2 @param {!string=} backColor
value1Painter
javascript
Strilanc/Quirk
src/draw/MathPainter.js
https://github.com/Strilanc/Quirk/blob/master/src/draw/MathPainter.js
Apache-2.0
value1Painter = (w, h) => { painter.print( valueText, boundingRect.x, boundingRect.bottom()-h, 'left', 'bottom', 'black', valueFont, boundingRec...
@param {!Painter} painter @param {!number} x @param {!number} y @param {!string} labelText @param {!string} valueText @param {undefined|!string=} valueText2 @param {!string=} backColor
value1Painter
javascript
Strilanc/Quirk
src/draw/MathPainter.js
https://github.com/Strilanc/Quirk/blob/master/src/draw/MathPainter.js
Apache-2.0
static coordinateSystem(unit) { return { dx: new Point(unit / 3, -unit / 3), dy: new Point(unit, 0), dz: new Point(0, unit) }; }
@param {!number} unit @returns {!{dx: !Point, dy: !Point, dz: !Point}}
coordinateSystem
javascript
Strilanc/Quirk
src/draw/MathPainter.js
https://github.com/Strilanc/Quirk/blob/master/src/draw/MathPainter.js
Apache-2.0
static paintBlochSphereRotation(painter, operation, drawArea, backgroundColor = Config.DISPLAY_GATE_BACK_COLOR, fillColor = Config.DISPLAY_GATE_FORE_COLOR) { let c = dr...
@param {!Painter} painter @param {!Matrix} operation @param {!Rect} drawArea @param {!string=} backgroundColor @param {!string=} fillColor
paintBlochSphereRotation
javascript
Strilanc/Quirk
src/draw/MathPainter.js
https://github.com/Strilanc/Quirk/blob/master/src/draw/MathPainter.js
Apache-2.0
projToPt = col => { let p = projMatrix.times(col); return new Point(p.cell(0, 0).real, p.cell(0, 1).real) }
@param {!Painter} painter @param {!Matrix} operation @param {!Rect} drawArea @param {!string=} backgroundColor @param {!string=} fillColor
projToPt
javascript
Strilanc/Quirk
src/draw/MathPainter.js
https://github.com/Strilanc/Quirk/blob/master/src/draw/MathPainter.js
Apache-2.0
projToPt = col => { let p = projMatrix.times(col); return new Point(p.cell(0, 0).real, p.cell(0, 1).real) }
@param {!Painter} painter @param {!Matrix} operation @param {!Rect} drawArea @param {!string=} backgroundColor @param {!string=} fillColor
projToPt
javascript
Strilanc/Quirk
src/draw/MathPainter.js
https://github.com/Strilanc/Quirk/blob/master/src/draw/MathPainter.js
Apache-2.0
traceCouplingsWith = cellTraceFunc => painter.trace(trace => { for (let row = 0; row < numRows; row++) { for (let col = 0; col < numCols; col++) { let k = (row * numCols + col) * 2; cellTraceFunc( trace, ...
@param {!Painter} painter @param {!Matrix} matrix @param {!Rect} drawArea @param {!Array.<!Point>} focusPoints @param {!string=} backgroundColor @param {!string=} fillColor
traceCouplingsWith
javascript
Strilanc/Quirk
src/draw/MathPainter.js
https://github.com/Strilanc/Quirk/blob/master/src/draw/MathPainter.js
Apache-2.0
traceCouplingsWith = cellTraceFunc => painter.trace(trace => { for (let row = 0; row < numRows; row++) { for (let col = 0; col < numCols; col++) { let k = (row * numCols + col) * 2; cellTraceFunc( trace, ...
@param {!Painter} painter @param {!Matrix} matrix @param {!Rect} drawArea @param {!Array.<!Point>} focusPoints @param {!string=} backgroundColor @param {!string=} fillColor
traceCouplingsWith
javascript
Strilanc/Quirk
src/draw/MathPainter.js
https://github.com/Strilanc/Quirk/blob/master/src/draw/MathPainter.js
Apache-2.0
traceDiagonalWith = cellTraceFunc => painter.trace(trace => { for (let col = 0; col < numRows; col++) { let k = col * (numCols + 1) * 2; cellTraceFunc( trace, buf[k], buf[k + 1], x + diam * col, ...
@param {!Painter} painter @param {!Matrix} matrix @param {!Rect} drawArea @param {!Array.<!Point>} focusPoints @param {!string=} backgroundColor @param {!string=} fillColor
traceDiagonalWith
javascript
Strilanc/Quirk
src/draw/MathPainter.js
https://github.com/Strilanc/Quirk/blob/master/src/draw/MathPainter.js
Apache-2.0
traceDiagonalWith = cellTraceFunc => painter.trace(trace => { for (let col = 0; col < numRows; col++) { let k = col * (numCols + 1) * 2; cellTraceFunc( trace, buf[k], buf[k + 1], x + diam * col, ...
@param {!Painter} painter @param {!Matrix} matrix @param {!Rect} drawArea @param {!Array.<!Point>} focusPoints @param {!string=} backgroundColor @param {!string=} fillColor
traceDiagonalWith
javascript
Strilanc/Quirk
src/draw/MathPainter.js
https://github.com/Strilanc/Quirk/blob/master/src/draw/MathPainter.js
Apache-2.0
constructor(canvas, rng = new RestartableRng()) { /** @type {!HTMLCanvasElement} */ this.canvas = canvas; /** @type {!CanvasRenderingContext2D} */ this.ctx = canvas.getContext("2d"); /** * @type {!Array.<!function()>} * @private */ this._deferre...
@param {!HTMLCanvasElement} canvas @param {!RestartableRng=} rng
constructor
javascript
Strilanc/Quirk
src/draw/Painter.js
https://github.com/Strilanc/Quirk/blob/master/src/draw/Painter.js
Apache-2.0
noteTouchBlocker(blocker) { if (this._ignoringTouchBlockers === 0) { this.touchBlockers.push(blocker); } }
@param {!{rect: !Rect, cursor: undefined|!string}} blocker
noteTouchBlocker
javascript
Strilanc/Quirk
src/draw/Painter.js
https://github.com/Strilanc/Quirk/blob/master/src/draw/Painter.js
Apache-2.0
setDesiredCursor(cursorStyle) { this.desiredCursorStyle = cursorStyle; }
@param {!string} cursorStyle auto|pointer|move|ns-resize|...
setDesiredCursor
javascript
Strilanc/Quirk
src/draw/Painter.js
https://github.com/Strilanc/Quirk/blob/master/src/draw/Painter.js
Apache-2.0
strokeLine(p1, p2, color = Config.DEFAULT_STROKE_COLOR, thickness = 1) { this.ctx.beginPath(); this.ctx.moveTo(p1.x, p1.y); this.ctx.lineTo(p2.x, p2.y); this.ctx.strokeStyle = color; this.ctx.lineWidth = thickness; this.ctx.stroke(); }
Draws a line segment between the two points. @param {!Point} p1 @param {!Point} p2 @param {=string} color The color of the drawn line. @param {=number} thickness The thickness of the drawn line.
strokeLine
javascript
Strilanc/Quirk
src/draw/Painter.js
https://github.com/Strilanc/Quirk/blob/master/src/draw/Painter.js
Apache-2.0
strokeRect(rect, color = "black", thickness = 1) { this.ctx.strokeStyle = color; this.ctx.lineWidth = thickness; this.ctx.strokeRect(rect.x, rect.y, rect.w, rect.h); }
Draws the outside of a rectangle. @param {!Rect} rect The rectangular perimeter to stroke. @param {!string=} color The stroke color. @param {!number=} thickness The stroke thickness.
strokeRect
javascript
Strilanc/Quirk
src/draw/Painter.js
https://github.com/Strilanc/Quirk/blob/master/src/draw/Painter.js
Apache-2.0
fillRect(rect, color = Config.DEFAULT_FILL_COLOR) { this.ctx.fillStyle = color; this.ctx.fillRect(rect.x, rect.y, rect.w, rect.h); }
Draws the inside of a rectangle. @param {!Rect} rect The rectangular area to fill. @param {!string=} color The fill color.
fillRect
javascript
Strilanc/Quirk
src/draw/Painter.js
https://github.com/Strilanc/Quirk/blob/master/src/draw/Painter.js
Apache-2.0
strokeCircle(center, radius, color = Config.DEFAULT_STROKE_COLOR, thickness = Config.DEFAULT_STROKE_THICKNESS) { this.ctx.beginPath(); this.ctx.strokeStyle = color; this.ctx.lineWidth = thickness; this.ctx.arc(center.x, center.y, Math.max(radius - 0.5, 0), 0, 2 * Math.PI); this.c...
Draws the outside of a circle. @param {!Point} center The center of the circle. @param {!number} radius The distance from the center of the circle to its side. @param {!string=} color The stroke color. @param {!number=} thickness The stroke thickness.
strokeCircle
javascript
Strilanc/Quirk
src/draw/Painter.js
https://github.com/Strilanc/Quirk/blob/master/src/draw/Painter.js
Apache-2.0
trace(tracerFunc) { this.ctx.beginPath(); tracerFunc(this._tracer); return this._traceAction; }
@param {!function(!Tracer) : void} tracerFunc @returns {!TraceAction}
trace
javascript
Strilanc/Quirk
src/draw/Painter.js
https://github.com/Strilanc/Quirk/blob/master/src/draw/Painter.js
Apache-2.0
fillCircle(center, radius, color = Config.DEFAULT_FILL_COLOR) { this.ctx.beginPath(); this.ctx.arc(center.x, center.y, Math.max(radius - 0.5, 0), 0, 2 * Math.PI); this.ctx.fillStyle = color; this.ctx.fill(); }
Draws the inside of a circle. @param {!Point} center The center of the circle. @param {!number} radius The distance from the center of the circle to its side. @param {!string=} color The fill color. Defaults to white.
fillCircle
javascript
Strilanc/Quirk
src/draw/Painter.js
https://github.com/Strilanc/Quirk/blob/master/src/draw/Painter.js
Apache-2.0
print(text, x, y, textAlign, textBaseline, fillStyle, font, boundingWidth, boundingHeight, afterMeasureBeforeDraw = undefined, alsoStroke = false) { this.ctx.font = font; let naiveWidth = this.ctx.measur...
Draws some text in a bounded area. @param {!string} text The text to print. @param {!number} x @param {!number} y @param {!number} boundingWidth The text will be scaled down so it doesn't exceed this width. @param {!number} boundingHeight The text will be scaled down so it doesn't exceed this width. @param {!string} te...
print
javascript
Strilanc/Quirk
src/draw/Painter.js
https://github.com/Strilanc/Quirk/blob/master/src/draw/Painter.js
Apache-2.0
printParagraph(text, area, proportionalCenterOfAlignment = new Point(0, 0), fontColor = Config.DEFAULT_TEXT_COLOR, maxFontSize = Config.DEFAULT_FONT_SIZE, fontFamily = Config.DEFAULT_FONT_FAMILY) { let fontSize; ...
Draws some text within the given rectangular area, aligned based on the given proportional center, with line breaking and (if line breaking isn't enough) font size reduction to make things fit. @param {!string} text @param {!Rect} area @param {!Point} proportionalCenterOfAlignment @param {!string} fontColor @param {!i...
printParagraph
javascript
Strilanc/Quirk
src/draw/Painter.js
https://github.com/Strilanc/Quirk/blob/master/src/draw/Painter.js
Apache-2.0
ascendingHeightOf = metric => { let d = metric.fontBoundingBoxAscent; return d === undefined ? fontSize * 0.75 : d; }
Draws some text within the given rectangular area, aligned based on the given proportional center, with line breaking and (if line breaking isn't enough) font size reduction to make things fit. @param {!string} text @param {!Rect} area @param {!Point} proportionalCenterOfAlignment @param {!string} fontColor @param {!i...
ascendingHeightOf
javascript
Strilanc/Quirk
src/draw/Painter.js
https://github.com/Strilanc/Quirk/blob/master/src/draw/Painter.js
Apache-2.0
ascendingHeightOf = metric => { let d = metric.fontBoundingBoxAscent; return d === undefined ? fontSize * 0.75 : d; }
Draws some text within the given rectangular area, aligned based on the given proportional center, with line breaking and (if line breaking isn't enough) font size reduction to make things fit. @param {!string} text @param {!Rect} area @param {!Point} proportionalCenterOfAlignment @param {!string} fontColor @param {!i...
ascendingHeightOf
javascript
Strilanc/Quirk
src/draw/Painter.js
https://github.com/Strilanc/Quirk/blob/master/src/draw/Painter.js
Apache-2.0
descendingHeightOf = metric => { let d = metric.fontBoundingBoxDescent; return d === undefined ? fontSize * 0.25 : d; }
Draws some text within the given rectangular area, aligned based on the given proportional center, with line breaking and (if line breaking isn't enough) font size reduction to make things fit. @param {!string} text @param {!Rect} area @param {!Point} proportionalCenterOfAlignment @param {!string} fontColor @param {!i...
descendingHeightOf
javascript
Strilanc/Quirk
src/draw/Painter.js
https://github.com/Strilanc/Quirk/blob/master/src/draw/Painter.js
Apache-2.0
descendingHeightOf = metric => { let d = metric.fontBoundingBoxDescent; return d === undefined ? fontSize * 0.25 : d; }
Draws some text within the given rectangular area, aligned based on the given proportional center, with line breaking and (if line breaking isn't enough) font size reduction to make things fit. @param {!string} text @param {!Rect} area @param {!Point} proportionalCenterOfAlignment @param {!string} fontColor @param {!i...
descendingHeightOf
javascript
Strilanc/Quirk
src/draw/Painter.js
https://github.com/Strilanc/Quirk/blob/master/src/draw/Painter.js
Apache-2.0
printLine(text, area, proportionalCenterOfHorizontalAlignment = 0, fontColor = Config.DEFAULT_TEXT_COLOR, maxFontSize = Config.DEFAULT_FONT_SIZE, fontFamily = Config.DEFAULT_FONT_FAMILY, proportionalCenterOfVerticalAlignment = undefined...
Draws a single line of text, without line breaks, using font size reduction to make things fit. @param {!string} text @param {!Rect} area @param {!number|undefined=} proportionalCenterOfHorizontalAlignment @param {!string|undefined=} fontColor @param {!int|undefined=} maxFontSize @param {!string|undefined=} fontFamily...
printLine
javascript
Strilanc/Quirk
src/draw/Painter.js
https://github.com/Strilanc/Quirk/blob/master/src/draw/Painter.js
Apache-2.0
ascendingHeightOf = metric => { let d = metric.fontBoundingBoxAscent; return d === undefined ? fontSize * 0.75 : d; }
Draws a single line of text, without line breaks, using font size reduction to make things fit. @param {!string} text @param {!Rect} area @param {!number|undefined=} proportionalCenterOfHorizontalAlignment @param {!string|undefined=} fontColor @param {!int|undefined=} maxFontSize @param {!string|undefined=} fontFamily...
ascendingHeightOf
javascript
Strilanc/Quirk
src/draw/Painter.js
https://github.com/Strilanc/Quirk/blob/master/src/draw/Painter.js
Apache-2.0
ascendingHeightOf = metric => { let d = metric.fontBoundingBoxAscent; return d === undefined ? fontSize * 0.75 : d; }
Draws a single line of text, without line breaks, using font size reduction to make things fit. @param {!string} text @param {!Rect} area @param {!number|undefined=} proportionalCenterOfHorizontalAlignment @param {!string|undefined=} fontColor @param {!int|undefined=} maxFontSize @param {!string|undefined=} fontFamily...
ascendingHeightOf
javascript
Strilanc/Quirk
src/draw/Painter.js
https://github.com/Strilanc/Quirk/blob/master/src/draw/Painter.js
Apache-2.0
descendingHeightOf = metric => { let d = metric.fontBoundingBoxDescent; return d === undefined ? fontSize * 0.25 : d; }
Draws a single line of text, without line breaks, using font size reduction to make things fit. @param {!string} text @param {!Rect} area @param {!number|undefined=} proportionalCenterOfHorizontalAlignment @param {!string|undefined=} fontColor @param {!int|undefined=} maxFontSize @param {!string|undefined=} fontFamily...
descendingHeightOf
javascript
Strilanc/Quirk
src/draw/Painter.js
https://github.com/Strilanc/Quirk/blob/master/src/draw/Painter.js
Apache-2.0
descendingHeightOf = metric => { let d = metric.fontBoundingBoxDescent; return d === undefined ? fontSize * 0.25 : d; }
Draws a single line of text, without line breaks, using font size reduction to make things fit. @param {!string} text @param {!Rect} area @param {!number|undefined=} proportionalCenterOfHorizontalAlignment @param {!string|undefined=} fontColor @param {!int|undefined=} maxFontSize @param {!string|undefined=} fontFamily...
descendingHeightOf
javascript
Strilanc/Quirk
src/draw/Painter.js
https://github.com/Strilanc/Quirk/blob/master/src/draw/Painter.js
Apache-2.0
strokePolygon(vertices, strokeColor = Config.DEFAULT_STROKE_COLOR, strokeThickness = Config.DEFAULT_STROKE_THICKNESS) { if (vertices.length === 0) { return; } let last = vertices[vertices.length - 1]; this.ctx.beginPath(); this.ctx...
Draws the outside of a polygon. @param {!(!Point[])} vertices @param {!string=} strokeColor The stroke color. @param {!number=} strokeThickness The stroke thickness.
strokePolygon
javascript
Strilanc/Quirk
src/draw/Painter.js
https://github.com/Strilanc/Quirk/blob/master/src/draw/Painter.js
Apache-2.0
strokePath(vertices, strokeColor = Config.DEFAULT_STROKE_COLOR, strokeThickness = Config.DEFAULT_STROKE_THICKNESS) { if (vertices.length === 0) { return; } this.ctx.beginPath(); this.ctx.moveTo(vertices[0].x, vertices[0].y); for (l...
Draws a path. @param {!(!Point[])} vertices @param {!string=} strokeColor The stroke color. @param {!number=} strokeThickness The stroke thickness.
strokePath
javascript
Strilanc/Quirk
src/draw/Painter.js
https://github.com/Strilanc/Quirk/blob/master/src/draw/Painter.js
Apache-2.0
fillPolygon(vertices, fillColor) { let last = vertices[vertices.length - 1]; this.ctx.beginPath(); this.ctx.moveTo(last.x, last.y); for (let p of vertices) { this.ctx.lineTo(p.x, p.y); } this.ctx.fillStyle = fillColor; this.ctx.fill(); }
Draws the inside of a polygon. @param {!(!Point[])} vertices @param {!string} fillColor
fillPolygon
javascript
Strilanc/Quirk
src/draw/Painter.js
https://github.com/Strilanc/Quirk/blob/master/src/draw/Painter.js
Apache-2.0
line(x1, y1, x2, y2) { this.ctx.moveTo(x1, y1); this.ctx.lineTo(x2, y2); }
@param {!number} x1 @param {!number} y1 @param {!number} x2 @param {!number} y2
line
javascript
Strilanc/Quirk
src/draw/Painter.js
https://github.com/Strilanc/Quirk/blob/master/src/draw/Painter.js
Apache-2.0
rect(x, y, w, h) { this.ctx.moveTo(x, y); this.ctx.lineTo(x + w, y); this.ctx.lineTo(x + w, y + h); this.ctx.lineTo(x, y + h); this.ctx.lineTo(x, y); }
@param {!number} x @param {!number} y @param {!number} w @param {!number} h
rect
javascript
Strilanc/Quirk
src/draw/Painter.js
https://github.com/Strilanc/Quirk/blob/master/src/draw/Painter.js
Apache-2.0
circle(x, y, radius) { this.ctx.moveTo(x + radius, y); this.ctx.arc(x, y, radius, 0, 2 * Math.PI, false); }
@param {!number} x The x-coordinate of the center of the circle. @param {!number} y The y-coordinate of the center of the circle. @param {!number} radius The distance from the center of the circle to its side.
circle
javascript
Strilanc/Quirk
src/draw/Painter.js
https://github.com/Strilanc/Quirk/blob/master/src/draw/Painter.js
Apache-2.0
ellipse(x, y, horizontal_radius, vertical_radius) { this.ctx.save(); this.ctx.translate(x - horizontal_radius, y - vertical_radius); this.ctx.scale(horizontal_radius, vertical_radius); this.ctx.moveTo(2, 1); this.ctx.arc(1, 1, 1, 0, 2 * Math.PI, false); this.ctx.restore...
@param {!number} x The x-coordinate of the center of the ellipse. @param {!number} y The y-coordinate of the center of the ellipse. @param {!number} horizontal_radius The horizontal distance from the center of the ellipse to its side. @param {!number} vertical_radius The vertical distance from the center of the ellipse...
ellipse
javascript
Strilanc/Quirk
src/draw/Painter.js
https://github.com/Strilanc/Quirk/blob/master/src/draw/Painter.js
Apache-2.0
grid(x, y, w, h, numCols, numRows) { let dw = w / numCols; let dh = h / numRows; let x2 = x + numCols * dw; let y2 = y + numRows * dh; for (let c = 0; c <= numCols; c++) { this.ctx.moveTo(x + c * dw, y); this.ctx.lineTo(x + c * dw, y2); } f...
@param {!number} x @param {!number} y @param {!number} w @param {!number} h @param {!int} numCols @param {!int} numRows
grid
javascript
Strilanc/Quirk
src/draw/Painter.js
https://github.com/Strilanc/Quirk/blob/master/src/draw/Painter.js
Apache-2.0
arrowHead(x, y, radius, facingAngle, sweptAngle) { let a1 = facingAngle + sweptAngle/2 + Math.PI; let a2 = facingAngle - sweptAngle/2 + Math.PI; this.polygon([ x + Math.cos(facingAngle)*radius, y + Math.sin(facingAngle)*radius, x + Math.cos(a1)*radius, y + Math.sin(a1)*ra...
@param {!number} x The x-position of the center of the arrow head. @param {number} y The y-position of the center of the arrow head. @param {number} radius The radius of the circle the arrow head is inscribed inside. @param {number} facingAngle The direction the arrow head is pointing towards. @param {number} sweptAngl...
arrowHead
javascript
Strilanc/Quirk
src/draw/Painter.js
https://github.com/Strilanc/Quirk/blob/master/src/draw/Painter.js
Apache-2.0
thenStroke(strokeStyle, lineWidth = 1) { this.ctx.strokeStyle = strokeStyle; this.ctx.lineWidth = lineWidth; this.ctx.stroke(); return this; }
@param {!string} strokeStyle @param {!number=} lineWidth @returns {!TraceAction}
thenStroke
javascript
Strilanc/Quirk
src/draw/Painter.js
https://github.com/Strilanc/Quirk/blob/master/src/draw/Painter.js
Apache-2.0
static _paintGateTooltip_matrix(painter, gate, matrix, pad, dispSize, w, pushRect, nextY) { if (matrix === undefined) { return; } pushRect(new Rect(0, nextY(), 1, 0), pad*2); pushRect(painter.printParagraph('As matrix:', new Rect(pad, nextY(), w, 18), new Point(0, 0), 'black...
@param {!Painter} painter @param {!Gate} gate @param {undefined|!Matrix} matrix @param {!number} pad @param {!number} dispSize @param {!number} w @param {!function(!Rect, pad:!number=):void} pushRect @param {!function():!number} nextY @private
_paintGateTooltip_matrix
javascript
Strilanc/Quirk
src/draw/WidgetPainter.js
https://github.com/Strilanc/Quirk/blob/master/src/draw/WidgetPainter.js
Apache-2.0
static _paintGateTooltip_circuit(painter, nestedCircuit, pad, dispSize, w, pushRect, nextY, time) { if (nestedCircuit === undefined) { return; } let weight = nestedCircuit.gateWeight(); pushRect(new Rect(0, nextY(), 1, 0), pad*2); pushRect(painter.printParagraph( ...
@param {!Painter} painter @param {undefined|!CircuitDefinition} nestedCircuit @param {!number} pad @param {!number} dispSize @param {!number} w @param {!function(!Rect, pad:!number=):void} pushRect @param {!function():!number} nextY @param {!number} time @private
_paintGateTooltip_circuit
javascript
Strilanc/Quirk
src/draw/WidgetPainter.js
https://github.com/Strilanc/Quirk/blob/master/src/draw/WidgetPainter.js
Apache-2.0
static paintGateTooltipHelper(painter, w, gate, time) { const [pad, dispSize] = [4, 65]; let [maxX, maxY] = [0, pad]; let pushRect = (rect, actualPad=pad) => { maxY = Math.max(maxY, rect.bottom() + actualPad); maxX = Math.max(maxX, rect.right() + actualPad); }; ...
@param {!Painter} painter @param {!number} w @param {!Gate} gate @param {!number} time @returns {!{maxX: !number, maxY: !number}} @private
paintGateTooltipHelper
javascript
Strilanc/Quirk
src/draw/WidgetPainter.js
https://github.com/Strilanc/Quirk/blob/master/src/draw/WidgetPainter.js
Apache-2.0
pushRect = (rect, actualPad=pad) => { maxY = Math.max(maxY, rect.bottom() + actualPad); maxX = Math.max(maxX, rect.right() + actualPad); }
@param {!Painter} painter @param {!number} w @param {!Gate} gate @param {!number} time @returns {!{maxX: !number, maxY: !number}} @private
pushRect
javascript
Strilanc/Quirk
src/draw/WidgetPainter.js
https://github.com/Strilanc/Quirk/blob/master/src/draw/WidgetPainter.js
Apache-2.0
pushRect = (rect, actualPad=pad) => { maxY = Math.max(maxY, rect.bottom() + actualPad); maxX = Math.max(maxX, rect.right() + actualPad); }
@param {!Painter} painter @param {!number} w @param {!Gate} gate @param {!number} time @returns {!{maxX: !number, maxY: !number}} @private
pushRect
javascript
Strilanc/Quirk
src/draw/WidgetPainter.js
https://github.com/Strilanc/Quirk/blob/master/src/draw/WidgetPainter.js
Apache-2.0
static paintGateTooltip(painter, area, gate, time, mayNeedToScale=true) { painter.ctx.save(); painter.ctx.translate(area.x, area.y); area = area.withX(0).withY(0); let scale = Math.min(area.w/500, area.h/300); if (mayNeedToScale && scale < 1) { painter.ctx.scale(scale...
@param {!Painter} painter @param {!Rect} area @param {!Gate} gate @param {!number} time @param {!boolean=true} mayNeedToScale @returns {!{maxW: number, maxH: number}}
paintGateTooltip
javascript
Strilanc/Quirk
src/draw/WidgetPainter.js
https://github.com/Strilanc/Quirk/blob/master/src/draw/WidgetPainter.js
Apache-2.0
function amplitudeDisplayStatTextures(stateKet, controls, controlsTexture, rangeOffset, rangeLength) { let incoherentKet = probabilityStatTexture(stateKet, controlsTexture, rangeOffset, rangeLength); let trader = new WglTextureTrader(stateKet); trader.dontDeallocCurrentTexture(); // Put into normal fo...
@param {!WglTexture} stateKet @param {!Controls} controls @param {!WglTexture} controlsTexture @param {!int} rangeOffset @param {!int} rangeLength @returns {!Array.<!WglTexture>}
amplitudeDisplayStatTextures
javascript
Strilanc/Quirk
src/gates/AmplitudeDisplay.js
https://github.com/Strilanc/Quirk/blob/master/src/gates/AmplitudeDisplay.js
Apache-2.0
function processOutputs(span, pixelGroups, circuitDefinition) { let [ketPixels, qualityPixels, rawIncoherentKetPixels] = pixelGroups; let denormalizedQuality = qualityPixels[0]; let n = 1 << span; let w = n === 2 ? 2 : 1 << Math.floor(Math.round(Math.log2(n))/2); let h = n/w; // Rescale quantit...
@param {!int} span @param {!Array.<!Float32Array>} pixelGroups @param {!CircuitDefinition} circuitDefinition @returns {!{quality: !number, ket: !Matrix, phaseLockIndex: !int,incoherentKet: !Matrix}}
processOutputs
javascript
Strilanc/Quirk
src/gates/AmplitudeDisplay.js
https://github.com/Strilanc/Quirk/blob/master/src/gates/AmplitudeDisplay.js
Apache-2.0
function paintErrorIfPresent(args, indicatorAlpha) { /** @type {undefined|!string} */ let err = undefined; let {col, row} = args.positionInCircuit; let measured = ((args.stats.circuitDefinition.colIsMeasuredMask(col) >> row) & ((1 << args.gate.height) - 1)) !== 0; if (measured) { indicatorAl...
@param {!GateDrawParams} args @param {!number} indicatorAlpha
paintErrorIfPresent
javascript
Strilanc/Quirk
src/gates/AmplitudeDisplay.js
https://github.com/Strilanc/Quirk/blob/master/src/gates/AmplitudeDisplay.js
Apache-2.0
function customStatsToJsonData(customStats) { let {quality, ket, phaseLockIndex, incoherentKet} = customStats; let n = ket.width() * ket.height(); return { coherence_measure: quality, superposition_phase_locked_state_index: phaseLockIndex === undefined ? null : phaseLockIndex, ket: c...
@param {!{quality: !number, ket: !Matrix, phaseLockIndex: !int,incoherentKet: !Matrix}} customStats
customStatsToJsonData
javascript
Strilanc/Quirk
src/gates/AmplitudeDisplay.js
https://github.com/Strilanc/Quirk/blob/master/src/gates/AmplitudeDisplay.js
Apache-2.0
function _paintBlochSphereDisplay_indicator( painter, x, y, z, drawArea, fillColor) { let c = drawArea.center(); let u = Math.min(drawArea.w, drawArea.h) / 2; let {dx, dy, dz} = MathPainter.coordinateSystem(u); let p = c.plus(dx.times(x)).plus(dy.times(y)...
@param {!Painter} painter @param {!number} x @param {!number} y @param {!number} z @param {!Rect} drawArea @param {!string=} fillColor
_paintBlochSphereDisplay_indicator
javascript
Strilanc/Quirk
src/gates/BlochSphereDisplay.js
https://github.com/Strilanc/Quirk/blob/master/src/gates/BlochSphereDisplay.js
Apache-2.0
function paintBlochSphereDisplay( painter, qubitDensityMatrix, drawArea, focusPoints = [], backgroundColor = Config.DISPLAY_GATE_BACK_COLOR, fillColor = Config.DISPLAY_GATE_FORE_COLOR) { let c = drawArea.center(); let u = Math.min(drawArea.w, drawArea.h) / 2; ...
@param {!Painter} painter @param {!Matrix} qubitDensityMatrix @param {!Rect} drawArea @param {!Array.<!Point>=} focusPoints @param {!string=} backgroundColor @param {!string=} fillColor
paintBlochSphereDisplay
javascript
Strilanc/Quirk
src/gates/BlochSphereDisplay.js
https://github.com/Strilanc/Quirk/blob/master/src/gates/BlochSphereDisplay.js
Apache-2.0
function customComparisonShader(compareCode) { const shader = ketShaderPermute( ` ${ketInputGateShaderCode('A')} ${ketInputGateShaderCode('B')} `, ` float lhs = read_input_A(); float rhs = read_input_B(); return mod(out_id + ((${com...
@param {!string} compareCode @returns {!function(!CircuitEvalContext) : !WglConfiguredShader}
customComparisonShader
javascript
Strilanc/Quirk
src/gates/ComparisonGates.js
https://github.com/Strilanc/Quirk/blob/master/src/gates/ComparisonGates.js
Apache-2.0
function parityGatherScatter(ctx, order) { let c = ctx.rawControls; let isLast = 2 << ctx.row > c.parityMask; let isFirst = 1 << ctx.row === (c.parityMask & ~(c.parityMask - 1)); if (order ? isLast : isFirst) { ctx.applyOperation(PARITY_SHADER.withArgs( ...ketArgs(ctx.withRow(Util.ce...
Applies a multi-target CNOT operation, merging the parities onto a single qubit (or reversing that process). Note that this method is invoked for each parity control, but only the last one in the column is supposed to perform the operation (or, when uncomputing, the first one). @param {!CircuitEvalContext} ctx @param...
parityGatherScatter
javascript
Strilanc/Quirk
src/gates/Controls.js
https://github.com/Strilanc/Quirk/blob/master/src/gates/Controls.js
Apache-2.0
function parityDrawer(name) { return args => { if (args.isInToolbox || args.isHighlighted) { GatePainting.paintBackground(args); GatePainting.paintOutline(args); } let center = args.rect.paddedBy(-10); args.painter.fillRect(center); args.painter.stroke...
@param {!string} name @returns {!function(args: !GateDrawParams)}
parityDrawer
javascript
Strilanc/Quirk
src/gates/Controls.js
https://github.com/Strilanc/Quirk/blob/master/src/gates/Controls.js
Apache-2.0
function offsetPermutation(time, factor, span, state) { let offset = Math.floor(time * (1 << span)) * factor; return (state + offset) & ((1 << span) - 1); }
@param {!number} time @param {!int} factor @param {!int} span @param {!int} state @returns {!int}
offsetPermutation
javascript
Strilanc/Quirk
src/gates/CountingGates.js
https://github.com/Strilanc/Quirk/blob/master/src/gates/CountingGates.js
Apache-2.0
function bitOffsetPermutation(time, factor, span, state) { let offset = Math.floor(time*span) * factor; return makeCycleBitsPermutation(offset, span)(state) }
@param {!number} time @param {!int} factor @param {!int} span @param {!int} state @returns {!int}
bitOffsetPermutation
javascript
Strilanc/Quirk
src/gates/CountingGates.js
https://github.com/Strilanc/Quirk/blob/master/src/gates/CountingGates.js
Apache-2.0
cycleBitsShader = (ctx, qubitSpan, shiftAmount) => CYCLE_SHADER.withArgs( ...ketArgs(ctx, qubitSpan), WglArg.float("amount", 1 << Util.properMod(-shiftAmount, qubitSpan)))
@param {!CircuitEvalContext} ctx @param {!int} qubitSpan @param {!int} shiftAmount @returns {!WglConfiguredShader}
cycleBitsShader
javascript
Strilanc/Quirk
src/gates/CycleBitsGates.js
https://github.com/Strilanc/Quirk/blob/master/src/gates/CycleBitsGates.js
Apache-2.0