/* Rebalance after insertion */
#define jsw_insert_balance(root,dir) do { \
- avlnode n = root.link[dir]; \
+ avlnode ni = root.link[dir]; \
int bal = dir == 0 ? -1 : +1; \
- if ( n.balance == bal ) { \
- root.balance = n.balance = 0; \
+ if ( ni.balance == bal ) { \
+ root.balance = ni.balance = 0; \
jsw_single ( root, 1-dir ); \
} \
else { /* n.balance == -bal */ \
/* Rebalance after deletion */
#define jsw_remove_balance(root,dir,done) do { \
- avlnode n = root.link[1-dir]; \
+ avlnode nr = root.link[1-dir]; \
int bal = dir == 0 ? -1 : +1; \
- if ( n.balance == -bal ) { \
- root.balance = n.balance = 0; \
+ if ( nr.balance == -bal ) { \
+ root.balance = nr.balance = 0; \
jsw_single ( root, dir ); \
} \
- else if ( n.balance == bal ) { \
+ else if ( nr.balance == bal ) { \
jsw_adjust_balance ( root, 1-dir, -bal ); \
jsw_double ( root, dir ); \
} \
else { /* n.balance == 0 */ \
root.balance = -bal; \
- n.balance = bal; \
+ nr.balance = bal; \
jsw_single ( root, dir ); \
done = 1; \
} \
boolean avlinsert(Object data ) {
/* Empty tree case */
if ( root == null ) {
- root = new avlnode(tree,data);
+ root = new avlnode(this,data);
} else {
avlnode head =new avlnode(); /* Temporary tree root */
avlnode s, t; /* Place to rebalance and parent */
}
}
- p.link[dir] = q = new avlnode(tree, data);
+ p.link[dir] = q = new avlnode(this, data);
if (q==null)
return false;
break;
/* Push direction and node onto stack */
- upd[top] = cmp ( it.data, data ) < 0;
+ upd[top] = (cmp ( it.data, data ) < 0)?1:0;
up[top++] = it;
it = it.link[upd[top - 1]];
if (top != 0)
up[top-1].link[upd[top - 1]] = it.link[dir];
else
- tree.root = it.link[dir];
+ root = it.link[dir];
} else {
/* Find the inorder successor */
avlnode heir = it.link[1];
heir.data = save;
/* Unlink successor and fix parent */
- up[top-1].link[up[top - 1] == it] = heir.link[1];
+ up[top-1].link[(up[top - 1] == it)?1:0] = heir.link[1];
}
/* Walk back up the search path */
up[top].balance += upd[top] != 0 ? -1 : +1;
/* Terminate or rebalance as necessary */
- if ( abs ( up[top].balance ) == 1 )
+ if (up[top].balance == 1 || up[top].balance==-1 )
break;
- else if ( abs ( up[top].balance ) > 1 ) {
+ else if ( up[top].balance > 1 ||up[top].balance < -1) {
jsw_remove_balance ( up[top], upd[top], done );
/* Fix parent */
int minPosition = 0;
for (int i = 1; i < numCoordinate; i++) {
- if (coordinate_compare(coordinates[i], coordinates[minPosition]) < 0) {
+ if (coordinate.coordinate_compare(coordinates[i], coordinates[minPosition]) < 0) {
minPosition = i;
}
}
if (numCoordinate == 3) {
int i;
for (i = 0; i < 3; i++) {
- double angle = coordinate_angle(coordinates[i],
+ double angle = coordinate.coordinate_angle(coordinates[i],
coordinates[(i + 1) % 3],
coordinates[(i + 2) % 3]);
yada.Assert(angle > 0.0);
circumCenterPtr.y = ry;
}
- elementPtr.circumRadius = coordinate_distance(circumCenterPtr,
+ elementPtr.circumRadius = coordinate.coordinate_distance(circumCenterPtr,
coordinates[0]);
}
coordinate secondPtr = coordinates[(i + 1) % numCoordinate];
edge edgePtr = edges[i];
- int cmp = coordinate_compare(firstPtr, secondPtr);
+ int cmp = coordinate.coordinate_compare(firstPtr, secondPtr);
yada.Assert(cmp != 0);
if (cmp < 0) {
edgePtr.firstPtr = firstPtr;
midpointPtr.x = (firstPtr.x + secondPtr.x) / 2.0;
midpointPtr.y = (firstPtr.y + secondPtr.y) / 2.0;
- elementPtr.radii[i] = coordinate_distance(firstPtr, midpointPtr);
+ elementPtr.radii[i] = coordinate.coordinate_distance(firstPtr, midpointPtr);
}
int element_compare (element aElementPtr, element bElementPtr) {
int aNumCoordinate = aElementPtr.numCoordinate;
int bNumCoordinate = bElementPtr.numCoordinate;
- coordinate aCoordinates = aElementPtr.coordinates;
- coordinate bCoordinates = bElementPtr.coordinates;
+ coordinate aCoordinates[] = aElementPtr.coordinates;
+ coordinate bCoordinates[] = bElementPtr.coordinates;
if (aNumCoordinate < bNumCoordinate) {
return -1;
for (int i = 0; i < aNumCoordinate; i++) {
int compareCoordinate =
- coordinate_compare(aCoordinates[i], bCoordinates[i]);
+ coordinate.coordinate_compare(aCoordinates[i], bCoordinates[i]);
if (compareCoordinate != 0) {
return compareCoordinate;
}
* =============================================================================
*/
static int compareEdge(edge aEdgePtr, edge bEdgePtr) {
- int diffFirst = coordinate_compare((coordinate)aEdgePtr.firstPtr,
+ int diffFirst = coordinate.coordinate_compare((coordinate)aEdgePtr.firstPtr,
(coordinate)bEdgePtr.firstPtr);
return ((diffFirst != 0) ?
(diffFirst) :
- (coordinate_compare((coordinate)aEdgePtr.secondPtr,
+ (coordinate.coordinate_compare((coordinate)aEdgePtr.secondPtr,
(coordinate)bEdgePtr.secondPtr)));
}
element aElementPtr = (element)aPtr;
element bElementPtr = (element)bPtr;
- if (aElementPtr.encroachedEdgePtr) {
- if (bElementPtr.encroachedEdgePtr) {
+ if (aElementPtr.encroachedEdgePtr!=null) {
+ if (bElementPtr.encroachedEdgePtr!=null) {
return 0; /* do not care */
} else {
return 1;
}
}
- if (bElementPtr.encroachedEdgePtr) {
+ if (bElementPtr.encroachedEdgePtr!=null) {
return -1;
}
* =============================================================================
*/
boolean element_isInCircumCircle(coordinate coordinatePtr) {
- double distance = coordinate_distance(coordinatePtr, circumCenter);
+ double distance = coordinate.coordinate_distance(coordinatePtr, circumCenter);
return distance <= circumRadius;
}
* =============================================================================
*/
void element_addNeighbor(element neighborPtr) {
- TMLIST_INSERT(neighborListPtr, neighborPtr);
+ neighborListPtr.insert(neighborPtr);
}
// double angleConstraint = global_angleConstraint;
if (numCoordinate == 3) {
for (int i = 0; i < 3; i++) {
- double angle = coordinate_angle(coordinates[i],
+ double angle = coordinate.coordinate_angle(coordinates[i],
coordinates[(i + 1) % 3],
coordinates[(i + 2) % 3]);
if (angle < angleConstraint) {
*/
void element_print() {
for (int c = 0; c < numCoordinate; c++) {
- coordinate_print(coordinates[c]);
+ coordinates[c].coordinate_print();
System.out.println(" ");
}
}
* =============================================================================
*/
void element_printEdge (edge edgePtr) {
- coordinate_print((coordinate)edgePtr.firstPtr);
+ ((coordinate)edgePtr.firstPtr).coordinate_print();
System.out.println(" -> ");
- coordinate_print((coordinate)edgePtr.secondPtr);
+ ((coordinate)edgePtr.secondPtr).coordinate_print();
}
void element_printAngles() {
if (numCoordinate == 3) {
for (int i = 0; i < 3; i++) {
- double angle = coordinate_angle(coordinates[i],
+ double angle = coordinate.coordinate_angle(coordinates[i],
coordinates[(i + 1) % 3],
coordinates[(i + 2) % 3]);
System.out.println(angle);
element rootElementPtr;
Queue_t initBadQueuePtr;
int size;
- SET_T boundarySetPtr;
+ RBTree boundarySetPtr;
/* =============================================================================
* mesh_alloc
rootElementPtr = null;
initBadQueuePtr = new Queue_t(-1);
size = 0;
- boundarySetPtr = SET_ALLOC(null, element_listCompareEdge);
+ boundarySetPtr = new RBTree(null, element_listCompareEdge);
}
edge encroachedPtr = elementPtr.element_getEncroachedPtr();
if (encroachedPtr!=null) {
- if (!TMSET_CONTAINS(meshPtr.boundarySetPtr, encroachedPtr)) {
+ if (!boundarySetPtr.contains(encroachedPtr)) {
element_clearEncroached(elementPtr);
}
}
* =============================================================================
*/
boolean TMmesh_insertBoundary(edge boundaryPtr) {
- return TMSET_INSERT(boundarySetPtr, boundaryPtr);
+ return boundarySetPtr.insert(boundaryPtr,null);
}
* =============================================================================
*/
boolean TMmesh_removeBoundary(edge boundaryPtr) {
- return TMSET_REMOVE(boundarySetPtr, boundaryPtr);
+ return boundarySetPtr.remove(boundaryPtr);
}
if (numCoordinate == 2) {
edge boundaryPtr = elementPtr.element_getEdge(0);
- boolean status = SET_INSERT(boundarySetPtr, boundaryPtr);
+ boolean status = boundarySetPtr.insert(boundaryPtr, null);
yada.Assert(status);
}