public void QuantizeEntity() { var settings = new QuantizeSettings(distanceQuantum: OneSixteenth, angleQuantum: 1.0); var line = new Line(new Point(1.4999999999, 1.5000000001, 0.0), new Point(2.50000000001, 2.4999999999, 0.0)); var quantized = (Line)EditUtilities.Quantize(line, settings); Assert.Equal(new Point(1.5, 1.5, 0.0), quantized.P1); Assert.Equal(new Point(2.5, 2.5, 0.0), quantized.P2); }
public async Task <bool> Execute(IWorkspace workspace, object arg = null) { // get entities var entities = await workspace.InputService.GetEntities(); if (entities.Cancel || !entities.HasValue) { return(false); } if (!entities.Value.Any()) { return(true); } // get distance quantum var distance = await workspace.InputService.GetDistance(new UserDirective("Distance quantum"), defaultDistance : LastDistanceQuantum); if (distance.Cancel) { return(false); } double distanceQuantum; if (distance.HasValue) { distanceQuantum = distance.Value; } else { distanceQuantum = LastDistanceQuantum; } LastDistanceQuantum = distanceQuantum; // get angle quantum var angle = await workspace.InputService.GetDistance(new UserDirective("Angle quantum"), defaultDistance : LastAngleQuantum); if (angle.Cancel) { return(false); } double angleQuantum; if (angle.HasValue) { angleQuantum = angle.Value; } else { angleQuantum = LastAngleQuantum; } LastAngleQuantum = angleQuantum; // do it var settings = new QuantizeSettings(distanceQuantum, angleQuantum); var drawing = workspace.Drawing; foreach (var entity in entities.Value) { var quantized = EditUtilities.Quantize(entity, settings); var layer = drawing.ContainingLayer(entity); var originalLayer = layer; layer = layer.Remove(entity); layer = layer.Add(quantized); drawing = drawing.Remove(originalLayer); drawing = drawing.Add(layer); } workspace.Update(drawing: drawing); return(true); }