public void BinarySerializationShouldWork() { var assembly = this.GetType().Assembly; var sut = new HitTestMethod(assembly.FullName, this.GetType().FullName, nameof(BinarySerializationShouldWork), assembly.Location, 15, new Dictionary <int, int> { { 1, 15 } }); byte[] data; using (var stream = new MemoryStream()) { sut.Serialize(stream); data = stream.ToArray(); } using (var stream = new MemoryStream(data)) { var results = HitTestMethod.Deserialize(stream).ToArray(); results.Length.ShouldBe(1); var result = results.First(); result.ClassName.ShouldBe(sut.ClassName); result.MethodName.ShouldBe(sut.MethodName); result.AssemblyName.ShouldBe(sut.AssemblyName); result.AssemblyLocation.ShouldBe(sut.AssemblyLocation); result.Counter.ShouldBe(sut.Counter); result.HitedInstructions.ShouldBe(sut.HitedInstructions); } }
public static Hits TryReadFromFile(string file) { if (!File.Exists(file)) { return(new Hits(Enumerable.Empty <Hit>())); } using (var fileStream = File.Open(file, FileMode.Open, FileAccess.Read)) { var tests = HitTestMethod.Deserialize(fileStream); return(ConvertToHits(tests)); } }
private static Hit Convert(int id, IEnumerable <Hit> hits) { var items = hits.ToArray(); var methods = items.SelectMany(hi => hi.TestMethods); var validMethods = methods.Where(a => a.HasBeenHitBy(id)); var converted = HitTestMethod.MergeDuplicates(validMethods, id).ToArray(); return(new Hit( id, items.Sum(h => h.Counter), converted)); }
/// <summary> /// This method let's the Draw(...) know to retrieve the object at the requested location. When an object is found, the ModelSelectedEvent will be triggered. /// </summary> /// <param name="p">The 2D point relative to the OpenGL viewport.</param> public void GetModelAtPoint(Point p, IEnumerable<ElementAndTransformation> models, HitTestMethod method = HitTestMethod.OpenGLHack) { return; //TODO!! if (p != null && models != null && models.Count() > 0) { Point correctedPoint = new Point((int)(p.X * _performanceScaleValue), (int)(p.Y * _performanceScaleValue)); // Create an array that will be the viewport. int[] viewport = new int[4]; // Get the viewport, then convert the mouse point to an opengl point. GL.GetInteger(OpenGL.GL_VIEWPORT, viewport); // Take deep copy of everything we need. var mvCopy = new ModelView() { ResultMatrix = ModelView.ModelviewMatrix }; var prCopy = new Projection() { ProjectionMatrix = Projection.ProjectionMatrix }; var nrmlCopy = new Normal() { NormalMatrix = Normal.NormalMatrix }; Task t = new Task(() => { int selectedIndex = -1; if (method == HitTestMethod.OpenGLHack) { selectedIndex = GetModelAtPointHack(correctedPoint, models, viewport, mvCopy, prCopy, nrmlCopy); } OnModelSelected(correctedPoint, models, selectedIndex); }); t.Start(); } }
/// <summary> /// This method let's the Draw(...) know to retrieve the object at the requested location. When an object is found, the ModelSelectedEvent will be triggered. /// </summary> /// <param name="p">The 2D point relative to the OpenGL viewport.</param> public void GetModelAtPoint(Point p, IEnumerable <ElementAndTransformation> models, HitTestMethod method = HitTestMethod.OpenGLHack) { return; //TODO!! if (p != null && models != null && models.Count() > 0) { Point correctedPoint = new Point((int)(p.X * _performanceScaleValue), (int)(p.Y * _performanceScaleValue)); // Create an array that will be the viewport. int[] viewport = new int[4]; // Get the viewport, then convert the mouse point to an opengl point. GL.GetInteger(OpenGL.GL_VIEWPORT, viewport); // Take deep copy of everything we need. var mvCopy = new ModelView() { ResultMatrix = ModelView.ModelviewMatrix }; var prCopy = new Projection() { ProjectionMatrix = Projection.ProjectionMatrix }; var nrmlCopy = new Normal() { NormalMatrix = Normal.NormalMatrix }; Task t = new Task(() => { int selectedIndex = -1; if (method == HitTestMethod.OpenGLHack) { selectedIndex = GetModelAtPointHack(correctedPoint, models, viewport, mvCopy, prCopy, nrmlCopy); } OnModelSelected(correctedPoint, models, selectedIndex); }); t.Start(); } }