juyoung518 - 10 months ago 31

jQuery Question

I am trying to make a code to draw vertical lines.

http://codepen.io/juyoung518/pen/BzAJwg

Chrome error pops up on this paragraph.

Uncaught TypeError: Cannot read property 'x' of undefined

`function getNearestIntersections(line, arr) {`

var index = arr.length - 2;

if (arr[index].x !== line.center.x) {

while (Math.sign(line.center.x - line.a.x) === Math.sign(line.center.x - arr[index].x)) {

index--;

}

} else {

while (Math.sign(line.center.y - line.a.y) === Math.sign(line.center.y - arr[index].y)) {

index--;

}

}

return [arr[arr.length - 1], arr[index]];

}

Please can anyone tell my what the problem is?

This codepen doesn't work at all in IE.

Answer

Did you define "line" properly? Looking at your reference I see:

```
var Line = function(x1, y1, x2, y2) {
this.a = new Vec(x1, y1);
this.b = new Vec(x2, y2);
this.center = new Vec((x1 + x2) / 2, (y1 + y2) / 2);
this.dx = x2 - x1;
this.dy = y2 - y1;
};
```

You do have this (or something similar) somewhere in your code, don't you?