From 9be77427e7a49d2a30931f28511f9b831ccce1ad Mon Sep 17 00:00:00 2001
From: Peter Kleiweg
Date: Sat, 31 Aug 2019 16:57:47 +0200
Subject: [PATCH] another check; simplified code
---
v5/proj.c | 4 ----
v5/proj.go | 11 ++++++++---
v5/proj_go.h | 1 -
3 files changed, 8 insertions(+), 8 deletions(-)
diff --git a/v5/proj.c b/v5/proj.c
index 8313c75..f957856 100644
--- a/v5/proj.c
+++ b/v5/proj.c
@@ -1,9 +1,5 @@
#include "proj_go.h"
-int pjnull(PJ *pj) {
- return pj == 0 ? 0 : 1;
-}
-
void trans(PJ *pj, PJ_DIRECTION direction, double u1, double v1, double w1, double t1, double *u2, double *v2, double *w2, double *t2) {
PJ_COORD
co1,
diff --git a/v5/proj.go b/v5/proj.go
index 4662a64..9370b6d 100644
--- a/v5/proj.go
+++ b/v5/proj.go
@@ -9,6 +9,7 @@ import "C"
import (
"errors"
+ "fmt"
"math"
"runtime"
"unsafe"
@@ -106,7 +107,7 @@ func (ctx *Context) Create(definition string) (*PJ, error) {
cs := C.CString(definition)
defer C.free(unsafe.Pointer(cs))
pj := C.proj_create(ctx.pj_context, cs)
- if C.pjnull(pj) == 0 {
+ if pj == nil {
errno := C.proj_context_errno(ctx.pj_context)
err := C.GoString(C.proj_errno_string(errno))
return &PJ{}, errors.New(err)
@@ -249,19 +250,23 @@ func (p *PJ) TransSlice(direction Direction, u1, v1, w1, t1 []float64) (u2, v2,
st := C.size_t(C.sizeof_double)
- C.proj_trans_generic(
+ count := int(C.proj_trans_generic(
p.pj,
C.PJ_DIRECTION(direction),
up, st, unc,
vp, st, vnc,
wp, st, wnc,
- tp, st, tnc)
+ tp, st, tnc))
e := C.proj_errno(p.pj)
if e != 0 {
return nil, nil, nil, nil, errors.New(C.GoString(C.proj_errno_string(e)))
}
+ if count != n {
+ return nil, nil, nil, nil, fmt.Errorf("Got %d coordinates, translated %d coordinates", n, count)
+ }
+
u2 = make([]float64, un)
for i := 0; i < un; i++ {
u2[i] = float64(u[i])
diff --git a/v5/proj_go.h b/v5/proj_go.h
index d2b1ff0..3cfdf90 100644
--- a/v5/proj_go.h
+++ b/v5/proj_go.h
@@ -4,7 +4,6 @@
#include
#include
-int pjnull(PJ *pj);
void trans(PJ *pj, PJ_DIRECTION direction, double u1, double v1, double w1, double t1, double *u2, double *v2, double *w2, double *t2);
PJ_COORD uvwt(double u, double v, double w, double t);