本文整理汇总了C++中DPoint::distance方法的典型用法代码示例。如果您正苦于以下问题:C++ DPoint::distance方法的具体用法?C++ DPoint::distance怎么用?C++ DPoint::distance使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类DPoint
的用法示例。
在下文中一共展示了DPoint::distance方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: edgeLengths
double LayoutStatistics::edgeLengths(
const GraphAttributes &ga,
double *pMinLength,
double *pMaxLength,
double *pAvgLength,
double *pStdDeviation,
bool considerSelfLoops)
{
const Graph &G = ga.constGraph();
int m = G.numberOfEdges();
double totalLength = 0, minLength = numeric_limits<double>::max(), maxLength = -numeric_limits<double>::max();
EdgeArray<double> len(G);
int nSelfLoops = 0;
for(edge e : G.edges) {
if(!considerSelfLoops && e->isSelfLoop()) {
nSelfLoops++;
continue;
}
const DPolyline &dpl = ga.bends(e);
if(!dpl.empty()) {
len[e] = dpl.length();
} else {
DPoint pv = DPoint(ga.x(e->source()),ga.y(e->source()));
DPoint pw = DPoint(ga.x(e->target()),ga.y(e->target()));
len[e] = pv.distance(pw);
}
totalLength += len[e];
minLength = min(minLength, len[e]);
maxLength = max(maxLength, len[e]);
}
m -= nSelfLoops;
double avgEdgeLength = totalLength / m;
if(pAvgLength) *pAvgLength = avgEdgeLength;
if(pMinLength) *pMinLength = minLength;
if(pMaxLength) *pMaxLength = maxLength;
if(pStdDeviation) {
double sum = 0;
for(edge e : G.edges) {
if(!considerSelfLoops && e->isSelfLoop())
continue;
double d = len[e] - avgEdgeLength;
sum += d*d;
}
*pStdDeviation = sqrt(sum / m);
}
return totalLength;
}