avm1: Shorten integers values
The .0 suffix can be omitted since into() supports integers as well.
This commit is contained in:
parent
38a2650c0e
commit
59970bf7ac
|
@ -60,10 +60,7 @@ pub fn set_distance<'gc>(
|
|||
this: Object<'gc>,
|
||||
args: &[Value<'gc>],
|
||||
) -> Result<Value<'gc>, Error<'gc>> {
|
||||
let distance = args
|
||||
.get(0)
|
||||
.unwrap_or(&4.0.into())
|
||||
.coerce_to_f64(activation)?;
|
||||
let distance = args.get(0).unwrap_or(&4.into()).coerce_to_f64(activation)?;
|
||||
|
||||
if let Some(filter) = this.as_bevel_filter_object() {
|
||||
filter.set_distance(activation.context.gc_context, distance);
|
||||
|
|
|
@ -56,7 +56,7 @@ pub fn set_alpha<'gc>(
|
|||
) -> Result<Value<'gc>, Error<'gc>> {
|
||||
let alpha = args
|
||||
.get(0)
|
||||
.unwrap_or(&0.0.into())
|
||||
.unwrap_or(&0.into())
|
||||
.coerce_to_f64(activation)
|
||||
.map(|x| x.max(0.0).min(1.0))?;
|
||||
|
||||
|
@ -84,10 +84,7 @@ pub fn set_bias<'gc>(
|
|||
this: Object<'gc>,
|
||||
args: &[Value<'gc>],
|
||||
) -> Result<Value<'gc>, Error<'gc>> {
|
||||
let bias = args
|
||||
.get(0)
|
||||
.unwrap_or(&0.0.into())
|
||||
.coerce_to_f64(activation)?;
|
||||
let bias = args.get(0).unwrap_or(&0.into()).coerce_to_f64(activation)?;
|
||||
|
||||
if let Some(filter) = this.as_convolution_filter_object() {
|
||||
filter.set_bias(activation.context.gc_context, bias);
|
||||
|
@ -171,10 +168,7 @@ pub fn set_divisor<'gc>(
|
|||
this: Object<'gc>,
|
||||
args: &[Value<'gc>],
|
||||
) -> Result<Value<'gc>, Error<'gc>> {
|
||||
let divisor = args
|
||||
.get(0)
|
||||
.unwrap_or(&1.0.into())
|
||||
.coerce_to_f64(activation)?;
|
||||
let divisor = args.get(0).unwrap_or(&1.into()).coerce_to_f64(activation)?;
|
||||
|
||||
if let Some(filter) = this.as_convolution_filter_object() {
|
||||
filter.set_divisor(activation.context.gc_context, divisor);
|
||||
|
@ -250,7 +244,7 @@ pub fn set_matrix_x<'gc>(
|
|||
) -> Result<Value<'gc>, Error<'gc>> {
|
||||
let matrix_x = args
|
||||
.get(0)
|
||||
.unwrap_or(&0.0.into())
|
||||
.unwrap_or(&0.into())
|
||||
.coerce_to_i32(activation)
|
||||
.map(|x| x.max(0).min(15))? as u8;
|
||||
|
||||
|
@ -280,7 +274,7 @@ pub fn set_matrix_y<'gc>(
|
|||
) -> Result<Value<'gc>, Error<'gc>> {
|
||||
let matrix_y = args
|
||||
.get(0)
|
||||
.unwrap_or(&0.0.into())
|
||||
.unwrap_or(&0.into())
|
||||
.coerce_to_i32(activation)
|
||||
.map(|x| x.max(0).min(15))? as u8;
|
||||
|
||||
|
|
|
@ -56,7 +56,7 @@ pub fn set_alpha<'gc>(
|
|||
) -> Result<Value<'gc>, Error<'gc>> {
|
||||
let alpha = args
|
||||
.get(0)
|
||||
.unwrap_or(&0.0.into())
|
||||
.unwrap_or(&0.into())
|
||||
.coerce_to_f64(activation)
|
||||
.map(|x| x.max(0.0).min(1.0))?;
|
||||
|
||||
|
@ -113,10 +113,7 @@ pub fn set_component_x<'gc>(
|
|||
this: Object<'gc>,
|
||||
args: &[Value<'gc>],
|
||||
) -> Result<Value<'gc>, Error<'gc>> {
|
||||
let component = args
|
||||
.get(0)
|
||||
.unwrap_or(&0.0.into())
|
||||
.coerce_to_i32(activation)?;
|
||||
let component = args.get(0).unwrap_or(&0.into()).coerce_to_i32(activation)?;
|
||||
|
||||
if let Some(object) = this.as_displacement_map_filter_object() {
|
||||
object.set_component_x(activation.context.gc_context, component);
|
||||
|
@ -142,10 +139,7 @@ pub fn set_component_y<'gc>(
|
|||
this: Object<'gc>,
|
||||
args: &[Value<'gc>],
|
||||
) -> Result<Value<'gc>, Error<'gc>> {
|
||||
let component = args
|
||||
.get(0)
|
||||
.unwrap_or(&0.0.into())
|
||||
.coerce_to_i32(activation)?;
|
||||
let component = args.get(0).unwrap_or(&0.into()).coerce_to_i32(activation)?;
|
||||
|
||||
if let Some(object) = this.as_displacement_map_filter_object() {
|
||||
object.set_component_y(activation.context.gc_context, component);
|
||||
|
@ -271,10 +265,7 @@ pub fn set_scale_x<'gc>(
|
|||
this: Object<'gc>,
|
||||
args: &[Value<'gc>],
|
||||
) -> Result<Value<'gc>, Error<'gc>> {
|
||||
let scale = args
|
||||
.get(0)
|
||||
.unwrap_or(&0.0.into())
|
||||
.coerce_to_f64(activation)?;
|
||||
let scale = args.get(0).unwrap_or(&0.into()).coerce_to_f64(activation)?;
|
||||
|
||||
if let Some(object) = this.as_displacement_map_filter_object() {
|
||||
object.set_scale_x(activation.context.gc_context, scale);
|
||||
|
@ -300,10 +291,7 @@ pub fn set_scale_y<'gc>(
|
|||
this: Object<'gc>,
|
||||
args: &[Value<'gc>],
|
||||
) -> Result<Value<'gc>, Error<'gc>> {
|
||||
let scale = args
|
||||
.get(0)
|
||||
.unwrap_or(&0.0.into())
|
||||
.coerce_to_f64(activation)?;
|
||||
let scale = args.get(0).unwrap_or(&0.into()).coerce_to_f64(activation)?;
|
||||
|
||||
if let Some(object) = this.as_displacement_map_filter_object() {
|
||||
object.set_scale_y(activation.context.gc_context, scale);
|
||||
|
|
|
@ -60,7 +60,7 @@ pub fn set_alpha<'gc>(
|
|||
) -> Result<Value<'gc>, Error<'gc>> {
|
||||
let alpha = args
|
||||
.get(0)
|
||||
.unwrap_or(&1.0.into())
|
||||
.unwrap_or(&1.into())
|
||||
.coerce_to_f64(activation)
|
||||
.map(|x| x.max(0.0).min(1.0))?;
|
||||
|
||||
|
@ -88,10 +88,7 @@ pub fn set_distance<'gc>(
|
|||
this: Object<'gc>,
|
||||
args: &[Value<'gc>],
|
||||
) -> Result<Value<'gc>, Error<'gc>> {
|
||||
let distance = args
|
||||
.get(0)
|
||||
.unwrap_or(&4.0.into())
|
||||
.coerce_to_f64(activation)?;
|
||||
let distance = args.get(0).unwrap_or(&4.into()).coerce_to_f64(activation)?;
|
||||
|
||||
if let Some(object) = this.as_drop_shadow_filter_object() {
|
||||
object.set_distance(activation.context.gc_context, distance);
|
||||
|
@ -154,7 +151,7 @@ pub fn set_blur_x<'gc>(
|
|||
) -> Result<Value<'gc>, Error<'gc>> {
|
||||
let blur_x = args
|
||||
.get(0)
|
||||
.unwrap_or(&4.0.into())
|
||||
.unwrap_or(&4.into())
|
||||
.coerce_to_f64(activation)
|
||||
.map(|x| x.max(0.0).min(255.0))?;
|
||||
|
||||
|
@ -184,7 +181,7 @@ pub fn set_blur_y<'gc>(
|
|||
) -> Result<Value<'gc>, Error<'gc>> {
|
||||
let blur_y = args
|
||||
.get(0)
|
||||
.unwrap_or(&4.0.into())
|
||||
.unwrap_or(&4.into())
|
||||
.coerce_to_f64(activation)
|
||||
.map(|x| x.max(0.0).min(255.0))?;
|
||||
|
||||
|
@ -330,7 +327,7 @@ pub fn set_quality<'gc>(
|
|||
) -> Result<Value<'gc>, Error<'gc>> {
|
||||
let quality = args
|
||||
.get(0)
|
||||
.unwrap_or(&1.0.into())
|
||||
.unwrap_or(&1.into())
|
||||
.coerce_to_i32(activation)
|
||||
.map(|x| x.max(0).min(15))?;
|
||||
|
||||
|
@ -360,7 +357,7 @@ pub fn set_strength<'gc>(
|
|||
) -> Result<Value<'gc>, Error<'gc>> {
|
||||
let strength = args
|
||||
.get(0)
|
||||
.unwrap_or(&1.0.into())
|
||||
.unwrap_or(&1.into())
|
||||
.coerce_to_f64(activation)
|
||||
.map(|x| x.max(0.0).min(255.0))?;
|
||||
|
||||
|
|
|
@ -59,10 +59,7 @@ pub fn set_distance<'gc>(
|
|||
this: Object<'gc>,
|
||||
args: &[Value<'gc>],
|
||||
) -> Result<Value<'gc>, Error<'gc>> {
|
||||
let distance = args
|
||||
.get(0)
|
||||
.unwrap_or(&4.0.into())
|
||||
.coerce_to_f64(activation)?;
|
||||
let distance = args.get(0).unwrap_or(&4.into()).coerce_to_f64(activation)?;
|
||||
|
||||
if let Some(object) = this.as_gradient_bevel_filter_object() {
|
||||
object.set_distance(activation.context.gc_context, distance);
|
||||
|
@ -287,7 +284,7 @@ pub fn set_blur_x<'gc>(
|
|||
) -> Result<Value<'gc>, Error<'gc>> {
|
||||
let blur_x = args
|
||||
.get(0)
|
||||
.unwrap_or(&4.0.into())
|
||||
.unwrap_or(&4.into())
|
||||
.coerce_to_f64(activation)
|
||||
.map(|x| x.max(0.0).min(255.0))?;
|
||||
|
||||
|
@ -317,7 +314,7 @@ pub fn set_blur_y<'gc>(
|
|||
) -> Result<Value<'gc>, Error<'gc>> {
|
||||
let blur_y = args
|
||||
.get(0)
|
||||
.unwrap_or(&4.0.into())
|
||||
.unwrap_or(&4.into())
|
||||
.coerce_to_f64(activation)
|
||||
.map(|x| x.max(0.0).min(255.0))?;
|
||||
|
||||
|
@ -347,7 +344,7 @@ pub fn set_strength<'gc>(
|
|||
) -> Result<Value<'gc>, Error<'gc>> {
|
||||
let strength = args
|
||||
.get(0)
|
||||
.unwrap_or(&1.0.into())
|
||||
.unwrap_or(&1.into())
|
||||
.coerce_to_f64(activation)
|
||||
.map(|x| x.max(0.0).min(255.0))?;
|
||||
|
||||
|
@ -377,7 +374,7 @@ pub fn set_quality<'gc>(
|
|||
) -> Result<Value<'gc>, Error<'gc>> {
|
||||
let quality = args
|
||||
.get(0)
|
||||
.unwrap_or(&1.0.into())
|
||||
.unwrap_or(&1.into())
|
||||
.coerce_to_i32(activation)
|
||||
.map(|x| x.max(0).min(15))?;
|
||||
|
||||
|
|
|
@ -59,10 +59,7 @@ pub fn set_distance<'gc>(
|
|||
this: Object<'gc>,
|
||||
args: &[Value<'gc>],
|
||||
) -> Result<Value<'gc>, Error<'gc>> {
|
||||
let distance = args
|
||||
.get(0)
|
||||
.unwrap_or(&4.0.into())
|
||||
.coerce_to_f64(activation)?;
|
||||
let distance = args.get(0).unwrap_or(&4.into()).coerce_to_f64(activation)?;
|
||||
|
||||
if let Some(object) = this.as_gradient_glow_filter_object() {
|
||||
object.set_distance(activation.context.gc_context, distance);
|
||||
|
@ -287,7 +284,7 @@ pub fn set_blur_x<'gc>(
|
|||
) -> Result<Value<'gc>, Error<'gc>> {
|
||||
let blur_x = args
|
||||
.get(0)
|
||||
.unwrap_or(&4.0.into())
|
||||
.unwrap_or(&4.into())
|
||||
.coerce_to_f64(activation)
|
||||
.map(|x| x.max(0.0).min(255.0))?;
|
||||
|
||||
|
@ -317,7 +314,7 @@ pub fn set_blur_y<'gc>(
|
|||
) -> Result<Value<'gc>, Error<'gc>> {
|
||||
let blur_y = args
|
||||
.get(0)
|
||||
.unwrap_or(&4.0.into())
|
||||
.unwrap_or(&4.into())
|
||||
.coerce_to_f64(activation)
|
||||
.map(|x| x.max(0.0).min(255.0))?;
|
||||
|
||||
|
@ -347,7 +344,7 @@ pub fn set_strength<'gc>(
|
|||
) -> Result<Value<'gc>, Error<'gc>> {
|
||||
let strength = args
|
||||
.get(0)
|
||||
.unwrap_or(&1.0.into())
|
||||
.unwrap_or(&1.into())
|
||||
.coerce_to_f64(activation)
|
||||
.map(|x| x.max(0.0).min(255.0))?;
|
||||
|
||||
|
@ -377,7 +374,7 @@ pub fn set_quality<'gc>(
|
|||
) -> Result<Value<'gc>, Error<'gc>> {
|
||||
let quality = args
|
||||
.get(0)
|
||||
.unwrap_or(&1.0.into())
|
||||
.unwrap_or(&1.into())
|
||||
.coerce_to_i32(activation)
|
||||
.map(|x| x.max(0).min(15))?;
|
||||
|
||||
|
|
|
@ -396,15 +396,15 @@ mod tests {
|
|||
|
||||
assert_eq!(atan2(activation, math, &[]).unwrap(), f64::NAN.into());
|
||||
assert_eq!(
|
||||
atan2(activation, math, &[1.0.into(), Value::Null]).unwrap(),
|
||||
atan2(activation, math, &[1.into(), Value::Null]).unwrap(),
|
||||
f64::NAN.into()
|
||||
);
|
||||
assert_eq!(
|
||||
atan2(activation, math, &[1.0.into(), Value::Undefined]).unwrap(),
|
||||
atan2(activation, math, &[1.into(), Value::Undefined]).unwrap(),
|
||||
f64::NAN.into()
|
||||
);
|
||||
assert_eq!(
|
||||
atan2(activation, math, &[Value::Undefined, 1.0.into()]).unwrap(),
|
||||
atan2(activation, math, &[Value::Undefined, 1.into()]).unwrap(),
|
||||
f64::NAN.into()
|
||||
);
|
||||
Ok(())
|
||||
|
@ -421,11 +421,11 @@ mod tests {
|
|||
);
|
||||
|
||||
assert_eq!(
|
||||
atan2(activation, math, &[10.0.into()]).unwrap(),
|
||||
atan2(activation, math, &[10.into()]).unwrap(),
|
||||
std::f64::consts::FRAC_PI_2.into()
|
||||
);
|
||||
assert_eq!(
|
||||
atan2(activation, math, &[1.0.into(), 2.0.into()]).unwrap(),
|
||||
atan2(activation, math, &[1.into(), 2.into()]).unwrap(),
|
||||
f64::atan2(1.0, 2.0).into()
|
||||
);
|
||||
Ok(())
|
||||
|
|
|
@ -29,7 +29,7 @@ pub fn get_begin_index<'gc>(
|
|||
{
|
||||
Ok(selection.start().into())
|
||||
} else {
|
||||
Ok((-1.0).into())
|
||||
Ok((-1).into())
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -47,7 +47,7 @@ pub fn get_end_index<'gc>(
|
|||
{
|
||||
Ok(selection.end().into())
|
||||
} else {
|
||||
Ok((-1.0).into())
|
||||
Ok((-1).into())
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -65,7 +65,7 @@ pub fn get_caret_index<'gc>(
|
|||
{
|
||||
Ok(selection.to().into())
|
||||
} else {
|
||||
Ok((-1.0).into())
|
||||
Ok((-1).into())
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -9,7 +9,7 @@ fn locals_into_form_values() {
|
|||
my_locals
|
||||
.set("value1", "string".into(), activation)
|
||||
.unwrap();
|
||||
my_locals.set("value2", 2.0.into(), activation).unwrap();
|
||||
my_locals.set("value2", 2.into(), activation).unwrap();
|
||||
let my_local_values = activation.locals_into_form_values();
|
||||
|
||||
assert_eq!(my_local_values.len(), 2);
|
||||
|
|
Loading…
Reference in New Issue