-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
tedjmzhang
committed
Jun 24, 2024
1 parent
7199051
commit c6d6124
Showing
7 changed files
with
156 additions
and
6 deletions.
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
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,26 @@ | ||
const resolve = require("enhanced-resolve"); | ||
const path =require('path') | ||
|
||
// resolve("/some/path/to/folder", "module/dir", (err, result) => { | ||
// result; // === "/some/path/node_modules/module/dir/index.js" | ||
// }); | ||
console.log(__dirname); // /Users/zhangjiaming/code/learn/blog/src/frontend/library/enhanced-resolve | ||
let res = resolve.sync(__dirname, "asap"); // /Users/zhangjiaming/code/learn/blog/node_modules/asap/asap.js | ||
let res2 = resolve.sync(__dirname, "esbuild"); // /Users/zhangjiaming/code/learn/blog/node_modules/esbuild/lib/main.js | ||
console.log(res); | ||
console.log(res2); | ||
|
||
const myResolve = resolve.create({ | ||
// or resolve.create.sync | ||
extensions: [".ts", ".js"], | ||
alias: { | ||
"@": __dirname | ||
} | ||
// see more options below | ||
}); | ||
|
||
let res3 = myResolve('/', "@/index", (err, result) => { | ||
if(err) throw err | ||
console.log('res3', result); | ||
}); | ||
|
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,14 @@ | ||
# enhanced-resolve 获取绝对路径,用来处理模块引用的 | ||
[通过可以设置各种配置,例如别名,根路径等](https://www.npmjs.com/package/enhanced-resolve) | ||
|
||
``` | ||
// webpack使用该库处理成xxx/node_modules/moduleA/xxx, 后面的xxx是该库的package.json里面的main定义的 | ||
import moduleA from 'moduleA' | ||
// 处理相对路径 xxx/moduleB/xxx.[ext] | ||
import moduleB from './moduleB' | ||
``` | ||
|
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,45 @@ | ||
// 公式: 向量a.向量b = |a||b|cosAngle。 | ||
// 公式:向量a.向量b = (a.X * b.X) + (b.Y * b.Y) | ||
// 结合两者可以求出cosAngle,然后求出比例ratio | ||
|
||
/** | ||
* @typedef Point | ||
* @property {number} latitude | ||
* @property {number} longitude | ||
*/ | ||
|
||
/** | ||
* @desc: 求其他点在起终点对应直线的投影(ps: 常用地理坐标系是二维坐标系) | ||
* @param {Point} startPoint 起点 | ||
* @param {Point} endPoint 终点 | ||
* @param {Point} point 其他点 | ||
*/ | ||
function getAbsorbPoint(startPoint, endPoint, point) { | ||
const { | ||
longitude: sX, | ||
latitude: sY | ||
} = startPoint | ||
const { | ||
longitude: eX, | ||
latitude: eY | ||
} = endPoint | ||
const { | ||
longitude: pX, | ||
latitude: pY | ||
} = point | ||
|
||
let so = [sX, sY]; // 向量so,从原点o指向startPoint | ||
let eo = [eX, eY]; // 向量eo,从原点o指向endPoint | ||
let po = [pX, pY]; // 向量po,从原点o指向point | ||
let es = [eo[0] - so[0], eo[1] - so[1]]; // 向量es,由向量eo - 向量so | ||
let ps = [po[0] - so[0], po[1] - so[1]]; // 向量ps,由向量po - 向量so | ||
let esMang = Math.sqrt(Math.pow(es[0], 2) + Math.pow(es[1], 2)) // 向量es的模 | ||
let psMang = Math.sqrt(Math.pow(ps[0], 2) + Math.pow(ps[1], 2)) // 向量ps的模 | ||
|
||
let cosAngle = (es[0] * ps[0] + es[1] * ps[1]) / esMang / psMang; | ||
let ratio = psMang * cosAngle / esMang; // 其实就是(es[0] * ps[0] + es[1] * ps[1]) / Math.pow(esMang, 2) | ||
return { | ||
longitude: sX + ratio * es[0], | ||
latitude: sY + ratio * es[1] | ||
} | ||
} |