Skip to content

Commit f3e13e5

Browse files
committed
lcc: use xy/set_xy
1 parent b9d48f0 commit f3e13e5

File tree

1 file changed

+19
-24
lines changed

1 file changed

+19
-24
lines changed

src/inner_op/lcc.rs

+19-24
Original file line numberDiff line numberDiff line change
@@ -25,25 +25,23 @@ fn fwd(op: &Op, _ctx: &dyn Context, operands: &mut dyn CoordinateSet) -> usize {
2525
let length = operands.len();
2626

2727
for i in 0..length {
28-
let mut coord = operands.get_coord(i);
29-
let lam = coord[0] - lon_0;
30-
let phi = coord[1];
28+
let (mut lam, phi) = operands.xy(i);
29+
lam -= lon_0;
3130
let mut rho = 0.;
3231

3332
// Close to one of the poles?
3433
if (phi.abs() - FRAC_PI_2).abs() < EPS10 {
3534
if phi * n <= 0. {
36-
coord = Coor4D::nan();
37-
operands.set_coord(i, &coord);
35+
operands.set_coord(i, &Coor4D::nan());
3836
continue;
3937
}
4038
} else {
4139
rho = c * crate::math::ancillary::ts(phi.sin_cos(), e).powf(n);
4240
}
4341
let sc = (lam * n).sin_cos();
44-
coord[0] = a * k_0 * rho * sc.0 + x_0;
45-
coord[1] = a * k_0 * (rho0 - rho * sc.1) + y_0;
46-
operands.set_coord(i, &coord);
42+
let x = a * k_0 * rho * sc.0 + x_0;
43+
let y = a * k_0 * (rho0 - rho * sc.1) + y_0;
44+
operands.set_xy(i, x, y);
4745
successes += 1;
4846
}
4947
successes
@@ -64,20 +62,19 @@ fn inv(op: &Op, _ctx: &dyn Context, operands: &mut dyn CoordinateSet) -> usize {
6462
return 0;
6563
};
6664
let mut successes = 0_usize;
67-
let length = operands.len();
6865

69-
for i in 0..length {
70-
let mut coord = operands.get_coord(i);
71-
let mut x = (coord[0] - x_0) / (a * k_0);
72-
let mut y = rho0 - (coord[1] - y_0) / (a * k_0);
66+
for i in 0..operands.len() {
67+
let (mut x, mut y) = operands.xy(i);
68+
x = (x - x_0) / (a * k_0);
69+
y = rho0 - (y - y_0) / (a * k_0);
7370

7471
let mut rho = x.hypot(y);
7572

76-
// On one of the poles
73+
// On one of the poles?
7774
if rho == 0. {
78-
coord[0] = 0.;
79-
coord[1] = FRAC_PI_2.copysign(n);
80-
operands.set_coord(i, &coord);
75+
let lon = 0.;
76+
let lat = FRAC_PI_2.copysign(n);
77+
operands.set_xy(i, lon, lat);
8178
successes += 1;
8279
continue;
8380
}
@@ -90,15 +87,13 @@ fn inv(op: &Op, _ctx: &dyn Context, operands: &mut dyn CoordinateSet) -> usize {
9087
}
9188

9289
let ts0 = (rho / c).powf(1. / n);
93-
let phi = crate::math::ancillary::pj_phi2(ts0, e);
94-
if phi.is_infinite() || phi.is_nan() {
95-
coord = Coor4D::nan();
96-
operands.set_coord(i, &coord);
90+
let lat = crate::math::ancillary::pj_phi2(ts0, e);
91+
if lat.is_infinite() || lat.is_nan() {
92+
operands.set_coord(i, &Coor4D::nan());
9793
continue;
9894
}
99-
coord[0] = x.atan2(y) / n + lon_0;
100-
coord[1] = phi;
101-
operands.set_coord(i, &coord);
95+
let lon = x.atan2(y) / n + lon_0;
96+
operands.set_xy(i, lon, lat);
10297
successes += 1;
10398
}
10499
successes

0 commit comments

Comments
 (0)