public void TestSTCPAWithin() { using (var db = new PostGisTestDataConnection(TestDatabaseConnectionString)) { const string Wkt1 = "LINESTRING ZM (0 0 0 1432623600,10 0 5 1432627200)"; db.TestGeometries .Value(g => g.Id, 1) .Value(g => g.Geometry, () => GeometryInput.STGeomFromText(Wkt1)) .Insert(); const string Wkt2 = "LINESTRING ZM (0 2 10 1432623600,12 1 2 1432627200)"; db.TestGeometries .Value(g => g.Id, 2) .Value(g => g.Geometry, () => GeometryInput.STGeomFromText(Wkt2)) .Insert(); db.TestGeometries.Value(g => g.Id, 3) .Value(g => g.Geometry, () => null) .Insert(); Assert.IsTrue(db.TestGeometries.Where(g => g.Id == 1) .Select(g => g.Geometry.STCPAWithin(db.TestGeometries.Where(g2 => g2.Id == 2).Single().Geometry, 2)) .Single()); Assert.IsNull(db.TestGeometries.Where(g => g.Id == 3).Select(g => g.Geometry.STCPAWithin(null, 2)).Single()); Assert.IsTrue(db.Select(() => TrajectoryFunctions.STCPAWithin(Wkt1, Wkt2, 2))); Assert.IsNull(db.Select(() => TrajectoryFunctions.STCPAWithin((string)null, (string)null, 2))); } }
public void TestSTIsValidTrajectory() { using (var db = new PostGisTestDataConnection(TestDatabaseConnectionString)) { db.TestGeometries .Value(g => g.Id, 1) .Value(g => g.Geometry, () => GeometryConstructors.STMakeLine( GeometryConstructors.STMakePointM(0, 0, 1), GeometryConstructors.STMakePointM(0, 1, 2))) .Insert(); db.TestGeometries .Value(g => g.Id, 2) .Value(g => g.Geometry, () => GeometryConstructors.STMakeLine( GeometryConstructors.STMakePointM(0, 0, 1), GeometryConstructors.STMakePointM(0, 1, 0))) .Insert(); db.TestGeometries.Value(g => g.Id, 3) .Value(g => g.Geometry, () => null) .Insert(); Assert.IsTrue(db.TestGeometries .Where(g => g.Id == 1) .Select(g => g.Geometry.STIsValidTrajectory()).Single()); Assert.IsFalse(db.TestGeometries .Where(g => g.Id == 2) .Select(g => g.Geometry.STIsValidTrajectory()) .Single()); Assert.IsNull(db.TestGeometries .Where(g => g.Id == 3) .Select(g => g.Geometry.STIsValidTrajectory()) .Single()); Assert.IsTrue(db.Select(() => TrajectoryFunctions.STIsValidTrajectory("LINESTRING(0 0 0 1,0 1 0 2)"))); Assert.IsFalse(db.Select(() => TrajectoryFunctions.STIsValidTrajectory("POINT(0 0)"))); } }
// Update is called once per frame void Update() { Vector3[] Points = new Vector3[10]; LineRend.SetPositions(Points); // If the max force has been exceeded and the shell hasn't yet been launched... if (CurrentLaunchForce >= MaxLaunchForce && !bFired) { // ... use the max force and launch the shell. CurrentLaunchForce = MaxLaunchForce; Fire(); } // Otherwise, if the fire button has just started being pressed... else if (Input.GetButtonDown("Fire" + PlayerNum)) { // ... reset the fired flag and reset the launch force. bFired = false; CurrentLaunchForce = MinLaunchForce; } // Otherwise, if the fire button is being held and the shell hasn't been launched yet... else if (Input.GetButton("Fire" + PlayerNum) && !bFired) { // Increment the launch force and update the slider. CurrentLaunchForce += ChargeSpeed * Time.deltaTime; Vector3 LanuchForce = CurrentLaunchForce * SpawnLocation.forward; Points = TrajectoryFunctions.GetTrajectoryPath(LanuchForce, SpawnLocation.position, 10, TrajectoryFunctions.TimeToReachTarget(LanuchForce, 15.0f, SpawnLocation.position.y, 0.0f)); LineRend.SetPositions(Points); } // Otherwise, if the fire button is released and the shell hasn't been launched yet... else if (Input.GetButtonUp("Fire" + PlayerNum) && !bFired) { // ... launch the shell. Fire(); } }
public void TestSTClosestPointOfApproach() { using (var db = new PostGisTestDataConnection(TestDatabaseConnectionString)) { const string Wkt1 = "LINESTRING ZM (0 0 0 1432623600,10 0 5 1432627200)"; db.TestGeometries .Value(g => g.Id, 1).Value(g => g.Geometry, () => GeometryInput.STGeomFromText(Wkt1)) .Insert(); const string Wkt2 = "LINESTRING ZM (0 2 10 1432623600,12 1 2 1432627200)"; db.TestGeometries .Value(g => g.Id, 2).Value(g => g.Geometry, () => GeometryInput.STGeomFromText(Wkt2)) .Insert(); db.TestGeometries .Value(g => g.Id, 3).Value(g => g.Geometry, () => null) .Insert(); Assert.AreEqual(1432626331.03448, db.TestGeometries .Where(g => g.Id == 1) .Select(g => g.Geometry.STClosestPointOfApproach(db.TestGeometries .Where(g2 => g2.Id == 2).Single().Geometry)) .Single().Value, 1.0E-3); Assert.IsNull(db.TestGeometries .Where(g => g.Id == 3) .Select(g => g.Geometry.STClosestPointOfApproach(null)) .Single()); Assert.AreEqual( 1432626331.03448, db.Select(() => TrajectoryFunctions.STClosestPointOfApproach(Wkt1, Wkt2)).Value, 1.0E-3); Assert.IsNull(db.Select(() => TrajectoryFunctions.STClosestPointOfApproach((string)null, (string)null))); } }