47 lines
1.6 KiB
TypeScript
47 lines
1.6 KiB
TypeScript
// @deno-types="npm:@types/express"
|
|
import express, { Request, Response } from 'express';
|
|
import cors from 'cors';
|
|
import {getCollisionPoints, linearInterpolation, parabalInterpolatePoints} from "./physics.ts";
|
|
import {changeBasis} from "./math.ts";
|
|
import IPoint from "./IPoint.ts";
|
|
|
|
const app = express();
|
|
const PORT = 3000;
|
|
|
|
app.use(cors());
|
|
|
|
app.get('/api/points', (req: Request, res: Response) => {
|
|
const { g, h, l, alpha } = req.query;
|
|
if (g === undefined || h === undefined || l === undefined || alpha === undefined) {
|
|
res.status(401).send("Параметры должны быть заданы");
|
|
}
|
|
res.json(changeBasis(
|
|
getCollisionPoints({ g: Number(g), h: Number(h), l: Number(l), alpha: Number(alpha) }),
|
|
-Number(alpha)
|
|
));
|
|
});
|
|
|
|
app.get('/api/interpolation', (req: Request, res: Response) => {
|
|
const { g, h, l, alpha, count } = req.query;
|
|
if (g === undefined || h === undefined || l === undefined || alpha === undefined || count === undefined) {
|
|
res.status(401).send("Параметры должны быть заданы");
|
|
}
|
|
const collisionPoints = changeBasis(getCollisionPoints({ g: Number(g), h: Number(h), l: Number(l), alpha: Number(alpha) }), -Number(alpha));
|
|
const points: IPoint[] = [];
|
|
|
|
collisionPoints.forEach((point, i, array) => {
|
|
if (i === 0) {
|
|
points.push(...linearInterpolation(point, array[i+1], Number(count)));
|
|
return;
|
|
}
|
|
if (i >= array.length - 2) return;
|
|
points.push(...parabalInterpolatePoints(point, array[i+1], Number(count)));
|
|
});
|
|
|
|
res.json(points);
|
|
});
|
|
|
|
app.listen(PORT, () => {
|
|
console.log(`Сервер запущен на http://localhost:${PORT}`);
|
|
});
|