Index: boost/gil/extension/numeric/sampler.hpp
===================================================================
--- boost/gil/extension/numeric/sampler.hpp	(revision 796)
+++ boost/gil/extension/numeric/sampler.hpp	(working copy)
@@ -45,7 +45,7 @@
 
 template <typename DstP, typename SrcView, typename F>
 bool sample(nearest_neighbor_sampler, const SrcView& src, const point2<F>& p, DstP& result) {
-    point2<int> center(iround(p));
+    typename SrcView::point_t center(iround(p));
     if (center.x>=0 && center.y>=0 && center.x<src.width() && center.y<src.height()) {
         result=src(center.x,center.y);
         return true;
@@ -118,33 +118,35 @@
     {
 		if (p0.y == -1)
         {
+		    // the top-left corner pixel
 			++loc.y();
-			detail::add_dst_mul_src<SrcP,F,pixel<F,devicen_layout_t<num_channels<SrcView>::value> > >()(loc.x()[1],   frac.x *   frac.y ,mp);
+			detail::add_dst_mul_src<SrcP,F,pixel<F,devicen_layout_t<num_channels<SrcView>::value> > >()(loc.x()[1],  1        ,mp);
 		}
         else if (p0.y+1<src.height())
         {
-			// most common case - inside the image, not on the last row or column
-			detail::add_dst_mul_src<SrcP,F,pixel<F,devicen_layout_t<num_channels<SrcView>::value> > >()(loc.x()[1],   frac.x *(1-frac.y),mp);
+            // on the first column, but not the top-left nor bottom-left corner pixel
+			detail::add_dst_mul_src<SrcP,F,pixel<F,devicen_layout_t<num_channels<SrcView>::value> > >()(loc.x()[1], (1-frac.y),mp);
 			++loc.y();
-			detail::add_dst_mul_src<SrcP,F,pixel<F,devicen_layout_t<num_channels<SrcView>::value> > >()(loc.x()[1],   frac.x *   frac.y ,mp);
+			detail::add_dst_mul_src<SrcP,F,pixel<F,devicen_layout_t<num_channels<SrcView>::value> > >()(loc.x()[1],    frac.y ,mp);
 		}
         else
         {
-			// on the last row, but not the bottom-right corner pixel
-			detail::add_dst_mul_src<SrcP,F,pixel<F,devicen_layout_t<num_channels<SrcView>::value> > >()(loc.x()[1],   frac.x ,mp);
+			// the bottom-left corner pixel
+			detail::add_dst_mul_src<SrcP,F,pixel<F,devicen_layout_t<num_channels<SrcView>::value> > >()(loc.x()[1],  1        ,mp);
 		}
 	}
     else if (p0.x+1<src.width())
     {
 		if (p0.y == -1)
         {
+		    // on the first row, but not the top-left nor top-right corner pixel
 			++loc.y();
-			detail::add_dst_mul_src<SrcP,F,pixel<F,devicen_layout_t<num_channels<SrcView>::value> > >()(*loc,      (1-frac.x)*   frac.y ,mp);
-			detail::add_dst_mul_src<SrcP,F,pixel<F,devicen_layout_t<num_channels<SrcView>::value> > >()(loc.x()[1],   frac.x *   frac.y ,mp);
+			detail::add_dst_mul_src<SrcP,F,pixel<F,devicen_layout_t<num_channels<SrcView>::value> > >()(*loc,      (1-frac.x)           ,mp);
+			detail::add_dst_mul_src<SrcP,F,pixel<F,devicen_layout_t<num_channels<SrcView>::value> > >()(loc.x()[1],   frac.x            ,mp);
 		}
         else if (p0.y+1<src.height())
         {
-			// most common case - inside the image, not on the last row or column
+			// most common case - inside the image, not on the frist nor last row/column
 			detail::add_dst_mul_src<SrcP,F,pixel<F,devicen_layout_t<num_channels<SrcView>::value> > >()(*loc,      (1-frac.x)*(1-frac.y),mp);
 			detail::add_dst_mul_src<SrcP,F,pixel<F,devicen_layout_t<num_channels<SrcView>::value> > >()(loc.x()[1],   frac.x *(1-frac.y),mp);
 			++loc.y();
@@ -153,24 +155,30 @@
 		}
         else
         {
-			// on the last row, but not the bottom-right corner pixel
-			detail::add_dst_mul_src<SrcP,F,pixel<F,devicen_layout_t<num_channels<SrcView>::value> > >()(*loc,      (1-frac.x),mp);
-			detail::add_dst_mul_src<SrcP,F,pixel<F,devicen_layout_t<num_channels<SrcView>::value> > >()(loc.x()[1],   frac.x ,mp);
+			// on the last row, but not the bottom-left nor bottom-right corner pixel
+			detail::add_dst_mul_src<SrcP,F,pixel<F,devicen_layout_t<num_channels<SrcView>::value> > >()(*loc,      (1-frac.x)           ,mp);
+			detail::add_dst_mul_src<SrcP,F,pixel<F,devicen_layout_t<num_channels<SrcView>::value> > >()(loc.x()[1],   frac.x            ,mp);
 		}
 	}
     else
     {
-		if (p0.y+1<src.height())
+        if (p0.y == -1)
         {
-			// on the last column, but not the bottom-right corner pixel
-			detail::add_dst_mul_src<SrcP,F,pixel<F,devicen_layout_t<num_channels<SrcView>::value> > >()(*loc,      (1-frac.y),mp);
+            // the top-right corner pixel
+            ++loc.y();
+            detail::add_dst_mul_src<SrcP,F,pixel<F,devicen_layout_t<num_channels<SrcView>::value> > >()(*loc,  1        ,mp);
+        }
+        else if (p0.y+1<src.height())
+        {
+			// on the last column, but not the top-right nor bottom-right corner pixel
+			detail::add_dst_mul_src<SrcP,F,pixel<F,devicen_layout_t<num_channels<SrcView>::value> > >()(*loc, (1-frac.y),mp);
 			++loc.y();
-			detail::add_dst_mul_src<SrcP,F,pixel<F,devicen_layout_t<num_channels<SrcView>::value> > >()(*loc,         frac.y ,mp);
+			detail::add_dst_mul_src<SrcP,F,pixel<F,devicen_layout_t<num_channels<SrcView>::value> > >()(*loc,    frac.y ,mp);
 		}
         else
         {
 			// the bottom-right corner pixel
-			detail::add_dst_mul_src<SrcP,F,pixel<F,devicen_layout_t<num_channels<SrcView>::value> > >()(*loc,1,mp);
+			detail::add_dst_mul_src<SrcP,F,pixel<F,devicen_layout_t<num_channels<SrcView>::value> > >()(*loc,  1        ,mp);
 		}
 	}
 
