const double YsShellExt_RoundUtil::CalculateMaximumRadius(const YsShell &shl) const { double maxRadTotal=0.0; for(YSSIZE_T idx=0; idx<cornerArray.GetN(); ++idx) { const RoundCorner &corner=cornerArray[idx]; const double edgeLen[2]= { shl.GetEdgeLength(corner.fromVtHd,corner.toVtHd[0]), shl.GetEdgeLength(corner.fromVtHd,corner.toVtHd[1]) }; const double maxTanDist=YsSmaller(edgeLen[0],edgeLen[1]); const double maxRad=CalculateRadiusFromTangentDistance(shl,corner.fromVtHd,corner.toVtHd,maxTanDist); if(YsTolerance>maxRad) { return 0.0; } if(0==idx || maxRad<maxRadTotal) { maxRadTotal=maxRad; } } return maxRadTotal; }
YSRESULT YsClipLineSeg2(YsVec2 &c1,YsVec2 &c2,const YsVec2 &l1,const YsVec2 &l2,const YsVec2 &range1,const YsVec2 &range2) { c1=l1; c2=l2; if(YsClipLineSegByTopSide(c1,c2,YsGreater(range1.y(),range2.y()))==YSOK && YsClipLineSegByBottomSide(c1,c2,YsSmaller(range1.y(),range2.y()))==YSOK && YsClipLineSegByRightSide(c1,c2,YsGreater(range1.x(),range2.x()))==YSOK && YsClipLineSegByLeftSide(c1,c2,YsSmaller(range1.x(),range2.x()))==YSOK) { return YSOK; } else { return YSERR; } }
void YsBoundingBoxMaker2::Add(const YsVec2 &vec) { if(first!=YSTRUE) { min.Set (YsSmaller(min.x(),vec.x()), YsSmaller(min.y(),vec.y())); max.Set (YsGreater(max.x(),vec.x()), YsGreater(max.y(),vec.y())); } else { Begin(vec); } }
// 1. Calculate max radius and then max displacement for each edge. // 2. tmin=minimum of the maximum displacements. // 3. Calculate radius from the tmin for each edge. YSRESULT YsShellExt_RoundUtil3d::CalculateRoundingPerVertex(const YsShell &shl,const YsArray <YsShellExt_RoundUtil3d::HalfRoundCorner *> &roundCornerPerVertex,const double radius) const { const YsVec3 m=CalculateRoundingDirction(shl,roundCornerPerVertex); const YsVec3 fromPos=shl.GetVertexPosition(roundCornerPerVertex[0]->fromVtHd); double tMin=-1.0; for(auto corner : roundCornerPerVertex) { const YsVec3 toPos=corner->toPos; const double L=(toPos-fromPos).GetLength(); const double r=(YSTRUE==corner->notReallyDistanceLimited ? radius : YsSmaller(radius,CalculateRadiusFromLimit(fromPos,toPos,m,L))); const double t=CalculateDisplacementFromRadius(fromPos,toPos,m,r); if(-0.1>tMin || t<tMin) { tMin=t; } } if(YsTolerance>tMin) { return YSERR; } const YsVec3 roundedCornerPos=fromPos+m*tMin; for(auto corner : roundCornerPerVertex) { const YsVec3 toPos=corner->toPos; const double r=CalculateRadiusFromDisplacement(fromPos,toPos,m,tMin); if(YsTolerance>r) { return YSERR; } YsVec3 center; if(YSOK!=CalculateCenterFromRadius(center,fromPos,toPos,m,r)) { return YSERR; } corner->roundedCornerPos=roundedCornerPos; YsGetNearestPointOnLine3(corner->foot,fromPos,toPos,center); corner->radius=r; corner->center=center; } return YSOK; }