我正在为内部需求编写 API,因此易用性是首要任务之一。我想知道我是否像下面的例子那样把它推得太远了。
解决逆大地测量问题的函数采用两点的地理坐标,并计算它们之间的距离以及从每个点到另一个点的方位角(角度)。
易于使用优化的传统解决方案可能看起来像(请不要介意名称的长度,我知道还有改进的余地):
class Angle;
class GeoCoordinate;
...
struct InverseGeodeticOut
{
Angle forwardAzimuth;
Angle backAzimuth;
double distance;
};
InverseGeodeticOut inverseGeodetic(const GeoCoordinate &firstPoint,
const GeoCoordinate &secondPoint);
// or
void inverseGeodetic(const GeoCoordinate &firstPoint,
const GeoCoordinate &secondPoint,
InverseGeodeticOut *result);
我的问题是,进一步为用户节省一些输入是否合理:
class Angle;
class GeoCoordinate;
...
struct InverseGeodetic
{
InverseGeodetic();
InverseGeodetic(const GeoCoordinate &firstPoint,
const GeoCoordinate &secondPoint);
Angle forwardAzimuth;
Angle backAzimuth;
double distance;
};
// so the usages would be
InverseGeodeticOut inverse = inverseGeodetic(firstPoint, secondPoint);
InverseGeodeticOut inverse;
inverseGeodetic(firstPoint, secondPoint, &inverse);
InverseGeodetic inverse(firstPoint, secondPoint);
也许在这个特殊的例子中,差异太小了,不值得一提,但我想知道这样的结构总体上是否还可以。