This is an automated email from the ASF dual-hosted git repository. carlosrovira pushed a commit to branch develop in repository https://gitbox.apache.org/repos/asf/royale-asjs.git
The following commit(s) were added to refs/heads/develop by this push: new 1b98eee core: add transformValueFromRange function 1b98eee is described below commit 1b98eeeb5559af05d33c92a59187dc48dc98aa97 Author: Carlos Rovira <carlosrov...@apache.org> AuthorDate: Sun Mar 15 22:50:03 2020 +0100 core: add transformValueFromRange function --- .../projects/Core/src/main/royale/CoreClasses.as | 1 + .../apache/royale/utils/transformValueFromRange.as | 42 ++++++++++++++++++++++ 2 files changed, 43 insertions(+) diff --git a/frameworks/projects/Core/src/main/royale/CoreClasses.as b/frameworks/projects/Core/src/main/royale/CoreClasses.as index 6d5d44c..caf1467 100644 --- a/frameworks/projects/Core/src/main/royale/CoreClasses.as +++ b/frameworks/projects/Core/src/main/royale/CoreClasses.as @@ -311,6 +311,7 @@ internal class CoreClasses import org.apache.royale.utils.HSV; HSV; import org.apache.royale.utils.rgbToHsv; rgbToHsv; import org.apache.royale.utils.hsvToHex; hsvToHex; + import org.apache.royale.utils.transformValueFromRange; transformValueFromRange; import org.apache.royale.utils.array.rangeCheck; rangeCheck; diff --git a/frameworks/projects/Core/src/main/royale/org/apache/royale/utils/transformValueFromRange.as b/frameworks/projects/Core/src/main/royale/org/apache/royale/utils/transformValueFromRange.as new file mode 100644 index 0000000..90c9c2c --- /dev/null +++ b/frameworks/projects/Core/src/main/royale/org/apache/royale/utils/transformValueFromRange.as @@ -0,0 +1,42 @@ +//////////////////////////////////////////////////////////////////////////////// +// +// Licensed to the Apache Software Foundation (ASF) under one or more +// contributor license agreements. See the NOTICE file distributed with +// this work for additional information regarding copyright ownership. +// The ASF licenses this file to You under the Apache License, Version 2.0 +// (the "License"); you may not use this file except in compliance with +// the License. You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. +// +//////////////////////////////////////////////////////////////////////////////// +package org.apache.royale.utils +{ + /** + * convert a given a value number from a range, convert to other range and return the new value + * between the new range. + * + * @langversion 3.0 + * @playerversion Flash 10.2 + * @playerversion AIR 2.6 + * @productversion Royale 0.9.7 + */ + public function transformValueFromRange(oldValue:Number, oldMin:Number, oldMax:Number, newMin:Number, newMax:Number):Number + { + var newValue:Number; + var oldRange:Number = oldMax - oldMin; + if (oldRange == 0) { + newValue = newMin; + } else { + var NewRange:Number = newMax - newMin; + newValue = (((oldValue - oldMin) * NewRange) / oldRange) + newMin + } + return newValue + } +}