dymokomi/luced-3d
Source of release 0.11.9
0.11.9 / src / check_labels.luc
## A Check node's edge labels on the model, as Alias labels its continuity
## check: at each checked edge's middle the order it reached (G0 to G3) and
## the measure that decided it, in the edge's color (green it meets the
## order asked for, yellow one short, red further). luce-cad's CheckLabel
## crosses from the cook (or the worker) as two point pairs a label
## (overlay_lines.lucb's check_label_pairs); `read` makes them text.
from luce_3d.graphics import Vector3
from luce_ui.ui import Painter, Point, Rect
from overlay_lines import OverlayLines
import theme
pub class EdgeLabel:
## Where the label points (world space), what it reads, and its line
## group (luce-cad's check_passed, check_near, check_failed).
pub let at: Vector3
pub let text: str
pub let group: int
pub func init(self, at: Vector3, text: str, group: int):
self.at = at
self.text = text
self.group = group
## The labels `pairs` holds.
pub func read(pairs: OverlayLines) -> list[EdgeLabel]!:
let result: list[EdgeLabel] = []
for k in 0..<pairs.count() // 2:
let measured = pairs.point(k * 4 + 1)
result.append(EdgeLabel(pairs.point(k * 4), text_of(int(measured.x), int(measured.y), measured.z), int(pairs.point(k * 4 + 2).x)))
return result
## "G2 0.01%": the order reached (or "G0 ×" when even the gap is too wide)
## and the measure of order `order`, in its unit: a gap in model units, an
## angle in degrees, curvature and rate differences in percent.
pub func text_of(level: int, order: int, value: float) -> str:
let reached = "G0 ×" if level < 0 else f"G{level}"
if order == 0:
return f"{reached} gap {value:.4f}"
if order == 1:
return f"{reached} {value:.2f}°"
return f"{reached} {"κ" if order == 2 else "κ'"} {value:.2f}%"
## Draw `labels` over the viewport, each where `place` puts its point on
## screen (x, y and the depth before the near plane): a dot on its edge
## and, up and to the right of it, its text on a dark plate edged in its
## color. Labels behind the camera are skipped.
pub func draw(p: Painter, labels: list[EdgeLabel], place: func(Vector3) -> list[float]!) -> unit!:
for label in labels:
let s = place(label.at)
if s[2] <= 0.0:
continue
let color = theme.check_group(label.group)
let box = Rect(s[0] + 10.0, s[1] - 30.0, float(label.text.length) * 7.5 + 12.0, 20.0)
p.line(Point(s[0], s[1]), Point(box.x, box.y + box.height), 1.0, color)
p.rounded_rectangle(Rect(s[0] - 3.0, s[1] - 3.0, 6.0, 6.0), color, 3.0)
p.rounded_rectangle(Rect(box.x - 1.0, box.y - 1.0, box.width + 2.0, box.height + 2.0), color, 4.0)
p.rounded_rectangle(box, theme.grey(24.0), 3.0)
p.text(label.text, box.x + 6.0, box.y + 3.0, color)