reorganize directory and file structure

This commit is contained in:
Joeri Exelmans 2025-05-07 13:44:49 +02:00
parent 1d826ea8d4
commit 48390b8556
99 changed files with 1155 additions and 1629 deletions

23
extra/point/nominal.js Normal file
View file

@ -0,0 +1,23 @@
export const cart2polar = ({x, y}) => {
const r = Math.sqrt(x*x + y*y);
const θ = Math.atan(y/x);
return {r, θ};
};
export const polar2cart = ({r, θ}) => {
const x = r * Math.cos(θ);
const y = r * Math.sin(θ);
return {x, y};
}
export const translate = dx => dy => ({x, y}) => {
return {left: x+dx, right: y+dy};
}
export const rotate = => ({r, θ}) => {
return {r, θ: θ+};
}
export const scale = dr => ({r, θ}) => {
return {r: r+dr, θ};
}

View file

@ -0,0 +1,30 @@
import { makeTypeParser } from "../../lib/parser/type_parser.js";
import { Type } from "../../lib/primitives/primitive_types.js";
import { makeTypeConstructor } from "../../lib/meta/type_constructor.js";
import { cart2polar, polar2cart, rotate, scale, translate } from "./nominal.js";
const PointCartesian2D = makeTypeConstructor('PCartesian2D__20bb64ce2cd52cfc6702f7d5d9bd1e60')(0);
const PointPolar2D = makeTypeConstructor('PPolar2D__dd566869d57d440e0bc299c53cac3846')(0);
const examplePoint = {x: 1, y: 2};
const mkType = makeTypeParser({
extraPrimitives: [
["PointCartesian2D", PointCartesian2D],
["PointPolar2D", PointPolar2D],
]
});
export const ModulePointNominal = [
{i: PointCartesian2D , t: Type},
{i: PointPolar2D , t: Type},
{i: examplePoint , t: PointCartesian2D},
{i: cart2polar, t: mkType("PointCartesian2D -> PointPolar2D")},
{i: polar2cart, t: mkType("PointPolar2D -> PointCartesian2D")},
{i: translate, t: mkType("Double -> Double -> PointCartesian2D")},
{i: rotate , t: mkType("Double -> PointPolar2D -> PointPolar2D")},
{i: scale , t: mkType("Double -> PointPolar2D -> PointPolar2D")},
];

View file

@ -0,0 +1,81 @@
import { makeTypeParser } from "../../lib/parser/type_parser.js";
import { makeModuleStruct } from "../../lib/structures/struct.types.js";
import { makeTypeConstructor } from "../../lib/meta/type_constructor.js";
import { newProduct } from "../../lib/structures/product.js";
import { Double } from "../../lib/primitives/primitive_types.js";
// Nominal types:
const NPoint2DCartesian = makeTypeConstructor('PCartesian2D__7efe2dd14d9b036e2e83d6e4771c88ac')(0);
const NPoint2DPolar = makeTypeConstructor('PPolar2D__9297b15478804ee209a91f1af943b67a')(0);
// Structural types:
const ModuleCartesian = makeModuleStruct([
newProduct("x")(Double),
newProduct("y")(Double),
]);
const ModulePolar = makeModuleStruct([
newProduct("r")(Double),
newProduct("θ")(Double),
]);
const [
{i: SPoint2DCartesian},
{i: newCartesian},
{i: getX},
{i: getY},
] = ModuleCartesian;
const [
{i: SPoint2DPolar},
{i: newPolar},
{i: getR},
{i: getΘ},
] = ModulePolar;
const cart2polar = cart => {
const x = getX(cart);
const y = getY(cart);
const r = Math.sqrt(x*x + y*y);
const θ = Math.atan(y/x);
return newPolar(r)(θ);
};
const polar2cart = polar => {
const r = getR(polar);
const θ = getΘ(polar);
const x = r * Math.cos(θ);
const y = r * Math.sin(θ);
return newCartesian(x)(y);
};
const mkType = makeTypeParser({
extraPrimitives: [
["NPoint2DCartesian", NPoint2DCartesian],
["NPoint2DPolar" , NPoint2DPolar ],
],
});
const ModuleConversions = [
{ i: NPoint2DCartesian , t: mkType("NPoint2DCartesian") },
{ i: NPoint2DPolar , t: mkType("NPoint2DPolar") },
{ i: cart2polar , t: mkType("NPoint2DCartesian -> NPoint2DPolar") },
{ i: polar2cart , t: mkType("NPoint2DPolar -> NPoint2DCartesian") },
];
const examplePointCart = newCartesian(1)(2);
const examplePointPolar = newPolar(0)(5);
const ModuleExamples = [
{ i: examplePointCart , t: SPoint2DCartesian },
{ i: examplePointCart , t: NPoint2DCartesian },
{ i: examplePointPolar , t: SPoint2DPolar },
{ i: examplePointPolar , t: NPoint2DPolar },
];
export const ModuleAll = [
...ModuleCartesian,
...ModulePolar,
...ModuleConversions,
...ModuleExamples,
];