public abstract class

CurveFit

extends java.lang.Object

 java.lang.Object

↳androidx.constraintlayout.core.motion.utils.CurveFit

Subclasses:

MonotonicCurveFit, ArcCurveFit, LinearCurveFit

Gradle dependencies

compile group: 'androidx.constraintlayout', name: 'constraintlayout-core', version: '1.1.0-beta01'

  • groupId: androidx.constraintlayout
  • artifactId: constraintlayout-core
  • version: 1.1.0-beta01

Artifact androidx.constraintlayout:constraintlayout-core:1.1.0-beta01 it located at Google repository (https://maven.google.com/)

Overview

Base class for curve fitting / interpolation Curve fits must be capable of being differentiable and extend beyond the points (extrapolate)

Summary

Fields
public static final intCONSTANT

public static final intLINEAR

public static final intSPLINE

Constructors
publicCurveFit()

Methods
public static CurveFitget(int type, double[] time[], double[][] y[][])

public static CurveFitgetArc(int[] arcModes[], double[] time[], double[][] y[][])

public abstract voidgetPos(double t, double[] v[])

public abstract voidgetPos(double t, float[] v[])

public abstract doublegetPos(double t, int j)

public abstract voidgetSlope(double t, double[] v[])

public abstract doublegetSlope(double t, int j)

public abstract double[]getTimePoints()

from java.lang.Objectclone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait

Fields

public static final int SPLINE

public static final int LINEAR

public static final int CONSTANT

Constructors

public CurveFit()

Methods

public static CurveFit get(int type, double[] time[], double[][] y[][])

public static CurveFit getArc(int[] arcModes[], double[] time[], double[][] y[][])

public abstract void getPos(double t, double[] v[])

public abstract void getPos(double t, float[] v[])

public abstract double getPos(double t, int j)

public abstract void getSlope(double t, double[] v[])

public abstract double getSlope(double t, int j)

public abstract double[] getTimePoints()

Source

/*
 * Copyright (C) 2020 The Android Open Source Project
 *
 * Licensed 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 androidx.constraintlayout.core.motion.utils;

/**
 * Base class for curve fitting / interpolation
 * Curve fits must be capable of being differentiable and extend beyond the points (extrapolate)
 *
 *
 */

public abstract class CurveFit {
    public static final int SPLINE = 0;
    public static final int LINEAR = 1;
    public static final int CONSTANT = 2;

    // @TODO: add description
    public static CurveFit get(int type, double[] time, double[][] y) {
        if (time.length == 1) {
            type = CONSTANT;
        }
        switch (type) {
            case SPLINE:
                return new MonotonicCurveFit(time, y);
            case CONSTANT:
                return new Constant(time[0], y[0]);
            default:
                return new LinearCurveFit(time, y);
        }
    }

    // @TODO: add description
    public static CurveFit getArc(int[] arcModes, double[] time, double[][] y) {
        return new ArcCurveFit(arcModes, time, y);
    }

    // @TODO: add description
    public abstract void getPos(double t, double[] v);

    // @TODO: add description
    public abstract void getPos(double t, float[] v);

    // @TODO: add description
    public abstract double getPos(double t, int j);

    // @TODO: add description
    public abstract void getSlope(double t, double[] v);

    // @TODO: add description
    public abstract double getSlope(double t, int j);

    // @TODO: add description
    public abstract double[] getTimePoints();

    static class Constant extends CurveFit {
        double mTime;
        double[] mValue;

        Constant(double time, double[] value) {
            mTime = time;
            mValue = value;
        }

        @Override
        public void getPos(double t, double[] v) {
            System.arraycopy(mValue, 0, v, 0, mValue.length);
        }

        @Override
        public void getPos(double t, float[] v) {
            for (int i = 0; i < mValue.length; i++) {
                v[i] = (float) mValue[i];
            }
        }

        @Override
        public double getPos(double t, int j) {
            return mValue[j];
        }

        @Override
        public void getSlope(double t, double[] v) {
            for (int i = 0; i < mValue.length; i++) {
                v[i] = 0;
            }
        }

        @Override
        public double getSlope(double t, int j) {
            return 0;
        }

        @Override
        public double[] getTimePoints() {
            return new double[]{mTime};
        }
    }
}