| 1891 | } |
| 1892 | |
| 1893 | std::vector<SubSurface> Surface_Impl::createSubSurfaces(const std::vector<std::vector<Point3d>>& faces, double inset, |
| 1894 | const boost::optional<ConstructionBase>& construction) { |
| 1895 | std::vector<SubSurface> result; |
| 1896 | |
| 1897 | double tol = 0.0254; |
| 1898 | |
| 1899 | if (!this->subSurfaces().empty()) { |
| 1900 | return result; |
| 1901 | } |
| 1902 | |
| 1903 | if (this->adjacentSurface()) { |
| 1904 | return result; |
| 1905 | } |
| 1906 | |
| 1907 | boost::optional<Point3d> centroid = this->centroid(); |
| 1908 | if (!centroid) { |
| 1909 | return result; |
| 1910 | } |
| 1911 | |
| 1912 | Point3dVector vertices = this->vertices(); |
| 1913 | Point3dVector insetVertices = moveVerticesTowardsPoint(vertices, *centroid, inset); |
| 1914 | |
| 1915 | Transformation transformation = Transformation::alignFace(vertices); |
| 1916 | Transformation inverseTransformation = transformation.inverse(); |
| 1917 | Point3dVector insetFaceVertices = inverseTransformation * insetVertices; |
| 1918 | |
| 1919 | // boost polygon wants vertices in clockwise order, insetFaceVertices must be reversed |
| 1920 | std::reverse(insetFaceVertices.begin(), insetFaceVertices.end()); |
| 1921 | |
| 1922 | Model model = this->model(); |
| 1923 | auto surface = getObject<Surface>(); |
| 1924 | for (const std::vector<Point3d>& face : faces) { |
| 1925 | Point3dVector faceVertices = inverseTransformation * face; |
| 1926 | |
| 1927 | // boost polygon wants vertices in clockwise order, faceVertices must be reversed |
| 1928 | std::reverse(faceVertices.begin(), faceVertices.end()); |
| 1929 | |
| 1930 | boost::optional<IntersectionResult> intersection = openstudio::intersect(faceVertices, insetFaceVertices, tol); |
| 1931 | if (intersection) { |
| 1932 | Point3dVector intersectionVertices = intersection->polygon1(); |
| 1933 | |
| 1934 | std::vector<std::vector<Point3d>> allNewFaceVertices; |
| 1935 | if (intersectionVertices.size() <= 4) { |
| 1936 | allNewFaceVertices.push_back(intersectionVertices); |
| 1937 | } else { |
| 1938 | std::vector<std::vector<Point3d>> holes; |
| 1939 | allNewFaceVertices = computeTriangulation(intersectionVertices, holes, tol); |
| 1940 | } |
| 1941 | |
| 1942 | // TODO: I think the copy makes sense here |
| 1943 | for (Point3dVector newFaceVertices : allNewFaceVertices) { |
| 1944 | |
| 1945 | std::reverse(newFaceVertices.begin(), newFaceVertices.end()); |
| 1946 | |
| 1947 | Point3dVector newVertices = transformation * newFaceVertices; |
| 1948 | try { |
| 1949 | |
| 1950 | SubSurface subSurface(newVertices, model); |