Skip to content

Commit

Permalink
Merge pull request #14 from const-ae/fix_issue_11
Browse files Browse the repository at this point in the history
Fix issue #11, thanks @const-ae
  • Loading branch information
LKremer authored Aug 19, 2020
2 parents cf22c25 + 6010a81 commit 02f3ab2
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 7 deletions.
4 changes: 2 additions & 2 deletions R/geom_pointdensity.R
Original file line number Diff line number Diff line change
Expand Up @@ -138,8 +138,8 @@ StatPointdensity <- ggproto("StatPointdensity", Stat,
ix <- findInterval(data$x, dens$x)
iy <- findInterval(data$y, dens$y)
ii <- cbind(ix, iy)
data$density <- dens$z[ii]

data$density[finites] <- dens$z[ii]
data$density[!finites] <- min(dens$z)
} else {

if (is.character(method)) {
Expand Down
17 changes: 12 additions & 5 deletions src/count_neighbors.c
Original file line number Diff line number Diff line change
Expand Up @@ -22,11 +22,18 @@ SEXP count_neighbors_( SEXP x, SEXP y, SEXP r2, SEXP xy ) {
int s = 0;
double xi = xp[i];
double yi = yp[i];
for( int j = 0; j < l; j++ ) {
double dx = xi - xp[j];
double dy = yi - yp[j];
if( yxp*dx*dx + xyp*dy*dy <= r2p )
s++;
for( int j = 0; j < l; j++ ) {\
double xj = xp[j];
double yj = yp[j];
double dx = xi - xj;
double dy = yi - yj;
if((xi == xj && yi == yj) ||
(xi == xj && xyp * dy * dy <= r2p) ||
(yi == yj && xyp * dx * dx <= r2p) ||
(yxp*dx*dx + xyp*dy*dy <= r2p) ){
s++;
}

}
resp[i] = s;
}
Expand Down

0 comments on commit 02f3ab2

Please sign in to comment.