var EdgesManager = {
    edges: [],
    edgesNeedUpdate: false,
    getCubeEdges: function () {
        if (this.edgesNeedUpdate || this.edges.length === 0) {
            return this.resetCubeEdges();
        }
        return this.edges;
    },
    resetCubeEdges: function () {
        this.edges.splice(0, this.edges.length);
        cube.geometry.faces.forEach(face => {
            let a = cube.geometry.vertices[face.a].clone(),
                b = cube.geometry.vertices[face.b].clone(),
                c = cube.geometry.vertices[face.c].clone();
            cube.localToWorld(a);
            cube.localToWorld(b);
            cube.localToWorld(c);
            let maxDistance = Math.max(a.distanceTo(b), b.distanceTo(c), c.distanceTo(a));
            addCubeEdgesTolines(EdgesManager.edges, a, b, maxDistance);
            addCubeEdgesTolines(EdgesManager.edges, b, c, maxDistance);
            addCubeEdgesTolines(EdgesManager.edges, c, a, maxDistance);
        });
        this.edgesNeedUpdate = false;
        return this.edges;

        function lineContains(lines, pointStart, pointEnd) {
            let index = lines.findIndex(line => (line.start.equals(pointEnd) && line.end.equals(pointStart)) ||
                (line.start.equals(pointStart) && line.end.equals(pointEnd)));
            if (index > -1) {
                return true;
            }
            return false;
        }

        function addCubeEdgesTolines(lines, pointStart, pointEnd, maxDistance) {
            if (pointStart.distanceTo(pointEnd) !== maxDistance) {
                if (!lineContains(lines, pointStart, pointEnd)) {
                    lines.push(new THREE.Line3(pointStart, pointEnd));
                }
            }
        }
    }
};





