@mark1russell7/visuals 0.3.2 → 0.3.3

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/README.md CHANGED
@@ -398,6 +398,16 @@ shapeRing("triangle").length; // => 3: the corners of the sign, counter-clockwis
398
398
  - A meter has no place. A page draws it in a panel, and a 3D view ignores it.
399
399
  - A meter with no limit has no `limit`. A page shows only its value and its unit.
400
400
  - Each point of a list of marks is in one space. The producer tells the unit and the axes of that space.
401
+ - `transformMarks` gives the marks in a different space. It moves each point, and it turns each direction.
402
+
403
+ ```ts
404
+ import { transformMarks } from "@mark1russell7/visuals/marks";
405
+
406
+ // The marks of a room have the z axis up. A stage has the y axis up: a turn of a quarter about the x axis.
407
+ const onStage = transformMarks(marks, { position: { x: 0, y: 0, z: 0 }, rotation: { x: -Math.SQRT1_2, y: 0, z: 0, w: Math.SQRT1_2 } });
408
+ ```
409
+
410
+ A transform is a `Transform3` of `@mark1russell7/layout-contract`. It has no scale, so each length of a mark stays.
401
411
 
402
412
  `checkMarks` gives the faults of a list, each with a code, the index of its mark and the part with the fault. It examines the values that the types do not hold:
403
413
 
@@ -458,6 +468,7 @@ stage?.refresh();
458
468
  - A record with a highlight gets a larger sign, and a line of the color `accent` around it.
459
469
  - `signReach` gives the radius of a sign with its line. Give it to the field `clear` of a label.
460
470
  - The pick of a field gives the mark. `fieldValue` reads the value of a cell.
471
+ - The content draws the marks in the space of the stage. `transformMarks` moves the marks of a different space into it.
461
472
 
462
473
  ## The camera maths
463
474
 
@@ -1,4 +1,4 @@
1
- import { addPoints3, cross3, scalePoint3 } from "@mark1russell7/layout-contract";
1
+ import { addPoints3, cross3, rotatePoint3, scalePoint3, transformPoint3 } from "@mark1russell7/layout-contract";
2
2
  // src/marks/levels.ts
3
3
  /** These are the levels of a mark, from the lowest to the highest. */
4
4
  const LEVELS = [
@@ -93,6 +93,49 @@ function fieldValue(field, column, row) {
93
93
  if (!Number.isInteger(column) || !Number.isInteger(row) || column < 0 || row < 0 || column >= field.columns || row >= field.rows) return null;
94
94
  return field.values[row * field.columns + column] ?? null;
95
95
  }
96
- export { LEVELS as a, levelRank as c, fieldValue as i, levelShape as l, fieldCellCenter as n, LEVEL_SHAPES as o, fieldRowStep as r, SHAPE_OUTLINES as s, MARK_TYPES as t, shapeRing as u };
96
+ /** This function gives a frame after a transform. The point gets the transform, and the direction gets only its rotation. */
97
+ function transformFrame(frame, transform) {
98
+ return {
99
+ at: transformPoint3(transform, frame.at),
100
+ out: rotatePoint3(transform.rotation, frame.out)
101
+ };
102
+ }
103
+ /**
104
+ * This function gives the marks in a different space. Each point gets the transform, and each direction gets only its rotation.
105
+ * An example is the marks of a room with the z axis up, for a stage with the y axis up.
106
+ *
107
+ * A transform has no scale, so each length stays: the size of a point, the width of a run and the cell of a field.
108
+ * A meter has no place, so it stays. Each other part of a mark stays, and the function changes no mark of the list.
109
+ */
110
+ function transformMarks(marks, transform) {
111
+ return marks.map((mark) => {
112
+ if (mark.type === "point") return {
113
+ ...mark,
114
+ frame: transformFrame(mark.frame, transform)
115
+ };
116
+ if (mark.type === "run") return {
117
+ ...mark,
118
+ path: mark.path.map((frame) => transformFrame(frame, transform))
119
+ };
120
+ if (mark.type === "link") return {
121
+ ...mark,
122
+ from: {
123
+ ...mark.from,
124
+ at: transformPoint3(transform, mark.from.at)
125
+ },
126
+ to: {
127
+ ...mark.to,
128
+ at: transformPoint3(transform, mark.to.at)
129
+ }
130
+ };
131
+ if (mark.type === "field") return {
132
+ ...mark,
133
+ frame: transformFrame(mark.frame, transform),
134
+ across: rotatePoint3(transform.rotation, mark.across)
135
+ };
136
+ return mark;
137
+ });
138
+ }
139
+ export { transformMarks as a, SHAPE_OUTLINES as c, shapeRing as d, fieldValue as i, levelRank as l, fieldCellCenter as n, LEVELS as o, fieldRowStep as r, LEVEL_SHAPES as s, MARK_TYPES as t, levelShape as u };
97
140
 
98
- //# sourceMappingURL=mark-AZ5AuAIJ.js.map
141
+ //# sourceMappingURL=mark-D9bjgO-y.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"mark-D9bjgO-y.js","names":[],"sources":["../src/marks/levels.ts","../src/marks/mark.ts"],"sourcesContent":["import type { Ring } from \"@mark1russell7/layout-contract\";\n\n/** These are the levels of a mark, from the lowest to the highest. */\nexport const LEVELS: readonly [\"unknown\", \"ok\", \"near\", \"over\"] = [\"unknown\", \"ok\", \"near\", \"over\"];\n\n/**\n * A level of a mark, in the scale of limits. `ok` is below a limit, `near` is near it and `over` is above it.\n * A mark with no known value has `unknown`. The producer of a mark calculates the level, because each topic has its own limits.\n */\nexport type Level = (typeof LEVELS)[number];\n\n/**\n * This function gives the rank of a level: 0 for `unknown` and 3 for `over`.\n * A viewer draws the marks in the sequence of their ranks, so the worst level is always in view.\n */\nexport function levelRank(level: Level): number {\n return LEVELS.indexOf(level);\n}\n\n/** These are the shapes of the sign of a level. */\nexport const LEVEL_SHAPES: readonly [\"ring\", \"disc\", \"triangle\", \"square\"] = [\"ring\", \"disc\", \"triangle\", \"square\"];\n\n/** A shape of the sign of a level. A person who does not see a color reads the level from the shape. */\nexport type LevelShape = (typeof LEVEL_SHAPES)[number];\n\n/**\n * This function gives the shape of the sign of a level: a disc for `ok`, a triangle for `near` and a square for `over`.\n * The level `unknown` has a ring, and so has a record with no level.\n */\nexport function levelShape(level: Level | undefined): LevelShape {\n return level === \"ok\" ? \"disc\" : level === \"near\" ? \"triangle\" : level === \"over\" ? \"square\" : \"ring\";\n}\n\n/** The outline of the sign of a shape, as a regular polygon. A circle is a polygon with 40 sides. */\nexport interface ShapeOutline {\n /** The radius of the circle through the corners, for a disc with the radius 1. */\n readonly radius: number;\n /** The number of the sides. */\n readonly sides: number;\n /** The angle of the first corner, in radians, counter-clockwise from the x axis. */\n readonly start: number;\n /** The radius of the hole of the sign, for a disc with the radius 1. A sign with no hole has 0. */\n readonly hole: number;\n}\n\n/**\n * The outline of the sign of each shape. Each viewer draws the signs from these values, so each viewer shows the same signs.\n * A triangle and a square with the radius of the disc look small, so they are larger.\n */\nexport const SHAPE_OUTLINES: Readonly<Record<LevelShape, ShapeOutline>> = {\n ring: { radius: 1, sides: 40, start: 0, hole: 0.52 },\n disc: { radius: 1, sides: 40, start: 0, hole: 0 },\n triangle: { radius: 1.3, sides: 3, start: Math.PI / 2, hole: 0 },\n square: { radius: 1.25, sides: 4, start: Math.PI / 4, hole: 0 },\n};\n\n/**\n * This function gives the corners of the outline of a sign, counter-clockwise, with the y axis up.\n * The center of the sign is the origin, and `radius` is the radius of a disc.\n */\nexport function shapeRing(shape: LevelShape, radius: number = 1): Ring {\n const outline = SHAPE_OUTLINES[shape];\n return Array.from({ length: outline.sides }, (_, index): readonly [number, number] => {\n const angle = outline.start + (index * 2 * Math.PI) / outline.sides;\n return [radius * outline.radius * Math.cos(angle), radius * outline.radius * Math.sin(angle)];\n });\n}\n","import { addPoints3, cross3, rotatePoint3, scalePoint3, transformPoint3, type Point3, type Transform3 } from \"@mark1russell7/layout-contract\";\nimport type { Level } from \"./levels.ts\";\n\n/** A point of a surface, and the direction out of the surface. */\nexport interface Frame {\n /** The point. */\n readonly at: Point3;\n /** The unit vector out of the surface at the point. */\n readonly out: Point3;\n}\n\n/** These are the types of a mark. */\nexport const MARK_TYPES: readonly [\"point\", \"run\", \"link\", \"field\", \"meter\"] = [\"point\", \"run\", \"link\", \"field\", \"meter\"];\n\n/** A type of a mark. */\nexport type MarkType = (typeof MARK_TYPES)[number];\n\n/**\n * The parts that each mark has. A mark has no shape and no color.\n * A viewer gets the shape from the level, and the color from the level and its theme. Thus a mark does not use color alone.\n */\nexport interface MarkBase {\n /** The name of the record of the mark. The pointer and the selection of a viewer use this name. */\n readonly record: string;\n /** A word of the producer for the legend and the filter, for example `outlet`. */\n readonly kind: string;\n /** The level of the mark. The producer calculates it. */\n readonly level: Level;\n /** One line of text: the name of the mark for a person and for a screen reader. */\n readonly label: string;\n}\n\n/** A mark at one point of a surface, for example an outlet, a tap or a lamp. */\nexport interface PointMark extends MarkBase {\n readonly type: \"point\";\n /** The point, and the direction out of its surface. */\n readonly frame: Frame;\n /** The width of the sign, in the unit of the space. A mark with no size gets the default size of the viewer. */\n readonly size?: number | undefined;\n}\n\n/** A mark along a path on surfaces, for example a cable, a pipe or a duct. */\nexport interface RunMark extends MarkBase {\n readonly type: \"run\";\n /** The points of the path, in sequence. Each point has its own direction, so a run can go across surfaces. A path has 2 or more points. */\n readonly path: readonly Frame[];\n /** The width of the run, in the unit of the space. */\n readonly width: number;\n}\n\n/** One end of a link. */\nexport interface LinkEnd {\n /** The name of the record at this end. A viewer shows the link when the record of one end is selected or under the pointer. */\n readonly record: string;\n /** The point of this end. */\n readonly at: Point3;\n}\n\n/** A mark between two records, for example a power line from an outlet to a computer. */\nexport interface LinkMark extends MarkBase {\n readonly type: \"link\";\n readonly from: LinkEnd;\n readonly to: LinkEnd;\n}\n\n/** The scale of the values of a field. The theme of a viewer gives the colors from `min` to `max`. */\nexport interface FieldScale {\n /** The value of the first color. It is less than `max`. */\n readonly min: number;\n /** The value of the last color. */\n readonly max: number;\n /** The text of the unit of the values, for example `lx`. */\n readonly unit: string;\n}\n\n/** A grid of values on a plane, for example the light on a floor or the heat of a wall. */\nexport interface FieldMark extends MarkBase {\n readonly type: \"field\";\n /** The corner of the first cell, and the direction out of the plane. */\n readonly frame: Frame;\n /** The unit vector of a column step, in the plane. The step of a row is the cross product of `frame.out` and `across`. */\n readonly across: Point3;\n /** The length of a side of a cell, in the unit of the space. */\n readonly cell: number;\n /** The number of the columns. */\n readonly columns: number;\n /** The number of the rows. */\n readonly rows: number;\n /**\n * The values, row by row. The value of the column `c` and the row `r` has the index `r * columns + c`.\n * A cell with no value has `null`, because JSON has no NaN.\n */\n readonly values: readonly (number | null)[];\n readonly scale: FieldScale;\n}\n\n/**\n * A value against a limit, for example the load of a circuit. A meter has no place.\n * A page draws it in a panel, and a 3D view ignores it.\n */\nexport interface MeterMark extends MarkBase {\n readonly type: \"meter\";\n readonly value: number;\n /**\n * The limit of the value. A meter with no limit has no `limit`, for example a circuit with a known load and no known breaker.\n * A page shows only the value and the unit of that meter. A limit of 0 is a real limit, so it is not a sign for no limit.\n */\n readonly limit?: number | undefined;\n /** The text of the unit of the value and of the limit, for example `W`. */\n readonly unit: string;\n}\n\n/**\n * A record that a viewer draws. A mark is plain data with no topic, so it goes through JSON with no change.\n * Each point of a list of marks is in one space. The producer tells the unit and the axes of that space.\n */\nexport type Mark = PointMark | RunMark | LinkMark | FieldMark | MeterMark;\n\n/** This function gives the unit vector of a row step of a field: the cross product of `frame.out` and `across`. */\nexport function fieldRowStep(field: FieldMark): Point3 {\n return cross3(field.frame.out, field.across);\n}\n\n/** This function gives the center of a cell of a field. The first cell has the column 0 and the row 0. */\nexport function fieldCellCenter(field: FieldMark, column: number, row: number): Point3 {\n const across = scalePoint3(field.across, (column + 0.5) * field.cell);\n const down = scalePoint3(fieldRowStep(field), (row + 0.5) * field.cell);\n return addPoints3(field.frame.at, addPoints3(across, down));\n}\n\n/** This function gives the value of a cell of a field. A cell with no value gives `null`, and so does a cell that is not in the grid. */\nexport function fieldValue(field: FieldMark, column: number, row: number): number | null {\n if (!Number.isInteger(column) || !Number.isInteger(row) || column < 0 || row < 0 || column >= field.columns || row >= field.rows) return null;\n return field.values[row * field.columns + column] ?? null;\n}\n\n/** This function gives a frame after a transform. The point gets the transform, and the direction gets only its rotation. */\nfunction transformFrame(frame: Frame, transform: Transform3): Frame {\n return { at: transformPoint3(transform, frame.at), out: rotatePoint3(transform.rotation, frame.out) };\n}\n\n/**\n * This function gives the marks in a different space. Each point gets the transform, and each direction gets only its rotation.\n * An example is the marks of a room with the z axis up, for a stage with the y axis up.\n *\n * A transform has no scale, so each length stays: the size of a point, the width of a run and the cell of a field.\n * A meter has no place, so it stays. Each other part of a mark stays, and the function changes no mark of the list.\n */\nexport function transformMarks(marks: readonly Mark[], transform: Transform3): readonly Mark[] {\n return marks.map((mark): Mark => {\n if (mark.type === \"point\") return { ...mark, frame: transformFrame(mark.frame, transform) };\n if (mark.type === \"run\") return { ...mark, path: mark.path.map((frame) => transformFrame(frame, transform)) };\n if (mark.type === \"link\") {\n return { ...mark, from: { ...mark.from, at: transformPoint3(transform, mark.from.at) }, to: { ...mark.to, at: transformPoint3(transform, mark.to.at) } };\n }\n if (mark.type === \"field\") return { ...mark, frame: transformFrame(mark.frame, transform), across: rotatePoint3(transform.rotation, mark.across) };\n return mark;\n });\n}\n"],"mappings":";;;AAGA,MAAa,SAAqD;CAAC;CAAW;CAAM;CAAQ;AAAM;;;;;AAYlG,SAAgB,UAAU,OAAsB;CAC9C,OAAO,OAAO,QAAQ,KAAK;AAC7B;;AAGA,MAAa,eAAgE;CAAC;CAAQ;CAAQ;CAAY;AAAQ;;;;;AASlH,SAAgB,WAAW,OAAsC;CAC/D,OAAO,UAAU,OAAO,SAAS,UAAU,SAAS,aAAa,UAAU,SAAS,WAAW;AACjG;;;;;AAkBA,MAAa,iBAA6D;CACxE,MAAM;EAAE,QAAQ;EAAG,OAAO;EAAI,OAAO;EAAG,MAAM;CAAK;CACnD,MAAM;EAAE,QAAQ;EAAG,OAAO;EAAI,OAAO;EAAG,MAAM;CAAE;CAChD,UAAU;EAAE,QAAQ;EAAK,OAAO;EAAG,OAAO,KAAK,KAAK;EAAG,MAAM;CAAE;CAC/D,QAAQ;EAAE,QAAQ;EAAM,OAAO;EAAG,OAAO,KAAK,KAAK;EAAG,MAAM;CAAE;AAChE;;;;;AAMA,SAAgB,UAAU,OAAmB,SAAiB,GAAS;CACrE,MAAM,UAAU,eAAe;CAC/B,OAAO,MAAM,KAAK,EAAE,QAAQ,QAAQ,MAAM,IAAI,GAAG,UAAqC;EACpF,MAAM,QAAQ,QAAQ,QAAS,QAAQ,IAAI,KAAK,KAAM,QAAQ;EAC9D,OAAO,CAAC,SAAS,QAAQ,SAAS,KAAK,IAAI,KAAK,GAAG,SAAS,QAAQ,SAAS,KAAK,IAAI,KAAK,CAAC;CAC9F,CAAC;AACH;;;ACtDA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GAAE;EAAE;EAEzJ,IAAI,KAAK,SAAS,SAAS,OAAO;GAAE,GAAG;GAAM,OAAO,eAAe,KAAK,OAAO,SAAS;GAAG,QAAQ,aAAa,UAAU,UAAU,KAAK,MAAM;EAAE;EACjJ,OAAO;CACT,CAAC;AACH"}
@@ -1,4 +1,4 @@
1
- import { Point3, Ring } from "@mark1russell7/layout-contract";
1
+ import { Point3, Ring, Transform3 } from "@mark1russell7/layout-contract";
2
2
  /** These are the levels of a mark, from the lowest to the highest. */
3
3
  declare const LEVELS: readonly ["unknown", "ok", "near", "over"];
4
4
  /**
@@ -150,5 +150,13 @@ declare function fieldRowStep(field: FieldMark): Point3;
150
150
  declare function fieldCellCenter(field: FieldMark, column: number, row: number): Point3;
151
151
  /** This function gives the value of a cell of a field. A cell with no value gives `null`, and so does a cell that is not in the grid. */
152
152
  declare function fieldValue(field: FieldMark, column: number, row: number): number | null;
153
- export { levelShape as C, levelRank as S, LEVEL_SHAPES as _, LinkMark as a, SHAPE_OUTLINES as b, MarkBase as c, PointMark as d, RunMark as f, LEVELS as g, fieldValue as h, LinkEnd as i, MarkType as l, fieldRowStep as m, FieldScale as n, MARK_TYPES as o, fieldCellCenter as p, Frame as r, Mark as s, FieldMark as t, MeterMark as u, Level as v, shapeRing as w, ShapeOutline as x, LevelShape as y };
154
- //# sourceMappingURL=mark-D8AdQYAS.d.ts.map
153
+ /**
154
+ * This function gives the marks in a different space. Each point gets the transform, and each direction gets only its rotation.
155
+ * An example is the marks of a room with the z axis up, for a stage with the y axis up.
156
+ *
157
+ * A transform has no scale, so each length stays: the size of a point, the width of a run and the cell of a field.
158
+ * A meter has no place, so it stays. Each other part of a mark stays, and the function changes no mark of the list.
159
+ */
160
+ declare function transformMarks(marks: readonly Mark[], transform: Transform3): readonly Mark[];
161
+ export { levelRank as C, ShapeOutline as S, shapeRing as T, LEVELS as _, LinkMark as a, LevelShape as b, MarkBase as c, PointMark as d, RunMark as f, transformMarks as g, fieldValue as h, LinkEnd as i, MarkType as l, fieldRowStep as m, FieldScale as n, MARK_TYPES as o, fieldCellCenter as p, Frame as r, Mark as s, FieldMark as t, MeterMark as u, LEVEL_SHAPES as v, levelShape as w, SHAPE_OUTLINES as x, Level as y };
162
+ //# sourceMappingURL=mark-ubn709Qw.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"mark-D8AdQYAS.d.ts","names":[],"sources":["../src/marks/levels.ts","../src/marks/mark.ts"],"mappings":";;cAGa;;;;;KAMD,gBAAgB;;;;;iBAMZ,UAAU,OAAO;;cAKpB;;KAGD,qBAAqB;;;;;iBAMjB,WAAW,OAAO,oBAAoB;;UAKrC;;WAEN;;WAEA;;WAEA;;WAEA;;;;;;cAOE,gBAAgB,SAAS,OAAO,YAAY;;;;;iBAWzC,UAAU,OAAO,YAAY,kBAAqB;;UCxDjD;;WAEN,IAAI;;WAEJ,KAAK;;;cAIH;;KAGD,mBAAmB;;;;;UAMd;;WAEN;;WAEA;;WAEA,OAAO;;WAEP;;;UAIM,kBAAkB;WACxB;;WAEA,OAAO;;WAEP;;;UAIM,gBAAgB;WACtB;;WAEA,eAAe;;WAEf;;;UAIM;;WAEN;;WAEA,IAAI;;;UAIE,iBAAiB;WACvB;WACA,MAAM;WACN,IAAI;;;UAIE;;WAEN;;WAEA;;WAEA;;;UAIM,kBAAkB;WACxB;;WAEA,OAAO;;WAEP,QAAQ;;WAER;;WAEA;;WAEA;;;;;WAKA;WACA,OAAO;;;;;;UAOD,kBAAkB;WACxB;WACA;;;;;WAKA;;WAEA;;;;;;KAOC,OAAO,YAAY,UAAU,WAAW,YAAY;;iBAGhD,aAAa,OAAO,YAAY;;iBAKhC,gBAAgB,OAAO,WAAW,gBAAgB,cAAc;;iBAOhE,WAAW,OAAO,WAAW,gBAAgB"}
1
+ {"version":3,"file":"mark-ubn709Qw.d.ts","names":[],"sources":["../src/marks/levels.ts","../src/marks/mark.ts"],"mappings":";;cAGa;;;;;KAMD,gBAAgB;;;;;iBAMZ,UAAU,OAAO;;cAKpB;;KAGD,qBAAqB;;;;;iBAMjB,WAAW,OAAO,oBAAoB;;UAKrC;;WAEN;;WAEA;;WAEA;;WAEA;;;;;;cAOE,gBAAgB,SAAS,OAAO,YAAY;;;;;iBAWzC,UAAU,OAAO,YAAY,kBAAqB;;UCxDjD;;WAEN,IAAI;;WAEJ,KAAK;;;cAIH;;KAGD,mBAAmB;;;;;UAMd;;WAEN;;WAEA;;WAEA,OAAO;;WAEP;;;UAIM,kBAAkB;WACxB;;WAEA,OAAO;;WAEP;;;UAIM,gBAAgB;WACtB;;WAEA,eAAe;;WAEf;;;UAIM;;WAEN;;WAEA,IAAI;;;UAIE,iBAAiB;WACvB;WACA,MAAM;WACN,IAAI;;;UAIE;;WAEN;;WAEA;;WAEA;;;UAIM,kBAAkB;WACxB;;WAEA,OAAO;;WAEP,QAAQ;;WAER;;WAEA;;WAEA;;;;;WAKA;WACA,OAAO;;;;;;UAOD,kBAAkB;WACxB;WACA;;;;;WAKA;;WAEA;;;;;;KAOC,OAAO,YAAY,UAAU,WAAW,YAAY;;iBAGhD,aAAa,OAAO,YAAY;;iBAKhC,gBAAgB,OAAO,WAAW,gBAAgB,cAAc;;iBAOhE,WAAW,OAAO,WAAW,gBAAgB;;;;;;;;iBAiB7C,eAAe,gBAAgB,QAAQ,WAAW,sBAAsB"}
@@ -1,4 +1,4 @@
1
- import { s as Mark, v as Level } from "./mark-D8AdQYAS.js";
1
+ import { s as Mark, y as Level } from "./mark-ubn709Qw.js";
2
2
  import { r as StageContent } from "./stage-DmFfah2e.js";
3
3
  import { t as StageTheme } from "./theme-3EGbXXoP.js";
4
4
  /** The colors of the marks of a stage. Each color is a CSS hex color, for example `#22364a`. */
package/build/markers.js CHANGED
@@ -1,4 +1,4 @@
1
- import { i as fieldValue, l as levelShape, r as fieldRowStep, s as SHAPE_OUTLINES } from "./mark-AZ5AuAIJ.js";
1
+ import { c as SHAPE_OUTLINES, i as fieldValue, r as fieldRowStep, u as levelShape } from "./mark-D9bjgO-y.js";
2
2
  import "./view-BB_EQx3I.js";
3
3
  import { BufferAttribute, BufferGeometry, Color, DataTexture, DoubleSide, InstancedBufferAttribute, InstancedBufferGeometry, Mesh, MeshBasicMaterial, NearestFilter, Plane, RGBAFormat, SRGBColorSpace, ShaderMaterial, UnsignedByteType, Vector3 } from "three";
4
4
  // src/markers/content.ts
package/build/marks.d.ts CHANGED
@@ -1,4 +1,4 @@
1
- import { C as levelShape, S as levelRank, _ as LEVEL_SHAPES, a as LinkMark, b as SHAPE_OUTLINES, c as MarkBase, d as PointMark, f as RunMark, g as LEVELS, h as fieldValue, i as LinkEnd, l as MarkType, m as fieldRowStep, n as FieldScale, o as MARK_TYPES, p as fieldCellCenter, r as Frame, s as Mark, t as FieldMark, u as MeterMark, v as Level, w as shapeRing, x as ShapeOutline, y as LevelShape } from "./mark-D8AdQYAS.js";
1
+ import { C as levelRank, S as ShapeOutline, T as shapeRing, _ as LEVELS, a as LinkMark, b as LevelShape, c as MarkBase, d as PointMark, f as RunMark, g as transformMarks, h as fieldValue, i as LinkEnd, l as MarkType, m as fieldRowStep, n as FieldScale, o as MARK_TYPES, p as fieldCellCenter, r as Frame, s as Mark, t as FieldMark, u as MeterMark, v as LEVEL_SHAPES, w as levelShape, x as SHAPE_OUTLINES, y as Level } from "./mark-ubn709Qw.js";
2
2
  /**
3
3
  * These are the codes of the faults of a mark:
4
4
  * - `type`: the type of the mark is not known. A list from a later version of a producer can have a new type.
@@ -41,5 +41,5 @@ export declare const DIRECTION_TOLERANCE = 1e-6;
41
41
  * It does not examine the form of a mark: read a list from JSON through a schema first.
42
42
  */
43
43
  export declare function checkMarks(marks: readonly Mark[]): readonly MarkFault[];
44
- export { type FieldMark, type FieldScale, type Frame, LEVELS, LEVEL_SHAPES, type Level, type LevelShape, type LinkEnd, type LinkMark, MARK_TYPES, type Mark, type MarkBase, type MarkFault, type MarkFaultCode, type MarkType, type MeterMark, type PointMark, type RunMark, SHAPE_OUTLINES, type ShapeOutline, fieldCellCenter, fieldRowStep, fieldValue, levelRank, levelShape, shapeRing };
44
+ export { type FieldMark, type FieldScale, type Frame, LEVELS, LEVEL_SHAPES, type Level, type LevelShape, type LinkEnd, type LinkMark, MARK_TYPES, type Mark, type MarkBase, type MarkFault, type MarkFaultCode, type MarkType, type MeterMark, type PointMark, type RunMark, SHAPE_OUTLINES, type ShapeOutline, fieldCellCenter, fieldRowStep, fieldValue, levelRank, levelShape, shapeRing, transformMarks };
45
45
  //# sourceMappingURL=marks.d.ts.map
package/build/marks.js CHANGED
@@ -1,4 +1,4 @@
1
- import { a as LEVELS, c as levelRank, i as fieldValue, l as levelShape, n as fieldCellCenter, o as LEVEL_SHAPES, r as fieldRowStep, s as SHAPE_OUTLINES, t as MARK_TYPES, u as shapeRing } from "./mark-AZ5AuAIJ.js";
1
+ import { a as transformMarks, c as SHAPE_OUTLINES, d as shapeRing, i as fieldValue, l as levelRank, n as fieldCellCenter, o as LEVELS, r as fieldRowStep, s as LEVEL_SHAPES, t as MARK_TYPES, u as levelShape } from "./mark-D9bjgO-y.js";
2
2
  import { dot3, length3 } from "@mark1russell7/layout-contract";
3
3
  // src/marks/check.ts
4
4
  /**
@@ -133,6 +133,6 @@ function checkMarks(marks) {
133
133
  });
134
134
  return faults;
135
135
  }
136
- export { DIRECTION_TOLERANCE, LEVELS, LEVEL_SHAPES, MARK_FAULT_CODES, MARK_TYPES, SHAPE_OUTLINES, checkMarks, fieldCellCenter, fieldRowStep, fieldValue, levelRank, levelShape, shapeRing };
136
+ export { DIRECTION_TOLERANCE, LEVELS, LEVEL_SHAPES, MARK_FAULT_CODES, MARK_TYPES, SHAPE_OUTLINES, checkMarks, fieldCellCenter, fieldRowStep, fieldValue, levelRank, levelShape, shapeRing, transformMarks };
137
137
 
138
138
  //# sourceMappingURL=marks.js.map
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "$schema": "https://json.schemastore.org/package",
3
3
  "name": "@mark1russell7/visuals",
4
- "version": "0.3.2",
4
+ "version": "0.3.3",
5
5
  "description": "3D stages for data on three.js: a camera that a person moves, views by name, picking, highlights and themes, a globe of the Earth, and the shared marks of the viewers as data.",
6
6
  "license": "MIT",
7
7
  "repository": {
@@ -1 +0,0 @@
1
- {"version":3,"file":"mark-AZ5AuAIJ.js","names":[],"sources":["../src/marks/levels.ts","../src/marks/mark.ts"],"sourcesContent":["import type { Ring } from \"@mark1russell7/layout-contract\";\n\n/** These are the levels of a mark, from the lowest to the highest. */\nexport const LEVELS: readonly [\"unknown\", \"ok\", \"near\", \"over\"] = [\"unknown\", \"ok\", \"near\", \"over\"];\n\n/**\n * A level of a mark, in the scale of limits. `ok` is below a limit, `near` is near it and `over` is above it.\n * A mark with no known value has `unknown`. The producer of a mark calculates the level, because each topic has its own limits.\n */\nexport type Level = (typeof LEVELS)[number];\n\n/**\n * This function gives the rank of a level: 0 for `unknown` and 3 for `over`.\n * A viewer draws the marks in the sequence of their ranks, so the worst level is always in view.\n */\nexport function levelRank(level: Level): number {\n return LEVELS.indexOf(level);\n}\n\n/** These are the shapes of the sign of a level. */\nexport const LEVEL_SHAPES: readonly [\"ring\", \"disc\", \"triangle\", \"square\"] = [\"ring\", \"disc\", \"triangle\", \"square\"];\n\n/** A shape of the sign of a level. A person who does not see a color reads the level from the shape. */\nexport type LevelShape = (typeof LEVEL_SHAPES)[number];\n\n/**\n * This function gives the shape of the sign of a level: a disc for `ok`, a triangle for `near` and a square for `over`.\n * The level `unknown` has a ring, and so has a record with no level.\n */\nexport function levelShape(level: Level | undefined): LevelShape {\n return level === \"ok\" ? \"disc\" : level === \"near\" ? \"triangle\" : level === \"over\" ? \"square\" : \"ring\";\n}\n\n/** The outline of the sign of a shape, as a regular polygon. A circle is a polygon with 40 sides. */\nexport interface ShapeOutline {\n /** The radius of the circle through the corners, for a disc with the radius 1. */\n readonly radius: number;\n /** The number of the sides. */\n readonly sides: number;\n /** The angle of the first corner, in radians, counter-clockwise from the x axis. */\n readonly start: number;\n /** The radius of the hole of the sign, for a disc with the radius 1. A sign with no hole has 0. */\n readonly hole: number;\n}\n\n/**\n * The outline of the sign of each shape. Each viewer draws the signs from these values, so each viewer shows the same signs.\n * A triangle and a square with the radius of the disc look small, so they are larger.\n */\nexport const SHAPE_OUTLINES: Readonly<Record<LevelShape, ShapeOutline>> = {\n ring: { radius: 1, sides: 40, start: 0, hole: 0.52 },\n disc: { radius: 1, sides: 40, start: 0, hole: 0 },\n triangle: { radius: 1.3, sides: 3, start: Math.PI / 2, hole: 0 },\n square: { radius: 1.25, sides: 4, start: Math.PI / 4, hole: 0 },\n};\n\n/**\n * This function gives the corners of the outline of a sign, counter-clockwise, with the y axis up.\n * The center of the sign is the origin, and `radius` is the radius of a disc.\n */\nexport function shapeRing(shape: LevelShape, radius: number = 1): Ring {\n const outline = SHAPE_OUTLINES[shape];\n return Array.from({ length: outline.sides }, (_, index): readonly [number, number] => {\n const angle = outline.start + (index * 2 * Math.PI) / outline.sides;\n return [radius * outline.radius * Math.cos(angle), radius * outline.radius * Math.sin(angle)];\n });\n}\n","import { addPoints3, cross3, scalePoint3, type Point3 } from \"@mark1russell7/layout-contract\";\nimport type { Level } from \"./levels.ts\";\n\n/** A point of a surface, and the direction out of the surface. */\nexport interface Frame {\n /** The point. */\n readonly at: Point3;\n /** The unit vector out of the surface at the point. */\n readonly out: Point3;\n}\n\n/** These are the types of a mark. */\nexport const MARK_TYPES: readonly [\"point\", \"run\", \"link\", \"field\", \"meter\"] = [\"point\", \"run\", \"link\", \"field\", \"meter\"];\n\n/** A type of a mark. */\nexport type MarkType = (typeof MARK_TYPES)[number];\n\n/**\n * The parts that each mark has. A mark has no shape and no color.\n * A viewer gets the shape from the level, and the color from the level and its theme. Thus a mark does not use color alone.\n */\nexport interface MarkBase {\n /** The name of the record of the mark. The pointer and the selection of a viewer use this name. */\n readonly record: string;\n /** A word of the producer for the legend and the filter, for example `outlet`. */\n readonly kind: string;\n /** The level of the mark. The producer calculates it. */\n readonly level: Level;\n /** One line of text: the name of the mark for a person and for a screen reader. */\n readonly label: string;\n}\n\n/** A mark at one point of a surface, for example an outlet, a tap or a lamp. */\nexport interface PointMark extends MarkBase {\n readonly type: \"point\";\n /** The point, and the direction out of its surface. */\n readonly frame: Frame;\n /** The width of the sign, in the unit of the space. A mark with no size gets the default size of the viewer. */\n readonly size?: number | undefined;\n}\n\n/** A mark along a path on surfaces, for example a cable, a pipe or a duct. */\nexport interface RunMark extends MarkBase {\n readonly type: \"run\";\n /** The points of the path, in sequence. Each point has its own direction, so a run can go across surfaces. A path has 2 or more points. */\n readonly path: readonly Frame[];\n /** The width of the run, in the unit of the space. */\n readonly width: number;\n}\n\n/** One end of a link. */\nexport interface LinkEnd {\n /** The name of the record at this end. A viewer shows the link when the record of one end is selected or under the pointer. */\n readonly record: string;\n /** The point of this end. */\n readonly at: Point3;\n}\n\n/** A mark between two records, for example a power line from an outlet to a computer. */\nexport interface LinkMark extends MarkBase {\n readonly type: \"link\";\n readonly from: LinkEnd;\n readonly to: LinkEnd;\n}\n\n/** The scale of the values of a field. The theme of a viewer gives the colors from `min` to `max`. */\nexport interface FieldScale {\n /** The value of the first color. It is less than `max`. */\n readonly min: number;\n /** The value of the last color. */\n readonly max: number;\n /** The text of the unit of the values, for example `lx`. */\n readonly unit: string;\n}\n\n/** A grid of values on a plane, for example the light on a floor or the heat of a wall. */\nexport interface FieldMark extends MarkBase {\n readonly type: \"field\";\n /** The corner of the first cell, and the direction out of the plane. */\n readonly frame: Frame;\n /** The unit vector of a column step, in the plane. The step of a row is the cross product of `frame.out` and `across`. */\n readonly across: Point3;\n /** The length of a side of a cell, in the unit of the space. */\n readonly cell: number;\n /** The number of the columns. */\n readonly columns: number;\n /** The number of the rows. */\n readonly rows: number;\n /**\n * The values, row by row. The value of the column `c` and the row `r` has the index `r * columns + c`.\n * A cell with no value has `null`, because JSON has no NaN.\n */\n readonly values: readonly (number | null)[];\n readonly scale: FieldScale;\n}\n\n/**\n * A value against a limit, for example the load of a circuit. A meter has no place.\n * A page draws it in a panel, and a 3D view ignores it.\n */\nexport interface MeterMark extends MarkBase {\n readonly type: \"meter\";\n readonly value: number;\n /**\n * The limit of the value. A meter with no limit has no `limit`, for example a circuit with a known load and no known breaker.\n * A page shows only the value and the unit of that meter. A limit of 0 is a real limit, so it is not a sign for no limit.\n */\n readonly limit?: number | undefined;\n /** The text of the unit of the value and of the limit, for example `W`. */\n readonly unit: string;\n}\n\n/**\n * A record that a viewer draws. A mark is plain data with no topic, so it goes through JSON with no change.\n * Each point of a list of marks is in one space. The producer tells the unit and the axes of that space.\n */\nexport type Mark = PointMark | RunMark | LinkMark | FieldMark | MeterMark;\n\n/** This function gives the unit vector of a row step of a field: the cross product of `frame.out` and `across`. */\nexport function fieldRowStep(field: FieldMark): Point3 {\n return cross3(field.frame.out, field.across);\n}\n\n/** This function gives the center of a cell of a field. The first cell has the column 0 and the row 0. */\nexport function fieldCellCenter(field: FieldMark, column: number, row: number): Point3 {\n const across = scalePoint3(field.across, (column + 0.5) * field.cell);\n const down = scalePoint3(fieldRowStep(field), (row + 0.5) * field.cell);\n return addPoints3(field.frame.at, addPoints3(across, down));\n}\n\n/** This function gives the value of a cell of a field. A cell with no value gives `null`, and so does a cell that is not in the grid. */\nexport function fieldValue(field: FieldMark, column: number, row: number): number | null {\n if (!Number.isInteger(column) || !Number.isInteger(row) || column < 0 || row < 0 || column >= field.columns || row >= field.rows) return null;\n return field.values[row * field.columns + column] ?? null;\n}\n"],"mappings":";;;AAGA,MAAa,SAAqD;CAAC;CAAW;CAAM;CAAQ;AAAM;;;;;AAYlG,SAAgB,UAAU,OAAsB;CAC9C,OAAO,OAAO,QAAQ,KAAK;AAC7B;;AAGA,MAAa,eAAgE;CAAC;CAAQ;CAAQ;CAAY;AAAQ;;;;;AASlH,SAAgB,WAAW,OAAsC;CAC/D,OAAO,UAAU,OAAO,SAAS,UAAU,SAAS,aAAa,UAAU,SAAS,WAAW;AACjG;;;;;AAkBA,MAAa,iBAA6D;CACxE,MAAM;EAAE,QAAQ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