-
Notifications
You must be signed in to change notification settings - Fork 225
Description
When I tried to read an ifc file that had a 2-coordinate IfcCartesianPoint #61=IFCCARTESIANPOINT((0.075,12.));, ifcpluplus read it as a 3-coordinate IfcCartesianPoint in the IfcCartesianPoint object, and when writing this object back to disk, it also wrote a 3-coordinate IFCCARTESIANPOINT: #61=IFCCARTESIANPOINT((0.075,12.,0.));.
There are some polylines that must have 2 coordinates (2 dimensions), according to the standard IFC scheme, for example in the case of the closed polygonal defined in IfcArbitraryClosedProfileDef used to generate the solid with IfcExtrudedAreaSolid, as explained in this issue #301.
So to fix this I added a modification to the readRealArray function defined in ReaderUtil.cpp, so that the IFC standard is still followed when reading an IFC file with 2-dimensional IfcCartesian, as shown below:
void readRealArray( const std::string& str, double(&vec)[3] )
{
const char* ch = str.c_str();
const size_t argsize = str.size();
if (argsize == 0)
{
return;
}
size_t i = 0;
size_t last_token = 0;
while (i < argsize)
{
if (ch[i] == '(')
{
++i;
last_token = i;
break;
}
++i;
}
short idx = 0;
while (i < argsize)
{
if (ch[i] == ',')
{
if (idx < 3)
{
vec[idx] = std::stod(str.substr(last_token, i - last_token));
}
++idx;
last_token = i + 1;
}
else if (ch[i] == ')')
{
if (idx < 3)
{
vec[idx] = std::stod(str.substr(last_token, i - last_token));
}
// If the read IfcCartesianPoint is 2-dimensional, the z coordinate is defined as quiet_NaN
if (idx == 1)
vec[2] = std::numeric_limits<double>::quiet_NaN();
return;
}
++i;
}
}
Best Regards.