예제 #1
0
  /**
   * 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);
  }
예제 #2
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);
    }
  }
예제 #3
0
  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);
    }
  }
예제 #4
0
  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);
    }
  }
예제 #5
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);
  }
예제 #6
0
  public GeoElement[] process(Command c) throws MyError {
    int n = c.getArgumentNumber();
    GeoElement[] arg;

    arg = resArgs(c);
    switch (n) {
      case 0:
        throw argNumErr(app, c.getName(), n);
        // G.Sturr 2010-3-14
      case 1:
        if (arg[0].isGeoList()) return kernel.Polygon(c.getLabels(), (GeoList) arg[0]);
        // END G.Sturr

      case 3:
        // regular polygon
        if (arg[0].isGeoPoint() && arg[1].isGeoPoint() && arg[2].isNumberValue())
          return kernel.RegularPolygon(
              c.getLabels(), (GeoPoint) arg[0], (GeoPoint) arg[1], (NumberValue) arg[2]);

      default:
        // polygon for given points
        GeoPoint[] points = new GeoPoint[n];
        // check arguments
        for (int i = 0; i < n; i++) {
          if (!(arg[i].isGeoPoint())) throw argErr(app, c.getName(), arg[i]);
          else {
            points[i] = (GeoPoint) arg[i];
          }
        }
        // everything ok
        return kernel.Polygon(c.getLabels(), points);
    }
  }
예제 #7
0
  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);
    }
  }
예제 #8
0
  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;
  }
예제 #9
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);
    }
  }
예제 #10
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);
    }
  }
예제 #11
0
  /**
   * Resolves arguments, creates local variables and fills the vars and overlists
   *
   * @param c
   * @return list of arguments
   */
  protected final GeoElement[] resArgsForZip(Command c) {
    // check if there is a local variable in arguments
    int numArgs = c.getArgumentNumber();
    vars = new GeoElement[numArgs / 2];
    over = new GeoList[numArgs / 2];
    Construction cmdCons = (Construction) c.getKernel().getConstruction();

    for (int varPos = 1; varPos < numArgs; varPos += 2) {
      String localVarName = c.getVariableName(varPos);
      if (localVarName == null) {
        throw argErr(app, c.getName(), c.getArgument(varPos));
      }

      // add local variable name to construction

      GeoElement num = null;

      // initialize first value of local numeric variable from initPos

      boolean oldval = cons.isSuppressLabelsActive();
      cons.setSuppressLabelCreation(true);
      GeoList gl = (GeoList) resArg(c.getArgument(varPos + 1))[0];
      cons.setSuppressLabelCreation(oldval);
      num = gl.get(0).copyInternal(cons);

      cmdCons.addLocalVariable(localVarName, num);
      // set local variable as our varPos argument
      c.setArgument(varPos, new ExpressionNode(c.getKernel(), num));
      vars[varPos / 2] = num.toGeoElement();
      over[varPos / 2] = gl;
      // resolve all command arguments including the local variable just
      // created

      // remove local variable name from kernel again

    }
    GeoElement[] arg = resArgs(c);
    for (GeoElement localVar : vars) cmdCons.removeLocalVariable(localVar.getLabel());
    return arg;
  }
예제 #12
0
  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);
    }
  }
예제 #13
0
  public GeoElement[] processExpressionNode(ExpressionNode n) throws MyError {
    // command is leaf: process command
    if (n.isLeaf()) {
      ExpressionValue leaf = n.getLeft();
      if (leaf instanceof Command) {
        Command c = (Command) leaf;
        c.setLabels(n.getLabels());
        return cmdDispatcher.processCommand(c, true);
      } else if (leaf instanceof Equation) {
        Equation eqn = (Equation) leaf;
        eqn.setLabels(n.getLabels());
        return processEquation(eqn);
      } else if (leaf instanceof Function) {
        Function fun = (Function) leaf;
        fun.setLabels(n.getLabels());
        return processFunction(n, fun);
      } else if (leaf instanceof FunctionNVar) {
        FunctionNVar fun = (FunctionNVar) leaf;
        fun.setLabels(n.getLabels());
        return processFunctionNVar(n, fun);
      }
    }

    // ELSE:  resolve variables and evaluate expressionnode
    n.resolveVariables();
    eval = n.evaluate();
    boolean dollarLabelFound = false;

    ExpressionNode myNode = n;
    if (myNode.isLeaf()) myNode = myNode.getLeftTree();
    // leaf (no new label specified): just return the existing GeoElement
    if (eval.isGeoElement()
        && n.getLabel() == null
        && !(n.operation.equals(Operation.ELEMENT_OF))) {
      // take care of spreadsheet $ names: don't loose the wrapper ExpressionNode here
      // check if we have a Variable
      switch (myNode.getOperation()) {
        case $VAR_COL:
        case $VAR_ROW:
        case $VAR_ROW_COL:
          // don't do anything here: we need to keep the wrapper ExpressionNode
          // and must not return the GeoElement here
          dollarLabelFound = true;
          break;

        default:
          // return the GeoElement
          GeoElement[] ret = {(GeoElement) eval};
          return ret;
      }
    }

    if (eval.isBooleanValue()) return processBoolean(n, eval);
    else if (eval.isNumberValue()) return processNumber(n, eval);
    else if (eval.isVectorValue()) return processPointVector(n, eval);
    else if (eval.isVector3DValue()) return processPointVector3D(n, eval);
    else if (eval.isTextValue()) return processText(n, eval);
    else if (eval instanceof MyList) {
      return processList(n, (MyList) eval);
    } else if (eval instanceof Function) {
      return processFunction(n, (Function) eval);
    } else if (eval instanceof FunctionNVar) {

      return processFunctionNVar(n, (FunctionNVar) eval);
    }
    // we have to process list in case list=matrix1(1), but not when list=list2
    else if (eval instanceof GeoList && myNode.hasOperations()) {
      Application.debug("should work");
      return processList(n, ((GeoList) eval).getMyList());
    } else if (eval.isGeoElement()) {

      // e.g. B1 = A1 where A1 is a GeoElement and B1 does not exist yet
      // create a copy of A1
      if (n.getLabel() != null || dollarLabelFound) {
        return processGeoCopy(n.getLabel(), n);
      }
    }

    // REMOVED due to issue 131: http://code.google.com/p/geogebra/issues/detail?id=131
    //		// expressions like 2 a (where a:x + y = 1)
    //		// A1=b doesn't work for these objects
    //		else if (eval instanceof GeoLine) {
    //			if (((GeoLine)eval).getParentAlgorithm() instanceof AlgoDependentLine) {
    //				GeoElement[] ret = {(GeoElement) eval };
    //				return ret;
    //			}
    //
    //		}

    // if we get here, nothing worked
    Application.debug("Unhandled ExpressionNode: " + eval + ", " + eval.getClass());
    return null;
  }
예제 #14
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);
    }
  }