Can you go one step further and convert/replace your vector of vectors with
std::vector<point>
?
That says much more clearly what data you have.
The x.x, x.y, y.x, y.y is confusing.
I would rename and retype the arguments of your function:
float fd( point lhs, point rhs );
There are essentially three types of arguments:
* by value
* by reference
* const reference
The by reference is for modifying a variable of the caller. Your fd() does not modify.
There is debate on which is more efficient today, by value or const reference. The point is small POD (plain old data), so by value is fine.
I would not use pow(), because a square is simply
tempx*tempx
You have N points and you want to fill a N*N symmetric matrix.
What is on the diagonal? fd(foo, foo). That is 0.0. We can do that separately.
You only need to calculate the upper triangle.
1 2 3 4 5 6 7 8 9 10 11 12 13
|
for ( size_t row = 0; row < N; ++row ) {
for ( size_t col = row+1; col < N; ++col ) {
// calculation
result = ...
m(row,col) = result;
m(col,row) = result;
}
}
// diagonal
for ( size_t row = 0; row < N; ++row ) {
m(row,row) = ...
}
|