<commit_before>#ifndef BASEINTTOOL_H
#define BASEINTTOOL_H


#include <sofa/core/collision/Intersection.h>
#include <sofa/helper/FnDispatcher.h>
#include <sofa/component/collision/CapsuleModel.h>
#include <sofa/component/collision/SphereModel.h>
#include <sofa/component/collision/OBBModel.h>
#include <sofa/component/collision/IntrCapsuleOBB.h>
#include <sofa/component/collision/CapsuleIntTool.h>
#include <sofa/component/collision/OBBIntTool.h>
#include <cmath>

namespace sofa
{
namespace component
{
namespace collision
{

class SOFA_BASE_COLLISION_API BaseIntTool : public CapsuleIntTool,public OBBIntTool{
public:
    typedef sofa::helper::vector<sofa::core::collision::DetectionOutput> OutputVector;

    static bool testIntersection(Cube& ,Cube&,double alarmDist);

    template <class DataTypes1,class DataTypes2>
    static bool testIntersection(TSphere<DataTypes1>& sph1, TSphere<DataTypes2>& sph2,double alarmDist)
    {
        typename TSphere<DataTypes1>::Real r = sph1.r() + sph2.r() + alarmDist;
        return ( sph1.center() - sph2.center() ).norm2() <= r*r;
    }


    template <class DataTypes1,class DataTypes2>
    static int computeIntersection(TSphere<DataTypes1>& sph1, TSphere<DataTypes2>& sph2,double alarmDist,double contactDist,OutputVector* contacts);


    inline static int computeIntersection(Capsule &c1, Capsule &c2, double alarmDist, double contactDist, OutputVector *contacts){
        return CapsuleIntTool::computeIntersection(c1,c2,alarmDist,contactDist,contacts);
    }

    template <class DataType>
    inline static int computeIntersection(Capsule &cap, TSphere<DataType> &sph, double alarmDist, double contactDist, OutputVector *contacts){
        return CapsuleIntTool::computeIntersection(cap,sph,alarmDist,contactDist,contacts);
    }

    inline static int computeIntersection(Capsule &cap, OBB & obb, double alarmDist, double contactDist, OutputVector *contacts){
        return CapsuleIntTool::computeIntersection(cap,obb,alarmDist,contactDist,contacts);
    }

    inline static int computeIntersection(OBB &obb0, OBB &obb1, double alarmDist, double contactDist, OutputVector *contacts){
        return OBBIntTool::computeIntersection(obb0,obb1,alarmDist,contactDist,contacts);
    }

    template <class DataType>
    inline static int computeIntersection(TSphere<DataType> &sph, OBB &obb, double alarmDist, double contactDist, OutputVector *contacts){
        return OBBIntTool::computeIntersection(sph,obb,alarmDist,contactDist,contacts);
    }
};

template <class DataTypes1,class DataTypes2>
int BaseIntTool::computeIntersection(TSphere<DataTypes1>& sph1, TSphere<DataTypes2>& sph2, double alarmDist, double contactDist, OutputVector * contacts)
{
    double r = sph1.r() + sph2.r();
    double myAlarmDist = alarmDist + r;
    Vector3 dist = sph2.center() - sph1.center();
    SReal norm2 = dist.norm2();

    if (norm2 >= myAlarmDist*myAlarmDist)
        return 0;

    contacts->resize(contacts->size()+1);
    DetectionOutput *detection = &*(contacts->end()-1);
    detection->normal = dist;
    double distSph1Sph2 = helper::rsqrt(norm2);
    detection->normal /= distSph1Sph2;
    detection->point[0] = sph1.center() + detection->normal * sph1.r();
    detection->point[1] = sph2.center() - detection->normal * sph2.r();

    detection->value = distSph1Sph2 - r - contactDist;
    detection->elem.first = sph1;
    detection->elem.second = sph2;
    detection->id = (sph1.getCollisionModel()->getSize() > sph2.getCollisionModel()->getSize()) ? sph1.getIndex() : sph2.getIndex();

    return 1;
}

}
}
}
#endif // BASEINTTOOL_H<commit_msg>r9639/sofa : Reverting some changes in BaseIntTool.h<commit_after>#ifndef BASEINTTOOL_H
#define BASEINTTOOL_H


#include <sofa/core/collision/Intersection.h>
#include <sofa/helper/FnDispatcher.h>
#include <sofa/component/collision/CapsuleModel.h>
#include <sofa/component/collision/SphereModel.h>
#include <sofa/component/collision/OBBModel.h>
#include <sofa/component/collision/IntrCapsuleOBB.h>
#include <sofa/component/collision/CapsuleIntTool.h>
#include <sofa/component/collision/OBBIntTool.h>
#include <cmath>

namespace sofa
{
namespace component
{
namespace collision
{

class SOFA_BASE_COLLISION_API BaseIntTool : public CapsuleIntTool,public OBBIntTool{
public:
    typedef sofa::helper::vector<sofa::core::collision::DetectionOutput> OutputVector;

    static bool testIntersection(Cube& ,Cube&,double alarmDist);

    template <class DataTypes1,class DataTypes2>
    static bool testIntersection(TSphere<DataTypes1>& sph1, TSphere<DataTypes2>& sph2,double alarmDist)
    {
        typename TSphere<DataTypes1>::Real r = sph1.r() + sph2.r() + alarmDist;
        return ( sph1.center() - sph2.center() ).norm2() <= r*r;
    }


    template <class DataTypes1,class DataTypes2>
    static int computeIntersection(TSphere<DataTypes1>& sph1, TSphere<DataTypes2>& sph2,double alarmDist,double contactDist,OutputVector* contacts);


    inline static int computeIntersection(Capsule &c1, Capsule &c2, double alarmDist, double contactDist, OutputVector *contacts){
        return CapsuleIntTool::computeIntersection(c1,c2,alarmDist,contactDist,contacts);
    }

    template <class DataType>
    inline static int computeIntersection(Capsule &cap, TSphere<DataType> &sph, double alarmDist, double contactDist, OutputVector *contacts){
        return CapsuleIntTool::computeIntersection(cap,sph,alarmDist,contactDist,contacts);
    }

    inline static int computeIntersection(Capsule &cap, OBB & obb, double alarmDist, double contactDist, OutputVector *contacts){
        return CapsuleIntTool::computeIntersection(cap,obb,alarmDist,contactDist,contacts);
    }

    inline static int computeIntersection(OBB &obb0, OBB &obb1, double alarmDist, double contactDist, OutputVector *contacts){
        return OBBIntTool::computeIntersection(obb0,obb1,alarmDist,contactDist,contacts);
    }

    template <class DataType>
    inline static int computeIntersection(TSphere<DataType> &sph, OBB &obb, double alarmDist, double contactDist, OutputVector *contacts){
        return OBBIntTool::computeIntersection(sph,obb,alarmDist,contactDist,contacts);
    }

    template <class TReal>
	static int computeIntersection(TSphere<StdVectorTypes<Vec<3,TReal>,Vec<3,TReal>,TReal> >& sph1, TSphere<StdRigidTypes<3,TReal> >& sph2,
	                                   double alarmDist, double contactDist, OutputVector * contacts);

    template <class TReal>
	static int computeIntersection(TSphere<StdVectorTypes<Vec<3,TReal>,Vec<3,TReal>,TReal> >& sph1, TSphere<StdVectorTypes<Vec<3,TReal>,Vec<3,TReal>,TReal> >& sph2,
	                                   double alarmDist, double contactDist, OutputVector * contacts);
};

template <class DataTypes1,class DataTypes2>
int BaseIntTool::computeIntersection(TSphere<DataTypes1>& sph1, TSphere<DataTypes2>& sph2, double alarmDist, double contactDist, OutputVector * contacts)
{
    double r = sph1.r() + sph2.r();
    double myAlarmDist = alarmDist + r;
    Vector3 dist = sph2.center() - sph1.center();
    SReal norm2 = dist.norm2();

    if (norm2 >= myAlarmDist*myAlarmDist)
        return 0;

    contacts->resize(contacts->size()+1);
    DetectionOutput *detection = &*(contacts->end()-1);
    detection->normal = dist;
    double distSph1Sph2 = helper::rsqrt(norm2);
    detection->normal /= distSph1Sph2;
    detection->point[0] = sph1.center() + detection->normal * sph1.r();
    detection->point[1] = sph2.center() - detection->normal * sph2.r();

    detection->value = distSph1Sph2 - r - contactDist;
    detection->elem.first = sph1;
    detection->elem.second = sph2;
    detection->id = (sph1.getCollisionModel()->getSize() > sph2.getCollisionModel()->getSize()) ? sph1.getIndex() : sph2.getIndex();

    return 1;
}

//CAUTION the next methods are different, the point of contact differs depending the sphere data type, if the sphere data type is vectortype,
//then the point of contact is the center of the sphere, otherwise, it is the real point of contact on the sphere surface.
template <class TReal>
int BaseIntTool::computeIntersection(TSphere<StdVectorTypes<Vec<3,TReal>,Vec<3,TReal>,TReal> >& sph1, TSphere<StdRigidTypes<3,TReal> >& sph2,
                                     double alarmDist, double contactDist, OutputVector * contacts)
{
    double r = sph1.r() + sph2.r();
    double myAlarmDist = alarmDist + r;
    Vector3 dist = sph2.center() - sph1.center();
    SReal norm2 = dist.norm2();

    if (norm2 >= myAlarmDist*myAlarmDist)
        return 0;

    contacts->resize(contacts->size()+1);
    DetectionOutput *detection = &*(contacts->end()-1);
    detection->normal = dist;
    double distSph1Sph2 = helper::rsqrt(norm2);
    detection->normal /= distSph1Sph2;
    detection->point[0] = sph1.center();//difference is here
    detection->point[1] = sph2.center() - detection->normal * sph2.r();//difference is here
    detection->value = distSph1Sph2 - r - contactDist;
    detection->elem.first = sph1;
    detection->elem.second = sph2;
    detection->id = (sph1.getCollisionModel()->getSize() > sph2.getCollisionModel()->getSize()) ? sph1.getIndex() : sph2.getIndex();

    return 1;
}


template <class TReal>
int BaseIntTool::computeIntersection(TSphere<StdVectorTypes<Vec<3,TReal>,Vec<3,TReal>,TReal> >& sph1, TSphere<StdVectorTypes<Vec<3,TReal>,Vec<3,TReal>,TReal> >& sph2,
                                     double alarmDist, double contactDist, OutputVector * contacts)
{
    double r = sph1.r() + sph2.r();
    double myAlarmDist = alarmDist + r;
    Vector3 dist = sph2.center() - sph1.center();

    if (dist.norm2() >= myAlarmDist*myAlarmDist)
        return 0;

    contacts->resize(contacts->size()+1);
    DetectionOutput *detection = &*(contacts->end()-1);
    detection->normal = dist;
    double distSph1Sph2 = detection->normal.norm();
    detection->normal /= distSph1Sph2;
    detection->point[0] = sph1.center();//difference is here
    detection->point[1] = sph2.center();//difference is here

    detection->value = distSph1Sph2 - r - contactDist;
    detection->elem.first = sph1;
    detection->elem.second = sph2;
    detection->id = (sph1.getCollisionModel()->getSize() > sph2.getCollisionModel()->getSize()) ? sph1.getIndex() : sph2.getIndex();

    return 1;
}


}
}
}
#endif // BASEINTTOOL_H
{'fraction_non_alphanumeric': 0.12607978258759583, 'fraction_numerical': 0.020188294671454915, 'mean_word_length': 4.545748116254036, 'pattern_counts': {'":': 0, '<': 85, '<?xml version=': 0, '>': 149, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 4, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '1781172', 'n_tokens_mistral': 3478, 'n_tokens_neox': 3348, 'n_words': 675}