找回密码
 立即注册

QQ登录

只需一步,快速开始

扫一扫,访问微社区

查看: 1547|回复: 0

[分享] ChGeCurveCurveInt2d

[复制链接]

已领礼包: 1268个

财富等级: 财源广进

发表于 2014-7-12 08:32:00 | 显示全部楼层 |阅读模式

马上注册,结交更多好友,享用更多功能,让你轻松玩转社区。

您需要 登录 才可以下载或查看,没有账号?立即注册

×
[ 本帖最后由 st788796 于 2014-7-12 09:06 编辑 ]\n\n#ifndef CH_GECURVECURVEINT2D_H
#define CH_GECURVECURVEINT2D_H

#ifndef ACGEXCONFIGARRAY
#define ACGEXCONFIGARRAY
typedef AcArray<AcGeXConfig> AcGeXConfigArray;
#endif

#include <gecint2d.h>

class ChGeCurveCurveInt2d : public AcGeCurveCurveInt2d
{
public:
        ChGeCurveCurveInt2d() {}
        ChGeCurveCurveInt2d(const AcGeCurve2d& curve1,const AcGeCurve2d& curve2,
                const AcGeTol& tol = AcGeContext::gTol);
        ChGeCurveCurveInt2d(const AcGeCurve2d& curve1,const AcGeCurve2d& curve2,
                const AcGeInterval& range1,const AcGeInterval& range2,
                const AcGeTol& tol = AcGeContext::gTol);
        ChGeCurveCurveInt2d(const ChGeCurveCurveInt2d& src);
        ChGeCurveCurveInt2d& set(const AcGeCurve2d& curve1,const AcGeCurve2d& curve2,
                const AcGeTol& tol=AcGeContext::gTol);
        ChGeCurveCurveInt2d& set(const AcGeCurve2d& curve1,const AcGeCurve2d& curve2,
                const AcGeInterval& range1,const AcGeInterval& range2,
                const AcGeTol& tol=AcGeContext::gTol);
        ChGeCurveCurveInt2d & orderWrt1();
        ChGeCurveCurveInt2d & orderWrt2();
        void getParams(AcGeDoubleArray& ps1,AcGeDoubleArray& ps2) { ps1 = params1; ps2 = params2; }
        void getXConfigs(AcGeXConfigArray& cs1,AcGeXConfigArray& cs2) { cs1 = confs1; cs2 = confs2;        }
        void getIntPoints(AcGePoint2dArray& ps) { ps = pnts;        }
protected:
        AcGeXConfigArray confs1,confs2;                // 曲线交点的config
        AcGeDoubleArray params1,params2;    // 曲线交点参数
        AcGePoint2dArray pnts;       // 曲线交点
};

inline ChGeCurveCurveInt2d::ChGeCurveCurveInt2d(const AcGeCurve2d& curve1,const AcGeCurve2d& curve2,
                                                                                 const AcGeTol& tol)
                                                                                 : AcGeCurveCurveInt2d(curve1,curve2,tol)
{
        int i,intNum;
        intNum = numIntPoints();
        confs1.setLogicalLength(intNum);
        confs2.setLogicalLength(intNum);
        params1.setLogicalLength(intNum);
        params2.setLogicalLength(intNum);
        pnts.setLogicalLength(intNum);
        for (i=0; i<intNum; i++) {
                pnts[i] = intPoint(i);
                getIntConfigs(i,confs1[i],confs2[i]);
                getIntParams(i,params1[i],params2[i]);
        }
}

inline ChGeCurveCurveInt2d& ChGeCurveCurveInt2d::set(const AcGeCurve2d& curve1,const AcGeCurve2d& curve2,
                                                                                                         const AcGeTol& tol)
{
        // ?
        AcGeCurveCurveInt2d::set(curve1,curve2,tol);
        int i,intNum;
        intNum = numIntPoints();
        confs1.setLogicalLength(intNum);
        confs2.setLogicalLength(intNum);
        params1.setLogicalLength(intNum);
        params2.setLogicalLength(intNum);
        pnts.setLogicalLength(intNum);
        for (i=0; i<intNum; i++) {
                pnts[i] = intPoint(i);
                getIntConfigs(i,confs1[i],confs2[i]);
                getIntParams(i,params1[i],params2[i]);
        }

        return *this;
}

inline ChGeCurveCurveInt2d::ChGeCurveCurveInt2d(const AcGeCurve2d& curve1,const AcGeCurve2d& curve2,
                                                                                 const AcGeInterval& range1,const AcGeInterval& range2,
                                                                                 const AcGeTol& tol)
                                                                                 : AcGeCurveCurveInt2d(curve1,curve2,range1,range2,tol)
{
        int i,intNum;
        intNum = numIntPoints();
        confs1.setLogicalLength(intNum);
        confs2.setLogicalLength(intNum);
        params1.setLogicalLength(intNum);
        params2.setLogicalLength(intNum);
        pnts.setLogicalLength(intNum);
        for (i=0; i<intNum; i++) {
                pnts[i] = intPoint(i);
                getIntConfigs(i,confs1[i],confs2[i]);
                getIntParams(i,params1[i],params2[i]);
        }
}

inline ChGeCurveCurveInt2d& ChGeCurveCurveInt2d::set(const AcGeCurve2d& curve1,const AcGeCurve2d& curve2,
                                                                                 const AcGeInterval& range1,const AcGeInterval& range2,
                                                                                 const AcGeTol& tol)
{
        AcGeCurveCurveInt2d::set(curve1,curve2,range1,range2,tol);
        int i,intNum;
        intNum = numIntPoints();
        confs1.setLogicalLength(intNum);
        confs2.setLogicalLength(intNum);
        params1.setLogicalLength(intNum);
        params2.setLogicalLength(intNum);
        pnts.setLogicalLength(intNum);
        for (i=0; i<intNum; i++) {
                pnts[i] = intPoint(i);
                getIntConfigs(i,confs1[i],confs2[i]);
                getIntParams(i,params1[i],params2[i]);
        }
        return *this;
}


inline ChGeCurveCurveInt2d::ChGeCurveCurveInt2d(const ChGeCurveCurveInt2d& src)
{
        // ?
//        AcGeCurve2d *cu1,*cu2;
//        AcGeTol tol;
//        cu1 = src.curve1();
//        cu2 = src.curve2();
//        tol = src.tolerance();

//        *this = ChGeCurveCurveInt2d(*(src.curve1()),*(src.curve2()),tol);
        *this = src;
}

inline ChGeCurveCurveInt2d & ChGeCurveCurveInt2d::orderWrt1()
{
        if (!numIntPoints()) return *this; // 没有交点

        int i,intNum;
        bool bAlready = true; // 是否已经是按照curve1排序
        intNum = numIntPoints();
        for (i=1; i<intNum; i++) {
                if (params1[i] < params1[i-1]) {
                        bAlready = false;
                        break;
                }
        }

        if (!bAlready) {
                int j,min;
                for (i=0; i<intNum-1; i++) {
                        min = i;
                        for (j=i+1; j<intNum; j++) {
                                if (params1[min]>params1[j]) min = j;
                        }
                        if (min != i) {
                                params1.swap(i,min);
                                params2.swap(i,min);
                                confs1.swap(i,min);
                                confs2.swap(i,min);
                                pnts.swap(i,min);
                        }
                }
        }

        return *this;
}

inline ChGeCurveCurveInt2d & ChGeCurveCurveInt2d::orderWrt2()
{
        if (!numIntPoints()) return *this; // 没有交点

        int i,intNum;
        bool bAlready = true; // 是否已经是按照curve1排序
        intNum = numIntPoints();
        for (i=1; i<intNum; i++) {
                if (params2[i] < params2[i-1]) {
                        bAlready = false;
                        break;
                }
        }

        if (!bAlready) {
                int j,min;
                for (i=0; i<intNum-1; i++) {
                        min = i;
                        for (j=i+1; j<intNum; j++) {
                                if (params2[min]>params2[j]) min = j;
                        }
                        if (min != i) {
                                params1.swap(i,min);
                                params2.swap(i,min);
                                confs1.swap(i,min);
                                confs2.swap(i,min);
                                pnts.swap(i,min);
                        }
                }
        }

        return *this;
}

#endif // CH_GECURVECURVEINT2D_H
论坛插件加载方法
发帖求助前要善用【论坛搜索】功能,那里可能会有你要找的答案;
如果你在论坛求助问题,并且已经从坛友或者管理的回复中解决了问题,请把帖子标题加上【已解决】;
如何回报帮助你解决问题的坛友,一个好办法就是给对方加【D豆】,加分不会扣除自己的积分,做一个热心并受欢迎的人!
您需要登录后才可以回帖 登录 | 立即注册

本版积分规则

QQ|申请友链|Archiver|手机版|小黑屋|辽公网安备|晓东CAD家园 ( 辽ICP备15016793号 )

GMT+8, 2025-9-10 05:41 , Processed in 0.358086 second(s), 28 queries , Gzip On.

Powered by Discuz! X3.5

© 2001-2025 Discuz! Team.

快速回复 返回顶部 返回列表