Nikita Romanenko
6 years ago
8 changed files with 68 additions and 7 deletions
@ -0,0 +1,47 @@ |
|||||
|
using Pores.Models; |
||||
|
using System; |
||||
|
using System.Collections.Generic; |
||||
|
using System.Linq; |
||||
|
|
||||
|
namespace Pores.Controllers |
||||
|
{ |
||||
|
public class ConnectedPoreReportGenerator |
||||
|
{ |
||||
|
public Material Material { get; } |
||||
|
public ReportGenerator ReportGenerator { get; } |
||||
|
|
||||
|
public ConnectedPoreReportGenerator(Material material, ReportGenerator reportGenerator) |
||||
|
{ |
||||
|
Material = material; |
||||
|
ReportGenerator = reportGenerator; |
||||
|
} |
||||
|
|
||||
|
public void CreateReport(IList<Pore> pores, int index) |
||||
|
{ |
||||
|
IList<Tuple<Pore,Pore>> report = new List<Tuple<Pore, Pore>>(); |
||||
|
foreach(Pore p1 in pores) |
||||
|
foreach(Pore p2 in pores) |
||||
|
if (!p1.Equals(p2)) |
||||
|
if (!report.Any(a => a.Item1.Id == p2.Id && a.Item2.Id == p1.Id)) |
||||
|
if (IsTwoPoresConnecting(p1, p2)) |
||||
|
report.Add(Tuple.Create(p1, p2)); |
||||
|
ReportGenerator.Save(report, ReportGenerator.AddOther("report_connected_pores_" + index)); |
||||
|
} |
||||
|
|
||||
|
public double DistanceBetweenTwoPoints(Point3D point1, Point3D point2) |
||||
|
{ |
||||
|
return Math.Sqrt( |
||||
|
Math.Pow(point2.X - point1.X, 2) + |
||||
|
Math.Pow(point2.Y - point1.Y, 2) + |
||||
|
Math.Pow(point2.Z - point1.Z, 2) |
||||
|
); |
||||
|
} |
||||
|
|
||||
|
public bool IsTwoPoresConnecting(Pore pore1, Pore pore2) |
||||
|
{ |
||||
|
if (DistanceBetweenTwoPoints(pore1.Point, pore2.Point) > pore1.Radius + pore2.Radius) |
||||
|
return false; |
||||
|
return true; |
||||
|
} |
||||
|
} |
||||
|
} |
Loading…
Reference in new issue