First time here? Check out the Help page!
| 1 | initial version |
I can answer as to the why.
OpenStudio SDK code is C++, period. The Ruby and Python bindings are (almost) automagically generated via SWIG (Simplified Wrapper Interface Generator).
SWIG will create a target language wrapper class for class objects. This is the case for Point3d.
Your confusion here is that Point3dVector is NOT a class. It's an alias (typedef) to std::vector<Point3d>.
https://github.com/NREL/OpenStudio/blob/e1a72e0ab79aa6768bfd4104dcf1462b03d34b69/src/utilities/geometry/Point3d.hpp#L79
// vector of Point3d
using Point3dVector = std::vector<Point3d>;
We tell SWIG to handle it here. SWIG has logic to handle collections such as std::vector<T>, and will result in a Ruby Array[wrapper<T>] or Python tuple[wrapper<T>]
| 2 | No.2 Revision |
I can answer as to the why.
OpenStudio SDK code is C++, period. The Ruby and Python bindings are (almost) automagically generated via SWIG (Simplified Wrapper Interface Generator).
SWIG will create a target language shallow wrapper class for class objects. This is the case for Point3d.
TL;DR: it creates a Python Point3d class that will basically forward to native C++ library, so it "acts" like it.
Your confusion here is that Point3dVector is generally NOT a class. It's an alias (typedef) to std::vector<Point3d>.
https://github.com/NREL/OpenStudio/blob/e1a72e0ab79aa6768bfd4104dcf1462b03d34b69/src/utilities/geometry/Point3d.hpp#L79
// vector of Point3d
using Point3dVector = std::vector<Point3d>;
SWIG has logic to handle return type collections such as std::vector<T>, and will result in a Ruby Array[wrapper<T>] or Python tuple[wrapper<T>] for convenience (see Note 1)
We still tell SWIG to handle it here, meaning that you also have a shallow wrapper class in your target language that acts like a std::vector.
Note 1: With python, tuples are immutable, and you probably hit that too. What you may not have noticed is that the ruby Array returned is frozen. SWIG has logic to handle collections such as std::vector<T>, and will result in a Ruby Array[wrapper<T>] or Python tuple[wrapper<T>]
m = exampleModel
s = m.getSurfaces.first
vertices = s.vertices
vertices[0] = "hello"
FrozenError: can't modify frozen Array: [#<OpenStudio::Point3d:0x00007d30e8f42360 @__swigtype__="_p_openstudio__Point3d">, #<OpenStudio::Point3d:0x00007d30e8f42338 @__swigtype__="_p_openstudio__Point3d">, #<OpenStudio::Point3d:0x00007d30e8f42310 @__swigtype__="_p_openstudio__Point3d">, #<OpenStudio::Point3d:0x00007d30e8f422e8 @__swigtype__="_p_openstudio__Point3d">] (FrozenError)
| 3 | No.3 Revision |
I can answer as to the why.
OpenStudio SDK code is C++, period. The Ruby and Python bindings are (almost) automagically generated via SWIG (Simplified Wrapper Interface Generator).
SWIG will create a target language shallow wrapper class for class objects. This is the case for Point3d.
TL;DR: it creates a Python Point3d class that will basically forward to native C++ library, so it "acts" like it.
Your confusion here is that Point3dVector is generally NOT a class. It's an alias (typedef) to std::vector<Point3d>.
https://github.com/NREL/OpenStudio/blob/e1a72e0ab79aa6768bfd4104dcf1462b03d34b69/src/utilities/geometry/Point3d.hpp#L79
// vector of Point3d
using Point3dVector = std::vector<Point3d>;
SWIG has logic to handle return type collections such as std::vector<T>, and will result in a Ruby Array[wrapper<T>] or Python tuple[wrapper<T>] for convenience (see Note 1)
We still tell SWIG to handle it here, meaning that you also have a shallow wrapper class in your target language that acts like a std::vector.
Note 1: With python, tuples are immutable, and you you've probably hit that too. a TypeError: 'tuple' object does not support item assignment already.
What you may not have noticed is that the ruby Array returned is frozen. Try this for eg:
m = exampleModel
s = m.getSurfaces.first
vertices = s.vertices
vertices[0] = "hello"
FrozenError: can't modify frozen Array: [#<OpenStudio::Point3d:0x00007d30e8f42360 @__swigtype__="_p_openstudio__Point3d">, #<OpenStudio::Point3d:0x00007d30e8f42338 @__swigtype__="_p_openstudio__Point3d">, #<OpenStudio::Point3d:0x00007d30e8f42310 @__swigtype__="_p_openstudio__Point3d">, #<OpenStudio::Point3d:0x00007d30e8f422e8 @__swigtype__="_p_openstudio__Point3d">] (FrozenError)
| 4 | No.4 Revision |
I can answer as to the why.
OpenStudio SDK code is C++, period. The Ruby and Python bindings are (almost) automagically generated via SWIG (Simplified Wrapper Interface Generator).
SWIG will create a target language shallow wrapper class for class objects. This is the case for Point3d.
TL;DR: it creates a Python Point3d class that will basically forward to native C++ library, so it "acts" like it.
Your confusion here is that Point3dVector is generally NOT a class. It's an alias (typedef) to std::vector<Point3d>.
https://github.com/NREL/OpenStudio/blob/e1a72e0ab79aa6768bfd4104dcf1462b03d34b69/src/utilities/geometry/Point3d.hpp#L79
// vector of Point3d
using Point3dVector = std::vector<Point3d>;
SWIG has logic to handle return type collections such as std::vector<T>, and will result in a Ruby Array[wrapper<T>] or Python tuple[wrapper<T>] for convenience (see Note 1)
We still tell SWIG to handle it here, meaning that you also have a shallow wrapper class in your target language that acts like a std::vector.
Note 1: With python, tuples are immutable, and you've probably hit a TypeError: 'tuple' object does not support item assignment already.
What you may not have noticed is that the ruby Array returned is frozen. Try this for eg:
m = exampleModel
s = m.getSurfaces.first
vertices = s.vertices
raise unless vertices.class == Array
raise unless vertices.frozen?
vertices[0] = "hello"
FrozenError: can't modify frozen Array: [#<OpenStudio::Point3d:0x00007d30e8f42360 @__swigtype__="_p_openstudio__Point3d">, #<OpenStudio::Point3d:0x00007d30e8f42338 @__swigtype__="_p_openstudio__Point3d">, #<OpenStudio::Point3d:0x00007d30e8f42310 @__swigtype__="_p_openstudio__Point3d">, #<OpenStudio::Point3d:0x00007d30e8f422e8 @__swigtype__="_p_openstudio__Point3d">] (FrozenError)