Java Array Combine combineAlpha(float[] partsAlpha, int partsN)

Here you can find the source of combineAlpha(float[] partsAlpha, int partsN)

Description

Combine multiple alpha values.

License

Apache License

Parameter

Parameter Description
partsAlpha alpha values.
partsN number of values.

Return

combined alpha

Declaration

public static float combineAlpha(float[] partsAlpha, int partsN) 

Method Source Code

//package com.java2s;
//License from project: Apache License 

public class Main {
    /**/*from  w w  w.j a va 2 s  .  co  m*/
     * Combine multiple alpha values.
     * 
     * @param partsAlpha
     *            alpha values.
     * @param partsN
     *            number of values.
     * @return combined alpha
     */
    public static float combineAlpha(float[] partsAlpha, int partsN) {
        float sumAlpha = 0.f;
        int count = 0;

        for (int i = 0; i < partsN; i++) {
            if (!Float.isNaN(partsAlpha[i])) {
                sumAlpha += partsAlpha[i];
                count++;
            }
        }

        if (count > 0) {
            return sumAlpha / count;
        } else {
            return 0.f;
        }
    }
}

Related

  1. combine(int size, Object[]... arrays)
  2. combine(int[][] arr, int[] terms)
  3. combine(Object[] array1, Object[] array2, Object[] combinedArray)
  4. combine(Object[] first, Object[] last)
  5. combine(Object[] objects, String glue)
  6. combineArrays(final Object[] array1, final Object[] array2, final Object[] targetArray)
  7. combineArrays(float[]... arrays)
  8. combineByteArray(byte[] one, byte[] two)
  9. combineChannels(int[][] a, int[][] r, int[][] g, int[][] b, int[][] pixels)