解决没有考虑 gcd 导致跳转异常的问题

This commit is contained in:
锦恢 2024-09-11 12:59:05 +08:00
parent de7600a578
commit 802f95ab0a
6 changed files with 18 additions and 12 deletions

View File

@ -17,7 +17,7 @@
<script> <script>
window.readVcdFile = async () => { window.readVcdFile = async () => {
const response = await fetch('test.vcd'); const response = await fetch('FFT_IFFT.vcd');
const blob = await response.blob(); const blob = await response.blob();
const reader = new FileReader(); const reader = new FileReader();
return new Promise((resolve, reject) => { return new Promise((resolve, reject) => {

Binary file not shown.

View File

@ -51,8 +51,6 @@ defineComponent({ name: 'main-render' });
function onMousedown() { function onMousedown() {
updateWireCurrentValue(); updateWireCurrentValue();
changeCursorLocation(); changeCursorLocation();
console.log(MovingPivot);
// //
for (const id of UserPivotCtxShows.keys()) { for (const id of UserPivotCtxShows.keys()) {

View File

@ -46,8 +46,9 @@ export function toBegin() {
export function toEnd() { export function toEnd() {
const pstate = globalLookup.pstate; const pstate = globalLookup.pstate;
const gcd = globalLookup.tgcd || 1;
if (pstate) { if (pstate) {
moveto(globalLookup.time, pstate.width - pstate.sidebarWidth, pstate); moveto(globalLookup.time * gcd, pstate.width - pstate.sidebarWidth, pstate);
} }
} }
@ -64,6 +65,7 @@ function clip(v, min, max) {
export function toPrevChange() { export function toPrevChange() {
const link = sidebarSelectedWires.lastLink; const link = sidebarSelectedWires.lastLink;
const pstate = globalLookup.pstate; const pstate = globalLookup.pstate;
const gcd = globalLookup.tgcd || 1;
if (link === undefined || pstate === undefined) { if (link === undefined || pstate === undefined) {
return; return;
@ -81,13 +83,15 @@ export function toPrevChange() {
let pivot = bisearch(wave, currentT); let pivot = bisearch(wave, currentT);
const pwave = wave[pivot]; const pwave = wave[pivot];
if (pwave[0] === currentT) { if (pwave[0] * gcd === currentT) {
pivot = clip(pivot - 1, 0, wave.length - 1); pivot = clip(pivot - 1, 0, wave.length - 1);
} else { } else {
pivot = clip(pivot, 0, wave.length - 1); pivot = clip(pivot, 0, wave.length - 1);
} }
console.log(pivot, wave.length);
const targetT = wave[pivot][0]; const targetT = wave[pivot][0] * gcd;
moveto(targetT, (pstate.width + pstate.sidebarWidth) / 2, pstate); moveto(targetT, (pstate.width + pstate.sidebarWidth) / 2, pstate);
} }
} }
@ -97,12 +101,13 @@ export function toPrevChange() {
export function toNextChange() { export function toNextChange() {
const link = sidebarSelectedWires.lastLink; const link = sidebarSelectedWires.lastLink;
const pstate = globalLookup.pstate; const pstate = globalLookup.pstate;
const gcd = globalLookup.tgcd || 1;
if (link === undefined || pstate === undefined) { if (link === undefined || pstate === undefined) {
return; return;
} }
const chango = globalLookup.chango[link]; const chango = globalLookup.chango[link];
if (chango && chango.wave && chango.wave.length > 0) { if (chango && chango.wave && chango.wave.length > 0) {
const wave = chango.wave; const wave = chango.wave;
@ -115,10 +120,10 @@ export function toNextChange() {
let targetT; let targetT;
if (pivot === wave.length - 1) { if (pivot === wave.length - 1) {
pivot = clip(pivot + 1, 0, wave.length - 1); pivot = clip(pivot + 1, 0, wave.length - 1);
targetT = globalLookup.time; targetT = globalLookup.time * gcd;
} else { } else {
pivot = clip(pivot + 1, 0, wave.length - 1); pivot = clip(pivot + 1, 0, wave.length - 1);
targetT = wave[pivot][0]; targetT = wave[pivot][0] * gcd;
} }
moveto(targetT, (pstate.width + pstate.sidebarWidth) / 2, pstate); moveto(targetT, (pstate.width + pstate.sidebarWidth) / 2, pstate);
@ -157,7 +162,10 @@ export function clearAllPivot() {
* @return {number} * @return {number}
*/ */
export function bisearch(wave, time) { export function bisearch(wave, time) {
const gcd = globalLookup.tgcd || 1;
const times = wave.map(p => p[0]); const times = wave.map(p => p[0]);
time = time / gcd;
// 二分查找,并将结果存入 i // 二分查找,并将结果存入 i
let i = 0, j = wave.length - 1; let i = 0, j = wave.length - 1;

View File

@ -166,6 +166,9 @@ async function updateWireCurrentValue(time) {
if (time === undefined) { if (time === undefined) {
time = globalLookup.currentTime; time = globalLookup.currentTime;
} }
const gcd = globalLookup.tgcd || 1;
time = time / gcd;
const currentSignalValues = globalLookup.currentSignalValues; const currentSignalValues = globalLookup.currentSignalValues;

View File

@ -498,12 +498,9 @@ class WebGL2WaveRender {
if (signal.size === 1) { if (signal.size === 1) {
// 如果是 bit // 如果是 bit
gl.uniform2fv(webglLocation.widthShifts, gl_WidthShifts); gl.uniform2fv(webglLocation.widthShifts, gl_WidthShifts);
gl.uniform2fv(webglLocation.shifts, gl_Shifts); gl.uniform2fv(webglLocation.shifts, gl_Shifts);
gl.bindVertexArray(signalItem.lineVao); gl.bindVertexArray(signalItem.lineVao);
gl.drawArrays(gl.TRIANGLE_STRIP, 0, lineVertices.length / glslInputLength); gl.drawArrays(gl.TRIANGLE_STRIP, 0, lineVertices.length / glslInputLength);
gl.bindVertexArray(signalItem.maskVao); gl.bindVertexArray(signalItem.maskVao);
gl.drawArrays(gl.TRIANGLES, 0, maskVertices.length / glslInputLength); gl.drawArrays(gl.TRIANGLES, 0, maskVertices.length / glslInputLength);
} else { } else {