@@ -805,30 +805,39 @@ int CLuaColShapeDefs::RemoveColPolygonPoint(lua_State* luaVM)
805
805
return luaL_error (luaVM, argStream.GetFullErrorMessage ());
806
806
}
807
807
808
- std::tuple <float , float > CLuaColShapeDefs::GetColPolygonHeight (CColPolygon* pColPolygon )
808
+ CLuaMultiReturn <float , float > CLuaColShapeDefs::GetColPolygonHeight (CColShape* shape )
809
809
{
810
- float fFloor , fCeil ;
811
- pColPolygon->GetHeight (fFloor , fCeil );
812
- return std::make_tuple (fFloor , fCeil );
810
+ if (shape->GetShapeType () != COLSHAPE_POLYGON)
811
+ {
812
+ throw std::invalid_argument (" Shape must be a polygon" );
813
+ }
814
+
815
+ auto * polygon = static_cast <CColPolygon*>(shape);
816
+
817
+ float floor;
818
+ float ceil;
819
+
820
+ polygon->GetHeight (floor, ceil);
821
+
822
+ return {floor, ceil};
813
823
}
814
824
815
- bool CLuaColShapeDefs::SetColPolygonHeight (CColPolygon* pColPolygon , std::variant<bool , float > floor, std::variant<bool , float > ceil)
825
+ bool CLuaColShapeDefs::SetColPolygonHeight (CColShape* shape , std::variant<bool , float > floor, std::variant<bool , float > ceil)
816
826
{
817
- // bool SetColPolygonHeight ( colshape theColShape, float floor, float ceil )
818
- float fFloor , fCeil ;
827
+ if (shape->GetShapeType () != COLSHAPE_POLYGON)
828
+ {
829
+ throw std::invalid_argument (" Shape must be a polygon" );
830
+ }
819
831
820
- if (std::holds_alternative<bool >(floor))
821
- fFloor = std::numeric_limits<float >::lowest ();
822
- else
823
- fFloor = std::get<float >(floor);
832
+ auto * polygon = static_cast <CColPolygon*>(shape);
824
833
825
- if (std::holds_alternative<bool >(ceil))
826
- fCeil = std::numeric_limits<float >::max ();
827
- else
828
- fCeil = std::get<float >(ceil);
834
+ float lowest = std::holds_alternative<bool >(floor) ? std::numeric_limits<float >::lowest () : std::get<float >(floor);
835
+ float highest = std::holds_alternative<bool >(ceil) ? std::numeric_limits<float >::max () : std::get<float >(ceil);
829
836
830
- if (fFloor > fCeil )
831
- std::swap (fFloor , fCeil );
837
+ if (lowest > highest)
838
+ {
839
+ std::swap (lowest, highest);
840
+ }
832
841
833
- return CStaticFunctionDefinitions::SetColPolygonHeight (pColPolygon, fFloor , fCeil );
842
+ return CStaticFunctionDefinitions::SetColPolygonHeight (polygon, lowest, highest );
834
843
}
0 commit comments