/** * @param c * new construction */ public void setConstruction(final Construction c) { cons = c; kernel = c.getKernel(); }
/** * Add intersection to cache. * * @param algo * intersection algo */ public void addIntersectionAlgorithm(AlgoIntersectAbstract algo) { if (!isIntersectCacheEnabled || cons.getKernel().isSilentMode()) { return; } intersectionAlgos.add(algo); }
private Manager3DInterface getManager3D() { return cons.getKernel().getManager3D(); }
protected Localization getLoc() { return cons.getKernel().getLocalization(); }
/** * @param cons * construction * @return function If[x < 0,0,0] */ public static GeoFunction zeroWhenNegative(Construction cons) { return zeroWhenLessThan(new MyDouble(cons.getKernel(), 0), cons, true); }
/** * @param c * construction */ public AlgoSimpleRootsPolynomial(Construction c) { super(c); eqnSolver = cons.getKernel().getEquationSolver(); points = new OutputHandler<>(new ElementFactory<GeoPoint>() { @Override public GeoPoint newElement() { GeoPoint p = new GeoPoint(cons); // p.setCoords(0, 0, 1); p.setUndefined(); p.setParentAlgorithm(AlgoSimpleRootsPolynomial.this); return p; } }); }
@Override public void updateLocalAxesNames() { super.updateLocalAxesNames(); HashMap<String, GeoElement> geoTable = cons.getGeoTable(); geoTable.remove(zAxis3DLocalName); geoTable.remove(xOyPlaneLocalName); geoTable.remove(spaceLocalName); Localization app = cons.getKernel().getLocalization(); zAxis3DLocalName = app.getMenu("zAxis"); xOyPlaneLocalName = app.getMenu("xOyPlane"); spaceLocalName = app.getMenu("space"); geoTable.put(zAxis3DLocalName, zAxis3D); geoTable.put(xOyPlaneLocalName, xOyPlane); geoTable.put(spaceLocalName, space); }
private double parseStringData(String s, ErrorHandler handler) { if (s == null || s.length() == 0) { return Double.NaN; } Log.debug(s); try { String inputText = s.trim(); // allow input such as sqrt(2) NumberValue nv; nv = cons.getKernel().getAlgebraProcessor() .evaluateToNumeric(inputText, handler); return nv == null ? Double.NaN : nv.getDouble(); } catch (NumberFormatException e) { e.printStackTrace(); } return Double.NaN; }
/** * @return next color in sequence */ public GColor getNextColor() { GColor color = getColorSequence()[colorIndex]; if (!cons.getKernel().isSilentMode()) { colorIndex = (colorIndex + 1) % getColorSequence().length; } return color; }
@Override public void setPointsVisible(int column, boolean visible) { GeoEvaluatable geoEvaluatable = tableModel.getEvaluatable(column - 1); geoEvaluatable.setPointsVisible(visible); if (visible && points.get(column - 1) == null) { createAndAddPoints(tableModel, column); } else if (!visible && points.get(column - 1) != null) { removePoints(column); } construction.getKernel().getApplication().storeUndoInfo(); } }
private static GeoElement doGetTemplate(Construction cons, GeoClass listElement) { switch (listElement) { case POINT: return new GeoPoint(cons); case POINT3D: return (GeoElement) cons.getKernel().getGeoFactory().newPoint(3, cons); case VECTOR: return new GeoVector(cons); case VECTOR3D: return (GeoElement) cons.getKernel().getGeoFactory().newPoint(3, cons); } return new GeoPoint(cons); }
private static Function isFunction(ExpressionValue val, Construction cons) { if (val.unwrap() instanceof Function) { return (Function) val.unwrap(); } if (val.unwrap() instanceof GeoFunction) { return ((GeoFunction) val.unwrap()).getFunction() .deepCopy(cons.getKernel()); } if (val.wrap().containsFreeFunctionVariable(null)) { FunctionNVar fun = cons.getKernel().getAlgebraProcessor() .makeFunctionNVar(val.wrap()); if (fun instanceof Function) { return ((Function) fun).deepCopy(cons.getKernel()); } } return null; }
/** * @param label * vector label * @param p0 * start point * @param p1 * end point * @return vector */ public GeoElement vectorND(String label, GeoPointND p0, GeoPointND p1) { if (p0.isGeoElement3D() || p1.isGeoElement3D()) { return cons.getKernel().getManager3D().vector3D(label, p0, p1); } return vector(label, (GeoPoint) p0, (GeoPoint) p1); }
/** * @param cons * construction * @param f * function */ public AlgoRootsPolynomial(Construction cons, GeoFunction f) { super(cons); this.f = f; tempPoint = new GeoPoint(cons); // set mode mode = ROOTS; eqnSolver = cons.getKernel().getEquationSolver(); // make sure root points is not null int number = 1; rootPoints = new GeoPoint[0]; initRootPoints(number); initLabels = true; setInputOutput(); // for AlgoElement compute(); }
private void initPoints3D(int number) { // make sure that there are enough points if (points3D.length < number) { GeoPoint3D[] temp = new GeoPoint3D[number]; for (int i = 0; i < points3D.length; i++) { temp[i] = points3D[i]; temp[i].setCoords(0, 0, 1); // init as defined } for (int i = points3D.length; i < temp.length; i++) { temp[i] = (GeoPoint3D) cons.getKernel().getGeoFactory().newPoint(3, cons); temp[i].setCoords(0, 0, 1); // init as defined temp[i].setParentAlgorithm(this); } points3D = temp; super.setOutput(points3D); } }
/** * @param border * left border of function support * @param cons * construction * @param sharp * whether to use < or <= * @return function If[x < border, 0, 0] */ public static GeoFunction zeroWhenLessThan(ExpressionValue border, Construction cons, boolean sharp) { Kernel kernel = cons.getKernel(); FunctionVariable fv = new FunctionVariable(kernel); ExpressionNode en = fv.wrap() .apply(sharp ? Operation.LESS : Operation.LESS_EQUAL, border) .ifElse(new MyDouble(kernel, 0), new MyDouble(kernel, 0)); return en.buildFunction(fv); } }
private boolean isConditionalPolynomial(GeoFunction f) { if (f.getFunctionExpression() != null && f.getFunctionExpression().getOperation().isIf()) { Function test = new Function( f.getFunctionExpression().deepCopy(cons.getKernel()) .getRightTree()); test.initFunction(); return test.isPolynomialFunction(false, true); } return false; }
/** * initializes auxiliary elements of the algo */ private void initElements() { this.outputPoints = createOutputPoints(); this.hasLabels = false; numOfOutputPoints = 0; polyPointCount = (getPoly().getPoints()).length; segCountOfPoly = isPolyclosed() ? polyPointCount : polyPointCount - 1; tempSegEndPoints = new GeoPoint[2]; for (int i = 0; i < tempSegEndPoints.length; i++) { tempSegEndPoints[i] = new GeoPoint(getConstruction()); } tempSeg = new GeoSegment(getConstruction()); eqnSolver = getConstruction().getKernel().getEquationSolver(); }
private void initElements() { numOfOutputPoints = 0; polyPointCount = (getPoly().getPoints()).length; segCountOfPoly = isPolyClosed() ? polyPointCount : polyPointCount - 1; tempSegEndPoints = new GeoPoint[2]; for (int i = 0; i < tempSegEndPoints.length; i++) { tempSegEndPoints[i] = new GeoPoint(getConstruction()); } tempSeg = new GeoSegment(getConstruction()); diffFunction = new Function(kernel); tempPoint = new GeoPoint(getConstruction()); eqnSolver = cons.getKernel().getEquationSolver(); solution.resetRoots(); outputPoints = this.createOutputPoints(); }