@johnmorrisdotca/kyogijo-stadiums 0.0.0-stage → 0.4.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +129 -0
- package/LICENSE +21 -0
- package/NOTICE.md +293 -0
- package/README.md +600 -2
- package/dist/annotate.d.ts +47 -0
- package/dist/annotate.js +349 -0
- package/dist/atlas-entry.d.ts +4 -0
- package/dist/atlas-entry.js +3 -0
- package/dist/atlas.d.ts +131 -0
- package/dist/atlas.js +149 -0
- package/dist/background.d.ts +56 -0
- package/dist/background.js +127 -0
- package/dist/ballpark.d.ts +48 -0
- package/dist/ballpark.js +129 -0
- package/dist/canvas-entry.d.ts +2 -0
- package/dist/canvas-entry.js +2 -0
- package/dist/canvas.d.ts +85 -0
- package/dist/canvas.js +279 -0
- package/dist/charts-entry.d.ts +10 -0
- package/dist/charts-entry.js +8 -0
- package/dist/charts.baseball.d.ts +30 -0
- package/dist/charts.baseball.js +152 -0
- package/dist/charts.curling.d.ts +52 -0
- package/dist/charts.curling.js +196 -0
- package/dist/charts.d.ts +172 -0
- package/dist/charts.js +508 -0
- package/dist/charts.network.d.ts +66 -0
- package/dist/charts.network.js +64 -0
- package/dist/charts.soccer.d.ts +43 -0
- package/dist/charts.soccer.js +191 -0
- package/dist/charts.types.d.ts +396 -0
- package/dist/charts.types.js +1 -0
- package/dist/colour.d.ts +29 -0
- package/dist/colour.js +97 -0
- package/dist/common.d.ts +14 -0
- package/dist/common.js +32 -0
- package/dist/court.d.ts +89 -0
- package/dist/court.js +248 -0
- package/dist/courts.style.d.ts +20 -0
- package/dist/courts.style.js +54 -0
- package/dist/cricket.board.d.ts +18 -0
- package/dist/cricket.board.js +67 -0
- package/dist/curling.board.d.ts +24 -0
- package/dist/curling.board.js +147 -0
- package/dist/d3-entry.d.ts +3 -0
- package/dist/d3-entry.js +2 -0
- package/dist/d3.d.ts +45 -0
- package/dist/d3.js +56 -0
- package/dist/draw.d.ts +52 -0
- package/dist/draw.js +705 -0
- package/dist/element-define.d.ts +2 -0
- package/dist/element-define.js +4 -0
- package/dist/element-entry.d.ts +1 -0
- package/dist/element-entry.js +2 -0
- package/dist/element.d.ts +39 -0
- package/dist/element.js +321 -0
- package/dist/eras-entry.d.ts +2 -0
- package/dist/eras-entry.js +2 -0
- package/dist/eras.d.ts +204 -0
- package/dist/eras.js +396 -0
- package/dist/events-entry.d.ts +3 -0
- package/dist/events-entry.js +3 -0
- package/dist/events.d.ts +54 -0
- package/dist/events.data.d.ts +59 -0
- package/dist/events.data.js +297 -0
- package/dist/events.js +127 -0
- package/dist/features.d.ts +31 -0
- package/dist/features.js +284 -0
- package/dist/field.score.d.ts +5 -0
- package/dist/field.score.js +33 -0
- package/dist/fields/afl.d.ts +11 -0
- package/dist/fields/afl.js +103 -0
- package/dist/fields/cricket.d.ts +9 -0
- package/dist/fields/cricket.js +81 -0
- package/dist/fields/fieldhockey.d.ts +6 -0
- package/dist/fields/fieldhockey.js +81 -0
- package/dist/fields/gaelic.d.ts +10 -0
- package/dist/fields/gaelic.js +86 -0
- package/dist/fields/handball.d.ts +6 -0
- package/dist/fields/handball.js +85 -0
- package/dist/fields/lacrosse.d.ts +17 -0
- package/dist/fields/lacrosse.js +169 -0
- package/dist/fields/rugby.d.ts +10 -0
- package/dist/fields/rugby.js +130 -0
- package/dist/fields.d.ts +12 -0
- package/dist/fields.js +44 -0
- package/dist/fields.kit.d.ts +63 -0
- package/dist/fields.kit.js +108 -0
- package/dist/fields.style.d.ts +4 -0
- package/dist/fields.style.js +19 -0
- package/dist/fields.types.d.ts +155 -0
- package/dist/fields.types.js +1 -0
- package/dist/format.d.ts +10 -0
- package/dist/format.js +28 -0
- package/dist/formations.d.ts +18 -0
- package/dist/formations.js +211 -0
- package/dist/frames-entry.d.ts +8 -0
- package/dist/frames-entry.js +7 -0
- package/dist/frames.d.ts +199 -0
- package/dist/frames.js +271 -0
- package/dist/frames.providers.d.ts +16 -0
- package/dist/frames.providers.js +302 -0
- package/dist/geojson-entry.d.ts +2 -0
- package/dist/geojson-entry.js +2 -0
- package/dist/geojson.d.ts +79 -0
- package/dist/geojson.js +147 -0
- package/dist/geometry-entry.d.ts +7 -0
- package/dist/geometry-entry.js +5 -0
- package/dist/geometry.d.ts +295 -0
- package/dist/geometry.js +361 -0
- package/dist/grounds-entry.d.ts +4 -0
- package/dist/grounds-entry.js +3 -0
- package/dist/grounds.d.ts +134 -0
- package/dist/grounds.data.d.ts +2 -0
- package/dist/grounds.data.js +1849 -0
- package/dist/grounds.js +74 -0
- package/dist/heat.colour.d.ts +37 -0
- package/dist/heat.colour.js +54 -0
- package/dist/heat.d.ts +43 -0
- package/dist/heat.js +614 -0
- package/dist/heat.stats.d.ts +123 -0
- package/dist/heat.stats.js +413 -0
- package/dist/heat.types.d.ts +145 -0
- package/dist/heat.types.js +1 -0
- package/dist/heat.zones.d.ts +54 -0
- package/dist/heat.zones.js +424 -0
- package/dist/homeside.d.ts +16 -0
- package/dist/homeside.js +43 -0
- package/dist/index.d.ts +47 -0
- package/dist/index.js +29 -0
- package/dist/layers-entry.d.ts +19 -0
- package/dist/layers-entry.js +11 -0
- package/dist/layers.d.ts +41 -0
- package/dist/layers.env.d.ts +72 -0
- package/dist/layers.env.js +79 -0
- package/dist/layers.js +533 -0
- package/dist/layers.marks.d.ts +45 -0
- package/dist/layers.marks.js +168 -0
- package/dist/layers.types.d.ts +226 -0
- package/dist/layers.types.js +1 -0
- package/dist/layout.d.ts +97 -0
- package/dist/layout.js +381 -0
- package/dist/layout.style.d.ts +6 -0
- package/dist/layout.style.js +17 -0
- package/dist/layouts-entry.d.ts +5 -0
- package/dist/layouts-entry.js +4 -0
- package/dist/leagues/aussie.d.ts +57 -0
- package/dist/leagues/aussie.js +36 -0
- package/dist/leagues/baseball.d.ts +58 -0
- package/dist/leagues/baseball.js +171 -0
- package/dist/leagues/basketball.d.ts +67 -0
- package/dist/leagues/basketball.js +128 -0
- package/dist/leagues/courts.d.ts +212 -0
- package/dist/leagues/courts.js +114 -0
- package/dist/leagues/cricket.d.ts +45 -0
- package/dist/leagues/cricket.js +34 -0
- package/dist/leagues/curling.d.ts +64 -0
- package/dist/leagues/curling.js +53 -0
- package/dist/leagues/fieldhockey.d.ts +48 -0
- package/dist/leagues/fieldhockey.js +29 -0
- package/dist/leagues/fields.d.ts +10 -0
- package/dist/leagues/fields.js +6 -0
- package/dist/leagues/football.d.ts +8 -0
- package/dist/leagues/football.js +82 -0
- package/dist/leagues/gaelic.d.ts +50 -0
- package/dist/leagues/gaelic.js +29 -0
- package/dist/leagues/handball.d.ts +45 -0
- package/dist/leagues/handball.js +32 -0
- package/dist/leagues/hockey.d.ts +63 -0
- package/dist/leagues/hockey.js +166 -0
- package/dist/leagues/lacrosse.d.ts +103 -0
- package/dist/leagues/lacrosse.js +175 -0
- package/dist/leagues/rugby.d.ts +59 -0
- package/dist/leagues/rugby.js +72 -0
- package/dist/leagues/sources.d.ts +18 -0
- package/dist/leagues/sources.js +95 -0
- package/dist/leagues/types.d.ts +43 -0
- package/dist/leagues/types.js +5 -0
- package/dist/leagues-entry.d.ts +23 -0
- package/dist/leagues-entry.js +15 -0
- package/dist/leagues.d.ts +172 -0
- package/dist/leagues.js +462 -0
- package/dist/look.d.ts +50 -0
- package/dist/look.js +186 -0
- package/dist/mark.d.ts +35 -0
- package/dist/mark.js +59 -0
- package/dist/mount-entry.d.ts +2 -0
- package/dist/mount-entry.js +2 -0
- package/dist/mount.d.ts +63 -0
- package/dist/mount.js +167 -0
- package/dist/mow.d.ts +36 -0
- package/dist/mow.js +111 -0
- package/dist/names.d.ts +77 -0
- package/dist/names.js +97 -0
- package/dist/outline.d.ts +25 -0
- package/dist/outline.js +112 -0
- package/dist/parks-entry.d.ts +4 -0
- package/dist/parks-entry.js +3 -0
- package/dist/parks.d.ts +200 -0
- package/dist/parks.data.d.ts +2 -0
- package/dist/parks.data.js +4489 -0
- package/dist/parks.js +92 -0
- package/dist/plot-entry.d.ts +2 -0
- package/dist/plot-entry.js +2 -0
- package/dist/plot.d.ts +74 -0
- package/dist/plot.js +68 -0
- package/dist/png-entry.d.ts +2 -0
- package/dist/png-entry.js +2 -0
- package/dist/png.d.ts +26 -0
- package/dist/png.js +46 -0
- package/dist/ranges.d.ts +33 -0
- package/dist/ranges.js +178 -0
- package/dist/ranges.names.d.ts +31 -0
- package/dist/ranges.names.js +65 -0
- package/dist/react-entry.d.ts +2 -0
- package/dist/react-entry.js +2 -0
- package/dist/react.d.ts +53 -0
- package/dist/react.js +58 -0
- package/dist/replay-entry.d.ts +5 -0
- package/dist/replay-entry.js +4 -0
- package/dist/replay.control.d.ts +47 -0
- package/dist/replay.control.js +184 -0
- package/dist/replay.d.ts +170 -0
- package/dist/replay.dom.d.ts +21 -0
- package/dist/replay.dom.js +388 -0
- package/dist/replay.js +579 -0
- package/dist/replay.types.d.ts +152 -0
- package/dist/replay.types.js +1 -0
- package/dist/restyle.d.ts +21 -0
- package/dist/restyle.js +70 -0
- package/dist/road.d.ts +26 -0
- package/dist/road.draw.d.ts +6 -0
- package/dist/road.draw.js +269 -0
- package/dist/road.js +59 -0
- package/dist/road.model.d.ts +63 -0
- package/dist/road.model.js +215 -0
- package/dist/road.style.d.ts +7 -0
- package/dist/road.style.js +26 -0
- package/dist/road.types.d.ts +122 -0
- package/dist/road.types.js +1 -0
- package/dist/scene-entry.d.ts +7 -0
- package/dist/scene-entry.js +5 -0
- package/dist/scene.css.d.ts +44 -0
- package/dist/scene.css.js +296 -0
- package/dist/scene.d.ts +27 -0
- package/dist/scene.fit.d.ts +12 -0
- package/dist/scene.fit.js +18 -0
- package/dist/scene.flat.d.ts +38 -0
- package/dist/scene.flat.js +167 -0
- package/dist/scene.js +420 -0
- package/dist/scene.path.d.ts +40 -0
- package/dist/scene.path.js +357 -0
- package/dist/scene.types.d.ts +172 -0
- package/dist/scene.types.js +1 -0
- package/dist/scene.xml.d.ts +31 -0
- package/dist/scene.xml.js +81 -0
- package/dist/score.d.ts +70 -0
- package/dist/score.js +212 -0
- package/dist/sets.board.d.ts +22 -0
- package/dist/sets.board.js +89 -0
- package/dist/sheet.d.ts +18 -0
- package/dist/sheet.js +38 -0
- package/dist/special.d.ts +44 -0
- package/dist/special.js +204 -0
- package/dist/special.style.d.ts +8 -0
- package/dist/special.style.js +36 -0
- package/dist/strings.d.ts +581 -0
- package/dist/strings.js +411 -0
- package/dist/style.d.ts +35 -0
- package/dist/style.js +177 -0
- package/dist/surfaces/baseball.d.ts +33 -0
- package/dist/surfaces/baseball.js +208 -0
- package/dist/surfaces/baseball.walls.d.ts +16 -0
- package/dist/surfaces/baseball.walls.js +150 -0
- package/dist/surfaces/basketball.d.ts +8 -0
- package/dist/surfaces/basketball.js +199 -0
- package/dist/surfaces/curling.d.ts +23 -0
- package/dist/surfaces/curling.js +128 -0
- package/dist/surfaces/field.d.ts +12 -0
- package/dist/surfaces/field.js +163 -0
- package/dist/surfaces/football.d.ts +12 -0
- package/dist/surfaces/football.js +208 -0
- package/dist/surfaces/hockey.d.ts +10 -0
- package/dist/surfaces/hockey.js +166 -0
- package/dist/surfaces/net.d.ts +7 -0
- package/dist/surfaces/net.js +151 -0
- package/dist/surfaces/soccer-providers.d.ts +124 -0
- package/dist/surfaces/soccer-providers.js +334 -0
- package/dist/surfaces/soccer-spec.d.ts +138 -0
- package/dist/surfaces/soccer-spec.js +175 -0
- package/dist/surfaces/soccer.d.ts +25 -0
- package/dist/surfaces/soccer.js +270 -0
- package/dist/surfaces/surface.d.ts +180 -0
- package/dist/surfaces/surface.js +49 -0
- package/dist/team.common.d.ts +75 -0
- package/dist/team.common.js +97 -0
- package/dist/team.formation.d.ts +24 -0
- package/dist/team.formation.js +121 -0
- package/dist/team.geometry.d.ts +66 -0
- package/dist/team.geometry.js +304 -0
- package/dist/team.layers.d.ts +16 -0
- package/dist/team.layers.js +32 -0
- package/dist/team.motion.d.ts +9 -0
- package/dist/team.motion.js +325 -0
- package/dist/team.network.d.ts +43 -0
- package/dist/team.network.js +215 -0
- package/dist/team.shape.d.ts +12 -0
- package/dist/team.shape.js +217 -0
- package/dist/team.types.d.ts +189 -0
- package/dist/team.types.js +1 -0
- package/dist/text.d.ts +31 -0
- package/dist/text.js +88 -0
- package/dist/themes.d.ts +14 -0
- package/dist/themes.js +24 -0
- package/dist/types.d.ts +565 -0
- package/dist/types.js +1 -0
- package/dist/units.d.ts +45 -0
- package/dist/units.js +90 -0
- package/dist/version.d.ts +2 -0
- package/dist/version.js +2 -0
- package/package.json +234 -4
|
@@ -0,0 +1,199 @@
|
|
|
1
|
+
import { el, num } from "../format.js";
|
|
2
|
+
import { rulesFor } from "../eras.js";
|
|
3
|
+
import { NBA_COURT } from "../leagues/basketball.js";
|
|
4
|
+
import { atEnds, edges, ft, quarterTurn, textOn } from "./surface.js";
|
|
5
|
+
/**
|
|
6
|
+
* A basketball court: the floor, the keys, the arcs, the circles, the baskets and the small marks. By default the NBA's, as the
|
|
7
|
+
* rules of a season (today's by default) marked it; with a `court` (leagues.ts), that league's, in feet.
|
|
8
|
+
*/
|
|
9
|
+
export function basketball(o, era, court = NBA_COURT) {
|
|
10
|
+
// The NBA's court has a history of its own (eras.ts); a league's, if it has one, is already in its `court`.
|
|
11
|
+
const nba = court === NBA_COURT ? (era ?? rulesFor("nba").rules) : undefined;
|
|
12
|
+
const { length: L, width: W } = court;
|
|
13
|
+
const m = o.margin ?? 7;
|
|
14
|
+
const view0 = { x: -m, y: -m, w: L + 2 * m, h: W + 2 * m };
|
|
15
|
+
const cy = W / 2;
|
|
16
|
+
const full = o.detail === "full";
|
|
17
|
+
const bw = 2.6;
|
|
18
|
+
const thin = o.exact ? 1 / 6 : 0.4;
|
|
19
|
+
const turned = o.portrait;
|
|
20
|
+
const laneWidth = nba?.keyWidth ?? court.laneWidth;
|
|
21
|
+
const half = laneWidth / 2;
|
|
22
|
+
// The three-point line: an arc of the season's radius from the basket, meeting the straight lines a few feet in from the
|
|
23
|
+
// sidelines (or, with none, running on to the baseline).
|
|
24
|
+
const three = nba === undefined ? court.threePoint : nba.threePoint === null ? null : { radius: nba.threePoint.radius, sideInset: court.threePoint?.sideInset ?? 3 };
|
|
25
|
+
const restricted = nba === undefined ? court.restricted : nba.restrictedArea ? court.restricted : null;
|
|
26
|
+
const bx = court.basket;
|
|
27
|
+
const radius = three?.radius ?? 0;
|
|
28
|
+
const inset = three?.sideInset ?? 0;
|
|
29
|
+
const J = three === null ? 0 : bx + Math.sqrt(radius * radius - (W / 2 - inset) * (W / 2 - inset));
|
|
30
|
+
const threeLeft = () => `M0 ${num(inset)}H${num(J)}A${num(radius)} ${num(radius)} 0 0 1 ${num(J)} ${num(W - inset)}H0`;
|
|
31
|
+
const threeRight = () => `M${num(L)} ${num(inset)}H${num(L - J)}A${num(radius)} ${num(radius)} 0 0 0 ${num(L - J)} ${num(W - inset)}H${num(L)}`;
|
|
32
|
+
let base = el("rect", { class: ft(o, "apron", "ky-apron"), x: view0.x, y: view0.y, width: view0.w, height: view0.h });
|
|
33
|
+
base += el("path", { class: ft(o, "border", "ky-boards"), "fill-rule": "evenodd", d: `M${-bw} ${-bw}H${num(L + bw)}V${num(W + bw)}H${-bw}ZM0 0V${num(W)}H${num(L)}V0Z` });
|
|
34
|
+
base += el("rect", { class: ft(o, "floor", "ky-surface"), x: 0, y: 0, width: L, height: W });
|
|
35
|
+
if (o.stripes) {
|
|
36
|
+
// The planks run along the court: a second tone on every other board.
|
|
37
|
+
const planks = [];
|
|
38
|
+
for (let y = 1; y < W; y += 2)
|
|
39
|
+
planks.push(`M0 ${y}H${num(L)}v1H0z`);
|
|
40
|
+
base += el("path", { class: ft(o, "planks", "ky-stripe"), d: planks.join("") });
|
|
41
|
+
}
|
|
42
|
+
// The keys, painted, and the three-point areas when asked.
|
|
43
|
+
const keyW = court.freeThrowLine;
|
|
44
|
+
const wide = (court.laneEndWidth ?? laneWidth) / 2;
|
|
45
|
+
if (o.court?.paintThreePoint && three !== null) {
|
|
46
|
+
base += el("path", { class: ft(o, "three-point-area", "ky-key ky-key-left"), d: `${threeLeft()}Z` });
|
|
47
|
+
base += el("path", { class: ft(o, "three-point-area", "ky-key ky-key-right"), d: `${threeRight()}Z` });
|
|
48
|
+
}
|
|
49
|
+
// A lane that is a rectangle, or a trapezoid wider at the baseline.
|
|
50
|
+
const lane = (x, away) => `M${num(x)} ${num(cy - wide)}L${num(x + away * keyW)} ${num(cy - half)}V${num(cy + half)}L${num(x)} ${num(cy + wide)}`;
|
|
51
|
+
if (court.laneEndWidth === undefined) {
|
|
52
|
+
base += el("rect", { class: ft(o, "key", "ky-key ky-key-left"), x: 0, y: cy - half, width: keyW, height: laneWidth });
|
|
53
|
+
base += el("rect", { class: ft(o, "key", "ky-key ky-key-right"), x: L - keyW, y: cy - half, width: keyW, height: laneWidth });
|
|
54
|
+
}
|
|
55
|
+
else {
|
|
56
|
+
base += el("path", { class: ft(o, "key", "ky-key ky-key-left"), d: `${lane(0, 1)}Z` });
|
|
57
|
+
base += el("path", { class: ft(o, "key", "ky-key ky-key-right"), d: `${lane(L, -1)}Z` });
|
|
58
|
+
}
|
|
59
|
+
base += el("circle", { class: ft(o, "centre-paint", "ky-centre"), cx: L / 2, cy, r: court.centreRadius });
|
|
60
|
+
let lines = el("rect", { class: ft(o, "boundary", "ky-line"), x: 0, y: 0, width: L, height: W, "stroke-width": thin * 1.25, fill: "none" });
|
|
61
|
+
lines += el("path", { class: ft(o, "halfway-line", "ky-line"), d: `M${num(L / 2)} 0V${num(W)}`, "stroke-width": thin, fill: "none" });
|
|
62
|
+
lines += el("circle", { class: ft(o, "centre-circle", "ky-line"), cx: L / 2, cy, r: court.centreRadius, "stroke-width": thin, fill: "none" });
|
|
63
|
+
if (full && court.centreInnerRadius !== null)
|
|
64
|
+
lines += el("circle", { class: ft(o, "centre-circle", "ky-line"), cx: L / 2, cy, r: court.centreInnerRadius, "stroke-width": thin, fill: "none" });
|
|
65
|
+
// Lane lines, with the free-throw lines across them.
|
|
66
|
+
lines += el("path", { class: ft(o, "lane-lines", "ky-line"), d: court.laneEndWidth === undefined ? `M0 ${num(cy - half)}H${num(keyW)}V${num(cy + half)}H0M${num(L)} ${num(cy - half)}H${num(L - keyW)}V${num(cy + half)}H${num(L)}` : `${lane(0, 1)}${lane(L, -1)}`, "stroke-width": thin, fill: "none" });
|
|
67
|
+
const R = court.freeThrowRadius;
|
|
68
|
+
// The free-throw circles: whole outside the key, dashed inside it.
|
|
69
|
+
lines += el("path", { class: ft(o, "free-throw-circles", "ky-line"), d: `M${num(keyW)} ${num(cy - R)}A${num(R)} ${num(R)} 0 0 1 ${num(keyW)} ${num(cy + R)}M${num(L - keyW)} ${num(cy - R)}A${num(R)} ${num(R)} 0 0 0 ${num(L - keyW)} ${num(cy + R)}`, "stroke-width": thin, fill: "none" });
|
|
70
|
+
lines += el("path", { class: ft(o, "free-throw-circles", "ky-line"), d: `M${num(keyW)} ${num(cy - R)}A${num(R)} ${num(R)} 0 0 0 ${num(keyW)} ${num(cy + R)}M${num(L - keyW)} ${num(cy - R)}A${num(R)} ${num(R)} 0 0 1 ${num(L - keyW)} ${num(cy + R)}`, "stroke-width": thin, fill: "none", "stroke-dasharray": "1.6 1.2" });
|
|
71
|
+
// Three-point lines, from the season the league had them.
|
|
72
|
+
if (three !== null)
|
|
73
|
+
lines += el("path", { class: ft(o, "three-point-line", "ky-line"), d: `${threeLeft()}${threeRight()}`, "stroke-width": thin, fill: "none" });
|
|
74
|
+
// Restricted areas (the NBA's from 1997), backboards, rims.
|
|
75
|
+
const back = court.backboard.fromBaseline;
|
|
76
|
+
const board = court.backboard.width / 2;
|
|
77
|
+
if (restricted !== null) {
|
|
78
|
+
lines += el("path", {
|
|
79
|
+
class: ft(o, "restricted-areas", "ky-line"),
|
|
80
|
+
d: `M${num(back)} ${num(cy - restricted)}H${num(bx)}A${num(restricted)} ${num(restricted)} 0 0 1 ${num(bx)} ${num(cy + restricted)}H${num(back)}M${num(L - back)} ${num(cy - restricted)}H${num(L - bx)}A${num(restricted)} ${num(restricted)} 0 0 0 ${num(L - bx)} ${num(cy + restricted)}H${num(L - back)}`,
|
|
81
|
+
"stroke-width": thin,
|
|
82
|
+
fill: "none",
|
|
83
|
+
});
|
|
84
|
+
}
|
|
85
|
+
// The baskets, seen from above: the backboard, its arm and the rim (the usual), the backboard alone, a solid backboard and a filled rim, or none; or a function of the caller's.
|
|
86
|
+
const reachRim = bx - back + court.rim;
|
|
87
|
+
const basket = (end) => {
|
|
88
|
+
const sign = end === 0 ? 1 : -1;
|
|
89
|
+
const at = end === 0 ? back : L - back;
|
|
90
|
+
const rimX = end === 0 ? bx : L - bx;
|
|
91
|
+
if (o.goalMarkup !== undefined)
|
|
92
|
+
return o.goalMarkup({ sport: "nba", end: end === 0 ? "left" : "right", x: at, y: cy, width: court.backboard.width, depth: reachRim, out: sign, line: thin });
|
|
93
|
+
const boardLine = `M${num(at)} ${num(cy - board)}V${num(cy + board)}`;
|
|
94
|
+
const arm = `M${num(at)} ${num(cy)}H${num(rimX - sign * court.rim)}`;
|
|
95
|
+
switch (o.goals) {
|
|
96
|
+
case "none":
|
|
97
|
+
return "";
|
|
98
|
+
case "line":
|
|
99
|
+
return el("path", { class: ft(o, "backboards", "ky-board"), d: boardLine, "stroke-width": 0.5, fill: "none" });
|
|
100
|
+
case "strip":
|
|
101
|
+
return el("path", { class: ft(o, "backboards", "ky-board"), d: `${boardLine}${arm}`, "stroke-width": 1, fill: "none" }) + el("circle", { class: ft(o, "rims", "ky-rim"), cx: rimX, cy, r: court.rim, "stroke-width": 0.3, fill: "#e8591a" });
|
|
102
|
+
default:
|
|
103
|
+
return el("path", { class: ft(o, "backboards", "ky-board"), d: `${boardLine}${arm}`, "stroke-width": 0.5, fill: "none" }) + el("circle", { class: ft(o, "rims", "ky-rim"), cx: rimX, cy, r: court.rim, "stroke-width": 0.3, fill: "none" });
|
|
104
|
+
}
|
|
105
|
+
};
|
|
106
|
+
if (o.goalMarkup === undefined && (o.goals === undefined || o.goals === "box")) {
|
|
107
|
+
lines += el("path", { class: ft(o, "backboards", "ky-board"), d: `M${num(back)} ${num(cy - board)}V${num(cy + board)}M${num(L - back)} ${num(cy - board)}V${num(cy + board)}M${num(back)} ${num(cy)}H${num(bx - court.rim)}M${num(L - back)} ${num(cy)}H${num(L - bx + court.rim)}`, "stroke-width": 0.5, fill: "none" });
|
|
108
|
+
lines += el("circle", { class: ft(o, "rims", "ky-rim"), cx: bx, cy, r: court.rim, "stroke-width": 0.3, fill: "none" });
|
|
109
|
+
lines += el("circle", { class: ft(o, "rims", "ky-rim"), cx: L - bx, cy, r: court.rim, "stroke-width": 0.3, fill: "none" });
|
|
110
|
+
}
|
|
111
|
+
else
|
|
112
|
+
lines += basket(0) + basket(1);
|
|
113
|
+
const marks = court.marks;
|
|
114
|
+
if (full && marks !== null) {
|
|
115
|
+
// The marks along the lane (the first is the block), the lower defensive box's marks, the sideline marks and the substitution marks.
|
|
116
|
+
const laneMarks = [];
|
|
117
|
+
const block = [];
|
|
118
|
+
marks.lane.forEach((x, i) => {
|
|
119
|
+
const draw = (px) => `M${num(px)} ${num(cy - half)}v-0.6M${num(px)} ${num(cy + half)}v0.6`;
|
|
120
|
+
(i === 0 ? block : laneMarks).push(draw(x), draw(L - x));
|
|
121
|
+
});
|
|
122
|
+
lines += el("path", { class: ft(o, "court-marks", "ky-line"), d: laneMarks.join(""), "stroke-width": thin, fill: "none" });
|
|
123
|
+
lines += el("path", { class: ft(o, "court-marks", "ky-line"), d: block.join(""), "stroke-width": thin * 2.4, fill: "none" });
|
|
124
|
+
const box = marks.box;
|
|
125
|
+
if (box !== null) {
|
|
126
|
+
const yBox = [cy - half - box.fromLane, cy + half + box.fromLane];
|
|
127
|
+
const boxMarks = [];
|
|
128
|
+
for (const y of yBox)
|
|
129
|
+
boxMarks.push(`M0 ${num(y)}h${num(box.length)}M${num(L)} ${num(y)}h${num(-box.length)}M${num(box.fromBaseline)} ${num(y)}v${num(y < cy ? box.length : -box.length)}M${num(L - box.fromBaseline)} ${num(y)}v${num(y < cy ? box.length : -box.length)}`);
|
|
130
|
+
lines += el("path", { class: ft(o, "court-marks", "ky-line"), d: boxMarks.join(""), "stroke-width": thin, fill: "none" });
|
|
131
|
+
}
|
|
132
|
+
const side = marks.sideline;
|
|
133
|
+
lines += el("path", { class: ft(o, "court-marks", "ky-line"), d: [side.fromBaseline, L - side.fromBaseline].map((x) => `M${num(x)} 0v${num(side.length)}M${num(x)} ${num(W)}v${num(-side.length)}`).join(""), "stroke-width": thin, fill: "none" });
|
|
134
|
+
if (marks.substitution !== null)
|
|
135
|
+
lines += el("path", { class: ft(o, "court-marks", "ky-line"), d: [L / 2 - marks.substitution, L / 2 + marks.substitution].map((x) => `M${num(x)} ${num(W)}v${num(-side.length)}`).join(""), "stroke-width": thin, fill: "none" });
|
|
136
|
+
}
|
|
137
|
+
// The court's own words and logo: the baseline words in the apron, the logo in the centre circle.
|
|
138
|
+
const words = o.court?.baselineText;
|
|
139
|
+
if (words !== undefined) {
|
|
140
|
+
const x = -bw - 1.4;
|
|
141
|
+
lines += textOn(turned, x, cy + 1.1, words[0], { size: 3, anchor: "middle", rot: -90, cls: ft(o, "baseline-text", "ky-baseline"), weight: 800, spacing: 0.3 });
|
|
142
|
+
lines += textOn(turned, L - x, cy + 1.1, words[1], { size: 3, anchor: "middle", rot: 90, cls: ft(o, "baseline-text", "ky-baseline"), weight: 800, spacing: 0.3 });
|
|
143
|
+
}
|
|
144
|
+
if (o.court?.centreLogo !== undefined) {
|
|
145
|
+
const s = court.centreRadius * 1.5;
|
|
146
|
+
lines += el("image", { href: o.court.centreLogo, x: L / 2 - s / 2, y: cy - s / 2, width: s, height: s, preserveAspectRatio: "xMidYMid meet", transform: turned ? `rotate(-90 ${num(L / 2)} ${num(cy)})` : undefined });
|
|
147
|
+
}
|
|
148
|
+
// The teams' places and the score's panel, in proportion to the court (the NBA's is 94 feet by 50).
|
|
149
|
+
const kx = L / NBA_COURT.length;
|
|
150
|
+
const ky = W / NBA_COURT.width;
|
|
151
|
+
const surface = {
|
|
152
|
+
sport: "nba",
|
|
153
|
+
view: view0,
|
|
154
|
+
base,
|
|
155
|
+
lines,
|
|
156
|
+
defs: "",
|
|
157
|
+
left: { cx: 16.5 * kx, cy, w: 27 * kx, h: 25 * ky, rot: 0, panel: true },
|
|
158
|
+
right: { cx: L - 16.5 * kx, cy, w: 27 * kx, h: 25 * ky, rot: 0, panel: true },
|
|
159
|
+
plate: { cx: L / 2, cy, w: 34 * kx, h: 20 * ky },
|
|
160
|
+
turned,
|
|
161
|
+
bannersOver: true,
|
|
162
|
+
};
|
|
163
|
+
surface.lineRef = { width: thin, feet: 1 };
|
|
164
|
+
surface.box = { x: 0, y: 0, w: L, h: W };
|
|
165
|
+
// The paint: the lane from the baseline to the free-throw line and the circle beyond it, with a little floor round them.
|
|
166
|
+
const paintDeep = keyW + R + 1.5;
|
|
167
|
+
const paintHalf = Math.min(cy, Math.max(half, wide, R) + 2);
|
|
168
|
+
surface.ranges = {
|
|
169
|
+
"half-court": atEnds((end) => (end === "left" ? edges(0, 0, L / 2, W) : edges(L / 2, 0, L, W))),
|
|
170
|
+
paint: atEnds((end) => (end === "left" ? edges(0, cy - paintHalf, paintDeep, cy + paintHalf) : edges(L - paintDeep, cy - paintHalf, L, cy + paintHalf))),
|
|
171
|
+
};
|
|
172
|
+
if (o.landmarks === true) {
|
|
173
|
+
const R = court.freeThrowRadius;
|
|
174
|
+
const cos = Math.cos((40 * Math.PI) / 180);
|
|
175
|
+
const sin = Math.sin((40 * Math.PI) / 180);
|
|
176
|
+
const marks = [
|
|
177
|
+
{ id: "sideline", x: L * 0.62, y: 0, side: "top" },
|
|
178
|
+
{ id: "baseline", x: 0, y: W * 0.8, side: "bottom" },
|
|
179
|
+
{ id: "half-court-line", x: L / 2, y: W, side: "bottom" },
|
|
180
|
+
{ id: "centre-circle", x: L / 2 + court.centreRadius * 0.7, y: cy - court.centreRadius * 0.7, side: "top" },
|
|
181
|
+
{ id: "key", x: keyW * 0.5, y: cy - half, side: "top" },
|
|
182
|
+
{ id: "free-throw-line", x: keyW, y: cy + half, side: "bottom" },
|
|
183
|
+
{ id: "free-throw-circle", x: keyW + R * 0.7, y: cy - R * 0.7, side: "top" },
|
|
184
|
+
{ id: "backboard", x: back, y: cy - board, side: "top" },
|
|
185
|
+
{ id: "basket", x: bx, y: cy + court.rim, side: "bottom" },
|
|
186
|
+
];
|
|
187
|
+
if (three !== null)
|
|
188
|
+
marks.push({ id: "three-point-line", x: bx + radius * cos, y: cy + radius * sin, side: "bottom" });
|
|
189
|
+
if (restricted !== null)
|
|
190
|
+
marks.push({ id: "restricted-area", x: bx + restricted * 0.7, y: cy - restricted * 0.7, side: "top" });
|
|
191
|
+
surface.marks = marks;
|
|
192
|
+
}
|
|
193
|
+
if (turned) {
|
|
194
|
+
const tt = quarterTurn(view0);
|
|
195
|
+
surface.view = tt.view;
|
|
196
|
+
surface.turn = tt.turn;
|
|
197
|
+
}
|
|
198
|
+
return surface;
|
|
199
|
+
}
|
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
import type { SheetSpec } from "../leagues/curling.ts";
|
|
2
|
+
import type { SheetShow } from "../types.ts";
|
|
3
|
+
import { type BuildOptions, type Surface } from "./surface.ts";
|
|
4
|
+
/** What a curling sheet is drawn with besides the figures of its rulebook. */
|
|
5
|
+
export interface SheetLook {
|
|
6
|
+
/** The ice's pebble, as a texture of dots over the sheet. */
|
|
7
|
+
pebble: boolean;
|
|
8
|
+
/** The free guard zone, shaded. */
|
|
9
|
+
guardZone: boolean;
|
|
10
|
+
/** How much of the sheet is in view, and at which end. */
|
|
11
|
+
show: SheetShow;
|
|
12
|
+
end: "left" | "right";
|
|
13
|
+
/** Which league's marks to draw: the hack line and the courtesy lines are World Curling's. */
|
|
14
|
+
figures: SheetSpec;
|
|
15
|
+
}
|
|
16
|
+
/** Where each tee is on the sheet, along it from the left backboard: the left tee and the right tee. */
|
|
17
|
+
export declare function teesOf(spec: Pick<SheetSpec, "length" | "teeFromMiddle">): [number, number];
|
|
18
|
+
/**
|
|
19
|
+
* A curling sheet in the frame of a drawing lying wide: x along it from the left backboard, y across it from the top sideline. A house at
|
|
20
|
+
* each end (the 12-, 8- and 4-foot circles and the button), the tee, back, hog and centre lines, the hacks, and, in World Curling's, the
|
|
21
|
+
* hack lines and the courtesy lines. Every figure is the rulebook's (leagues/curling.ts).
|
|
22
|
+
*/
|
|
23
|
+
export declare function curling(o: BuildOptions, look: SheetLook): Surface;
|
|
@@ -0,0 +1,128 @@
|
|
|
1
|
+
import { el, num } from "../format.js";
|
|
2
|
+
import { ft, quarterTurn } from "./surface.js";
|
|
3
|
+
/** Where each tee is on the sheet, along it from the left backboard: the left tee and the right tee. */
|
|
4
|
+
export function teesOf(spec) {
|
|
5
|
+
return [spec.length / 2 - spec.teeFromMiddle, spec.length / 2 + spec.teeFromMiddle];
|
|
6
|
+
}
|
|
7
|
+
/**
|
|
8
|
+
* A curling sheet in the frame of a drawing lying wide: x along it from the left backboard, y across it from the top sideline. A house at
|
|
9
|
+
* each end (the 12-, 8- and 4-foot circles and the button), the tee, back, hog and centre lines, the hacks, and, in World Curling's, the
|
|
10
|
+
* hack lines and the courtesy lines. Every figure is the rulebook's (leagues/curling.ts).
|
|
11
|
+
*/
|
|
12
|
+
export function curling(o, look) {
|
|
13
|
+
const spec = look.figures;
|
|
14
|
+
const { length: L, width: W } = spec;
|
|
15
|
+
const m = o.margin ?? 3;
|
|
16
|
+
const cy = W / 2;
|
|
17
|
+
const [tl, tr] = teesOf(spec);
|
|
18
|
+
const [twelve, eight, four, button] = spec.rings;
|
|
19
|
+
const full = o.detail === "full";
|
|
20
|
+
const sticks = (value) => (o.exact ? value : Math.max(value, 0.2));
|
|
21
|
+
const lineW = sticks(spec.lineWidths.line);
|
|
22
|
+
const hogW = spec.lineWidths.hog;
|
|
23
|
+
const board = 0.7;
|
|
24
|
+
let defs = "";
|
|
25
|
+
let base = el("rect", { class: ft(o, "apron", "ky-apron"), x: -m, y: -m, width: L + 2 * m, height: W + 2 * m });
|
|
26
|
+
base += el("path", { class: ft(o, "boards", "ky-boards"), "fill-rule": "evenodd", d: `M${num(-board)} ${num(-board)}H${num(L + board)}V${num(W + board)}H${num(-board)}ZM0 0V${num(W)}H${num(L)}V0Z` });
|
|
27
|
+
base += el("rect", { class: ft(o, "ice", "ky-surface"), x: 0, y: 0, width: L, height: W });
|
|
28
|
+
if (look.pebble) {
|
|
29
|
+
// A few dots in a tile, and the tile laid over the ice.
|
|
30
|
+
defs += el("pattern", { id: `${o.id}-pebble`, class: ft(o, "pebble", "") === "" ? undefined : ft(o, "pebble", "").trim(), width: 1.6, height: 1.6, patternUnits: "userSpaceOnUse" }, el("circle", { cx: 0.3, cy: 0.4, r: 0.09 }) + el("circle", { cx: 1.1, cy: 0.2, r: 0.07 }) + el("circle", { cx: 0.7, cy: 1.0, r: 0.08 }) + el("circle", { cx: 1.4, cy: 1.35, r: 0.07 }) + el("circle", { cx: 0.15, cy: 1.45, r: 0.06 }));
|
|
31
|
+
base += el("rect", { class: "ky-pebble", x: 0, y: 0, width: L, height: W, fill: `url(#${o.id}-pebble)` });
|
|
32
|
+
}
|
|
33
|
+
// The free guard zone: between each hog line and the tee line, outside the house (the house is painted over it).
|
|
34
|
+
if (look.guardZone) {
|
|
35
|
+
base += el("path", { class: ft(o, "guard-zone", "ky-fgz"), d: `M${num(tl)} 0H${num(tl + spec.hogLine)}V${num(W)}H${num(tl)}ZM${num(tr)} 0H${num(tr - spec.hogLine)}V${num(W)}H${num(tr)}Z` });
|
|
36
|
+
}
|
|
37
|
+
// The houses: the 12-foot circle is the outer band, then the 8-foot, the 4-foot and the button.
|
|
38
|
+
for (const t of [tl, tr]) {
|
|
39
|
+
base += el("g", { class: "ky-house" }, [twelve, eight, four, button].map((r, i) => el("circle", { class: ft(o, ["house-outer", "house-middle", "house-inner", "button"][i], `ky-rg-${["o", "m", "i", "b"][i]}`), cx: t, cy, r })).join(""));
|
|
40
|
+
}
|
|
41
|
+
// Lines. The tee and centre lines stop short of the button, where the rules let them be left out.
|
|
42
|
+
let lines = "";
|
|
43
|
+
const gap = button;
|
|
44
|
+
const across = (x) => `M${num(x)} 0V${num(cy - gap)}M${num(x)} ${num(cy + gap)}V${num(W)}`;
|
|
45
|
+
lines += el("path", { class: ft(o, "tee-lines", "ky-line"), d: `${across(tl)}${across(tr)}`, "stroke-width": lineW, fill: "none" });
|
|
46
|
+
lines += el("path", { class: ft(o, "back-lines", "ky-line"), d: `M${num(tl - spec.backLine + lineW / 2)} 0V${num(W)}M${num(tr + spec.backLine - lineW / 2)} 0V${num(W)}`, "stroke-width": lineW, fill: "none" });
|
|
47
|
+
const beyond = spec.centreBeyondTee;
|
|
48
|
+
lines += el("path", { class: ft(o, "centre-line", "ky-line"), d: `M${num(tl - beyond)} ${num(cy)}H${num(tl - gap)}M${num(tl + gap)} ${num(cy)}H${num(tr - gap)}M${num(tr + gap)} ${num(cy)}H${num(tr + beyond)}`, "stroke-width": lineW, fill: "none" });
|
|
49
|
+
// The hog lines, 4 inches wide: the inside edge is the one 21 feet from the tee.
|
|
50
|
+
lines += el("path", { class: ft(o, "hog-lines", "ky-hog"), d: `M${num(tl + spec.hogLine)} 0h${num(hogW)}V${num(W)}h${num(-hogW)}ZM${num(tr - spec.hogLine)} 0h${num(-hogW)}V${num(W)}h${num(hogW)}Z` });
|
|
51
|
+
if (full) {
|
|
52
|
+
// The hacks, two at each end, at the end of the centre line: the inside edge 3 inches from it, in front of the hack line.
|
|
53
|
+
const hack = spec.hack;
|
|
54
|
+
const hacks = [];
|
|
55
|
+
for (const [t, sign] of [[tl, -1], [tr, 1]]) {
|
|
56
|
+
const back = t + sign * beyond;
|
|
57
|
+
for (const side of [-1, 1]) {
|
|
58
|
+
const y0 = side < 0 ? cy - hack.insideFromCentre - hack.width : cy + hack.insideFromCentre;
|
|
59
|
+
hacks.push(`M${num(sign < 0 ? back : back - hack.depth)} ${num(y0)}h${num(hack.depth)}v${num(hack.width)}h${num(-hack.depth)}z`);
|
|
60
|
+
}
|
|
61
|
+
}
|
|
62
|
+
lines += el("path", { class: ft(o, "hacks", "ky-hack"), d: hacks.join("") });
|
|
63
|
+
if (spec.hackLine !== null) {
|
|
64
|
+
lines += el("path", { class: ft(o, "courtesy-lines", "ky-line"), d: `M${num(tl - beyond)} ${num(cy - spec.hackLine / 2)}V${num(cy + spec.hackLine / 2)}M${num(tr + beyond)} ${num(cy - spec.hackLine / 2)}V${num(cy + spec.hackLine / 2)}`, "stroke-width": lineW, fill: "none" });
|
|
65
|
+
}
|
|
66
|
+
if (spec.courtesy !== null) {
|
|
67
|
+
// Short lines at each side, parallel to the hog lines and 4 feet outside them (towards the middle of the sheet).
|
|
68
|
+
const c = spec.courtesy;
|
|
69
|
+
const xs = [tl + spec.hogLine + hogW + c.outsideHog, tr - spec.hogLine - hogW - c.outsideHog];
|
|
70
|
+
lines += el("path", { class: ft(o, "courtesy-lines", "ky-line"), d: xs.map((x) => `M${num(x)} 0v${num(c.length)}M${num(x)} ${num(W)}v${num(-c.length)}`).join(""), "stroke-width": lineW, fill: "none" });
|
|
71
|
+
}
|
|
72
|
+
}
|
|
73
|
+
// What is in view: all of the sheet, the half from the hog line to the back line, or the house, at one end.
|
|
74
|
+
const along = 1.5;
|
|
75
|
+
let view0 = { x: -m, y: -m, w: L + 2 * m, h: W + 2 * m };
|
|
76
|
+
const left = look.end !== "right";
|
|
77
|
+
if (look.show === "half" || look.show === "house") {
|
|
78
|
+
const outer = look.show === "half" ? spec.hogLine + hogW : twelve;
|
|
79
|
+
const x0 = left ? tl - spec.backLine - along : tr - outer - along;
|
|
80
|
+
const x1 = left ? tl + outer + along : tr + spec.backLine + along;
|
|
81
|
+
view0 = { x: x0, y: -m, w: x1 - x0, h: W + 2 * m };
|
|
82
|
+
}
|
|
83
|
+
// The scoreboard's place: between the hog lines, as the eye sees it (so a tall drawing's board is tall, a wide drawing's wide).
|
|
84
|
+
const between = tr - tl - 2 * spec.hogLine - 2 * hogW;
|
|
85
|
+
const turned = o.portrait;
|
|
86
|
+
const surface = {
|
|
87
|
+
sport: "curling",
|
|
88
|
+
view: view0,
|
|
89
|
+
base,
|
|
90
|
+
lines,
|
|
91
|
+
defs,
|
|
92
|
+
left: { cx: tl, cy, w: twelve * 2, h: twelve * 2, rot: 0 },
|
|
93
|
+
right: { cx: tr, cy, w: twelve * 2, h: twelve * 2, rot: 0 },
|
|
94
|
+
plate: turned ? { cx: L / 2, cy, w: W - 1.6, h: between - 4 } : { cx: L / 2, cy, w: between - 4, h: W - 1.6 },
|
|
95
|
+
turned,
|
|
96
|
+
};
|
|
97
|
+
surface.lineRef = { width: lineW, feet: 1 };
|
|
98
|
+
surface.box = { x: 0, y: 0, w: L, h: W };
|
|
99
|
+
if (o.landmarks === true) {
|
|
100
|
+
const marks = [
|
|
101
|
+
{ id: "hog-line", x: tl + spec.hogLine + hogW / 2, y: 0, side: "top" },
|
|
102
|
+
{ id: "hog-line", x: tr - spec.hogLine - hogW / 2, y: 0, side: "top" },
|
|
103
|
+
{ id: "tee-line", x: tl, y: 0, side: "top" },
|
|
104
|
+
{ id: "tee-line", x: tr, y: 0, side: "top" },
|
|
105
|
+
{ id: "back-line", x: tl - spec.backLine + lineW / 2, y: 0, side: "top" },
|
|
106
|
+
{ id: "back-line", x: tr + spec.backLine - lineW / 2, y: 0, side: "top" },
|
|
107
|
+
{ id: "house", x: tl + twelve * Math.SQRT1_2, y: cy + twelve * Math.SQRT1_2, side: "bottom" },
|
|
108
|
+
{ id: "house", x: tr + twelve * Math.SQRT1_2, y: cy + twelve * Math.SQRT1_2, side: "bottom" },
|
|
109
|
+
{ id: "button", x: tl, y: cy, side: "bottom" },
|
|
110
|
+
{ id: "button", x: tr, y: cy, side: "bottom" },
|
|
111
|
+
{ id: "centre-line", x: L / 2, y: cy, side: "bottom" },
|
|
112
|
+
{ id: "sideline", x: L * 0.3, y: W, side: "bottom" },
|
|
113
|
+
];
|
|
114
|
+
if (full) {
|
|
115
|
+
marks.push({ id: "hack", x: tl - beyond - spec.hack.depth / 2, y: cy - spec.hack.insideFromCentre - spec.hack.width / 2, side: "top" });
|
|
116
|
+
marks.push({ id: "hack", x: tr + beyond + spec.hack.depth / 2, y: cy - spec.hack.insideFromCentre - spec.hack.width / 2, side: "top" });
|
|
117
|
+
}
|
|
118
|
+
if (look.guardZone)
|
|
119
|
+
marks.push({ id: "free-guard-zone", x: tl + spec.hogLine / 2, y: 0, side: "top" });
|
|
120
|
+
surface.marks = marks;
|
|
121
|
+
}
|
|
122
|
+
if (turned) {
|
|
123
|
+
const tt = quarterTurn(view0);
|
|
124
|
+
surface.view = tt.view;
|
|
125
|
+
surface.turn = tt.turn;
|
|
126
|
+
}
|
|
127
|
+
return surface;
|
|
128
|
+
}
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
import type { FieldPlan } from "../fields.types.ts";
|
|
2
|
+
import type { GoalStyle } from "../types.ts";
|
|
3
|
+
import { type BuildOptions, type Surface } from "./surface.ts";
|
|
4
|
+
/** The painted lines of a plan: the shapes drawn with the line's paint, those alike in feature, width and dash put in one path. */
|
|
5
|
+
export declare function strokes(plan: FieldPlan, o: Pick<BuildOptions, "exact" | "features">): string;
|
|
6
|
+
/**
|
|
7
|
+
* A field sport's surface lying wide, from the sport's plan: the ground, the mown turf, the painted areas, the lines, the goals, and, on a score, the
|
|
8
|
+
* ends painted in the teams' colours and the place for the board. The markings are the plan's, which are the rulebook's (leagues/*.ts).
|
|
9
|
+
*/
|
|
10
|
+
export declare function fieldSurface(o: BuildOptions, plan: FieldPlan, style?: {
|
|
11
|
+
goals?: GoalStyle;
|
|
12
|
+
}): Surface;
|
|
@@ -0,0 +1,163 @@
|
|
|
1
|
+
import { el, num } from "../format.js";
|
|
2
|
+
import { outlineD, roundedD } from "../fields.kit.js";
|
|
3
|
+
import { mowTurf, oddCells } from "../mow.js";
|
|
4
|
+
import { ft, quarterTurn } from "./surface.js";
|
|
5
|
+
const RAD = Math.PI / 180;
|
|
6
|
+
/** The path of one shape that is drawn as a line, or of one filled bar. */
|
|
7
|
+
function pathOf(shape) {
|
|
8
|
+
switch (shape.kind) {
|
|
9
|
+
case "line":
|
|
10
|
+
return shape.y0 === shape.y1 ? `M${num(shape.x0)} ${num(shape.y0)}H${num(shape.x1)}` : shape.x0 === shape.x1 ? `M${num(shape.x0)} ${num(shape.y0)}V${num(shape.y1)}` : `M${num(shape.x0)} ${num(shape.y0)}L${num(shape.x1)} ${num(shape.y1)}`;
|
|
11
|
+
case "arc": {
|
|
12
|
+
const p = (a) => `${num(shape.cx + shape.r * Math.cos(a * RAD))} ${num(shape.cy + shape.r * Math.sin(a * RAD))}`;
|
|
13
|
+
const sweep = shape.a1 > shape.a0 ? 1 : 0;
|
|
14
|
+
return `M${p(shape.a0)}A${num(shape.r)} ${num(shape.r)} 0 ${Math.abs(shape.a1 - shape.a0) > 180 ? 1 : 0} ${sweep} ${p(shape.a1)}`;
|
|
15
|
+
}
|
|
16
|
+
case "ring":
|
|
17
|
+
return `M${num(shape.cx - shape.rx)} ${num(shape.cy)}A${num(shape.rx)} ${num(shape.ry)} 0 1 0 ${num(shape.cx + shape.rx)} ${num(shape.cy)}A${num(shape.rx)} ${num(shape.ry)} 0 1 0 ${num(shape.cx - shape.rx)} ${num(shape.cy)}Z`;
|
|
18
|
+
case "box":
|
|
19
|
+
return `M${num(shape.x0)} ${num(shape.y0)}H${num(shape.x1)}V${num(shape.y1)}H${num(shape.x0)}Z`;
|
|
20
|
+
case "poly":
|
|
21
|
+
return `M${shape.points.map(([x, y]) => `${num(x)} ${num(y)}`).join("L")}${shape.closed === true ? "Z" : ""}`;
|
|
22
|
+
case "bar":
|
|
23
|
+
return `M${num(shape.x0)} ${num(shape.y0)}H${num(shape.x1)}V${num(shape.y1)}H${num(shape.x0)}Z`;
|
|
24
|
+
case "path":
|
|
25
|
+
return shape.d;
|
|
26
|
+
default:
|
|
27
|
+
return "";
|
|
28
|
+
}
|
|
29
|
+
}
|
|
30
|
+
const areaD = (a) => {
|
|
31
|
+
if (a.d !== undefined)
|
|
32
|
+
return a.d;
|
|
33
|
+
if (a.frame !== undefined) {
|
|
34
|
+
const f = a.frame;
|
|
35
|
+
return `${roundedD(f.x0 - f.thick, f.y0 - f.thick, f.x1 + f.thick, f.y1 + f.thick, f.radius + f.thick)}${roundedD(f.x0, f.y0, f.x1, f.y1, f.radius)}`;
|
|
36
|
+
}
|
|
37
|
+
if (a.rect !== undefined) {
|
|
38
|
+
const [x0, y0, x1, y1] = a.rect;
|
|
39
|
+
return `M${num(x0)} ${num(y0)}H${num(x1)}V${num(y1)}H${num(x0)}Z`;
|
|
40
|
+
}
|
|
41
|
+
const [cx, cy, rx, ry] = a.ellipse;
|
|
42
|
+
return `M${num(cx - rx)} ${num(cy)}A${num(rx)} ${num(ry)} 0 1 0 ${num(cx + rx)} ${num(cy)}A${num(rx)} ${num(ry)} 0 1 0 ${num(cx - rx)} ${num(cy)}Z`;
|
|
43
|
+
};
|
|
44
|
+
/** The painted lines of a plan: the shapes drawn with the line's paint, those alike in feature, width and dash put in one path. */
|
|
45
|
+
export function strokes(plan, o) {
|
|
46
|
+
const groups = new Map();
|
|
47
|
+
const base = o.exact ? plan.lineWidth : plan.drawnLine;
|
|
48
|
+
for (const shape of plan.shapes) {
|
|
49
|
+
if (shape.kind === "dot" || shape.kind === "bar")
|
|
50
|
+
continue;
|
|
51
|
+
const w = o.exact ? (shape.w ?? plan.lineWidth) : Math.max(shape.w ?? plan.lineWidth, shape.least ?? plan.drawnLine);
|
|
52
|
+
const key = `${shape.feature}|${num(w)}|${shape.dash?.join(",") ?? ""}|${shape.cls ?? ""}`;
|
|
53
|
+
const group = groups.get(key) ?? { feature: shape.feature, w, dash: shape.dash, cls: shape.cls ?? "ky-line", d: [] };
|
|
54
|
+
group.d.push(pathOf(shape));
|
|
55
|
+
groups.set(key, group);
|
|
56
|
+
}
|
|
57
|
+
let out = "";
|
|
58
|
+
for (const group of groups.values()) {
|
|
59
|
+
out += el("path", { class: ft(o, group.feature, group.cls), d: group.d.join(""), "stroke-width": group.w === base ? base : group.w, "stroke-dasharray": group.dash === undefined ? undefined : `${num(group.dash[0])} ${num(group.dash[1])}`, fill: "none" });
|
|
60
|
+
}
|
|
61
|
+
return out;
|
|
62
|
+
}
|
|
63
|
+
/** The filled marks of a plan: the bars in one path to a feature, the dots one each. */
|
|
64
|
+
function marks(plan, o) {
|
|
65
|
+
const bars = new Map();
|
|
66
|
+
let dots = "";
|
|
67
|
+
const lift = o.exact ? 1 : 1.6;
|
|
68
|
+
for (const shape of plan.shapes) {
|
|
69
|
+
if (shape.kind === "bar")
|
|
70
|
+
bars.set(shape.feature, [...(bars.get(shape.feature) ?? []), pathOf(shape)]);
|
|
71
|
+
else if (shape.kind === "dot")
|
|
72
|
+
dots += el("circle", { class: ft(o, shape.feature, shape.paint === "post" ? "ky-post-end" : "ky-fill-line"), cx: shape.cx, cy: shape.cy, r: shape.r * lift });
|
|
73
|
+
}
|
|
74
|
+
let out = "";
|
|
75
|
+
for (const [feature, d] of bars)
|
|
76
|
+
out += el("path", { class: ft(o, feature, "ky-fill-line"), d: d.join("") });
|
|
77
|
+
return out + dots;
|
|
78
|
+
}
|
|
79
|
+
/** One goal as the options ask for it: the net behind the goal line as a box, a line across the mouth, a solid strip, or nothing. */
|
|
80
|
+
function goalMarkup(goal, style, thick, o) {
|
|
81
|
+
if (style === "none")
|
|
82
|
+
return "";
|
|
83
|
+
const half = goal.width / 2;
|
|
84
|
+
const x = goal.x;
|
|
85
|
+
const out = goal.out;
|
|
86
|
+
if (style === "line")
|
|
87
|
+
return el("path", { class: ft(o, "goals", "ky-goal"), d: `M${num(x)} ${num(goal.y - half)}V${num(goal.y + half)}`, "stroke-width": thick * 3, fill: "none" });
|
|
88
|
+
if (style === "strip")
|
|
89
|
+
return el("path", { class: ft(o, "goals", "ky-goal-strip"), d: `M${num(x)} ${num(goal.y - half)}h${num(out * Math.max(goal.depth, thick * 2))}v${num(2 * half)}h${num(-out * Math.max(goal.depth, thick * 2))}z` });
|
|
90
|
+
const d = `M${num(x)} ${num(goal.y - half)}h${num(out * goal.depth)}v${num(2 * half)}h${num(-out * goal.depth)}`;
|
|
91
|
+
return el("path", { class: ft(o, "goals", "ky-goal"), d, "stroke-width": thick * 1.4, fill: "none", "stroke-linejoin": "round" }) + el("path", { class: ft(o, "goals", "ky-goal"), d: `M${num(x)} ${num(goal.y - half)}V${num(goal.y + half)}`, "stroke-width": thick * 1.4, fill: "none" });
|
|
92
|
+
}
|
|
93
|
+
/**
|
|
94
|
+
* A field sport's surface lying wide, from the sport's plan: the ground, the mown turf, the painted areas, the lines, the goals, and, on a score, the
|
|
95
|
+
* ends painted in the teams' colours and the place for the board. The markings are the plan's, which are the rulebook's (leagues/*.ts).
|
|
96
|
+
*/
|
|
97
|
+
export function fieldSurface(o, plan, style = {}) {
|
|
98
|
+
const L = plan.length;
|
|
99
|
+
const W = plan.width;
|
|
100
|
+
const m = o.margin ?? plan.margin;
|
|
101
|
+
const view0 = { x: -m, y: -m, w: L + 2 * m, h: W + 2 * m };
|
|
102
|
+
const shaped = plan.outline.kind !== "rect" || (plan.outline.radius ?? 0) > 0;
|
|
103
|
+
const full = o.detail === "full";
|
|
104
|
+
const edge = outlineD(L, W, plan.outline);
|
|
105
|
+
let defs = "";
|
|
106
|
+
const surfaceShape = shaped ? el("path", { class: ft(o, plan.surfaceFeature ?? "turf", "ky-surface"), d: edge }) : el("rect", { class: ft(o, plan.surfaceFeature ?? "turf", "ky-surface"), x: 0, y: 0, width: L, height: W });
|
|
107
|
+
let base = el("rect", { class: ft(o, "apron", "ky-apron"), x: view0.x, y: view0.y, width: view0.w, height: view0.h }) + surfaceShape;
|
|
108
|
+
// Mown bands, cut to an oval surface or to the rectangle where the pattern runs past it.
|
|
109
|
+
if (o.stripes && plan.band > 0 && o.mow !== "none") {
|
|
110
|
+
const pattern = o.mow !== undefined && o.mow !== "rings" && o.mow !== "fan" ? o.mow : "bands";
|
|
111
|
+
const cells = oddCells(L, plan.band);
|
|
112
|
+
const mown = mowTurf(pattern, { x: 0, y: 0, w: L, h: W }, L / cells);
|
|
113
|
+
if (mown.path !== "") {
|
|
114
|
+
const clip = shaped || mown.clip;
|
|
115
|
+
if (clip)
|
|
116
|
+
defs += el("clipPath", { id: `${o.id}-turf` }, shaped ? el("path", { d: edge }) : el("rect", { x: 0, y: 0, width: L, height: W }));
|
|
117
|
+
base += el("path", { class: ft(o, "mowing", "ky-stripe"), d: mown.path, "fill-rule": mown.evenodd ? "evenodd" : undefined, "clip-path": clip ? `url(#${o.id}-turf)` : undefined });
|
|
118
|
+
}
|
|
119
|
+
}
|
|
120
|
+
for (const area of plan.areas)
|
|
121
|
+
base += el("path", { class: ft(o, area.feature, area.cls), d: areaD(area), "fill-rule": area.frame === undefined ? undefined : "evenodd" });
|
|
122
|
+
const ends = o.score && plan.ends !== undefined ? plan.ends : undefined;
|
|
123
|
+
if (ends !== undefined) {
|
|
124
|
+
for (const side of ["left", "right"]) {
|
|
125
|
+
const b = ends[side];
|
|
126
|
+
base += el("rect", { class: ft(o, `${plan.endFeature ?? "end-zone"}-${side}`, `ky-zone ky-zone-${side}`), x: b.x, y: b.y, width: b.w, height: b.h });
|
|
127
|
+
}
|
|
128
|
+
}
|
|
129
|
+
let lines = strokes(plan, o) + marks(plan, o);
|
|
130
|
+
const thick = o.exact ? plan.lineWidth : plan.drawnLine;
|
|
131
|
+
let goals = "";
|
|
132
|
+
let custom = "";
|
|
133
|
+
for (const goal of plan.goals) {
|
|
134
|
+
if (o.goalMarkup === undefined)
|
|
135
|
+
goals += goalMarkup(goal, style.goals ?? "box", thick, o);
|
|
136
|
+
else
|
|
137
|
+
custom += o.goalMarkup({ sport: plan.sport, end: goal.end, x: goal.x, y: goal.y, width: goal.width, depth: goal.depth, out: goal.out, line: thick });
|
|
138
|
+
}
|
|
139
|
+
lines += goals;
|
|
140
|
+
const surface = {
|
|
141
|
+
sport: plan.sport,
|
|
142
|
+
view: view0,
|
|
143
|
+
base,
|
|
144
|
+
lines: lines + custom,
|
|
145
|
+
defs,
|
|
146
|
+
left: plan.left,
|
|
147
|
+
right: plan.right,
|
|
148
|
+
plate: plan.plate,
|
|
149
|
+
turned: o.portrait,
|
|
150
|
+
onColour: ends !== undefined,
|
|
151
|
+
};
|
|
152
|
+
surface.box = { x: 0, y: 0, w: L, h: W };
|
|
153
|
+
surface.lineRef = { width: thick, feet: 1 };
|
|
154
|
+
surface.ranges = plan.ranges;
|
|
155
|
+
if (o.landmarks === true)
|
|
156
|
+
surface.marks = full ? [...plan.marks] : plan.marks.filter((mark) => !mark.id.startsWith("~"));
|
|
157
|
+
if (o.portrait) {
|
|
158
|
+
const t = quarterTurn(view0);
|
|
159
|
+
surface.view = t.view;
|
|
160
|
+
surface.turn = t.turn;
|
|
161
|
+
}
|
|
162
|
+
return surface;
|
|
163
|
+
}
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
import { type FootballSpec } from "../geometry.ts";
|
|
2
|
+
import { type BuildOptions, type Surface } from "./surface.ts";
|
|
3
|
+
/** What a season changes in a football field beyond its spec: whether it had hash marks, and the shape of its goal posts. */
|
|
4
|
+
export interface FootballMarks {
|
|
5
|
+
hashMarks: boolean;
|
|
6
|
+
postShape: "h" | "slingshot";
|
|
7
|
+
}
|
|
8
|
+
/**
|
|
9
|
+
* A football field of the NFL, the CFL or the IFAF: the field, the end zones, the lines, the marks, the numbers and the posts.
|
|
10
|
+
* The spec is the field of a season (`footballIn`); `marks` says what else that season had, and is today's by default.
|
|
11
|
+
*/
|
|
12
|
+
export declare function football(spec: FootballSpec, o: BuildOptions, marks?: FootballMarks): Surface;
|