You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 

42 lines
877 B

export const get = (url) =>
new Promise((resolve) => {
wx.request({
url,
success({ data }) {
resolve(data);
},
});
});
export const post = (url, data) =>
new Promise((resolve) => {
wx.request({
url,
method: "POST",
data,
success({ data }) {
resolve(data);
},
});
});
export const getCrossPoint = (point, point1, point2) => {
const cross =
(point2.x - point1.x) * (point.x - point1.x) +
(point2.y - point1.y) * (point.y - point1.y);
if (cross <= 0) return point1;
const d2 =
(point2.x - point1.x) * (point2.x - point1.x) +
(point2.y - point1.y) * (point2.y - point1.y);
if (cross >= d2) return point2;
const r = cross / d2;
const px = point1.x + (point2.x - point1.x) * r;
const py = point1.y + (point2.y - point1.y) * r;
return { x: px, y: py };
};