lotta progress
This commit is contained in:
parent
29d20b2273
commit
bc91d9bf39
27 changed files with 317 additions and 475 deletions
79
lib/point.js
79
lib/point.js
|
|
@ -1,65 +1,72 @@
|
|||
import { Double } from "../primitives/symbols.js";
|
||||
import { nominalType, NominalType } from "../structures/nominal_type.js";
|
||||
import { makeProductType } from "../structures/product.js";
|
||||
import { typedFnType } from "../metacircular.js";
|
||||
import { prodType } from "../structures/product.js";
|
||||
import { Type } from "../type.js";
|
||||
import { typedFnType } from "../structures/types.js"
|
||||
import { Double } from "../primitives/types.js";
|
||||
|
||||
const PointCartesian2D = nominalType(
|
||||
"PointCartesian2D")
|
||||
// just a unique number, to make sure that our type is only equal to itself
|
||||
// BigInt("0xBBAAD62B10EE21993BA690A732DA2A6875CE4B6F5E7139D5AEC9FD887F9D24A8"))
|
||||
(prodType(Double, Double));
|
||||
// Create nominal types
|
||||
export const PointCartesian2D = { symbol: Symbol('PointCartesian2D'), params: [] };
|
||||
export const PointPolar2D = { symbol: Symbol('PointPolar2D') , params: [] };
|
||||
|
||||
const PointPolar2D = nominalType(
|
||||
"PointPolar2D")
|
||||
// just a unique number, to make sure that our type is only equal to itself
|
||||
// BigInt("0x31CDAB4B3D84C4EB27D3C111FD7580E533268B72E05BD694F8B262913E018B72"))
|
||||
(prodType(Double, Double));
|
||||
|
||||
export const cart2polar = ({left: x, right: y}) => {
|
||||
export const cart2polar = ({x, y}) => {
|
||||
const r = Math.sqrt(x*x + y*y);
|
||||
const θ = Math.atan(y/x);
|
||||
return {left: r, right: θ};
|
||||
return {r, θ};
|
||||
};
|
||||
|
||||
export const polar2cart = ({left: r, right: θ}) => {
|
||||
export const polar2cart = ({r, θ}) => {
|
||||
const x = r * Math.cos(θ);
|
||||
const y = r * Math.sin(θ);
|
||||
return {left: x, right: y};
|
||||
return {x, y};
|
||||
}
|
||||
|
||||
export const translate = dx => dy => ({left: x, right: y}) => {
|
||||
export const translate = dx => dy => ({x, y}) => {
|
||||
return {left: x+dx, right: y+dy};
|
||||
}
|
||||
|
||||
export const rotate = dθ => ({left: r, right: θ}) => {
|
||||
return {left: r, right: θ+dθ};
|
||||
export const rotate = dθ => ({r, θ}) => {
|
||||
return {r, θ: θ+dθ};
|
||||
}
|
||||
|
||||
export const scale = dr => ({left: r, right: θ}) => {
|
||||
return {left: r+dr, right: θ};
|
||||
export const scale = dr => ({r, θ}) => {
|
||||
return {r: r+dr, θ};
|
||||
}
|
||||
|
||||
const examplePoint = {left: 1, right: 2};
|
||||
const examplePoint = {x: 1, y: 2};
|
||||
|
||||
export const ModulePoint = {l:[
|
||||
{i: -1 , t: Double},
|
||||
{i: 2 , t: Double},
|
||||
{i: examplePoint , t: PointCartesian2D},
|
||||
{i: examplePoint , t: prodType(Double, Double)},
|
||||
|
||||
...makeProductType(Double, Double).l,
|
||||
{i: PointCartesian2D , t: Type},
|
||||
{i: PointPolar2D , t: Type},
|
||||
|
||||
{i: PointCartesian2D , t: NominalType},
|
||||
{i: PointPolar2D , t: NominalType},
|
||||
...typedFnType(cart2polar, fnType => fnType(PointCartesian2D)(PointPolar2D)),
|
||||
|
||||
...typedFnType(cart2polar, fnType => fnType({in: PointCartesian2D, out: PointPolar2D})),
|
||||
...typedFnType(polar2cart, fnType => fnType(PointPolar2D)(PointCartesian2D)),
|
||||
|
||||
...typedFnType(polar2cart, fnType => fnType({in: PointPolar2D, out: PointCartesian2D})),
|
||||
// Double -> Double -> PointCartesian2D -> PointCartesian2D
|
||||
...typedFnType(translate, fnType =>
|
||||
fnType
|
||||
(Double)
|
||||
(fnType
|
||||
(Double)
|
||||
(fnType
|
||||
(PointCartesian2D)
|
||||
(PointCartesian2D)))),
|
||||
|
||||
...typedFnType(translate , fnType => fnType({in: Double, out: fnType({in: Double, out: fnType({in: PointCartesian2D, out: PointCartesian2D})})})),
|
||||
// Double -> PointPolar2D -> PointPolar2D
|
||||
...typedFnType(rotate, fnType =>
|
||||
fnType
|
||||
(Double)
|
||||
(fnType
|
||||
(PointPolar2D)
|
||||
(PointPolar2D))),
|
||||
|
||||
...typedFnType(rotate, fnType => fnType({in: Double, out: fnType({in: PointPolar2D, out: PointPolar2D})})),
|
||||
|
||||
...typedFnType(scale, fnType => fnType({in: Double, out: fnType({in: PointPolar2D, out: PointPolar2D})})),
|
||||
// Double -> PointPolar2D -> PointPolar2D
|
||||
...typedFnType(scale, fnType =>
|
||||
fnType
|
||||
(Double)
|
||||
(fnType
|
||||
(PointPolar2D)
|
||||
(PointPolar2D))),
|
||||
]};
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue