[GEOS] #860: Prefer empty to size of zero

Previous Topic Next Topic
 
classic Classic list List threaded Threaded
3 messages Options
Reply | Threaded
Open this post in threaded view
|

[GEOS] #860: Prefer empty to size of zero

geos-2
#860: Prefer empty to size of zero
------------------------+--------------------------
 Reporter:  goatbar     |      Owner:  geos-devel@…
     Type:  defect      |     Status:  new
 Priority:  major       |  Milestone:  3.6.3
Component:  Default     |    Version:  3.6.2
 Severity:  Unassigned  |   Keywords:
------------------------+--------------------------
 {{{#!c++
 double
 ElevationMatrixCell::getAvg() const
 {
         return  zvals.size() ?
                 ztot / static_cast<double>(zvals.size()) :
                 DoubleNotANumber;
 }
 }}}

 Should become:

 {{{#!c++
 double
 ElevationMatrixCell::getAvg() const
 {
     return !zvals.empty() ? ztot / static_cast<double>(zvals.size())
                         : DoubleNotANumber;
 }
 }}}

 or better yet, drop the not (!) in the test.

 {{{#!c++
 double
 ElevationMatrixCell::getAvg() const
 {
     return zvals.empty()
         ? DoubleNotANumber
         : ztot / static_cast<double>(zvals.size()) ;
 }
 }}}

--
Ticket URL: <https://trac.osgeo.org/geos/ticket/860>
GEOS <http://trac.osgeo.org/geos>
GEOS (Geometry Engine - Open Source) is a C++ port of the Java Topology Suite (JTS).

_______________________________________________
geos-devel mailing list
[hidden email]
https://lists.osgeo.org/mailman/listinfo/geos-devel
Reply | Threaded
Open this post in threaded view
|

Re: [GEOS] #860: Prefer empty to size of zero

geos-2
#860: Prefer empty to size of zero
------------------------+---------------------------
 Reporter:  goatbar     |       Owner:  geos-devel@…
     Type:  defect      |      Status:  new
 Priority:  major       |   Milestone:  3.6.3
Component:  Default     |     Version:  3.6.2
 Severity:  Unassigned  |  Resolution:
 Keywords:              |
------------------------+---------------------------

Comment (by goatbar):

 And there are some easy to find instances of the same thing:

 {{{
 find . -name \*.cpp | xargs egrep '[.]size()' | egrep '== *0|0 *=='
 ./geomgraph/EdgeEndStar.cpp:    if (edgeMap.size()==0) return nullCoord;
 ./geomgraph/EdgeEndStar.cpp:    if (edgeMap.size()==0) return true;
 ./operation/buffer/SubgraphDepthLocater.cpp:    if
 (stabbedSegments.size()==0) return 0;
 ./operation/overlay/LineBuilder.cpp:    if ( v3d.size() == 0 )
 ./linearref/ExtractLineByLocation.cpp:  if (newCoordinateArray.size() ==
 0)
 }}}

--
Ticket URL: <https://trac.osgeo.org/geos/ticket/860#comment:1>
GEOS <http://trac.osgeo.org/geos>
GEOS (Geometry Engine - Open Source) is a C++ port of the Java Topology Suite (JTS).

_______________________________________________
geos-devel mailing list
[hidden email]
https://lists.osgeo.org/mailman/listinfo/geos-devel
Reply | Threaded
Open this post in threaded view
|

Re: [GEOS] #860: Prefer empty to size of zero

geos-2
In reply to this post by geos-2
#860: Prefer empty to size of zero
------------------------+---------------------------
 Reporter:  goatbar     |       Owner:  geos-devel@…
     Type:  defect      |      Status:  new
 Priority:  major       |   Milestone:  3.6.4
Component:  Default     |     Version:  3.6.2
 Severity:  Unassigned  |  Resolution:
 Keywords:              |
------------------------+---------------------------
Changes (by robe):

 * milestone:  3.6.3 => 3.6.4


--
Ticket URL: <https://trac.osgeo.org/geos/ticket/860#comment:2>
GEOS <http://trac.osgeo.org/geos>
GEOS (Geometry Engine - Open Source) is a C++ port of the Java Topology Suite (JTS).

_______________________________________________
geos-devel mailing list
[hidden email]
https://lists.osgeo.org/mailman/listinfo/geos-devel