feat(anatomy): canvas and highlight composition in Rust (O1 + O3 tree-equal)
This commit is contained in:
1 parent
67d9af3f79
commit
1ec9316a73
8 files changed
+882
-33
No files matched your search
@@ -0,0 +1,236 @@
|
||||
//! Composition of one view (`docs/ANNOTATION-RENDERING.md`): the sanitised drawing framed on
|
||||
//! the view, with its annotation layer last. Two forms, as the TypeScript has them: the
|
||||
//! editor canvas (`apps/app/src/anatomy/drawing.ts`: a fresh root, `0 0 100 100` when no box
|
||||
//! is known, the interactive layer) and the PDF highlight (`packages/anatomy/src/render/
|
||||
//! compose.ts`: the asset's root framed in place, the selected markers only, recoloured, the
|
||||
//! halo filter on request). Both take a sanitised tree, never text.
|
||||
|
||||
use std::collections::HashSet;
|
||||
|
||||
use super::layer::{LayerError, find_view, render_layer, view_box_of};
|
||||
use super::svg::serialize::is_xml_text;
|
||||
use super::svg::{Element, Node};
|
||||
use crate::domain::sheet::AnatomicalSheetDocument;
|
||||
|
||||
pub const HIGHLIGHT_FILL: &str = "#b85a3f";
|
||||
pub const HIGHLIGHT_FILL_OPACITY: &str = "0.85";
|
||||
pub const HALO_FILTER_ID: &str = "osteo-halo";
|
||||
const CANVAS_FALLBACK_VIEW_BOX: &str = "0 0 100 100";
|
||||
|
||||
/// Why a view cannot be composed.
|
||||
#[derive(Debug, Clone, Copy, PartialEq, Eq)]
|
||||
pub enum ComposeError {
|
||||
UnknownView,
|
||||
/// A label or a path of the layer holds a code point XML 1.0 cannot carry.
|
||||
InvalidCharacter,
|
||||
}
|
||||
|
||||
impl From<LayerError> for ComposeError {
|
||||
fn from(_: LayerError) -> Self {
|
||||
Self::UnknownView
|
||||
}
|
||||
}
|
||||
|
||||
/// The asset a view draws: its own, else the first up its parent chain (cycle-safe).
|
||||
pub fn asset_id_of_view<'a>(
|
||||
document: &'a AnatomicalSheetDocument,
|
||||
view_id: &str,
|
||||
) -> Option<&'a str> {
|
||||
let mut visited: HashSet<&str> = HashSet::new();
|
||||
let mut current = find_view(document, view_id);
|
||||
while let Some(view) = current {
|
||||
if let Some(asset) = view.svg_asset_id() {
|
||||
return Some(asset);
|
||||
}
|
||||
if !visited.insert(view.id()) {
|
||||
return None;
|
||||
}
|
||||
current = view.parent_view_id().and_then(|p| find_view(document, p));
|
||||
}
|
||||
None
|
||||
}
|
||||
|
||||
/// The editor canvas of `view_id` drawn on `asset` (its sanitised drawing), no state: the
|
||||
/// canvas sets `data-state` in place after every build.
|
||||
pub fn compose_canvas(
|
||||
document: &AnatomicalSheetDocument,
|
||||
view_id: &str,
|
||||
asset: &Element,
|
||||
) -> Result<Element, ComposeError> {
|
||||
let view = find_view(document, view_id).ok_or(ComposeError::UnknownView)?;
|
||||
let mut root = Element {
|
||||
qname: "svg".to_owned(),
|
||||
namespace: asset.namespace.clone(),
|
||||
attrs: asset
|
||||
.attrs
|
||||
.iter()
|
||||
.filter(|a| a.qname != "width" && a.qname != "height")
|
||||
.cloned()
|
||||
.collect(),
|
||||
children: asset.children.clone(),
|
||||
};
|
||||
let view_box = view_box_of(view)
|
||||
.or_else(|| asset.attr("viewBox").map(str::to_owned))
|
||||
.unwrap_or_else(|| CANVAS_FALLBACK_VIEW_BOX.to_owned());
|
||||
root.set_attr("viewBox", view_box);
|
||||
let layer = render_layer(document, view_id, &HashSet::new())?;
|
||||
root.children.push(Node::Element(checked(layer)?));
|
||||
Ok(root)
|
||||
}
|
||||
|
||||
/// The PDF view of `view_id`: `asset` (sanitised, consumed) framed on the view, the markers
|
||||
/// of `annotation_ids` only, recoloured, with the halo filter when `halo`.
|
||||
pub fn compose_highlight(
|
||||
document: &AnatomicalSheetDocument,
|
||||
view_id: &str,
|
||||
mut asset: Element,
|
||||
annotation_ids: &HashSet<&str>,
|
||||
halo: bool,
|
||||
) -> Result<Element, ComposeError> {
|
||||
let view = find_view(document, view_id).ok_or(ComposeError::UnknownView)?;
|
||||
if let Some(view_box) = view_box_of(view) {
|
||||
asset.set_attr("viewBox", view_box);
|
||||
}
|
||||
asset.remove_attr("width");
|
||||
asset.remove_attr("height");
|
||||
if halo {
|
||||
ensure_halo_filter(&mut asset);
|
||||
}
|
||||
let layer = render_layer(document, view_id, &HashSet::new())?;
|
||||
let layer = highlight_layer(layer, annotation_ids, halo);
|
||||
asset.children.push(Node::Element(checked(layer)?));
|
||||
Ok(asset)
|
||||
}
|
||||
|
||||
/// The layer reduced to the selected annotations, recoloured, every `data-*` dropped.
|
||||
fn highlight_layer(mut layer: Element, ids: &HashSet<&str>, halo: bool) -> Element {
|
||||
layer.attrs.retain(|a| !a.qname.starts_with("data-"));
|
||||
let children = std::mem::take(&mut layer.children);
|
||||
layer.children = children
|
||||
.into_iter()
|
||||
.filter_map(|child| match child {
|
||||
Node::Element(e) if e.attr("data-anno-id").is_some_and(|id| ids.contains(id)) => {
|
||||
Some(Node::Element(highlight_element(e, halo)))
|
||||
}
|
||||
_ => None,
|
||||
})
|
||||
.collect();
|
||||
layer
|
||||
}
|
||||
|
||||
/// `{ ...withoutData(attrs), fill, 'fill-opacity' }` then `filter`: JavaScript keeps an
|
||||
/// existing key in place and appends a new one.
|
||||
fn highlight_element(mut element: Element, halo: bool) -> Element {
|
||||
element.attrs.retain(|a| !a.qname.starts_with("data-"));
|
||||
element.set_attr("fill", HIGHLIGHT_FILL.to_owned());
|
||||
element.set_attr("fill-opacity", HIGHLIGHT_FILL_OPACITY.to_owned());
|
||||
if halo {
|
||||
element.set_attr("filter", format!("url(#{HALO_FILTER_ID})"));
|
||||
}
|
||||
element
|
||||
}
|
||||
|
||||
/// One halo filter per root: in the first `<defs>` of the drawing, else in a new `<defs>`
|
||||
/// placed first; nothing when a `filter#osteo-halo` already exists.
|
||||
fn ensure_halo_filter(root: &mut Element) {
|
||||
if has_halo_filter(root) {
|
||||
return;
|
||||
}
|
||||
if !append_to_first_defs(root) {
|
||||
let defs = Element::svg("defs", Vec::new(), vec![Node::Element(halo_filter())]);
|
||||
root.children.insert(0, Node::Element(defs));
|
||||
}
|
||||
}
|
||||
|
||||
fn has_halo_filter(element: &Element) -> bool {
|
||||
element.element_children().any(|c| {
|
||||
(c.qname == "filter" && c.attr("id") == Some(HALO_FILTER_ID)) || has_halo_filter(c)
|
||||
})
|
||||
}
|
||||
|
||||
/// Appends the halo to the first `<defs>` below `element` (document order).
|
||||
fn append_to_first_defs(element: &mut Element) -> bool {
|
||||
for child in &mut element.children {
|
||||
let Node::Element(child) = child else {
|
||||
continue;
|
||||
};
|
||||
if child.qname == "defs" {
|
||||
child.children.push(Node::Element(halo_filter()));
|
||||
return true;
|
||||
}
|
||||
if append_to_first_defs(child) {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
false
|
||||
}
|
||||
|
||||
fn halo_filter() -> Element {
|
||||
let blur = |std: &str, result: &str| {
|
||||
Node::Element(Element::svg(
|
||||
"feGaussianBlur",
|
||||
vec![
|
||||
("in", "SourceGraphic".to_owned()),
|
||||
("stdDeviation", std.to_owned()),
|
||||
("result", result.to_owned()),
|
||||
],
|
||||
Vec::new(),
|
||||
))
|
||||
};
|
||||
let inputs = [
|
||||
"haloWide",
|
||||
"haloWide",
|
||||
"haloWide",
|
||||
"haloTight",
|
||||
"haloTight",
|
||||
"SourceGraphic",
|
||||
];
|
||||
let merge = Element::svg(
|
||||
"feMerge",
|
||||
Vec::new(),
|
||||
inputs
|
||||
.iter()
|
||||
.map(|i| {
|
||||
Node::Element(Element::svg(
|
||||
"feMergeNode",
|
||||
vec![("in", (*i).to_owned())],
|
||||
Vec::new(),
|
||||
))
|
||||
})
|
||||
.collect(),
|
||||
);
|
||||
let attrs = vec![
|
||||
("id", HALO_FILTER_ID.to_owned()),
|
||||
("x", "-100%".to_owned()),
|
||||
("y", "-100%".to_owned()),
|
||||
("width", "300%".to_owned()),
|
||||
("height", "300%".to_owned()),
|
||||
("filterUnits", "userSpaceOnUse".to_owned()),
|
||||
];
|
||||
Element::svg(
|
||||
"filter",
|
||||
attrs,
|
||||
vec![
|
||||
blur("18", "haloWide"),
|
||||
blur("8", "haloTight"),
|
||||
Node::Element(merge),
|
||||
],
|
||||
)
|
||||
}
|
||||
|
||||
/// The layer carries document strings: refuse one XML cannot carry (never replace it).
|
||||
fn checked(layer: Element) -> Result<Element, ComposeError> {
|
||||
if xml_safe(&layer) {
|
||||
Ok(layer)
|
||||
} else {
|
||||
Err(ComposeError::InvalidCharacter)
|
||||
}
|
||||
}
|
||||
|
||||
fn xml_safe(element: &Element) -> bool {
|
||||
element.attrs.iter().all(|a| is_xml_text(&a.value))
|
||||
&& element.children.iter().all(|c| match c {
|
||||
Node::Element(e) => xml_safe(e),
|
||||
Node::Text(t) => is_xml_text(t),
|
||||
})
|
||||
}
|
||||
@@ -1,5 +1,6 @@
|
||||
//! The anatomy core (R3): SVG reading and sanitising, the annotation layer drawn from the
|
||||
//! sheet document, and the composition of a view (canvas and highlight).
|
||||
|
||||
pub mod compose;
|
||||
pub mod layer;
|
||||
pub mod svg;
|
||||
@@ -0,0 +1,145 @@
|
||||
//! R3 O1 + O3: the Rust compositions against the TypeScript trees frozen before the switch.
|
||||
//! O3 (`oracles/r3/highlight.json`, `packages/pdf/tests/r3.highlight-oracles.test.ts`): the
|
||||
//! engine's highlighted view for every observation and view of the three reference reports
|
||||
//! and an edge sheet. O1 (`apps/app/tests/fixtures/goldens/r3/canvas.*.json`,
|
||||
//! `apps/app/tests/unit/canvas.trees.test.ts`): the editor canvas of each view with no state,
|
||||
//! and its layer for every state set of the reference reports. Trees compared as structure,
|
||||
//! text nodes included; the Rust tree is the composition serialised and read again.
|
||||
#![allow(clippy::disallowed_methods, clippy::unwrap_used, clippy::expect_used)]
|
||||
|
||||
mod common;
|
||||
|
||||
use std::collections::HashSet;
|
||||
|
||||
use common::svg_tree::{reread, tree_value};
|
||||
use faunosteo_core::anatomy::compose::{asset_id_of_view, compose_canvas, compose_highlight};
|
||||
use faunosteo_core::anatomy::layer::render_layer;
|
||||
use faunosteo_core::anatomy::svg::{Element, read_svg};
|
||||
use faunosteo_core::domain::sheet::AnatomicalSheetDocument;
|
||||
use serde::Deserialize;
|
||||
use serde_json::{Value, json};
|
||||
|
||||
const HORSE: &str = "supabase/seed/anatomical-sheets/equine/draft/assets/horse.svg";
|
||||
|
||||
fn draft() -> AnatomicalSheetDocument {
|
||||
let (_, draft) = common::oracle_file("sheet.draft.json");
|
||||
AnatomicalSheetDocument::deserialize(&draft["output"]).unwrap()
|
||||
}
|
||||
|
||||
fn sanitized(text: &str) -> Element {
|
||||
read_svg(text).unwrap().root
|
||||
}
|
||||
|
||||
/// The frozen case's root rebuilt: root attributes, children before the asset, the asset's
|
||||
/// children (the shared sanitised tree, or the case's own), the layer.
|
||||
fn expected(case: &Value, oracle: &Value) -> Value {
|
||||
let mut children = case["before"].as_array().unwrap().clone();
|
||||
match &case["asset"] {
|
||||
Value::String(reference) => {
|
||||
let id = reference.strip_prefix("asset:").unwrap();
|
||||
children.extend(
|
||||
oracle["sanitized"][id]["children"]
|
||||
.as_array()
|
||||
.unwrap()
|
||||
.iter()
|
||||
.cloned(),
|
||||
);
|
||||
}
|
||||
own => children.extend(own.as_array().unwrap().iter().cloned()),
|
||||
}
|
||||
children.push(case["layer"].clone());
|
||||
let root = &case["root"];
|
||||
json!({ "ns": root["ns"], "name": root["name"], "attrs": root["attrs"], "children": children })
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn every_highlighted_view_equals_the_engine_tree() {
|
||||
let (_, oracle) = common::oracle_file("r3/highlight.json");
|
||||
let horse = sanitized(&common::repo_file(HORSE));
|
||||
let draft = draft();
|
||||
let edge = AnatomicalSheetDocument::deserialize(&oracle["edgeDocument"]).unwrap();
|
||||
let edge_assets = &oracle["edgeAssets"];
|
||||
let edge_main = sanitized(edge_assets["main"].as_str().unwrap());
|
||||
let edge_own = sanitized(edge_assets["own"].as_str().unwrap());
|
||||
let cases = oracle["cases"].as_array().unwrap();
|
||||
assert_eq!(cases.len(), 36);
|
||||
for case in cases {
|
||||
let view = case["viewId"].as_str().unwrap();
|
||||
let is_edge = case["sheet"] == "edge";
|
||||
let document = if is_edge { &edge } else { &draft };
|
||||
let asset_id = asset_id_of_view(document, view).unwrap();
|
||||
let asset = if !is_edge {
|
||||
horse.clone()
|
||||
} else if asset_id == edge_assets["ownAssetId"] {
|
||||
edge_own.clone()
|
||||
} else {
|
||||
edge_main.clone()
|
||||
};
|
||||
let ids: HashSet<&str> = case["observation"]["zones"]
|
||||
.as_array()
|
||||
.unwrap()
|
||||
.iter()
|
||||
.filter(|z| z["viewId"] == view)
|
||||
.map(|z| z["annotationId"].as_str().unwrap())
|
||||
.collect();
|
||||
let main = document
|
||||
.views
|
||||
.iter()
|
||||
.find(|v| v.id() == view)
|
||||
.unwrap()
|
||||
.is_main();
|
||||
let composed = compose_highlight(document, view, asset, &ids, main).unwrap();
|
||||
let label = format!("{} {} {view}", case["sheet"], case["observation"]["id"]);
|
||||
assert_eq!(reread(&composed), expected(case, &oracle), "{label}");
|
||||
}
|
||||
}
|
||||
|
||||
fn canvas_golden(name: &str) -> Value {
|
||||
let text = common::repo_file(&format!("apps/app/tests/fixtures/goldens/r3/{name}"));
|
||||
serde_json::from_str(&text).unwrap()
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn every_canvas_equals_the_frozen_tree_and_every_state_set_its_layer() {
|
||||
let horse = sanitized(&common::repo_file(HORSE));
|
||||
let draft = draft();
|
||||
for view in ["main", "head"] {
|
||||
let canvas = compose_canvas(&draft, view, &horse).unwrap();
|
||||
assert_eq!(
|
||||
reread(&canvas),
|
||||
canvas_golden(&format!("canvas.{view}.json")),
|
||||
"{view}"
|
||||
);
|
||||
let layers = canvas_golden(&format!("canvas.{view}.layers.json"));
|
||||
for (name, frozen) in layers.as_object().unwrap() {
|
||||
let states = frozen_states(frozen);
|
||||
let ids: HashSet<&str> = states.iter().map(String::as_str).collect();
|
||||
let layer = render_layer(&draft, view, &ids).unwrap();
|
||||
assert_eq!(tree_value(&layer), *frozen, "{view} {name}");
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/// The annotation ids a frozen layer marks `data-state="current"`.
|
||||
fn frozen_states(layer: &Value) -> Vec<String> {
|
||||
let mut ids = Vec::new();
|
||||
for child in layer["children"].as_array().unwrap() {
|
||||
let attrs = &child["attrs"];
|
||||
if attrs["data-state"] == "current" {
|
||||
ids.push(attrs["data-anno-id"].as_str().unwrap().to_owned());
|
||||
}
|
||||
}
|
||||
ids
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn a_label_xml_cannot_carry_is_refused_never_replaced() {
|
||||
let mut draft = draft();
|
||||
let horse = sanitized(&common::repo_file(HORSE));
|
||||
if let Some(faunosteo_core::domain::sheet::Annotation::Observable(a)) =
|
||||
draft.annotations.first_mut()
|
||||
{
|
||||
a.name.en = "bad\u{1}name".to_owned();
|
||||
}
|
||||
assert!(compose_canvas(&draft, "main", &horse).is_err());
|
||||
}
|
||||
@@ -6,6 +6,8 @@
|
||||
clippy::expect_used
|
||||
)]
|
||||
|
||||
pub mod svg_tree;
|
||||
|
||||
use faunosteo_core::domain::js::{find_lone_surrogate, parse_json};
|
||||
use serde_json::Value;
|
||||
|
||||
|
||||
@@ -0,0 +1,37 @@
|
||||
//! SVG trees as structure for the R3 oracles: namespace, local name, attributes by qualified
|
||||
//! name (sorted), children with text, the shape the TypeScript generators freeze.
|
||||
#![allow(dead_code, clippy::unwrap_used)]
|
||||
|
||||
use std::collections::BTreeMap;
|
||||
|
||||
use faunosteo_core::anatomy::svg::serialize::serialize;
|
||||
use faunosteo_core::anatomy::svg::tree::{SVG_NS, parse_svg};
|
||||
use faunosteo_core::anatomy::svg::{Element, Node};
|
||||
use serde_json::{Value, json};
|
||||
|
||||
pub fn tree_value(element: &Element) -> Value {
|
||||
let attrs: BTreeMap<&str, &str> = element
|
||||
.attrs
|
||||
.iter()
|
||||
.map(|a| (a.qname.as_str(), a.value.as_str()))
|
||||
.collect();
|
||||
let children: Vec<Value> = element
|
||||
.children
|
||||
.iter()
|
||||
.map(|n| match n {
|
||||
Node::Element(e) => tree_value(e),
|
||||
Node::Text(t) => json!({ "text": t }),
|
||||
})
|
||||
.collect();
|
||||
json!({
|
||||
"ns": element.namespace.as_deref().unwrap_or(SVG_NS),
|
||||
"name": element.local_name(),
|
||||
"attrs": attrs,
|
||||
"children": children,
|
||||
})
|
||||
}
|
||||
|
||||
/// The element serialised and read again by the core, as a tree.
|
||||
pub fn reread(element: &Element) -> Value {
|
||||
tree_value(&parse_svg(&serialize(element)).unwrap())
|
||||
}
|
||||
@@ -4,6 +4,458 @@
|
||||
"own": "<svg xmlns=\"http://www.w3.org/2000/svg\" width=\"50\" height=\"50\"><circle cx=\"5\" cy=\"5\" r=\"2\"/></svg>",
|
||||
"ownAssetId": "9d0e5f3a-1b2c-4d5e-8f90-a1b2c3d4e5f6"
|
||||
},
|
||||
"edgeDocument": {
|
||||
"schema_version": 2,
|
||||
"species_id": "equine",
|
||||
"name": {
|
||||
"fr": "Mini",
|
||||
"en": "Mini"
|
||||
},
|
||||
"description": {},
|
||||
"scope_disclaimer": {},
|
||||
"attribution": {
|
||||
"authors": [],
|
||||
"license": null,
|
||||
"notes": null
|
||||
},
|
||||
"vertebral_config": {
|
||||
"regions": [
|
||||
{
|
||||
"code": "C",
|
||||
"name": {
|
||||
"fr": "Cervicales",
|
||||
"en": "Cervical"
|
||||
},
|
||||
"count": 7,
|
||||
"count_range": null
|
||||
},
|
||||
{
|
||||
"code": "T",
|
||||
"name": {
|
||||
"fr": "Thoraciques",
|
||||
"en": "Thoracic"
|
||||
},
|
||||
"count": 18,
|
||||
"count_range": null
|
||||
}
|
||||
]
|
||||
},
|
||||
"references": [],
|
||||
"categories": [
|
||||
{
|
||||
"id": "joints",
|
||||
"name": {
|
||||
"fr": "Articulations",
|
||||
"en": "Joints"
|
||||
},
|
||||
"color": "#ff9500"
|
||||
},
|
||||
{
|
||||
"id": "bones",
|
||||
"name": {
|
||||
"fr": "Os",
|
||||
"en": "Bones"
|
||||
},
|
||||
"color": null
|
||||
}
|
||||
],
|
||||
"views": [
|
||||
{
|
||||
"id": "main",
|
||||
"name": {
|
||||
"fr": "Vue",
|
||||
"en": "View"
|
||||
},
|
||||
"svg_asset_id": "3f6c1b52-8a4e-4d17-9b0c-5e2a7d91c4f8",
|
||||
"view_box": null,
|
||||
"kind": "main"
|
||||
},
|
||||
{
|
||||
"id": "head",
|
||||
"name": {
|
||||
"fr": "Tête",
|
||||
"en": "Head"
|
||||
},
|
||||
"svg_asset_id": null,
|
||||
"view_box": {
|
||||
"min_x": 0,
|
||||
"min_y": 0,
|
||||
"width": 10,
|
||||
"height": 10
|
||||
},
|
||||
"kind": "detail",
|
||||
"parent_view_id": "main"
|
||||
},
|
||||
{
|
||||
"id": "detail-own",
|
||||
"kind": "detail",
|
||||
"parent_view_id": "main",
|
||||
"name": {
|
||||
"fr": "Détail",
|
||||
"en": "Detail"
|
||||
},
|
||||
"svg_asset_id": "9d0e5f3a-1b2c-4d5e-8f90-a1b2c3d4e5f6",
|
||||
"view_box": null
|
||||
}
|
||||
],
|
||||
"annotations": [
|
||||
{
|
||||
"id": "hip",
|
||||
"view_id": "main",
|
||||
"category_id": "joints",
|
||||
"laterality": "bilateral",
|
||||
"geometry": {
|
||||
"type": "circle",
|
||||
"cx": 1,
|
||||
"cy": 2,
|
||||
"r": 3
|
||||
},
|
||||
"review_status": "inherited",
|
||||
"color": null,
|
||||
"name": {
|
||||
"fr": "Hanche",
|
||||
"en": "Hip"
|
||||
},
|
||||
"finding_zone_id": "hip",
|
||||
"vertebral_region_code": null,
|
||||
"kind": "point"
|
||||
},
|
||||
{
|
||||
"id": "neck",
|
||||
"view_id": "main",
|
||||
"category_id": "bones",
|
||||
"laterality": "unpaired",
|
||||
"geometry": null,
|
||||
"review_status": "inherited",
|
||||
"color": null,
|
||||
"name": {
|
||||
"fr": "Cou",
|
||||
"en": "Neck"
|
||||
},
|
||||
"finding_zone_id": "neck",
|
||||
"vertebral_region_code": "C",
|
||||
"kind": "zone"
|
||||
},
|
||||
{
|
||||
"id": "head-trigger",
|
||||
"view_id": "main",
|
||||
"category_id": "bones",
|
||||
"laterality": "unpaired",
|
||||
"geometry": null,
|
||||
"review_status": "inherited",
|
||||
"color": null,
|
||||
"kind": "detail_trigger",
|
||||
"name": null,
|
||||
"opens_view_id": "head"
|
||||
},
|
||||
{
|
||||
"id": "point-polygon",
|
||||
"view_id": "main",
|
||||
"category_id": "joints",
|
||||
"laterality": "left",
|
||||
"geometry": {
|
||||
"type": "polygon",
|
||||
"points": [
|
||||
[
|
||||
0.1,
|
||||
0.2
|
||||
],
|
||||
[
|
||||
1.5e-7,
|
||||
3
|
||||
],
|
||||
[
|
||||
2,
|
||||
1e+21
|
||||
]
|
||||
]
|
||||
},
|
||||
"review_status": "inherited",
|
||||
"color": null,
|
||||
"name": {
|
||||
"fr": "Polygone « point »",
|
||||
"en": "Point & <polygon>"
|
||||
},
|
||||
"finding_zone_id": "hip",
|
||||
"vertebral_region_code": null,
|
||||
"kind": "point"
|
||||
},
|
||||
{
|
||||
"id": "zone-circle",
|
||||
"view_id": "main",
|
||||
"category_id": "joints",
|
||||
"laterality": "right",
|
||||
"geometry": {
|
||||
"type": "circle",
|
||||
"cx": 743.0451049804688,
|
||||
"cy": 0.30000000000000004,
|
||||
"r": 12.5
|
||||
},
|
||||
"review_status": "inherited",
|
||||
"color": "#123456",
|
||||
"name": {
|
||||
"fr": "Zone ronde",
|
||||
"en": "Round zone"
|
||||
},
|
||||
"finding_zone_id": "hip",
|
||||
"vertebral_region_code": null,
|
||||
"kind": "zone"
|
||||
},
|
||||
{
|
||||
"id": "zone-path",
|
||||
"view_id": "main",
|
||||
"category_id": "bones",
|
||||
"laterality": "unpaired",
|
||||
"geometry": {
|
||||
"type": "path",
|
||||
"d": "M0 0 L10 10 Z"
|
||||
},
|
||||
"review_status": "inherited",
|
||||
"color": null,
|
||||
"name": {
|
||||
"fr": "Chemin",
|
||||
"en": "Path"
|
||||
},
|
||||
"finding_zone_id": null,
|
||||
"vertebral_region_code": "T",
|
||||
"kind": "zone"
|
||||
},
|
||||
{
|
||||
"id": "trigger-circle",
|
||||
"view_id": "main",
|
||||
"category_id": "missing-category",
|
||||
"laterality": "unpaired",
|
||||
"geometry": {
|
||||
"type": "circle",
|
||||
"cx": 5,
|
||||
"cy": 5,
|
||||
"r": 40
|
||||
},
|
||||
"review_status": "inherited",
|
||||
"color": null,
|
||||
"kind": "detail_trigger",
|
||||
"name": null,
|
||||
"opens_view_id": "head"
|
||||
},
|
||||
{
|
||||
"id": "trigger-named",
|
||||
"view_id": "main",
|
||||
"category_id": "bones",
|
||||
"laterality": "unpaired",
|
||||
"geometry": {
|
||||
"type": "polygon",
|
||||
"points": [
|
||||
[
|
||||
0,
|
||||
0
|
||||
],
|
||||
[
|
||||
1,
|
||||
0
|
||||
],
|
||||
[
|
||||
1,
|
||||
1
|
||||
]
|
||||
]
|
||||
},
|
||||
"review_status": "inherited",
|
||||
"color": null,
|
||||
"kind": "detail_trigger",
|
||||
"name": {
|
||||
"fr": "Ouvrir",
|
||||
"en": "Open"
|
||||
},
|
||||
"opens_view_id": "head"
|
||||
},
|
||||
{
|
||||
"id": "head-point",
|
||||
"view_id": "head",
|
||||
"category_id": "joints",
|
||||
"laterality": "bilateral",
|
||||
"geometry": {
|
||||
"type": "circle",
|
||||
"cx": 1,
|
||||
"cy": 1,
|
||||
"r": 27.5
|
||||
},
|
||||
"review_status": "inherited",
|
||||
"color": null,
|
||||
"name": {
|
||||
"fr": "Tête",
|
||||
"en": "Head"
|
||||
},
|
||||
"finding_zone_id": "hip",
|
||||
"vertebral_region_code": null,
|
||||
"kind": "point"
|
||||
},
|
||||
{
|
||||
"id": "own-point",
|
||||
"kind": "point",
|
||||
"view_id": "detail-own",
|
||||
"category_id": "joints",
|
||||
"laterality": "unpaired",
|
||||
"geometry": {
|
||||
"type": "circle",
|
||||
"cx": 5,
|
||||
"cy": 5,
|
||||
"r": 20
|
||||
},
|
||||
"review_status": "inherited",
|
||||
"color": null,
|
||||
"name": {
|
||||
"fr": "Point",
|
||||
"en": "Point"
|
||||
},
|
||||
"finding_zone_id": "hip",
|
||||
"vertebral_region_code": null
|
||||
}
|
||||
],
|
||||
"finding_zones": [
|
||||
{
|
||||
"id": "hip",
|
||||
"name": {
|
||||
"fr": "Hanche",
|
||||
"en": "Hip"
|
||||
},
|
||||
"categories": [
|
||||
{
|
||||
"id": "hip-dysfunctions",
|
||||
"kind": "dysfunction",
|
||||
"name": {
|
||||
"fr": "Dysfonctions",
|
||||
"en": "Dysfunctions"
|
||||
},
|
||||
"description": {},
|
||||
"reference_ids": [],
|
||||
"review_status": "inherited",
|
||||
"children": [
|
||||
{
|
||||
"id": "mobility",
|
||||
"name": {
|
||||
"fr": "mobility fr",
|
||||
"en": "mobility en"
|
||||
},
|
||||
"description": {},
|
||||
"requires_vet_referral": false,
|
||||
"reference_ids": [],
|
||||
"review_status": "inherited",
|
||||
"children": [
|
||||
{
|
||||
"id": "flexion",
|
||||
"name": {
|
||||
"fr": "flexion fr",
|
||||
"en": "flexion en"
|
||||
},
|
||||
"description": {},
|
||||
"requires_vet_referral": false,
|
||||
"reference_ids": [],
|
||||
"review_status": "inherited",
|
||||
"children": []
|
||||
},
|
||||
{
|
||||
"id": "extension",
|
||||
"name": {
|
||||
"fr": "extension fr",
|
||||
"en": "extension en"
|
||||
},
|
||||
"description": {},
|
||||
"requires_vet_referral": false,
|
||||
"reference_ids": [],
|
||||
"review_status": "inherited",
|
||||
"children": []
|
||||
}
|
||||
]
|
||||
},
|
||||
{
|
||||
"id": "pain",
|
||||
"name": {
|
||||
"fr": "pain fr",
|
||||
"en": "pain en"
|
||||
},
|
||||
"description": {},
|
||||
"requires_vet_referral": false,
|
||||
"reference_ids": [],
|
||||
"review_status": "inherited",
|
||||
"children": []
|
||||
}
|
||||
]
|
||||
},
|
||||
{
|
||||
"id": "anamnesis",
|
||||
"kind": "anamnesis",
|
||||
"name": {
|
||||
"fr": "Anamnèse",
|
||||
"en": "Anamnesis"
|
||||
},
|
||||
"description": {},
|
||||
"reference_ids": [],
|
||||
"review_status": "inherited",
|
||||
"children": [
|
||||
{
|
||||
"id": "trauma",
|
||||
"name": {
|
||||
"fr": "trauma fr",
|
||||
"en": "trauma en"
|
||||
},
|
||||
"description": {},
|
||||
"requires_vet_referral": false,
|
||||
"reference_ids": [],
|
||||
"review_status": "inherited",
|
||||
"children": []
|
||||
}
|
||||
]
|
||||
}
|
||||
]
|
||||
},
|
||||
{
|
||||
"id": "neck",
|
||||
"name": {
|
||||
"fr": "Cou",
|
||||
"en": "Neck"
|
||||
},
|
||||
"categories": [
|
||||
{
|
||||
"id": "neck-dysfunctions",
|
||||
"kind": "dysfunction",
|
||||
"name": {
|
||||
"fr": "Dysfonctions",
|
||||
"en": "Dysfunctions"
|
||||
},
|
||||
"description": {},
|
||||
"reference_ids": [],
|
||||
"review_status": "inherited",
|
||||
"children": [
|
||||
{
|
||||
"id": "stiffness",
|
||||
"name": {
|
||||
"fr": "stiffness fr",
|
||||
"en": "stiffness en"
|
||||
},
|
||||
"description": {},
|
||||
"requires_vet_referral": false,
|
||||
"reference_ids": [],
|
||||
"review_status": "inherited",
|
||||
"children": []
|
||||
},
|
||||
{
|
||||
"id": "vet",
|
||||
"name": {
|
||||
"fr": "vet fr",
|
||||
"en": "vet en"
|
||||
},
|
||||
"description": {},
|
||||
"requires_vet_referral": true,
|
||||
"reference_ids": [],
|
||||
"review_status": "inherited",
|
||||
"children": []
|
||||
}
|
||||
]
|
||||
}
|
||||
]
|
||||
}
|
||||
]
|
||||
},
|
||||
"sanitized": {
|
||||
"7f767f74-3b36-51a7-8465-52dd7e2ead4a": {
|
||||
"ns": "http://www.w3.org/2000/svg",
|
||||
|
||||
@@ -13,12 +13,10 @@
|
||||
|
||||
mod common;
|
||||
|
||||
use std::collections::BTreeMap;
|
||||
|
||||
use common::svg_tree::reread;
|
||||
use faunosteo_core::anatomy::svg::sanitize::is_reference_name;
|
||||
use faunosteo_core::anatomy::svg::serialize::serialize;
|
||||
use faunosteo_core::anatomy::svg::tree::{SVG_NS, parse_svg};
|
||||
use faunosteo_core::anatomy::svg::{Element, Node, SvgRejection, read_svg};
|
||||
use faunosteo_core::anatomy::svg::tree::SVG_NS;
|
||||
use faunosteo_core::anatomy::svg::{SvgRejection, read_svg};
|
||||
use serde_json::{Value, json};
|
||||
|
||||
/// Rust outcomes that differ from the TS on purpose: file → expected Rust verdict.
|
||||
@@ -53,28 +51,6 @@ fn declared_spec(spec: &Value) -> Option<&'static str> {
|
||||
}
|
||||
}
|
||||
|
||||
fn tree_value(element: &Element) -> Value {
|
||||
let attrs: BTreeMap<&str, &str> = element
|
||||
.attrs
|
||||
.iter()
|
||||
.map(|a| (a.qname.as_str(), a.value.as_str()))
|
||||
.collect();
|
||||
let children: Vec<Value> = element
|
||||
.children
|
||||
.iter()
|
||||
.map(|n| match n {
|
||||
Node::Element(e) => tree_value(e),
|
||||
Node::Text(t) => json!({ "text": t }),
|
||||
})
|
||||
.collect();
|
||||
json!({
|
||||
"ns": element.namespace.as_deref().unwrap_or(SVG_NS),
|
||||
"name": element.local_name(),
|
||||
"attrs": attrs,
|
||||
"children": children,
|
||||
})
|
||||
}
|
||||
|
||||
/// Removes the named attribute from every element of that local name (a declared removal).
|
||||
fn strip(tree: &mut Value, element: &str, attribute: &str) {
|
||||
if tree["name"] == element
|
||||
@@ -89,11 +65,6 @@ fn strip(tree: &mut Value, element: &str, attribute: &str) {
|
||||
}
|
||||
}
|
||||
|
||||
/// The Rust output read again, as a tree.
|
||||
fn reread(element: &Element) -> Value {
|
||||
tree_value(&parse_svg(&serialize(element)).unwrap())
|
||||
}
|
||||
|
||||
fn is_space(text: &str) -> bool {
|
||||
text.chars().all(|c| matches!(c, ' ' | '\t' | '\n' | '\r'))
|
||||
}
|
||||
|
||||
@@ -182,7 +182,12 @@ function build() {
|
||||
cases.push(highlightCase('edge', edge, obs, viewId, sanitized))
|
||||
}
|
||||
}
|
||||
return { edgeAssets: { main: EDGE_MAIN, own: EDGE_OWN, ownAssetId: OWN_ASSET }, sanitized, cases }
|
||||
return {
|
||||
edgeAssets: { main: EDGE_MAIN, own: EDGE_OWN, ownAssetId: OWN_ASSET },
|
||||
edgeDocument: edge.document,
|
||||
sanitized,
|
||||
cases,
|
||||
}
|
||||
}
|
||||
|
||||
describe('R3 highlight oracles (TypeScript freeze)', () => {
|
||||
|
||||
Reference in new issue
Block a user