本文整理汇总了C#中Path.Add方法的典型用法代码示例。如果您正苦于以下问题:C# Path.Add方法的具体用法?C# Path.Add怎么用?C# Path.Add使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Path
的用法示例。
在下文中一共展示了Path.Add方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: Main
static void Main()
{
//Create some path
Path path = new Path();
path.Add(Point3D.Origin);
path.Add(new Point3D(0, 0, 5));
path.Add(new Point3D(0, 0, 10));
path.Add(new Point3D(5, 5, 10));
//Save it to a file
string file = "../../path.txt";
PathStorage.Save(path, file);
//Read it from the file
Path pathFromFile = PathStorage.Load(file);
//Check if the initial path and the one that we read from file are same
bool areTheSame = true;
for (int i = 0; i < path.Length; i++)
{
if (path[i].X != pathFromFile[i].X || path[i].Y != pathFromFile[i].Y || path[i].Z != pathFromFile[i].Z)
{
areTheSame = false;
break;
}
}
Console.WriteLine(areTheSame);
}
示例2: Main
static void Main(string[] args)
{
Point3d pointOne = new Point3d();
pointOne.PointX = 0.5;
pointOne.PointY = 0.5;
pointOne.PointZ = 0.5;
Console.WriteLine(pointOne);
Console.WriteLine(Point3d.ZeroPosition);
Point3d pointTwo = new Point3d(1.5, 1.5, 1.5);
Console.WriteLine(pointTwo);
Console.WriteLine("Distance between");
Console.WriteLine(Distance.DistanceBetween(pointOne, pointTwo));
Path path = new Path();
path.Add(pointOne);
path.Add(pointTwo);
PathStorage.SavePath(path, @"../../Points3d.txt");
path.Clear();
Console.WriteLine();
Console.WriteLine("Path is saved and then cleared");
path = PathStorage.LoadPath(@"../../Points3d.txt");
Console.WriteLine();
Console.WriteLine("After reloading again from file");
Console.WriteLine();
foreach (var item in path.Paths)
{
Console.WriteLine(item);
}
}
示例3: Main
static void Main()
{
Point3D p = new Point3D();
Point3D q = new Point3D(4, 4, 4);
Console.WriteLine(CalcDistance.Distance(p, q));
Path path = new Path();
path.Add(p);
path.Add(q);
path.Add(new Point3D(9, 9, 9));
Console.WriteLine(path.ToString());
PathStorage.Save(path);
Console.WriteLine(PathStorage.Load().ToString());
}
示例4: Main
static void Main()
{
Console.WriteLine("Testing 3D Points, Path and Path Storage....\r\n");
Console.WriteLine("Enter a path as a sequence of 3D points (x y z, separated with spaces, one per line)\r\nFinish with 0,0,0 or wrong input");
Path p1 = new Path();
try
{
while (true)
{
Console.Write("Point {0}: ", p1.Count + 1);
string[] coords = Console.ReadLine().Split(' '); // reads each point (X,Y,Z, separated by spaces)
int x = int.Parse(coords[0]);
int y = int.Parse(coords[1]);
int z = int.Parse(coords[2]);
if (x == 0 && y == 0 && z == 0) break; // finishes input on {0,0,0}
p1.Add(x, y, z); // and loads it into the path
// calculates the distance between last two entered points
if (p1.Count > 1) Console.WriteLine("Distance:" + Distance3D.Calc(p1[p1.Count - 1], p1[p1.Count - 2]));
else Console.WriteLine("Distance:" + Distance3D.Calc(p1[p1.Count - 1], Point3D.O));
}
}
catch
{
}
Console.WriteLine("The result is " + p1);
Console.WriteLine("Saves to text file and reads back to another variable");
PathStorage.Write(p1, "..\\..\\testpath.txt");
Path p2 = PathStorage.Read("..\\..\\testpath.txt");
Console.WriteLine(p2);
Console.WriteLine("press Enter to finish");
Console.ReadLine();
}
示例5: LoadPath
public static Path LoadPath(string fileFullName)
{
if (String.IsNullOrWhiteSpace(fileFullName))
{
throw new ArgumentException("File name cannot be null or empty.");
}
if (!File.Exists(fileFullName))
{
throw new ArgumentException("The specified file doesn't exist in the local file system.");
}
Path points = new Path();
using (StreamReader fileReader = new StreamReader(fileFullName))
{
string line;
while ((line = fileReader.ReadLine()) != null)
{
string[] coordinates = line.Split(new char[] { ' ' }, StringSplitOptions.RemoveEmptyEntries);
double x, y, z;
if (coordinates.Length == 3 &&
Double.TryParse(coordinates[0], out x) &&
Double.TryParse(coordinates[1], out y) &&
Double.TryParse(coordinates[2], out z))
{
Point3D point = new Point3D(x, y, z);
points.Add(point);
}
}
}
return points;
}
示例6: Main
static void Main()
{
Console.WriteLine("# Testing distance");
Console.WriteLine("Distance: {0}", Distance.Calculate(new Point3D(1, 1, 1), Point3D.Zero));
Console.WriteLine("# Testing path");
Path path = new Path(
Point3D.Zero,
new Point3D(1, 1, 1),
new Point3D(1, 2, 1),
new Point3D(1, 3, 1)
);
Console.WriteLine(path);
Console.WriteLine("# Testing add/remove");
Console.WriteLine(path.Add(new Point3D(1, 2, 4)).Remove(new Point3D(1, 1, 1)));
Console.WriteLine("# Testing path storage");
PathStorage.Write(path, "../../input.txt");
Console.WriteLine(PathStorage.Load("../../input.txt"));
}
示例7: Main
static void Main()
{
Point3D a = new Point3D(1, 2, 3);
Console.WriteLine("Point({0})", a); // point A
Point3D b = Point3D.Center;
Console.WriteLine("Point({0}, {1}, {2})", b.X, b.Y, b.Z); // point O
Console.WriteLine("Distance: {0}", Distance.Calculate(a, b)); // Calculate distance
// Path of points
Path path = new Path(new Point3D(1, 1, 1), new Point3D(2, 2, 2));
path.Add(new Point3D(3, 3, 3));
path.Remove(new Point3D(1, 1, 1));
Console.WriteLine("\nPoints in path (total: {0})\n{1}", path.Count, path);
path.Clear();
// Loads new points from the file
path = PathStorage.Load("../../input.txt");
Console.WriteLine("\nPoints in path (total: {0})\n{1}", path.Count, path);
// Saves the points in output file
PathStorage.Save(path, "../../output.txt");
}
示例8: Main
static void Main(string[] args)
{
Console.WriteLine(Point3D.O);
Path checkPath = new Path("[0,0,0][1, 3, -4]");
checkPath.Add(Point3D.O);
Path probs = new Path("[4,3,5][3,7,8][13,5,2]");
var listOfPaths = new List<Path>();
listOfPaths.Add(probs);
listOfPaths.Add(probs);
listOfPaths.Add(probs);
Console.WriteLine(probs);
PathStorage.SavePaths(listOfPaths, "probs");
var secondListOfPaths = new List<Path>();
secondListOfPaths = PathStorage.LoadPaths("probs");
foreach (var path in secondListOfPaths)
{
Console.WriteLine(path);
}
}
示例9: LoadPath
public static List<Path> LoadPath()
{
List<Path> allPaths=new List<Path>();
using (StreamReader reader = new StreamReader("storage.txt"))
{
string line=reader.ReadLine();
while(line!=null)
{
Path onePath = new Path();
string[] onePointCoords=line.Split(';');
foreach (var point in onePointCoords)
{
string[] coords=point.Split(',');
Point3D aPoint=new Point3D();
aPoint.X=double.Parse(coords[0]);
aPoint.Y=double.Parse(coords[1]);
aPoint.Z=double.Parse(coords[2]);
onePath.Add(aPoint);
}
allPaths.Add(onePath);
line=reader.ReadLine();
}
}
return allPaths;
}
示例10: Main
static void Main()
{
{
Console.WriteLine("# Testing distance");
Console.WriteLine("Distance: {0}", Distance.Calculate(new Point3D(1, 1, 1), Point3D.Zero));
Console.WriteLine();
}
{
Console.WriteLine("# Testing path");
Point3D point = new Point3D(1, 1, 1);
Path path = new Path();
path.Add(point);
path.Add(new Point3D(1, 2, 1));
path.Add(new Point3D(1, 3, 1));
path.Add(Point3D.Zero);
Console.WriteLine(path);
Console.WriteLine();
{
Console.WriteLine("# Testing remove");
path.Remove(point);
Console.WriteLine(path);
Console.WriteLine();
}
{
Console.WriteLine("# Testing path storage");
PathStorage.Write(path);
path = PathStorage.Load();
Console.WriteLine(path);
}
}
}
示例11: smoothPath
public static Path smoothPath(Path inputPath)
{
if (inputPath.Count <= 2) return inputPath;
Path outputPath = new Path();
outputPath.Add(inputPath[0]);
for (int i = 2; i < inputPath.Count - 1; ++i) {
float distance = Vector3.Distance(outputPath[outputPath.Count - 1], inputPath[i]);
// be careful with the direction of the ray
Vector3 direction = (inputPath[i] - outputPath[outputPath.Count - 1]).normalized;
if (Physics.Raycast(outputPath[outputPath.Count - 1], direction, distance, 1 << layerObstacles)) {
outputPath.Add(inputPath[i - 1]);
}
}
outputPath.Add(inputPath[inputPath.Count - 1]);
return outputPath;
}
示例12: Load
// TODO: Optimize bytes
public static Path Load(string file = DefaultFile)
{
Path path = new Path();
foreach (string line in File.ReadAllLines(file))
{
foreach (Match item in Regex.Matches(line, @"X: (\d+), Y: (\d+), Z: (\d+)"))
{
int x = int.Parse(item.Groups[1].Value);
int y = int.Parse(item.Groups[2].Value);
int z = int.Parse(item.Groups[3].Value);
path.Add(new Point3D(x, y, z));
}
}
return path;
}
示例13: Load
public static Path Load()
{
StreamReader reader = new StreamReader(@"d:/text.txt");
Path loadPath = new Path();
using (reader)
{
string line = reader.ReadLine();
while (line != null)
{
string[] extract = line.Split(',');
Point3D pointLoaded = new Point3D();
pointLoaded.X = int.Parse(extract[0].Trim());
pointLoaded.Y = int.Parse(extract[1].Trim());
pointLoaded.Z = int.Parse(extract[2].Trim());
loadPath.Add(pointLoaded);
line = reader.ReadLine();
}
}
return loadPath;
}
示例14: Add_AddsSegment_ForSegment
public void Add_AddsSegment_ForSegment()
{
// Arrange
// Act
var sut = new Path(Point.Unknown);
sut.Add(m_Segment1);
// Assert
Assert.AreEqual(1,
sut.Segments.Count(),
"Count");
Assert.AreEqual(m_Segment1,
sut.Segments.First(),
"First");
Assert.AreEqual(new Distance(1.0),
sut.Distance,
"Distance");
Assert.False(sut.IsUnknown,
"IsUnknown");
}
示例15: LoadPath
// method that loads/saves the path from a file
public static Path LoadPath(string fileName)
{
Path points = new Path();
using (StreamReader reader = new StreamReader(fileName))
{
string line = reader.ReadLine();
while (line != null)
{
string[] linePoints = line.Split(' ');
Struct3DPoint currentPoint = new Struct3DPoint();
currentPoint.X = int.Parse(linePoints[0]);
currentPoint.Y = int.Parse(linePoints[1]);
currentPoint.Z = int.Parse(linePoints[2]);
points.Add(currentPoint);
line = reader.ReadLine();
}
}
return points;
}