void btnValidate_Clicked(System.Object sender, System.EventArgs e) { try { string idNumber = txtIDNumber.Text.Trim(); if (txtIDNumber.Text != "") { bool isValid = Computations.validateDlsuIdNumber(int.Parse(idNumber)); if (isValid) { DisplayAlert("ID Validator", "ID Number " + idNumber + " is VALID.", "Ok"); } else { DisplayAlert("ID Validator", "ID Number " + idNumber + " is INVALID.", "Ok"); } } else { DisplayAlert("ID Validator", "Please enter an ID number to validate.", "Ok"); } } catch (Exception ex) { DisplayAlert("ID Validator", "Please check if your input format is correct.", "Ok"); } }
public void T17_ReflectanceOfPerpRay() { if (Scene.current == null) { new Scene(); } Scene.current.Clear(); Sphere sphere = new Sphere(); sphere.material.Glassy(); Ray ray = new Ray(new Point(0, 0, 0), new Vector(0, 1, 0)); List <Intersection> xs = new List <Intersection>(); xs.Add(new Intersection(sphere, -1)); xs.Add(new Intersection(sphere, 1)); Computations c = Computations.Prepare(xs[1], ray, xs); double reflectance = Scene.current.Schlick(c); Assert.IsTrue(Utility.FE(0.04, reflectance)); }
public void ShouldFindN1AndN2AtIntersection(int index, float n1, float n2) { var a = Sphere.CreateGlass(); a.Transform = CreateScale(2, 2, 2); a.Material.RefractiveIndex = 1.5f; var b = Sphere.CreateGlass(); b.Transform = CreateTranslation(0, 0, -0.25f); b.Material.RefractiveIndex = 2f; var c = Sphere.CreateGlass(); c.Transform = CreateTranslation(0, 0, 0.25f); c.Material.RefractiveIndex = 2.5f; var r = new Ray(CreatePoint(0, 0, -4f), CreateVector(0, 0, 1)); var xs = new List <Intersection> { new Intersection(2, a), new Intersection(2.75f, b), new Intersection(3.25f, c), new Intersection(4.75f, b), new Intersection(5.25f, c), new Intersection(6, a), }; var comps = Computations.Prepare(xs[index], r, xs); comps.N1.Should().BeApproximately(n1, Tolerance); comps.N2.Should().BeApproximately(n2, Tolerance); }
/// <summary> /// generate data packet from this vechile to the TargetVehicle. /// </summary> /// <param name="DestinationVehicle"></param> public void GeneratePacket(VehicleUi DestinationVehicle) { Dispatcher.Invoke((Action) delegate { Packet packet = new Packet(); packet.Type = PacketType.Data; PublicStatistics.GeneratedPacketsCount += 1; packet.PID = PublicStatistics.GeneratedPacketsCount; packet.PacketLength = PublicParamerters.DataPacketLength; packet.TravelledRoadSegmentString += CurrentLane.MyRoadSegment.RID; // add the first rs. packet.VehiclesString += VID; // start by current sender. packet.SRID = CurrentLane.MyRoadSegment.RID; // set source and distination: packet.SourceVehicle = this; packet.DestinationVehicle = DestinationVehicle; packet.Direction = DestinationVehicle.CurrentLane.LaneDirection; packet.CurrentRoadSegment = CurrentLane.MyRoadSegment; // the segment of the vechile. packet.EuclideanDistance = Computations.Distance(InstanceLocation, DestinationVehicle.InstanceLocation); // the intial distance packet.RoutingDistance = packet.EuclideanDistance; packet.SVID = VID; packet.DVID = DestinationVehicle.VID; this.SetNotationSign(NotationsSign.HasPacket); DestinationVehicle.SetNotationSign(NotationsSign.Destination); DestinationVehicle.WaitingPacketsIDsList.Add(packet.PID); // flage // start count the delay. PacketQueue.Enqueue(packet); // add the packet to the queue. PacketQueueTimer.Interval = TimeSpan.FromSeconds(PublicParamerters.PacketQueueTimerInterval); // retry after... PacketQueueTimer.Start(); // start the timer. }); }
public void T18_ReflectanceN2GreaterN1() { if (Scene.current == null) { new Scene(); } Scene.current.Clear(); Sphere sphere = new Sphere(); sphere.material.Glassy(); Ray ray = new Ray(new Point(0, 0.99, -2), new Vector(0, 0, 1)); List <Intersection> xs = new List <Intersection>(); xs.Add(new Intersection(sphere, 1.8589)); Computations c = Computations.Prepare(xs[0], ray, xs); double reflectance = Scene.current.Schlick(c); Assert.IsTrue(Utility.FE(0.48873, reflectance)); }
public void T06_ShadeHitIntersectionInShadow() { if (Scene.current == null) { new Scene(); } Scene.current.Clear(); Light light = new Light(new Point(0, 0, -10), new Color(1, 1, 1)); Sphere s1 = new Sphere(); Sphere s2 = new Sphere(); s2.SetMatrix(Mat4.TranslateMatrix(0, 0, 10)); Ray ray = new Ray(new Point(0, 0, 5), new Vector(0, 0, 1)); Intersection i = new Intersection(s2, 4); Computations c = Computations.Prepare(i, ray, null); Color color = Scene.current.ShadeHit(c); Assert.AreEqual(new Color(0.1f, 0.1f, 0.1f), color); }
public void T16_ReflectanceUnderTotalInteralReflection() { if (Scene.current == null) { new Scene(); } Scene.current.Clear(); Sphere sphere = new Sphere(); sphere.material.Glassy(); Ray ray = new Ray(new Point(0, 0, Math.Sqrt(2) / 2), new Vector(0, 1, 0)); List <Intersection> xs = new List <Intersection>(); xs.Add(new Intersection(sphere, Math.Sqrt(2) / -2)); xs.Add(new Intersection(sphere, Math.Sqrt(2) / 2)); Computations c = Computations.Prepare(xs[1], ray, xs); double reflectance = Scene.current.Schlick(c); Assert.IsTrue(Utility.FE(1.0, reflectance)); }
public void ShadeHitWithReflectiveTransparency() { World w = World.DefaultWorld(); Shape floor = new Plane(); floor.Transform = new Translate(0, -1, 0).GetTransform(); floor.Material.Reflectivity = 0.5; floor.Material.Transparency = 0.5; floor.Material.RefractiveIndex = 1.5; w.AddShape(floor); Shape ball = new Sphere(); ball.Material.Color = new Color(1, 0, 0); ball.Material.Ambient = 0.5; ball.Transform = new Translate(0, -3.5, -0.5).GetTransform(); w.AddShape(ball); Ray r = new Ray(Tuple.Point(0, 0, -3), Tuple.Vector(0, -Math.Sqrt(2) / 2, Math.Sqrt(2) / 2)); List <Intersection> xs = new List <Intersection>(); xs.Add(new Intersection(Math.Sqrt(2), floor)); Computations comps = Computations.PrepareComputations(xs[0], r, xs); Color c = w.ShadeHit(comps, 5); Assert.AreEqual(c, new Color(0.93391, 0.69643, 0.69243)); }
public void T13_TotalInternalReflection() { if (Scene.current == null) { new Scene(); } Scene.current.Default(); RayObject ro1 = Scene.current.root.GetChildren()[0]; ro1.material.Transparency = 1.0; ro1.material.RefracIndex = 1.5; Ray r = new Ray(new Point(0, 0, Math.Sqrt(2) / 2), new Vector(0, 1, 0)); List <Intersection> xs = new List <Intersection>(); xs.Add(new Intersection(ro1, Math.Sqrt(2) / -2)); xs.Add(new Intersection(ro1, Math.Sqrt(2) / 2)); Computations c = Computations.Prepare(xs[1], r, xs); Color color = Scene.current.RefractedColor(c, 5); Assert.AreEqual(Color.black, color); }
public void T14_FindRefractedColor() { if (Scene.current == null) { new Scene(); } Scene.current.Default(); RayObject a = Scene.current.root.GetChildren()[0]; a.material.Ambient = 1.0; a.material.pattern = new Patterns.TestPattern(); RayObject b = Scene.current.root.GetChildren()[1]; b.material.Transparency = 1.0; b.material.RefracIndex = 1.5; Ray ray = new Ray(new Point(0, 0, 0.1), new Vector(0, 1, 0)); List <Intersection> xs = new List <Intersection>(); xs.Add(new Intersection(a, -0.9899)); xs.Add(new Intersection(b, -0.4899)); xs.Add(new Intersection(b, 0.4899)); xs.Add(new Intersection(a, 0.9899)); Computations c = Computations.Prepare(xs[2], ray, xs); Color color = Scene.current.RefractedColor(c, 5); Assert.AreEqual(new Color(0, 0.99888, 0.04725), color); }
public void T12_RefractedColorAtMaxRecusionDepth() { if (Scene.current == null) { new Scene(); } Scene.current.Default(); RayObject ro1 = Scene.current.root.GetChildren()[0]; ro1.material.Transparency = 1; ro1.material.RefracIndex = 1.5; Ray r = new Ray(new Point(0, 0, -5), new Vector(0, 0, 1)); List <Intersection> xs = new List <Intersection>(); xs.Add(new Intersection(ro1, 4)); xs.Add(new Intersection(ro1, 6)); Computations c = Computations.Prepare(xs[0], r, xs); Color color = Scene.current.RefractedColor(c, 0); Assert.AreEqual(Color.black, color); }
public void T11_RefractedColorOfOpaque() { if (Scene.current == null) { new Scene(); } Scene.current.Clear(); Scene.current.Default(); RayObject ro1 = Scene.current.root.GetChildren()[0]; Ray ray = new Ray(new Point(0, 0, -5), new Vector(0, 0, 1)); List <Intersection> xs = new List <Intersection>(); xs.Add(new Intersection(ro1, 4)); xs.Add(new Intersection(ro1, 6)); Computations c = Computations.Prepare(xs[0], ray, xs); Color color = Scene.current.RefractedColor(c, 5); Assert.AreEqual(Color.black, color); }
public void ShouldShadeHitWithReflectiveTransparentMaterial() { var w = World.CreateDefault(); var floorPlane = new XZPlane { Transform = CreateTranslation(0, -1, 0), Material = { Reflective = 0.5f, Transparency = 0.5f, RefractiveIndex = 1.5f, } }; w.Objects.Add(floorPlane); var ball = new Sphere { Material = { Color = VColor.LinearRGB(1, 0, 0), Ambient = 0.5f, }, Transform = CreateTranslation(0, -3.5f, -0.5f), }; w.Objects.Add(ball); var r = new Ray(CreatePoint(0, 0, -3), CreateVector(0, -Sqrt(2) / 2, Sqrt(2) / 2)); var xs = Intersection.CreateList((Sqrt(2), floorPlane)); var comps = Computations.Prepare(xs[0], r, xs); var color = w.ShadeHit(comps, 5); AssertActualEqualToExpected(color, VColor.LinearRGB(0.93391f, 0.69643f, 0.69243f)); }
public IRegionModelResident CreateModelOnceResolved(Computations computations, IRegionNodeResident resident) { var resolver = new CreateModel_RegionNodeResidentResolver(this, computations); resident.Accept(resolver); return(resolver.Result); }
public void T19_CombiningReflectionAndRefraction() { if (Scene.current == null) { new Scene(); } Scene.current.Default(); Plane plane = new Plane(); plane.SetMatrix(Mat4.TranslateMatrix(0, -1, 0)); plane.material.Reflective = 0.5; plane.material.Transparency = 0.5; plane.material.RefracIndex = 1.5; Sphere ball = new Sphere(); ball.material.color = new Color(1, 0, 0); ball.material.Ambient = 0.5; ball.SetMatrix(Mat4.TranslateMatrix(0, -3.5, -0.5)); Ray r = new Ray(new Point(0, 0, -3), new Vector(0, Math.Sqrt(2) / -2, Math.Sqrt(2) / 2)); List <Intersection> xs = new List <Intersection>(); xs.Add(new Intersection(plane, Math.Sqrt(2))); Computations c = Computations.Prepare(xs[0], r, xs); Color color = Scene.current.ShadeHit(c, 5); Assert.AreEqual(new Color(0.93391, 0.69643, 0.69243), color); }
public IGlobeResident CreateModelOnceResolved(Computations computations, ITaxonomyResident resident) { var resolver = new CreateModel_TaxonomyResidentResolver(this, computations); resident.Accept(resolver); return(resolver.Result); }
public void computeElevationTest() { Computations computations = new Computations(); double answer = computations.computeElevation(2.7260); Assert.AreEqual(-1.2088, answer); }
public void computeCTest() { Computations computations = new Computations(); double answer = computations.computeC(15.1981, computations.computeDistance(15.1981, -29.1068)); Assert.AreEqual(115.214431518215, answer); }
public void NanTest() { Computations computations = new Computations(); decimal answer = (decimal)computations.convertToDegrees(Math.Acos(0.8431564976)); Assert.AreEqual(12.415, answer); }
public void convertToDegreesTest() { Computations computations = new Computations(); double answer = computations.convertToDegrees(0.942893362561167); Assert.AreEqual(32.5250, answer); }
public void computeDistanceTest() { Computations computations = new Computations(); double answer = computations.computeDistance(15.1981, -29.1068); Assert.AreEqual(32.5250, answer); }
/// <summary> /// we have three lanes per segments. the index should be 1,2,3. ONLY. /// </summary> /// <param name="lindex"></param> public void ChangeLaneRandomly() { Dispatcher.Invoke((Action) delegate { int lanConut = CurrentLane.MyRoadSegment.LanesCount; if (lanConut > 2) { RoadSegment rs = CurrentLane.MyRoadSegment; LaneUi prevLane = CurrentLane; LaneUi newlane = null; if (prevLane.LaneDirection == Direction.N) { newlane = rs.Lanes[LaneIndex.RandomLaneIndex.North(rs.LanesCount)]; prevLane.LaneVehicleAndQueue.RemoveFromLane(this); this.CurrentLane = newlane; this.Margin = new Thickness(newlane.MyCenterLeft, this.Margin.Top, 0, 0); this.SetVehicleDirection(Direction.N); } else if (prevLane.LaneDirection == Direction.S) { newlane = rs.Lanes[LaneIndex.RandomLaneIndex.South(rs.LanesCount)]; prevLane.LaneVehicleAndQueue.RemoveFromLane(this); this.CurrentLane = newlane; this.Margin = new Thickness(newlane.MyCenterLeft, this.Margin.Top, 0, 0); this.SetVehicleDirection(Direction.S); } else if (prevLane.LaneDirection == Direction.E) { newlane = rs.Lanes[LaneIndex.RandomLaneIndex.East(rs.LanesCount)]; prevLane.LaneVehicleAndQueue.RemoveFromLane(this); this.CurrentLane = newlane; this.Margin = new Thickness(this.Margin.Left, newlane.MyCenterTop, 0, 0); this.SetVehicleDirection(Direction.E); } else if (prevLane.LaneDirection == Direction.W) { newlane = rs.Lanes[LaneIndex.RandomLaneIndex.West(rs.LanesCount)]; prevLane.LaneVehicleAndQueue.RemoveFromLane(this); this.CurrentLane = newlane; this.Margin = new Thickness(this.Margin.Left, newlane.MyCenterTop, 0, 0); this.SetVehicleDirection(Direction.W); } // change my speed to random. double instanceSpeed = Computations.GetTimeIntervalInSecond(Computations.RandomSpeedkmh(CurrentLane.MyRoadSegment)); // slow the speed. InstantaneousSpeed = instanceSpeed; // display: prevLane._MainWindow.Dispatcher.Invoke(new Action(() => prevLane.lbl_info.Text = prevLane.LaneVehicleAndQueue.CountInLane.ToString()), DispatcherPriority.Send); } }); }
public void PrecomputeReflectionVector() { Plane shape = new Plane(); Ray r = new Ray(Tuple.Point(0, 1, -1), Tuple.Vector(0, -Math.Sqrt(2) / 2, Math.Sqrt(2) / 2)); Intersection i = new Intersection(Math.Sqrt(2), shape); Computations comps = Computations.PrepareComputations(i, r); Assert.AreEqual(comps.reflectv, Tuple.Vector(0, Math.Sqrt(2) / 2, Math.Sqrt(2) / 2)); }
public void PrepareComputationsOutside() { Ray r = new Ray(Tuple.Point(0, 0, -5), Tuple.Vector(0, 0, 1)); Sphere shape = new Sphere(); Intersection i = new Intersection(4, shape); Computations comps = Computations.PrepareComputations(i, r); Assert.IsFalse(comps.inside); }
public void ShouldPrecomputeReflectionVector() { var shape = new XZPlane(); var r = CreateRay(CreatePoint(0, 1, -1), CreateVector(0, -Sqrt(2) / 2, Sqrt(2) / 2)); var i = new Intersection(Sqrt(2), shape); var comps = Computations.Prepare(i, r); AssertActualEqualToExpected(comps.ReflectV, CreateVector(0, Sqrt(2) / 2, Sqrt(2) / 2)); }
public void ShouldComputeSchlickApproximationUnderTotalInternalReflection() { var shape = Sphere.CreateGlass(); var r = new Ray(CreatePoint(0, 0, Sqrt(2) / 2), CreateVector(0, 1, 0)); var xs = Intersection.CreateList((-Sqrt(2) / 2, shape), (Sqrt(2) / 2, shape)); var comps = Computations.Prepare(xs[1], r, xs); var reflectance = comps.GetSchlickReflectance(); reflectance.Should().BeApproximately(1, Tolerance); }
public void ShouldIndicateWhenIntersectionOccursOnTheOutside() { var r = CreateRay(CreatePoint(0, 0, -5), CreateVector(0, 0, 1)); var shape = new Sphere(); var i = new Intersection(4, shape); var comps = Computations.Prepare(i, r); comps.Inside.Should().Be(false); }
public void ShouldComputeSchlickApproximationWithSmallAngleAndN2GreaterThanN1() { var shape = Sphere.CreateGlass(); var r = new Ray(CreatePoint(0, .99f, -2), CreateVector(0, 0, 1)); var xs = Intersection.CreateList((1.8589f, shape)); var comps = Computations.Prepare(xs[0], r, xs); var reflectance = comps.GetSchlickReflectance(); reflectance.Should().BeApproximately(0.48873f, Tolerance); }
public void ShouldComputeSchlickApproximationWithPerpendicularViewingAngle() { var shape = Sphere.CreateGlass(); var r = new Ray(CreatePoint(0, 0, 0), CreateVector(0, 1, 0)); var xs = Intersection.CreateList((-1, shape), (1, shape)); var comps = Computations.Prepare(xs[1], r, xs); var reflectance = comps.GetSchlickReflectance(); reflectance.Should().BeApproximately(0.04f, Tolerance); }
public void TestZeroIfEmpty() { var computator = new Computations(); //Given string emptyString = string.Empty; //When var result = computator.Calculate(emptyString); //Than Assert.Equal(0, result, 5); }