-
Notifications
You must be signed in to change notification settings - Fork 5
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(lodCalculator): 抽取计算工具类,增加测试,调整样式
- Loading branch information
1 parent
250c869
commit 18c393c
Showing
6 changed files
with
180 additions
and
71 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,39 @@ | ||
import { expect, it } from 'vitest' | ||
import { getPPI, getResolution, getScaleDomination, ppiToPX, pxToPPI } from './scaleCalculator' | ||
|
||
const scaleDomination = 5.90995197141668e8 | ||
const resolution = 1.406250026231578 | ||
const resolutionMeter = 156367.47924 | ||
const ppi = 96 | ||
|
||
it('scaleDomination (degree)', () => { | ||
expect(Math.abs(getScaleDomination(resolution, ppi, 'degree') - scaleDomination) / scaleDomination).toBeLessThan(1e-5) | ||
}) | ||
|
||
it('scaleDomination (meter)', () => { | ||
expect(Math.abs(getScaleDomination(resolutionMeter, ppi, 'meter') - scaleDomination) / scaleDomination).toBeLessThan(1e-5) | ||
}) | ||
|
||
it('resolution (degree)', () => { | ||
expect(Math.abs(getResolution(scaleDomination, ppi, 'degree') - resolution) / resolution).toBeLessThan(1e-5) | ||
}) | ||
|
||
it('resolution (meter)', () => { | ||
expect(Math.abs(getResolution(scaleDomination, ppi, 'meter') - resolutionMeter) / resolutionMeter).toBeLessThan(1e-5) | ||
}) | ||
|
||
it('ppi (degree)', () => { | ||
expect(getPPI(scaleDomination, resolution, 'degree')).toBeCloseTo(ppi, 3) | ||
}) | ||
|
||
it('ppi (meter)', () => { | ||
expect(getPPI(scaleDomination, resolutionMeter, 'meter')).toBeCloseTo(ppi, 3) | ||
}) | ||
|
||
it('ppi to pixelSize', () => { | ||
expect(ppiToPX(90.713)).toBeCloseTo(0.00028, 6) | ||
}) | ||
|
||
it('pixelSize to ppi', () => { | ||
expect(pxToPPI(0.00028)).toBeCloseTo(90.714, 3) | ||
}) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,40 @@ | ||
const INCH = 0.0254 | ||
const DEGREE = 111194.872221777 | ||
|
||
export function getScaleDomination(resolution: number, ppi: number, unit: 'degree' | 'meter' = 'meter') { | ||
const tmp = resolution / INCH * ppi | ||
if (unit === 'degree') { | ||
return tmp * DEGREE | ||
} | ||
else { | ||
return tmp | ||
} | ||
} | ||
|
||
export function getResolution(scaleDomination: number, ppi: number, unit: 'degree' | 'meter') { | ||
const tmp = scaleDomination / ppi * INCH | ||
if (unit === 'degree') { | ||
return tmp / DEGREE | ||
} | ||
else { | ||
return tmp | ||
} | ||
} | ||
|
||
export function getPPI(scaleDomination: number, resolution: number, unit: 'degree' | 'meter') { | ||
const tmp = scaleDomination / resolution * INCH | ||
if (unit === 'degree') { | ||
return tmp / DEGREE | ||
} | ||
else { | ||
return tmp | ||
} | ||
} | ||
|
||
export function pxToPPI(px: number) { | ||
return INCH / px | ||
} | ||
|
||
export function ppiToPX(ppi: number) { | ||
return INCH / ppi | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -14,6 +14,7 @@ | |
"types": [ | ||
"vitest", | ||
"vite/client", | ||
"vitest/importMeta", | ||
"vite-plugin-pwa/vue" | ||
], | ||
"allowJs": true, | ||
|