Package ket.math.purpose.function

Source Code of ket.math.purpose.function.FunctionSqrt

/*
* Copyright (C) 2011  Alasdair C. Hamilton
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program.  If not, see <http://www.gnu.org/licenses/>
*/

package ket.math.purpose.function;

import java.awt.*;
import java.util.*;

import ket.display.*;
import ket.display.box.Box;
import ket.display.box.BoxGraphic;
import ket.display.box.BoxTools;
import ket.math.*;

public class FunctionSqrt extends FunctionForm {

  @Override
  public String toLatex(Vector<Argument> args) {
    if (args.size()==1) {
      return "\\sqrt{" + args.get(0).toLatex() + "}";
    } else {
      return super.toLatex(args);
    }
  }

  @Override
  public Box toBox(Argument argument, Vector<Box> boxArgs, long settings, ColourScheme colourScheme) {
    switch (boxArgs.size()) {
      case 0:
      case 1:
        BoxGraphic horizontalBar = new BoxGraphic(argument, 0L, BoxGraphic.HORIZONTAL_LINE);
        boxArgs.add(0, horizontalBar);
        Box argsAndOverbar = BoxTools.centredVerticalBoxList(argument, 0L, boxArgs);
        BoxGraphic radical = new BoxGraphic(argument, 0L, BoxGraphic.RADICAL);
        Box sqrtBox = BoxTools.centredHorizontalBoxList(argument, 0L, radical, argsAndOverbar);
        radical.setProperty(Box.HORIZONTAL_STRETCH);
        radical.setProperty(Box.TOP_ALIGN);
        radical.setProperty(Box.PRESERVE_ASPECT_RATIO);
        horizontalBar.setProperty(Box.HORIZONTAL_STRETCH);
        sqrtBox.setProperty(settings);
        return sqrtBox;
      default:
        return super.toBox(argument, boxArgs, settings, colourScheme);
    }
  }
}
TOP

Related Classes of ket.math.purpose.function.FunctionSqrt

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.