@nakafa/aksara-contracts 8.1.0 → 8.4.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/math/boundary.d.ts +9 -0
- package/dist/math/boundary.js +81 -0
- package/dist/math/curve.d.ts +1 -0
- package/dist/math/curve.js +4 -2
- package/dist/math/formula/affine.d.ts +22 -0
- package/dist/math/formula/affine.js +79 -0
- package/dist/math/formula/contour.js +27 -12
- package/dist/math/object.d.ts +12 -0
- package/dist/math/object.js +11 -0
- package/dist/math/plane.d.ts +10 -0
- package/dist/math/plane.js +7 -1
- package/dist/math/space.d.ts +8 -0
- package/dist/math/space.js +5 -1
- package/dist/math/visual.d.ts +239 -212
- package/dist/visual/base/math.d.ts +78 -0
- package/dist/visual/base/math.js +31 -3
- package/dist/visual/base/media.d.ts +67 -0
- package/dist/visual/biology/bacteria.d.ts +268 -0
- package/dist/visual/biology/cell.d.ts +201 -0
- package/dist/visual/biology/climate.d.ts +201 -0
- package/dist/visual/biology/ecology.d.ts +268 -0
- package/dist/visual/biology/physiology.d.ts +201 -0
- package/dist/visual/biology/plant.d.ts +335 -0
- package/dist/visual/biology.d.ts +16 -16
- package/dist/visual/biology.js +2 -2
- package/dist/visual/card.d.ts +79 -1
- package/dist/visual/card.js +18 -2
- package/dist/visual/catalog.d.ts +14808 -28
- package/dist/visual/catalog.js +26 -0
- package/dist/visual/chemistry/atom.d.ts +203 -2
- package/dist/visual/chemistry/atom.js +2 -2
- package/dist/visual/chemistry/balance.d.ts +335 -0
- package/dist/visual/chemistry/bonding.d.ts +335 -0
- package/dist/visual/chemistry/discovery.d.ts +469 -0
- package/dist/visual/chemistry/electrochemistry.d.ts +134 -0
- package/dist/visual/chemistry/electron.d.ts +134 -0
- package/dist/visual/chemistry/laws.d.ts +268 -0
- package/dist/visual/chemistry/particles.d.ts +335 -0
- package/dist/visual/chemistry/periodic.d.ts +134 -0
- package/dist/visual/chemistry/rate.d.ts +67 -0
- package/dist/visual/chemistry/reaction.d.ts +201 -0
- package/dist/visual/chemistry/titration.d.ts +67 -0
- package/dist/visual/length.d.ts +79 -0
- package/dist/visual/length.js +37 -0
- package/dist/visual/mathematics/chance.d.ts +258 -0
- package/dist/visual/mathematics/chance.js +117 -0
- package/dist/visual/mathematics/chart.d.ts +67 -0
- package/dist/visual/mathematics/charts.d.ts +335 -0
- package/dist/visual/mathematics/function.d.ts +205 -4
- package/dist/visual/mathematics/function.js +4 -4
- package/dist/visual/mathematics/geometry.d.ts +1 -1
- package/dist/visual/mathematics/geometry.js +1 -1
- package/dist/visual/mathematics/numeral.d.ts +170 -0
- package/dist/visual/mathematics/numeral.js +85 -0
- package/dist/visual/physics/braking.d.ts +268 -0
- package/dist/visual/physics/circuit.d.ts +343 -0
- package/dist/visual/physics/circuit.js +86 -0
- package/dist/visual/physics/circular.d.ts +134 -0
- package/dist/visual/physics/dynamics.d.ts +579 -0
- package/dist/visual/physics/dynamics.js +134 -0
- package/dist/visual/physics/efficiency.d.ts +402 -0
- package/dist/visual/physics/electronics.d.ts +260 -0
- package/dist/visual/physics/electronics.js +71 -0
- package/dist/visual/physics/falling.d.ts +268 -0
- package/dist/visual/physics/field.d.ts +249 -0
- package/dist/visual/physics/field.js +60 -0
- package/dist/visual/physics/fluid.d.ts +336 -0
- package/dist/visual/physics/fluid.js +83 -0
- package/dist/visual/physics/force.d.ts +335 -0
- package/dist/visual/physics/gravity.d.ts +172 -0
- package/dist/visual/physics/gravity.js +47 -0
- package/dist/visual/physics/heat.d.ts +255 -0
- package/dist/visual/physics/heat.js +66 -0
- package/dist/visual/physics/instrument.d.ts +469 -0
- package/dist/visual/physics/light.d.ts +343 -0
- package/dist/visual/physics/light.js +90 -0
- package/dist/visual/physics/measurement.d.ts +268 -0
- package/dist/visual/physics/motion.d.ts +402 -0
- package/dist/visual/physics/nuclear.d.ts +258 -0
- package/dist/visual/physics/nuclear.js +69 -0
- package/dist/visual/physics/parabolic.d.ts +69 -2
- package/dist/visual/physics/parabolic.js +2 -2
- package/dist/visual/physics/position.d.ts +402 -0
- package/dist/visual/physics/power.d.ts +536 -0
- package/dist/visual/physics/precision.d.ts +469 -0
- package/dist/visual/physics/product.d.ts +268 -0
- package/dist/visual/physics/reading.d.ts +253 -0
- package/dist/visual/physics/reading.js +61 -0
- package/dist/visual/physics/record.d.ts +134 -0
- package/dist/visual/physics/relative.d.ts +201 -0
- package/dist/visual/physics/solar.d.ts +402 -0
- package/dist/visual/physics/vector.d.ts +335 -0
- package/dist/visual/physics/velocity.d.ts +469 -0
- package/dist/visual/physics/wave.d.ts +338 -0
- package/dist/visual/physics/wave.js +85 -0
- package/dist/visual/politics.d.ts +403 -1
- package/dist/visual/politics.js +1 -1
- package/package.json +1 -1
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
import { Schema } from "effect";
|
|
2
|
+
import type { PlaneMathObject } from "#contracts/math/plane";
|
|
3
|
+
/**
|
|
4
|
+
* Guardrail G5: a line, ray, segment or straight graph that runs along the
|
|
5
|
+
* boundary of a strict inequality of a region in the same scene draws dashed. Its points are
|
|
6
|
+
* not solutions, and the region draws that edge dashed too, so a solid line
|
|
7
|
+
* on it would say the opposite of the region.
|
|
8
|
+
*/
|
|
9
|
+
export declare function strictBoundaryIssues(objects: readonly PlaneMathObject[]): readonly Schema.FilterIssue[];
|
|
@@ -0,0 +1,81 @@
|
|
|
1
|
+
import { Array as Arr, Match, Option, Result, Schema } from "effect";
|
|
2
|
+
import { readAffine } from "#contracts/math/formula/affine";
|
|
3
|
+
import { readFormula, readRelation } from "#contracts/math/formula/parse";
|
|
4
|
+
/**
|
|
5
|
+
* How far from a boundary line a point may lie and still stand on it, relative
|
|
6
|
+
* to the size of the line's terms there: room for the rounding of decimal
|
|
7
|
+
* coefficients such as 0.1, never for an authored approximation such as 3.33.
|
|
8
|
+
*/
|
|
9
|
+
const ON_LINE_TOLERANCE = 1e-9;
|
|
10
|
+
/**
|
|
11
|
+
* The boundary of one strict linear inequality of a region, `a x + b y + c = 0`,
|
|
12
|
+
* with the inequality as its author wrote it.
|
|
13
|
+
*/
|
|
14
|
+
const StrictBoundarySchema = Schema.Struct({
|
|
15
|
+
a: Schema.Finite,
|
|
16
|
+
b: Schema.Finite,
|
|
17
|
+
c: Schema.Finite,
|
|
18
|
+
inequality: Schema.String,
|
|
19
|
+
});
|
|
20
|
+
/** The boundary of an inequality when it is strict and linear in x and y. */
|
|
21
|
+
function strictBoundary(inequality) {
|
|
22
|
+
return Result.getSuccess(readRelation(inequality)).pipe(Option.filter(({ comparison }) => comparison === "<" || comparison === ">"), Option.flatMap(({ left, right }) => readAffine({ kind: "binary", left, operator: "-", right }, ["x", "y"])), Option.flatMap(({ constant, terms }) => {
|
|
23
|
+
const a = terms.x ?? 0;
|
|
24
|
+
const b = terms.y ?? 0;
|
|
25
|
+
return a === 0 && b === 0
|
|
26
|
+
? Option.none()
|
|
27
|
+
: Option.some({ a, b, c: constant, inequality });
|
|
28
|
+
}));
|
|
29
|
+
}
|
|
30
|
+
/** Whether a point stands on a boundary line. */
|
|
31
|
+
function onLine({ a, b, c }, { x, y }) {
|
|
32
|
+
const value = a * x + b * y + c;
|
|
33
|
+
const size = Math.abs(a * x) + Math.abs(b * y) + Math.abs(c);
|
|
34
|
+
return Math.abs(value) <= ON_LINE_TOLERANCE * Math.max(1, size);
|
|
35
|
+
}
|
|
36
|
+
/** Two points of a graph that is a straight line: an affine formula in its input axis. */
|
|
37
|
+
function straightGraph(formula, input) {
|
|
38
|
+
return Result.getSuccess(readFormula(formula)).pipe(Option.flatMap((node) => readAffine(node, [input])), Option.map(({ constant, terms }) => {
|
|
39
|
+
const slope = terms[input] ?? 0;
|
|
40
|
+
/** The graph's point at one value of its input. */
|
|
41
|
+
const at = (value) => input === "x"
|
|
42
|
+
? { x: value, y: slope * value + constant }
|
|
43
|
+
: { x: slope * value + constant, y: value };
|
|
44
|
+
return [at(0), at(1)];
|
|
45
|
+
}));
|
|
46
|
+
}
|
|
47
|
+
/** Two points of a straight object: a line, ray, segment or straight graph. */
|
|
48
|
+
function straightPoints(object) {
|
|
49
|
+
return Match.value(object).pipe(Match.discriminators("kind")({
|
|
50
|
+
function: ({ formula, inputAxis = "x" }) => straightGraph(formula, inputAxis),
|
|
51
|
+
line: ({ through }) => Option.some(through),
|
|
52
|
+
ray: ({ from, through }) => Option.some([from, through]),
|
|
53
|
+
segment: ({ from, to }) => Option.some([from, to]),
|
|
54
|
+
}), Match.orElse(() => Option.none()));
|
|
55
|
+
}
|
|
56
|
+
/** Two points of a straight object drawn solid, which a strict boundary may not hold. */
|
|
57
|
+
function solidStraight(object) {
|
|
58
|
+
return "stroke" in object && object.stroke !== undefined
|
|
59
|
+
? Option.none()
|
|
60
|
+
: straightPoints(object);
|
|
61
|
+
}
|
|
62
|
+
/**
|
|
63
|
+
* Guardrail G5: a line, ray, segment or straight graph that runs along the
|
|
64
|
+
* boundary of a strict inequality of a region in the same scene draws dashed. Its points are
|
|
65
|
+
* not solutions, and the region draws that edge dashed too, so a solid line
|
|
66
|
+
* on it would say the opposite of the region.
|
|
67
|
+
*/
|
|
68
|
+
export function strictBoundaryIssues(objects) {
|
|
69
|
+
const boundaries = Arr.flatMap(objects, (object) => object.kind === "region"
|
|
70
|
+
? Arr.getSomes(Arr.map(object.inequalities, strictBoundary))
|
|
71
|
+
: []);
|
|
72
|
+
return Arr.flatMap(objects, (object, index) => solidStraight(object).pipe(Option.flatMap(([from, to]) => Arr.findFirst(boundaries, (boundary) => onLine(boundary, from) && onLine(boundary, to))), Option.match({
|
|
73
|
+
onNone: () => [],
|
|
74
|
+
onSome: ({ inequality }) => [
|
|
75
|
+
{
|
|
76
|
+
issue: `Expected the ${object.kind === "function" ? "graph" : object.kind} on the boundary of the strict inequality "${inequality}" to be dashed (stroke: "dashed"): the points on it are not solutions.`,
|
|
77
|
+
path: ["objects", index],
|
|
78
|
+
},
|
|
79
|
+
],
|
|
80
|
+
})));
|
|
81
|
+
}
|
package/dist/math/curve.d.ts
CHANGED
|
@@ -3,6 +3,7 @@ import { Schema } from "effect";
|
|
|
3
3
|
export declare const PlaneCurveObjectSchemas: readonly [Schema.Struct<{
|
|
4
4
|
readonly appearance: Schema.Literals<readonly ["answer", "construction", "highlight", "primary", "reference", "secondary", "warning"]>;
|
|
5
5
|
readonly id: Schema.String;
|
|
6
|
+
readonly stroke: Schema.optionalKey<Schema.Literals<readonly ["dashed"]>>;
|
|
6
7
|
readonly domain: Schema.optionalKey<Schema.Struct<{
|
|
7
8
|
readonly max: Schema.Finite;
|
|
8
9
|
readonly min: Schema.Finite;
|
package/dist/math/curve.js
CHANGED
|
@@ -1,15 +1,17 @@
|
|
|
1
1
|
import { Schema } from "effect";
|
|
2
2
|
import { MathAxisRangeSchema } from "#contracts/math/base";
|
|
3
3
|
import { EquationTextSchema, FormulaTextSchema, InequalityTextSchema, PlaneFormulaPointSchema, } from "#contracts/math/formula/field";
|
|
4
|
-
import { MathObjectFields } from "#contracts/math/object";
|
|
4
|
+
import { MathObjectFields, MathStrokeFields } from "#contracts/math/object";
|
|
5
5
|
/**
|
|
6
6
|
* The graph of y = f(x), or of x = f(y) when its input axis is y. The renderer
|
|
7
7
|
* samples it inside the frame, at least 200 times per visible branch, exactly
|
|
8
8
|
* at its domain ends and labels, and splits it at every break and asymptote.
|
|
9
|
-
* Without a domain it spans the frame along its input axis.
|
|
9
|
+
* Without a domain it spans the frame along its input axis. A straight graph
|
|
10
|
+
* on the boundary of a strict inequality draws dashed (`MathStrokeSchema`).
|
|
10
11
|
*/
|
|
11
12
|
const PlaneFunctionObjectSchema = Schema.Struct({
|
|
12
13
|
...MathObjectFields,
|
|
14
|
+
...MathStrokeFields,
|
|
13
15
|
domain: Schema.optionalKey(MathAxisRangeSchema),
|
|
14
16
|
formula: FormulaTextSchema,
|
|
15
17
|
inputAxis: Schema.optionalKey(Schema.Literals(["x", "y"])),
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
import { Option, Schema } from "effect";
|
|
2
|
+
import type { FormulaNode } from "#contracts/math/formula/syntax";
|
|
3
|
+
/**
|
|
4
|
+
* An affine expression: a constant plus one coefficient for each variable it
|
|
5
|
+
* reads, such as `2x + 5y - 10`, read as 2 for x, 5 for y and -10.
|
|
6
|
+
*/
|
|
7
|
+
export declare const AffineSchema: Schema.Struct<{
|
|
8
|
+
readonly constant: Schema.Finite;
|
|
9
|
+
readonly terms: Schema.$Record<Schema.String, Schema.Finite>;
|
|
10
|
+
}>;
|
|
11
|
+
export type Affine = typeof AffineSchema.Type;
|
|
12
|
+
/** The value of an affine expression that reads no variable, if it reads none. */
|
|
13
|
+
export declare function affineConstant(affine: Affine): Option.None<number> | Option.Some<number>;
|
|
14
|
+
/**
|
|
15
|
+
* Reads a formula as an affine expression in the given variables, from its
|
|
16
|
+
* syntax and without sampling it: sums, differences and constant multiples of
|
|
17
|
+
* the variables, with any part that reads no name folded to its value. A
|
|
18
|
+
* formula that multiplies two variables, divides by one, or calls a function
|
|
19
|
+
* of one is not affine, and neither is one that reads any other name, such as
|
|
20
|
+
* a slider's parameter, whose value changes as the reader moves it.
|
|
21
|
+
*/
|
|
22
|
+
export declare function readAffine(node: FormulaNode, variables: readonly string[]): Option.Option<Affine>;
|
|
@@ -0,0 +1,79 @@
|
|
|
1
|
+
import { Array as Arr, Match, Option, Record as Rec, Schema } from "effect";
|
|
2
|
+
import { compileFormula } from "#contracts/math/formula/compile";
|
|
3
|
+
/**
|
|
4
|
+
* An affine expression: a constant plus one coefficient for each variable it
|
|
5
|
+
* reads, such as `2x + 5y - 10`, read as 2 for x, 5 for y and -10.
|
|
6
|
+
*/
|
|
7
|
+
export const AffineSchema = Schema.Struct({
|
|
8
|
+
constant: Schema.Finite,
|
|
9
|
+
terms: Schema.Record(Schema.String, Schema.Finite),
|
|
10
|
+
});
|
|
11
|
+
/** An expression that reads no variable. */
|
|
12
|
+
function constant(value) {
|
|
13
|
+
return { constant: value, terms: {} };
|
|
14
|
+
}
|
|
15
|
+
/** Multiplies every part of an affine expression by one number. */
|
|
16
|
+
function scale(affine, factor) {
|
|
17
|
+
return {
|
|
18
|
+
constant: affine.constant * factor,
|
|
19
|
+
terms: Rec.map(affine.terms, (coefficient) => coefficient * factor),
|
|
20
|
+
};
|
|
21
|
+
}
|
|
22
|
+
/** Adds two affine expressions, or subtracts the second when `sign` is -1. */
|
|
23
|
+
function combine(left, right, sign) {
|
|
24
|
+
const names = Arr.dedupe([...Rec.keys(left.terms), ...Rec.keys(right.terms)]);
|
|
25
|
+
return {
|
|
26
|
+
constant: left.constant + sign * right.constant,
|
|
27
|
+
terms: Rec.fromEntries(Arr.map(names, (name) => [
|
|
28
|
+
name,
|
|
29
|
+
(left.terms[name] ?? 0) + sign * (right.terms[name] ?? 0),
|
|
30
|
+
])),
|
|
31
|
+
};
|
|
32
|
+
}
|
|
33
|
+
/** The value of an affine expression that reads no variable, if it reads none. */
|
|
34
|
+
export function affineConstant(affine) {
|
|
35
|
+
return Arr.every(Rec.values(affine.terms), (coefficient) => coefficient === 0)
|
|
36
|
+
? Option.some(affine.constant)
|
|
37
|
+
: Option.none();
|
|
38
|
+
}
|
|
39
|
+
/** Reads a product, which stays affine while one side is a constant. */
|
|
40
|
+
function product(left, right) {
|
|
41
|
+
return Option.orElse(Option.map(affineConstant(left), (factor) => scale(right, factor)), () => Option.map(affineConstant(right), (factor) => scale(left, factor)));
|
|
42
|
+
}
|
|
43
|
+
/** Reads a quotient, which stays affine while its divisor is a constant other than zero. */
|
|
44
|
+
function quotient(left, right) {
|
|
45
|
+
return Option.flatMap(affineConstant(right), (divisor) => divisor === 0 ? Option.none() : Option.some(scale(left, 1 / divisor)));
|
|
46
|
+
}
|
|
47
|
+
/** How each operator combines two affine expressions, while the result stays affine. */
|
|
48
|
+
const OPERATORS = {
|
|
49
|
+
"-": (left, right) => Option.some(combine(left, right, -1)),
|
|
50
|
+
"*": product,
|
|
51
|
+
"/": quotient,
|
|
52
|
+
// Only a power of one keeps a variable affine.
|
|
53
|
+
"^": (left, right) => Option.filter(affineConstant(right), (power) => power === 1).pipe(Option.as(left)),
|
|
54
|
+
"+": (left, right) => Option.some(combine(left, right, 1)),
|
|
55
|
+
};
|
|
56
|
+
/**
|
|
57
|
+
* Reads a formula as an affine expression in the given variables, from its
|
|
58
|
+
* syntax and without sampling it: sums, differences and constant multiples of
|
|
59
|
+
* the variables, with any part that reads no name folded to its value. A
|
|
60
|
+
* formula that multiplies two variables, divides by one, or calls a function
|
|
61
|
+
* of one is not affine, and neither is one that reads any other name, such as
|
|
62
|
+
* a slider's parameter, whose value changes as the reader moves it.
|
|
63
|
+
*/
|
|
64
|
+
export function readAffine(node, variables) {
|
|
65
|
+
const value = compileFormula(node)({});
|
|
66
|
+
if (Number.isFinite(value)) {
|
|
67
|
+
return Option.some(constant(value));
|
|
68
|
+
}
|
|
69
|
+
return Match.value(node).pipe(Match.discriminators("kind")({
|
|
70
|
+
binary: ({ left, operator, right }) => Option.flatMap(Option.all([
|
|
71
|
+
readAffine(left, variables),
|
|
72
|
+
readAffine(right, variables),
|
|
73
|
+
]), ([first, second]) => OPERATORS[operator](first, second)),
|
|
74
|
+
name: ({ name }) => Arr.contains(variables, name)
|
|
75
|
+
? Option.some({ constant: 0, terms: { [name]: 1 } })
|
|
76
|
+
: Option.none(),
|
|
77
|
+
negate: ({ operand }) => Option.map(readAffine(operand, variables), (read) => scale(read, -1)),
|
|
78
|
+
}), Match.orElse(() => Option.none()));
|
|
79
|
+
}
|
|
@@ -99,7 +99,12 @@ function cellSegments(field, cell) {
|
|
|
99
99
|
},
|
|
100
100
|
});
|
|
101
101
|
}
|
|
102
|
-
/**
|
|
102
|
+
/**
|
|
103
|
+
* Joins segments that share an edge crossing into continuous polylines. A
|
|
104
|
+
* line grows from its first segment in both directions: the grid lists cells
|
|
105
|
+
* column by column, so a segment found first may lie in the middle of its
|
|
106
|
+
* curve, and its two ends may point either way along it.
|
|
107
|
+
*/
|
|
103
108
|
function join(segments) {
|
|
104
109
|
const byKey = MutableHashMap.empty();
|
|
105
110
|
Arr.forEach(segments, (segment) => {
|
|
@@ -109,15 +114,10 @@ function join(segments) {
|
|
|
109
114
|
}
|
|
110
115
|
});
|
|
111
116
|
const used = MutableHashSet.empty();
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
MutableHashSet.add(used, start.index);
|
|
117
|
-
const line = MutableList.make();
|
|
118
|
-
MutableList.append(line, start.from.point);
|
|
119
|
-
MutableList.append(line, start.to.point);
|
|
120
|
-
let { key } = start.to;
|
|
117
|
+
/** The points of the unused segments that continue a line from one crossing, in order. */
|
|
118
|
+
const follow = (from) => {
|
|
119
|
+
const points = MutableList.make();
|
|
120
|
+
let key = from;
|
|
121
121
|
let next = Option.none();
|
|
122
122
|
do {
|
|
123
123
|
next = Arr.findFirst(Arr.flatten(Option.toArray(MutableHashMap.get(byKey, key))), (segment) => !MutableHashSet.has(used, segment.index));
|
|
@@ -125,11 +125,26 @@ function join(segments) {
|
|
|
125
125
|
const segment = next.value;
|
|
126
126
|
MutableHashSet.add(used, segment.index);
|
|
127
127
|
const forward = segment.from.key === key;
|
|
128
|
-
MutableList.append(
|
|
128
|
+
MutableList.append(points, forward ? segment.to.point : segment.from.point);
|
|
129
129
|
key = forward ? segment.to.key : segment.from.key;
|
|
130
130
|
}
|
|
131
131
|
} while (Option.isSome(next));
|
|
132
|
-
return
|
|
132
|
+
return MutableList.toArray(points);
|
|
133
|
+
};
|
|
134
|
+
return Arr.filterMap(segments, (start) => {
|
|
135
|
+
if (MutableHashSet.has(used, start.index)) {
|
|
136
|
+
return Result.failVoid;
|
|
137
|
+
}
|
|
138
|
+
MutableHashSet.add(used, start.index);
|
|
139
|
+
// A closed curve comes back to the start ahead, which leaves nothing behind it.
|
|
140
|
+
const ahead = follow(start.to.key);
|
|
141
|
+
const behind = follow(start.from.key);
|
|
142
|
+
return Result.succeed([
|
|
143
|
+
...Arr.reverse(behind),
|
|
144
|
+
start.from.point,
|
|
145
|
+
start.to.point,
|
|
146
|
+
...ahead,
|
|
147
|
+
]);
|
|
133
148
|
});
|
|
134
149
|
}
|
|
135
150
|
/**
|
package/dist/math/object.d.ts
CHANGED
|
@@ -4,6 +4,18 @@ export declare const MathObjectFields: {
|
|
|
4
4
|
appearance: Schema.Literals<readonly ["answer", "construction", "highlight", "primary", "reference", "secondary", "warning"]>;
|
|
5
5
|
id: Schema.String;
|
|
6
6
|
};
|
|
7
|
+
/**
|
|
8
|
+
* How a straight object draws its line when not solid. `dashed` marks points
|
|
9
|
+
* that do not belong to what the line shows, such as the boundary of a strict
|
|
10
|
+
* inequality: the points on `2x + 5y = 10` are not solutions of
|
|
11
|
+
* `2x + 5y < 10`. A line without a stroke is solid.
|
|
12
|
+
*/
|
|
13
|
+
export declare const MathStrokeSchema: Schema.Literals<readonly ["dashed"]>;
|
|
14
|
+
export type MathStroke = typeof MathStrokeSchema.Type;
|
|
15
|
+
/** Fields of an object drawn as one stroke: a line, ray, segment, polyline or graph. */
|
|
16
|
+
export declare const MathStrokeFields: {
|
|
17
|
+
stroke: Schema.optionalKey<Schema.Literals<readonly ["dashed"]>>;
|
|
18
|
+
};
|
|
7
19
|
/**
|
|
8
20
|
* Fields that every rich-label anchor shares. Each dimension supplies its own
|
|
9
21
|
* point schema, so the struct built from these fields stays fully typed.
|
package/dist/math/object.js
CHANGED
|
@@ -5,6 +5,17 @@ export const MathObjectFields = {
|
|
|
5
5
|
appearance: MathAppearanceSchema,
|
|
6
6
|
id: MathVisualKeySchema,
|
|
7
7
|
};
|
|
8
|
+
/**
|
|
9
|
+
* How a straight object draws its line when not solid. `dashed` marks points
|
|
10
|
+
* that do not belong to what the line shows, such as the boundary of a strict
|
|
11
|
+
* inequality: the points on `2x + 5y = 10` are not solutions of
|
|
12
|
+
* `2x + 5y < 10`. A line without a stroke is solid.
|
|
13
|
+
*/
|
|
14
|
+
export const MathStrokeSchema = Schema.Literals(["dashed"]);
|
|
15
|
+
/** Fields of an object drawn as one stroke: a line, ray, segment, polyline or graph. */
|
|
16
|
+
export const MathStrokeFields = {
|
|
17
|
+
stroke: Schema.optionalKey(MathStrokeSchema),
|
|
18
|
+
};
|
|
8
19
|
/**
|
|
9
20
|
* Fields that every rich-label anchor shares. Each dimension supplies its own
|
|
10
21
|
* point schema, so the struct built from these fields stays fully typed.
|
package/dist/math/plane.d.ts
CHANGED
|
@@ -3,6 +3,7 @@ import { Schema } from "effect";
|
|
|
3
3
|
export declare const PlaneMathObjectSchema: Schema.Union<readonly [Schema.Struct<{
|
|
4
4
|
readonly appearance: Schema.Literals<readonly ["answer", "construction", "highlight", "primary", "reference", "secondary", "warning"]>;
|
|
5
5
|
readonly id: Schema.String;
|
|
6
|
+
readonly stroke: Schema.optionalKey<Schema.Literals<readonly ["dashed"]>>;
|
|
6
7
|
readonly domain: Schema.optionalKey<Schema.Struct<{
|
|
7
8
|
readonly max: Schema.Finite;
|
|
8
9
|
readonly min: Schema.Finite;
|
|
@@ -84,6 +85,7 @@ export declare const PlaneMathObjectSchema: Schema.Union<readonly [Schema.Struct
|
|
|
84
85
|
}>, Schema.Struct<{
|
|
85
86
|
readonly appearance: Schema.Literals<readonly ["answer", "construction", "highlight", "primary", "reference", "secondary", "warning"]>;
|
|
86
87
|
readonly id: Schema.String;
|
|
88
|
+
readonly stroke: Schema.optionalKey<Schema.Literals<readonly ["dashed"]>>;
|
|
87
89
|
readonly kind: Schema.Literal<"line">;
|
|
88
90
|
readonly through: Schema.Tuple<readonly [Schema.Struct<{
|
|
89
91
|
readonly x: Schema.Finite;
|
|
@@ -120,6 +122,7 @@ export declare const PlaneMathObjectSchema: Schema.Union<readonly [Schema.Struct
|
|
|
120
122
|
}>, Schema.Struct<{
|
|
121
123
|
readonly appearance: Schema.Literals<readonly ["answer", "construction", "highlight", "primary", "reference", "secondary", "warning"]>;
|
|
122
124
|
readonly id: Schema.String;
|
|
125
|
+
readonly stroke: Schema.optionalKey<Schema.Literals<readonly ["dashed"]>>;
|
|
123
126
|
readonly kind: Schema.Literal<"polyline">;
|
|
124
127
|
readonly vertices: Schema.TupleWithRest<Schema.Tuple<readonly [Schema.Struct<{
|
|
125
128
|
readonly x: Schema.Finite;
|
|
@@ -148,6 +151,7 @@ export declare const PlaneMathObjectSchema: Schema.Union<readonly [Schema.Struct
|
|
|
148
151
|
}>, Schema.Struct<{
|
|
149
152
|
readonly appearance: Schema.Literals<readonly ["answer", "construction", "highlight", "primary", "reference", "secondary", "warning"]>;
|
|
150
153
|
readonly id: Schema.String;
|
|
154
|
+
readonly stroke: Schema.optionalKey<Schema.Literals<readonly ["dashed"]>>;
|
|
151
155
|
readonly from: Schema.Struct<{
|
|
152
156
|
readonly x: Schema.Finite;
|
|
153
157
|
readonly y: Schema.Finite;
|
|
@@ -160,6 +164,7 @@ export declare const PlaneMathObjectSchema: Schema.Union<readonly [Schema.Struct
|
|
|
160
164
|
}>, Schema.Struct<{
|
|
161
165
|
readonly appearance: Schema.Literals<readonly ["answer", "construction", "highlight", "primary", "reference", "secondary", "warning"]>;
|
|
162
166
|
readonly id: Schema.String;
|
|
167
|
+
readonly stroke: Schema.optionalKey<Schema.Literals<readonly ["dashed"]>>;
|
|
163
168
|
readonly from: Schema.Struct<{
|
|
164
169
|
readonly x: Schema.Finite;
|
|
165
170
|
readonly y: Schema.Finite;
|
|
@@ -247,6 +252,7 @@ export declare const PlaneMathVisualSchema: Schema.Struct<{
|
|
|
247
252
|
readonly objects: Schema.NonEmptyArray<Schema.Union<readonly [Schema.Struct<{
|
|
248
253
|
readonly appearance: Schema.Literals<readonly ["answer", "construction", "highlight", "primary", "reference", "secondary", "warning"]>;
|
|
249
254
|
readonly id: Schema.String;
|
|
255
|
+
readonly stroke: Schema.optionalKey<Schema.Literals<readonly ["dashed"]>>;
|
|
250
256
|
readonly domain: Schema.optionalKey<Schema.Struct<{
|
|
251
257
|
readonly max: Schema.Finite;
|
|
252
258
|
readonly min: Schema.Finite;
|
|
@@ -328,6 +334,7 @@ export declare const PlaneMathVisualSchema: Schema.Struct<{
|
|
|
328
334
|
}>, Schema.Struct<{
|
|
329
335
|
readonly appearance: Schema.Literals<readonly ["answer", "construction", "highlight", "primary", "reference", "secondary", "warning"]>;
|
|
330
336
|
readonly id: Schema.String;
|
|
337
|
+
readonly stroke: Schema.optionalKey<Schema.Literals<readonly ["dashed"]>>;
|
|
331
338
|
readonly kind: Schema.Literal<"line">;
|
|
332
339
|
readonly through: Schema.Tuple<readonly [Schema.Struct<{
|
|
333
340
|
readonly x: Schema.Finite;
|
|
@@ -364,6 +371,7 @@ export declare const PlaneMathVisualSchema: Schema.Struct<{
|
|
|
364
371
|
}>, Schema.Struct<{
|
|
365
372
|
readonly appearance: Schema.Literals<readonly ["answer", "construction", "highlight", "primary", "reference", "secondary", "warning"]>;
|
|
366
373
|
readonly id: Schema.String;
|
|
374
|
+
readonly stroke: Schema.optionalKey<Schema.Literals<readonly ["dashed"]>>;
|
|
367
375
|
readonly kind: Schema.Literal<"polyline">;
|
|
368
376
|
readonly vertices: Schema.TupleWithRest<Schema.Tuple<readonly [Schema.Struct<{
|
|
369
377
|
readonly x: Schema.Finite;
|
|
@@ -392,6 +400,7 @@ export declare const PlaneMathVisualSchema: Schema.Struct<{
|
|
|
392
400
|
}>, Schema.Struct<{
|
|
393
401
|
readonly appearance: Schema.Literals<readonly ["answer", "construction", "highlight", "primary", "reference", "secondary", "warning"]>;
|
|
394
402
|
readonly id: Schema.String;
|
|
403
|
+
readonly stroke: Schema.optionalKey<Schema.Literals<readonly ["dashed"]>>;
|
|
395
404
|
readonly from: Schema.Struct<{
|
|
396
405
|
readonly x: Schema.Finite;
|
|
397
406
|
readonly y: Schema.Finite;
|
|
@@ -404,6 +413,7 @@ export declare const PlaneMathVisualSchema: Schema.Struct<{
|
|
|
404
413
|
}>, Schema.Struct<{
|
|
405
414
|
readonly appearance: Schema.Literals<readonly ["answer", "construction", "highlight", "primary", "reference", "secondary", "warning"]>;
|
|
406
415
|
readonly id: Schema.String;
|
|
416
|
+
readonly stroke: Schema.optionalKey<Schema.Literals<readonly ["dashed"]>>;
|
|
407
417
|
readonly from: Schema.Struct<{
|
|
408
418
|
readonly x: Schema.Finite;
|
|
409
419
|
readonly y: Schema.Finite;
|
package/dist/math/plane.js
CHANGED
|
@@ -1,11 +1,12 @@
|
|
|
1
1
|
import { Array as Arr, Schema } from "effect";
|
|
2
2
|
import { ArcStartDegreesSchema, ArcSweepDegreesSchema, GEOMETRY_TOLERANCE, hasUniquePositions, MathAxisRangeSchema, MathViewPaddingSchema, mathVisualIdentityIssues, PlanePointSchema, PositiveMeasureSchema, samePlanePoint, } from "#contracts/math/base";
|
|
3
|
+
import { strictBoundaryIssues } from "#contracts/math/boundary";
|
|
3
4
|
import { planeBoundsIssues } from "#contracts/math/bounds";
|
|
4
5
|
import { PlaneCurveObjectSchemas } from "#contracts/math/curve";
|
|
5
6
|
import { FormulaParameterSchema, FormulaReadoutSchema, PlaneFormulaPointSchema, } from "#contracts/math/formula/field";
|
|
6
7
|
import { formulaScopeIssues, parameterScope, planeFormulaFields, } from "#contracts/math/formula/scope";
|
|
7
8
|
import { sliderFormulaIssues } from "#contracts/math/formula/slider";
|
|
8
|
-
import { MATH_LINE_MESSAGE, MATH_POLYLINE_MESSAGE, MATH_RAY_MESSAGE, MATH_SEGMENT_MESSAGE, MATH_VECTOR_MESSAGE, MathObjectFields, mathLabelAnchorFields, } from "#contracts/math/object";
|
|
9
|
+
import { MATH_LINE_MESSAGE, MATH_POLYLINE_MESSAGE, MATH_RAY_MESSAGE, MATH_SEGMENT_MESSAGE, MATH_VECTOR_MESSAGE, MathObjectFields, MathStrokeFields, mathLabelAnchorFields, } from "#contracts/math/object";
|
|
9
10
|
import { planeResolutionIssues } from "#contracts/math/resolution";
|
|
10
11
|
/** Checks a plane polygon has non-zero signed area. */
|
|
11
12
|
function hasPlaneArea(vertices) {
|
|
@@ -55,6 +56,7 @@ const PlanePathSchema = Schema.TupleWithRest(Schema.Tuple([PlanePointSchema, Pla
|
|
|
55
56
|
const PlaneShapeSchema = Schema.TupleWithRest(Schema.Tuple([PlanePointSchema, PlanePointSchema, PlanePointSchema]), [PlanePointSchema]);
|
|
56
57
|
const PlaneLineObjectSchema = Schema.Struct({
|
|
57
58
|
...MathObjectFields,
|
|
59
|
+
...MathStrokeFields,
|
|
58
60
|
kind: Schema.Literal("line"),
|
|
59
61
|
through: Schema.Tuple([PlanePointSchema, PlanePointSchema]),
|
|
60
62
|
}).pipe(Schema.check(Schema.makeFilter(({ through: [from, to] }) => !samePlanePoint(from, to), {
|
|
@@ -62,6 +64,7 @@ const PlaneLineObjectSchema = Schema.Struct({
|
|
|
62
64
|
})));
|
|
63
65
|
const PlaneRayObjectSchema = Schema.Struct({
|
|
64
66
|
...MathObjectFields,
|
|
67
|
+
...MathStrokeFields,
|
|
65
68
|
from: PlanePointSchema,
|
|
66
69
|
kind: Schema.Literal("ray"),
|
|
67
70
|
through: PlanePointSchema,
|
|
@@ -70,6 +73,7 @@ const PlaneRayObjectSchema = Schema.Struct({
|
|
|
70
73
|
})));
|
|
71
74
|
const PlaneSegmentObjectSchema = Schema.Struct({
|
|
72
75
|
...MathObjectFields,
|
|
76
|
+
...MathStrokeFields,
|
|
73
77
|
from: PlanePointSchema,
|
|
74
78
|
kind: Schema.Literal("segment"),
|
|
75
79
|
to: PlanePointSchema,
|
|
@@ -90,6 +94,7 @@ const PlaneVectorObjectSchema = Schema.Struct({
|
|
|
90
94
|
})));
|
|
91
95
|
const PlanePolylineObjectSchema = Schema.Struct({
|
|
92
96
|
...MathObjectFields,
|
|
97
|
+
...MathStrokeFields,
|
|
93
98
|
kind: Schema.Literal("polyline"),
|
|
94
99
|
vertices: PlanePathSchema,
|
|
95
100
|
}).pipe(Schema.check(Schema.makeFilter(({ vertices }) => hasUniquePositions(vertices, samePlanePoint), { message: MATH_POLYLINE_MESSAGE })));
|
|
@@ -170,4 +175,5 @@ export const PlaneMathVisualSchema = Schema.Struct({
|
|
|
170
175
|
...sliderFormulaIssues(labels, readouts, parameters),
|
|
171
176
|
...planeBoundsIssues(frame, objects, labels, parameterScope(parameters)),
|
|
172
177
|
...planeResolutionIssues(frame, objects, labels, view),
|
|
178
|
+
...strictBoundaryIssues(objects),
|
|
173
179
|
])));
|
package/dist/math/space.d.ts
CHANGED
|
@@ -120,6 +120,7 @@ export declare const SpaceMathObjectSchema: Schema.Union<readonly [Schema.Struct
|
|
|
120
120
|
}>, Schema.Struct<{
|
|
121
121
|
readonly appearance: Schema.Literals<readonly ["answer", "construction", "highlight", "primary", "reference", "secondary", "warning"]>;
|
|
122
122
|
readonly id: Schema.String;
|
|
123
|
+
readonly stroke: Schema.optionalKey<Schema.Literals<readonly ["dashed"]>>;
|
|
123
124
|
readonly kind: Schema.Literal<"line">;
|
|
124
125
|
readonly through: Schema.Tuple<readonly [Schema.Struct<{
|
|
125
126
|
readonly x: Schema.Finite;
|
|
@@ -163,6 +164,7 @@ export declare const SpaceMathObjectSchema: Schema.Union<readonly [Schema.Struct
|
|
|
163
164
|
}>, Schema.Struct<{
|
|
164
165
|
readonly appearance: Schema.Literals<readonly ["answer", "construction", "highlight", "primary", "reference", "secondary", "warning"]>;
|
|
165
166
|
readonly id: Schema.String;
|
|
167
|
+
readonly stroke: Schema.optionalKey<Schema.Literals<readonly ["dashed"]>>;
|
|
166
168
|
readonly kind: Schema.Literal<"polyline">;
|
|
167
169
|
readonly vertices: Schema.TupleWithRest<Schema.Tuple<readonly [Schema.Struct<{
|
|
168
170
|
readonly x: Schema.Finite;
|
|
@@ -180,6 +182,7 @@ export declare const SpaceMathObjectSchema: Schema.Union<readonly [Schema.Struct
|
|
|
180
182
|
}>, Schema.Struct<{
|
|
181
183
|
readonly appearance: Schema.Literals<readonly ["answer", "construction", "highlight", "primary", "reference", "secondary", "warning"]>;
|
|
182
184
|
readonly id: Schema.String;
|
|
185
|
+
readonly stroke: Schema.optionalKey<Schema.Literals<readonly ["dashed"]>>;
|
|
183
186
|
readonly from: Schema.Struct<{
|
|
184
187
|
readonly x: Schema.Finite;
|
|
185
188
|
readonly y: Schema.Finite;
|
|
@@ -194,6 +197,7 @@ export declare const SpaceMathObjectSchema: Schema.Union<readonly [Schema.Struct
|
|
|
194
197
|
}>, Schema.Struct<{
|
|
195
198
|
readonly appearance: Schema.Literals<readonly ["answer", "construction", "highlight", "primary", "reference", "secondary", "warning"]>;
|
|
196
199
|
readonly id: Schema.String;
|
|
200
|
+
readonly stroke: Schema.optionalKey<Schema.Literals<readonly ["dashed"]>>;
|
|
197
201
|
readonly from: Schema.Struct<{
|
|
198
202
|
readonly x: Schema.Finite;
|
|
199
203
|
readonly y: Schema.Finite;
|
|
@@ -422,6 +426,7 @@ export declare const SpaceMathVisualSchema: Schema.Struct<{
|
|
|
422
426
|
}>, Schema.Struct<{
|
|
423
427
|
readonly appearance: Schema.Literals<readonly ["answer", "construction", "highlight", "primary", "reference", "secondary", "warning"]>;
|
|
424
428
|
readonly id: Schema.String;
|
|
429
|
+
readonly stroke: Schema.optionalKey<Schema.Literals<readonly ["dashed"]>>;
|
|
425
430
|
readonly kind: Schema.Literal<"line">;
|
|
426
431
|
readonly through: Schema.Tuple<readonly [Schema.Struct<{
|
|
427
432
|
readonly x: Schema.Finite;
|
|
@@ -465,6 +470,7 @@ export declare const SpaceMathVisualSchema: Schema.Struct<{
|
|
|
465
470
|
}>, Schema.Struct<{
|
|
466
471
|
readonly appearance: Schema.Literals<readonly ["answer", "construction", "highlight", "primary", "reference", "secondary", "warning"]>;
|
|
467
472
|
readonly id: Schema.String;
|
|
473
|
+
readonly stroke: Schema.optionalKey<Schema.Literals<readonly ["dashed"]>>;
|
|
468
474
|
readonly kind: Schema.Literal<"polyline">;
|
|
469
475
|
readonly vertices: Schema.TupleWithRest<Schema.Tuple<readonly [Schema.Struct<{
|
|
470
476
|
readonly x: Schema.Finite;
|
|
@@ -482,6 +488,7 @@ export declare const SpaceMathVisualSchema: Schema.Struct<{
|
|
|
482
488
|
}>, Schema.Struct<{
|
|
483
489
|
readonly appearance: Schema.Literals<readonly ["answer", "construction", "highlight", "primary", "reference", "secondary", "warning"]>;
|
|
484
490
|
readonly id: Schema.String;
|
|
491
|
+
readonly stroke: Schema.optionalKey<Schema.Literals<readonly ["dashed"]>>;
|
|
485
492
|
readonly from: Schema.Struct<{
|
|
486
493
|
readonly x: Schema.Finite;
|
|
487
494
|
readonly y: Schema.Finite;
|
|
@@ -496,6 +503,7 @@ export declare const SpaceMathVisualSchema: Schema.Struct<{
|
|
|
496
503
|
}>, Schema.Struct<{
|
|
497
504
|
readonly appearance: Schema.Literals<readonly ["answer", "construction", "highlight", "primary", "reference", "secondary", "warning"]>;
|
|
498
505
|
readonly id: Schema.String;
|
|
506
|
+
readonly stroke: Schema.optionalKey<Schema.Literals<readonly ["dashed"]>>;
|
|
499
507
|
readonly from: Schema.Struct<{
|
|
500
508
|
readonly x: Schema.Finite;
|
|
501
509
|
readonly y: Schema.Finite;
|
package/dist/math/space.js
CHANGED
|
@@ -3,7 +3,7 @@ import { hasUniquePositions, MathAxisRangeSchema, MathViewPaddingSchema, mathVis
|
|
|
3
3
|
import { spaceBoundsIssues } from "#contracts/math/bounds";
|
|
4
4
|
import { FormulaParameterSchema } from "#contracts/math/formula/field";
|
|
5
5
|
import { formulaScopeIssues, parameterScope, spaceFormulaFields, } from "#contracts/math/formula/scope";
|
|
6
|
-
import { MATH_LINE_MESSAGE, MATH_POLYLINE_MESSAGE, MATH_RAY_MESSAGE, MATH_SEGMENT_MESSAGE, MATH_VECTOR_MESSAGE, MathObjectFields, mathLabelAnchorFields, } from "#contracts/math/object";
|
|
6
|
+
import { MATH_LINE_MESSAGE, MATH_POLYLINE_MESSAGE, MATH_RAY_MESSAGE, MATH_SEGMENT_MESSAGE, MATH_VECTOR_MESSAGE, MathObjectFields, MathStrokeFields, mathLabelAnchorFields, } from "#contracts/math/object";
|
|
7
7
|
import { spaceResolutionIssues } from "#contracts/math/resolution";
|
|
8
8
|
import { SpaceSolidObjectSchemas } from "#contracts/math/solid";
|
|
9
9
|
import { hasCoplanarArea } from "#contracts/math/vector";
|
|
@@ -16,6 +16,7 @@ const SpacePathSchema = Schema.TupleWithRest(Schema.Tuple([SpacePointSchema, Spa
|
|
|
16
16
|
const SpaceShapeSchema = Schema.TupleWithRest(Schema.Tuple([SpacePointSchema, SpacePointSchema, SpacePointSchema]), [SpacePointSchema]);
|
|
17
17
|
const SpaceLineObjectSchema = Schema.Struct({
|
|
18
18
|
...MathObjectFields,
|
|
19
|
+
...MathStrokeFields,
|
|
19
20
|
kind: Schema.Literal("line"),
|
|
20
21
|
through: Schema.Tuple([SpacePointSchema, SpacePointSchema]),
|
|
21
22
|
}).pipe(Schema.check(Schema.makeFilter(({ through: [from, to] }) => !sameSpacePoint(from, to), {
|
|
@@ -23,6 +24,7 @@ const SpaceLineObjectSchema = Schema.Struct({
|
|
|
23
24
|
})));
|
|
24
25
|
const SpaceRayObjectSchema = Schema.Struct({
|
|
25
26
|
...MathObjectFields,
|
|
27
|
+
...MathStrokeFields,
|
|
26
28
|
from: SpacePointSchema,
|
|
27
29
|
kind: Schema.Literal("ray"),
|
|
28
30
|
through: SpacePointSchema,
|
|
@@ -31,6 +33,7 @@ const SpaceRayObjectSchema = Schema.Struct({
|
|
|
31
33
|
})));
|
|
32
34
|
const SpaceSegmentObjectSchema = Schema.Struct({
|
|
33
35
|
...MathObjectFields,
|
|
36
|
+
...MathStrokeFields,
|
|
34
37
|
from: SpacePointSchema,
|
|
35
38
|
kind: Schema.Literal("segment"),
|
|
36
39
|
to: SpacePointSchema,
|
|
@@ -51,6 +54,7 @@ const SpaceVectorObjectSchema = Schema.Struct({
|
|
|
51
54
|
})));
|
|
52
55
|
const SpacePolylineObjectSchema = Schema.Struct({
|
|
53
56
|
...MathObjectFields,
|
|
57
|
+
...MathStrokeFields,
|
|
54
58
|
kind: Schema.Literal("polyline"),
|
|
55
59
|
vertices: SpacePathSchema,
|
|
56
60
|
}).pipe(Schema.check(Schema.makeFilter(({ vertices }) => hasUniquePositions(vertices, sameSpacePoint), { message: MATH_POLYLINE_MESSAGE })));
|