public void ProjectsOnePointToTheXYPlane() { var result = sut.Project(Plane.XY, 1.0f, 2.0f, 3.0f); Assert.AreEqual(1, result.Length); Assert.AreEqual(new Point2D(1, 2), result[0]); }
public async Task Project_MessageWithCorrectSequenceNumber_ShouldCallHandleMethodOfProjectionsWithMatchingSequenceNumber() { await _sequenceNumberRepository.Store(new Dictionary <string, int> { { "A", 5 }, { "B", 6 }, { "C", 5 } }); _projectionMocks[0].SetupGet(x => x.Key).Returns("A"); _projectionMocks[1].SetupGet(x => x.Key).Returns("B"); _projectionMocks[2].SetupGet(x => x.Key).Returns("C"); var message = new RegisteredMessageA(); _projectionMocks[0] .Setup(x => x.Handle(It.IsAny <Func <object> >(), It.Is <FakeMessageEnvelope>(e => e.Message == message), CancellationToken.None)) .Returns(() => Task.FromResult(true)); _projectionMocks[1] .Setup(x => x.Handle(It.IsAny <Func <object> >(), It.Is <FakeMessageEnvelope>(e => e.Message == message), CancellationToken.None)) .Returns(() => Task.FromResult(true)); _projectionMocks[2] .Setup(x => x.Handle(It.IsAny <Func <object> >(), It.Is <FakeMessageEnvelope>(e => e.Message == message), CancellationToken.None)) .Returns(() => Task.FromResult(true)); var projections = new HashSet <IProjection <string, FakeMessageEnvelope> >(_projectionMocks.Select(x => x.Object)); var projector = new Projector <string, FakeMessageEnvelope, TestNextSequenceNumberRepository>(projections, _factoryMock.Object); await projector.Project(new FakeMessageEnvelope(5, message)); _projectionMocks[0].Verify( x => x.Handle(It.IsAny <Func <object> >(), It.IsAny <FakeMessageEnvelope>(), It.IsAny <CancellationToken>()), Times.Once); _projectionMocks[1].Verify( x => x.Handle(It.IsAny <Func <object> >(), It.IsAny <FakeMessageEnvelope>(), It.IsAny <CancellationToken>()), Times.Never); _projectionMocks[2].Verify( x => x.Handle(It.IsAny <Func <object> >(), It.IsAny <FakeMessageEnvelope>(), It.IsAny <CancellationToken>()), Times.Once); await projector.Project(new FakeMessageEnvelope(6, message)); _projectionMocks[0].Verify( x => x.Handle(It.IsAny <Func <object> >(), It.IsAny <FakeMessageEnvelope>(), It.IsAny <CancellationToken>()), Times.Exactly(2)); _projectionMocks[1].Verify( x => x.Handle(It.IsAny <Func <object> >(), It.IsAny <FakeMessageEnvelope>(), It.IsAny <CancellationToken>()), Times.Once); _projectionMocks[2].Verify( x => x.Handle(It.IsAny <Func <object> >(), It.IsAny <FakeMessageEnvelope>(), It.IsAny <CancellationToken>()), Times.Exactly(2)); }
public async Task Project_TwoProjectionsWithDifferentPriority_ShouldHandleProjectionsInCorrectOrder() { var projectSequence = string.Empty; await _sequenceNumberRepository.Store(new Dictionary <string, int> { { "A", 1 }, { "B", 1 }, { "C", 1 } }); _projectionMocks[0].SetupGet(x => x.Key).Returns("A"); _projectionMocks[1].SetupGet(x => x.Key).Returns("B"); _projectionMocks[2].SetupGet(x => x.Key).Returns("C"); _projectionMocks[0].Setup(x => x.Handle(It.IsAny <Func <object> >(), It.IsAny <FakeMessageEnvelope>(), CancellationToken.None)).Callback(() => projectSequence += "A").Returns(Task.FromResult(false)); _projectionMocks[1].Setup(x => x.Handle(It.IsAny <Func <object> >(), It.IsAny <FakeMessageEnvelope>(), CancellationToken.None)).Callback(() => projectSequence += "B").Returns(Task.FromResult(false)); _projectionMocks[2].Setup(x => x.Handle(It.IsAny <Func <object> >(), It.IsAny <FakeMessageEnvelope>(), CancellationToken.None)).Callback(() => projectSequence += "C").Returns(Task.FromResult(false)); _projectionMocks[0].SetupGet(x => x.Priority).Returns(Priority.Low); _projectionMocks[1].SetupGet(x => x.Priority).Returns(Priority.High); _projectionMocks[2].SetupGet(x => x.Priority).Returns(Priority.Normal); var projections = new HashSet <IProjection <string, FakeMessageEnvelope> >(_projectionMocks.Select(x => x.Object)); var projector = new Projector <string, FakeMessageEnvelope, TestNextSequenceNumberRepository>(projections, _factoryMock.Object); await projector.Project(new FakeMessageEnvelope(1, new RegisteredMessageA())); _projectionMocks[0].SetupGet(x => x.Priority).Returns(Priority.Normal); _projectionMocks[1].SetupGet(x => x.Priority).Returns(Priority.Low); _projectionMocks[2].SetupGet(x => x.Priority).Returns(Priority.High); projections = new HashSet <IProjection <string, FakeMessageEnvelope> >(_projectionMocks.Select(x => x.Object)); projector = new Projector <string, FakeMessageEnvelope, TestNextSequenceNumberRepository>(projections, _factoryMock.Object); await projector.Project(new FakeMessageEnvelope(2, new RegisteredMessageA())); Assert.That(projectSequence, Is.EqualTo("BCACAB")); }
public async Task Project_CancelMessageWithCorrectSequenceNumber_ShouldCancelHandlerAndNotThrowSequenceNumberException() { await _sequenceNumberRepository.Store(new Dictionary <string, int> { { "A", 10 } }); var messageEnvelope = new FakeMessageEnvelope(10, new RegisteredMessageA()); var isCancelled = false; _projectionMocks[0].SetupGet(x => x.Key).Returns("A"); _projectionMocks[0] .Setup(x => x.Handle(It.IsAny <Func <object> >(), messageEnvelope, It.IsAny <CancellationToken>())) .Returns <object, FakeMessageEnvelope, CancellationToken>(async(_, __, token) => { await Task.Delay(20).ConfigureAwait(false); isCancelled = token.IsCancellationRequested; return(false); }); var projections = new HashSet <IProjection <string, FakeMessageEnvelope> >(_projectionMocks.Take(1).Select(x => x.Object)); var projector = new Projector <string, FakeMessageEnvelope, TestNextSequenceNumberRepository>(projections, _factoryMock.Object); var cancellationTokenSource = new CancellationTokenSource(5); await projector.Project(messageEnvelope, cancellationTokenSource.Token).ConfigureAwait(false); Assert.True(isCancelled); }
protected override void Draw(DrawingContext dc, int Zoom) { var elementPoint = Projector.Project(Position, Zoom); dc.PushTransform(new TranslateTransform(elementPoint.X, elementPoint.Y)); DrawPointElement(dc, Zoom); dc.Pop(); }
protected override void Draw(DrawingContext dc, int RenderZoom) { EarthPoint topLeftPoint = OsmIndexes.GetTopLeftPoint(HorizontalIndex, VerticalIndex, RenderZoom); Point topLeftPointScreenProjection = Projector.Project(topLeftPoint, RenderZoom); var tileRect = new Rect(topLeftPointScreenProjection, new Size(256, 256)); DrawTile(dc, tileRect); }
public void DrawPadLock(Graphics g, AirPlane ap) { double r = 110.0D; double l = 20.0D; //g.SetColor(padLockColor); // g.SetFont(padFont); PadlockObject pobj = ap.pilot.pObjList.PadlockObj(ap); if (pobj != null) { Vector3D vec = pobj.RPosPilotView(ap); Vector3D vec2 = clip.Vs_point_clip_3df(vec); if (vec2 != null) { vec2 = proj.Project(vec2); vec2 = clip.Vs_point_clip2d(vec2); } if (vec2 != null) { int x0 = (int)(vec2.x + 0.5D); int y0 = (int)(vec2.y + 0.5D); g.DrawRectangle(new Pen(padLockColor), x0 - 10, y0 - 10, 1, 1); //g.DrawRect(x0 + 8, y0 - 10, 1, 1); //g.DrawRect(x0 + 8, y0 + 8, 1, 1); //g.DrawRect(x0 - 10, y0 + 8, 1, 1); //g.DrawString(pobj.name, x0 + 12, y0 + 9); } else { Bearing3 be3 = pobj.Bearing2PilotView(ap); double sinr = -System.Math.Sin(be3.roll.GetValue()); double cosr = -System.Math.Cos(be3.roll.GetValue()); double w = l * System.Math.Sin(be3.pitch.GetValue() / 2.0D); double h = l * System.Math.Cos(be3.pitch.GetValue() / 2.0D); int x0_0 = 300 + (int)(r * sinr); int y0_1 = 200 + (int)(r * cosr); int x1 = 300 + (int)((r + l) * sinr); int y1 = 200 + (int)((r + l) * cosr); Jp.Maker1.Util.Symbol.DrawArrow(g, x0_0, y0_1, x1, y1, (int)h, (int)w); //g.DrawString(pobj.name, (x0_0 + x1) / 2 + (int)(l * 0.71D), (y0_1 + y1) / 2 + (int)(l * 0.71D)); g.DrawString(pobj.name, padFont, new SolidBrush(padLockColor), (x0_0 + x1) / 2 + (int)(l * 0.71D), (y0_1 + y1) / 2 + (int)(l * 0.71D)); } } }
public async Task Project_WithProjectionThatResolvesConnection_ShouldCreateResolveDisposeLifetimeScopeInCorrectOrder() { await _sequenceNumberRepository.Store(new Dictionary <string, int> { { "A", 5 } }); var messageEnvelope = new FakeMessageEnvelope(5, new RegisteredMessageA()); var connectionType = typeof(ConnectionA); _projectionMocks[0].SetupGet(x => x.Key).Returns("A"); _projectionMocks[0].SetupGet(x => x.ConnectionType).Returns(connectionType); _projectionMocks[0] .Setup(x => x.Handle(It.IsAny <Func <object> >(), messageEnvelope, CancellationToken.None)) .Callback <Func <object>, FakeMessageEnvelope, CancellationToken>((connectionResolver, _, __) => { Assert.That(connectionResolver(), Is.Not.Null); }) .Returns(() => Task.FromResult(true)); var projections = new HashSet <IProjection <string, FakeMessageEnvelope> >(_projectionMocks.Take(1).Select(x => x.Object)); var projector = new Projector <string, FakeMessageEnvelope, TestNextSequenceNumberRepository>(projections, _factoryMock.Object); // Get the sequence number first so this scope creation/disposal does not influence our test await projector.GetNextSequenceNumber(); var executionOrder = 0; _factoryMock.Reset(); _factoryMock .Setup(x => x.BeginLifetimeScope()) .Callback(() => Assert.That(executionOrder++, Is.EqualTo(0))) .Returns(() => { var scopeMock = new Mock <IDependencyLifetimeScope>(); scopeMock .Setup(x => x.Resolve(typeof(TestNextSequenceNumberRepository))) .Returns(_sequenceNumberRepository); scopeMock .Setup(x => x.Resolve(connectionType)) .Callback(() => Assert.That(executionOrder++, Is.EqualTo(1))) .Returns(() => new FakeConnection()); scopeMock .Setup(x => x.Dispose()) .Callback(() => Assert.That(executionOrder++, Is.EqualTo(2))); return(scopeMock.Object); }); // ReSharper disable once MethodSupportsCancellation await projector.Project(messageEnvelope); Assert.That(executionOrder, Is.EqualTo(3)); }
public async Task Project_MessageWithWrongSequenceNumber_ShouldThrowException() { await _sequenceNumberRepository.Store(new Dictionary <string, int> { { "A", 5 }, { "B", 6 }, { "C", 3 } }); _projectionMocks[0].SetupGet(x => x.Key).Returns("A"); _projectionMocks[1].SetupGet(x => x.Key).Returns("B"); _projectionMocks[2].SetupGet(x => x.Key).Returns("C"); var messageEnvelope = new FakeMessageEnvelope(2, new RegisteredMessageA()); var projections = new HashSet <IProjection <string, FakeMessageEnvelope> >(_projectionMocks.Select(x => x.Object)); var projector = new Projector <string, FakeMessageEnvelope, TestNextSequenceNumberRepository>(projections, _factoryMock.Object); var ex = Assert.ThrowsAsync <ArgumentOutOfRangeException>(() => projector.Project(messageEnvelope)); Assert.That(ex.ParamName, Is.EqualTo("SequenceNumber")); }
public void PerformUSP(double constant) { var pcs = ((PCAResult)analysisResults[AnalysisAlgorithm.PCA]).PrincipalComponents; double[,] entryPcs = Projector.Project(pcs, USPSampleInputData, constant); //DataTable result = Projector.ProjectionToDataTable(entryPcs); //var result = new double[entryPcs.GetLength(0), twoDim ? 2 : 3]; //for (int i = 0; i < result.GetLength(0); i++) //{ // for (int j = 0; j < result.GetLength(1); j++) // { // result[i, j] = entryPcs[i, j]; // } //} IsSaved = false; USPPerformed(this, new USPPerformedEventArgs(entryPcs)); }
public async Task Project_MessageWithCorrectSequenceNumber_ShouldIncrementSequenceNumber() { await _sequenceNumberRepository.Store(new Dictionary <string, int> { { "A", 5 }, { "B", 6 }, { "C", 3 } }); _projectionMocks[0].SetupGet(x => x.Key).Returns("A"); _projectionMocks[1].SetupGet(x => x.Key).Returns("B"); _projectionMocks[2].SetupGet(x => x.Key).Returns("C"); var messageEnvelope = new FakeMessageEnvelope(3, new RegisteredMessageA()); var projections = new HashSet <IProjection <string, FakeMessageEnvelope> >(_projectionMocks.Select(x => x.Object)); var projector = new Projector <string, FakeMessageEnvelope, TestNextSequenceNumberRepository>(projections, _factoryMock.Object); Assert.That(await projector.GetNextSequenceNumber(), Is.EqualTo(3)); await projector.Project(messageEnvelope); Assert.That(await projector.GetNextSequenceNumber(), Is.EqualTo(4)); }
protected override object ExecuteImpl(Expression expression, Type itemType) { var query = (RelativesAwareTranslatedQuery)WiqlQueryBuilder.BuildQuery(expression); var results = query.WillEverHaveResults() ? ExecuteRawQuery(query.UnderlyingQueryType, query.ToQueryString()) : Activator.CreateInstance(typeof(List <>).MakeGenericType(query.UnderlyingQueryType)) as IEnumerable; if (query.Relatives != null) { var asOf = query.AsOfDateTime ?? DateTime.Now; results = GetRelatives(results.Cast <IIdentifiable>(), query.Relatives, itemType, asOf); } else if (query.Projections.Count > 0) { return(Projector.Project(query.Projections, results.Cast <object>())); } return(results); }
protected IEnumerable <Point> GetScreenPoints(int Zoom) { Point?previousPoint = null; Point?tailPoint = null; foreach (var point in Points) { tailPoint = Projector.Project(point, Zoom); if (previousPoint == null || (previousPoint.Value - tailPoint.Value).LengthSquared >= _screenStepSquared) { previousPoint = tailPoint; yield return(tailPoint.Value); } } if (previousPoint != null && tailPoint != previousPoint.Value) { yield return(tailPoint.Value); } }
public async Task Project_SecondProjectionThrowsException_ProjectShouldThrowExceptionAfterStoringCorrectSequenceNumbers() { await _sequenceNumberRepository.Store(new Dictionary <string, int> { { "A", 50 }, { "B", 50 }, { "C", 50 } }); _projectionMocks[0].SetupGet(x => x.Key).Returns("A"); _projectionMocks[1].SetupGet(x => x.Key).Returns("B"); _projectionMocks[2].SetupGet(x => x.Key).Returns("C"); var messageEnvelope = new FakeMessageEnvelope(50, new RegisteredMessageA()); _projectionMocks[1].Setup(x => x.Handle(It.IsAny <Func <object> >(), messageEnvelope, CancellationToken.None)) .Callback(() => { throw new DivideByZeroException(); }); var projections = new HashSet <IProjection <string, FakeMessageEnvelope> >(_projectionMocks.Select(x => x.Object)); var projector = new Projector <string, FakeMessageEnvelope, TestNextSequenceNumberRepository>(projections, _factoryMock.Object); Assert.ThrowsAsync <DivideByZeroException>(() => projector.Project(messageEnvelope)); Assert.That(_sequenceNumberRepository["A"], Is.EqualTo(51)); Assert.That(_sequenceNumberRepository["B"], Is.EqualTo(50)); Assert.That(_sequenceNumberRepository["C"], Is.EqualTo(50)); }
private ODataEntity CreateFieldDictionary(Content content, Projector projector, HttpContext httpContext) { return(projector.Project(content, httpContext)); }
/// <summary>Projects a command to the given plane.</summary> /// <param name="plane">The plane.</param> /// <param name="parsedCommand">The parsed command.</param> /// <returns>The command with its coordinates projected to the given plane as <see cref="Point2D"/>s.</returns> private ProjectedCommand CreateCommand(Plane plane, ParsedCommand parsedCommand) => new ProjectedCommand(plane, parsedCommand.Name, projector.Project(plane, parsedCommand.Args));
public static Image AlignLocallyToTarget(Image map, Image target, int alignmentSize, int oversampling, out float3 shift, out float3 rotation) { float ScaleFactor = (float)alignmentSize / map.Dims.X; int3 DimsScaled = new int3(alignmentSize, alignmentSize, alignmentSize); #region Prepare Scaled & FFTed maps Image MapScaled = map.AsScaled(DimsScaled); map.FreeDevice(); Image TargetScaled = target.AsScaled(DimsScaled); target.FreeDevice(); TargetScaled.RemapToFT(true); TargetScaled.WriteMRC("d_targetscaled.mrc", true); Image TargetScaledFT = TargetScaled.AsFFT(true); TargetScaled.Dispose(); Projector ProjMapScaled = new Projector(MapScaled, oversampling); Image TestFT = ProjMapScaled.Project(DimsScaled, new float3[1]); Image Test = TestFT.AsIFFT(true); Test.RemapFromFT(true); Test.WriteMRC("d_projected.mrc", true); #endregion float3 CurShift = new float3(), CurRotation = new float3(); Func <double[], double> GetDiff = input => { CurShift = new float3((float)input[0], (float)input[1], (float)input[2]); CurRotation = new float3((float)input[3], (float)input[4], (float)input[5]) * Helper.ToRad; CurRotation = Matrix3.EulerFromMatrix(Matrix3.RotateX(CurRotation.X) * Matrix3.RotateY(CurRotation.Y) * Matrix3.RotateZ(CurRotation.Z)) * Helper.ToDeg; Image TargetFTShifted = TargetScaledFT.AsShiftedVolume(-CurShift * ScaleFactor); Image MapRotatedFT = ProjMapScaled.Project(DimsScaled, new[] { CurRotation *Helper.ToRad }); GPU.MultiplySlices(TargetFTShifted.GetDevice(Intent.Read), MapRotatedFT.GetDevice(Intent.Read), TargetFTShifted.GetDevice(Intent.Write), TargetFTShifted.ElementsReal, 1); MapRotatedFT.Dispose(); IntPtr d_Sum = GPU.MallocDevice(1); GPU.Sum(TargetFTShifted.GetDevice(Intent.Read), d_Sum, (uint)TargetFTShifted.ElementsReal, 1); TargetFTShifted.Dispose(); float[] h_Sum = new float[1]; GPU.CopyDeviceToHost(d_Sum, h_Sum, 1); GPU.FreeDevice(d_Sum); return(h_Sum[0]); }; Func <double[], double[]> GetGradient = input => { float Delta = 0.05f; double[] Result = new double[input.Length]; Console.WriteLine(GetDiff(input)); for (int i = 0; i < input.Length; i++) { double[] InputPlus = input.ToList().ToArray(); InputPlus[i] += Delta; double ScorePlus = GetDiff(InputPlus); double[] InputMinus = input.ToList().ToArray(); InputMinus[i] -= Delta; double ScoreMinus = GetDiff(InputMinus); Result[i] = (ScorePlus - ScoreMinus) / (Delta * 2); } return(Result); }; double[] StartParams = new double[6]; BroydenFletcherGoldfarbShanno Optimizer = new BroydenFletcherGoldfarbShanno(StartParams.Length, GetDiff, GetGradient); Optimizer.MaxIterations = 20; Optimizer.Maximize(StartParams); GetDiff(StartParams); shift = CurShift; rotation = CurRotation; #region Shift and rotate input map by determined values for final output ProjMapScaled.Dispose(); Image MapResult = map.AsShiftedVolume(shift); map.FreeDevice(); Projector ProjMapResult = new Projector(MapResult, oversampling); MapResult.Dispose(); Image MapResultFT = ProjMapResult.Project(map.Dims, new[] { rotation *Helper.ToRad }); ProjMapResult.Dispose(); MapResult = MapResultFT.AsIFFT(true); MapResultFT.Dispose(); MapResult.RemapFromFT(true); #endregion return(MapResult); }
public IEnumerable <T> Build <T>(ResultTable rt) { Projector.Results = rt; return(Projector.Project(Expression.Lambda <Func <T> >(_buildExpression).Compile())); }