UI: Fixed issue with drawing vertical lines

This commit is contained in:
dsavvinov
2016-08-26 15:56:22 +03:00
parent be7c7f7876
commit 0dd23f638d
2 changed files with 20 additions and 2 deletions
+1 -1
View File
@@ -56,7 +56,7 @@ object RoomModel {
val alg = DebugClInterface.algorithmImpl
val car = if (alg == null) Car(0, "", 0) else alg.thisCar
val mult = 1000000
val mult = 100
linesModel.forEachIndexed { idx, line ->
aRef[idx] = (line.A * mult).toInt()
bRef[idx] = (line.B * mult).toInt()
+19 -1
View File
@@ -10,7 +10,7 @@ var canvas = $( "#pathCanvas" )[0],
carColour = "red",
referenceColour = "green",
foundColour = "blue",
multiplier = 1e6;
multiplier = 100;
canvas.style = "border:5px solid #000000;";
@@ -41,6 +41,16 @@ function drawLine(line) {
var end_x = canvas.width;
var end_y = (line.A * (canvas.width - zero.x) + line.C) / line.B + zero.y;
// check if evaluated y-coordinates are in the canvas. If not, re-evaluate x-coordinates from y, to prevent issues with lines that are close to vertical
if (gt(begin_y, canvas.height) || gt(end_y, canvas.height)) {
begin_x = (line.B * (0 - zero.y) + line.C) / line.A + zero.x;
begin_y = 0;
end_x = (line.B * (canvas.height - zero.y) + line.C) / line.A + zero.x;
end_y = canvas.height;
}
console.log("Drawing line from (" + begin_x + ", " + begin_y + ") to (" + end_x + ", " + end_y + ")");
ctx.beginPath();
ctx.moveTo(begin_x, begin_y);
ctx.lineTo(end_x, end_y);
@@ -63,6 +73,14 @@ function eq(lhs, rhs) {
return Math.abs(lhs - rhs) < eps;
}
function lt(lhs, rhs) {
return lhs - rhs < -eps;
}
function gt(lhs, rhs) {
return lhs - rhs > eps;
}
function intersectLines(l1, l2) {
// Kramer's dets
var delta1 = l1.A * l2.B - l1.B * l2.A;