Although Alex's answer might be more correct,
I have figured out this solution where I create the grid at an xPos/yPos that will definitely correspond to a gridLine placement.
So yPos/xPos
have now a correctedBoundingRectLeft
and a correctedBoundingRectTop
to draw their calculations from
The code:
var drawGrid = function(boundingRect, cellSize) {
var vCellsNum = boundingRect.height / cellSize;
var hCellsNum = boundingRect.width / cellSize;
for (var i = 0; i <= hCellsNum; i++) {
var offsetXPos = Math.ceil(boundingRect.left / cellSize) * cellSize;
var xPos = offsetXPos + i * cellSize;
var topPoint = new paper.Point(xPos, boundingRect.top);
var bottomPoint = new paper.Point(xPos, boundingRect.bottom);
var line = new paper.Path.Line(topPoint, bottomPoint);
line.strokeColor = '#968d8d';
}
for (var i = 0; i <= vCellsNum; i++) {
var offsetYPos = Math.ceil(boundingRect.top / cellSize) * cellSize;
var yPos = offsetYPos + i * cellSize;
var leftPoint = new paper.Point(boundingRect.left, yPos);
var rightPoint = new paper.Point(boundingRect.right, yPos);
var line = new paper.Path.Line(leftPoint, rightPoint);
line.strokeColor = '#968d8d';
}
}
// where `30` is the cell width/height in px
drawGrid(paper.view.bounds, 30);