double treeNodeCostOfPoint ( treeNode node , Point p ) { if ( p . weight == 0.0 ) { return 0.0 ; } //stores the distance between centre and p double distance = 0.0 ; //loop counter variable int l ; for ( l = 0 ; l < p . dimension ; l ++ ) { //centroid coordinate of the point double centroidCoordinatePoint ; if ( p . weight != 0.0 ) { centroidCoordinatePoint = p . coordinates [ l ] / p . weight ; } else { centroidCoordinatePoint = p . coordinates [ l ] ; } //centroid coordinate of the centre double centroidCoordinateCentre ; if ( node . centre . weight != 0.0 ) { centroidCoordinateCentre = node . centre . coordinates [ l ] / node . centre . weight ; } else { centroidCoordinateCentre = node . centre . coordinates [ l ] ; } distance += ( centroidCoordinatePoint - centroidCoordinateCentre ) * ( centroidCoordinatePoint - centroidCoordinateCentre ) ; } return distance * p . weight ; }
computes the cost of point p with the centre of treenode node