1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209
|
/**********************************************************************
* $Id: HotPixel.cpp 1820 2006-09-06 16:54:23Z mloskot $
*
* GEOS - Geometry Engine Open Source
* http://geos.refractions.net
*
* Copyright (C) 2006 Refractions Research Inc.
*
* This is free software; you can redistribute and/or modify it under
* the terms of the GNU Lesser General Licence as published
* by the Free Software Foundation.
* See the COPYING file for more information.
*
**********************************************************************
*
* Last port: noding/snapround/HotPixel.java rev. 1.2 (JTS-1.7)
*
**********************************************************************/
#include <geos/noding/snapround/HotPixel.h>
#include <geos/algorithm/LineIntersector.h>
#include <geos/geom/Coordinate.h>
#ifndef GEOS_INLINE
# include "geos/noding/snapround/HotPixel.inl"
#endif
#include <cassert>
#include <memory>
using namespace std;
using namespace geos::algorithm;
using namespace geos::geom;
namespace geos {
namespace noding { // geos.noding
namespace snapround { // geos.noding.snapround
HotPixel::HotPixel(const Coordinate& newPt, double newScaleFactor,
LineIntersector& newLi)
:
li(newLi),
pt(newPt),
originalPt(pt),
scaleFactor(newScaleFactor)
{
if (scaleFactor != 1.0) {
pt.x=scale(pt.x);
pt.y=scale(pt.y);
}
initCorners(pt);
}
const Envelope&
HotPixel::getSafeEnvelope() const
{
if (safeEnv.get() == NULL) {
double safeTolerance = .75 / scaleFactor;
safeEnv = auto_ptr<Envelope>(new Envelope(originalPt.x - safeTolerance,
originalPt.x + safeTolerance,
originalPt.y - safeTolerance,
originalPt.y + safeTolerance
));
}
return *safeEnv;
}
/*private*/
void
HotPixel::initCorners(const Coordinate& pt)
{
double tolerance = 0.5;
minx = pt.x - tolerance;
maxx = pt.x + tolerance;
miny = pt.y - tolerance;
maxy = pt.y + tolerance;
corner.assign(4, Coordinate(minx, maxy));
}
bool
HotPixel::intersects(const Coordinate& p0,
const Coordinate& p1) const
{
if (scaleFactor == 1.0) return intersectsScaled(p0, p1);
Coordinate p0Scaled;
Coordinate p1Scaled;
copyScaled(p0, p0Scaled);
copyScaled(p1, p1Scaled);
return intersectsScaled(p0Scaled, p1Scaled);
}
bool
HotPixel::intersectsScaled(const Coordinate& p0,
const Coordinate& p1) const
{
#define MIN(x,y) (x)<(y)?(x):(y)
double segMinx = MIN(p0.x, p1.x);
double segMaxx = MIN(p0.x, p1.x);
double segMiny = MIN(p0.y, p1.y);
double segMaxy = MIN(p0.y, p1.y);
bool isOutsidePixelEnv = maxx < segMinx
|| minx > segMaxx
|| maxy < segMiny
|| miny > segMaxy;
if (isOutsidePixelEnv) return false;
bool intersects = intersectsToleranceSquare(p0, p1);
// Found bad envelope test
assert(!(isOutsidePixelEnv && intersects));
return intersects;
}
/*private*/
bool
HotPixel::intersectsToleranceSquare(const Coordinate& p0,
const Coordinate& p1) const
{
bool intersectsLeft = false;
bool intersectsBottom = false;
li.computeIntersection(p0, p1, corner[0], corner[1]);
if (li.isProper()) return true;
li.computeIntersection(p0, p1, corner[1], corner[2]);
if (li.isProper()) return true;
if (li.hasIntersection()) intersectsLeft = true;
li.computeIntersection(p0, p1, corner[2], corner[3]);
if (li.isProper()) return true;
if (li.hasIntersection()) intersectsBottom = true;
li.computeIntersection(p0, p1, corner[3], corner[0]);
if (li.isProper()) return true;
if (intersectsLeft && intersectsBottom) return true;
if (p0.equals2D(pt)) return true;
if (p1.equals2D(pt)) return true;
return false;
}
/*private*/
bool
HotPixel::intersectsPixelClosure(const Coordinate& p0,
const Coordinate& p1)
{
li.computeIntersection(p0, p1, corner[0], corner[1]);
if (li.hasIntersection()) return true;
li.computeIntersection(p0, p1, corner[1], corner[2]);
if (li.hasIntersection()) return true;
li.computeIntersection(p0, p1, corner[2], corner[3]);
if (li.hasIntersection()) return true;
li.computeIntersection(p0, p1, corner[3], corner[0]);
if (li.hasIntersection()) return true;
return false;
}
} // namespace geos.noding.snapround
} // namespace geos.noding
} // namespace geos
/**********************************************************************
* $Log$
* Revision 1.8 2006/05/03 17:51:24 strk
* system headers included after package headers
*
* Revision 1.7 2006/03/24 09:52:41 strk
* USE_INLINE => GEOS_INLINE
*
* Revision 1.6 2006/03/14 12:55:56 strk
* Headers split: geomgraphindex.h, nodingSnapround.h
*
* Revision 1.5 2006/03/03 10:46:21 strk
* Removed 'using namespace' from headers, added missing headers in .cpp files, removed useless includes in headers (bug#46)
*
* Revision 1.4 2006/02/21 16:53:49 strk
* MCIndexPointSnapper, MCIndexSnapRounder
*
* Revision 1.3 2006/02/19 19:46:49 strk
* Packages <-> namespaces mapping for most GEOS internal code (uncomplete, but working). Dir-level libs for index/ subdirs.
*
* Revision 1.2 2006/02/18 21:08:09 strk
* - new CoordinateSequence::applyCoordinateFilter method (slow but useful)
* - SegmentString::getCoordinates() doesn't return a clone anymore.
* - SegmentString::getCoordinatesRO() obsoleted.
* - SegmentString constructor does not promises constness of passed
* CoordinateSequence anymore.
* - NEW ScaledNoder class
* - Stubs for MCIndexPointSnapper and MCIndexSnapRounder
* - Simplified internal interaces of OffsetCurveBuilder and OffsetCurveSetBuilder
*
* Revision 1.1 2006/02/14 13:28:26 strk
* New SnapRounding code ported from JTS-1.7 (not complete yet).
* Buffer op optimized by using new snaprounding code.
* Leaks fixed in XMLTester.
*
**********************************************************************/
|