mirror of
https://github.com/storytold/vectorcraft.git
synced 2026-11-26 08:26:04 +00:00
Merge pull request #9031 from MMexicann/patch-5
Allow a linked vertex to define an angular dimension
This commit is contained in:
@@ -88,11 +88,13 @@ fn recipe(s: &Session, p: &Value) -> Result<Dimension> {
|
||||
}
|
||||
let a = if source.is_none() || p.get("a").is_some() { point(p, "a")? } else { Point::ZERO };
|
||||
let b = if source.is_none() || p.get("b").is_some() { point(p, "b")? } else { Point::new(1.0, 0.0) };
|
||||
let vertex = if mode == DimensionMode::Angular && (source.is_none() || matches!(source, Some(DimensionSource::Points { .. }))) {
|
||||
point(p, "vertex")?
|
||||
} else {
|
||||
Point::ZERO
|
||||
// Resolution supplies a linked vertex. An explicit coordinate is still checked when given.
|
||||
let read_vertex = match &source {
|
||||
None => true,
|
||||
Some(DimensionSource::Points { vertex, .. }) => vertex.is_none() || p.get("vertex").is_some(),
|
||||
_ => false,
|
||||
};
|
||||
let vertex = if mode == DimensionMode::Angular && read_vertex { point(p, "vertex")? } else { Point::ZERO };
|
||||
let orientation = orientation(p, mode)?.unwrap_or_default();
|
||||
let mut d = Dimension {
|
||||
mode,
|
||||
|
||||
@@ -225,6 +225,28 @@ fn dimension_angles_circles_arcs_and_curves() {
|
||||
assert_eq!(text(&s, id), "100 pt");
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn an_angular_dimension_can_take_its_vertex_from_an_anchor() {
|
||||
let mut s = session();
|
||||
let line = edge(&mut s);
|
||||
let request = json!({
|
||||
"mode": "angular", "a": [172, 100], "b": [100, 172], "options": {"precision": 1},
|
||||
"source": {"kind": "points", "vertex": {"node": line, "subpath": 0, "anchor": 0}}
|
||||
});
|
||||
let id = run(&mut s, "dimension.create", request.clone())["id"].as_u64().unwrap();
|
||||
assert_eq!(text(&s, id), "90.0°");
|
||||
run(&mut s, "select.set", json!({"ids": [line]}));
|
||||
run(&mut s, "object.move", json!({"dx": 18, "dy": 0}));
|
||||
assert!(near(recipe(&s, id).vertex, vectorcraft_geom::Point::new(118.0, 100.0)));
|
||||
|
||||
let mut invalid = request.clone();
|
||||
invalid["vertex"] = json!("bad point");
|
||||
assert!(s.execute("dimension.create", &invalid).is_err());
|
||||
let mut missing = request;
|
||||
missing["source"]["vertex"] = Value::Null;
|
||||
assert!(s.execute("dimension.create", &missing).is_err());
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn dimension_rejects_bad_input_without_mutation() {
|
||||
let mut s = session();
|
||||
|
||||
Reference in New Issue
Block a user