void CLogic::quantize_to_allowed_states( CValue &value, const value_set &allowed_states ) const { const CValue *nearest_allowed_state = NULL; float distance_to_current = 0; float distance_to_nearest_allowed_state = 0; bool first = true; for( value_set::const_iterator i = allowed_states.begin(); i != allowed_states.end(); i++ ) { const CValue *allowed_state = *i; if( value.get_type() != allowed_state->get_type() ) { INTEGRA_TRACE_ERROR << "Value type mismatch whilst quantizing to allowed states"; continue; } distance_to_current = value.get_distance( *allowed_state ); if( first || distance_to_current < distance_to_nearest_allowed_state ) { distance_to_nearest_allowed_state = distance_to_current; nearest_allowed_state = allowed_state; first = false; } } if( !nearest_allowed_state ) { INTEGRA_TRACE_ERROR << "failed to quantize to allowed states - allowed states is empty"; return; } assert( nearest_allowed_state->get_type() == value.get_type() ); value = *nearest_allowed_state; }