Package ket.math.purpose.symbolicFunctions

Source Code of ket.math.purpose.symbolicFunctions.SymbolicFunctionRange

/*
* 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.symbolicFunctions;

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

import ket.display.*;
import ket.display.box.Box;
import ket.display.box.BoxGraphic;
import ket.display.box.BoxList;
import ket.display.box.BoxTools;
import ket.display.box.BoxWord;
import ket.math.*;
import ket.math.purpose.SymbolicState;

/**
* A specific mathematical operation that acts on arguments in a case-specific
* way.
*/
public class SymbolicFunctionRange extends SymbolicFunctionForm {

  @Override
  public String toLatex(Vector<Argument> args) {
    // TODO: Extend purpose to two arguments as well.
    if (args.size()==3) {
      return "\\left. " + args.get(0).toLatex()
        + " \\right|_{" + args.get(1).toLatex()
        + "}^{" + args.get(2).toLatex() + "}";
    } else if (args.size()==2) {
      return "\\left. " + args.get(0).toLatex()
        + " \\right|_{" + args.get(1).toLatex() + "}";
    } else {
      return super.toLatex(args);
    }
  }

  @Override
  public String toHTML(Vector<Argument> args) {
    // TODO: Note yet implemented. 
    return super.toHTML(args);
  }

  @Override
  public Box toBox(Argument argument, Vector<Box> boxArgs, long settings, ColourScheme colourScheme) {
    if (boxArgs.size()>=4) {
      return super.toBox(argument, boxArgs, settings, colourScheme);
    }
    switch (boxArgs.size()) {
      case 0:
      case 1:
        BoxGraphic verticalBar1 = new BoxGraphic(argument, Box.LEFT_ALIGN|Box.VERTICAL_STRETCH, BoxGraphic.VERTICAL_LINE);
        boxArgs.add(1, verticalBar1);
        boxArgs.get(2).setProperty(Box.BOTTOM_ALIGN|Box.SMALL_FONT);
        return BoxTools.centredHorizontalBoxList(argument, settings, boxArgs);

      case 2:
      case 3:
        BoxGraphic verticalBar2 = new BoxGraphic(argument, Box.X_CENTRE_ALIGN|Box.VERTICAL_STRETCH, BoxGraphic.VERTICAL_LINE);
        Box subject = boxArgs.get(0);
        Box from = boxArgs.get(1);
        Box to = boxArgs.size()==3 ? boxArgs.get(2) : new BoxWord(argument, " ", 0L);
        BoxList boxList = new BoxList(argument, settings);
        boxList.nextHorizontalPath(new Box[]{to});
        boxList.nextHorizontalPath(new Box[]{subject, verticalBar2});
        boxList.nextHorizontalPath(new Box[]{from});
        boxList.nextVerticalPath(new Box[]{subject});
        boxList.nextVerticalPath(new Box[]{verticalBar2});
        boxList.nextVerticalPath(new Box[]{to, from});
        subject.setProperty(Box.RIGHT_ALIGN|Box.Y_CENTRE_ALIGN);
        from.setProperty(Box.LEFT_ALIGN|Box.BOTTOM_ALIGN|Box.SMALL_FONT);
        to.setProperty(Box.LEFT_ALIGN|Box.TOP_ALIGN|Box.SMALL_FONT);
        return boxList;

      default:
        return null;
    }
  }
}
TOP

Related Classes of ket.math.purpose.symbolicFunctions.SymbolicFunctionRange

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.