private void addNewGeoToConstruction() { if (objectType == TYPE_LISTOFPOINTS || objectType == TYPE_POLYLINE) { app.getKernel().getConstruction().addToConstructionList(newGeo.getParentAlgorithm(), true); } newGeo.setEuclidianVisible(true); if (!newGeo.isGeoText()) newGeo.setAuxiliaryObject(false); if (objectType == TYPE_LISTOFPOINTS) { GeoList gl = (GeoList) newGeo; for (int i = 0; i < gl.size(); i++) { gl.get(i).setEuclidianVisible(true); gl.get(i).setAuxiliaryObject(false); } } if (objectType == TYPE_POLYLINE) { GeoPoint[] pts = ((AlgoPolyLine) newGeo.getParentAlgorithm()).getPoints(); for (int i = 0; i < pts.length; i++) { pts[i].setEuclidianVisible(true); pts[i].setAuxiliaryObject(false); } } newGeo.update(); app.storeUndoInfo(); }
@Override public void compute() { if (!factorList.isDefined() || !Kernel.isInteger(number.getDouble())) { result.setUndefined(); return; } long res = 1; for (int i = 0; i < factorList.size(); i++) { GeoList pair = (GeoList) factorList.get(i); double exp = ((NumberValue) pair.get(1)).getDouble(); if (sum) { double prime = ((NumberValue) pair.get(0)).getDouble(); App.debug(prime); res = res * Math.round((Math.pow(prime, exp + 1) - 1) / (prime - 1.0)); } else { res = res * Math.round(exp + 1); } } result.setValue(res); }
@Override public final void compute() { size = inputList.size(); if (!inputList.isDefined() || !function.toGeoElement().isDefined()) { r2.setUndefined(); return; } GeoFunction funGeo = function.getGeoFunction(); // Calculate errorsum and ssy: double sumyy = 0.0d; double sumy = 0.0d; double syy = 0.0d; double errorsum = 0.0d; GeoElement geo = null; GeoPoint point = null; double x, y, v; for (int i = 0; i < size; i++) { geo = inputList.get(i); if (geo.isGeoPoint()) { point = (GeoPoint) geo; x = point.getX(); y = point.getY(); v = funGeo.evaluate(x); errorsum += (v - y) * (v - y); sumy += y; sumyy += y * y; } else { r2.setUndefined(); return; } // if calculation is possible } // for all points syy = sumyy - sumy * sumy / size; // calculate RSquare r2.setValue(1 - errorsum / syy); } // compute()
/** * 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; }
private void createNewGeo() { boolean nullGeo = newGeo == null; if (!nullGeo) { if (objectType == TYPE_LISTOFPOINTS) { GeoList gl = (GeoList) newGeo; for (int i = 0; i < gl.size(); i++) gl.get(i).remove(); } if (objectType == TYPE_POLYLINE) { GeoPoint[] pts = ((AlgoPolyLine) newGeo.getParentAlgorithm()).getPoints(); for (int i = 0; i < pts.length; i++) pts[i].remove(); } newGeo.remove(); } int column1 = table.selectedCellRanges.get(0).getMinColumn(); int column2 = table.selectedCellRanges.get(0).getMaxColumn(); int row1 = table.selectedCellRanges.get(0).getMinRow(); int row2 = table.selectedCellRanges.get(0).getMaxRow(); boolean copyByValue = btnValue.isSelected(); boolean scanByColumn = cbScanOrder.getSelectedIndex() == 1; boolean leftToRight = cbLeftRightOrder.getSelectedIndex() == 0; boolean transpose = ckTranspose.isSelected(); boolean doCreateFreePoints = true; boolean doStoreUndo = true; boolean isSorted = false; try { switch (objectType) { case TYPE_LIST: newGeo = cp.createList(selectedCellRanges, scanByColumn, copyByValue); break; case TYPE_LISTOFPOINTS: newGeo = cp.createPointGeoList( selectedCellRanges, copyByValue, leftToRight, isSorted, doStoreUndo, doCreateFreePoints); newGeo.setLabel(null); for (int i = 0; i < ((GeoList) newGeo).size(); i++) { ((GeoList) newGeo).get(i).setAuxiliaryObject(true); ((GeoList) newGeo).get(i).setEuclidianVisible(false); } newGeo.updateRepaint(); break; case TYPE_MATRIX: newGeo = cp.createMatrix(column1, column2, row1, row2, copyByValue, transpose); break; case TYPE_TABLETEXT: newGeo = cp.createTableText(column1, column2, row1, row2, copyByValue, transpose); break; case TYPE_POLYLINE: newGeo = cp.createPolyLine(selectedCellRanges, copyByValue, leftToRight); newGeo.setLabel(null); GeoPoint[] pts = ((AlgoPolyLine) newGeo.getParentAlgorithm()).getPoints(); for (int i = 0; i < pts.length; i++) { pts[i].setAuxiliaryObject(true); pts[i].setEuclidianVisible(false); } newGeo.updateRepaint(); break; } ImageIcon latexIcon = new ImageIcon(); // String latexStr = newGeo.getLaTeXAlgebraDescription(true); String latexStr = newGeo.getFormulaString(StringTemplate.latexTemplate, true); // System.out.println(latexStr); Font latexFont = new Font( app.getPlainFont().getName(), app.getPlainFont().getStyle(), app.getPlainFont().getSize() - 1); if (latexStr != null && newGeo.isLaTeXDrawableGeo()) { app.getDrawEquation() .drawLatexImageIcon(app, latexIcon, latexStr, latexFont, false, Color.black, null); lblPreview.setText(" "); } else { lblPreview.setText(newGeo.getAlgebraDescriptionTextOrHTMLDefault()); } lblPreview.setIcon(latexIcon); if (!nullGeo) { newGeo.setLabel(fldName.getText()); newGeo.setAuxiliaryObject(true); newGeo.setEuclidianVisible(false); } updateGUI(); } catch (Exception e) { e.printStackTrace(); } }
/** * Return the item at a given position in a GeoList * * @param list the GeoList * @param index the index of the item * @return the item at position index */ public static GeoElement getListItem(GeoList list, int index) { return list.get(index); }