From 57638ad03b1bc243fc1676dec33033c4d52cc87e Mon Sep 17 00:00:00 2001 From: Craig Gidney Date: Sun, 14 May 2017 13:34:41 -0700 Subject: [PATCH 01/28] Add text to delayed choice eraser example --- src/ui/menu.js | 48 ++++++++++++++++++++++++++++++------------------ 1 file changed, 30 insertions(+), 18 deletions(-) diff --git a/src/ui/menu.js b/src/ui/menu.js index 9eb05251..ecdf049a 100644 --- a/src/ui/menu.js +++ b/src/ui/menu.js @@ -45,24 +45,36 @@ const teleportLink = { {"id":"~f7c0","name":"received","matrix":"{{1,0},{0,1}}"} ] }; -const eraserLink = {"cols":[ - [1,"H"], - [1,"•",1,1,"X"], - [1,1,"QFT7"], - [1,1,"Measure","Measure","Measure","Measure","Measure","Measure","Measure"], - ["…","…","Chance7"], - ["…","…"], - ["…","…"], - ["…","…"], - ["H"], - ["Measure"], - ["•","X^½"], - [1,"Measure"], - ["◦","◦","Chance7"], - ["◦","•","Chance7"], - ["•","◦","Chance7"], - ["•","•","Chance7"] -]}; +const eraserLink = { + "cols": [ + [1,"H"], + [1,"•",1,1,"X"], + [1,"~slits","QFT7"], + [1,1,"Measure","Measure","Measure","Measure","Measure","Measure","Measure"], + ["…","…","Chance7"], + ["…","…"], + ["…","…"], + ["…","…"], + ["H"], + ["Measure"], + ["~choice"], + ["•","X^½"], + [1,"Measure"], + [1,"~result",1,1,1,"~flat"], + ["◦","◦","Chance7"], + ["◦","•","Chance7"], + [1,1,1,1,1,"~waves"], + ["•","◦","Chance7"], + ["•","•","Chance7"] + ], + "gates": [ + {"id":"~choice","name":"choice","matrix":"{{1,0},{0,1}}"}, + {"id":"~result","name":"result","matrix":"{{1,0},{0,1}}"}, + {"id":"~flat","name":"flat","matrix":"{{1,0},{0,1}}"}, + {"id":"~waves","name":"waves","matrix":"{{1,0},{0,1}}"}, + {"id":"~slits","name":"slits","matrix":"{{1,0},{0,1}}"} + ] +}; const chshTestLink = { "cols": [ ["H"], From 108db8ba02f188a7cefe98abd3e85de1b95b5964 Mon Sep 17 00:00:00 2001 From: Craig Gidney Date: Thu, 6 Jul 2017 22:19:12 -0700 Subject: [PATCH 02/28] Drop reversed input gates from toolbox --- src/gates/AllGates.js | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/src/gates/AllGates.js b/src/gates/AllGates.js index d588f04e..e139bc81 100644 --- a/src/gates/AllGates.js +++ b/src/gates/AllGates.js @@ -263,10 +263,10 @@ Gates.BottomToolboxGroups = [ { hint: "Inputs", gates: [ - InputGates.InputAFamily.ofSize(2), InputGates.InputRevAFamily.ofSize(2), - InputGates.InputBFamily.ofSize(2), InputGates.InputRevBFamily.ofSize(2), + InputGates.InputAFamily.ofSize(2), InputGates.SetA, + InputGates.InputBFamily.ofSize(2), InputGates.SetB, InputGates.InputRFamily.ofSize(2), InputGates.SetR, - InputGates.SetA, InputGates.SetB, + undefined, undefined, ] }, { From 2f6bd1cb6a65c257d8ed1413d21091d0cc217f6a Mon Sep 17 00:00:00 2001 From: Craig Gidney Date: Thu, 6 Jul 2017 22:41:56 -0700 Subject: [PATCH 03/28] Extract IncrementGates.js from ArithmeticGates.js - Added assertThatCircuitShaderActsLikePermutation test util --- src/gates/AllGates.js | 5 +++- src/gates/ArithmeticGates.js | 28 +------------------- src/gates/CountingGates.js | 2 +- src/gates/IncrementGates.js | 36 ++++++++++++++++++++++++++ test/CircuitOperationTestUtil.js | 34 +++++++++++++++++------- test/circuit/CircuitDefinition.test.js | 4 +-- test/gates/ArithmeticGates.test.js | 17 ++---------- test/gates/IncrementGates.test.js | 33 +++++++++++++++++++++++ 8 files changed, 104 insertions(+), 55 deletions(-) create mode 100644 src/gates/IncrementGates.js create mode 100644 test/gates/IncrementGates.test.js diff --git a/src/gates/AllGates.js b/src/gates/AllGates.js index e139bc81..b7aee446 100644 --- a/src/gates/AllGates.js +++ b/src/gates/AllGates.js @@ -11,6 +11,7 @@ import {ErrorInjectionGate} from "src/gates/Debug_ErrorInjectionGate.js" import {ExponentiatingGates} from "src/gates/ExponentiatingGates.js" import {FourierTransformGates} from "src/gates/FourierTransformGates.js" import {HalfTurnGates} from "src/gates/HalfTurnGates.js" +import {IncrementGates} from "src/gates/IncrementGates.js" import {InputGates} from "src/gates/InputGates.js" import {InterleaveBitsGates} from "src/gates/InterleaveBitsGates.js" import {MeasurementGate} from "src/gates/MeasurementGate.js" @@ -73,6 +74,7 @@ Gates.ErrorInjection = ErrorInjectionGate; Gates.Exponentiating = ExponentiatingGates; Gates.FourierTransformGates = FourierTransformGates; Gates.HalfTurns = HalfTurnGates; +Gates.IncrementGates = IncrementGates; Gates.InputGates = InputGates; Gates.InterleaveBitsGates = InterleaveBitsGates; Gates.ModularIncrementGates = ModularIncrementGates; @@ -123,6 +125,7 @@ Gates.KnownToSerializer = [ ...ExponentiatingGates.all, ...FourierTransformGates.all, ...HalfTurnGates.all, + ...IncrementGates.all, ...InterleaveBitsGates.all, ...ModularAdditionGates.all, ...ModularIncrementGates.all, @@ -272,7 +275,7 @@ Gates.BottomToolboxGroups = [ { hint: 'Arithmetic', gates: [ - ArithmeticGates.IncrementFamily.ofSize(2), ArithmeticGates.DecrementFamily.ofSize(2), + IncrementGates.IncrementFamily.ofSize(2), IncrementGates.DecrementFamily.ofSize(2), ArithmeticGates.PlusAFamily.ofSize(2), ArithmeticGates.MinusAFamily.ofSize(2), MultiplyAccumulateGates.MultiplyAddInputsFamily.ofSize(2), MultiplyAccumulateGates.MultiplySubtractInputsFamily.ofSize(2), diff --git a/src/gates/ArithmeticGates.js b/src/gates/ArithmeticGates.js index 8dae5425..ad213035 100644 --- a/src/gates/ArithmeticGates.js +++ b/src/gates/ArithmeticGates.js @@ -15,10 +15,6 @@ const chunkedScaledAdditionPermutationMaker = (span, factor) => e => { return a + (b << sa); }; -const offsetShader = ketShaderPermute( - 'uniform float amount;', - 'return mod(out_id - amount + span, span);'); - const ADDITION_SHADER = ketShaderPermute( ` uniform float factor; @@ -30,26 +26,6 @@ const ADDITION_SHADER = ketShaderPermute( d = mod(d, span); return mod(out_id + span - d, span);`); -ArithmeticGates.IncrementFamily = Gate.buildFamily(1, 16, (span, builder) => builder. - setSerializedId("inc" + span). - setSymbol("+1"). - setTitle("Increment Gate"). - setBlurb("Adds 1 to the little-endian number represented by a block of qubits."). - setActualEffectToShaderProvider(ctx => offsetShader.withArgs( - ...ketArgs(ctx, span), - WglArg.float("amount", +1))). - setKnownEffectToPermutation(t => (t + 1) & ((1 << span) - 1))); - -ArithmeticGates.DecrementFamily = Gate.buildFamily(1, 16, (span, builder) => builder. - setSerializedId("dec" + span). - setSymbol("−1"). - setTitle("Decrement Gate"). - setBlurb("Subtracts 1 from the little-endian number represented by a block of qubits."). - setActualEffectToShaderProvider(ctx => offsetShader.withArgs( - ...ketArgs(ctx, span), - WglArg.float("amount", -1))). - setKnownEffectToPermutation(t => (t - 1) & ((1 << span) - 1))); - ArithmeticGates.Legacy_AdditionFamily = Gate.buildFamily(2, 16, (span, builder) => builder. setSerializedId("add" + span). setSymbol("b+=a"). @@ -97,12 +73,10 @@ ArithmeticGates.MinusAFamily = Gate.buildFamily(1, 16, (span, builder) => builde setKnownEffectToParametrizedPermutation((v, a) => (v - a) & ((1 << span) - 1))); ArithmeticGates.all = [ - ...ArithmeticGates.IncrementFamily.all, - ...ArithmeticGates.DecrementFamily.all, ...ArithmeticGates.Legacy_AdditionFamily.all, ...ArithmeticGates.Legacy_SubtractionFamily.all, ...ArithmeticGates.PlusAFamily.all, ...ArithmeticGates.MinusAFamily.all, ]; -export {ArithmeticGates, offsetShader} +export {ArithmeticGates} diff --git a/src/gates/CountingGates.js b/src/gates/CountingGates.js index 9aae2140..ad6564e9 100644 --- a/src/gates/CountingGates.js +++ b/src/gates/CountingGates.js @@ -6,7 +6,7 @@ import {Point} from "src/math/Point.js" import {ketArgs} from "src/circuit/KetShaderUtil.js" import {WglArg} from "src/webgl/WglArg.js" -import {offsetShader} from "src/gates/ArithmeticGates.js" +import {offsetShader} from "src/gates/IncrementGates.js" import {makeCycleBitsPermutation, cycleBitsShader} from "src/gates/CycleBitsGates.js" let CountingGates = {}; diff --git a/src/gates/IncrementGates.js b/src/gates/IncrementGates.js new file mode 100644 index 00000000..3ea9e2d5 --- /dev/null +++ b/src/gates/IncrementGates.js @@ -0,0 +1,36 @@ +import {Gate} from "src/circuit/Gate.js" +import {ketArgs, ketShaderPermute} from "src/circuit/KetShaderUtil.js" +import {WglArg} from "src/webgl/WglArg.js" + +let IncrementGates = {}; + +const offsetShader = ketShaderPermute( + 'uniform float amount;', + 'return mod(out_id - amount + span, span);'); + +IncrementGates.IncrementFamily = Gate.buildFamily(1, 16, (span, builder) => builder. + setSerializedId("inc" + span). + setSymbol("+1"). + setTitle("Increment Gate"). + setBlurb("Adds 1 to the little-endian number represented by a block of qubits."). + setActualEffectToShaderProvider(ctx => offsetShader.withArgs( + ...ketArgs(ctx, span), + WglArg.float("amount", +1))). + setKnownEffectToPermutation(t => (t + 1) & ((1 << span) - 1))); + +IncrementGates.DecrementFamily = Gate.buildFamily(1, 16, (span, builder) => builder. + setSerializedId("dec" + span). + setSymbol("−1"). + setTitle("Decrement Gate"). + setBlurb("Subtracts 1 from the little-endian number represented by a block of qubits."). + setActualEffectToShaderProvider(ctx => offsetShader.withArgs( + ...ketArgs(ctx, span), + WglArg.float("amount", -1))). + setKnownEffectToPermutation(t => (t - 1) & ((1 << span) - 1))); + +IncrementGates.all = [ + ...IncrementGates.IncrementFamily.all, + ...IncrementGates.DecrementFamily.all, +]; + +export {IncrementGates, offsetShader} diff --git a/test/CircuitOperationTestUtil.js b/test/CircuitOperationTestUtil.js index 4428fbe9..d64005b9 100644 --- a/test/CircuitOperationTestUtil.js +++ b/test/CircuitOperationTestUtil.js @@ -58,13 +58,13 @@ function assertThatCircuitShaderActsLikeMatrix(shaderFunc, matrix, repeats=5) { * @param {!function(target : !int,inputA:!int) : !int | * !function(target : !int, inputA : !int, inputB : !int) : !int | * !function(target : !int, inputA : !int, inputB : !int, inputR : !int) : !int} permutationFunc - * @param {!Array.} inputSpans + * @param {!Array.=} inputSpans * @param {!boolean} ignoreTargetEndsUpDisabled */ function assertThatGateActsLikePermutation( gate, permutationFunc, - inputSpans, + inputSpans=[], ignoreTargetEndsUpDisabled=false) { let inputGates = []; for (let [key, inputGate] of [['Input Range A', Gates.InputGates.InputAFamily], @@ -115,7 +115,7 @@ function assertThatGateActsLikePermutation( } let updateAction = ctx => advanceStateWithCircuit(ctx, circuit, false); - _assertThatCircuitMutationActsLikePermutation_single( + assertThatCircuitUpdateActsLikePermutation( wireCount, updateAction, fullPermutation, @@ -188,12 +188,26 @@ function assertThatCircuitMutationActsLikeMatrix_single(updateAction, matrix) { } /** - * @param {!int} wireCount - * @param {!function(!CircuitEvalContext)} updateAction - * @param {!function(!int) : !int} permutation - * @param {*} permuteInfo + * @param {!int} wireCount The number of wires in the circuit. + * @param {!function(!CircuitEvalContext) : !WglConfiguredShader} shaderMaker Makes the shader to apply. + * @param {!function(!int) : !int} permutation The expected permutation. + * @param {*} permuteInfo Debug info included when the assertion fails. */ -function _assertThatCircuitMutationActsLikePermutation_single(wireCount, updateAction, permutation, permuteInfo) { +function assertThatCircuitShaderActsLikePermutation(wireCount, shaderMaker, permutation, permuteInfo=undefined) { + assertThatCircuitUpdateActsLikePermutation( + wireCount, + ctx => ctx.applyOperation(shaderMaker(ctx)), + permutation, + permuteInfo) +} + +/** + * @param {!int} wireCount The number of wires in the circuit. + * @param {!function(!CircuitEvalContext) : void} updateAction The actual update action. + * @param {!function(!int) : !int} permutation The expected permutation. + * @param {*} permuteInfo Debug info included when the assertion fails. + */ +function assertThatCircuitUpdateActsLikePermutation(wireCount, updateAction, permutation, permuteInfo=undefined) { let time = Math.random(); let ampCount = 1 << wireCount; @@ -236,5 +250,7 @@ export { assertThatCircuitUpdateActsLikeMatrix, assertThatCircuitShaderActsLikeMatrix, assertThatGateActsLikePermutation, - assertThatCircuitOutputsBasisKet + assertThatCircuitOutputsBasisKet, + assertThatCircuitUpdateActsLikePermutation, + assertThatCircuitShaderActsLikePermutation, } diff --git a/test/circuit/CircuitDefinition.test.js b/test/circuit/CircuitDefinition.test.js index 091ad5e8..b5614f2f 100644 --- a/test/circuit/CircuitDefinition.test.js +++ b/test/circuit/CircuitDefinition.test.js @@ -51,8 +51,8 @@ const TEST_GATES = new Map([ ['#', new GateBuilder().setKnownEffectToMatrix(Matrix.zero(4, 4)).setWidth(2).setHeight(2).gate], ['~', new GateBuilder().setKnownEffectToMatrix(Matrix.zero(2, 2)).setWidth(3).gate], - ['2', Gates.Arithmetic.IncrementFamily.ofSize(2)], - ['3', Gates.Arithmetic.IncrementFamily.ofSize(3)], + ['2', Gates.IncrementGates.IncrementFamily.ofSize(2)], + ['3', Gates.IncrementGates.IncrementFamily.ofSize(3)], ['Q', new GateBuilder(). setKnownEffectToMatrix(Matrix.square(1, 1, 1, 1, 1, Complex.I, -1, Complex.I.neg(), diff --git a/test/gates/ArithmeticGates.test.js b/test/gates/ArithmeticGates.test.js index e1bb7c87..d1d1758b 100644 --- a/test/gates/ArithmeticGates.test.js +++ b/test/gates/ArithmeticGates.test.js @@ -1,31 +1,18 @@ import {Suite} from "test/TestUtil.js" -import {offsetShader, ArithmeticGates} from "src/gates/ArithmeticGates.js" +import {ArithmeticGates} from "src/gates/ArithmeticGates.js" import {InputGates} from "src/gates/InputGates.js" import { - assertThatCircuitShaderActsLikeMatrix, assertThatCircuitUpdateActsLikeMatrix, - assertThatGateActsLikePermutation + assertThatGateActsLikePermutation, } from "test/CircuitOperationTestUtil.js" import {advanceStateWithCircuit} from "src/circuit/CircuitComputeUtil.js" import {CircuitDefinition} from "src/circuit/CircuitDefinition.js" import {GateColumn} from "src/circuit/GateColumn.js" import {Matrix} from "src/math/Matrix.js" -import {ketArgs} from "src/circuit/KetShaderUtil.js" -import {WglArg} from "src/webgl/WglArg.js" let suite = new Suite("ArithmeticGates"); -suite.testUsingWebGL('increment', () => { - assertThatCircuitShaderActsLikeMatrix( - ctx => offsetShader.withArgs(...ketArgs(ctx, 3), WglArg.float("amount", 5)), - Matrix.generateTransition(8, e => (e+5)&7)); - - assertThatCircuitShaderActsLikeMatrix( - ctx => offsetShader.withArgs(...ketArgs(ctx, 2), WglArg.float("amount", -3)), - Matrix.generateTransition(4, e => (e-3)&3)); -}); - suite.testUsingWebGL('plus_A', () => { assertThatCircuitUpdateActsLikeMatrix( ctx => advanceStateWithCircuit( diff --git a/test/gates/IncrementGates.test.js b/test/gates/IncrementGates.test.js new file mode 100644 index 00000000..dc9fbd15 --- /dev/null +++ b/test/gates/IncrementGates.test.js @@ -0,0 +1,33 @@ +import {Suite} from "test/TestUtil.js" +import {offsetShader, IncrementGates} from "src/gates/IncrementGates.js" +import { + assertThatCircuitShaderActsLikePermutation, + assertThatGateActsLikePermutation, +} from "test/CircuitOperationTestUtil.js" + +import {ketArgs} from "src/circuit/KetShaderUtil.js" +import {WglArg} from "src/webgl/WglArg.js" + +let suite = new Suite("ArithmeticGates"); + +suite.testUsingWebGL('offsetShader', () => { + assertThatCircuitShaderActsLikePermutation( + 3, + ctx => offsetShader.withArgs(...ketArgs(ctx, 3), WglArg.float("amount", 5)), + e => (e+5) & 7); + + assertThatCircuitShaderActsLikePermutation( + 6, + ctx => offsetShader.withArgs(...ketArgs(ctx, 6), WglArg.float("amount", -31)), + e => (e-31) & 63); +}); + +suite.testUsingWebGL('IncrementGate', () => { + assertThatGateActsLikePermutation( + IncrementGates.IncrementFamily.ofSize(3), + e => (e + 1) & 7); + + assertThatGateActsLikePermutation( + IncrementGates.DecrementFamily.ofSize(4), + e => (e - 1) & 15); +}); From af4ab4e92a7bb83b052403b327dc7707baa34c48 Mon Sep 17 00:00:00 2001 From: Craig Gidney Date: Thu, 6 Jul 2017 22:44:00 -0700 Subject: [PATCH 04/28] Change square-accumulate gate symbols from -=/+= to -/+ --- src/gates/MultiplyAccumulateGates.js | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/gates/MultiplyAccumulateGates.js b/src/gates/MultiplyAccumulateGates.js index ab55c7c9..cf8683ee 100644 --- a/src/gates/MultiplyAccumulateGates.js +++ b/src/gates/MultiplyAccumulateGates.js @@ -111,7 +111,7 @@ MultiplyAccumulateGates.MultiplySubtractInputsFamily = Gate.buildFamily(1, 16, ( MultiplyAccumulateGates.SquareAddInputFamily = Gate.buildFamily(1, 16, (span, builder) => builder. setSerializedId("+=AA" + span). - setSymbol("+=A^2"). + setSymbol("+A^2"). setTitle("Square-Add Gate [Input A]"). setBlurb("Adds the square of input A into the qubits covered by this gate."). setRequiredContextKeys('Input Range A'). @@ -122,7 +122,7 @@ MultiplyAccumulateGates.SquareAddInputFamily = Gate.buildFamily(1, 16, (span, bu MultiplyAccumulateGates.SquareSubtractInputFamily = Gate.buildFamily(1, 16, (span, builder) => builder. setSerializedId("-=AA" + span). - setSymbol("-=A^2"). + setSymbol("-A^2"). setTitle("Square-Subtract Gate [Input A]"). setBlurb("Subtracts the square of input A out of the qubits covered by this gate."). setRequiredContextKeys('Input Range A'). From 626d869a1ebc845ab816918011cb3db34f41b656 Mon Sep 17 00:00:00 2001 From: Craig Gidney Date: Thu, 6 Jul 2017 23:10:40 -0700 Subject: [PATCH 05/28] Center circuit symbol better when painting custom gate --- src/ui/DisplayedCircuit.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/ui/DisplayedCircuit.js b/src/ui/DisplayedCircuit.js index 11329d8b..43a6f6e2 100644 --- a/src/ui/DisplayedCircuit.js +++ b/src/ui/DisplayedCircuit.js @@ -117,7 +117,7 @@ class DisplayedCircuit { */ desiredWidth(forTooltip=false) { if (forTooltip) { - return this.gateRect(1, this.circuitDefinition.columns.length).x + CIRCUIT_OP_LEFT_SPACING; + return this.opRect(this.circuitDefinition.columns.length - 1).right() + CIRCUIT_OP_LEFT_SPACING; } return this._rectForSuperpositionDisplay().right() + 101; } From d710ae05b786549874dc67ee0eb88830886ee37d Mon Sep 17 00:00:00 2001 From: Craig Gidney Date: Thu, 6 Jul 2017 23:13:18 -0700 Subject: [PATCH 06/28] Update multiplication gate tooltips to note that irreversibiltiy is caused by even-ness --- src/gates/MultiplicationGates.js | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/gates/MultiplicationGates.js b/src/gates/MultiplicationGates.js index d01b64bd..2b758676 100644 --- a/src/gates/MultiplicationGates.js +++ b/src/gates/MultiplicationGates.js @@ -42,7 +42,7 @@ MultiplicationGates.TimesAFamily = Gate.buildFamily(1, 16, (span, builder) => bu setSymbol("×A"). setTitle("Multiplication Gate"). setBlurb("Multiplies the target by input A.\n" + - "No effect if the multiplication would be irreversible."). + "No effect if the input is even (would be irreversible)."). setRequiredContextKeys("Input Range A"). setActualEffectToShaderProvider(ctx => MULTIPLICATION_SHADER.withArgs(...ketArgs(ctx, span, ['A']))). setKnownEffectToParametrizedPermutation((x, a) => modularMultiply(x, a, 1< modularUnmultiply(x, a, 1< INVERSE_MULTIPLICATION_SHADER.withArgs(...ketArgs(ctx, span, ['A'])))); From 0ffc9e4a47a99b4825a9e23f6e65e0785f8a49e2 Mon Sep 17 00:00:00 2001 From: Craig Gidney Date: Thu, 6 Jul 2017 23:20:51 -0700 Subject: [PATCH 07/28] Fix middle-click being blocked by resize-tab --- src/main.js | 2 +- src/ui/DisplayedCircuit.js | 15 +++++++++++++-- src/ui/DisplayedInspector.js | 5 +++-- 3 files changed, 17 insertions(+), 5 deletions(-) diff --git a/src/main.js b/src/main.js index 099b744c..1b8bac24 100644 --- a/src/main.js +++ b/src/main.js @@ -233,7 +233,7 @@ canvasDiv.addEventListener('mousedown', ev => { let newHand = displayed.get().hand.withPos(eventPosRelativeTo(ev, canvas)); let newInspector = syncArea(displayed.get()). withHand(newHand). - afterGrabbing(false, false). // Grab the gate. + afterGrabbing(false, false, true). // Grab the gate. withHand(newHand). // Lose the gate. afterTidyingUp(). withJustEnoughWires(newHand, 0); diff --git a/src/ui/DisplayedCircuit.js b/src/ui/DisplayedCircuit.js index 43a6f6e2..f4f86741 100644 --- a/src/ui/DisplayedCircuit.js +++ b/src/ui/DisplayedCircuit.js @@ -934,13 +934,24 @@ class DisplayedCircuit { * @param {!Hand} hand * @param {!boolean=false} duplicate * @param {!boolean=false} wholeColumn + * @param {!boolean=false} ignoreResizeTabs * @returns {!{newCircuit: !DisplayedCircuit, newHand: !Hand}} */ - tryGrab(hand, duplicate=false, wholeColumn=false) { + tryGrab(hand, duplicate=false, wholeColumn=false, ignoreResizeTabs=false) { if (wholeColumn) { return this._tryGrabWholeColumn(hand, duplicate) || {newCircuit: this, newHand: hand}; } - let {newCircuit, newHand} = this._tryGrabResizeTab(hand) || {newCircuit: this, newHand: hand}; + + let newHand = hand; + let newCircuit = this; + if (!ignoreResizeTabs) { + let resizing = this._tryGrabResizeTab(hand); + if (resizing !== undefined) { + newHand = resizing.newHand; + newCircuit = resizing.newCircuit; + } + } + return newCircuit._tryGrabGate(newHand, duplicate) || {newCircuit, newHand}; } diff --git a/src/ui/DisplayedInspector.js b/src/ui/DisplayedInspector.js index 1a50cffe..8c428447 100644 --- a/src/ui/DisplayedInspector.js +++ b/src/ui/DisplayedInspector.js @@ -132,15 +132,16 @@ class DisplayedInspector { /** * @param {!boolean=false} duplicate * @param {!boolean=false} wholeCol + * @param {!boolean=false} ignoreResizeTabs * @returns {!DisplayedInspector} */ - afterGrabbing(duplicate=false, wholeCol=false) { + afterGrabbing(duplicate=false, wholeCol=false, ignoreResizeTabs=false) { let hand = this.hand; let circuit = this.displayedCircuit; hand = this.displayedToolboxTop.tryGrab(hand); hand = this.displayedToolboxBottom.tryGrab(hand); - let obj = circuit.tryGrab(hand, duplicate, wholeCol); + let obj = circuit.tryGrab(hand, duplicate, wholeCol, ignoreResizeTabs); hand = obj.newHand; circuit = obj.newCircuit; From 125c1cfe3af285ba2cab2defbae808833a9006d7 Mon Sep 17 00:00:00 2001 From: Craig Gidney Date: Thu, 6 Jul 2017 23:21:54 -0700 Subject: [PATCH 08/28] Remove unused "" from html --- html/quirk.template.html | 2 -- 1 file changed, 2 deletions(-) diff --git a/html/quirk.template.html b/html/quirk.template.html index e9fa7c5f..1a34732d 100644 --- a/html/quirk.template.html +++ b/html/quirk.template.html @@ -12,8 +12,6 @@ - -