Android Open Source - android-plotter Scene






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;
/* w  ww.j  ava2 s  .  c  om*/
import org.solovyev.android.plotter.Dimensions;

import javax.annotation.Nonnull;

// Spx = Scene pixels
// Gpx = Graph pixels
// Vpx = View pixels
final class Scene {
  private Scene() {
  }

  static final class Axis {

    final float length;
    final float lengthX;
    final float minLength;
    final float arrowLength;
    final float arrowWidth;

    public Axis(@Nonnull Dimensions.Scene scene, boolean y) {
      lengthX = scene.width();
      if (y) {
        length = scene.height();
      } else {
        length = scene.width();
      }
      minLength = Math.min(scene.width(), scene.height());
      arrowLength = minLength / 30;
      arrowWidth = minLength / 40;
    }

    @Nonnull
    public static Axis create(@Nonnull Dimensions.Scene scene, boolean y) {
      return new Axis(scene, y);
    }
  }

  static final class Ticks {

    final int count;
    final float step;
    final float width;
    final float axisLength;

    Ticks(int count, float step, float width) {
      this.count = count;
      this.step = step;
      this.width = width;
      this.axisLength = (count - 1) * step;
    }

    @Nonnull
    public static Ticks create(@Nonnull Dimensions.Graph graph, @Nonnull Axis axis) {
      final float sidePaddingSpx = 1.2f * axis.arrowLength;
      final float sidePaddingGpx = graph.toGraphX(sidePaddingSpx);
      final float tickWidthSpx = axis.arrowWidth / 3;

      final float graphWidthGpx = graph.width() - 2 * sidePaddingGpx;
      final float tickStepGpx = Meshes.getTickStep(graphWidthGpx, 10);

      int ticksCount = (int) (axis.lengthX / graph.toScreenX(tickStepGpx));
      if (ticksCount > 20) {
        ticksCount /= 2;
      }
      if (ticksCount < 10) {
        ticksCount *= 2;
      }
      if (ticksCount % 2 == 0) {
        ticksCount++;
      }
      float ticksStepSpx = axis.lengthX / ticksCount;
      float tickedAxisLengthSpx = (ticksCount - 1) * ticksStepSpx;

      float maxTickedAxisLengthSpx = axis.length - 2 * sidePaddingSpx;
      if (tickedAxisLengthSpx < maxTickedAxisLengthSpx) {
        while (tickedAxisLengthSpx < maxTickedAxisLengthSpx) {
          ticksCount += 2;
          tickedAxisLengthSpx = (ticksCount - 1) * ticksStepSpx;
        }
        ticksCount -= 2;
      } else if (tickedAxisLengthSpx > maxTickedAxisLengthSpx) {
        while (tickedAxisLengthSpx > maxTickedAxisLengthSpx) {
          ticksCount -= 2;
          tickedAxisLengthSpx = (ticksCount - 1) * ticksStepSpx;
        }
      }
      return new Ticks(ticksCount, ticksStepSpx, tickWidthSpx);
    }
  }
}




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