mirror of
https://github.com/aziis98/ro-vis.git
synced 2026-10-20 04:42:19 +00:00
fix: some rendering bugs with negative values
This commit is contained in:
@@ -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()
|
||||
|
||||
+2
-1
@@ -26,4 +26,5 @@ export const rowVectorToLatex = (vector: Vector<Rational>) =>
|
||||
.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'
|
||||
|
||||
@@ -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))
|
||||
|
||||
Reference in New Issue
Block a user