diff --git a/src/cahillKeyes.js b/src/cahillKeyes.js index 5390b14..4493be0 100644 --- a/src/cahillKeyes.js +++ b/src/cahillKeyes.js @@ -10,6 +10,7 @@ import { abs, cos, degrees, pi, radians, sin, sign, sqrt, tan } from "./math.js" import { cartesianCross, cartesianDegrees, cartesianDot, sphericalDegrees } from "./cartesian.js"; import polyhedral from "./polyhedral/index.js"; import { geoProjectionMutator as projectionMutator } from "d3-geo"; +import {solve2d} from "./newton.js"; export default function(faceProjection) { faceProjection = @@ -669,6 +670,8 @@ export function cahillKeyesRaw(mg) { return mm; } + forward.invert = solve2d(forward); + return forward; } diff --git a/test/invert-test.js b/test/invert-test.js index 6794b9b..7061637 100644 --- a/test/invert-test.js +++ b/test/invert-test.js @@ -30,6 +30,19 @@ tape("inverse Imago, tetrahedralLee", function(test) { test.end(); }); +tape("inverse Cahill-Keyes", function(test) { + + [ d3.geoCahillKeyes() ] + .forEach(function(projection) { + [ [-23, 12], [10,10], [100,-45] ] + .forEach(function(location) { + projection.angle(Math.random()*360); + test.projectionEqual(projection, location, projection(location), 1e-5); + }); + }); + test.end(); +}); + tape("inverse complex log", function(test) { [ d3.geoComplexLog() ]