/// -1 s'il n'est pas dedans /// 0 si c'est A /// 1 si c'est B /// 2 si c'est C public int getIndexOf(Vector3 P) { if (MathsHlp.approximately(A, P)) { return(0); } else if (MathsHlp.approximately(B, P)) { return(1); } else if (MathsHlp.approximately(C, P)) { return(2); } else { return(-1); } }
/// true si P1 et P2 sont 2 sommets de notre triangle /// si notre triangle est (P1, P2, C) => true /// si notre triangle est (P2, P1, C) => true (car non oriente) public bool hasEdge_nonOriented(Vector3 p1, Vector3 p2) { bool testA1 = MathsHlp.approximately(A, p1); bool testA2 = MathsHlp.approximately(A, p2); bool testB1 = MathsHlp.approximately(B, p1); bool testB2 = MathsHlp.approximately(B, p2); bool testC1 = MathsHlp.approximately(C, p1); bool testC2 = MathsHlp.approximately(C, p2); bool result = (testA1 && testB2) || (testA2 && testB1) || (testB1 && testC2) || (testB2 && testC1) || (testC1 && testA2) || (testC2 && testA1); return(result); }
/// quand un point 3D est le meme position qu'un autre, on le merge public void mergePointsAtSamePositions() { int nbMerged = 0; // pour chaque face, trouver si un point3D identique est present plus tot dans la liste, puis pointer dessus for (int f = 0; f < mFaces.Count; ++f) { var lFace = mFaces[f]; for (int i = 0; i < 3; ++i) { int lIndex = lFace.getByIndex02(i); Vector3 lPoint3D = mPoints[lIndex]; int found = mPoints.FindIndex((pPoint) => { return(MathsHlp.approximately(lPoint3D, pPoint)); }); if (found != lIndex && found != -1) { lFace.setByIndex02(i, found); ++nbMerged; } } } //Debug.Log("on vient de merge "+ nbMerged.ToString() +" sommets"); // supprimer les points qui ne sont plus utilises du tout int nbDeleted = 0; for (int p = mPoints.Count - 1; p >= 0; --p) { var lIndexFaceFound = mFaces.FindIndex((face) => { return(face.has(p)); }); bool is_used = (-1 != lIndexFaceFound); if (!is_used) { removePoint(p); ++nbDeleted; } } //Debug.Log("on vient de supprimer "+ nbDeleted.ToString() +" sommets"); }
/// true si les 3 points sont presents dans this public bool isSameAs(Vector3 pA, Vector3 pB, Vector3 pC) { bool testA1 = MathsHlp.approximately(A, pA); bool testA2 = MathsHlp.approximately(A, pB); bool testA3 = MathsHlp.approximately(A, pC); bool testB1 = MathsHlp.approximately(B, pA); bool testB2 = MathsHlp.approximately(B, pB); bool testB3 = MathsHlp.approximately(B, pC); bool testC1 = MathsHlp.approximately(C, pA); bool testC2 = MathsHlp.approximately(C, pB); bool testC3 = MathsHlp.approximately(C, pC); return ((testA1 && testB2 && testC3) || (testA1 && testB3 && testC2) || (testA2 && testB3 && testC1) || (testA2 && testB1 && testC3) || (testA3 && testB2 && testC1) || (testA3 && testB1 && testC2)); }
/// return true si jamais le point P est l'un des 3 sommets : A ou B ou C public bool hasVertex(Vector3 P) { return(MathsHlp.approximately(A, P) || MathsHlp.approximately(B, P) || MathsHlp.approximately(C, P)); }
/// dit s'il sont pareils (meme si l'ordre n'est pas le meme) /// 'u' pour 'unordered' => sans ordre public bool isSame_u(Line3D pLine) { return((MathsHlp.approximately(pLine.p1, p1) && MathsHlp.approximately(pLine.p2, p2)) || (MathsHlp.approximately(pLine.p2, p1) && MathsHlp.approximately(pLine.p1, p2))); }
/// dit s'il sont pareils (meme si l'ordre n'est pas le meme) /// 'u' pour 'unordered' => sans ordre public bool isSame_u(Vector3 pA, Vector3 pB) { return((MathsHlp.approximately(pA, p1) && MathsHlp.approximately(pB, p2)) || (MathsHlp.approximately(pB, p1) && MathsHlp.approximately(pA, p2))); }
/// vrai si l'une des deux extremites est 'p' public bool hasExtremity(Vector3 p) { return(MathsHlp.approximately(p, p1) || MathsHlp.approximately(p, p2)); }