📄 coherentpointset.java
字号:
/*
Netwar
Copyright (C) 2002 Daniel Grund, Kyle Kakligian, Jason Komutrattananon, & Brian Hibler.
This file is part of Netwar.
Netwar 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 2 of the License, or
(at your option) any later version.
Netwar 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 Netwar; if not, write to the Free Software
Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
*/
package netwar.utils.vectorgraphics;
/** A collection of SelfConvertingPoint instances which may be rotated/translated together.
* This is used for VirtualCoherentGraphicThing and any other context in which
* a group of GraphicThings must be moved or rotated without guarantee that they
* do not share any points. The translate and rotate methods on collection type
* GraphicThings will only work properly if all the subordinate GraphicThings have
* no shared points.
*/
public class CoherentPointSet {
private SelfConvertingPoint points[];
private int count = 0;
/** Creates a new instance of CoherentPointSet
* @param size The number of SelfConvertingPoint objects which will be put in this set.
*/
public CoherentPointSet(int size) {
points = new SelfConvertingPoint[size];
}
/** Add the next SelfConvertingPoint to the set.
* This will not allow a point to be added if the set is full.
* @param pt The SelfConvertingPoint to add.
*/
public void add(SelfConvertingPoint pt) {
netwar.utils.Assert.notFalse(count < points.length, "Too many adds to CoherentPointSet");
points[count++] = pt;
}
/** Get the point with the specified index.
* Indexes are array indexes, starting from zero.
* @param index The index of the point.
* @return The specified SelfConvertingPoint
*/
public SelfConvertingPoint getPoint(int index) {
netwar.utils.Assert.notFalse(index >= 0, "Negative index in getPoint in CoherentPointSet");
netwar.utils.Assert.notFalse(index < count, "Index too high in getPoint in CoherentPointSet");
return points[index];
}
/** Rotate all of the points in the set.
* @param axisPt A point on the axis of rotation.
* @param axisDir The direction of the axis of rotation.
* @param angle The number of degrees to rotate.
*/
public void rotate(Point3D axisPt, Point3D axisDir, int angle) {
for(int i = 0; i < count; i++)
points[i].doRotate(axisPt, axisDir, angle);
}
/** Translate all the points in the set.
* @param offset The distance and direction to move them.
*/
public void translate(Point3D offset) {
for(int i = 0; i < count; i++)
points[i].doSum(offset);
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -