import {add, subtract, dot, length, scale, unit, rotate, limit, angle, intersect} from './vector2'

class Pipe {
    set (v) {
        this.v = v
        return this
    }

    val () { return this.v }

    add (v) {
        this.v = add(this.v, v)
        return this
    }

    subtract (v) {
        this.v = subtract(this.v, v)
        return this
    }

    dot (v) {
        this.v = dot(this.v, v)
        return this
    }

    length () {
        return length(this.v)
    }

    scale (l) {
        this.v = scale(this.v, l)
        return this
    }

    unit () {
        this.v = scale(this.v, 1 / length(this.v))
        return this
    }

    rotate (angle) {
        this.v = rotate(this.v, angle)
        return this
    }

    limit (max) {
        this.v = limit(this.v, max)
        return this
    }

    angle () {
        return angle(this.v)
    }

    intersect (v1, v2, v3) {
        return intersect(this.v, v1, v2, v3)
    }

}

const instance = new Pipe()

const vector = v => instance.set(v)

export default vector