| 1158 | return bv_variable_create_float(0.0f); |
| 1159 | } |
| 1160 | bv_variable lib_common_clamp(bv_program* prog, u8 count, bv_variable* args) |
| 1161 | { |
| 1162 | /* clamp(genType, genType, genType), clamp(genType, float, float), also for genIType and genUType */ |
| 1163 | if (count == 3) { |
| 1164 | if (args[0].type == bv_type_object) { |
| 1165 | bv_object* vec = bv_variable_get_object(args[0]); |
| 1166 | |
| 1167 | // using: genType, float, genDType, double |
| 1168 | if (vec->prop[0].type == bv_type_float) |
| 1169 | { |
| 1170 | glm::vec4 minVal(0.0f), maxVal(0.0f); |
| 1171 | |
| 1172 | // get minBound |
| 1173 | if (args[1].type == bv_type_object) |
| 1174 | minVal = sd::AsVector<4, float>(args[1]); |
| 1175 | else |
| 1176 | minVal = glm::vec4(bv_variable_get_float(bv_variable_cast(bv_type_float, args[1]))); |
| 1177 | |
| 1178 | // get maxBound |
| 1179 | if (args[2].type == bv_type_object) |
| 1180 | maxVal = sd::AsVector<4, float>(args[2]); |
| 1181 | else |
| 1182 | maxVal = glm::vec4(bv_variable_get_float(bv_variable_cast(bv_type_float, args[2]))); |
| 1183 | |
| 1184 | glm::vec4 vecData = glm::clamp(sd::AsVector<4, float>(args[0]), minVal, maxVal); |
| 1185 | |
| 1186 | bv_variable ret = Common::create_vec(prog, bv_type_float, vec->type->props.name_count); |
| 1187 | bv_object* retObj = bv_variable_get_object(ret); |
| 1188 | |
| 1189 | for (u16 i = 0; i < retObj->type->props.name_count; i++) |
| 1190 | retObj->prop[i] = bv_variable_create_float(vecData[i]); |
| 1191 | |
| 1192 | return ret; |
| 1193 | } |
| 1194 | // using: genUType, uint |
| 1195 | else if (vec->prop[0].type == bv_type_uint) |
| 1196 | { |
| 1197 | glm::uvec4 minVal(0u), maxVal(0u); |
| 1198 | |
| 1199 | // get minBound |
| 1200 | if (args[1].type == bv_type_object) |
| 1201 | minVal = sd::AsVector<4, unsigned int>(args[1]); |
| 1202 | else |
| 1203 | minVal = glm::uvec4(bv_variable_get_uint(bv_variable_cast(bv_type_uint, args[1]))); |
| 1204 | |
| 1205 | // get maxBound |
| 1206 | if (args[2].type == bv_type_object) |
| 1207 | maxVal = sd::AsVector<4, unsigned int>(args[2]); |
| 1208 | else |
| 1209 | maxVal = glm::uvec4(bv_variable_get_uint(bv_variable_cast(bv_type_uint, args[2]))); |
| 1210 | |
| 1211 | glm::uvec4 vecData = glm::clamp(sd::AsVector<4, unsigned int>(args[0]), minVal, maxVal); |
| 1212 | |
| 1213 | bv_variable ret = Common::create_vec(prog, bv_type_uint, vec->type->props.name_count); |
| 1214 | bv_object* retObj = bv_variable_get_object(ret); |
| 1215 | |
| 1216 | for (u16 i = 0; i < retObj->type->props.name_count; i++) |
| 1217 | retObj->prop[i] = bv_variable_create_uint(vecData[i]); |
nothing calls this directly
no test coverage detected