Package org.matheusdev.util.matrix.matrix2

Source Code of org.matheusdev.util.matrix.matrix2.MappedMatrix2

package org.matheusdev.util.matrix.matrix2;

import org.matheusdev.util.NumUtils;
import org.matheusdev.util.matrix.OPTION;
import org.matheusdev.util.matrix.PositionOutsideDimensionsException;

/**
* @author matheusdev
*
*/
public abstract class MappedMatrix2 {

  public int w, h;

  public MappedMatrix2(int w, int h) {
    if (w == 0 || h == 0) {
      throw new IllegalArgumentException ("w == 0 || h == 0");
    }
    this.w = w;
    this.h = h;
  }

  public int getSize() {
    return w*h;
  }

  protected int getPosition(int x, int y) {
    if (OPTION.PERFORM_CHECKS) {
      if (NumUtils.outside(x, 0, w-1)) throwDimException(x, y);
      if (NumUtils.outside(y, 0, h-1)) throwDimException(x, y);
    }
    return (x*h)+y;
  }

  private void throwDimException(int x, int y) {
    throw new PositionOutsideDimensionsException(
        new int[] { w, h },
        new int[] { x, y });
  }

  public int getWidth() {
    return w;
  }

  public int getHeight() {
    return h;
  }

}
TOP

Related Classes of org.matheusdev.util.matrix.matrix2.MappedMatrix2

TOP
Copyright © 2018 www.massapi.com. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.