私は社内のニーズに合わせて API を作成しているため、使いやすさは最優先事項の 1 つです。次の例のように、押しすぎているのではないでしょうか。
逆測地問題を解く関数は、2 点の地理座標を取り込み、それらの間の距離と、各点から他の点までの方位 (角度) を計算します。
使いやすさを最適化した従来のソリューションは次のようになります (名前の長さは気にしないでください。改善の余地があることは承知しています)。
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);
おそらく、この特定の例では、違いが小さすぎて話す価値はありませんが、そのような構成が一般的に問題ないかどうか疑問に思います.