/ specs / construct_language_cl_norm_5_spec.tex
construct_language_cl_norm_5_spec.tex
 1  \documentclass[11pt]{article}
 2  
 3  \usepackage[margin=1in]{geometry}
 4  \usepackage{microtype}
 5  \usepackage{booktabs}
 6  \usepackage{longtable}
 7  \usepackage[hidelinks]{hyperref}
 8  \usepackage{amsmath}
 9  
10  \title{CL-NORM-5 --- Polygon Containment (GML v0.2)}
11  \author{}
12  \date{January 13, 2026}
13  
14  \begin{document}
15  \maketitle
16  
17  \section{Purpose}
18  
19  CL-NORM-4 improved scope inference by using per-glyph radii derived from SVG bounds (GML v0.1).
20  CL-NORM-5 replaces radius containment with \textbf{polygon containment} using GML v0.2 convex hulls.
21  
22  This sharply reduces false containments and makes scope trees more stable under layout normalization.
23  
24  \section{GML v0.2}
25  
26  For each glyph \(G\), the mask library provides:
27  \begin{itemize}
28    \item \texttt{hull(G)}: a convex polygon in glyph-local coordinates (centered at (32,32)), up to 12 vertices
29  \end{itemize}
30  
31  For each frame glyph \(F\), the library provides:
32  \begin{itemize}
33    \item \texttt{contain\_hull(F)}: an expanded convex polygon representing the semantic interior
34  \end{itemize}
35  
36  \section{Transforming Hulls Into World Space}
37  
38  For an instance \(I\) with center \((x,y)\), scale \(s\), rotation \(\theta\), and optional reflection:
39  
40  \begin{enumerate}
41    \item shift each hull vertex \((u,v)\) by the glyph center (32,32):
42      \[
43        (d_x,d_y) = (u-32, v-32)
44      \]
45    \item apply reflection (mirrorX) if present:
46      \[
47        d_x \leftarrow -d_x
48      \]
49    \item apply scale:
50      \[
51        (d_x,d_y) \leftarrow s(d_x,d_y)
52      \]
53    \item apply rotation:
54      \[
55        (d'_x,d'_y) = (d_x\cos\theta - d_y\sin\theta,\ d_x\sin\theta + d_y\cos\theta)
56      \]
57    \item translate to world space:
58      \[
59        (x',y') = (x + d'_x,\ y + d'_y)
60      \]
61  \end{enumerate}
62  
63  \section{Containment Test}
64  
65  A frame instance \(F\) contains a child instance \(X\) if \emph{all} transformed vertices of \(X\)'s hull are inside
66  the transformed \texttt{contain\_hull(F)} polygon and at least a margin \(m\) away from its edges.
67  
68  \[
69  \text{contains}(F,X) \iff \forall p \in \text{Hull}(X):\ p \in \text{ContainHull}(F)\ \wedge\ \operatorname{dist}(p,\partial \text{ContainHull}(F)) \ge m
70  \]
71  
72  A practical margin is \(m=2\).
73  
74  \section{Scope Choice}
75  
76  As in CL-NORM-2/4, choose the deepest containing frame (smallest interior polygon area), deterministically.
77  
78  \section{Integration With CL-NORM-3}
79  
80  After CL-NORM-3 polar-slot layout, rerun polygon-based scope inference to ensure scope remains consistent under canonical layout.
81  
82  \section{Notes}
83  
84  GML v0.2 uses convex hulls derived from SVG geometry points (including curve control points), which is safe but may be slightly conservative.
85  Future GML revisions may use tighter hulls via curve sampling or signed-distance fields.
86  
87  \end{document}