1 /**********************************************************************
4 * GEOS - Geometry Engine Open Source
5 * http://geos.refractions.net
7 * Copyright (C) 2005-2006 Refractions Research Inc.
8 * Copyright (C) 2001-2002 Vivid Solutions Inc.
10 * This is free software; you can redistribute and/or modify it under
11 * the terms of the GNU Lesser General Public Licence as published
12 * by the Free Software Foundation.
13 * See the COPYING file for more information.
15 **********************************************************************/
17 #include <geos/precision/CommonBitsOp.h>
18 #include <geos/precision/CommonBitsRemover.h>
19 #include <geos/geom/Geometry.h>
35 using namespace geos::geom
;
38 namespace precision
{ // geos.precision
41 CommonBitsOp::CommonBitsOp()
43 returnToOriginalPrecision(true)
47 std::cerr
<< "CommonBitsOp[" << this
48 << "]::CommonBitsOp()" << std::endl
;
53 CommonBitsOp::CommonBitsOp(bool nReturnToOriginalPrecision
)
55 returnToOriginalPrecision(nReturnToOriginalPrecision
)
58 std::cerr
<< "CommonBitsOp[" << this
59 << "]::CommonBitsOp(bool "
60 << nReturnToOriginalPrecision
<< ")"
67 CommonBitsOp::intersection(
68 const Geometry
* geom0
,
69 const Geometry
* geom1
)
71 auto_ptr
<Geometry
> rgeom0
;
72 auto_ptr
<Geometry
> rgeom1
;
73 removeCommonBits(geom0
, geom1
, rgeom0
, rgeom1
);
74 return computeResultPrecision(rgeom0
->intersection(rgeom1
.get()));
80 const Geometry
* geom0
,
81 const Geometry
* geom1
)
83 auto_ptr
<Geometry
> rgeom0
;
84 auto_ptr
<Geometry
> rgeom1
;
85 removeCommonBits(geom0
, geom1
, rgeom0
, rgeom1
);
86 return computeResultPrecision(rgeom0
->Union(rgeom1
.get()));
91 CommonBitsOp::difference(
92 const Geometry
* geom0
,
93 const Geometry
* geom1
)
95 auto_ptr
<Geometry
> rgeom0
;
96 auto_ptr
<Geometry
> rgeom1
;
97 removeCommonBits(geom0
, geom1
, rgeom0
, rgeom1
);
98 return computeResultPrecision(rgeom0
->difference(rgeom1
.get()));
103 CommonBitsOp::symDifference(
104 const Geometry
* geom0
,
105 const Geometry
* geom1
)
107 auto_ptr
<Geometry
> rgeom0
;
108 auto_ptr
<Geometry
> rgeom1
;
109 removeCommonBits(geom0
, geom1
, rgeom0
, rgeom1
);
110 return computeResultPrecision(rgeom0
->symDifference(rgeom1
.get()));
115 CommonBitsOp::buffer(const Geometry
* geom0
, double distance
)
117 auto_ptr
<Geometry
> rgeom0(removeCommonBits(geom0
));
118 return computeResultPrecision(rgeom0
->buffer(distance
));
123 CommonBitsOp::computeResultPrecision(Geometry
* result
)
126 if (returnToOriginalPrecision
)
127 cbr
->addCommonBits(result
);
133 CommonBitsOp::removeCommonBits(const Geometry
* geom0
)
135 cbr
.reset(new CommonBitsRemover());
139 const Coordinate
& commonCoord
= cbr
->getCommonCoordinate();
140 cerr
<< "CommonBitsRemover bits: " << commonCoord
.x
<< ", " << commonCoord
.y
<< endl
;
143 Geometry
* geom
=cbr
->removeCommonBits(geom0
->clone());
149 CommonBitsOp::removeCommonBits(
150 const geom::Geometry
* geom0
,
151 const geom::Geometry
* geom1
,
152 std::auto_ptr
<geom::Geometry
>& rgeom0
,
153 std::auto_ptr
<geom::Geometry
>& rgeom1
)
156 cbr
.reset(new CommonBitsRemover());
162 const Coordinate
& commonCoord
= cbr
->getCommonCoordinate();
163 cerr
<< "CommonBitsRemover bits: " << commonCoord
.x
<< ", " << commonCoord
.y
<< endl
;
166 rgeom0
.reset(cbr
->removeCommonBits(geom0
->clone()));
167 rgeom1
.reset(cbr
->removeCommonBits(geom1
->clone()));
171 } // namespace geos.precision
174 /**********************************************************************
176 * Revision 1.10 2006/04/13 23:28:26 strk
177 * "always build before commit" (forgot a closing paren)
179 * Revision 1.9 2006/04/13 23:23:52 strk
180 * fixed bug in binary ops failing to consistently reduce operands.
182 * Revision 1.8 2006/04/07 08:27:12 strk
185 * Revision 1.7 2006/04/06 14:36:51 strk
186 * Cleanup in geos::precision namespace (leaks plugged, auto_ptr use, ...)
188 * Revision 1.6 2006/03/23 09:17:19 strk
189 * precision.h header split, minor optimizations
191 **********************************************************************/