mirror of
https://github.com/bherbruck/solidcraft.git
synced 2026-11-15 21:20:54 +00:00
dc38349cbf
* Kernel: the B-rep record and the native body file come from solidcore-record
SolidCraft's portable B-rep record (`solidcraft_geom::brep`: brep.rs, topology, history,
envelope, part, curve2) and the native body file (`solidcraft_kernel::native`: the tagged binary
codec and the container) move to solidcore's `solidcore-record` crate: geometry as data, with
structural validation and no maths (solidcore's docs/layers.md, stage 1). Every caller uses
`solidcore_record::brep` and `solidcore_record::native`; the old copies are deleted.
What computes from coordinates stays with the kernel, in geom's `brep`:
- `brep::check`: the record's geometric checks (orthonormal frames, non-degenerate planes,
unit revolution axes, non-singular placements). `check::validate` and
`check::validate_built` are the record's validation and these together, and every caller of
`Brep::validate` uses them, so what is accepted is unchanged;
- `brep::label`: a surface's natural ranges (a cone's apex), `curve_interval`,
`edge_curve_interval` and `form_turns`;
- `brep::pcurve::eval`: a pcurve's point;
- `geometry::check`, `placement::moved` and `split_edges` become functions on the record.
The kernel's native module keeps the conversion between a body and its saved record
(metadata.rs) and checks the decoded record's geometry. `native/analytic.rs`, which no module
declared, is deleted.
solidcore-record is pinned to its rev on solidcore's `layer-record` branch.
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01NvoxKMbMFSQU8tzRtoJhtT
* Geometry: Vec2, Vec3, Plane and the profile types come from solidcore-record
The plain data of vectors and points, sketch planes and planar profiles (`Seg2`, `Loop2`,
`Region2`) moves to `solidcore-record`, with its constants and component-wise operators only
(owner decision, solidcore layer split). Their geometry stays in geom as traits:
`Vec2Geom`, `Vec3Geom`, `PlaneGeom`, `Seg2Geom`, `Loop2Geom`, `Region2Geom`, `Seg2ArcFit`,
`Loop2ArcFit` and `Region2ArcFit`, in scope with `use solidcraft_geom::prelude::*`. Every caller
names the types from `solidcore_record`; geom no longer defines or re-exports them.
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01NvoxKMbMFSQU8tzRtoJhtT
* Kernel: pin solidcore-record to solidcore main f5e8e9a29
solidcore-record is merged on solidcore main (tangency-labs/solidcore#2519); its crate there is
identical to the rev pinned before but for its clippy configuration. The lock is regenerated
against the merged rev.
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01NvoxKMbMFSQU8tzRtoJhtT
---------
Co-authored-by: jyviko <2501648+jyviko@users.noreply.github.com>
Co-authored-by: Claude Opus 5.5 <noreply@anthropic.com>
117 lines
5.1 KiB
Rust
117 lines
5.1 KiB
Rust
//! Engine time for live frames and release, independent of rendering/input scheduling.
|
|
use std::{error::Error, io::Write, path::PathBuf, sync::Arc, time::Instant};
|
|
|
|
use serde_json::{Value, json};
|
|
use solidcore_record::Vec2;
|
|
use solidcraft_engine::Session;
|
|
use solidcraft_sketch::{Analysis, ConstraintKind, Hold, Sketch, profiling::capture, solve_with};
|
|
|
|
type Result<T> = std::result::Result<T, Box<dyn Error>>;
|
|
|
|
fn prepare(size: usize, pinned: bool, cold: bool) -> Result<Session> {
|
|
let mut s = Session::default();
|
|
s.execute("sketch.create", &json!({"plane": "XY"}))?;
|
|
let id = s.active_sketch.ok_or("missing sketch")?;
|
|
let mut sk = Sketch::new();
|
|
let mut points = Vec::new();
|
|
let mut seed = 99u64;
|
|
let mut jitter = || {
|
|
seed = seed.wrapping_mul(6364136223846793005).wrapping_add(1442695040888963407);
|
|
(seed >> 11) as f64 / (1u64 << 53) as f64 * 2.0 - 1.0
|
|
};
|
|
for y in 0..size {
|
|
for x in 0..size {
|
|
let p = sk.add_point(Vec2::new((x + 1) as f64 * 10.0 + jitter(), (y + 1) as f64 * 10.0 + jitter()), None)?;
|
|
points.push(p);
|
|
if pinned && x == 0 && y == 0 {
|
|
sk.add_constraint(ConstraintKind::Fix { p }, None)?;
|
|
}
|
|
for (other, horizontal) in [((x > 0).then(|| points.len() - 2), true), ((y > 0).then(|| points.len() - 1 - size), false)] {
|
|
if let Some(q) = other.and_then(|i| points.get(i)).copied() {
|
|
let l = sk.add_line_pts(q, p, None)?;
|
|
sk.add_constraint(if horizontal { ConstraintKind::Horizontal { l } } else { ConstraintKind::Vertical { l } }, None)?;
|
|
sk.add_constraint(ConstraintKind::Distance { p, q, value: 10.0 }, None)?;
|
|
}
|
|
}
|
|
}
|
|
}
|
|
if !solve_with(&mut sk, &Hold::default(), None, Analysis::StatusOnly, None).ok() {
|
|
return Err("grid preparation failed".into());
|
|
}
|
|
*Arc::make_mut(&mut s.doc).sketch_mut(id)? = sk;
|
|
if cold {
|
|
s.model = Default::default();
|
|
} else {
|
|
s.refresh();
|
|
}
|
|
Ok(s)
|
|
}
|
|
|
|
fn frame(s: &mut Session) -> Result<Value> {
|
|
let id = s.active_sketch.ok_or("missing sketch")?;
|
|
let sk = s.doc.sketch(id)?;
|
|
let p = sk.points.get(1).ok_or("missing point")?;
|
|
let params = json!({"entity": p.id, "from": [p.pos.x, p.pos.y], "to": [p.pos.x + 0.25, p.pos.y], "live": true});
|
|
Ok(s.execute("sketch.drag", ¶ms)?)
|
|
}
|
|
|
|
fn main() -> Result<()> {
|
|
let mut size = 14usize;
|
|
let mut repeats = 10usize;
|
|
let mut out: Option<PathBuf> = None;
|
|
let mut args = std::env::args().skip(1);
|
|
while let Some(key) = args.next() {
|
|
let value = args.next().ok_or("missing option value")?;
|
|
match key.as_str() {
|
|
"--size" => size = value.parse()?,
|
|
"--repeats" => repeats = value.parse()?,
|
|
"--out" => out = Some(value.into()),
|
|
_ => return Err(format!("unknown option {key}").into()),
|
|
}
|
|
}
|
|
// The floating variant must stay within the solver's 400-variable redundancy cap so
|
|
// that this benchmark can require and compare nonempty published diagnostics.
|
|
if !(2..=14).contains(&size) || !(1..=100).contains(&repeats) {
|
|
return Err("size must be in 2..14 and repeats in 1..100".into());
|
|
}
|
|
let mut cases = Vec::new();
|
|
for (name, pinned, cold, release) in [
|
|
("live-floating", false, false, false),
|
|
("live-pinned", true, false, false),
|
|
("release-floating", false, false, true),
|
|
("first-frame", false, true, false),
|
|
] {
|
|
let mut samples = Vec::new();
|
|
for i in 0..repeats + 2 {
|
|
let mut s = prepare(size, pinned, cold)?;
|
|
if release {
|
|
frame(&mut s)?;
|
|
}
|
|
let start = Instant::now();
|
|
let (response, profile) = capture(|| if release { s.execute("sketch.drag_end", &json!({})).map_err(Into::into) } else { frame(&mut s) });
|
|
let elapsed_ns = start.elapsed().as_nanos().min(u64::MAX as u128) as u64;
|
|
let response: Value = response?;
|
|
let id = s.active_sketch.ok_or("missing sketch")?;
|
|
let state = s.world_state();
|
|
let report = &state.sketch(id).ok_or("missing published sketch")?.report;
|
|
if !report.ok() || report.redundant.is_empty() {
|
|
return Err(format!("{name}: missing full diagnostics: {report:?}; response {response}; counters {:?}", profile.counters).into());
|
|
}
|
|
if i >= 2 {
|
|
samples
|
|
.push(json!({"elapsed_ns": elapsed_ns, "response": response, "profile": profile, "report": report, "sketch": s.doc.sketch(id)?}));
|
|
}
|
|
}
|
|
cases.push(json!({"case": name, "samples": samples}));
|
|
}
|
|
let output = json!({"schema": "solidcraft/sketch-drag-bench/1", "size": size, "seed": 99, "repeats": repeats, "warmup": 2, "cases": cases});
|
|
let mut writer: Box<dyn Write> = match out {
|
|
Some(path) => Box::new(std::io::BufWriter::new(std::fs::File::create(path)?)),
|
|
None => Box::new(std::io::stdout().lock()),
|
|
};
|
|
serde_json::to_writer_pretty(&mut writer, &output)?;
|
|
writeln!(writer)?;
|
|
writer.flush()?;
|
|
Ok(())
|
|
}
|