コード例 #1
0
ファイル: CmdLCM.java プロジェクト: vnkmr7620/kojo.geogebra
  public GeoElement[] process(Command c) throws MyError {
    int n = c.getArgumentNumber();
    boolean[] ok = new boolean[n];
    GeoElement[] arg;

    switch (n) {
      case 1:
        arg = resArgs(c);
        if (arg[0].isGeoList()) {
          GeoElement[] ret = {kernel.LCM(c.getLabel(), (GeoList) arg[0])};
          return ret;
        } else throw argErr(app, c.getName(), arg[0]);

      case 2:
        arg = resArgs(c);
        if ((ok[0] = arg[0].isNumberValue()) && (ok[1] = arg[1].isNumberValue())) {
          GeoElement[] ret = {kernel.LCM(c.getLabel(), (NumberValue) arg[0], (NumberValue) arg[1])};
          return ret;

        } else throw argErr(app, c.getName(), arg[0]);

      default:
        throw argNumErr(app, c.getName(), n);
    }
  }
コード例 #2
0
ファイル: CmdPointIn.java プロジェクト: kovzol/geogebra
  /**
   * Checks correctness of inputs and runs the command. Last change: correct error messages
   * (2010-05-17), Zbynek Konecny
   */
  public GeoElement[] process(Command c) throws MyError {
    int n = c.getArgumentNumber();
    boolean[] ok = new boolean[n];
    GeoElement[] arg;

    if (n == 1) {
      arg = resArgs(c);
      if (ok[0] = (arg[0].isRegion())) {
        GeoElement[] ret = {kernel.PointIn(c.getLabel(), (Region) arg[0])};
        return ret;
      } else throw argErr(app, "PointIn", arg[0]);
    } else throw argNumErr(app, "PointIn", n);
  }
コード例 #3
0
  public final GeoElement[] process(Command c) throws MyError {
    int n = c.getArgumentNumber();
    GeoElement[] arg;

    switch (n) {
      case 1:
        arg = resArgs(c);

        // asymptotes to conic
        if (arg[0].isGeoConic()) {
          GeoElement[] ret = {kernel.FirstAxisLength(c.getLabel(), (GeoConic) arg[0])};
          return ret;
        } else throw argErr(app, "FirstAxisLength", arg[0]);

      default:
        throw argNumErr(app, "FirstAxisLength", n);
    }
  }
コード例 #4
0
ファイル: CmdDegree.java プロジェクト: avilleret/geogebra
  public final GeoElement[] process(Command c) throws MyError {
    int n = c.getArgumentNumber();
    boolean[] ok = new boolean[n];
    GeoElement[] arg;
    arg = resArgs(c);

    switch (n) {
      case 1:
        if (ok[0] = (arg[0].isGeoFunction())) {
          GeoElement[] ret = {kernel.Degree(c.getLabel(), (GeoFunction) arg[0])};
          return ret;
        } else throw argErr(app, c.getName(), arg[0]);

        // more than one argument
      default:
        throw argNumErr(app, c.getName(), n);
    }
  }
コード例 #5
0
ファイル: CmdGetTime.java プロジェクト: avilleret/geogebra
  public final GeoElement[] process(Command c) throws MyError {
    int n = c.getArgumentNumber();

    switch (n) {
      case 0:
        Calendar cal = Calendar.getInstance();
        GeoNumeric ms = new GeoNumeric(cons, cal.get(Calendar.MILLISECOND));
        GeoNumeric secs = new GeoNumeric(cons, cal.get(Calendar.SECOND));
        GeoNumeric mins = new GeoNumeric(cons, cal.get(Calendar.MINUTE));
        GeoNumeric hours = new GeoNumeric(cons, cal.get(Calendar.HOUR_OF_DAY));
        GeoNumeric date = new GeoNumeric(cons, cal.get(Calendar.DAY_OF_MONTH));
        int d = cal.get(Calendar.DAY_OF_WEEK);
        GeoNumeric day = new GeoNumeric(cons, d);
        int m = cal.get(Calendar.MONTH) + 1;
        GeoNumeric month = new GeoNumeric(cons, m);
        GeoNumeric year = new GeoNumeric(cons, cal.get(Calendar.YEAR));
        GeoText monthStr = new GeoText(cons);
        monthStr.setTextString(app.getPlain("Month." + m));

        GeoText dayStr = new GeoText(cons);
        dayStr.setTextString(app.getPlain("Day." + d));

        GeoList list = new GeoList(cons);
        list.setLabel(c.getLabel());

        list.add(ms);
        list.add(secs);
        list.add(mins);
        list.add(hours);
        list.add(date);
        list.add(month);
        list.add(year);
        list.add(monthStr);
        list.add(dayStr);
        list.add(day);
        list.update();

        GeoElement[] ret = {list};
        return ret;

      default:
        throw argNumErr(app, c.getName(), n);
    }
  }
コード例 #6
0
  public GeoElement[] process(Command c) throws MyError {

    int n = c.getArgumentNumber();
    boolean[] ok = new boolean[n];

    if (n == 6) {
      // Curve[ <x-coord expression>,  <y-coord expression>,  <z-coord expression>, <number-var>,
      // <from>, <to> ]
      // Note: x and y and z coords are numbers dependent on number-var

      // create local variable at position 3 and resolve arguments
      GeoElement[] arg = resArgsLocalNumVar(c, 3, 4);

      if ((ok[0] = arg[0].isNumberValue())
          && (ok[1] = arg[1].isNumberValue())
          && (ok[2] = arg[2].isNumberValue())
          && (ok[3] = arg[3].isGeoNumeric())
          && (ok[4] = arg[4].isNumberValue())
          && (ok[5] = arg[5].isNumberValue())) {
        GeoElement[] ret = new GeoElement[1];
        ret[0] =
            kernel
                .getManager3D()
                .CurveCartesian3D(
                    c.getLabel(),
                    (NumberValue) arg[0],
                    (NumberValue) arg[1],
                    (NumberValue) arg[2],
                    (GeoNumeric) arg[3],
                    (NumberValue) arg[4],
                    (NumberValue) arg[5]);
        return ret;
      } else {
        for (int i = 0; i < n; i++) {
          if (!ok[i]) throw argErr(app, "CurveCartesian", arg[i]);
        }
      }
    }

    return super.process(c);
  }
コード例 #7
0
ファイル: CmdZip.java プロジェクト: avilleret/geogebra
  public final GeoElement[] process(Command c) throws MyError {
    int n = c.getArgumentNumber();

    // avoid
    // "Command Sequence not known eg Sequence[If[Element[list1,i]=="b",0,1]]
    if (n < 3 || n % 2 == 0) throw argNumErr(app, c.getName(), n);

    boolean[] ok = new boolean[n];

    // create local variable at position 1 and resolve arguments
    GeoElement[] arg;
    arg = resArgsForZip(c);

    if ((ok[0] = arg[0].isGeoElement()) && (ok[2] = arg[2].isGeoList())) {
      return kernel.Zip(c.getLabel(), arg[0], vars, over);
    } else {
      for (int i = 0; i < n; i++) {
        if (!ok[i]) throw argErr(app, c.getName(), arg[i]);
      }
    }
    return null;
  }
コード例 #8
0
  public GeoElement[] process(Command c) throws MyError {
    int n = c.getArgumentNumber();
    boolean[] ok = new boolean[n];
    GeoElement[] arg;

    switch (n) {
      case 2:
        arg = resArgs(c);
        if (arg[0].isGeoList() && arg[1].isGeoList()) {
          GeoElement[] ret = {
            kernel.Intersection(c.getLabel(), (GeoList) arg[0], (GeoList) arg[1])
          };
          return ret;
        } else {
          if (!ok[0]) throw argErr(app, "Intersection", arg[0]);
          else throw argErr(app, "Intersection", arg[1]);
        }

      default:
        throw argNumErr(app, "Intersection", n);
    }
  }
コード例 #9
0
  public GeoElement[] process(Command c) throws MyError {
    int n = c.getArgumentNumber();
    boolean[] ok = new boolean[n];

    switch (n) {
        // Curve[ <x-coord expression>,  <y-coord expression>, <number-var>, <from>, <to> ]
        // Note: x and y coords are numbers dependent on number-var
      case 5:
        // create local variable at position 2 and resolve arguments
        GeoElement[] arg = resArgsLocalNumVar(c, 2, 3);

        if ((ok[0] = arg[0].isNumberValue())
            && (ok[1] = arg[1].isNumberValue())
            && (ok[2] = arg[2].isGeoNumeric())
            && (ok[3] = arg[3].isNumberValue())
            && (ok[4] = arg[4].isNumberValue())) {
          GeoElement[] ret = new GeoElement[1];
          ret[0] =
              kernel.CurveCartesian(
                  c.getLabel(),
                  (NumberValue) arg[0],
                  (NumberValue) arg[1],
                  (GeoNumeric) arg[2],
                  (NumberValue) arg[3],
                  (NumberValue) arg[4]);
          return ret;
        } else {
          for (int i = 0; i < n; i++) {
            if (!ok[i]) throw argErr(app, "CurveCartesian", arg[i]);
          }
        }

      default:
        throw argNumErr(app, "CurveCartesian", n);
    }
  }
コード例 #10
0
ファイル: CmdAngle.java プロジェクト: avilleret/geogebra
  public GeoElement[] process(Command c) throws MyError {
    int n = c.getArgumentNumber();
    boolean[] ok = new boolean[n];
    GeoElement[] arg;

    switch (n) {
        /**
         * // Anlge[ constant number ] // get number value ExpressionNode en = null; ExpressionValue
         * eval; double value = 0.0; // check if we got number: // ExpressionNode && NumberValue ||
         * Assignment // build ExpressionNode from one of these cases ok[0] = false; Object ob =
         * c.getArgument(0); if (ob instanceof ExpressionNode) { en = (ExpressionNode) ob; eval =
         * en.evaluate(); if (eval .isNumberValue() && !(eval .isGeoPolygon())) { value =
         * ((NumberValue) eval).getDouble(); ok[0] = true; } } else if (ob instanceof Assignment) {
         * GeoElement geo = cons.lookupLabel(((Assignment) ob).getVariable()); if (geo
         * .isGeoNumeric()) { // wrap GeoNumeric int ExpressionNode for // kernel.DependentNumer()
         * en = new ExpressionNode(kernel, (NumberValue) geo, ExpressionNode.NO_OPERATION, null);
         * ok[0] = true; } }
         */
      case 1:
        arg = resArgs(c);

        // wrap angle as angle (needed to avoid ambiguities between numbers
        // and angles in XML)
        if (arg[0].isGeoAngle()) {
          // maybe we have to set a label here
          if (!cons.isSuppressLabelsActive() && !arg[0].isLabelSet()) {
            arg[0].setLabel(c.getLabel());

            // make sure that arg[0] is in construction list
            if (arg[0].isIndependent()) cons.addToConstructionList(arg[0], true);
            else cons.addToConstructionList(arg[0].getParentAlgorithm(), true);
          }
          GeoElement[] ret = {arg[0]};
          return ret;
        }
        // angle from number
        else if (arg[0].isGeoNumeric()) {
          GeoElement[] ret = {kernel.Angle(c.getLabel(), (GeoNumeric) arg[0])};
          return ret;
        }
        // angle from number
        else if (arg[0].isGeoPoint() || arg[0].isGeoVector()) {
          GeoElement[] ret = {kernel.Angle(c.getLabel(), (GeoVec3D) arg[0])};
          return ret;
        }
        // angle of conic or polygon
        else {
          if (arg[0].isGeoConic()) {
            GeoElement[] ret = {kernel.Angle(c.getLabel(), (GeoConic) arg[0])};
            return ret;
          } else if (arg[0].isGeoPolygon())
            return kernel.Angles(c.getLabels(), (GeoPolygon) arg[0]);
        }

        throw argErr(app, "Angle", arg[0]);

      case 2:
        arg = resArgs(c);

        // angle between vectors
        if ((ok[0] = (arg[0].isGeoVector())) && (ok[1] = (arg[1].isGeoVector()))) {
          GeoElement[] ret = {kernel.Angle(c.getLabel(), (GeoVector) arg[0], (GeoVector) arg[1])};
          return ret;
        }
        // angle between lines
        else if ((ok[0] = (arg[0].isGeoLine())) && (ok[1] = (arg[1].isGeoLine()))) {
          GeoElement[] ret = {kernel.Angle(c.getLabel(), (GeoLine) arg[0], (GeoLine) arg[1])};
          return ret;
        }
        // syntax error
        else {
          if (ok[0] && !ok[1]) throw argErr(app, "Angle", arg[1]);
          else throw argErr(app, "Angle", arg[0]);
        }

      case 3:
        arg = resArgs(c);

        // angle between three points
        if ((ok[0] = (arg[0].isGeoPoint()))
            && (ok[1] = (arg[1].isGeoPoint()))
            && (ok[2] = (arg[2].isGeoPoint()))) {
          GeoElement[] ret = {
            kernel.Angle(c.getLabel(), (GeoPoint) arg[0], (GeoPoint) arg[1], (GeoPoint) arg[2])
          };
          return ret;
        }
        // fixed angle
        else if ((ok[0] = (arg[0].isGeoPoint()))
            && (ok[1] = (arg[1].isGeoPoint()))
            && (ok[2] = (arg[2].isNumberValue())))
          return kernel.Angle(
              c.getLabels(), (GeoPoint) arg[0], (GeoPoint) arg[1], (NumberValue) arg[2]);
        else throw argErr(app, "Angle", arg[0]);

      default:
        throw argNumErr(app, "Angle", n);
    }
  }
コード例 #11
0
  public GeoElement[] process(Command c) throws MyError {
    int n = c.getArgumentNumber();
    boolean[] ok = new boolean[n];
    GeoElement[] arg;

    switch (n) {
      case 3:
        arg = resArgs(c);
        if ((ok[0] = arg[0].isNumberValue()) && (ok[1] = arg[1].isNumberValue())) {
          GeoElement[] ret = {
            kernel.HyperGeometric(
                c.getLabel(), (NumberValue) arg[0], (NumberValue) arg[1], (NumberValue) arg[2])
          };
          return ret;

        } else if (!ok[0]) throw argErr(app, c.getName(), arg[0]);
        else if (!ok[1]) throw argErr(app, c.getName(), arg[1]);
        else throw argErr(app, c.getName(), arg[2]);

      case 4:
        arg = resArgs(c);
        if ((ok[0] = arg[0].isNumberValue())
            && (ok[1] = arg[1].isNumberValue())
            && (ok[2] = arg[2].isNumberValue())
            && (ok[3] = arg[3].isGeoBoolean())) {
          GeoElement[] ret = {
            kernel.HyperGeometric(
                c.getLabel(),
                (NumberValue) arg[0],
                (NumberValue) arg[1],
                (NumberValue) arg[2],
                (GeoBoolean) arg[3])
          };
          return ret;

        } else if (!ok[0]) throw argErr(app, c.getName(), arg[0]);
        else if (!ok[1]) throw argErr(app, c.getName(), arg[1]);
        else if (!ok[2]) throw argErr(app, c.getName(), arg[2]);
        else throw argErr(app, c.getName(), arg[3]);

      case 5:
        arg = resArgs(c);
        if ((ok[0] = arg[0].isNumberValue())
            && (ok[1] = arg[1].isNumberValue())
            && (ok[2] = arg[2].isNumberValue())
            && (ok[3] = arg[3].isNumberValue())
            && (ok[4] = arg[4].isGeoBoolean())) {
          GeoElement[] ret = {
            kernel.HyperGeometric(
                c.getLabel(),
                (NumberValue) arg[0],
                (NumberValue) arg[1],
                (NumberValue) arg[2],
                (NumberValue) arg[3],
                (GeoBoolean) arg[4])
          };
          return ret;

        } else if (!ok[0]) throw argErr(app, c.getName(), arg[0]);
        else if (!ok[1]) throw argErr(app, c.getName(), arg[1]);
        else if (!ok[2]) throw argErr(app, c.getName(), arg[2]);
        else if (!ok[3]) throw argErr(app, c.getName(), arg[3]);
        else throw argErr(app, c.getName(), arg[4]);

      default:
        throw argNumErr(app, c.getName(), n);
    }
  }