/// <inheritdoc /> public override void Register(CircuitContext context, IDiagnosticHandler diagnostics) { if (Fix) { RegisterFixed(context, diagnostics); return; } var map = context.Nodes.Shorts; var ckt = context.Circuit; string x = map[X]; string ox = map[_origin.X]; string y = map[Y]; string oy = map[_origin.Y]; var direction = _origin is ITransformingDrawable tfd?tfd.TransformNormal(Direction) : Direction; direction = direction.Order(ref ox, ref x, ref oy, ref y); // If we only work along one axis, we can simplify the schematic if (x == ox) { MinimumConstraint.AddMinimum(ckt, Y, oy, y, MinimumOffset); return; } if (y == oy) { MinimumConstraint.AddMinimum(ckt, X, ox, x, MinimumOffset); return; } // General case, both X and Y are different AddControlledMinimum(ckt, $"{Owner.Name}[{Name}]", ox, x, oy, y, direction); MinimumConstraint.AddMinimum(ckt, $"{Owner.Name}[{Name}].min.x", ox, x, direction.X * MinimumOffset); MinimumConstraint.AddMinimum(ckt, $"{Owner.Name}[{Name}].min.y", oy, y, direction.Y * MinimumOffset); }
private static void AddControlledMinimum(IEntityCollection ckt, string name, string lowX, string highX, string lowY, string highY, Vector2 direction) { string i = $"{name}.xc"; MinimumConstraint.AddRectifyingElement(ckt, $"D{i}", i, highX); ckt.Add(new VoltageControlledVoltageSource($"E{i}", i, lowX, highY, lowY, direction.X / direction.Y)); i = $"{name}.yc"; MinimumConstraint.AddRectifyingElement(ckt, $"D{i}", i, highY); ckt.Add(new VoltageControlledVoltageSource($"E{i}", i, lowY, highX, lowX, direction.Y / direction.X)); }