@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,124 @@
|
|
|
1
|
+
import { type FrameUnit } from "../frames.ts";
|
|
2
|
+
import { type SoccerLayout, type SoccerSpec } from "./soccer-spec.ts";
|
|
3
|
+
/** The providers, by the id the options use. */
|
|
4
|
+
export type SoccerProviderId = "opta" | "statsbomb" | "wyscout" | "tracab" | "metrica" | "skillcorner" | "secondspectrum" | "impect" | "uefa" | "international";
|
|
5
|
+
/**
|
|
6
|
+
* A pitch as a data provider writes it down. Everything is in the provider's own unit.
|
|
7
|
+
*
|
|
8
|
+
* `xLeft` and `xRight` are x at the two goal lines, with the team attacking left to right; `yTop` and `yBottom` are y
|
|
9
|
+
* at the touchlines as they lie in a picture with the first at the top. So the frame says both where the origin is and
|
|
10
|
+
* which way y runs: Opta (y up) has `yTop: 100, yBottom: 0`; StatsBomb (y down) has `yTop: 0, yBottom: 80`. The depths
|
|
11
|
+
* are measured from the goal line along x, the half widths from the middle of the pitch along y.
|
|
12
|
+
*/
|
|
13
|
+
export interface SoccerFrame {
|
|
14
|
+
id: string;
|
|
15
|
+
name: string;
|
|
16
|
+
/** The unit of the numbers, for people. */
|
|
17
|
+
unit: string;
|
|
18
|
+
xLeft: number;
|
|
19
|
+
xRight: number;
|
|
20
|
+
yTop: number;
|
|
21
|
+
yBottom: number;
|
|
22
|
+
/** How far the penalty area reaches from the goal line, and half its width. */
|
|
23
|
+
penaltyDepth: number;
|
|
24
|
+
penaltyHalfWidth: number;
|
|
25
|
+
/** How far the goal area reaches, and half its width. */
|
|
26
|
+
goalAreaDepth: number;
|
|
27
|
+
goalAreaHalfWidth: number;
|
|
28
|
+
/** The penalty mark, from the goal line. */
|
|
29
|
+
spot: number;
|
|
30
|
+
/** Half the width of the goal, between the posts. */
|
|
31
|
+
goalHalfWidth: number;
|
|
32
|
+
}
|
|
33
|
+
/** A provider: its name, the page its figures were read from, and its frame (which for some depends on the size of the pitch). */
|
|
34
|
+
export interface SoccerProvider {
|
|
35
|
+
id: SoccerProviderId;
|
|
36
|
+
name: string;
|
|
37
|
+
/** The unit of its numbers, for people. */
|
|
38
|
+
unit: string;
|
|
39
|
+
/** The unit as the frames registry names it. */
|
|
40
|
+
frameUnit: FrameUnit;
|
|
41
|
+
/** Where (0, 0) lies, in words. */
|
|
42
|
+
origin: string;
|
|
43
|
+
/** True when its extents follow the size of the pitch (Tracab's centimetres from the centre): the frame is made for a size. */
|
|
44
|
+
sized: boolean;
|
|
45
|
+
/** The page of the provider's own documentation the figures were read from. */
|
|
46
|
+
source: string;
|
|
47
|
+
/** One line on how the numbers run, for people. */
|
|
48
|
+
note: string;
|
|
49
|
+
/** The frame, for a pitch of this length and width in metres (ignored unless `sized`). */
|
|
50
|
+
frame: (length: number, width: number) => SoccerFrame;
|
|
51
|
+
}
|
|
52
|
+
/**
|
|
53
|
+
* The providers. Where a provider's own page gives the figures (StatsBomb's and Wyscout's diagrams, Impect's glossary,
|
|
54
|
+
* Metrica's and SkillCorner's READMEs) they are those; Opta's, Tracab's and Second Spectrum's specifications are not
|
|
55
|
+
* public, so theirs are the figures the open-source libraries mplsoccer, ggsoccer and kloppy agree on, which docs/sources.md says.
|
|
56
|
+
*/
|
|
57
|
+
export declare const SOCCER_PROVIDERS: Readonly<Record<SoccerProviderId, SoccerProvider>>;
|
|
58
|
+
/** The ids of the providers, in the order a menu lists them. */
|
|
59
|
+
export declare const SOCCER_PROVIDER_IDS: readonly SoccerProviderId[];
|
|
60
|
+
/** Whether a frame can be drawn and mapped: its numbers are finite, its extents are not empty and its landmarks lie in order. */
|
|
61
|
+
export declare function validFrame(f: unknown): f is SoccerFrame;
|
|
62
|
+
/** Where the landmarks of a frame stand on each axis, in its units, from the left goal line to the right and from the top touchline to the bottom. */
|
|
63
|
+
export declare function soccerLandmarks(f: SoccerFrame): {
|
|
64
|
+
x: number[];
|
|
65
|
+
y: number[];
|
|
66
|
+
};
|
|
67
|
+
/** A length and width in metres: what a provider whose numbers follow the pitch needs to know. */
|
|
68
|
+
export interface PitchMetres {
|
|
69
|
+
length: number;
|
|
70
|
+
width: number;
|
|
71
|
+
}
|
|
72
|
+
/**
|
|
73
|
+
* The frame of a provider (by id), or a frame of your own as it is, for a pitch of this size in metres (which matters
|
|
74
|
+
* only to a provider whose numbers follow the pitch). An id that is not a provider, or a frame that cannot be
|
|
75
|
+
* drawn, gives `undefined`.
|
|
76
|
+
* @example
|
|
77
|
+
* ```ts
|
|
78
|
+
* import { soccerFrame } from "@johnmorrisdotca/kyogijo-stadiums";
|
|
79
|
+
* const opta = soccerFrame("opta");
|
|
80
|
+
* console.log(opta?.xRight, opta?.yTop);
|
|
81
|
+
* // 100 100
|
|
82
|
+
* ```
|
|
83
|
+
*/
|
|
84
|
+
export declare function soccerFrame(frame: SoccerProviderId | SoccerFrame | string | undefined, pitch?: PitchMetres): SoccerFrame | undefined;
|
|
85
|
+
/** The frame an option asks for, for the pitch being drawn. */
|
|
86
|
+
export declare const resolveFrame: (pitchType: SoccerProviderId | SoccerFrame | string | undefined, spec: Pick<SoccerSpec, "length" | "width">) => SoccerFrame | undefined;
|
|
87
|
+
/** Where a provider's lines stand on a pitch of this size, in metres: its figures turned to metres. */
|
|
88
|
+
export declare function layoutFromFrame(f: SoccerFrame, spec: Pick<SoccerSpec, "length" | "width">): SoccerLayout;
|
|
89
|
+
/**
|
|
90
|
+
* The matrix `[a, b, c, d, e, f]` of an SVG `transform` that turns a provider's numbers into metres on a pitch of this
|
|
91
|
+
* size, the left goal line at x 0 and the top touchline at y 0. A group with this transform takes the provider's raw
|
|
92
|
+
* x and y: that is the `ky-data` group in a drawing made with `pitchType`.
|
|
93
|
+
*/
|
|
94
|
+
export declare function frameMatrix(f: SoccerFrame, spec: Pick<SoccerSpec, "length" | "width">): [number, number, number, number, number, number];
|
|
95
|
+
/** A map from one provider's coordinates to another's. */
|
|
96
|
+
export interface Rescaler {
|
|
97
|
+
(x: number, y: number): [number, number];
|
|
98
|
+
/** Only the x of a point. */
|
|
99
|
+
x(value: number): number;
|
|
100
|
+
/** Only the y of a point. */
|
|
101
|
+
y(value: number): number;
|
|
102
|
+
/** The map the other way: from the second provider's coordinates to the first's. */
|
|
103
|
+
inverse: Rescaler;
|
|
104
|
+
from: SoccerFrame;
|
|
105
|
+
to: SoccerFrame;
|
|
106
|
+
}
|
|
107
|
+
/**
|
|
108
|
+
* The map from one coordinate system to another, piecewise linear between the landmarks (it is built on `piecewise` of
|
|
109
|
+
* `@johnmorrisdotca/kyogijo-stadiums/frames`), so that a point on a line of the pitch (the goal line, the goal area, the penalty
|
|
110
|
+
* mark, the penalty area, the halfway line, the touchline, the posts) lands on the same line in the other system. Between
|
|
111
|
+
* two landmarks the map is linear; beyond the goal lines and the touchlines (a ball out of play) it runs on along the last
|
|
112
|
+
* piece. Give a pitch size in metres for a provider whose numbers follow the pitch (Tracab, SkillCorner, Second
|
|
113
|
+
* Spectrum, Metrica, `international`). The same map, through the surface and in feet, is `convert` of the frames module.
|
|
114
|
+
* @example
|
|
115
|
+
* ```ts
|
|
116
|
+
* import { rescale } from "@johnmorrisdotca/kyogijo-stadiums";
|
|
117
|
+
* const toStatsBomb = rescale("opta", "statsbomb");
|
|
118
|
+
* // The middle of Opta's penalty-box line, 17 units from the goal line, is on StatsBomb's, 18 yards from it.
|
|
119
|
+
* const [x, y] = toStatsBomb(100 - 17, 50);
|
|
120
|
+
* console.log(x, y);
|
|
121
|
+
* // 102 40
|
|
122
|
+
* ```
|
|
123
|
+
*/
|
|
124
|
+
export declare function rescale(from: SoccerProviderId | SoccerFrame, to: SoccerProviderId | SoccerFrame, pitch?: PitchMetres): Rescaler;
|
|
@@ -0,0 +1,334 @@
|
|
|
1
|
+
// The coordinate systems of the soccer data providers, as pitch specs (the idea of ggsoccer's `pitch_international` and
|
|
2
|
+
// its relatives, MIT, and of mplsoccer's pitch types, MIT), and the piecewise-linear map between any two of them that
|
|
3
|
+
// sends each landmark of one to the same landmark of the other (the idea of ggsoccer's `rescale_coordinates`). Our own
|
|
4
|
+
// code throughout; the providers' figures are facts, cited in docs/sources.md.
|
|
5
|
+
//
|
|
6
|
+
// A frame is the pitch as a provider writes it down: what x is at each goal line, what y is at each touchline, and where
|
|
7
|
+
// the provider puts the lines (the penalty area, the goal area, the penalty mark, the posts), in its own units. A
|
|
8
|
+
// provider that fixes its numbers (Opta, StatsBomb, Wyscout) puts the lines where its own figures say, which is rarely
|
|
9
|
+
// where the Laws put them on a pitch of 105 by 68 metres; the map keeps a point on a line on that line.
|
|
10
|
+
//
|
|
11
|
+
// The providers are registered as frames (`registerFrame`, src/frames.ts) under their ids, so that `toSurface`, `fromSurface`
|
|
12
|
+
// and `convert` take them by name, and the map between two of them is that module's `piecewise` mapper.
|
|
13
|
+
import { FRAMES, piecewise, registerFrame } from "../frames.js";
|
|
14
|
+
import { FEET_PER_METRE } from "../geometry.js";
|
|
15
|
+
import { SOCCER } from "./soccer-spec.js";
|
|
16
|
+
/** The Laws' landmarks, in metres, which every provider that reports metres (or a fraction of them) uses. */
|
|
17
|
+
const LAWS = { penaltyDepth: 16.5, penaltyHalfWidth: 20.16, goalAreaDepth: 5.5, goalAreaHalfWidth: 9.16, spot: 11, goalHalfWidth: 3.66 };
|
|
18
|
+
/** A frame whose numbers are metres (or a fixed multiple of them), centred or not. */
|
|
19
|
+
function lawsFrame(id, name, unit, k, e) {
|
|
20
|
+
return {
|
|
21
|
+
id,
|
|
22
|
+
name,
|
|
23
|
+
unit,
|
|
24
|
+
...e,
|
|
25
|
+
penaltyDepth: LAWS.penaltyDepth * k,
|
|
26
|
+
penaltyHalfWidth: LAWS.penaltyHalfWidth * k,
|
|
27
|
+
goalAreaDepth: LAWS.goalAreaDepth * k,
|
|
28
|
+
goalAreaHalfWidth: LAWS.goalAreaHalfWidth * k,
|
|
29
|
+
spot: LAWS.spot * k,
|
|
30
|
+
goalHalfWidth: LAWS.goalHalfWidth * k,
|
|
31
|
+
};
|
|
32
|
+
}
|
|
33
|
+
/** A frame whose extents are a fraction of the pitch: its landmarks are the Laws', as a fraction of the size. */
|
|
34
|
+
function fractionFrame(id, name, unit, length, width, e) {
|
|
35
|
+
const kx = Math.abs(e.xRight - e.xLeft) / length;
|
|
36
|
+
const ky = Math.abs(e.yBottom - e.yTop) / width;
|
|
37
|
+
return {
|
|
38
|
+
id,
|
|
39
|
+
name,
|
|
40
|
+
unit,
|
|
41
|
+
...e,
|
|
42
|
+
penaltyDepth: LAWS.penaltyDepth * kx,
|
|
43
|
+
penaltyHalfWidth: LAWS.penaltyHalfWidth * ky,
|
|
44
|
+
goalAreaDepth: LAWS.goalAreaDepth * kx,
|
|
45
|
+
goalAreaHalfWidth: LAWS.goalAreaHalfWidth * ky,
|
|
46
|
+
spot: LAWS.spot * kx,
|
|
47
|
+
goalHalfWidth: LAWS.goalHalfWidth * ky,
|
|
48
|
+
};
|
|
49
|
+
}
|
|
50
|
+
const centred = (length, width, k) => ({ xLeft: (-length / 2) * k, xRight: (length / 2) * k, yTop: (width / 2) * k, yBottom: (-width / 2) * k });
|
|
51
|
+
/**
|
|
52
|
+
* The providers. Where a provider's own page gives the figures (StatsBomb's and Wyscout's diagrams, Impect's glossary,
|
|
53
|
+
* Metrica's and SkillCorner's READMEs) they are those; Opta's, Tracab's and Second Spectrum's specifications are not
|
|
54
|
+
* public, so theirs are the figures the open-source libraries mplsoccer, ggsoccer and kloppy agree on, which docs/sources.md says.
|
|
55
|
+
*/
|
|
56
|
+
export const SOCCER_PROVIDERS = {
|
|
57
|
+
opta: {
|
|
58
|
+
id: "opta",
|
|
59
|
+
frameUnit: "percent",
|
|
60
|
+
origin: "the bottom left corner of the pitch",
|
|
61
|
+
name: "Opta / Stats Perform",
|
|
62
|
+
unit: "0 to 100",
|
|
63
|
+
sized: false,
|
|
64
|
+
source: "Stats Perform's event specification is not public: the figures are those mplsoccer and ggsoccer agree on (docs/sources.md)",
|
|
65
|
+
note: "0 to 100 on both axes, the origin at the bottom left, y up, each team attacking left to right; the lines stand at fixed numbers, whatever the pitch",
|
|
66
|
+
frame: () => ({ id: "opta", name: "Opta / Stats Perform", unit: "0 to 100", xLeft: 0, xRight: 100, yTop: 100, yBottom: 0, penaltyDepth: 17, penaltyHalfWidth: 28.9, goalAreaDepth: 5.8, goalAreaHalfWidth: 13.2, spot: 11.5, goalHalfWidth: 4.8 }),
|
|
67
|
+
},
|
|
68
|
+
statsbomb: {
|
|
69
|
+
id: "statsbomb",
|
|
70
|
+
frameUnit: "yd",
|
|
71
|
+
origin: "the top left corner of the pitch",
|
|
72
|
+
name: "StatsBomb",
|
|
73
|
+
unit: "yards",
|
|
74
|
+
sized: false,
|
|
75
|
+
source: "StatsBomb Open Data Events v4.0.0, Appendix 2, Locations (github.com/statsbomb/open-data, doc/)",
|
|
76
|
+
note: "120 by 80 yards, the origin at the top left, y down; the lines stand at 6, 12 and 18 yards from the goal line",
|
|
77
|
+
frame: () => ({ id: "statsbomb", name: "StatsBomb", unit: "yards", xLeft: 0, xRight: 120, yTop: 0, yBottom: 80, penaltyDepth: 18, penaltyHalfWidth: 22, goalAreaDepth: 6, goalAreaHalfWidth: 10, spot: 12, goalHalfWidth: 4 }),
|
|
78
|
+
},
|
|
79
|
+
wyscout: {
|
|
80
|
+
id: "wyscout",
|
|
81
|
+
frameUnit: "percent",
|
|
82
|
+
origin: "the top left corner of the pitch",
|
|
83
|
+
name: "Wyscout",
|
|
84
|
+
unit: "0 to 100",
|
|
85
|
+
sized: false,
|
|
86
|
+
source: "Wyscout Data Glossary, Pitch coordinates (dataglossary.wyscout.com/pitch_coordinates); the posts are from ggsoccer, which the glossary does not mark",
|
|
87
|
+
note: "0 to 100 on both axes, the origin at the top left, y down, the team attacking left to right; the lines stand at fixed numbers",
|
|
88
|
+
frame: () => ({ id: "wyscout", name: "Wyscout", unit: "0 to 100", xLeft: 0, xRight: 100, yTop: 0, yBottom: 100, penaltyDepth: 16, penaltyHalfWidth: 31, goalAreaDepth: 6, goalAreaHalfWidth: 13, spot: 10, goalHalfWidth: 6 }),
|
|
89
|
+
},
|
|
90
|
+
tracab: {
|
|
91
|
+
id: "tracab",
|
|
92
|
+
frameUnit: "cm",
|
|
93
|
+
origin: "the centre spot",
|
|
94
|
+
name: "Tracab",
|
|
95
|
+
unit: "centimetres",
|
|
96
|
+
sized: true,
|
|
97
|
+
source: "Tracab's specification is not public: the origin, unit and y direction are those mplsoccer, kloppy and floodlight use (docs/sources.md); the lines are the Laws'",
|
|
98
|
+
note: "centimetres from the middle of the pitch, y up, so the extents follow the pitch (about 5250 and 3400 on 105 by 68 m)",
|
|
99
|
+
frame: (length, width) => lawsFrame("tracab", "Tracab", "centimetres", 100, centred(length, width, 100)),
|
|
100
|
+
},
|
|
101
|
+
metrica: {
|
|
102
|
+
id: "metrica",
|
|
103
|
+
frameUnit: "fraction",
|
|
104
|
+
origin: "the top left corner of the pitch",
|
|
105
|
+
name: "Metrica Sports",
|
|
106
|
+
unit: "0 to 1",
|
|
107
|
+
sized: true,
|
|
108
|
+
source: "Metrica Sports sample-data README (github.com/metrica-sports/sample-data)",
|
|
109
|
+
note: "0 to 1 on both axes, the origin at the top left, y down, (0.5, 0.5) the kick-off; the lines are the Laws' as a fraction of the pitch",
|
|
110
|
+
frame: (length, width) => fractionFrame("metrica", "Metrica Sports", "0 to 1", length, width, { xLeft: 0, xRight: 1, yTop: 0, yBottom: 1 }),
|
|
111
|
+
},
|
|
112
|
+
skillcorner: {
|
|
113
|
+
id: "skillcorner",
|
|
114
|
+
frameUnit: "m",
|
|
115
|
+
origin: "the centre spot",
|
|
116
|
+
name: "SkillCorner",
|
|
117
|
+
unit: "metres",
|
|
118
|
+
sized: true,
|
|
119
|
+
source: "SkillCorner open data README and field diagram (github.com/SkillCorner/opendata)",
|
|
120
|
+
note: "metres from the middle of the pitch, y up, the long side x; the extents follow the pitch in the match's own file",
|
|
121
|
+
frame: (length, width) => lawsFrame("skillcorner", "SkillCorner", "metres", 1, centred(length, width, 1)),
|
|
122
|
+
},
|
|
123
|
+
secondspectrum: {
|
|
124
|
+
id: "secondspectrum",
|
|
125
|
+
frameUnit: "m",
|
|
126
|
+
origin: "the centre spot",
|
|
127
|
+
name: "Second Spectrum",
|
|
128
|
+
unit: "metres",
|
|
129
|
+
sized: true,
|
|
130
|
+
source: "Second Spectrum's specification is not public: the origin, unit and y direction are those mplsoccer, kloppy and floodlight use (docs/sources.md)",
|
|
131
|
+
note: "metres from the middle of the pitch, y up; the extents follow the pitch",
|
|
132
|
+
frame: (length, width) => lawsFrame("secondspectrum", "Second Spectrum", "metres", 1, centred(length, width, 1)),
|
|
133
|
+
},
|
|
134
|
+
impect: {
|
|
135
|
+
id: "impect",
|
|
136
|
+
frameUnit: "m",
|
|
137
|
+
origin: "the centre spot",
|
|
138
|
+
name: "Impect",
|
|
139
|
+
unit: "metres",
|
|
140
|
+
sized: false,
|
|
141
|
+
source: "Impect Glossary, context variables, \"How is the pitch defined?\" (glossary.impect.com/context-variable)",
|
|
142
|
+
note: "105 by 68 metres from the middle, x from -52.5 to 52.5 and y from -34 to 34, y up, the team attacking left to right",
|
|
143
|
+
frame: () => lawsFrame("impect", "Impect", "metres", 1, centred(105, 68, 1)),
|
|
144
|
+
},
|
|
145
|
+
uefa: {
|
|
146
|
+
id: "uefa",
|
|
147
|
+
frameUnit: "m",
|
|
148
|
+
origin: "the bottom left corner of the pitch",
|
|
149
|
+
name: "UEFA",
|
|
150
|
+
unit: "metres",
|
|
151
|
+
sized: false,
|
|
152
|
+
source: "UEFA Stadium Infrastructure Regulations, Article 5.01: 105 by 68 metres for categories 3 and 4; mplsoccer's 'uefa' type is the same in its code (its text says 65)",
|
|
153
|
+
note: "105 by 68 metres, the origin at the bottom left, y up",
|
|
154
|
+
frame: () => lawsFrame("uefa", "UEFA", "metres", 1, { xLeft: 0, xRight: 105, yTop: 68, yBottom: 0 }),
|
|
155
|
+
},
|
|
156
|
+
international: {
|
|
157
|
+
id: "international",
|
|
158
|
+
frameUnit: "m",
|
|
159
|
+
origin: "the bottom left corner of the pitch",
|
|
160
|
+
name: "International",
|
|
161
|
+
unit: "metres",
|
|
162
|
+
sized: true,
|
|
163
|
+
source: "IFAB Laws of the Game, Law 1; ggsoccer's pitch_international",
|
|
164
|
+
note: "metres from the bottom left corner, y up, the pitch as long and as wide as it is drawn (105 by 68 by default)",
|
|
165
|
+
frame: (length, width) => lawsFrame("international", "International", "metres", 1, { xLeft: 0, xRight: length, yTop: width, yBottom: 0 }),
|
|
166
|
+
},
|
|
167
|
+
};
|
|
168
|
+
/** The ids of the providers, in the order a menu lists them. */
|
|
169
|
+
export const SOCCER_PROVIDER_IDS = ["opta", "statsbomb", "wyscout", "tracab", "metrica", "skillcorner", "secondspectrum", "impect", "uefa", "international"];
|
|
170
|
+
/** Whether a frame can be drawn and mapped: its numbers are finite, its extents are not empty and its landmarks lie in order. */
|
|
171
|
+
export function validFrame(f) {
|
|
172
|
+
if (typeof f !== "object" || f === null)
|
|
173
|
+
return false;
|
|
174
|
+
const v = f;
|
|
175
|
+
const num = (key) => (typeof v[key] === "number" && Number.isFinite(v[key]) ? v[key] : Number.NaN);
|
|
176
|
+
const [xl, xr, yt, yb] = [num("xLeft"), num("xRight"), num("yTop"), num("yBottom")];
|
|
177
|
+
const [pd, pw, gd, gw, sp, gp] = [num("penaltyDepth"), num("penaltyHalfWidth"), num("goalAreaDepth"), num("goalAreaHalfWidth"), num("spot"), num("goalHalfWidth")];
|
|
178
|
+
if ([xl, xr, yt, yb, pd, pw, gd, gw, sp, gp].some(Number.isNaN))
|
|
179
|
+
return false;
|
|
180
|
+
const halfX = Math.abs(xr - xl) / 2;
|
|
181
|
+
const halfY = Math.abs(yb - yt) / 2;
|
|
182
|
+
return halfX > 0 && halfY > 0 && gd > 0 && gd < sp && sp < pd && pd < halfX && gp > 0 && gp < gw && gw < pw && pw < halfY;
|
|
183
|
+
}
|
|
184
|
+
/** Where the landmarks of a frame stand on each axis, in its units, from the left goal line to the right and from the top touchline to the bottom. */
|
|
185
|
+
export function soccerLandmarks(f) {
|
|
186
|
+
const sx = f.xRight >= f.xLeft ? 1 : -1;
|
|
187
|
+
const sy = f.yBottom >= f.yTop ? 1 : -1;
|
|
188
|
+
const mx = (f.xLeft + f.xRight) / 2;
|
|
189
|
+
const my = (f.yTop + f.yBottom) / 2;
|
|
190
|
+
const depths = [f.goalAreaDepth, f.spot, f.penaltyDepth];
|
|
191
|
+
const halves = [f.penaltyHalfWidth, f.goalAreaHalfWidth, f.goalHalfWidth];
|
|
192
|
+
return {
|
|
193
|
+
x: [f.xLeft, ...depths.map((d) => f.xLeft + sx * d), mx, ...depths.map((d) => f.xRight - sx * d).reverse(), f.xRight],
|
|
194
|
+
y: [f.yTop, ...halves.map((h) => my - sy * h), my, ...halves.map((h) => my + sy * h).reverse(), f.yBottom],
|
|
195
|
+
};
|
|
196
|
+
}
|
|
197
|
+
/** The size a frame is made for when none is given: the international 105 by 68 metres. */
|
|
198
|
+
const STANDARD = { length: 105, width: 68 };
|
|
199
|
+
/**
|
|
200
|
+
* The frame of a provider (by id), or a frame of your own as it is, for a pitch of this size in metres (which matters
|
|
201
|
+
* only to a provider whose numbers follow the pitch). An id that is not a provider, or a frame that cannot be
|
|
202
|
+
* drawn, gives `undefined`.
|
|
203
|
+
* @example
|
|
204
|
+
* ```ts
|
|
205
|
+
* import { soccerFrame } from "@johnmorrisdotca/kyogijo-stadiums";
|
|
206
|
+
* const opta = soccerFrame("opta");
|
|
207
|
+
* console.log(opta?.xRight, opta?.yTop);
|
|
208
|
+
* // 100 100
|
|
209
|
+
* ```
|
|
210
|
+
*/
|
|
211
|
+
export function soccerFrame(frame, pitch = STANDARD) {
|
|
212
|
+
if (typeof frame === "string") {
|
|
213
|
+
if (!Object.prototype.hasOwnProperty.call(SOCCER_PROVIDERS, frame))
|
|
214
|
+
return undefined;
|
|
215
|
+
const length = Number.isFinite(pitch.length) && pitch.length > 0 ? pitch.length : STANDARD.length;
|
|
216
|
+
const width = Number.isFinite(pitch.width) && pitch.width > 0 ? pitch.width : STANDARD.width;
|
|
217
|
+
const made = SOCCER_PROVIDERS[frame].frame(length, width);
|
|
218
|
+
return validFrame(made) ? made : undefined;
|
|
219
|
+
}
|
|
220
|
+
return validFrame(frame) ? frame : undefined;
|
|
221
|
+
}
|
|
222
|
+
/** The frame an option asks for, for the pitch being drawn. */
|
|
223
|
+
export const resolveFrame = (pitchType, spec) => (pitchType === undefined ? undefined : soccerFrame(pitchType, spec));
|
|
224
|
+
/** How the frame's units stand to metres on the pitch: metres per unit along x and along y. */
|
|
225
|
+
function unitsToMetres(f, spec) {
|
|
226
|
+
return { sx: spec.length / Math.abs(f.xRight - f.xLeft), sy: spec.width / Math.abs(f.yBottom - f.yTop) };
|
|
227
|
+
}
|
|
228
|
+
/** Where a provider's lines stand on a pitch of this size, in metres: its figures turned to metres. */
|
|
229
|
+
export function layoutFromFrame(f, spec) {
|
|
230
|
+
const { sx, sy } = unitsToMetres(f, spec);
|
|
231
|
+
return {
|
|
232
|
+
penaltyDepth: f.penaltyDepth * sx,
|
|
233
|
+
penaltyHalfWidth: f.penaltyHalfWidth * sy,
|
|
234
|
+
goalAreaDepth: f.goalAreaDepth * sx,
|
|
235
|
+
goalAreaHalfWidth: f.goalAreaHalfWidth * sy,
|
|
236
|
+
spot: f.spot * sx,
|
|
237
|
+
goalHalfWidth: f.goalHalfWidth * sy,
|
|
238
|
+
};
|
|
239
|
+
}
|
|
240
|
+
/**
|
|
241
|
+
* The matrix `[a, b, c, d, e, f]` of an SVG `transform` that turns a provider's numbers into metres on a pitch of this
|
|
242
|
+
* size, the left goal line at x 0 and the top touchline at y 0. A group with this transform takes the provider's raw
|
|
243
|
+
* x and y: that is the `ky-data` group in a drawing made with `pitchType`.
|
|
244
|
+
*/
|
|
245
|
+
export function frameMatrix(f, spec) {
|
|
246
|
+
const a = spec.length / (f.xRight - f.xLeft);
|
|
247
|
+
const d = spec.width / (f.yBottom - f.yTop);
|
|
248
|
+
return [a, 0, 0, d, -f.xLeft * a, -f.yTop * d];
|
|
249
|
+
}
|
|
250
|
+
function rescaler(a, b) {
|
|
251
|
+
const la = soccerLandmarks(a);
|
|
252
|
+
const lb = soccerLandmarks(b);
|
|
253
|
+
const pair = (from, to) => from.map((value, i) => [value, to[i]]);
|
|
254
|
+
const px = piecewise(pair(la.x, lb.x));
|
|
255
|
+
const py = piecewise(pair(la.y, lb.y));
|
|
256
|
+
const rx = piecewise(pair(lb.x, la.x));
|
|
257
|
+
const ry = piecewise(pair(lb.y, la.y));
|
|
258
|
+
const make = (fx, fy, from, to) => {
|
|
259
|
+
const map = ((x, y) => [fx(x), fy(y)]);
|
|
260
|
+
map.x = fx;
|
|
261
|
+
map.y = fy;
|
|
262
|
+
map.from = from;
|
|
263
|
+
map.to = to;
|
|
264
|
+
return map;
|
|
265
|
+
};
|
|
266
|
+
const forward = make(px.forward, py.forward, a, b);
|
|
267
|
+
forward.inverse = make(rx.forward, ry.forward, b, a);
|
|
268
|
+
forward.inverse.inverse = forward;
|
|
269
|
+
return forward;
|
|
270
|
+
}
|
|
271
|
+
/**
|
|
272
|
+
* The map from one coordinate system to another, piecewise linear between the landmarks (it is built on `piecewise` of
|
|
273
|
+
* `@johnmorrisdotca/kyogijo-stadiums/frames`), so that a point on a line of the pitch (the goal line, the goal area, the penalty
|
|
274
|
+
* mark, the penalty area, the halfway line, the touchline, the posts) lands on the same line in the other system. Between
|
|
275
|
+
* two landmarks the map is linear; beyond the goal lines and the touchlines (a ball out of play) it runs on along the last
|
|
276
|
+
* piece. Give a pitch size in metres for a provider whose numbers follow the pitch (Tracab, SkillCorner, Second
|
|
277
|
+
* Spectrum, Metrica, `international`). The same map, through the surface and in feet, is `convert` of the frames module.
|
|
278
|
+
* @example
|
|
279
|
+
* ```ts
|
|
280
|
+
* import { rescale } from "@johnmorrisdotca/kyogijo-stadiums";
|
|
281
|
+
* const toStatsBomb = rescale("opta", "statsbomb");
|
|
282
|
+
* // The middle of Opta's penalty-box line, 17 units from the goal line, is on StatsBomb's, 18 yards from it.
|
|
283
|
+
* const [x, y] = toStatsBomb(100 - 17, 50);
|
|
284
|
+
* console.log(x, y);
|
|
285
|
+
* // 102 40
|
|
286
|
+
* ```
|
|
287
|
+
*/
|
|
288
|
+
export function rescale(from, to, pitch = STANDARD) {
|
|
289
|
+
const a = soccerFrame(from, pitch);
|
|
290
|
+
const b = soccerFrame(to, pitch);
|
|
291
|
+
if (a === undefined || b === undefined)
|
|
292
|
+
throw new Error(`Unknown pitch type "${typeof (a === undefined ? from : to) === "string" ? String(a === undefined ? from : to) : "(a frame)"}", or a pitch too small for it: use one of ${SOCCER_PROVIDER_IDS.join(", ")}, or a valid frame`);
|
|
293
|
+
return rescaler(a, b);
|
|
294
|
+
}
|
|
295
|
+
// ----- The providers are frames of the frames module, for a pitch of any size: toSurface({ from: "opta", size }) and convert("opta", "statsbomb", { size }).
|
|
296
|
+
const feet = (metres) => metres * FEET_PER_METRE;
|
|
297
|
+
/** Where the landmarks stand on a pitch drawn with the Laws' markings, in feet, in the order of `soccerLandmarks`: along x from the left goal line, and across y from the top touchline. */
|
|
298
|
+
function surfaceLandmarks(length, width) {
|
|
299
|
+
const [ga, spot, pen] = [SOCCER.goalAreaReach, SOCCER.spot, SOCCER.penaltyReach].map(feet);
|
|
300
|
+
const { goalWidth } = SOCCER;
|
|
301
|
+
const goal = feet(goalWidth / 2);
|
|
302
|
+
const six = feet(goalWidth / 2 + SOCCER.goalAreaReach);
|
|
303
|
+
const box = feet(goalWidth / 2 + SOCCER.penaltyReach);
|
|
304
|
+
const mx = length / 2;
|
|
305
|
+
const my = width / 2;
|
|
306
|
+
return { x: [0, ga, spot, pen, mx, length - pen, length - spot, length - ga, length], y: [0, my - box, my - six, my - goal, my, my + goal, my + six, my + box, width] };
|
|
307
|
+
}
|
|
308
|
+
function asFrame(p) {
|
|
309
|
+
const sample = p.frame(STANDARD.length, STANDARD.width);
|
|
310
|
+
return {
|
|
311
|
+
name: p.id,
|
|
312
|
+
title: `${p.name} pitch coordinates`,
|
|
313
|
+
sport: "soccer",
|
|
314
|
+
unit: p.frameUnit,
|
|
315
|
+
x: [Math.min(sample.xLeft, sample.xRight), Math.max(sample.xLeft, sample.xRight)],
|
|
316
|
+
y: [Math.min(sample.yTop, sample.yBottom), Math.max(sample.yTop, sample.yBottom)],
|
|
317
|
+
origin: p.origin,
|
|
318
|
+
yDirection: sample.yBottom < sample.yTop ? "up" : "down",
|
|
319
|
+
size: "variable",
|
|
320
|
+
ends: "fixed",
|
|
321
|
+
// The landmarks on a pitch drawn with the Laws' markings: the surface's size is in feet, the provider's pitch in metres.
|
|
322
|
+
landmarks: ({ length, width }) => {
|
|
323
|
+
const frame = p.frame(length / FEET_PER_METRE, width / FEET_PER_METRE);
|
|
324
|
+
const own = soccerLandmarks(frame);
|
|
325
|
+
const there = surfaceLandmarks(length, width);
|
|
326
|
+
return { x: own.x.map((v, i) => [v, there.x[i]]), y: own.y.map((v, i) => [v, there.y[i]]) };
|
|
327
|
+
},
|
|
328
|
+
source: p.source,
|
|
329
|
+
note: p.note,
|
|
330
|
+
};
|
|
331
|
+
}
|
|
332
|
+
for (const id of SOCCER_PROVIDER_IDS)
|
|
333
|
+
if (!Object.prototype.hasOwnProperty.call(FRAMES, id))
|
|
334
|
+
registerFrame(asFrame(SOCCER_PROVIDERS[id]));
|
|
@@ -0,0 +1,138 @@
|
|
|
1
|
+
export declare const METRES_PER_YARD = 0.9144;
|
|
2
|
+
export declare const METRES_PER_FOOT = 0.3048;
|
|
3
|
+
/** How a pitch's penalty area is shaped: a box (two lines and a line across), futsal's two quarter circles and a line, or the FA small-sided laws' semicircle round the middle of the goal line. */
|
|
4
|
+
export type SoccerArea = "box" | "arcs" | "semicircle";
|
|
5
|
+
/** The formats: eleven a side under the IFAB Laws, the small-sided ones of the FA, and futsal under FIFA's Futsal Laws. */
|
|
6
|
+
export type SoccerFormat = "11" | "9" | "7" | "5" | "futsal";
|
|
7
|
+
/** A pitch: its size and every marking. All lengths in metres. */
|
|
8
|
+
export interface SoccerSpec {
|
|
9
|
+
id: string;
|
|
10
|
+
/** The name written in the title. */
|
|
11
|
+
name: string;
|
|
12
|
+
format: SoccerFormat;
|
|
13
|
+
/** Goal line to goal line (the touchline). */
|
|
14
|
+
length: number;
|
|
15
|
+
/** Touchline to touchline (the goal line). */
|
|
16
|
+
width: number;
|
|
17
|
+
/** The penalty area: how far it reaches into the field from the goal line, and its width along the goal line. */
|
|
18
|
+
penaltyDepth: number;
|
|
19
|
+
penaltyWidth: number;
|
|
20
|
+
/** The goal area (the six-yard box). `0` when the format has none. */
|
|
21
|
+
goalAreaDepth: number;
|
|
22
|
+
goalAreaWidth: number;
|
|
23
|
+
/** The penalty mark, from the goal line. `0` when there is none. */
|
|
24
|
+
spot: number;
|
|
25
|
+
/** A second penalty mark (futsal's 10 metres), from the goal line. */
|
|
26
|
+
secondSpot: number;
|
|
27
|
+
/** The radius of the centre circle. */
|
|
28
|
+
centreRadius: number;
|
|
29
|
+
/** The radius of the penalty arc, drawn outside the penalty area. `0` when there is none. */
|
|
30
|
+
arcRadius: number;
|
|
31
|
+
/** The radius of the corner arc. */
|
|
32
|
+
cornerRadius: number;
|
|
33
|
+
/** The goal, inside the posts. */
|
|
34
|
+
goalWidth: number;
|
|
35
|
+
goalHeight: number;
|
|
36
|
+
/** How deep the net is drawn behind the goal line. The Laws do not fix it. */
|
|
37
|
+
goalDepth: number;
|
|
38
|
+
/** The shape of the penalty area. */
|
|
39
|
+
area: SoccerArea;
|
|
40
|
+
/** Futsal: the line across the front of the penalty area, between its two quarter circles. */
|
|
41
|
+
areaLine: number;
|
|
42
|
+
/** The width of the lines, at most this (the Laws: 12 cm; futsal: 8 cm). */
|
|
43
|
+
lineWidth: number;
|
|
44
|
+
}
|
|
45
|
+
/**
|
|
46
|
+
* Law 1 of the IFAB Laws of the Game (2025/26), the markings of a full pitch: the goal area reaches 5.5 m from the
|
|
47
|
+
* posts and into the field, the penalty area 16.5 m, the penalty mark is 11 m from the goal line, the arcs and the
|
|
48
|
+
* centre circle have a radius of 9.15 m, the corner arc 1 m; the goal is 7.32 m between the posts and 2.44 m high; the
|
|
49
|
+
* lines are at most 12 cm wide. The Laws give yards beside each (6, 18, 12, 10 and 8 yards and 8 feet).
|
|
50
|
+
*/
|
|
51
|
+
export declare const SOCCER: {
|
|
52
|
+
readonly goalWidth: 7.32;
|
|
53
|
+
readonly goalHeight: 2.44;
|
|
54
|
+
readonly goalAreaReach: 5.5;
|
|
55
|
+
readonly penaltyReach: 16.5;
|
|
56
|
+
readonly spot: 11;
|
|
57
|
+
readonly centreRadius: 9.15;
|
|
58
|
+
readonly arcRadius: 9.15;
|
|
59
|
+
readonly cornerRadius: 1;
|
|
60
|
+
/** Corner flags stand at least 1.5 m high. */
|
|
61
|
+
readonly flagHeight: 1.5;
|
|
62
|
+
/** The least and the most of a pitch's length and width in any match, and in an international one. */
|
|
63
|
+
readonly limits: {
|
|
64
|
+
readonly length: readonly [90, 120];
|
|
65
|
+
readonly width: readonly [45, 90];
|
|
66
|
+
readonly internationalLength: readonly [100, 110];
|
|
67
|
+
readonly internationalWidth: readonly [64, 75];
|
|
68
|
+
};
|
|
69
|
+
readonly lineWidth: 0.12;
|
|
70
|
+
/** The marks off the field that show the distance of a corner kick: 9.15 m from the corner arc. */
|
|
71
|
+
readonly cornerMark: 9.15;
|
|
72
|
+
};
|
|
73
|
+
/** The goal area's width and the penalty area's, which follow from the goal and the reach. */
|
|
74
|
+
export declare const goalAreaWidth: (goal?: number, reach?: number) => number;
|
|
75
|
+
export declare const penaltyAreaWidth: (goal?: number, reach?: number) => number;
|
|
76
|
+
/** A full-size, eleven-a-side pitch of any size, with the Laws' markings. */
|
|
77
|
+
export declare function fullPitch(id: string, name: string, length: number, width: number): SoccerSpec;
|
|
78
|
+
/** Where the markings stand, in metres: the spec's, or a data provider's own. */
|
|
79
|
+
export interface SoccerLayout {
|
|
80
|
+
penaltyDepth: number;
|
|
81
|
+
penaltyHalfWidth: number;
|
|
82
|
+
goalAreaDepth: number;
|
|
83
|
+
goalAreaHalfWidth: number;
|
|
84
|
+
spot: number;
|
|
85
|
+
goalHalfWidth: number;
|
|
86
|
+
}
|
|
87
|
+
/** The layout of a spec as the Laws and the federation give it. */
|
|
88
|
+
export declare function layoutOf(spec: SoccerSpec): SoccerLayout;
|
|
89
|
+
/** Which of the Laws' ranges a length and a width fall in. */
|
|
90
|
+
export type SoccerPitchClass = "international" | "within-laws" | "outside-laws";
|
|
91
|
+
/**
|
|
92
|
+
* Where a pitch of this size stands under Law 1: `international` (100 to 110 m by 64 to 75 m, for international
|
|
93
|
+
* matches), `within-laws` (90 to 120 m by 45 to 90 m, and the touchline longer than the goal line) or `outside-laws`.
|
|
94
|
+
* @example
|
|
95
|
+
* ```ts
|
|
96
|
+
* import { soccerPitchClass } from "@johnmorrisdotca/kyogijo-stadiums";
|
|
97
|
+
* console.log(soccerPitchClass(105, 68), soccerPitchClass(95, 60), soccerPitchClass(60, 40));
|
|
98
|
+
* // international within-laws outside-laws
|
|
99
|
+
* ```
|
|
100
|
+
*/
|
|
101
|
+
export declare function soccerPitchClass(length: number, width: number): SoccerPitchClass;
|
|
102
|
+
/** The ids of the presets. */
|
|
103
|
+
export type SoccerPitchId = "fifa" | "uefa" | "mls" | "ncaa" | "law-min" | "law-max" | "9-a-side" | "7-a-side" | "5-a-side" | "futsal";
|
|
104
|
+
/** The ids of the presets, in the order a menu lists them. */
|
|
105
|
+
export declare const SOCCER_PITCH_IDS: readonly SoccerPitchId[];
|
|
106
|
+
/**
|
|
107
|
+
* The presets: the international pitch of 105 by 68 m (the Laws' usual, the Premier League's and UEFA's categories 3 and
|
|
108
|
+
* 4), the least size the MLS requires (110 by 70 yards) and the NCAA's best (120 by 75 yards), the least and most the Laws
|
|
109
|
+
* allow, the FA's 9-, 7- and 5-a-side pitches and FIFA's futsal court. Each is a full `SoccerSpec`.
|
|
110
|
+
* @example
|
|
111
|
+
* ```ts
|
|
112
|
+
* import { SOCCER_PITCHES } from "@johnmorrisdotca/kyogijo-stadiums";
|
|
113
|
+
* const { length, width, name } = SOCCER_PITCHES.fifa;
|
|
114
|
+
* console.log(name, length, width);
|
|
115
|
+
* // International (FIFA) 105 68
|
|
116
|
+
* ```
|
|
117
|
+
*/
|
|
118
|
+
export declare const SOCCER_PITCHES: Readonly<Record<SoccerPitchId, SoccerSpec>>;
|
|
119
|
+
/** A pitch given by size: any positive length and width, in metres, yards or feet. */
|
|
120
|
+
export interface SoccerSize {
|
|
121
|
+
length: number;
|
|
122
|
+
width: number;
|
|
123
|
+
/** `m` (the default), `yd`, `ft`, `in`, `cm` or `mm`. */
|
|
124
|
+
unit?: "m" | "yd" | "ft" | "in" | "cm" | "mm";
|
|
125
|
+
}
|
|
126
|
+
/**
|
|
127
|
+
* The pitch an option asks for: a preset's id, or a size. An unknown id, or a size that is not a positive number (or
|
|
128
|
+
* is more than 400 m), gives the international pitch. A size has the Laws' markings of a full pitch, sized to fit:
|
|
129
|
+
* the areas are never wider than the pitch.
|
|
130
|
+
* @example
|
|
131
|
+
* ```ts
|
|
132
|
+
* import { soccerSpec } from "@johnmorrisdotca/kyogijo-stadiums";
|
|
133
|
+
* const pitch = soccerSpec({ length: 110, width: 70, unit: "yd" });
|
|
134
|
+
* console.log(pitch.length.toFixed(2), pitch.width.toFixed(2));
|
|
135
|
+
* // 100.58 64.01
|
|
136
|
+
* ```
|
|
137
|
+
*/
|
|
138
|
+
export declare function soccerSpec(pitch?: SoccerPitchId | SoccerSize | string, defaultUnit?: NonNullable<SoccerSize["unit"]>): SoccerSpec;
|