Skip to content
Snippets Groups Projects
Commit a7e0828c authored by Sandro Christian Wenzel's avatar Sandro Christian Wenzel
Browse files

Bugfix for invalid read in Polyhedron

parent 25b970bf
No related branches found
No related merge requests found
......@@ -254,7 +254,7 @@ Precision UnplacedPolyhedron::SurfaceArea() const
area = GetZSegment(j).outer.GetQuadrilateralArea(0) * GetSideCount();
totArea += area;
if (GetZSegment(j).hasInnerRadius) {
if (GetZSegment(j).inner.size() > 0) {
area = GetZSegment(j).inner.GetQuadrilateralArea(0) * GetSideCount();
totArea += area;
}
......@@ -271,7 +271,7 @@ Precision UnplacedPolyhedron::SurfaceArea() const
Vector3D<Precision> point1 = GetZSegment(0).outer.GetCorners()[0][0];
Vector3D<Precision> point2 = GetZSegment(0).outer.GetCorners()[1][0];
Vector3D<Precision> point3, point4;
if (GetZSegment(0).hasInnerRadius) {
if (GetZSegment(0).inner.size() > 0) {
point3 = GetZSegment(0).inner.GetCorners()[0][0];
point4 = GetZSegment(0).inner.GetCorners()[1][0];
aTop = GetSideCount() * (GetTriangleArea(point1, point2, point3) + GetTriangleArea(point3, point4, point2));
......@@ -286,7 +286,7 @@ Precision UnplacedPolyhedron::SurfaceArea() const
point1 = GetZSegment(GetZSegmentCount() - 1).outer.GetCorners()[2][0];
point2 = GetZSegment(GetZSegmentCount() - 1).outer.GetCorners()[3][0];
if (GetZSegment(GetZSegmentCount() - 1).hasInnerRadius) {
if (GetZSegment(GetZSegmentCount() - 1).inner.size() > 0) {
point3 = GetZSegment(GetZSegmentCount() - 1).inner.GetCorners()[2][0];
point4 = GetZSegment(GetZSegmentCount() - 1).inner.GetCorners()[3][0];
aBottom = GetSideCount() * (GetTriangleArea(point1, point2, point3) + GetTriangleArea(point3, point4, point2));
......@@ -318,7 +318,7 @@ Vector3D<Precision> UnplacedPolyhedron::SamplePointOnSurface() const
area = GetZSegment(j).outer.GetQuadrilateralArea(0);
totArea += area * GetSideCount();
aVector1.push_back(area);
if (GetZSegment(j).hasInnerRadius) {
if (GetZSegment(j).inner.size() > 0) {
area = GetZSegment(j).inner.GetQuadrilateralArea(0);
totArea += area * GetSideCount();
aVector2.push_back(area);
......@@ -340,7 +340,7 @@ Vector3D<Precision> UnplacedPolyhedron::SamplePointOnSurface() const
Vector3D<Precision> point1 = GetZSegment(0).outer.GetCorners()[0][0];
Vector3D<Precision> point2 = GetZSegment(0).outer.GetCorners()[1][0];
Vector3D<Precision> point3, point4;
if (GetZSegment(0).hasInnerRadius) {
if (GetZSegment(0).inner.size() > 0) {
point3 = GetZSegment(0).inner.GetCorners()[0][0];
point4 = GetZSegment(0).inner.GetCorners()[1][0];
aTop = GetSideCount() * (GetTriangleArea(point1, point2, point3) + GetTriangleArea(point3, point4, point2));
......@@ -353,7 +353,7 @@ Vector3D<Precision> UnplacedPolyhedron::SamplePointOnSurface() const
point1 = GetZSegment(GetZSegmentCount() - 1).outer.GetCorners()[2][0];
point2 = GetZSegment(GetZSegmentCount() - 1).outer.GetCorners()[3][0];
if (GetZSegment(GetZSegmentCount() - 1).hasInnerRadius) {
if (GetZSegment(GetZSegmentCount() - 1).inner.size() > 0) {
point3 = GetZSegment(GetZSegmentCount() - 1).inner.GetCorners()[2][0];
point4 = GetZSegment(GetZSegmentCount() - 1).inner.GetCorners()[3][0];
aBottom = GetSideCount() * (GetTriangleArea(point1, point2, point3) + GetTriangleArea(point3, point4, point2));
......@@ -379,7 +379,7 @@ Vector3D<Precision> UnplacedPolyhedron::SamplePointOnSurface() const
point1 = GetZSegment(GetZSegmentCount() - 1).outer.GetCorners()[2][Flag];
point2 = GetZSegment(GetZSegmentCount() - 1).outer.GetCorners()[3][Flag];
// Avoid generating points on degenerated triangles
if (GetZSegment(GetZSegmentCount() - 1).hasInnerRadius) {
if (GetZSegment(GetZSegmentCount() - 1).inner.size() > 0) {
point3 = GetZSegment(GetZSegmentCount() - 1).inner.GetCorners()[2][Flag];
point4 = GetZSegment(GetZSegmentCount() - 1).inner.GetCorners()[3][Flag];
if ((point4 - point3).Mag2() < kTolerance || RNG::Instance().uniform(0.0, 1.0) < 0.5)
......@@ -395,7 +395,7 @@ Vector3D<Precision> UnplacedPolyhedron::SamplePointOnSurface() const
point1 = GetZSegment(0).outer.GetCorners()[0][Flag];
point2 = GetZSegment(0).outer.GetCorners()[1][Flag];
if (GetZSegment(0).hasInnerRadius) {
if (GetZSegment(0).inner.size() > 0) {
point3 = GetZSegment(0).inner.GetCorners()[0][Flag];
point4 = GetZSegment(0).inner.GetCorners()[1][Flag];
// Avoid generating points on degenerated triangles
......@@ -476,7 +476,7 @@ Precision UnplacedPolyhedron::Capacity() const
Vector3D<Precision> d = outercorners[3][0];
Precision volume = VolumeHelperFunc(a, b, c, d); // outer volume
if (GetZSegment(j).hasInnerRadius) {
if (GetZSegment(j).inner.size() > 0) {
if (GetZSegment(j).inner.size() > 0) {
auto innercorners = GetZSegment(j).inner.GetCorners();
a = innercorners[0][0];
......@@ -526,7 +526,7 @@ void UnplacedPolyhedron::PrintSegments() const
fPoly.fZSegments[i].phi.Print();
printf("\n");
}
if (fPoly.fZSegments[i].hasInnerRadius) {
if (fPoly.fZSegments[i].inner.size() > 0) {
printf(" Inner: ");
fPoly.fZSegments[i].inner.Print();
printf("\n");
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment