Skip to content

Commit c987a99

Browse files
committed
Fixed bugs
1 parent 4d5fa30 commit c987a99

2 files changed

Lines changed: 41 additions & 63 deletions

File tree

docs/js/class_p.js

Lines changed: 7 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -704,30 +704,13 @@ class Puzzle {
704704
let vertex = point[cell.surround[j]];
705705
let min = Number.MAX_VALUE;
706706
let corner = 0;
707-
if (Math.abs(vertex.x - cell.x) < 0.001) {
708-
for (let k = 0; k < corners.length; k++) {
709-
if (Math.abs(point[corners[k]].x - vertex.x) < 0.001) {
710-
if (vertex.y > point[corners[k]].y === point[corners[k]].y > cell.y) {
711-
corner = corners[k];
712-
}
713-
}
714-
}
715-
} else if (Math.abs(vertex.y - cell.y) < 0.001) {
716-
for (let k = 0; k < corners.length; k++) {
717-
if (Math.abs(point[corners[k]].y - vertex.y) < 0.001) {
718-
if (vertex.x > point[corners[k]].x === point[corners[k]].x > cell.x) {
719-
corner = corners[k];
720-
}
721-
}
722-
}
723-
} else {
724-
for (let k = 0; k < corners.length; k++) {
725-
let diff = Math.abs(((vertex.y - point[corners[k]].y)*(cell.x - point[corners[k]].x)) -
726-
((vertex.x - point[corners[k]].x)*(cell.y - point[corners[k]].y)));
727-
if (min > diff && (vertex.x > point[corners[k]].x === point[corners[k]].x > cell.x) && (vertex.y > point[corners[k]].y === point[corners[k]].y > cell.y)) {
728-
min = diff;
729-
corner = corners[k];
730-
}
707+
for (let k = 0; k < corners.length; k++) {
708+
let corner_point = point[corners[k]];
709+
let diff = Math.abs((cell.y - vertex.y)*corner_point.x - (cell.x - vertex.x)*corner_point.y + (cell.x * vertex.y) - (cell.y * vertex.x)) /
710+
Math.sqrt((cell.y - vertex.y)**2 + (cell.x - vertex.x)**2);
711+
if ((min > diff) && (cell.x > point[corners[k]].x === point[corners[k]].x > vertex.x) && (cell.y > point[corners[k]].y === point[corners[k]].y > vertex.y)) {
712+
min = diff;
713+
corner = corners[k];
731714
}
732715
}
733716
if (corner !== 0) {

docs/js/class_uniform.js

Lines changed: 34 additions & 39 deletions
Original file line numberDiff line numberDiff line change
@@ -4907,7 +4907,6 @@ class Puzzle_iso extends Puzzle_truncated_square {
49074907
}
49084908
}
49094909
}
4910-
[point, k] = this.create_corners(point, 0.25, k);
49114910
// 重複判定
49124911
var renumber = new Array(point.length);
49134912
for (var i = 0; i < point.length; i++) {
@@ -5029,7 +5028,9 @@ class Puzzle_iso extends Puzzle_truncated_square {
50295028
}
50305029
}
50315030
}
5032-
this.point = this.point_connect_corners(this.point_fillin_corners(this.fix_points(point)));
5031+
point = this.fix_points(point);
5032+
5033+
this.point = this.point_connect_corners(this.create_corners(point, 0.25, point.length + 1)[0]);
50335034
}
50345035

50355036
reset_frame() {
@@ -5356,54 +5357,48 @@ class Puzzle_iso extends Puzzle_truncated_square {
53565357
if (this.point[i2].neighbor.indexOf(this.point[i1].neighbor[j]) !== -1) {
53575358
i3 = this.point[i1].neighbor[j];
53585359
}
5359-
this.ctx.beginPath();
5360-
if (this[pu].line[i] === 40) {
5361-
var r = 0.6;
5362-
var x1 = r * this.point[i1].x + (1 - r) * this.point[i3].x;
5363-
var y1 = r * this.point[i1].y + (1 - r) * this.point[i3].y;
5364-
var x2 = (1 - r) * this.point[i3].x + r * this.point[i2].x;
5365-
var y2 = (1 - r) * this.point[i3].y + r * this.point[i2].y;
5366-
this.ctx.moveTo(x1, y1);
5367-
this.ctx.lineTo(this.point[i3].x, this.point[i3].y);
5368-
this.ctx.lineTo(x2, y2);
5369-
} else if (this[pu].line[i] === 30) {
5370-
var r = 0.15 * this.size;
5371-
var dx = this.point[i1].x - this.point[i2].x;
5372-
var dy = this.point[i1].y - this.point[i2].y;
5373-
var d = Math.sqrt(dx ** 2 + dy ** 2);
5374-
this.ctx.moveTo(this.point[i1].x - r / d * dy, this.point[i1].y + r / d * dx);
5375-
this.ctx.lineTo(this.point[i2].x - r / d * dy, this.point[i2].y + r / d * dx);
5360+
}
5361+
this.ctx.beginPath();
5362+
if (this[pu].line[i] === 40) {
5363+
var r = 0.6;
5364+
var x1 = r * this.point[i1].x + (1 - r) * this.point[i3].x;
5365+
var y1 = r * this.point[i1].y + (1 - r) * this.point[i3].y;
5366+
var x2 = (1 - r) * this.point[i3].x + r * this.point[i2].x;
5367+
var y2 = (1 - r) * this.point[i3].y + r * this.point[i2].y;
5368+
this.ctx.moveTo(x1, y1);
5369+
this.ctx.lineTo(this.point[i3].x, this.point[i3].y);
5370+
this.ctx.lineTo(x2, y2);
5371+
} else if (this[pu].line[i] === 30) {
5372+
var r = 0.15 * this.size;
5373+
var dx = this.point[i1].x - this.point[i2].x;
5374+
var dy = this.point[i1].y - this.point[i2].y;
5375+
var d = Math.sqrt(dx ** 2 + dy ** 2);
5376+
this.ctx.moveTo(this.point[i1].x - r / d * dy, this.point[i1].y + r / d * dx);
5377+
this.ctx.lineTo(this.point[i2].x - r / d * dy, this.point[i2].y + r / d * dx);
5378+
this.ctx.stroke();
5379+
this.ctx.moveTo(this.point[i1].x + r / d * dy, this.point[i1].y - r / d * dx);
5380+
this.ctx.lineTo(this.point[i2].x + r / d * dy, this.point[i2].y - r / d * dx);
5381+
} else {
5382+
if (this.point[i1].type === 2 || this.point[i1].type === 3) { //for centerline
5383+
this.ctx.moveTo(this.point[i2].x, this.point[i2].y);
5384+
this.ctx.lineTo((this.point[i1].x + this.point[i2].x) * 0.5, (this.point[i1].y + this.point[i2].y) * 0.5);
53765385
this.ctx.stroke();
5377-
this.ctx.moveTo(this.point[i1].x + r / d * dy, this.point[i1].y - r / d * dx);
5378-
this.ctx.lineTo(this.point[i2].x + r / d * dy, this.point[i2].y - r / d * dx);
5379-
} else {
5380-
if (this.point[i1].type === 2 || this.point[i1].type === 3) { //for centerline
5381-
this.ctx.moveTo(this.point[i2].x, this.point[i2].y);
5382-
this.ctx.lineTo((this.point[i1].x + this.point[i2].x) * 0.5, (this.point[i1].y + this.point[i2].y) * 0.5);
5383-
this.ctx.stroke();
5384-
this.ctx.lineCap = "butt";
5385-
} else if (this.point[i2].type === 2 || this.point[i2].type === 3) {
5386-
this.ctx.moveTo(this.point[i1].x, this.point[i1].y);
5387-
this.ctx.lineTo((this.point[i1].x + this.point[i2].x) * 0.5, (this.point[i1].y + this.point[i2].y) * 0.5);
5388-
this.ctx.stroke();
5389-
this.ctx.lineCap = "butt";
5390-
}
5386+
this.ctx.lineCap = "butt";
5387+
} else if (this.point[i2].type === 2 || this.point[i2].type === 3) {
53915388
this.ctx.moveTo(this.point[i1].x, this.point[i1].y);
5392-
this.ctx.lineTo(this.point[i3].x, this.point[i3].y);
5393-
this.ctx.lineTo(this.point[i2].x, this.point[i2].y);
5389+
this.ctx.lineTo((this.point[i1].x + this.point[i2].x) * 0.5, (this.point[i1].y + this.point[i2].y) * 0.5);
5390+
this.ctx.stroke();
5391+
this.ctx.lineCap = "butt";
53945392
}
5395-
this.ctx.stroke();
5396-
} else {
5397-
this.ctx.beginPath();
53985393
this.ctx.moveTo(this.point[i1].x, this.point[i1].y);
53995394

54005395
// If neighbor then break the line at midpoint or else directly draw a line between two ends (freeline)
54015396
if (this.point[i2].adjacent.includes(parseInt(i1))) {
54025397
this.ctx.lineTo(this.point[i3].x, this.point[i3].y);
54035398
}
54045399
this.ctx.lineTo(this.point[i2].x, this.point[i2].y);
5405-
this.ctx.stroke();
54065400
}
5401+
this.ctx.stroke();
54075402
}
54085403
}
54095404
for (var i in this[pu].lineE) {

0 commit comments

Comments
 (0)