@mark1russell7/visuals 0.1.0 → 0.2.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.
@@ -0,0 +1 @@
1
+ {"version":3,"file":"globe.js","names":["RADIANS"],"sources":["../src/globe/mesh.ts","../src/globe/space.ts","../src/globe/content.ts"],"sourcesContent":["import { densify, type Position, type Region } from \"@mark1russell7/geo\";\nimport { ShapeUtils, Vector2 } from \"three\";\n\n/**\n * The surface of a region as triangles. The region and the triangles are in the plane of longitude and latitude,\n * as the polygon tests of `@mark1russell7/geo` are. So a triangle does not go across the antimeridian.\n */\nexport interface RegionSurface {\n /** The longitude and the latitude of each corner, in degrees: two numbers for each corner. */\n readonly corners: Float64Array;\n /** The three corners of each triangle, as indices of corners. Each triangle is counterclockwise in the plane, with east on the right and north up. */\n readonly triangles: Uint32Array;\n}\n\n/** The largest count of corners of the surface of one region. A smaller step gives more corners. */\nexport const MAX_SURFACE_CORNERS = 2_000_000;\n\n/**\n * The longest edge in a surface, as a factor of the step. An edge of the outline is not longer than the step.\n * An edge in the surface can be longer by this factor, so the count of the passes has a small limit.\n */\nconst LONG_EDGE = 1.25;\n\n/**\n * The smallest length of a degree of longitude in the size of an edge, as a part of a degree at the equator.\n * Near a pole, a degree of longitude is short, and an edge can go across many of them. This limit keeps such an edge to 5 steps of longitude.\n * A straight edge on the Earth is not a straight line in longitude and latitude. The two are far apart for an edge across many degrees.\n */\nconst MIN_WIDTH = 0.25;\n\n/** The largest count of passes that divide the long edges. Each pass makes the longest edge shorter by almost a half. */\nconst MAX_PASSES = 48;\n\n/** The factor of the first corner in the key of an edge. A key is an exact integer for each pair of corners below this count. */\nconst KEY = 2 ** 26;\n\n/** The largest distance of a corner from an edge that it is on, as a part of the length of the edge. */\nconst ON_EDGE = 1e-12;\n\n/** The largest distance of a longitude from 180 degrees, or of a latitude from 90 degrees, that is on the antimeridian or on a pole. */\nconst ON_LINE = 1e-9;\n\nconst RADIANS = Math.PI / 180;\n\n/** This function gives one number of a list. The index is always in the list, so the default 0 has no use. */\nfunction at(list: ArrayLike<number>, index: number): number {\n return list[index] ?? 0;\n}\n\nfunction edgeKey(a: number, b: number): number {\n return a < b ? a * KEY + b : b * KEY + a;\n}\n\n/**\n * This function gives the height of the flat triangles of a surface below a ball of radius 1, at most.\n * A layer at this height above a ball does not go into the ball. `step` is the step of the surface, in degrees.\n */\nexport function surfaceSag(step: number): number {\n // A triangle with no edge longer than `a` on a ball is below the ball by 1 - cos(a / sqrt 3) at most.\n // An edge with a step of `s` in longitude and in latitude has the length s * sqrt 2 at most.\n return 1 - Math.cos((step * RADIANS * LONG_EDGE * Math.SQRT2) / Math.sqrt(3));\n}\n\n/** This function gives the points of a ring, each one time. A point is different from the point before it, and the last point is different from the first point. */\nfunction openRing(ring: readonly Position[]): Vector2[] {\n const points: Vector2[] = [];\n for (const position of ring) {\n const last = points[points.length - 1];\n if (last === undefined || last.x !== position[0] || last.y !== position[1]) points.push(new Vector2(position[0], position[1]));\n }\n const first = points[0];\n while (points.length > 1 && first !== undefined && points[points.length - 1]?.equals(first) === true) points.pop();\n return points;\n}\n\n/**\n * This function gives the size of an edge for the division of a surface, in degrees. The size is the larger of its steps in latitude and in longitude.\n * A step of longitude is as long as it is on the Earth, at the end of the edge that is nearer to the equator.\n */\nfunction edgeSize(lon: readonly number[], lat: readonly number[], a: number, b: number): number {\n const latA = at(lat, a);\n const latB = at(lat, b);\n const wide = Math.abs(at(lon, a) - at(lon, b)) * Math.max(Math.cos(Math.min(Math.abs(latA), Math.abs(latB)) * RADIANS), MIN_WIDTH);\n return Math.max(Math.abs(latA - latB), wide);\n}\n\n/** This function gives, for each edge of a list of faces, a face that has it. An edge of an outline has only one face. */\nfunction ownersOf(faces: readonly (readonly number[])[]): Map<number, number> {\n const owner = new Map<number, number>();\n faces.forEach((face, index) => {\n for (let side = 0; side < face.length; side++) owner.set(edgeKey(at(face, side), at(face, (side + 1) % face.length)), index);\n });\n return owner;\n}\n\n/**\n * This function divides the face with the edge from `a` to `b` at each corner of `run`. The corners of `run` are on the edge, in the sequence from `a` to `b`.\n * Each new face has the third corner of the face, and the direction of the face. An edge with no face changes nothing.\n */\nfunction divideAt(faces: number[][], owner: Map<number, number>, a: number, b: number, run: readonly number[]): void {\n const index = owner.get(edgeKey(a, b));\n const face = index === undefined ? undefined : faces[index];\n const c = face?.find((corner) => corner !== a && corner !== b);\n if (index === undefined || face === undefined || c === undefined || run.length === 0) return;\n const forward = face[(face.indexOf(a) + 1) % 3] === b;\n const chain = [a, ...run, b];\n for (let piece = 0; piece + 1 < chain.length; piece++) {\n const from = at(chain, piece);\n const to = at(chain, piece + 1);\n const place = piece === 0 ? index : faces.length;\n faces[place] = forward ? [from, to, c] : [to, from, c];\n owner.set(edgeKey(from, to), place);\n if (piece === 0) owner.set(edgeKey(a, c), place);\n if (piece === chain.length - 2) owner.set(edgeKey(b, c), place);\n }\n}\n\n/**\n * This function gives the corners that are on the edge from `u` to `v`, between its ends, in the sequence from `u` to `v`.\n * `byLon` has each corner, from the smallest longitude to the largest.\n */\nfunction cornersOn(points: readonly Vector2[], byLon: readonly number[], u: number, v: number): number[] {\n const from = points[u];\n const to = points[v];\n if (from === undefined || to === undefined) return [];\n const dx = to.x - from.x;\n const dy = to.y - from.y;\n const square = dx * dx + dy * dy;\n if (!(square > 0)) return [];\n const slack = Math.sqrt(square) * ON_EDGE;\n const low = Math.min(from.x, to.x) - slack;\n const high = Math.max(from.x, to.x) + slack;\n let first = 0;\n let end = byLon.length;\n while (first < end) {\n const middle = (first + end) >> 1;\n if ((points[at(byLon, middle)]?.x ?? Infinity) < low) first = middle + 1;\n else end = middle;\n }\n const found: { readonly corner: number; readonly part: number }[] = [];\n for (let index = first; index < byLon.length; index++) {\n const corner = at(byLon, index);\n const point = points[corner];\n if (point === undefined || point.x > high) break;\n if (corner === u || corner === v) continue;\n const px = point.x - from.x;\n const py = point.y - from.y;\n const part = (px * dx + py * dy) / square;\n if (part > 0 && part < 1 && Math.abs(px * dy - py * dx) <= square * ON_EDGE) found.push({ corner, part });\n }\n return found.sort((one, other) => one.part - other.part).map(({ corner }) => corner);\n}\n\n/**\n * This function divides a polygon into triangles. Each ring has no point two times in sequence. The faces have indices of the points of the rings, as one list.\n *\n * The division ignores a corner on the straight line between its two neighbors. A face then has an edge with a corner on it,\n * and the face on the other side of that corner has a different edge. The function divides such a face at each corner on its edge,\n * so two faces with a common border have a common edge.\n */\nfunction facesOf(rings: readonly (readonly Vector2[])[]): number[][] {\n const [outer = [], ...holes] = rings;\n const faces = ShapeUtils.triangulateShape(\n [...outer],\n holes.map((hole) => [...hole]),\n );\n const points = rings.flat();\n const ringOf: number[] = [];\n const spotOf: number[] = [];\n rings.forEach((ring, index) => {\n for (let spot = 0; spot < ring.length; spot++) {\n ringOf.push(index);\n spotOf.push(spot);\n }\n });\n const owner = new Map<number, number>();\n const counts = new Map<number, number>();\n faces.forEach((face, index) => {\n for (let side = 0; side < face.length; side++) {\n const key = edgeKey(at(face, side), at(face, (side + 1) % face.length));\n owner.set(key, index);\n counts.set(key, (counts.get(key) ?? 0) + 1);\n }\n });\n let byLon: number[] | undefined;\n for (const [key, count] of counts) {\n if (count !== 1) continue;\n const u = Math.floor(key / KEY);\n const v = key % KEY;\n const ring = at(ringOf, u);\n const gap = Math.abs(at(spotOf, u) - at(spotOf, v));\n // An edge between two neighbors of a ring is an edge of the outline. It has only one face, and no corner on it.\n if (ring === at(ringOf, v) && (gap === 1 || gap === (rings[ring]?.length ?? 0) - 1)) continue;\n byLon ??= points.map((_, index) => index).sort((one, other) => (points[one]?.x ?? 0) - (points[other]?.x ?? 0));\n divideAt(faces, owner, u, v, cornersOn(points, byLon, u, v));\n }\n return faces;\n}\n\n/**\n * This function gives the place of each point of a ring in the same ring with more points on its edges.\n * It gives `undefined` for a ring whose points are not in the other ring, in the same sequence.\n */\nfunction placesIn(dense: readonly Vector2[], own: readonly Vector2[]): number[] | undefined {\n const places: number[] = [];\n let index = 0;\n for (const point of own) {\n while (index < dense.length && dense[index]?.equals(point) !== true) index++;\n if (index >= dense.length) return undefined;\n places.push(index);\n index += 1;\n }\n return places;\n}\n\n/**\n * This function divides each triangle that has a long edge, at the middle of each long edge. It gives the new triangles,\n * or `undefined` when no edge is long. Two triangles with one edge get the same middle, so the surface has no hole.\n */\nfunction dividePass(triangles: readonly number[], lon: number[], lat: number[], limit: number, middles: Map<number, number>): number[] | undefined {\n const next: number[] = [];\n let divided = false;\n const middle = (a: number, b: number): number => {\n const key = edgeKey(a, b);\n const found = middles.get(key);\n if (found !== undefined) return found;\n lon.push((at(lon, a) + at(lon, b)) / 2);\n lat.push((at(lat, a) + at(lat, b)) / 2);\n middles.set(key, lon.length - 1);\n return lon.length - 1;\n };\n for (let index = 0; index < triangles.length; index += 3) {\n const a = at(triangles, index);\n const b = at(triangles, index + 1);\n const c = at(triangles, index + 2);\n const ab = edgeSize(lon, lat, a, b) > limit;\n const bc = edgeSize(lon, lat, b, c) > limit;\n const ca = edgeSize(lon, lat, c, a) > limit;\n const count = Number(ab) + Number(bc) + Number(ca);\n if (count === 0) {\n next.push(a, b, c);\n continue;\n }\n divided = true;\n if (count === 3) {\n const mab = middle(a, b);\n const mbc = middle(b, c);\n const mca = middle(c, a);\n next.push(a, mab, mca, mab, b, mbc, mca, mbc, c, mab, mbc, mca);\n continue;\n }\n // The corners turn to `p`, `q` and `r`. With one long edge, it is from `p` to `q`. With two long edges, the short edge is from `r` to `p`.\n let p = a;\n let q = b;\n let r = c;\n if (count === 1 ? bc : !ab) {\n p = b;\n q = c;\n r = a;\n } else if (count === 1 ? ca : !bc) {\n p = c;\n q = a;\n r = b;\n }\n const mpq = middle(p, q);\n if (count === 1) {\n next.push(p, mpq, r, mpq, q, r);\n continue;\n }\n const mqr = middle(q, r);\n next.push(mpq, q, mqr);\n // The part with four corners gets the shorter of its two diagonals.\n if (edgeSize(lon, lat, p, mqr) <= edgeSize(lon, lat, mpq, r)) next.push(p, mpq, mqr, p, mqr, r);\n else next.push(p, mpq, r, mpq, mqr, r);\n }\n return divided ? next : undefined;\n}\n\n/**\n * This function divides the surface of a region into triangles that follow the curve of the Earth.\n *\n * `step` is the largest step of an edge of the outline in longitude or latitude, in degrees. The outline is the outline of `densify` with this step:\n * each edge of the outline of the surface is an edge of that outline. So a line through the points of `densify` is exactly on the outline of the surface.\n * An edge in the surface is not longer than 1.25 steps. A step of longitude is as long as it is on the Earth at that latitude, and a quarter of a step at least.\n *\n * A straight edge in the plane is a curve on the Earth. So a flat triangle on a globe is not exactly the triangle in the plane.\n * The difference is small for a small step. It is largest near a pole.\n *\n * The function throws a `GeoError` for a region or a step that is not correct, and a `RangeError` for a surface with too many corners.\n */\nexport function regionSurface(region: Region, step: number, maxCorners: number = MAX_SURFACE_CORNERS): RegionSurface {\n const dense = densify(region, step);\n const ownPolygons = region.type === \"Polygon\" ? [region.coordinates] : region.coordinates;\n const densePolygons = dense.type === \"Polygon\" ? [dense.coordinates] : dense.coordinates;\n const lon: number[] = [];\n const lat: number[] = [];\n let triangles: number[] = [];\n ownPolygons.forEach((polygon, polygonIndex) => {\n // The division into triangles gets the corners of the region only. The corners that `densify` adds are on straight lines, and the division ignores some of them.\n const own: Vector2[][] = [];\n const more: Vector2[][] = [];\n const spots: number[][] = [];\n for (let index = 0; index < polygon.length; index++) {\n const ring = openRing(polygon[index] ?? []);\n if (ring.length < 3) {\n // A polygon whose outer ring has no area has no surface. Its holes are in the outer ring, so they have no surface also.\n if (index === 0) return;\n continue;\n }\n const added = openRing(densePolygons[polygonIndex]?.[index] ?? []);\n const places = placesIn(added, ring);\n own.push(ring);\n more.push(places === undefined ? ring : added);\n spots.push(places ?? ring.map((_, spot) => spot));\n }\n const base = lon.length;\n /** The corner of the surface for each corner of the region, as an index from `base`. */\n const cornerOf: number[] = [];\n const starts: number[] = [];\n more.forEach((ring, index) => {\n const start = lon.length - base;\n starts.push(start);\n for (const spot of spots[index] ?? []) cornerOf.push(start + spot);\n for (const point of ring) {\n lon.push(point.x);\n lat.push(point.y);\n }\n });\n if (lon.length > maxCorners) throw tooManyCorners(maxCorners);\n const faces = facesOf(own).map((face) => face.map((corner) => at(cornerOf, corner)));\n // Each edge of the outline gets the corners that `densify` added to it.\n const owner = ownersOf(faces);\n more.forEach((ring, index) => {\n const places = spots[index] ?? [];\n const start = at(starts, index);\n places.forEach((place, spot) => {\n const next = at(places, (spot + 1) % places.length);\n const run: number[] = [];\n for (let between = (place + 1) % ring.length; between !== next; between = (between + 1) % ring.length) run.push(start + between);\n divideAt(faces, owner, start + place, start + next, run);\n });\n });\n // East is on the right of a person who looks at the Earth from outside with north up. So a counterclockwise triangle in the plane has its front outside.\n // The faces of one polygon have one direction. Their sum tells it, also for a face with almost no area.\n const turnOf = ([a = 0, b = 0, c = 0]: readonly number[]): number =>\n (at(lon, base + b) - at(lon, base + a)) * (at(lat, base + c) - at(lat, base + a)) - (at(lon, base + c) - at(lon, base + a)) * (at(lat, base + b) - at(lat, base + a));\n let turn = 0;\n for (const face of faces) turn += turnOf(face);\n for (const [a = 0, b = 0, c = 0] of faces) {\n if (turn >= 0) triangles.push(base + a, base + b, base + c);\n else triangles.push(base + a, base + c, base + b);\n }\n });\n const limit = step * LONG_EDGE;\n const middles = new Map<number, number>();\n for (let pass = 0; ; pass++) {\n const next = dividePass(triangles, lon, lat, limit, middles);\n if (next === undefined) break;\n triangles = next;\n if (lon.length > maxCorners) throw tooManyCorners(maxCorners);\n if (pass >= MAX_PASSES) throw new RangeError(`The surface of the region has edges longer than ${limit} degrees after ${MAX_PASSES} passes.`);\n }\n const corners = new Float64Array(lon.length * 2);\n for (let index = 0; index < lon.length; index++) {\n corners[index * 2] = at(lon, index);\n corners[index * 2 + 1] = at(lat, index);\n }\n return { corners, triangles: Uint32Array.from(triangles) };\n}\n\nfunction tooManyCorners(maxCorners: number): RangeError {\n return new RangeError(`The surface of the region has more than ${maxCorners} corners. Use a larger step.`);\n}\n\n/** A range of latitudes of an edge on the antimeridian. */\ninterface Cut {\n readonly low: number;\n readonly high: number;\n}\n\n/** This function gives 1 for a longitude of 180 degrees east, -1 for 180 degrees west, and 0 for each other longitude. */\nfunction sideOf(position: Position): number {\n if (Math.abs(position[0] - 180) <= ON_LINE) return 1;\n return Math.abs(position[0] + 180) <= ON_LINE ? -1 : 0;\n}\n\n/** This function gives 1 for the north pole, -1 for the south pole, and 0 for each other latitude. */\nfunction poleOf(position: Position): number {\n if (position[1] >= 90 - ON_LINE) return 1;\n return position[1] <= -90 + ON_LINE ? -1 : 0;\n}\n\n/**\n * This function gives the edges of a region as lines, for the outline that a person sees. Each line is a list of longitudes and latitudes, in degrees:\n * two numbers for each point.\n *\n * `step` is the largest step of a line in longitude or latitude, in degrees. The points are the points of `densify`, so they are corners of `regionSurface`.\n * An edge that is only a cut gets no line. A cut is an edge along a pole, or an edge on the antimeridian with an edge of the region on its other side.\n */\nexport function regionEdges(region: Region, step: number): Float64Array[] {\n const polygons = region.type === \"Polygon\" ? [region.coordinates] : region.coordinates;\n const east: Cut[] = [];\n const west: Cut[] = [];\n for (const polygon of polygons) {\n for (const ring of polygon) {\n for (let index = 0; index + 1 < ring.length; index++) {\n const from = ring[index];\n const to = ring[index + 1];\n if (from === undefined || to === undefined) continue;\n const side = sideOf(from);\n if (side === 0 || side !== sideOf(to)) continue;\n (side > 0 ? east : west).push({ low: Math.min(from[1], to[1]), high: Math.max(from[1], to[1]) });\n }\n }\n }\n const isCut = (from: Position, to: Position): boolean => {\n const pole = poleOf(from);\n if (pole !== 0 && pole === poleOf(to)) return true;\n const side = sideOf(from);\n if (side === 0 || side !== sideOf(to)) return false;\n const low = Math.min(from[1], to[1]);\n const high = Math.max(from[1], to[1]);\n return (side > 0 ? west : east).some((cut) => Math.min(cut.high, high) > Math.max(cut.low, low));\n };\n const lines: Float64Array[] = [];\n const add = (run: readonly Position[]): void => {\n if (run.length < 2) return;\n const dense = densify({ type: \"LineString\", coordinates: [...run] }, step).coordinates;\n const line = new Float64Array(dense.length * 2);\n dense.forEach((position, index) => {\n line[index * 2] = position[0];\n line[index * 2 + 1] = position[1];\n });\n lines.push(line);\n };\n for (const polygon of polygons) {\n for (const ring of polygon) {\n const count = ring.length - 1;\n if (count < 1) continue;\n const cut: boolean[] = [];\n for (let index = 0; index < count; index++) {\n const from = ring[index];\n const to = ring[index + 1];\n cut.push(from === undefined || to === undefined || isCut(from, to));\n }\n const first = cut.indexOf(true);\n if (first < 0) {\n add(ring);\n continue;\n }\n // The walk starts after a cut and goes one time around the ring. So it ends at that cut, and each run of edges is complete.\n let run: Position[] = [];\n for (let steps = 1; steps <= count; steps++) {\n const edge = (first + steps) % count;\n const from = ring[edge];\n const to = ring[edge + 1];\n if (cut[edge] === true || from === undefined || to === undefined) {\n add(run);\n run = [];\n continue;\n }\n if (run.length === 0) run.push(from);\n run.push(to);\n }\n }\n }\n return lines;\n}\n\n/**\n * This function gives the lines of a grid of meridians and parallels. Each line is a list of longitudes and latitudes, in degrees: two numbers for each point.\n *\n * `spacing` is the angle between two lines, in degrees, and `step` is the largest step of a line. A spacing of 0 or less gives no lines.\n * The meridians at each 90 degrees go to the poles. The other meridians stop one spacing before each pole, so the poles stay clear.\n */\nexport function gridLines(spacing: number, step: number): Float64Array[] {\n if (!(spacing > 0) || !(step > 0) || !Number.isFinite(spacing)) return [];\n const lines: Float64Array[] = [];\n const add = (fromLon: number, fromLat: number, toLon: number, toLat: number): void => {\n const parts = Math.max(Math.ceil(Math.max(Math.abs(toLon - fromLon), Math.abs(toLat - fromLat)) / step), 1);\n const line = new Float64Array((parts + 1) * 2);\n for (let part = 0; part <= parts; part++) {\n line[part * 2] = fromLon + ((toLon - fromLon) * part) / parts;\n line[part * 2 + 1] = fromLat + ((toLat - fromLat) * part) / parts;\n }\n lines.push(line);\n };\n const top = (Math.ceil(90 / spacing) - 1) * spacing;\n for (let index = 0; index * spacing < 360 - ON_LINE; index++) {\n const lon = -180 + index * spacing;\n const quarter = Math.abs(lon / 90 - Math.round(lon / 90)) <= ON_LINE;\n const end = quarter ? 90 : top;\n if (end > 0) add(lon, -end, lon, end);\n }\n for (let lat = -top; lat <= top + ON_LINE; lat += spacing) add(-180, lat, 180, lat);\n return lines;\n}\n","import { fromUnitVector, toUnitVector, type LatLon, type Region } from \"@mark1russell7/geo\";\nimport type { Point3 } from \"@mark1russell7/layout-contract\";\nimport { ballView, capView, FIT_MARGIN, type StageView } from \"../extent.ts\";\nimport type { ViewAngles } from \"../view.ts\";\n\n/**\n * The polar limits of the camera of a globe: the camera goes above each pole.\n * Give this value to the option `polar` of a stage. Set the option `pan` to false, so the camera turns around the center of the Earth.\n */\nexport const GLOBE_POLAR: { readonly min: number; readonly max: number } = { min: 0.01, max: Math.PI - 0.01 };\n\nconst RADIANS = Math.PI / 180;\n\n/**\n * This function gives the point of a globe for a place on the Earth. The center of the globe is the origin of the stage.\n *\n * The axis `y` of the stage goes to the north pole. The axis `z` goes to latitude 0 and longitude 0, and the axis `x` goes to latitude 0 and longitude 90 east.\n * `radius` is the distance of the point from the center. The default is 1.\n */\nexport function globePoint(place: LatLon, radius: number = 1): Point3 {\n const unit = toUnitVector(place);\n return { x: unit.y * radius, y: unit.z * radius, z: unit.x * radius };\n}\n\n/**\n * This function gives the place on the Earth in the direction of a point of the stage, as seen from the center of the globe.\n * The center of the globe has no direction, so it gives `undefined`.\n */\nexport function globePlace(point: Point3): LatLon | undefined {\n if (point.x === 0 && point.y === 0 && point.z === 0) return undefined;\n if (!Number.isFinite(point.x) || !Number.isFinite(point.y) || !Number.isFinite(point.z)) return undefined;\n return fromUnitVector({ x: point.z, y: point.x, z: point.y });\n}\n\n/** This function gives the direction of a camera that is above a place on the Earth. */\nexport function globeAngles(place: LatLon): ViewAngles {\n return { polar: Math.PI / 2 - place.lat * RADIANS, azimuth: place.lon * RADIANS };\n}\n\n/**\n * This function makes a view from above a place on the Earth. The picture shows the cap of the Earth around the place.\n *\n * `degrees` is the angle of the cap at the center of the Earth. It is the distance from the place to the edge of the cap, in degrees of a great circle.\n * The default is 90: the picture shows a half of the Earth. `margin` is the space around the cap, as a factor of the height above the surface.\n */\nexport function globeView(place: LatLon, degrees: number = 90, margin: number = FIT_MARGIN): StageView {\n return capView(globeAngles(place), Math.min(Math.max(degrees, 0), 90) * RADIANS, margin);\n}\n\n/**\n * This function makes a view that shows each region of a list. The camera is above the middle of the regions.\n * A list with no regions gives a view of a half of the Earth. `margin` is the space around the regions, as a factor of the height above the surface.\n */\nexport function regionView(regions: readonly Region[], margin: number = FIT_MARGIN): StageView {\n const points: Point3[] = [];\n for (const region of regions) {\n const polygons = region.type === \"Polygon\" ? [region.coordinates] : region.coordinates;\n for (const polygon of polygons) {\n // The first ring of a polygon is its outer edge. A hole is in it, so the holes add no extent.\n for (const position of polygon[0] ?? []) points.push(globePoint({ lat: position[1], lon: position[0] }));\n }\n }\n return ballView(points, margin);\n}\n\n/**\n * This function gives the first point of a ball that a ray finds. The center of the ball is the origin of the stage.\n *\n * `direction` has the length 1. A ray that does not find the ball gives `undefined`, and a ray that starts in the ball also gives `undefined`.\n */\nexport function rayBall(origin: Point3, direction: Point3, radius: number): Point3 | undefined {\n const along = origin.x * direction.x + origin.y * direction.y + origin.z * direction.z;\n const outside = origin.x * origin.x + origin.y * origin.y + origin.z * origin.z - radius * radius;\n if (!(outside > 0)) return undefined;\n const root = along * along - outside;\n if (!(root >= 0)) return undefined;\n const distance = -along - Math.sqrt(root);\n if (!(distance >= 0)) return undefined;\n return { x: origin.x + direction.x * distance, y: origin.y + direction.y * distance, z: origin.z + direction.z * distance };\n}\n\n/**\n * This function tells if a camera at `eye` sees a point of the surface of a ball. The center of the ball is the origin of the stage.\n * A point on the far side of the ball gives false.\n */\nexport function inSight(point: Point3, eye: Point3, radius: number): boolean {\n const length = Math.hypot(point.x, point.y, point.z);\n if (!(length > 0)) return false;\n return (point.x * eye.x + point.y * eye.y + point.z * eye.z) / length > radius;\n}\n","import { pointLocator, type LatLon, type PointLocator, type Region } from \"@mark1russell7/geo\";\nimport type { Point3 } from \"@mark1russell7/layout-contract\";\nimport {\n BufferAttribute,\n BufferGeometry,\n Color,\n FrontSide,\n InstancedInterleavedBuffer,\n InterleavedBufferAttribute,\n Mesh,\n MeshBasicMaterial,\n Points,\n ShaderMaterial,\n Sphere,\n SphereGeometry,\n Vector3,\n type Object3D,\n type Raycaster,\n} from \"three\";\nimport { LineMaterial } from \"three/addons/lines/LineMaterial.js\";\nimport { LineSegments2 } from \"three/addons/lines/LineSegments2.js\";\nimport { LineSegmentsGeometry } from \"three/addons/lines/LineSegmentsGeometry.js\";\nimport type { Highlight } from \"../highlight.ts\";\nimport type { StageContent, StageFrame, StagePick } from \"../stage/stage.ts\";\nimport type { StageTheme } from \"../theme.ts\";\nimport { gridLines, regionEdges, regionSurface, surfaceSag } from \"./mesh.ts\";\nimport { globePlace, globePoint, inSight, rayBall } from \"./space.ts\";\n\n/** The look of the areas and the points of one kind. Each color is a CSS hex color. */\nexport interface GlobeStyle {\n /** The color of the surface of an area, or of a point. An area with no color has no surface, and a point with no color is not in the picture. */\n readonly fill?: string | undefined;\n /** The part of the light that the surface of an area stops, from 0 to 1. The default is 1. */\n readonly opacity?: number | undefined;\n /** The color of the edge of an area, or of the ring around a point. An area with no color has no edge. */\n readonly line?: string | undefined;\n}\n\n/** The colors of a globe. Each color is a CSS hex color. */\nexport interface GlobeTheme extends StageTheme {\n /** The color of the Earth where it has no area, for example the sea. */\n readonly ball: string;\n /** The color of the meridians and the parallels. */\n readonly grid: string;\n /** The color of the shade at the rim of the Earth. */\n readonly shade: string;\n /** The style of each kind of area or point, by the name of the kind. */\n readonly styles: Readonly<Record<string, GlobeStyle>>;\n /** The style of a kind that `styles` does not have. */\n readonly other: GlobeStyle;\n /** The color of the edge of a record under the pointer, or in the highlighted list. */\n readonly hovered: string;\n /** The color of the edge of the selected record. */\n readonly selected: string;\n}\n\n/** An area of a globe: a region of the Earth that belongs to a record. */\nexport interface GlobeArea<P> {\n /** The name of the record. Two parts with one name are one record: the stage highlights them together. */\n readonly record: string;\n /** The region, with edges that are straight lines in longitude and latitude, as in `@mark1russell7/geo`. */\n readonly region: Region;\n /** The name of the style of the area in the theme. */\n readonly kind: string;\n /** The value that a pick of the area gives to the page. */\n readonly value: P;\n /** This value is false for an area that the pointer does not find. The default is true. */\n readonly pick?: boolean | undefined;\n}\n\n/** A point of a globe: a place on the Earth that belongs to a record. The picture shows it as a dot of a constant size. */\nexport interface GlobePoint<P> {\n /** The name of the record. Two parts with one name are one record: the stage highlights them together. */\n readonly record: string;\n readonly place: LatLon;\n /** The name of the style of the point in the theme. */\n readonly kind: string;\n /** The value that a pick of the point gives to the page. */\n readonly value: P;\n /** The width of the dot, in CSS pixels. The default is the option `pointSize` of the globe. */\n readonly size?: number | undefined;\n /** This value is false for a point that the pointer does not find. The default is true. */\n readonly pick?: boolean | undefined;\n}\n\n/** The options of a globe. Each width is in CSS pixels. */\nexport interface GlobeOptions<P> {\n /** The areas, in the sequence of the picture: a later area is above an earlier area, and the pointer finds it first. */\n readonly areas?: readonly GlobeArea<P>[] | undefined;\n /** The points. Each point is above each area. */\n readonly points?: readonly GlobePoint<P>[] | undefined;\n /** The radius of the globe, in the units of the stage. The default is 1. */\n readonly radius?: number | undefined;\n /** The largest step of an edge in longitude or latitude, in degrees. A smaller step follows the curve of the Earth better. The default is 1. */\n readonly step?: number | undefined;\n /** The angle between two lines of the grid, in degrees. The value 0 gives no grid. The default is 15. */\n readonly grid?: number | undefined;\n /** The smallest height of the camera above the surface, as a part of the radius. The default is 0.005. */\n readonly nearest?: number | undefined;\n /** The width of the edge of an area. The default is 1.25. */\n readonly lineWidth?: number | undefined;\n /** The width of the edge of a record with a highlight. The default is 2.5. */\n readonly highlightWidth?: number | undefined;\n /** The width of a line of the grid. The default is 1. */\n readonly gridWidth?: number | undefined;\n /** The width of the dot of a point. The default is 9. */\n readonly pointSize?: number | undefined;\n /** The strength of the shade at the rim of the Earth, from 0 to 1. The default is 0.4. */\n readonly shade?: number | undefined;\n}\n\n/** The content of a stage that shows the Earth as a globe, with areas and points on it. */\nexport interface GlobeContent<P> extends StageContent<P, GlobeTheme> {\n /**\n * This function shows only the areas and the points that a test accepts. A part that the picture does not show gets no pick.\n * Start `refresh` of the stage after it. A test that accepts each part shows all of them again.\n */\n show(test: (part: GlobeArea<P> | GlobePoint<P>) => boolean): void;\n /** This function gives the place on the Earth that a ray from the camera finds. A ray that does not find the Earth gives `undefined`. */\n placeAt(ray: Raycaster): LatLon | undefined;\n}\n\n/** The smallest height of the layer of the areas above the ball, as a part of the radius. */\nconst MIN_LIFT = 0.0005;\n\n/** The opacity that a highlight adds to the surface of an area. */\nconst HIGHLIGHT_OPACITY = 0.16;\n\n/** The factor of the width of a point with a highlight. */\nconst HIGHLIGHT_SIZE = 1.35;\n\n/** The width of the ring around a point, in CSS pixels. */\nconst RING_WIDTH = 1.5;\n\n/** The distance around a point where the pointer finds it, in CSS pixels. */\nconst PICK_MARGIN = 4;\n\n/** The exponent of the shade at the rim. A large value keeps the shade near the rim. */\nconst SHADE_POWER = 2.6;\n\nconst BALL_SEGMENTS = 128;\n\nconst SHADE_VERTEX = `\nvarying vec3 vNormal;\nvarying vec3 vToEye;\nvoid main() {\n vec4 inView = modelViewMatrix * vec4(position, 1.0);\n vNormal = normalMatrix * normal;\n vToEye = -inView.xyz;\n gl_Position = projectionMatrix * inView;\n}`;\n\nconst SHADE_FRAGMENT = `\nuniform vec3 shade;\nuniform float strength;\nuniform float power;\nvarying vec3 vNormal;\nvarying vec3 vToEye;\nvoid main() {\n float facing = clamp(dot(normalize(vNormal), normalize(vToEye)), 0.0, 1.0);\n gl_FragColor = vec4(shade, strength * pow(1.0 - facing, power));\n #include <colorspace_fragment>\n}`;\n\nconst POINT_VERTEX = `\nuniform float pixelRatio;\nuniform float ringWidth;\nattribute vec3 fill;\nattribute vec3 ring;\nattribute float size;\nvarying vec3 vFill;\nvarying vec3 vRing;\nvarying float vFade;\nvarying float vInner;\nvoid main() {\n vec4 inWorld = modelMatrix * vec4(position, 1.0);\n vec3 up = normalize(inWorld.xyz - modelMatrix[3].xyz);\n float facing = dot(up, normalize(cameraPosition - inWorld.xyz));\n vFill = fill;\n vRing = ring;\n vFade = smoothstep(0.0, 0.1, facing);\n vInner = size / (size + 2.0 * ringWidth);\n gl_PointSize = (size + 2.0 * ringWidth) * pixelRatio;\n gl_Position = projectionMatrix * viewMatrix * inWorld;\n // A point on the far side of the Earth, and a point that the picture does not show, goes out of the picture.\n if (facing <= 0.0 || size <= 0.0) gl_Position = vec4(2.0, 2.0, 2.0, 1.0);\n}`;\n\nconst POINT_FRAGMENT = `\nvarying vec3 vFill;\nvarying vec3 vRing;\nvarying float vFade;\nvarying float vInner;\nvoid main() {\n float distance = length(gl_PointCoord * 2.0 - 1.0);\n float soft = fwidth(distance);\n float dot = 1.0 - smoothstep(1.0 - soft, 1.0, distance);\n float middle = 1.0 - smoothstep(vInner - soft, vInner, distance);\n gl_FragColor = vec4(mix(vRing, vFill, middle), dot * vFade);\n if (gl_FragColor.a <= 0.0) discard;\n #include <colorspace_fragment>\n}`;\n\n/** An area with the place of its data in the buffers of the globe. */\ninterface AreaPart<P> {\n readonly area: GlobeArea<P>;\n readonly locate: PointLocator | undefined;\n readonly firstCorner: number;\n readonly cornerCount: number;\n readonly firstIndex: number;\n readonly indexCount: number;\n readonly firstSegment: number;\n readonly segmentCount: number;\n shown: boolean;\n filled: boolean;\n lined: boolean;\n highlight: Highlight;\n}\n\n/** A point with its place on the globe. */\ninterface PointPart<P> {\n readonly point: GlobePoint<P>;\n readonly at: Point3;\n readonly size: number;\n shown: boolean;\n filled: boolean;\n highlight: Highlight;\n}\n\n/** This function gives the text of a thrown value. */\nfunction messageOf(error: unknown): string {\n return error instanceof Error ? error.message : String(error);\n}\n\n/** This function writes the points of lines into a list of segments on a ball: six numbers for each segment. It gives the count of the segments. */\nfunction addSegments(lines: readonly Float64Array[], radius: number, to: number[]): number {\n let count = 0;\n for (const line of lines) {\n let from: Point3 | undefined;\n for (let index = 0; index + 1 < line.length; index += 2) {\n const next = globePoint({ lat: line[index + 1] ?? 0, lon: line[index] ?? 0 }, radius);\n if (from !== undefined) {\n to.push(from.x, from.y, from.z, next.x, next.y, next.z);\n count += 1;\n }\n from = next;\n }\n }\n return count;\n}\n\n/** This function makes the geometry of thick line segments from a buffer of positions and a buffer of colors: six numbers for each segment. */\nfunction segmentGeometry(positions: InstancedInterleavedBuffer, colors: InstancedInterleavedBuffer | undefined, count: number, bounds: Sphere): LineSegmentsGeometry {\n const geometry = new LineSegmentsGeometry();\n geometry.setAttribute(\"instanceStart\", new InterleavedBufferAttribute(positions, 3, 0));\n geometry.setAttribute(\"instanceEnd\", new InterleavedBufferAttribute(positions, 3, 3));\n if (colors !== undefined) {\n geometry.setAttribute(\"instanceColorStart\", new InterleavedBufferAttribute(colors, 3, 0));\n geometry.setAttribute(\"instanceColorEnd\", new InterleavedBufferAttribute(colors, 3, 3));\n }\n geometry.instanceCount = count;\n geometry.boundingSphere = bounds;\n return geometry;\n}\n\n/**\n * This function makes the content of a stage that shows the Earth as a globe. The center of the globe is the origin of the stage.\n *\n * The materials use no light, so each color in the picture is the color of the theme. Use `GLOBE_POLAR` and no pan in the options of the stage.\n * The function throws an `Error` with the name of the record for an area that is not correct. Its cause is the error of `@mark1russell7/geo`.\n */\nexport function createGlobe<P>(options: GlobeOptions<P> = {}): GlobeContent<P> {\n const radius = options.radius ?? 1;\n const step = options.step ?? 1;\n const layer = radius * (1 + Math.max(MIN_LIFT, surfaceSag(step) * 2));\n const bounds = new Sphere(new Vector3(0, 0, 0), layer);\n const color = new Color();\n\n // The ball, and the shade at its rim.\n const ballGeometry = new SphereGeometry(radius, BALL_SEGMENTS, BALL_SEGMENTS / 2);\n const ballMaterial = new MeshBasicMaterial();\n const ball = new Mesh(ballGeometry, ballMaterial);\n const shadeColor = { value: new Color() };\n const shadeMaterial = new ShaderMaterial({\n uniforms: { shade: shadeColor, strength: { value: Math.min(Math.max(options.shade ?? 0.4, 0), 1) }, power: { value: SHADE_POWER } },\n vertexShader: SHADE_VERTEX,\n fragmentShader: SHADE_FRAGMENT,\n transparent: true,\n depthTest: false,\n depthWrite: false,\n side: FrontSide,\n });\n const shade = new Mesh(ballGeometry, shadeMaterial);\n shade.renderOrder = 4;\n\n // The grid.\n const gridList: number[] = [];\n const gridCount = addSegments(gridLines(options.grid ?? 15, step), layer, gridList);\n const gridMaterial = new LineMaterial({ linewidth: options.gridWidth ?? 1, transparent: true, depthWrite: false });\n const grid = new LineSegments2(segmentGeometry(new InstancedInterleavedBuffer(Float32Array.from(gridList), 6, 1), undefined, gridCount, bounds), gridMaterial);\n grid.renderOrder = 1;\n grid.visible = gridCount > 0;\n grid.frustumCulled = false;\n\n // The areas: one surface and one list of segments for all of them.\n const surfaces: { readonly corners: Float64Array; readonly triangles: Uint32Array }[] = [];\n const segmentList: number[] = [];\n const areaParts: AreaPart<P>[] = [];\n let cornerTotal = 0;\n let indexTotal = 0;\n let segmentTotal = 0;\n for (const area of options.areas ?? []) {\n try {\n const surface = regionSurface(area.region, step);\n const segmentCount = addSegments(regionEdges(area.region, step), layer, segmentList);\n areaParts.push({\n area,\n locate: area.pick === false ? undefined : pointLocator(area.region),\n firstCorner: cornerTotal,\n cornerCount: surface.corners.length / 2,\n firstIndex: indexTotal,\n indexCount: surface.triangles.length,\n firstSegment: segmentTotal,\n segmentCount,\n shown: true,\n filled: false,\n lined: false,\n highlight: 0,\n });\n surfaces.push(surface);\n cornerTotal += surface.corners.length / 2;\n indexTotal += surface.triangles.length;\n segmentTotal += segmentCount;\n } catch (error) {\n throw new Error(`The area of the record ${area.record} is not correct: ${messageOf(error)}`, { cause: error });\n }\n }\n const fillPositions = new Float32Array(cornerTotal * 3);\n const allIndices = new Uint32Array(indexTotal);\n surfaces.forEach((surface, index) => {\n const part = areaParts[index];\n if (part === undefined) return;\n for (let corner = 0; corner < part.cornerCount; corner++) {\n const point = globePoint({ lat: surface.corners[corner * 2 + 1] ?? 0, lon: surface.corners[corner * 2] ?? 0 }, layer);\n fillPositions.set([point.x, point.y, point.z], (part.firstCorner + corner) * 3);\n }\n for (let at = 0; at < part.indexCount; at++) allIndices[part.firstIndex + at] = (surface.triangles[at] ?? 0) + part.firstCorner;\n });\n const fillColors = new BufferAttribute(new Float32Array(cornerTotal * 4), 4);\n const fillIndices = new BufferAttribute(new Uint32Array(indexTotal), 1);\n const fillGeometry = new BufferGeometry();\n fillGeometry.setAttribute(\"position\", new BufferAttribute(fillPositions, 3));\n fillGeometry.setAttribute(\"color\", fillColors);\n fillGeometry.setIndex(fillIndices);\n fillGeometry.boundingSphere = bounds;\n const fillMaterial = new MeshBasicMaterial({ vertexColors: true, transparent: true, depthWrite: false, side: FrontSide });\n const fills = new Mesh(fillGeometry, fillMaterial);\n fills.renderOrder = 2;\n fills.frustumCulled = false;\n\n // The edges of the areas. The picture draws the segments at the start of the buffers, so the segments of the shown areas are there.\n const allSegments = Float32Array.from(segmentList);\n const allSegmentColors = new Float32Array(allSegments.length);\n const edgePositions = new InstancedInterleavedBuffer(new Float32Array(allSegments.length), 6, 1);\n const edgeColors = new InstancedInterleavedBuffer(new Float32Array(allSegments.length), 6, 1);\n const edgeGeometry = segmentGeometry(edgePositions, edgeColors, 0, bounds);\n const edgeMaterial = new LineMaterial({ linewidth: options.lineWidth ?? 1.25, vertexColors: true, transparent: true, depthWrite: false });\n const edges = new LineSegments2(edgeGeometry, edgeMaterial);\n edges.renderOrder = 3;\n edges.frustumCulled = false;\n\n // The edges of the records with a highlight, above the other edges.\n const highlightMaterial = new LineMaterial({ linewidth: options.highlightWidth ?? 2.5, vertexColors: true, transparent: true, depthWrite: false });\n const highlighted = new LineSegments2(new LineSegmentsGeometry(), highlightMaterial);\n highlighted.renderOrder = 5;\n highlighted.frustumCulled = false;\n highlighted.visible = false;\n\n // The points.\n const pointSize = options.pointSize ?? 9;\n const pointParts: PointPart<P>[] = (options.points ?? []).map((point) => ({\n point,\n at: globePoint(point.place, layer),\n size: point.size ?? pointSize,\n shown: true,\n filled: false,\n highlight: 0,\n }));\n const pointPositions = new Float32Array(pointParts.length * 3);\n pointParts.forEach((part, index) => pointPositions.set([part.at.x, part.at.y, part.at.z], index * 3));\n const pointFills = new BufferAttribute(new Float32Array(pointParts.length * 3), 3);\n const pointRings = new BufferAttribute(new Float32Array(pointParts.length * 3), 3);\n const pointSizes = new BufferAttribute(new Float32Array(pointParts.length), 1);\n const pointGeometry = new BufferGeometry();\n pointGeometry.setAttribute(\"position\", new BufferAttribute(pointPositions, 3));\n pointGeometry.setAttribute(\"fill\", pointFills);\n pointGeometry.setAttribute(\"ring\", pointRings);\n pointGeometry.setAttribute(\"size\", pointSizes);\n pointGeometry.boundingSphere = bounds;\n const pixelRatio = { value: 1 };\n const pointMaterial = new ShaderMaterial({\n uniforms: { pixelRatio, ringWidth: { value: RING_WIDTH } },\n vertexShader: POINT_VERTEX,\n fragmentShader: POINT_FRAGMENT,\n transparent: true,\n depthTest: false,\n depthWrite: false,\n });\n const dots = new Points(pointGeometry, pointMaterial);\n dots.renderOrder = 6;\n dots.frustumCulled = false;\n dots.visible = pointParts.length > 0;\n // The size of a dot is in CSS pixels, and the picture can have more than one pixel for each CSS pixel.\n dots.onBeforeRender = (renderer): void => {\n pixelRatio.value = renderer.getPixelRatio();\n };\n\n const records = new Set<string>([...areaParts.map((part) => part.area.record), ...pointParts.map((part) => part.point.record)]);\n let painted: GlobeTheme | undefined;\n /** The angle of one CSS pixel at the middle of the picture, in radians. */\n let pixelAngle = 0.001;\n\n const styleOf = (theme: GlobeTheme, kind: string): GlobeStyle => theme.styles[kind] ?? theme.other;\n const highlightColor = (theme: GlobeTheme, highlight: Highlight): string => (highlight === 2 ? theme.selected : theme.hovered);\n\n /** This function writes the colors of an area into the buffers. */\n const paintArea = (part: AreaPart<P>, theme: GlobeTheme): void => {\n const style = styleOf(theme, part.area.kind);\n part.filled = style.fill !== undefined;\n part.lined = style.line !== undefined;\n if (style.fill !== undefined) {\n color.set(style.fill);\n const opacity = Math.min(Math.max(style.opacity ?? 1, 0), 1);\n const alpha = part.highlight === 0 ? opacity : Math.min(opacity + HIGHLIGHT_OPACITY, 1);\n const values = [color.r, color.g, color.b, alpha];\n for (let corner = 0; corner < part.cornerCount; corner++) fillColors.array.set(values, (part.firstCorner + corner) * 4);\n fillColors.needsUpdate = true;\n }\n if (style.line !== undefined) {\n color.set(style.line);\n const values = [color.r, color.g, color.b, color.r, color.g, color.b];\n for (let segment = 0; segment < part.segmentCount; segment++) allSegmentColors.set(values, (part.firstSegment + segment) * 6);\n }\n };\n\n /** This function puts the data of the shown parts at the start of the buffers that the picture draws. */\n const sync = (theme: GlobeTheme): void => {\n let indexCount = 0;\n let segmentCount = 0;\n let highlightCount = 0;\n for (const part of areaParts) {\n if (!part.shown) continue;\n if (part.filled) {\n fillIndices.array.set(allIndices.subarray(part.firstIndex, part.firstIndex + part.indexCount), indexCount);\n indexCount += part.indexCount;\n }\n if (part.lined) {\n const from = part.firstSegment * 6;\n const to = from + part.segmentCount * 6;\n edgePositions.array.set(allSegments.subarray(from, to), segmentCount * 6);\n edgeColors.array.set(allSegmentColors.subarray(from, to), segmentCount * 6);\n segmentCount += part.segmentCount;\n }\n if (part.highlight !== 0) highlightCount += part.segmentCount;\n }\n fillIndices.needsUpdate = true;\n fillGeometry.setDrawRange(0, indexCount);\n fills.visible = indexCount > 0;\n edgePositions.needsUpdate = true;\n edgeColors.needsUpdate = true;\n edgeGeometry.instanceCount = segmentCount;\n edges.visible = segmentCount > 0;\n\n // The edges of the records with a highlight get a new geometry. They are few, and a record changes its highlight only on an act of a person.\n const highlightPositions = new Float32Array(highlightCount * 6);\n const highlightColors = new Float32Array(highlightCount * 6);\n let at = 0;\n for (const part of areaParts) {\n if (!part.shown || part.highlight === 0) continue;\n color.set(highlightColor(theme, part.highlight));\n const values = [color.r, color.g, color.b, color.r, color.g, color.b];\n highlightPositions.set(allSegments.subarray(part.firstSegment * 6, (part.firstSegment + part.segmentCount) * 6), at * 6);\n for (let segment = 0; segment < part.segmentCount; segment++) highlightColors.set(values, (at + segment) * 6);\n at += part.segmentCount;\n }\n highlighted.geometry.dispose();\n highlighted.geometry =\n highlightCount > 0 ? segmentGeometry(new InstancedInterleavedBuffer(highlightPositions, 6, 1), new InstancedInterleavedBuffer(highlightColors, 6, 1), highlightCount, bounds) : new LineSegmentsGeometry();\n highlighted.visible = highlightCount > 0;\n\n pointParts.forEach((part, index) => {\n const style = styleOf(theme, part.point.kind);\n part.filled = style.fill !== undefined;\n const visible = part.shown && style.fill !== undefined;\n pointSizes.array[index] = visible ? part.size * (part.highlight === 0 ? 1 : HIGHLIGHT_SIZE) : 0;\n if (style.fill === undefined) return;\n color.set(style.fill);\n pointFills.array.set([color.r, color.g, color.b], index * 3);\n color.set(part.highlight === 0 ? (style.line ?? style.fill) : highlightColor(theme, part.highlight));\n pointRings.array.set([color.r, color.g, color.b], index * 3);\n });\n pointSizes.needsUpdate = true;\n pointFills.needsUpdate = true;\n pointRings.needsUpdate = true;\n };\n\n return {\n objects: [ball, grid, fills, edges, shade, highlighted, dots] satisfies Object3D[],\n extent: { center: { x: 0, y: 0, z: 0 }, corners: [], surface: radius, minDistance: radius * (1 + Math.max(options.nearest ?? 0.005, 1e-6)) },\n has: (record) => records.has(record),\n pick(ray): StagePick<P> | undefined {\n const { origin, direction } = ray.ray;\n let found: PointPart<P> | undefined;\n let nearest = Infinity;\n for (const part of pointParts) {\n if (!part.shown || !part.filled || part.point.pick === false || !inSight(part.at, origin, radius)) continue;\n const x = part.at.x - origin.x;\n const y = part.at.y - origin.y;\n const z = part.at.z - origin.z;\n const cosine = (x * direction.x + y * direction.y + z * direction.z) / Math.hypot(x, y, z);\n const angle = Math.acos(Math.min(Math.max(cosine, -1), 1));\n if (angle > (part.size / 2 + PICK_MARGIN) * pixelAngle || angle >= nearest) continue;\n found = part;\n nearest = angle;\n }\n if (found !== undefined) return { record: found.point.record, value: found.point.value };\n const hit = rayBall(origin, direction, radius);\n const place = hit === undefined ? undefined : globePlace(hit);\n if (place === undefined) return undefined;\n for (let index = areaParts.length - 1; index >= 0; index--) {\n const part = areaParts[index];\n if (part === undefined || !part.shown || part.locate === undefined || !(part.filled || part.lined)) continue;\n if (part.locate(place) !== \"outside\") return { record: part.area.record, value: part.area.value };\n }\n return undefined;\n },\n paint(theme, highlight): void {\n const all = theme !== painted;\n painted = theme;\n if (all) {\n ballMaterial.color.set(theme.ball);\n gridMaterial.color.set(theme.grid);\n shadeColor.value.set(theme.shade);\n }\n for (const part of areaParts) {\n const next = highlight(part.area.record);\n if (!all && next === part.highlight) continue;\n part.highlight = next;\n paintArea(part, theme);\n }\n for (const part of pointParts) part.highlight = highlight(part.point.record);\n sync(theme);\n },\n step(frame: StageFrame): boolean {\n pixelAngle = (2 * Math.tan((frame.fieldOfView * Math.PI) / 360)) / Math.max(frame.height, 1);\n return false;\n },\n show(test): void {\n for (const part of areaParts) part.shown = test(part.area);\n for (const part of pointParts) part.shown = test(part.point);\n if (painted !== undefined) sync(painted);\n },\n placeAt(ray): LatLon | undefined {\n const hit = rayBall(ray.ray.origin, ray.ray.direction, radius);\n return hit === undefined ? undefined : globePlace(hit);\n },\n dispose(): void {\n ballGeometry.dispose();\n ballMaterial.dispose();\n shadeMaterial.dispose();\n grid.geometry.dispose();\n gridMaterial.dispose();\n fillGeometry.dispose();\n fillMaterial.dispose();\n edgeGeometry.dispose();\n edgeMaterial.dispose();\n highlighted.geometry.dispose();\n highlightMaterial.dispose();\n pointGeometry.dispose();\n pointMaterial.dispose();\n },\n };\n}\n"],"mappings":";;;;;;;;AAeA,MAAa,sBAAsB;;;;;AAMnC,MAAM,YAAY;;;;;;AAOlB,MAAM,YAAY;;AAGlB,MAAM,aAAa;;AAGnB,MAAM,MAAM,KAAK;;AAGjB,MAAM,UAAU;;AAGhB,MAAM,UAAU;AAEhB,MAAMA,YAAU,KAAK,KAAK;;AAG1B,SAAS,GAAG,MAAyB,OAAuB;CAC1D,OAAO,KAAK,UAAU;AACxB;AAEA,SAAS,QAAQ,GAAW,GAAmB;CAC7C,OAA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AAQ,YAAY,KAAK,QAAQ,KAAK,KAAK,KAAK;GAC3D,IAAI,YAAY,KAAA,GAAW,KAAK,OAAO;EACzC;EACA,QAAQ,KAAyB;GAC/B,MAAM,MAAM,QAAQ,IAAI,IAAI,QAAQ,IAAI,IAAI,WAAW,MAAM;GAC7D,OAAO,QAAQ,KAAA,IAAY,KAAA,IAAY,WAAW,GAAG;EACvD;EACA,UAAgB;GACd,aAAa,QAAQ;GACrB,aAAa,QAAQ;GACrB,cAAc,QAAQ;GACtB,KAAK,SAAS,QAAQ;GACtB,aAAa,QAAQ;GACrB,aAAa,QAAQ;GACrB,aAAa,QAAQ;GACrB,aAAa,QAAQ;GACrB,aAAa,QAAQ;GACrB,YAAY,SAAS,QAAQ;GAC7B,kBAAkB,QAAQ;GAC1B,cAAc,QAAQ;GACtB,cAAc,QAAQ;EACxB;CACF;AACF"}
package/build/index.d.ts CHANGED
@@ -1,4 +1,4 @@
1
- import { C as clampPlace, D as turnBetween, E as speedAt, O as viewAxes, S as capDistance, T as placeBetween, _ as Place, a as NO_MARKS, b as ViewAxes, c as FIT_MARGIN, d as StageView, f as ViewFrame, g as surfaceOf, h as stageLimits, i as Marks, k as viewOf, l as StageExtent, m as fitView, n as CLICK_DISTANCE, o as isClick, p as capView, r as Mark, s as markOf, t as StageTheme, u as StageLimits, v as PlaceLimits, w as fitDistance, x as cameraPosition, y as ViewAngles } from "./theme-eOmfx75p.js";
1
+ import { A as turnBetween, C as ViewAxes, D as fitDistance, E as clampPlace, M as viewOf, O as placeBetween, S as ViewAngles, T as capDistance, _ as reachOf, a as NO_HIGHLIGHTS, b as Place, c as FIT_MARGIN, d as StageView, f as ViewFrame, g as nearDepth, h as fitView, i as Highlights, j as viewAxes, k as speedAt, l as StageExtent, m as capView, n as CLICK_DISTANCE, o as highlightOf, p as ballView, r as Highlight, s as isClick, t as StageTheme, u as StageLimits, v as stageLimits, w as cameraPosition, x as PlaceLimits, y as surfaceOf } from "./theme-CKXd_emk.js";
2
2
  /** The angle of one step of an arrow key, in radians, for a camera far from the surface. */
3
3
  export declare const KEY_TURN: number;
4
4
  /** The factor of the height of a camera above the surface for one step of the key `+`. */
@@ -60,5 +60,5 @@ export declare function moveAt(move: Move, now: number, surface?: number): MoveS
60
60
  * A step with no time gives the goal. A value nearer to the goal than `snap` becomes the goal, so the steps have an end.
61
61
  */
62
62
  export declare function approach(value: number, goal: number, seconds: number, time: number, snap?: number): number;
63
- export { CLICK_DISTANCE, FIT_MARGIN, type KeyAction, type KeyOptions, type Mark, type Marks, type Move, type MoveStep, NO_MARKS, type Place, type PlaceLimits, type StageExtent, type StageLimits, type StageTheme, type StageView, type ViewAngles, type ViewAxes, type ViewFrame, cameraPosition, capDistance, capView, clampPlace, fitDistance, fitView, isClick, markOf, placeBetween, speedAt, stageLimits, surfaceOf, turnBetween, viewAxes, viewOf };
63
+ export { CLICK_DISTANCE, FIT_MARGIN, type Highlight, type Highlights, type KeyAction, type KeyOptions, type Move, type MoveStep, NO_HIGHLIGHTS, type Place, type PlaceLimits, type StageExtent, type StageLimits, type StageTheme, type StageView, type ViewAngles, type ViewAxes, type ViewFrame, ballView, cameraPosition, capDistance, capView, clampPlace, fitDistance, fitView, highlightOf, isClick, nearDepth, placeBetween, reachOf, speedAt, stageLimits, surfaceOf, turnBetween, viewAxes, viewOf };
64
64
  //# sourceMappingURL=index.d.ts.map
package/build/index.js CHANGED
@@ -1 +1,3 @@
1
- export { i as CLICK_DISTANCE, d as FIT_MARGIN, c as KEY_TURN, l as KEY_ZOOM, a as NO_MARKS, t as approach, g as cameraPosition, _ as capDistance, f as capView, v as clampPlace, n as easeInOut, y as fitDistance, p as fitView, o as isClick, u as keyAction, s as markOf, r as moveAt, b as placeBetween, x as speedAt, m as stageLimits, h as surfaceOf, S as turnBetween, C as viewAxes, w as viewOf } from "./motion-Ba4IIfAV.js";
1
+ import { _ as viewOf, a as nearDepth, c as surfaceOf, d as clampPlace, f as fitDistance, g as viewAxes, h as turnBetween, i as fitView, l as cameraPosition, m as speedAt, n as ballView, o as reachOf, p as placeBetween, r as capView, s as stageLimits, t as FIT_MARGIN, u as capDistance } from "./extent-CALhBZU-.js";
2
+ import { a as NO_HIGHLIGHTS, c as KEY_TURN, i as CLICK_DISTANCE, l as KEY_ZOOM, n as easeInOut, o as highlightOf, r as moveAt, s as isClick, t as approach, u as keyAction } from "./motion-0tsT6sY4.js";
3
+ export { CLICK_DISTANCE, FIT_MARGIN, KEY_TURN, KEY_ZOOM, NO_HIGHLIGHTS, approach, ballView, cameraPosition, capDistance, capView, clampPlace, easeInOut, fitDistance, fitView, highlightOf, isClick, keyAction, moveAt, nearDepth, placeBetween, reachOf, speedAt, stageLimits, surfaceOf, turnBetween, viewAxes, viewOf };
@@ -0,0 +1,192 @@
1
+ import { Point3, Ring } from "@mark1russell7/layout-contract";
2
+ /** These are the levels of a mark, from the lowest to the highest. */
3
+ export declare const LEVELS: readonly ["unknown", "ok", "near", "over"];
4
+ /**
5
+ * A level of a mark, in the scale of limits. `ok` is below a limit, `near` is near it and `over` is above it.
6
+ * A mark with no known value has `unknown`. The producer of a mark calculates the level, because each topic has its own limits.
7
+ */
8
+ type Level = (typeof LEVELS)[number];
9
+ /**
10
+ * This function gives the rank of a level: 0 for `unknown` and 3 for `over`.
11
+ * A viewer draws the marks in the sequence of their ranks, so the worst level is always in view.
12
+ */
13
+ export declare function levelRank(level: Level): number;
14
+ /** These are the shapes of the sign of a level. */
15
+ export declare const LEVEL_SHAPES: readonly ["ring", "disc", "triangle", "square"];
16
+ /** A shape of the sign of a level. A person who does not see a color reads the level from the shape. */
17
+ type LevelShape = (typeof LEVEL_SHAPES)[number];
18
+ /**
19
+ * This function gives the shape of the sign of a level: a disc for `ok`, a triangle for `near` and a square for `over`.
20
+ * The level `unknown` has a ring, and so has a record with no level.
21
+ */
22
+ export declare function levelShape(level: Level | undefined): LevelShape;
23
+ /** The outline of the sign of a shape, as a regular polygon. A circle is a polygon with 40 sides. */
24
+ interface ShapeOutline {
25
+ /** The radius of the circle through the corners, for a disc with the radius 1. */
26
+ readonly radius: number;
27
+ /** The number of the sides. */
28
+ readonly sides: number;
29
+ /** The angle of the first corner, in radians, counter-clockwise from the x axis. */
30
+ readonly start: number;
31
+ /** The radius of the hole of the sign, for a disc with the radius 1. A sign with no hole has 0. */
32
+ readonly hole: number;
33
+ }
34
+ /**
35
+ * The outline of the sign of each shape. Each viewer draws the signs from these values, so each viewer shows the same signs.
36
+ * A triangle and a square with the radius of the disc look small, so they are larger.
37
+ */
38
+ export declare const SHAPE_OUTLINES: Readonly<Record<LevelShape, ShapeOutline>>;
39
+ /**
40
+ * This function gives the corners of the outline of a sign, counter-clockwise, with the y axis up.
41
+ * The center of the sign is the origin, and `radius` is the radius of a disc.
42
+ */
43
+ export declare function shapeRing(shape: LevelShape, radius?: number): Ring;
44
+ /** A point of a surface, and the direction out of the surface. */
45
+ interface Frame {
46
+ /** The point. */
47
+ readonly at: Point3;
48
+ /** The unit vector out of the surface at the point. */
49
+ readonly out: Point3;
50
+ }
51
+ /** These are the types of a mark. */
52
+ export declare const MARK_TYPES: readonly ["point", "run", "link", "field", "meter"];
53
+ /** A type of a mark. */
54
+ type MarkType = (typeof MARK_TYPES)[number];
55
+ /**
56
+ * The parts that each mark has. A mark has no shape and no color.
57
+ * 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.
58
+ */
59
+ interface MarkBase {
60
+ /** The name of the record of the mark. The pointer and the selection of a viewer use this name. */
61
+ readonly record: string;
62
+ /** A word of the producer for the legend and the filter, for example `outlet`. */
63
+ readonly kind: string;
64
+ /** The level of the mark. The producer calculates it. */
65
+ readonly level: Level;
66
+ /** One line of text: the name of the mark for a person and for a screen reader. */
67
+ readonly label: string;
68
+ }
69
+ /** A mark at one point of a surface, for example an outlet, a tap or a lamp. */
70
+ interface PointMark extends MarkBase {
71
+ readonly type: "point";
72
+ /** The point, and the direction out of its surface. */
73
+ readonly frame: Frame;
74
+ /** The width of the sign, in the unit of the space. A mark with no size gets the default size of the viewer. */
75
+ readonly size?: number | undefined;
76
+ }
77
+ /** A mark along a path on surfaces, for example a cable, a pipe or a duct. */
78
+ interface RunMark extends MarkBase {
79
+ readonly type: "run";
80
+ /** 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. */
81
+ readonly path: readonly Frame[];
82
+ /** The width of the run, in the unit of the space. */
83
+ readonly width: number;
84
+ }
85
+ /** One end of a link. */
86
+ interface LinkEnd {
87
+ /** 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. */
88
+ readonly record: string;
89
+ /** The point of this end. */
90
+ readonly at: Point3;
91
+ }
92
+ /** A mark between two records, for example a power line from an outlet to a computer. */
93
+ interface LinkMark extends MarkBase {
94
+ readonly type: "link";
95
+ readonly from: LinkEnd;
96
+ readonly to: LinkEnd;
97
+ }
98
+ /** The scale of the values of a field. The theme of a viewer gives the colors from `min` to `max`. */
99
+ interface FieldScale {
100
+ /** The value of the first color. It is less than `max`. */
101
+ readonly min: number;
102
+ /** The value of the last color. */
103
+ readonly max: number;
104
+ /** The text of the unit of the values, for example `lx`. */
105
+ readonly unit: string;
106
+ }
107
+ /** A grid of values on a plane, for example the light on a floor or the heat of a wall. */
108
+ interface FieldMark extends MarkBase {
109
+ readonly type: "field";
110
+ /** The corner of the first cell, and the direction out of the plane. */
111
+ readonly frame: Frame;
112
+ /** The unit vector of a column step, in the plane. The step of a row is the cross product of `frame.out` and `across`. */
113
+ readonly across: Point3;
114
+ /** The length of a side of a cell, in the unit of the space. */
115
+ readonly cell: number;
116
+ /** The number of the columns. */
117
+ readonly columns: number;
118
+ /** The number of the rows. */
119
+ readonly rows: number;
120
+ /**
121
+ * The values, row by row. The value of the column `c` and the row `r` has the index `r * columns + c`.
122
+ * A cell with no value has `null`, because JSON has no NaN.
123
+ */
124
+ readonly values: readonly (number | null)[];
125
+ readonly scale: FieldScale;
126
+ }
127
+ /**
128
+ * A value against a limit, for example the load of a circuit. A meter has no place.
129
+ * A page draws it in a panel, and a 3D view ignores it.
130
+ */
131
+ interface MeterMark extends MarkBase {
132
+ readonly type: "meter";
133
+ readonly value: number;
134
+ readonly limit: number;
135
+ /** The text of the unit of the value and of the limit, for example `W`. */
136
+ readonly unit: string;
137
+ }
138
+ /**
139
+ * A record that a viewer draws. A mark is plain data with no topic, so it goes through JSON with no change.
140
+ * Each point of a list of marks is in one space. The producer tells the unit and the axes of that space.
141
+ */
142
+ type Mark = PointMark | RunMark | LinkMark | FieldMark | MeterMark;
143
+ /** This function gives the unit vector of a row step of a field: the cross product of `frame.out` and `across`. */
144
+ export declare function fieldRowStep(field: FieldMark): Point3;
145
+ /** This function gives the center of a cell of a field. The first cell has the column 0 and the row 0. */
146
+ export declare function fieldCellCenter(field: FieldMark, column: number, row: number): Point3;
147
+ /** 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. */
148
+ export declare function fieldValue(field: FieldMark, column: number, row: number): number | null;
149
+ /**
150
+ * These are the codes of the faults of a mark:
151
+ * - `type`: the type of the mark is not known. A list from a later version of a producer can have a new type.
152
+ * - `level`: the level of the mark is not known.
153
+ * - `name`: a record name or the kind is empty.
154
+ * - `label`: the label is empty, or it has more than one line.
155
+ * - `number`: a number is not finite.
156
+ * - `direction`: a direction is not a unit vector.
157
+ * - `angle`: the column step of a field is not at a right angle to the direction out of its plane.
158
+ * - `size`: a size, a width or a cell is not more than 0.
159
+ * - `grid`: the number of the columns or of the rows of a field is not a whole number of 1 or more.
160
+ * - `values`: a field does not have one value for each cell.
161
+ * - `scale`: the `min` of the scale of a field is not less than its `max`.
162
+ * - `path`: a run has fewer than 2 points.
163
+ */
164
+ export declare const MARK_FAULT_CODES: readonly ["type", "level", "name", "label", "number", "direction", "angle", "size", "grid", "values", "scale", "path"];
165
+ /** A code of a fault of a mark. */
166
+ type MarkFaultCode = (typeof MARK_FAULT_CODES)[number];
167
+ /** One fault of a mark of a list. */
168
+ interface MarkFault {
169
+ readonly code: MarkFaultCode;
170
+ /** The index of the mark in the list. */
171
+ readonly index: number;
172
+ /** The record name of the mark. */
173
+ readonly record: string;
174
+ /** The part of the mark with the fault, for example `path[2].out`. */
175
+ readonly part: string;
176
+ /** The fault in plain words, with the values. */
177
+ readonly message: string;
178
+ }
179
+ /**
180
+ * The tolerance of a direction. A unit vector has the length 1 with this tolerance.
181
+ * Two directions are at a right angle when their dot product is 0 with this tolerance.
182
+ */
183
+ export declare const DIRECTION_TOLERANCE = 1e-6;
184
+ /**
185
+ * This function gives the faults of a list of marks, in the sequence of the list. A list with no fault gives an empty list.
186
+ * It examines the values that the types do not hold: finite numbers, unit vectors, sizes, the grid of a field and the names.
187
+ * A producer of marks uses it as a gate in its tests, and a viewer uses it on a list that it did not make.
188
+ * It does not examine the form of a mark: read a list from JSON through a schema first.
189
+ */
190
+ export declare function checkMarks(marks: readonly Mark[]): readonly MarkFault[];
191
+ export type { FieldMark, FieldScale, Frame, Level, LevelShape, LinkEnd, LinkMark, Mark, MarkBase, MarkFault, MarkFaultCode, MarkType, MeterMark, PointMark, RunMark, ShapeOutline };
192
+ //# sourceMappingURL=marks.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"marks.d.ts","names":[],"sources":["../src/marks/levels.ts","../src/marks/mark.ts","../src/marks/check.ts"],"mappings":";;qBAGa;;;;;KAMD,gBAAgB;;;;;wBAMZ,UAAU,OAAO;;qBAKpB;;KAGD,qBAAqB;;;;;wBAMjB,WAAW,OAAO,oBAAoB;;UAKrC;;WAEN;;WAEA;;WAEA;;WAEA;;;;;;qBAOE,gBAAgB,SAAS,OAAO,YAAY;;;;;wBAWzC,UAAU,OAAO,YAAY,kBAAqB;;UCxDjD;;WAEN,IAAI;;WAEJ,KAAK;;;qBAIH;;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;WACA;;WAEA;;;;;;KAOC,OAAO,YAAY,UAAU,WAAW,YAAY;;wBAGhD,aAAa,OAAO,YAAY;;wBAKhC,gBAAgB,OAAO,WAAW,gBAAgB,cAAc;;wBAOhE,WAAW,OAAO,WAAW,gBAAgB;;;;;;;;;;;;;;;;qBC5GhD;;KAgBD,wBAAwB;;UAGnB;WACN,MAAM;;WAEN;;WAEA;;WAEA;;WAEA;;;;;;qBAOE;;;;;;;wBAQG,WAAW,gBAAgB,kBAAkB"}
package/build/marks.js ADDED
@@ -0,0 +1,231 @@
1
+ import { addPoints3, cross3, dot3, length3, scalePoint3 } from "@mark1russell7/layout-contract";
2
+ // src/marks/levels.ts
3
+ /** These are the levels of a mark, from the lowest to the highest. */
4
+ const LEVELS = [
5
+ "unknown",
6
+ "ok",
7
+ "near",
8
+ "over"
9
+ ];
10
+ /**
11
+ * This function gives the rank of a level: 0 for `unknown` and 3 for `over`.
12
+ * A viewer draws the marks in the sequence of their ranks, so the worst level is always in view.
13
+ */
14
+ function levelRank(level) {
15
+ return LEVELS.indexOf(level);
16
+ }
17
+ /** These are the shapes of the sign of a level. */
18
+ const LEVEL_SHAPES = [
19
+ "ring",
20
+ "disc",
21
+ "triangle",
22
+ "square"
23
+ ];
24
+ /**
25
+ * This function gives the shape of the sign of a level: a disc for `ok`, a triangle for `near` and a square for `over`.
26
+ * The level `unknown` has a ring, and so has a record with no level.
27
+ */
28
+ function levelShape(level) {
29
+ return level === "ok" ? "disc" : level === "near" ? "triangle" : level === "over" ? "square" : "ring";
30
+ }
31
+ /**
32
+ * The outline of the sign of each shape. Each viewer draws the signs from these values, so each viewer shows the same signs.
33
+ * A triangle and a square with the radius of the disc look small, so they are larger.
34
+ */
35
+ const SHAPE_OUTLINES = {
36
+ ring: {
37
+ radius: 1,
38
+ sides: 40,
39
+ start: 0,
40
+ hole: .52
41
+ },
42
+ disc: {
43
+ radius: 1,
44
+ sides: 40,
45
+ start: 0,
46
+ hole: 0
47
+ },
48
+ triangle: {
49
+ radius: 1.3,
50
+ sides: 3,
51
+ start: Math.PI / 2,
52
+ hole: 0
53
+ },
54
+ square: {
55
+ radius: 1.25,
56
+ sides: 4,
57
+ start: Math.PI / 4,
58
+ hole: 0
59
+ }
60
+ };
61
+ /**
62
+ * This function gives the corners of the outline of a sign, counter-clockwise, with the y axis up.
63
+ * The center of the sign is the origin, and `radius` is the radius of a disc.
64
+ */
65
+ function shapeRing(shape, radius = 1) {
66
+ const outline = SHAPE_OUTLINES[shape];
67
+ return Array.from({ length: outline.sides }, (_, index) => {
68
+ const angle = outline.start + index * 2 * Math.PI / outline.sides;
69
+ return [radius * outline.radius * Math.cos(angle), radius * outline.radius * Math.sin(angle)];
70
+ });
71
+ }
72
+ // src/marks/check.ts
73
+ /**
74
+ * These are the codes of the faults of a mark:
75
+ * - `type`: the type of the mark is not known. A list from a later version of a producer can have a new type.
76
+ * - `level`: the level of the mark is not known.
77
+ * - `name`: a record name or the kind is empty.
78
+ * - `label`: the label is empty, or it has more than one line.
79
+ * - `number`: a number is not finite.
80
+ * - `direction`: a direction is not a unit vector.
81
+ * - `angle`: the column step of a field is not at a right angle to the direction out of its plane.
82
+ * - `size`: a size, a width or a cell is not more than 0.
83
+ * - `grid`: the number of the columns or of the rows of a field is not a whole number of 1 or more.
84
+ * - `values`: a field does not have one value for each cell.
85
+ * - `scale`: the `min` of the scale of a field is not less than its `max`.
86
+ * - `path`: a run has fewer than 2 points.
87
+ */
88
+ const MARK_FAULT_CODES = [
89
+ "type",
90
+ "level",
91
+ "name",
92
+ "label",
93
+ "number",
94
+ "direction",
95
+ "angle",
96
+ "size",
97
+ "grid",
98
+ "values",
99
+ "scale",
100
+ "path"
101
+ ];
102
+ /**
103
+ * The tolerance of a direction. A unit vector has the length 1 with this tolerance.
104
+ * Two directions are at a right angle when their dot product is 0 with this tolerance.
105
+ */
106
+ const DIRECTION_TOLERANCE = 1e-6;
107
+ /**
108
+ * This function gives the faults of a list of marks, in the sequence of the list. A list with no fault gives an empty list.
109
+ * It examines the values that the types do not hold: finite numbers, unit vectors, sizes, the grid of a field and the names.
110
+ * A producer of marks uses it as a gate in its tests, and a viewer uses it on a list that it did not make.
111
+ * It does not examine the form of a mark: read a list from JSON through a schema first.
112
+ */
113
+ function checkMarks(marks) {
114
+ const faults = [];
115
+ marks.forEach((mark, index) => {
116
+ const fault = (code, part, message) => {
117
+ faults.push({
118
+ code,
119
+ index,
120
+ record: mark.record,
121
+ part,
122
+ message
123
+ });
124
+ };
125
+ const finite = (part, value) => {
126
+ if (Number.isFinite(value)) return true;
127
+ fault("number", part, `${part} is not a finite number: ${String(value)}`);
128
+ return false;
129
+ };
130
+ const point = (part, value) => {
131
+ const x = finite(`${part}.x`, value.x);
132
+ const y = finite(`${part}.y`, value.y);
133
+ const z = finite(`${part}.z`, value.z);
134
+ return x && y && z;
135
+ };
136
+ const direction = (part, value) => {
137
+ if (!point(part, value)) return false;
138
+ const length = length3(value);
139
+ if (Math.abs(length - 1) <= 1e-6) return true;
140
+ fault("direction", part, `${part} is not a unit vector: its length is ${String(length)}`);
141
+ return false;
142
+ };
143
+ const frame = (part, value) => {
144
+ const at = point(`${part}.at`, value.at);
145
+ const out = direction(`${part}.out`, value.out);
146
+ return at && out;
147
+ };
148
+ const positive = (part, value) => {
149
+ if (finite(part, value) && value <= 0) fault("size", part, `${part} is not more than 0: ${String(value)}`);
150
+ };
151
+ const count = (part, value) => {
152
+ if (Number.isInteger(value) && value >= 1) return true;
153
+ fault("grid", part, `${part} is not a whole number of 1 or more: ${String(value)}`);
154
+ return false;
155
+ };
156
+ if (mark.record === "") fault("name", "record", "the mark has no record name");
157
+ if (mark.kind === "") fault("name", "kind", "the mark has no kind");
158
+ if (!LEVELS.includes(mark.level)) fault("level", "level", `the level is not known: ${String(mark.level)}`);
159
+ if (mark.label.trim() === "") fault("label", "label", "the mark has no label");
160
+ else if (/[\r\n]/.test(mark.label)) fault("label", "label", "the label has more than one line");
161
+ switch (mark.type) {
162
+ case "point":
163
+ frame("frame", mark.frame);
164
+ if (mark.size !== void 0) positive("size", mark.size);
165
+ break;
166
+ case "run":
167
+ if (mark.path.length < 2) fault("path", "path", `the path has ${String(mark.path.length)} points, and a run needs 2 or more`);
168
+ mark.path.forEach((step, at) => frame(`path[${String(at)}]`, step));
169
+ positive("width", mark.width);
170
+ break;
171
+ case "link":
172
+ for (const [name, end] of [["from", mark.from], ["to", mark.to]]) {
173
+ if (end.record === "") fault("name", `${name}.record`, `the end ${name} has no record name`);
174
+ point(`${name}.at`, end.at);
175
+ }
176
+ break;
177
+ case "field": {
178
+ const hasFrame = frame("frame", mark.frame);
179
+ const hasAcross = direction("across", mark.across);
180
+ if (hasFrame && hasAcross) {
181
+ const dot = dot3(mark.frame.out, mark.across);
182
+ if (Math.abs(dot) > 1e-6) fault("angle", "across", `across is not at a right angle to frame.out: their dot product is ${String(dot)}`);
183
+ }
184
+ positive("cell", mark.cell);
185
+ const hasColumns = count("columns", mark.columns);
186
+ const hasRows = count("rows", mark.rows);
187
+ if (hasColumns && hasRows && mark.values.length !== mark.columns * mark.rows) fault("values", "values", `the field has ${String(mark.values.length)} values, and ${String(mark.columns)} columns of ${String(mark.rows)} rows need ${String(mark.columns * mark.rows)}`);
188
+ const bad = mark.values.flatMap((value, at) => value === null || Number.isFinite(value) ? [] : [at]);
189
+ const first = bad[0];
190
+ if (first !== void 0) fault("number", `values[${String(first)}]`, `${String(bad.length)} of the values are not finite numbers, the first is values[${String(first)}]: ${String(mark.values[first])}`);
191
+ const hasMin = finite("scale.min", mark.scale.min);
192
+ const hasMax = finite("scale.max", mark.scale.max);
193
+ if (hasMin && hasMax && mark.scale.min >= mark.scale.max) fault("scale", "scale", `scale.min is not less than scale.max: ${String(mark.scale.min)} and ${String(mark.scale.max)}`);
194
+ break;
195
+ }
196
+ case "meter":
197
+ finite("value", mark.value);
198
+ finite("limit", mark.limit);
199
+ break;
200
+ default: fault("type", "type", `the type is not known: ${String(mark.type)}`);
201
+ }
202
+ });
203
+ return faults;
204
+ }
205
+ // src/marks/mark.ts
206
+ /** These are the types of a mark. */
207
+ const MARK_TYPES = [
208
+ "point",
209
+ "run",
210
+ "link",
211
+ "field",
212
+ "meter"
213
+ ];
214
+ /** This function gives the unit vector of a row step of a field: the cross product of `frame.out` and `across`. */
215
+ function fieldRowStep(field) {
216
+ return cross3(field.frame.out, field.across);
217
+ }
218
+ /** This function gives the center of a cell of a field. The first cell has the column 0 and the row 0. */
219
+ function fieldCellCenter(field, column, row) {
220
+ const across = scalePoint3(field.across, (column + .5) * field.cell);
221
+ const down = scalePoint3(fieldRowStep(field), (row + .5) * field.cell);
222
+ return addPoints3(field.frame.at, addPoints3(across, down));
223
+ }
224
+ /** 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. */
225
+ function fieldValue(field, column, row) {
226
+ if (!Number.isInteger(column) || !Number.isInteger(row) || column < 0 || row < 0 || column >= field.columns || row >= field.rows) return null;
227
+ return field.values[row * field.columns + column] ?? null;
228
+ }
229
+ export { DIRECTION_TOLERANCE, LEVELS, LEVEL_SHAPES, MARK_FAULT_CODES, MARK_TYPES, SHAPE_OUTLINES, checkMarks, fieldCellCenter, fieldRowStep, fieldValue, levelRank, levelShape, shapeRing };
230
+
231
+ //# sourceMappingURL=marks.js.map