public void OffsetLineFromEndpoint() { var scaled = (Line)EditUtilities.Scale( new Line(new Point(1.0, 1.0, 0.0), new Point(2.0, 2.0, 0.0)), new Point(1.0, 1.0, 0.0), 2.0 ); Assert.Equal(new Point(1.0, 1.0, 0.0), scaled.P1); Assert.Equal(new Point(3.0, 3.0, 0.0), scaled.P2); }
public static Drawing ScaleEntities(this Drawing drawing, IEnumerable <Entity> entities, Point basePoint, double scaleFactor) { var result = drawing; foreach (var e in entities) { var layer = result.ContainingLayer(e); var scaledEntity = EditUtilities.Scale(e, basePoint, scaleFactor); var updatedLayer = layer.Remove(e).Add(scaledEntity); result = result.Remove(layer).Add(updatedLayer); } return(result); }
public async Task <bool> Execute(IWorkspace workspace, object arg) { // get all inputs var selection = await workspace.InputService.GetEntities("Select entities"); if (selection.Cancel || !selection.HasValue) { return(false); } var entities = selection.Value; var basePointValue = await workspace.InputService.GetPoint(new UserDirective("Select base point")); if (basePointValue.Cancel || !basePointValue.HasValue) { return(false); } var basePoint = basePointValue.Value; var scaleFactorValue = await workspace.InputService.GetDistance(new UserDirective("Scale factor or [r]eference", "r")); if (scaleFactorValue.Cancel || (!scaleFactorValue.HasValue && string.IsNullOrEmpty(scaleFactorValue.Directive))) { return(false); } double scaleFactor; if (scaleFactorValue.Directive == "r") { var firstDistanceValue = await workspace.InputService.GetDistance(new UserDirective("First scale distance")); if (firstDistanceValue.Cancel || !firstDistanceValue.HasValue || firstDistanceValue.Value == 0.0) { return(false); } var entityPrimitives = entities.SelectMany(e => e.GetPrimitives()).ToArray(); var secondDistanceValue = await workspace.InputService.GetDistance( new UserDirective("Second scale distance"), onCursorMove : distance => { var scaleFactor = distance / firstDistanceValue.Value; return(entityPrimitives.Select(p => EditUtilities.Scale(p, basePoint, scaleFactor))); }); if (secondDistanceValue.Cancel || !secondDistanceValue.HasValue || secondDistanceValue.Value == 0.0) { return(false); } scaleFactor = secondDistanceValue.Value / firstDistanceValue.Value; } else { scaleFactor = scaleFactorValue.Value; } // now do it var drawing = workspace.Drawing.ScaleEntities(entities, basePoint, scaleFactor); workspace.Update(drawing: drawing); return(true); }