|
@@ -14,21 +14,21 @@ const Erro = 0.00001; //TODO a definir...
|
|
|
|
|
|
export class LineModel extends LineSegmentModel {
|
|
|
|
|
|
- constructor(pointA, pointB, label, id) {
|
|
|
+ constructor (pointA, pointB, label, id) {
|
|
|
super(pointA, pointB, label, id);
|
|
|
this.setClass(ELEMENTS_CLASS.LINE);
|
|
|
- }
|
|
|
+ }
|
|
|
|
|
|
// Overload the Segment 'insideSegment' method (otherwise point intersection could be hiden)
|
|
|
- insideSegment(intersecX, intersecY) { //TODO Sempre verificar se esta dentro, nao parece bom...
|
|
|
+ insideSegment (intersecX, intersecY) { //TODO Sempre verificar se esta dentro, nao parece bom...
|
|
|
return true;
|
|
|
- }
|
|
|
+ }
|
|
|
|
|
|
// Intersection with circunference
|
|
|
- getIntersectionWithCircumference(circ) { // circ = circunference(C,radius)
|
|
|
+ getIntersectionWithCircumference (circ) { // circ = circunference(C,radius)
|
|
|
// Delegate to super class Segment
|
|
|
return super.getIntersectionWithCircumference(circ);
|
|
|
- }
|
|
|
+ }
|
|
|
|
|
|
// Intersection between Straigh Lines (SL): with sl
|
|
|
// r := this=SL(A1,A2) e s := SL(B1,B2)
|
|
@@ -90,24 +90,24 @@ export class LineModel extends LineSegmentModel {
|
|
|
else {
|
|
|
console.log("app/components/line-component/models/line-model.js: erro: O2y=0!"); //D
|
|
|
return null;
|
|
|
+ }
|
|
|
}
|
|
|
}
|
|
|
- }
|
|
|
//D console.log("line-model.js: getIntersectionWithStraightLine(sl): (" + x + "," + y + ") = " +
|
|
|
//D "inter(r(P("+A1x+","+A1y+"),P("+A2x+","+A2y+")), s(P("+B1x+","+B1y+"),P("+B2x+","+B2y+"))");
|
|
|
return [new IntersectionModel(x, y, undefined, this, sl, true, 0)];
|
|
|
} catch (e) { console.log("app/components/line-component/models/line-model.js: getIntersectionWithStraightLine(.): erro!\n" + e.stack); }
|
|
|
- } // getIntersectionWithStraightLine(sl)
|
|
|
+ } // getIntersectionWithStraightLine(sl)
|
|
|
|
|
|
|
|
|
// Intersection between Straigh Line (SL) and Segment (S)
|
|
|
// P in S(C,D) <=> P = a C+(1-a)D, a em [0,1] then | Px = Ax+b(Bx-Ax) = a*Cx + (1-a)Dx and Py = Ay+b(By-Ay) = a*Cy + (1-a)Dy and
|
|
|
// P in SL(A,B) <=> P = A + b(B-A) ---> | b = (a*Cx + (1-a)Dx - Ax)/(Bx-Ax)
|
|
|
- getIntersectionWithSegment(segm) {
|
|
|
+ getIntersectionWithSegment (segm) {
|
|
|
//const pointA = segm.pointA;
|
|
|
//const pointB = segm.pointB;
|
|
|
return segm.getIntersectionByLine(this); //TODO nome em './app/components/line-segment-component/models/line-segment-model.js ! getIntersectionByLine(.)' deveria ser 'getIntersectionWithSegment'
|
|
|
- }
|
|
|
+ }
|
|
|
|
|
|
|
|
|
// Starting point to intersection started with StraightLine
|
|
@@ -122,19 +122,29 @@ export class LineModel extends LineSegmentModel {
|
|
|
case ELEMENTS_CLASS.CIRCUMFERENCE:
|
|
|
return this.getIntersectionWithCircumference(geometricObject); //TODO melhor 'with' que 'by'
|
|
|
default: break;
|
|
|
- }
|
|
|
+ }
|
|
|
} catch (e) { console.log("app/components/line-component/models/line-model.js: getIntersection(.): error " + e + "\n" + e.stack); }
|
|
|
+ }
|
|
|
|
|
|
- }
|
|
|
+ static findOD_LM (vecIdObj, id) {
|
|
|
+ var tam = vecIdObj.length, ii;
|
|
|
+ for (ii=0; ii<tam; ii++)
|
|
|
+ if (vecIdObj[ii].id === id) return ii;
|
|
|
+ return -1; // Error! Not found!
|
|
|
+ }
|
|
|
|
|
|
- static do(map, list) {
|
|
|
+ static do (map, vecIdObj, list) {
|
|
|
const id = map.get("id");
|
|
|
const pointAId = map.get("param")[0];
|
|
|
const pointBId = map.get("param")[1];
|
|
|
- const pointA = list.find(x => x.id === pointAId);
|
|
|
- const pointB = list.find(x => x.id === pointBId);
|
|
|
+ //const pointA = list.find(x => x.id === pointAId);
|
|
|
+ //const pointB = list.find(x => x.id === pointBId);
|
|
|
+ const index_pointA = LineModel.findOD_LM(vecIdObj, pointAId); // get the index of vecIdObj[ii].id == pointAId
|
|
|
+ const index_pointB = LineModel.findOD_LM(vecIdObj, pointBId); // get the index of vecIdObj[ii].id == pointBId
|
|
|
+ const pointA = list[index_pointA]; // pointA = vecIdObj[index_pointA].obj; aux4 += "5,";
|
|
|
+ const pointB = list[index_pointB]; // pointB = vecIdObj[index_pointB].obj; aux4 += "6,";
|
|
|
const label = map.get("label")[0];
|
|
|
return new LineModel(pointA, pointB, label, id);
|
|
|
- }
|
|
|
+ }
|
|
|
|
|
|
-}
|
|
|
+ }
|