{
  "openapi": "3.1.1",
  "info": {
    "title": "Letterform Mask Comparison API",
    "version": "1.0.0",
    "summary": "Compare two binary text masks by letterform overlap and aspect ratio.",
    "description": "Every endpoint performs the same calculation as the human page and returns inputs, result, units, assumptions, sources, warnings and computedAt. MCP endpoint: /mcp."
  },
  "servers": [
    {
      "url": "https://luminaletterformcompare.usefulweb.app"
    }
  ],
  "paths": {
    "/api/v1/calculate": {
      "post": {
        "operationId": "calculate",
        "summary": "Compare two binary text masks by letterform overlap and aspect ratio.",
        "description": "Paste two binary grids representing the same visible text to compare their ink shapes and proportions. Get visual similarity, Dice overlap, intersection-over-union and an aligned SVG overlay. The score compares supplied masks; it does not identify a font or express identity confidence.\n\nMethodology:\n- Trim each binary grid to its ink bounds, then independently resample width and height to 128 × 48 using rectangular occupancy at a 35% threshold. Input grids are limited to 128 × 64 and must contain visible ink.\n- Find the best overlap over ±2 normalized pixels in each direction. Dice = 2 × intersection / total ink; IoU = intersection / union. Clipped pixels still count in the denominator.\n- Aspect similarity = exp(-3 × abs(ln(referenceAspect / candidateAspect))). Visual similarity = 85% Dice + 15% aspect similarity. Scores are rounded to two decimal places and are not probabilities.\n- Use identical text and case, one straight line and comparable thresholding. The SVG shows shared ink in dark gray, reference-only ink in orange and candidate-only ink in teal, after alignment. Type Lab uses this engine to rank candidate font renderings locally.",
        "tags": [
          "apps"
        ],
        "x-mcp-tool": "lumina_letterform_compare",
        "requestBody": {
          "required": true,
          "content": {
            "application/json": {
              "schema": {
                "$ref": "#/components/schemas/LuminaLetterformCompareInput"
              },
              "examples": {
                "example1": {
                  "summary": "Identical letterforms",
                  "value": {
                    "reference": "00100\n01010\n10001\n11111\n10001\n10001",
                    "candidate": "00100\n01010\n10001\n11111\n10001\n10001"
                  }
                },
                "example2": {
                  "summary": "Compare different letterforms",
                  "value": {
                    "reference": "00100\n01010\n10001\n11111\n10001\n10001",
                    "candidate": "10000\n10000\n10000\n10000\n10000\n11111"
                  }
                }
              }
            }
          }
        },
        "responses": {
          "200": {
            "description": "Calculation result envelope.",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/LuminaLetterformCompareResult"
                }
              }
            }
          },
          "400": {
            "description": "Malformed JSON body.",
            "content": {
              "application/problem+json": {
                "schema": {
                  "$ref": "#/components/schemas/Problem"
                }
              }
            }
          },
          "422": {
            "description": "Invalid input (see errors[]).",
            "content": {
              "application/problem+json": {
                "schema": {
                  "$ref": "#/components/schemas/Problem"
                }
              }
            }
          },
          "429": {
            "description": "Rate limit exceeded (see Retry-After).",
            "content": {
              "application/problem+json": {
                "schema": {
                  "$ref": "#/components/schemas/Problem"
                }
              }
            }
          }
        }
      }
    },
    "/api/v1/tool": {
      "get": {
        "operationId": "getToolDefinition",
        "summary": "Inputs, output schema and examples for this tool",
        "responses": {
          "200": {
            "description": "Tool definition.",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object"
                }
              }
            }
          }
        }
      }
    }
  },
  "components": {
    "schemas": {
      "Problem": {
        "type": "object",
        "description": "RFC 9457 problem details. 422 responses include per-field `errors`.",
        "required": [
          "type",
          "title",
          "status",
          "detail"
        ],
        "properties": {
          "type": {
            "type": "string"
          },
          "title": {
            "type": "string"
          },
          "status": {
            "type": "integer"
          },
          "detail": {
            "type": "string"
          },
          "code": {
            "type": "string"
          },
          "errors": {
            "type": "array",
            "items": {
              "type": "object",
              "required": [
                "field",
                "message"
              ],
              "properties": {
                "field": {
                  "type": "string"
                },
                "message": {
                  "type": "string"
                }
              }
            }
          }
        }
      },
      "LuminaLetterformCompareInput": {
        "type": "object",
        "additionalProperties": false,
        "properties": {
          "reference": {
            "title": "Reference grid (1 = ink, 0 = background)",
            "type": "string",
            "maxLength": 8400,
            "default": "00100\n01010\n10001\n11111\n10001\n10001"
          },
          "candidate": {
            "title": "Candidate grid (same text)",
            "type": "string",
            "maxLength": 8400,
            "default": "00100\n01010\n10001\n11111\n10001\n10001"
          }
        },
        "required": [
          "reference",
          "candidate"
        ]
      },
      "LuminaLetterformCompareResult": {
        "type": "object",
        "additionalProperties": false,
        "required": [
          "schemaVersion",
          "tool",
          "computedAt",
          "inputs",
          "summary",
          "result",
          "units",
          "assumptions",
          "sources",
          "warnings",
          "presentation",
          "links"
        ],
        "properties": {
          "schemaVersion": {
            "type": "string",
            "const": "1.0"
          },
          "tool": {
            "type": "object",
            "additionalProperties": false,
            "required": [
              "id",
              "name",
              "version"
            ],
            "properties": {
              "id": {
                "type": "string"
              },
              "name": {
                "type": "string"
              },
              "version": {
                "type": "string"
              }
            }
          },
          "computedAt": {
            "type": "string",
            "format": "date-time"
          },
          "inputs": {
            "type": "object",
            "description": "Normalised inputs actually used, including applied defaults."
          },
          "summary": {
            "type": "string"
          },
          "result": {
            "type": "object",
            "additionalProperties": false,
            "required": [
              "similarity",
              "dice",
              "iou",
              "aspectSimilarity",
              "shiftX",
              "shiftY",
              "referenceBounds",
              "candidateBounds",
              "referenceAspect",
              "candidateAspect"
            ],
            "properties": {
              "similarity": {
                "type": "number"
              },
              "dice": {
                "type": "number"
              },
              "iou": {
                "type": "number"
              },
              "aspectSimilarity": {
                "type": "number"
              },
              "shiftX": {
                "type": "integer"
              },
              "shiftY": {
                "type": "integer"
              },
              "referenceBounds": {
                "type": "object",
                "additionalProperties": false,
                "required": [
                  "x",
                  "y",
                  "width",
                  "height"
                ],
                "properties": {
                  "x": {
                    "type": "integer"
                  },
                  "y": {
                    "type": "integer"
                  },
                  "width": {
                    "type": "integer"
                  },
                  "height": {
                    "type": "integer"
                  }
                }
              },
              "candidateBounds": {
                "type": "object",
                "additionalProperties": false,
                "required": [
                  "x",
                  "y",
                  "width",
                  "height"
                ],
                "properties": {
                  "x": {
                    "type": "integer"
                  },
                  "y": {
                    "type": "integer"
                  },
                  "width": {
                    "type": "integer"
                  },
                  "height": {
                    "type": "integer"
                  }
                }
              },
              "referenceAspect": {
                "type": "number"
              },
              "candidateAspect": {
                "type": "number"
              }
            }
          },
          "units": {
            "type": "object",
            "additionalProperties": {
              "type": "string"
            }
          },
          "assumptions": {
            "type": "array",
            "items": {
              "type": "string"
            }
          },
          "sources": {
            "type": "array",
            "items": {
              "type": "object",
              "additionalProperties": false,
              "required": [
                "title"
              ],
              "properties": {
                "title": {
                  "type": "string"
                },
                "url": {
                  "type": "string"
                },
                "publisher": {
                  "type": "string"
                },
                "retrievedAt": {
                  "type": "string"
                },
                "note": {
                  "type": "string"
                }
              }
            }
          },
          "warnings": {
            "type": "array",
            "items": {
              "type": "string"
            }
          },
          "presentation": {
            "type": "array",
            "items": {
              "type": "object"
            },
            "description": "Display blocks used by the human page (same data)."
          },
          "links": {
            "type": "object",
            "additionalProperties": false,
            "required": [
              "human",
              "api",
              "openapi",
              "methodology"
            ],
            "properties": {
              "human": {
                "type": "string",
                "format": "uri"
              },
              "api": {
                "type": "string",
                "format": "uri"
              },
              "openapi": {
                "type": "string",
                "format": "uri"
              },
              "methodology": {
                "type": "string",
                "format": "uri"
              }
            }
          }
        }
      }
    }
  }
}