Skip to content

Commit a4e6a94

Browse files
committed
Bug fix and Test fix
- test: moc out FileUploadProcessor.jsx - bug fix: better rotation checking for wcs match
1 parent 1f46577 commit a4e6a94

File tree

3 files changed

+47
-17
lines changed

3 files changed

+47
-17
lines changed

__jest__/InitTest.js

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,20 @@
11
import * as jest from 'jest';
22
import {bootstrapRedux} from '../src/firefly/js/core/ReduxFlux';
33
import {getBootstrapRegistry} from '../src/firefly/js/core/BootstrapRegistry.js';
4+
import {initHandleExternalUpload} from '../src/firefly/js/ui/FileUploadProcessor';
45

56

67
jest.mock('firefly/Firefly.js', () => {
78
return {
89
};
910
});
1011

12+
jest.mock('firefly/ui/FileUploadProcessor.jsx', () => {
13+
return {
14+
initHandleExternalUpload: () => false,
15+
};
16+
});
17+
1118
jest.mock('firefly/util/BrowserInfo.js', () => {
1219
return {
1320
getBrowserType: () => '',
@@ -46,6 +53,7 @@ jest.mock('firefly/core/LayoutCntlr.js', () => {
4653
};
4754
});
4855

56+
4957
jest.mock('firefly/ui/UploadTableChooser.js', () => {
5058
return {
5159
showUploadTableChooser: () => '',

src/firefly/js/visualize/PlotViewUtil.js

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ import {Band} from './Band';
99
import CysConverter, {CCUtil} from './CsysConverter';
1010
import {getNumberHeader, HdrConst} from './FitsHeaderUtil.js';
1111
import {getViewer} from './MultiViewCntlr.js';
12-
import {getMatchingPlotRotationAngle, getRotationAngle, isPlotNorth } from './WebPlotAnalysis';
12+
import {getCenterPtOfPlot, getMatchingPlotRotationAngle, getRotationAngle, isPlotNorth} from './WebPlotAnalysis';
1313
import {getPlotGroupById} from './PlotGroup.js';
1414
import {makeTransform} from './PlotTransformUtils.js';
1515
import {makeDevicePt, makeImagePt, makeWorldPt, pointEquals} from './Point.js';
@@ -1105,8 +1105,9 @@ export function isRotationMatching(pv1, pv2) {
11051105

11061106
if (!p1 || !p2) return false;
11071107
if (isNorthCountingRotation(pv1, p1) && isNorthCountingRotation(pv2, p2)) return true;
1108-
const r1 = getRotationAngle(p1) + pv1.rotation;
1109-
const r2 = getRotationAngle(p2) + pv2.rotation;
1108+
const centerFirstPlot= isImage(p1) ? getCenterPtOfPlot(p1) : undefined; // if image use center point method
1109+
const r1 = getRotationAngle(p1,centerFirstPlot) + pv1.rotation;
1110+
const r2 = getRotationAngle(p2,centerFirstPlot) + pv2.rotation;
11101111
return Math.abs((r1 % 360) - (r2 % 360)) < .9;
11111112
}
11121113

src/firefly/js/visualize/WebPlotAnalysis.js

Lines changed: 35 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ import {makeDevicePt, makeImagePt, makeImageWorkSpacePt, makeWorldPt} from './Po
77
import {
88
contains, containsEllipse, containsRec, findIntersectionPt, getAngleInDeg, getBoundingBox, getPositionAngle
99
} from './VisUtil';
10-
import {getPixScaleDeg} from './WebPlot';
10+
import {getPixScaleDeg, isImage} from './WebPlot';
1111

1212

1313
export function isPlotRotatedNorth(plot, csys = CoordinateSys.EQ_J2000) {
@@ -46,7 +46,7 @@ export function isPlotNorth(plot, csys = CoordinateSys.EQ_J2000) {
4646

4747
/**
4848
* get the world point at the center of the plot
49-
* @param {WebPlot} plot
49+
* @param {WebPlot|undefined} plot
5050
* @return {WorldPt}
5151
*/
5252
export function getCenterPtOfPlot(plot) {
@@ -55,18 +55,38 @@ export function getCenterPtOfPlot(plot) {
5555
return CCUtil.getWorldCoords(plot, ip);
5656
}
5757

58-
export const getRotationAngle = (plot) => {
59-
const iWidth = plot.dataWidth;
60-
const iHeight = plot.dataHeight;
61-
const ix = iWidth / 2;
62-
const iy = iHeight / 2;
58+
/**
59+
* find the rotation angle of an image from north. The calculation will be based in the center of the image or some other
60+
* world point using the image's projection.
61+
* @param {WebPlot|undefined} plot
62+
* @param {WorldPt} [centerWp] The world point to base rotation angle on. If undefined or out of the projection conversion range then the center of the image is used
63+
* @return {number} rotation angle.
64+
*/
65+
export const getRotationAngle = (plot, centerWp) => {
66+
if (!plot) return 0;
6367
const cc = CysConverter.make(plot);
64-
const wptC = cc.getWorldCoords(makeImageWorkSpacePt(ix, iy));
65-
const wpt2 = cc.getWorldCoords(makeImageWorkSpacePt(ix, iy + iHeight / 4));
66-
if (wptC && wpt2) return getPositionAngle(wptC.getLon(), wptC.getLat(), wpt2.getLon(), wpt2.getLat());
67-
return 0;
68+
const iHeight = plot.dataHeight;
69+
70+
if (centerWp) {
71+
const ip1= cc.getImageWorkSpaceCoords(centerWp);
72+
if (ip1) {
73+
const wpt2 = cc.getWorldCoords(makeImageWorkSpacePt(ip1.x, ip1.y + iHeight / 4));
74+
if (wpt2) return getPAngle(centerWp, wpt2);
75+
}
76+
}
77+
78+
// use fallback if no centerWp or centerWp could not project
79+
const centerPlotImagePt= makeImageWorkSpacePt(plot.dataWidth / 2, iHeight / 2);
80+
const wptC= cc.getWorldCoords(centerPlotImagePt);
81+
const wpt2 = cc.getWorldCoords(makeImageWorkSpacePt(centerPlotImagePt.x, centerPlotImagePt.y + iHeight / 4));
82+
return getPAngle(wptC,wpt2);
6883
};
6984

85+
86+
const getPAngle= (wp1,wp2) => (wp1 && wp2)
87+
? getPositionAngle(wp1.getLon(), wp1.getLat(), wp2.getLon(), wp2.getLat()) : 0;
88+
89+
7090
/**
7191
* Return true if east if left of north. If east is right of north return false. This works regardless of the rotation
7292
* of the image.
@@ -111,13 +131,14 @@ export const isCsysDirMatching = (p1, p2) => isEastLeftOfNorth(p1) === isEastLef
111131

112132
export function getMatchingPlotRotationAngle(masterPlot, plot, masterRotationAngle, isMasterFlipY) {
113133
if (!plot || !masterPlot) return 0;
134+
const centerMasterPlot= isImage(plot) ? getCenterPtOfPlot(plot) : undefined; // if image use center point method
114135
const masterRot = masterRotationAngle * (isMasterFlipY ? -1 : 1);
115-
const rot = getRotationAngle(plot);
136+
const rot = getRotationAngle(plot,centerMasterPlot);
116137
let targetRotation;
117138
if (isEastLeftOfNorth(masterPlot)) {
118-
targetRotation = ((getRotationAngle(masterPlot) + masterRot) - rot) * (isMasterFlipY ? 1 : -1);
139+
targetRotation = ((getRotationAngle(masterPlot,centerMasterPlot) + masterRot) - rot) * (isMasterFlipY ? 1 : -1);
119140
} else {
120-
targetRotation = ((getRotationAngle(masterPlot) + (360 - masterRot)) - rot) * (isMasterFlipY ? 1 : -1);
141+
targetRotation = ((getRotationAngle(masterPlot,centerMasterPlot) + (360 - masterRot)) - rot) * (isMasterFlipY ? 1 : -1);
121142

122143
}
123144
if (!isCsysDirMatching(plot, masterPlot)) targetRotation = 360 - targetRotation;

0 commit comments

Comments
 (0)