Android Open Source - android-plotter Graph






From Project

Back to project page android-plotter.

License

The source code is released under:

Apache License

If you think the Android project android-plotter listed in this page is inappropriate, such as containing malicious code/tools or violating the copyright, please email info at java2s dot com, thanks.

Java Source Code

package org.solovyev.android.plotter.meshes;
//from  www .j  a  v  a2  s  .com
import javax.annotation.Nonnull;

class Graph {

  float accuracy = 1f;

  int start = 0;
  int end = 0;

  int capacity = 4 * 3;

  @Nonnull
  float[] vertices = new float[capacity];

  @Nonnull
  private short[] indices = new short[capacity / 3];

  private Graph() {
  }

  @Nonnull
  static Graph create() {
    return new Graph();
  }

  void prepend(float x, float y) {
    ensureCanPrepend();

    vertices[--start] = 0;
    vertices[--start] = y;
    vertices[--start] = x;
  }

  private void ensureCanPrepend() {
    if (start < 3) {
      makeSpaceAtTheStart();
    }
  }

  void append(float x, float y) {
    ensureCanAppend();

    vertices[end++] = x;
    vertices[end++] = y;
    vertices[end++] = 0;
  }

  private void ensureCanAppend() {
    if (end + 3 > capacity) {
      makeSpaceAtTheEnd();
    }
  }

  void makeSpaceAtTheEnd() {
    if (start > capacity / 2) {
      final int length = length();
      System.arraycopy(vertices, start, vertices, 0, length);
      start = 0;
      end = length;
      return;
    }

    final int newCapacity = 5 * capacity / 4;
    final float[] newVertices = new float[newCapacity];
    System.arraycopy(vertices, start, newVertices, start, length());
    vertices = newVertices;
    capacity = newCapacity;
  }

  private void makeSpaceAtTheStart() {
    if (end != 0 && end < capacity / 2) {
      final int newStart = start + capacity - end;
      final int length = length();
      System.arraycopy(vertices, start, vertices, newStart, length);
      start = newStart;
      end = newStart + length;
      return;
    }

    final int newCapacity = 5 * capacity / 4;
    final float[] newVertices = new float[newCapacity];
    final int offset = newCapacity - capacity;
    System.arraycopy(vertices, start, newVertices, start + offset, length());
    start += offset;
    end += offset;
    vertices = newVertices;
    capacity = newCapacity;
  }


  int length() {
    return end - start;
  }

  boolean isEmpty() {
    return start == end;
  }

  void clear() {
    start = 0;
    end = 0;
  }

  public float x(int position) {
    return vertices[position];
  }

  public void moveStartTo(float x) {
    while (start < end && vertices[start] < x) {
      start += 3;
    }

    if (start > end) {
      start = end;
    }
  }

  public void moveEndTo(float x) {
    while (start < end && vertices[end - 3] > x) {
      end -= 3;
    }

    if (start > end) {
      end = start;
    }
  }

  public float xMin() {
    return vertices[start];
  }

  public float xMax() {
    return vertices[end - 3];
  }

  short[] getIndices() {
    final int indicesCount = getIndicesCount();
    if (indices.length < indicesCount) {
      indices = new short[indicesCount];
    }
    for (short i = 0; i < indicesCount; i++) {
      indices[i] = i;
    }
    return indices;
  }

  int getIndicesCount() {
    return length() / 3;
  }
}




Java Source Code List

com.android.texample.GLText.java
com.android.texample.SpriteBatch.java
com.android.texample.TexampleRenderer.java
com.android.texample.TextureRegion.java
com.android.texample.Vertices.java
org.solovyev.android.plotter.Angle.java
org.solovyev.android.plotter.AxisStyle.java
org.solovyev.android.plotter.Check.java
org.solovyev.android.plotter.Color.java
org.solovyev.android.plotter.DefaultPlotter.java
org.solovyev.android.plotter.Dimensions.java
org.solovyev.android.plotter.Frustum.java
org.solovyev.android.plotter.Function0.java
org.solovyev.android.plotter.Function1.java
org.solovyev.android.plotter.Function2.java
org.solovyev.android.plotter.Function.java
org.solovyev.android.plotter.LineStyle.java
org.solovyev.android.plotter.MeshConfig.java
org.solovyev.android.plotter.MultisampleConfigChooser.java
org.solovyev.android.plotter.PinchZoomTracker.java
org.solovyev.android.plotter.PlotData.java
org.solovyev.android.plotter.PlotFunction.java
org.solovyev.android.plotter.PlotRenderer.java
org.solovyev.android.plotter.PlotView.java
org.solovyev.android.plotter.Plot.java
org.solovyev.android.plotter.Plotter.java
org.solovyev.android.plotter.PlottingView.java
org.solovyev.android.plotter.Spf.java
org.solovyev.android.plotter.SuperFunction.java
org.solovyev.android.plotter.TouchHandler.java
org.solovyev.android.plotter.ZoomLevels.java
org.solovyev.android.plotter.Zoomer.java
org.solovyev.android.plotter.app.MainActivity.java
org.solovyev.android.plotter.app.PlotterApplication.java
org.solovyev.android.plotter.meshes.Arrays.java
org.solovyev.android.plotter.meshes.AxisGrid.java
org.solovyev.android.plotter.meshes.Axis.java
org.solovyev.android.plotter.meshes.BaseCube.java
org.solovyev.android.plotter.meshes.BaseCurve.java
org.solovyev.android.plotter.meshes.BaseMesh.java
org.solovyev.android.plotter.meshes.BaseSurface.java
org.solovyev.android.plotter.meshes.DimensionsAwareSwapper.java
org.solovyev.android.plotter.meshes.DimensionsAware.java
org.solovyev.android.plotter.meshes.DoubleBufferGroup.java
org.solovyev.android.plotter.meshes.DoubleBufferMesh.java
org.solovyev.android.plotter.meshes.FunctionGraph2d.java
org.solovyev.android.plotter.meshes.FunctionGraph3d.java
org.solovyev.android.plotter.meshes.FunctionGraphSwapper.java
org.solovyev.android.plotter.meshes.FunctionGraph.java
org.solovyev.android.plotter.meshes.Graph.java
org.solovyev.android.plotter.meshes.Group.java
org.solovyev.android.plotter.meshes.IndicesOrder.java
org.solovyev.android.plotter.meshes.ListGroup.java
org.solovyev.android.plotter.meshes.ListPool.java
org.solovyev.android.plotter.meshes.Mesh.java
org.solovyev.android.plotter.meshes.Meshes.java
org.solovyev.android.plotter.meshes.Pool.java
org.solovyev.android.plotter.meshes.Scene.java
org.solovyev.android.plotter.meshes.SolidCube.java
org.solovyev.android.plotter.meshes.SurfaceInitializer.java
org.solovyev.android.plotter.meshes.WireFrameCube.java