Skip to content

Commit

Permalink
Changed Add() Sub() to return result instead of modify
Browse files Browse the repository at this point in the history
  • Loading branch information
kevinabrandon committed Sep 23, 2016
1 parent e6bc478 commit ca26d1e
Showing 1 changed file with 35 additions and 23 deletions.
58 changes: 35 additions & 23 deletions opencv/cxtype.go
Original file line number Diff line number Diff line change
Expand Up @@ -573,7 +573,7 @@ type Point3D interface {
IncAngle() float64 // the inclination angle from the z direction
}

/************************************* Point *******************************************/
/************************************* CvPoint Structs *********************************/

type CvPoint C.CvPoint

Expand All @@ -587,6 +587,20 @@ func (p CvPoint) ToPoint() Point {
return Point{int(p.x), int(p.y)}
}

type CvPoint2D32f C.CvPoint2D32f

// returns a new CvPoint
func NewCvPoint2D32f(x, y float32) CvPoint2D32f {
return CvPoint2D32f{C.float(x), C.float(y)}
}

// Returns a Point
func (p CvPoint2D32f) ToPoint() Point2D32f {
return Point2D32f{float32(p.x), float32(p.y)}
}

/************************************* Point *******************************************/

type Point struct {
X int
Y int
Expand All @@ -600,14 +614,16 @@ func (p Point) ToPoint() Point {
return p
}

func (p *Point) Add(p2 Point) {
func (p Point) Add(p2 Point) Point {
p.X += p2.X
p.Y += p2.Y
return p
}

func (p *Point) Sub(p2 Point) {
func (p Point) Sub(p2 Point) Point {
p.X -= p2.X
p.Y -= p2.Y
return p
}

func (p Point) Radius() float64 {
Expand All @@ -624,18 +640,6 @@ func (p Point) Angle() float64 {

/************************************* Point2D32f **************************************/

type CvPoint2D32f C.CvPoint2D32f

// returns a new CvPoint
func NewCvPoint2D32f(x, y float32) CvPoint2D32f {
return CvPoint2D32f{C.float(x), C.float(y)}
}

// Returns a Point
func (p CvPoint2D32f) ToPoint() Point2D32f {
return Point2D32f{float32(p.x), float32(p.y)}
}

type Point2D32f struct {
X float32
Y float32
Expand All @@ -649,14 +653,16 @@ func (p Point2D32f) ToCvPoint() CvPoint2D32f {
return NewCvPoint2D32f(p.X, p.Y)
}

func (p *Point2D32f) Add(p2 Point2D32f) {
func (p Point2D32f) Add(p2 Point2D32f) Point2D32f {
p.X += p2.X
p.Y += p2.Y
return p
}

func (p *Point2D32f) Sub(p2 Point2D32f) {
func (p Point2D32f) Sub(p2 Point2D32f) Point2D32f {
p.X -= p2.X
p.Y -= p2.Y
return p
}

func (p Point2D32f) Radius() float64 {
Expand All @@ -679,16 +685,18 @@ type Point3D32f struct {
Z float32
}

func (p *Point3D32f) Add(p2 Point3D32f) {
func (p Point3D32f) Add(p2 Point3D32f) Point3D32f {
p.X += p2.X
p.Y += p2.Y
p.Z += p2.Z
return p
}

func (p *Point3D32f) Sub(p2 Point3D32f) {
func (p Point3D32f) Sub(p2 Point3D32f) Point3D32f {
p.X -= p2.X
p.Y -= p2.Y
p.Z -= p2.Z
return p
}

func (p Point3D32f) Radius() float64 {
Expand Down Expand Up @@ -721,14 +729,16 @@ func (p Point2D64f) ToPoint() Point {
return Point{int(p.X), int(p.Y)}
}

func (p *Point2D64f) Add(p2 Point2D64f) {
func (p Point2D64f) Add(p2 Point2D64f) Point2D64f {
p.X += p2.X
p.Y += p2.Y
return p
}

func (p *Point2D64f) Sub(p2 Point2D64f) {
func (p Point2D64f) Sub(p2 Point2D64f) Point2D64f {
p.X -= p2.X
p.Y -= p2.Y
return p
}

func (p Point2D64f) Radius() float64 {
Expand All @@ -751,16 +761,18 @@ type Point3D64f struct {
Z float64
}

func (p *Point3D64f) Add(p2 Point3D64f) {
func (p Point3D64f) Add(p2 Point3D64f) Point3D64f {
p.X += p2.X
p.Y += p2.Y
p.Z += p2.Z
return p
}

func (p *Point3D64f) Sub(p2 Point3D64f) {
func (p Point3D64f) Sub(p2 Point3D64f) Point3D64f {
p.X -= p2.X
p.Y -= p2.Y
p.Z -= p2.Z
return p
}

func (p Point3D64f) Radius() float64 {
Expand Down

0 comments on commit ca26d1e

Please sign in to comment.