Home Reference Source Repository

src/app/components/intersection-component/services/intersection-service.js

/*
 * iGeom by LInE
 * Provides service to construct intersetion point of Geometric Objects (GO)
 * www.matematica.br/igeom
 * ./app/components/intersection-component/services/intersection-service.js
 * @calledby ./app/components/<go>-component/models/<go>-model.js
 * @version 2020/11/02: Implemented Line instersection
 */

// Provides service to (any) intersections
class IntersectionService {

  constructor () { // load under iGeom initialization
    this.intersectionsMap = new Map()
    }

  // @param {[]} intersections
  // @calledby ./app/components/intersection-component/drawers/intersection-drawer.js
  addIntersections (intersections) { try { //D //leo
    //D console.log("intersection-service.js: addIntersections(" + intersections + ")");
    const key = intersections.map((intersection) => {
      return `og1_${intersection.og1.id}_og2_${intersection.og2.id}`;
      });
    if (this.intersectionsMap.has(key)) {
      this.intersectionsMap.get(key).forEach((x, i) => intersections[i] = x.id);
      delete this.intersectionsMap.get(key);
      this.intersectionsMap.delete(key);
      }
    this.intersectionsMap.set(key, intersections);
    return intersections;
    } catch (e) { console.log("app/components/intersection-component/services/intersection-service.js: addIntersections(.): erro!\n" + e.stack); }
    }

  }

export const intersectionService = new IntersectionService();