public Rotation Determine(PanelRectangle parent, Panel panel) { if (parent == null) { throw new ArgumentNullException(nameof(parent)); } if (panel == null) { throw new ArgumentNullException(nameof(panel)); } switch (panel.AttachedToSide) { case 0: return(parent.Rotation + Rotation.Down); case 1: return(parent.Rotation + Rotation.Right); case 2: return(parent.Rotation + Rotation.None); case 3: return(parent.Rotation + Rotation.Left); default: throw new ArgumentOutOfRangeException($"Panel '{panel.Name}' ({panel.Id}) does not have a valid side to attach to: {panel.AttachedToSide}"); } }
ImmutableList <PanelRectangle> Create(PanelRectangle parent, Panel panel) { var panelRectangle = _panelPositioner.Position(parent, panel); return(ImmutableList.Create(panelRectangle) .AddRange(panel.AttachedPanels.SelectMany(attachedPanel => Create(panelRectangle, attachedPanel)))); }
public PanelRectangle Position(PanelRectangle parent, Panel panel) { if (parent == null) { throw new ArgumentNullException(nameof(parent)); } if (panel == null) { throw new ArgumentNullException(nameof(panel)); } var hingeToAttachTo = _attachToHingeDeterminer.Determine(parent, panel); var rectangle = _rectangleFactory.Create(hingeToAttachTo, panel.Dimensions); var rotation = _rotationDeterminer.Determine(parent, panel); var rotatedRectangle = _rectangleRotator.Rotate(hingeToAttachTo, rectangle, rotation); var rotatedRectangleWithHingeOffset = _hingeOffsetApplier.Apply(rotatedRectangle, rotation, panel.HingeOffset); return(new PanelRectangle(panel, rotatedRectangleWithHingeOffset, rotation)); }