/*
* 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 ketUI.panel;
import geom.Offset;
import java.util.*;
import java.awt.Stroke;
import java.awt.BasicStroke;
import java.awt.Graphics;
import java.awt.Graphics2D;
import java.awt.Color;
import geom.Position;
import ket.*;
import ket.display.*;
import ket.display.box.Box;
import ket.display.box.BoxFactory;
import ket.display.box.BoxText;
import ket.display.box.BoxTools;
import ket.math.*;
import ketUI.Document;
/**
* Represent a visual element within GraphDisplay.
*/
class Label implements Comparable<Label> {
String name;
double x;
double y;
Double actualX;
Double actualY;
protected Label() { }
public Label(String name, double x, double y) {
this.name = name;
this.x = x;
this.y = y;
}
/*-
public Label(Argument argument) { // Why store an argument in the superclass of node?
this.argument = argument;
Purpose purpose = argument.getPurpose();
this.name = purpose!=null ? purpose.getName() : "?";
}
*/
public boolean isSimpleFunction() {
return false;
}
public int compareTo(Label that) {
return name.compareTo(that.name);
}
public Offset inversePower(Label that) { // Inverse nth power repulsion law.
if (this==that) {
return new Offset(0.0, 0.0);
}
double dx = that.x - this.x;
double dy = that.y - this.y;
double length = Math.sqrt(dx*dx + dy*dy);
double rsq = 1.0 / (length * length);
double scale = 1.0E+4;
//D Ket.out.println("dx,dy:" + dx + ", " + dy + ", rsq = " + rsq);
//D Ket.out.println("::" + (-dx*rsq*scale/length) + ", " + ( -dy*rsq*scale/length ) );
//D assert 3==scale : "pop";
return new Offset(-dx*rsq*scale/length, -dy*rsq*scale/length); // (scale/length^2) * [dx, dy]
}
public Offset comb(Label that) {
if (this==that) return new Offset(0.0, 0.0);
double dx = this.x - that.x;
double dy = this.y - that.y;
double scale = 1.0E-2;
return new Offset(scale*sign(dx)/sq(dx), scale*sign(dy)/sq(dy));
}
public static int sign(double x) {
return x<0.0 ? -1 : +1;
}
public static int abs(int x) {
return x<0 ? -x : +x;
}
public static double sq(double x) {
return x*x;
}
}