X-Git-Url: https://gerrit.simantics.org/r/gitweb?p=simantics%2Fplatform.git;a=blobdiff_plain;f=bundles%2Forg.simantics.g2d%2Fsrc%2Forg%2Fsimantics%2Fg2d%2Frouting%2Falgorithm1%2FDirection.java;h=85ce69601d2bcf3c9a7660ccad4017d5c8baebf8;hp=31e391a21135053b5da054bf81d0e3018d58449d;hb=refs%2Fchanges%2F38%2F238%2F2;hpb=24e2b34260f219f0d1644ca7a138894980e25b14 diff --git a/bundles/org.simantics.g2d/src/org/simantics/g2d/routing/algorithm1/Direction.java b/bundles/org.simantics.g2d/src/org/simantics/g2d/routing/algorithm1/Direction.java index 31e391a21..85ce69601 100644 --- a/bundles/org.simantics.g2d/src/org/simantics/g2d/routing/algorithm1/Direction.java +++ b/bundles/org.simantics.g2d/src/org/simantics/g2d/routing/algorithm1/Direction.java @@ -1,114 +1,114 @@ -/******************************************************************************* - * Copyright (c) 2007, 2010 Association for Decentralized Information Management - * in Industry THTH ry. - * All rights reserved. This program and the accompanying materials - * are made available under the terms of the Eclipse Public License v1.0 - * which accompanies this distribution, and is available at - * http://www.eclipse.org/legal/epl-v10.html - * - * Contributors: - * VTT Technical Research Centre of Finland - initial API and implementation - *******************************************************************************/ -package org.simantics.g2d.routing.algorithm1; - -import java.awt.geom.Rectangle2D; - - -public interface Direction { - int getId(); - double front(Rectangle rectangle); - double back(Rectangle rectangle); - double minSide(Rectangle rectangle); - double maxSide(Rectangle rectangle); - double front(Rectangle2D rectangle); - double back(Rectangle2D rectangle); - double minSide(Rectangle2D rectangle); - double maxSide(Rectangle2D rectangle); - Direction turnLeft(); - Direction turnRight(); - double getDir(double x, double y); - double getSide(double x, double y); - RoutePencil createPencil(double front, double back, double min, double max, double penalty, RoutePencil parent); - - public static final Direction EAST = new East(); - public static final Direction SOUTH = new South(); - public static final Direction WEST = new West(); - public static final Direction NORTH = new North(); - public static final Direction[] directions = new Direction[] { EAST, SOUTH, WEST, NORTH }; - - public static class East implements Direction { - public int getId() { return 0; } - public double front(Rectangle rect) { return rect.x0; } - public double back(Rectangle rect) { return rect.x1; } - public double minSide(Rectangle rect) { return rect.y0; } - public double maxSide(Rectangle rect) { return rect.y1; } - public double front(Rectangle2D rect) { return rect.getMinX(); } - public double back(Rectangle2D rect) { return rect.getMaxX(); } - public double minSide(Rectangle2D rect) { return rect.getMinY(); } - public double maxSide(Rectangle2D rect) { return rect.getMaxY(); } - public Direction turnLeft() { return NORTH; } - public Direction turnRight() { return SOUTH; } - public RoutePencil createPencil(double front, double back, double min, double max, double penalty, RoutePencil parent) { - return new RoutePencil(front, min, back, max, penalty, this, parent); - } - public double getDir(double x, double y) { return x; } - public double getSide(double x, double y) { return y; } - } - - public static class South implements Direction { - public int getId() { return 1; } - public double front(Rectangle rect) { return rect.y0; } - public double back(Rectangle rect) { return rect.y1; } - public double minSide(Rectangle rect) { return rect.x0; } - public double maxSide(Rectangle rect) { return rect.x1; } - public double front(Rectangle2D rect) { return rect.getMinY(); } - public double back(Rectangle2D rect) { return rect.getMaxY(); } - public double minSide(Rectangle2D rect) { return rect.getMinX(); } - public double maxSide(Rectangle2D rect) { return rect.getMaxX(); } - public Direction turnLeft() { return EAST; } - public Direction turnRight() { return WEST; } - public RoutePencil createPencil(double front, double back, double min, double max, double penalty, RoutePencil parent) { - return new RoutePencil(min, front, max, back, penalty, this, parent); - } - public double getDir(double x, double y) { return y; } - public double getSide(double x, double y) { return x; } - } - - public static class West implements Direction { - public int getId() { return 2; } - public double front(Rectangle rect) { return -rect.x1; } - public double back(Rectangle rect) { return -rect.x0; } - public double minSide(Rectangle rect) { return rect.y0; } - public double maxSide(Rectangle rect) { return rect.y1; } - public double front(Rectangle2D rect) { return -rect.getMaxX(); } - public double back(Rectangle2D rect) { return -rect.getMinX(); } - public double minSide(Rectangle2D rect) { return rect.getMinY(); } - public double maxSide(Rectangle2D rect) { return rect.getMaxY(); } - public Direction turnLeft() { return SOUTH; } - public Direction turnRight() { return NORTH; } - public RoutePencil createPencil(double front, double back, double min, double max, double penalty, RoutePencil parent) { - return new RoutePencil(-back, min, -front, max, penalty, this, parent); - } - public double getDir(double x, double y) { return -x; } - public double getSide(double x, double y) { return y; } - } - - public static class North implements Direction { - public int getId() { return 3; } - public double front(Rectangle rect) { return -rect.y1; } - public double back(Rectangle rect) { return -rect.y0; } - public double minSide(Rectangle rect) { return rect.x0; } - public double maxSide(Rectangle rect) { return rect.x1; } - public double front(Rectangle2D rect) { return -rect.getMaxY(); } - public double back(Rectangle2D rect) { return -rect.getMinY(); } - public double minSide(Rectangle2D rect) { return rect.getMinX(); } - public double maxSide(Rectangle2D rect) { return rect.getMaxX(); } - public Direction turnLeft() { return WEST; } - public Direction turnRight() { return EAST; } - public RoutePencil createPencil(double front, double back, double min, double max, double penalty, RoutePencil parent) { - return new RoutePencil(min, -back, max, -front, penalty, this, parent); - } - public double getDir(double x, double y) { return -y; } - public double getSide(double x, double y) { return x; } - } -} +/******************************************************************************* + * Copyright (c) 2007, 2010 Association for Decentralized Information Management + * in Industry THTH ry. + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * VTT Technical Research Centre of Finland - initial API and implementation + *******************************************************************************/ +package org.simantics.g2d.routing.algorithm1; + +import java.awt.geom.Rectangle2D; + + +public interface Direction { + int getId(); + double front(Rectangle rectangle); + double back(Rectangle rectangle); + double minSide(Rectangle rectangle); + double maxSide(Rectangle rectangle); + double front(Rectangle2D rectangle); + double back(Rectangle2D rectangle); + double minSide(Rectangle2D rectangle); + double maxSide(Rectangle2D rectangle); + Direction turnLeft(); + Direction turnRight(); + double getDir(double x, double y); + double getSide(double x, double y); + RoutePencil createPencil(double front, double back, double min, double max, double penalty, RoutePencil parent); + + public static final Direction EAST = new East(); + public static final Direction SOUTH = new South(); + public static final Direction WEST = new West(); + public static final Direction NORTH = new North(); + public static final Direction[] directions = new Direction[] { EAST, SOUTH, WEST, NORTH }; + + public static class East implements Direction { + public int getId() { return 0; } + public double front(Rectangle rect) { return rect.x0; } + public double back(Rectangle rect) { return rect.x1; } + public double minSide(Rectangle rect) { return rect.y0; } + public double maxSide(Rectangle rect) { return rect.y1; } + public double front(Rectangle2D rect) { return rect.getMinX(); } + public double back(Rectangle2D rect) { return rect.getMaxX(); } + public double minSide(Rectangle2D rect) { return rect.getMinY(); } + public double maxSide(Rectangle2D rect) { return rect.getMaxY(); } + public Direction turnLeft() { return NORTH; } + public Direction turnRight() { return SOUTH; } + public RoutePencil createPencil(double front, double back, double min, double max, double penalty, RoutePencil parent) { + return new RoutePencil(front, min, back, max, penalty, this, parent); + } + public double getDir(double x, double y) { return x; } + public double getSide(double x, double y) { return y; } + } + + public static class South implements Direction { + public int getId() { return 1; } + public double front(Rectangle rect) { return rect.y0; } + public double back(Rectangle rect) { return rect.y1; } + public double minSide(Rectangle rect) { return rect.x0; } + public double maxSide(Rectangle rect) { return rect.x1; } + public double front(Rectangle2D rect) { return rect.getMinY(); } + public double back(Rectangle2D rect) { return rect.getMaxY(); } + public double minSide(Rectangle2D rect) { return rect.getMinX(); } + public double maxSide(Rectangle2D rect) { return rect.getMaxX(); } + public Direction turnLeft() { return EAST; } + public Direction turnRight() { return WEST; } + public RoutePencil createPencil(double front, double back, double min, double max, double penalty, RoutePencil parent) { + return new RoutePencil(min, front, max, back, penalty, this, parent); + } + public double getDir(double x, double y) { return y; } + public double getSide(double x, double y) { return x; } + } + + public static class West implements Direction { + public int getId() { return 2; } + public double front(Rectangle rect) { return -rect.x1; } + public double back(Rectangle rect) { return -rect.x0; } + public double minSide(Rectangle rect) { return rect.y0; } + public double maxSide(Rectangle rect) { return rect.y1; } + public double front(Rectangle2D rect) { return -rect.getMaxX(); } + public double back(Rectangle2D rect) { return -rect.getMinX(); } + public double minSide(Rectangle2D rect) { return rect.getMinY(); } + public double maxSide(Rectangle2D rect) { return rect.getMaxY(); } + public Direction turnLeft() { return SOUTH; } + public Direction turnRight() { return NORTH; } + public RoutePencil createPencil(double front, double back, double min, double max, double penalty, RoutePencil parent) { + return new RoutePencil(-back, min, -front, max, penalty, this, parent); + } + public double getDir(double x, double y) { return -x; } + public double getSide(double x, double y) { return y; } + } + + public static class North implements Direction { + public int getId() { return 3; } + public double front(Rectangle rect) { return -rect.y1; } + public double back(Rectangle rect) { return -rect.y0; } + public double minSide(Rectangle rect) { return rect.x0; } + public double maxSide(Rectangle rect) { return rect.x1; } + public double front(Rectangle2D rect) { return -rect.getMaxY(); } + public double back(Rectangle2D rect) { return -rect.getMinY(); } + public double minSide(Rectangle2D rect) { return rect.getMinX(); } + public double maxSide(Rectangle2D rect) { return rect.getMaxX(); } + public Direction turnLeft() { return WEST; } + public Direction turnRight() { return EAST; } + public RoutePencil createPencil(double front, double back, double min, double max, double penalty, RoutePencil parent) { + return new RoutePencil(min, -back, max, -front, penalty, this, parent); + } + public double getDir(double x, double y) { return -y; } + public double getSide(double x, double y) { return x; } + } +}