diff --git a/src/lib-v2/canvas/index.ts b/src/lib-v2/canvas/index.ts index 1500930..7faa551 100644 --- a/src/lib-v2/canvas/index.ts +++ b/src/lib-v2/canvas/index.ts @@ -38,6 +38,8 @@ export function drawSemiplane( p2 = b / a2 } + console.log('a1', a1, 'a2', a2) + const normalize = Math.sqrt(a1 ** 2 + a2 ** 2) / gradientSize const gradient = g.createLinearGradient(p1, p2, p1 - a1 / normalize, p2 - a2 / normalize) @@ -62,15 +64,33 @@ export function drawSemiplane( } } else { if (a2 > 0) { - g.moveTo(-MAX_LINE_SIZE, (b - a1 * -MAX_LINE_SIZE) / a2) - g.lineTo(-MAX_LINE_SIZE, MAX_LINE_SIZE) - g.lineTo(-MAX_LINE_SIZE, -MAX_LINE_SIZE) - g.lineTo(MAX_LINE_SIZE, (b - a1 * MAX_LINE_SIZE) / a2) + if (a1 >= 0) { + g.moveTo(-MAX_LINE_SIZE, (b - a1 * -MAX_LINE_SIZE) / a2) + g.lineTo(-MAX_LINE_SIZE, MAX_LINE_SIZE) + g.lineTo(-MAX_LINE_SIZE, -MAX_LINE_SIZE) + g.lineTo(MAX_LINE_SIZE, (b - a1 * MAX_LINE_SIZE) / a2) + } else { + g.moveTo(-MAX_LINE_SIZE, (b - a1 * -MAX_LINE_SIZE) / a2) + g.lineTo(-MAX_LINE_SIZE, -MAX_LINE_SIZE) + g.lineTo(MAX_LINE_SIZE, -MAX_LINE_SIZE) + g.lineTo(MAX_LINE_SIZE, (b - a1 * MAX_LINE_SIZE) / a2) + } } else { - g.moveTo(MAX_LINE_SIZE, (b - a1 * MAX_LINE_SIZE) / a2) - g.lineTo(MAX_LINE_SIZE, -MAX_LINE_SIZE) - g.lineTo(MAX_LINE_SIZE, MAX_LINE_SIZE) - g.lineTo(-MAX_LINE_SIZE, (b - a1 * -MAX_LINE_SIZE) / a2) + // g.moveTo(MAX_LINE_SIZE, (b - a1 * MAX_LINE_SIZE) / a2) + // g.lineTo(MAX_LINE_SIZE, -MAX_LINE_SIZE) + // g.lineTo(MAX_LINE_SIZE, MAX_LINE_SIZE) + // g.lineTo(-MAX_LINE_SIZE, (b - a1 * -MAX_LINE_SIZE) / a2) + if (a1 >= 0) { + g.moveTo(-MAX_LINE_SIZE, (b - a1 * -MAX_LINE_SIZE) / a2) + g.lineTo(-MAX_LINE_SIZE, -MAX_LINE_SIZE) + g.lineTo(-MAX_LINE_SIZE, MAX_LINE_SIZE) + g.lineTo(MAX_LINE_SIZE, (b - a1 * MAX_LINE_SIZE) / a2) + } else { + g.moveTo(-MAX_LINE_SIZE, (b - a1 * -MAX_LINE_SIZE) / a2) + g.lineTo(-MAX_LINE_SIZE, MAX_LINE_SIZE) + g.lineTo(MAX_LINE_SIZE, MAX_LINE_SIZE) + g.lineTo(MAX_LINE_SIZE, (b - a1 * MAX_LINE_SIZE) / a2) + } } } g.fill() diff --git a/src/lib-v2/latex.ts b/src/lib-v2/latex.ts index e433708..86c5fd2 100644 --- a/src/lib-v2/latex.ts +++ b/src/lib-v2/latex.ts @@ -26,4 +26,5 @@ export const rowVectorToLatex = (vector: Vector) => .join(' & ')} \\end{bmatrix}` : '' -export const indexSetToLatex = (indices: number[]) => `\\{${indices.map(i => (i + 1).toString()).join(', ')}\\}` +export const indexSetToLatex = (indices: number[]) => + indices.length > 0 ? `\\{${indices.map(i => (i + 1).toString()).join(', ')}\\}` : '\\varnothing' diff --git a/src/lib-v2/ro/primal-simplex.ts b/src/lib-v2/ro/primal-simplex.ts index d0f5084..b836e1f 100644 --- a/src/lib-v2/ro/primal-simplex.ts +++ b/src/lib-v2/ro/primal-simplex.ts @@ -179,14 +179,16 @@ export function computePrimalSimplexSteps(input: ProblemInput): ProblemOutput { content: `N = \\{1, \\dots, ${A.rows}\\} \\setminus B = ${indexSetToLatex(N)}`, }) - comments.push({ - type: 'formula', - content: [ - `A_N \\xi`, - `${matrixToLatex(A_N)} ${vectorToLatex(xi)}`, - `${vectorToLatex(A_N__xi)}`, - ].join(' = '), - }) + if (N.length > 0) { + comments.push({ + type: 'formula', + content: [ + `A_N \\xi`, + `${matrixToLatex(A_N)} ${vectorToLatex(xi)}`, + `${vectorToLatex(A_N__xi)}`, + ].join(' = '), + }) + } if (!A_N__xi.getData().every(x => x.leq(RationalField.zero))) { const [k, lambda] = N.filter(i => A_N__xi.at(A_N.forwardRowIndices[i]).gt(RationalField.zero))