Skip to content

Commit

Permalink
Add OffsetCurve
Browse files Browse the repository at this point in the history
  • Loading branch information
paulsmith committed Jun 14, 2013
1 parent fd2f14e commit 8bc66c1
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 0 deletions.
7 changes: 7 additions & 0 deletions geos/geom.go
Original file line number Diff line number Diff line change
Expand Up @@ -166,6 +166,13 @@ func (g *Geometry) BufferWithOpts(width float64, opts BufferOpts) (*Geometry, er
return geomFromC("BufferWithOpts", cGEOSBufferWithParams_r(handle, g.g, parms, C.double(width)))
}

// OffsetCurve computes a new linestring that is offset from the input
// linestring by the given distance and buffer options. A negative distance is
// offset on the right side; positive distance offset on the left side.
func (g *Geometry) OffsetCurve(distance float64, opts BufferOpts) (*Geometry, error) {
return geomFromC("OffsetCurve", cGEOSOffsetCurve_r(handle, g.g, C.double(distance), C.int(opts.QuadSegs), C.int(opts.JoinStyle), C.double(opts.MitreLimit)))
}

// Geometry Constructors

// NewPoint returns a new geometry of type Point, initialized with the given
Expand Down
12 changes: 12 additions & 0 deletions geos/geom_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -104,6 +104,18 @@ func TestGeometryBufferWithOpts(t *testing.T) {
}
}

func TestOffsetCurve(t *testing.T) {
g := Must(FromWKT("LINESTRING (0 10, 5 0, 10 10)"))
opts := BufferOpts{QuadSegs: 8, JoinStyle: JoinRound, MitreLimit: 5.0}
curve := Must(g.OffsetCurve(1.0, opts))
expected := Must(FromWKT(offsetCurve))
if !mustEqual(curve.EqualsExact(expected, 0.000001)) {
t.Errorf("want %v, got %v", expected, curve)
}
}

const offsetCurve = `LINESTRING (0.8944271909999159 10.4472135954999583, 5.0000000000000000 2.2360679774997907, 9.1055728090000834 10.4472135954999583)`

func reconstructGeom(g *Geometry) *Geometry {
typeId, err := g.Type()
if err != nil {
Expand Down

0 comments on commit 8bc66c1

Please sign in to comment.