discontinuedPackage jet_cad_floor_plan has been discontinued and replaced by jet_cad_2d_plan.

offsetFor function

double offsetFor(
  1. Vector2 q,
  2. Vector2 p0,
  3. Vector2 p1,
  4. DimKind kind,
  5. Transform2 m,
)

The placement function (spec 11 D6, R-7): the offset, in the group's local units, that puts a dimension of kind from world p0 to world p1 in a group whose local-to-world transform is m through world point q. With u = measuringDirection, n its left normal, the heights h0 = 0 and h1 (0 for aligned by definition, (p1 − p0) · n for a linear kind), hi/lo their max and min, hq = (q − p0) · n and s = m.scaleMagnitude:

  1. hq ≥ hi: (hq − hi) / s, from the upper extreme (+0.0 on it);
  2. hq ≤ lo: −((lo − hq) / s), from the lower one (-0.0 on it);
  3. between (a linear kind only): the nearer extreme with a zero offset, +0.0 when hi − hq ≤ hq − lo, else -0.0.

The side is the result's sign bit (R-2), which layoutDimension reads. The tool's third click and the offset grip both place the line with it (the plan's Ruling 11-3).

Implementation

double offsetFor(
    Vector2 q, Vector2 p0, Vector2 p1, DimKind kind, Transform2 m) {
  final u = measuringDirection(kind, p0, p1, m);
  final n = Vector2(-u.y, u.x);
  final h1 = kind == DimKind.aligned ? 0.0 : (p1 - p0).dot(n);
  final hi = math.max(0.0, h1), lo = math.min(0.0, h1);
  final hq = (q - p0).dot(n);
  final s = m.scaleMagnitude;
  if (hq >= hi) return (hq - hi) / s;
  if (hq <= lo) return -((lo - hq) / s);
  return hi - hq <= hq - lo ? 0.0 : -0.0;
}