Skip to content

Commit

Permalink
v1.8.1
Browse files Browse the repository at this point in the history
fix geoTetrahedralLeeSouth
#28
  • Loading branch information
Fil committed Apr 11, 2019
1 parent 305dd26 commit 3ef8487
Show file tree
Hide file tree
Showing 7 changed files with 16 additions and 5 deletions.
Binary file modified img/tetrahedralLee.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added img/tetrahedralLeeSouth.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "d3-geo-polygon",
"version": "1.8.0",
"version": "1.8.1",
"description": "Clipping and geometric operations for spherical polygons.",
"keywords": [
"d3",
Expand Down
6 changes: 3 additions & 3 deletions src/intersect.js
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
import {abs, acos, cos, degrees, epsilon, epsilon2, max, radians} from "./math";
import {abs, acos, cos, degrees, epsilon, epsilon2, pi, radians} from "./math";
import {cartesian, cartesianCross, cartesianDot, cartesianEqual, cartesianNormalizeInPlace, spherical} from "./cartesian";

export function intersectSegment(from, to) {
this.from = from, this.to = to;
this.normal = cartesianCross(from, to);
this.fromNormal = cartesianCross(this.normal, from);
this.toNormal = cartesianCross(this.normal, to);
this.l = acos(max(0,cartesianDot(from, to)));
this.l = acos(cartesianDot(from, to));
}

// >> here a and b are segments processed by intersectSegment
Expand All @@ -16,7 +16,7 @@ export function intersect(a, b) {
if (cartesianEqual(a.to, b.from) || cartesianEqual(a.to, b.to))
return a.to;

var lc = cos(a.l + b.l) - epsilon;
var lc = (a.l + b.l < pi) ? cos(a.l + b.l) - epsilon : -1;
if (cartesianDot(a.from, b.from) < lc
|| cartesianDot(a.from, b.to) < lc
|| cartesianDot(a.to, b.from) < lc
Expand Down
1 change: 1 addition & 0 deletions test/compare-images
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ for i in \
polyhedralCollignon \
polyhedralWaterman \
tetrahedralLee \
tetrahedralLeeSouth \
; do
test/render-world $i > test/output/$i.png \
&& [ "$(gm compare -metric rmse img/$i.png test/output/$i.png 2>&1)" = "Image Difference (RootMeanSquaredError):
Expand Down
4 changes: 4 additions & 0 deletions test/compute-scale
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,10 @@ switch (projectionName) {
land = d3.geoGraticule().extent([[-40, -40], [80, 80]]).outline();
break;
}
// For LeeSouth
// case "tetrahedralLee": {
// projection.angle(-30);
// }
}

var path = d3.geoPath()
Expand Down
8 changes: 7 additions & 1 deletion test/render-world
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,8 @@
var width = 960,
height = 500,
projectionName = process.argv[2],
projectionSymbol = "geo" + projectionName[0].toUpperCase() + projectionName.slice(1);
projectionSymbol = "geo" + projectionName[0].toUpperCase() + projectionName.slice(1),
rotate, angle, translate;

if (!/^[a-z0-9]+$/i.test(projectionName)) throw new Error;

Expand All @@ -24,13 +25,18 @@ switch (projectionName) {
case "littrow": outline = graticule.extent([[-90, -60], [90, 60]]).outline(); break;
case "modifiedStereographicGs50": outline = graticule.extent([[-180, 15], [-50, 75]]).outline(); break;
case "modifiedStereographicMiller": outline = graticule.extent([[-40, -40], [80, 80]]).outline(); break;
case "tetrahedralLeeSouth": projectionSymbol = "geoTetrahedralLee"; rotate = [-30,0]; angle = -30; translate = [599.204, 98.0632]; break;
}

var projection = d3[projectionSymbol]().precision(0.1),
path = d3.geoPath()
.projection(projection)
.context(context);

if (rotate) projection.rotate(rotate);
if (translate) projection.translate(translate);
if (angle) projection.angle(angle);

context.fillStyle = "#fff";
context.fillRect(0, 0, width, height);

Expand Down

0 comments on commit 3ef8487

Please sign in to comment.