Skip to content

Commit 317719e

Browse files
committed
fixed a bug in the Line.project method
1 parent a291329 commit 317719e

File tree

1 file changed

+8
-7
lines changed

1 file changed

+8
-7
lines changed

src_c/line.c

Lines changed: 8 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -220,16 +220,17 @@ _line_project_helper(pgLineBase *line, double *point, int clamp)
220220
dot_product * line_vector[1]};
221221

222222
if (clamp) {
223-
if (projection[0] * projection[0] + projection[1] * projection[1] >
224-
line_vector[0] * line_vector[0] +
225-
line_vector[1] * line_vector[1]) {
226-
projection[0] = line_vector[0];
227-
projection[1] = line_vector[1];
228-
}
229-
else if (dot_product < 0) {
223+
if (dot_product < 0) {
230224
projection[0] = 0;
231225
projection[1] = 0;
232226
}
227+
else if (projection[0] * projection[0] +
228+
projection[1] * projection[1] >
229+
line_vector[0] * line_vector[0] +
230+
line_vector[1] * line_vector[1]) {
231+
projection[0] = line_vector[0];
232+
projection[1] = line_vector[1];
233+
}
233234
}
234235

235236
double projected_point[2] = {line->ax + projection[0],

0 commit comments

Comments
 (0)