当前位置: 首页>>代码示例>>C++>>正文


C++ RS_VectorSolutions::getClosestDistance方法代码示例

本文整理汇总了C++中RS_VectorSolutions::getClosestDistance方法的典型用法代码示例。如果您正苦于以下问题:C++ RS_VectorSolutions::getClosestDistance方法的具体用法?C++ RS_VectorSolutions::getClosestDistance怎么用?C++ RS_VectorSolutions::getClosestDistance使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在RS_VectorSolutions的用法示例。


在下文中一共展示了RS_VectorSolutions::getClosestDistance方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。

示例1: draw

void RS_Line::draw(RS_Painter* painter, RS_GraphicView* view, double& patternOffset) {
	if (! (painter && view)) {
        return;
    }

    //only draw the visible portion of line
	LC_Rect const viewportRect{view->toGraph(0, 0),
				view->toGraph(view->getWidth(), view->getHeight())};
	RS_VectorSolutions endPoints(0);
	if (viewportRect.inArea(getStartpoint(), RS_TOLERANCE))
		 endPoints.push_back(getStartpoint());
	if (viewportRect.inArea(getEndpoint(), RS_TOLERANCE))
		 endPoints.push_back(getEndpoint());

	RS_EntityContainer ec(nullptr);
	ec.addRectangle(viewportRect.minP(), viewportRect.maxP());

	if (endPoints.size()<2){
		RS_VectorSolutions vpIts;
		for(auto p: ec) {
			auto const sol=RS_Information::getIntersection(this, p, true);
			for (auto const& vp: sol) {
				if (vpIts.getClosestDistance(vp) <= RS_TOLERANCE * 10.)
					continue;
				vpIts.push_back(vp);
			}
		}
		for (auto const& vp: vpIts) {
			if (endPoints.getClosestDistance(vp) <= RS_TOLERANCE * 10.)
				continue;
			endPoints.push_back(vp);
		}
	}

	if (endPoints.size()<2) return;

	if ((endPoints[0] - getStartpoint()).squared() >
			(endPoints[1] - getStartpoint()).squared() )
		std::swap(endPoints[0],endPoints[1]);

	RS_Vector pStart{view->toGui(endPoints.at(0))};
	RS_Vector pEnd{view->toGui(endPoints.at(1))};
    //    std::cout<<"draw line: "<<pStart<<" to "<<pEnd<<std::endl;
	RS_Vector direction = pEnd-pStart;

	if (isConstruction(true) && direction.squared() > RS_TOLERANCE){
        //extend line on a construction layer to fill the whole view
		RS_VectorSolutions vpIts;
		for(auto p: ec) {
			auto const sol=RS_Information::getIntersection(this, p, false);
			for (auto const& vp: sol) {
				if (vpIts.getClosestDistance(vp) <= RS_TOLERANCE * 10.)
					continue;
				vpIts.push_back(vp);
			}
		}

		//draw construction lines up to viewport border
		switch (vpIts.size()) {
		case 2:
			// no need to sort intersections
			break;
		case 3:
		case 4: {
			// will use the inner two points
			size_t i{0};
			for (size_t j = 2; j < vpIts.size(); ++j) {
				if (viewportRect.inArea(vpIts.at(j), RS_TOLERANCE * 10.))
					std::swap(vpIts[j], vpIts[i++]);
			}
		}
			break;
		default:
			//should not happen
			return;
		}
		pStart=view->toGui(vpIts.get(0));
		pEnd=view->toGui(vpIts.get(1));
		direction=pEnd-pStart;
    }
    double  length=direction.magnitude();
    patternOffset -= length;
    if (( !isSelected() && (
              getPen().getLineType()==RS2::SolidLine ||
              view->getDrawingMode()==RS2::ModePreview)) ) {
        //if length is too small, attempt to draw the line, could be a potential bug
        painter->drawLine(pStart,pEnd);
        return;
    }
    //    double styleFactor = getStyleFactor(view);


    // Pattern:
    const RS_LineTypePattern* pat;
    if (isSelected()) {
//        styleFactor=1.;
        pat = &RS_LineTypePattern::patternSelected;
    } else {
        pat = view->getPattern(getPen().getLineType());
    }
//.........这里部分代码省略.........
开发者ID:Rupicapra-rupicapra,项目名称:LibreCAD,代码行数:101,代码来源:rs_line.cpp


注:本文中的RS_VectorSolutions::getClosestDistance方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。