# Line

#####

declaration
Line

The line implementation of MathLib makes calculations with lines in the
real plane possible. (Higher dimensions will be supported later)

    var Line = (function (_super) {
    __extends(Line, _super);
    function Line(coords) {
        _super.call(this, coords);
        this.type = 'line';
        this.dimension = 2;
    }

# draw

#####

method
Line.prototype.draw() → boolean

Option name | Type | Description
--- | --- | ---
screen | Screen | The screen to draw onto.
options | object | Drawing options

Draws the line on one or more screens

    Line.prototype.draw = function (screen, options) {
        if (Array.isArray(screen)) {
            var line = this;
            screen.forEach(function (x) {
                x.line(line, options);
            });
        } else {
            screen.line(this, options);
        }
        return this;
    };

# isEqual

#####

method
Line.prototype.isEqual() → boolean

Option name | Type | Description
--- | --- | ---
l | Line | The line to compare with

Determines if two lines are equal.

    Line.prototype.isEqual = function (l) {
        var p = this.normalize();
        l = l.normalize();

        if (this.length !== l.length) {
            return false;
        }

        return p.every(function (x, i) {
            return MathLib.isEqual(x, l[i]);
        });
    };

# isFinite

#####

method
Line.prototype.isFinite() → boolean

Determines if the line is finite

    Line.prototype.isFinite = function () {
        return !MathLib.isZero(this[0]) || !MathLib.isZero(this[1]);
    };

# isParallelTo

#####

method
Line.prototype.isParallelTo() → boolean

Option name | Type | Description
--- | --- | ---
l | Line | The other line

Determines if two lines are parallel.

    Line.prototype.isParallelTo = function (l) {
        return MathLib.isZero(this[0] * l[1] - this[1] * l[0]);
    };

# meet

#####

method
Line.prototype.meet() → Point

Option name | Type | Description
--- | --- | ---
l | Line | The line to intersect the current line with

Calculates the meeting point of two lines

    Line.prototype.meet = function (l) {
        var point, k = this;

        if (this.dimension === 2 && l.dimension === 2) {
            point = new MathLib.Point(this.vectorProduct(l).toArray());

            Object.defineProperties(point, {
                '0': {
                    get: function () {
                        return k[1] * l[2] - k[2] * l[1];
                    },
                    set: function () {
                        MathLib.warning({ message: 'Trying to change the coordinates of a completely dependent point.', method: 'Line#meet' });
                    },
                    enumerable: true
                },
                '1': {
                    get: function () {
                        return k[2] * l[0] - k[0] * l[2];
                    },
                    set: function () {
                        MathLib.warning({ message: 'Trying to change the coordinates of a completely dependent point.', method: 'Line#meet' });
                    },
                    enumerable: true
                },
                '2': {
                    get: function () {
                        return k[0] * l[1] - k[1] * l[0];
                    },
                    set: function () {
                        MathLib.warning({ message: 'Trying to change the coordinates of a completely dependent point.', method: 'Line#meet' });
                    },
                    enumerable: true
                }
            });

            return point;
        }
    };

# normalize

#####

method
Line.prototype.normalize() → Line

Normalizes the line.

    Line.prototype.normalize = function () {
        var h = MathLib.hypot(this[0], this[1]);

        if (h !== 0) {
            return this.map(function (x) {
                return x / h;
            });
        } else {
            return new MathLib.Line([0, 0, 1]);
        }
    };

# parallelThrough

#####

method
Line.prototype.parallelThrough() → Line

Option name | Type | Description
--- | --- | ---
p | Point | The Point through which the line should go through

Determines an parallel line through a given point.

    Line.prototype.parallelThrough = function (p) {
        var l = this, parallel = new MathLib.Line([0, 0, 0]);

        Object.defineProperties(parallel, {
            '0': {
                get: function () {
                    return -l[0] * p[2];
                },
                set: function () {
                    MathLib.warning({ message: 'Trying to change the coordinates of a completely dependent line.', method: 'Line#parallelThrough' });
                },
                enumerable: true
            },
            '1': {
                get: function () {
                    return -l[1] * p[2];
                },
                set: function () {
                    MathLib.warning({ message: 'Trying to change the coordinates of a completely dependent line.', method: 'Line#parallelThrough' });
                },
                enumerable: true
            },
            '2': {
                get: function () {
                    return l[1] * p[1] + l[0] * p[0];
                },
                set: function () {
                    MathLib.warning({ message: 'Trying to change the coordinates of a completely dependent line.', method: 'Line#parallelThrough' });
                },
                enumerable: true
            }
        });

        return parallel;
    };
    return Line;
        })(MathLib.Vector);
        MathLib.Line = Line;
    })(MathLib || (MathLib = {}));