Skip to content

Commit

Permalink
another check; simplified code
Browse files Browse the repository at this point in the history
  • Loading branch information
pebbe committed Aug 31, 2019
1 parent 5edcc3b commit 9be7742
Show file tree
Hide file tree
Showing 3 changed files with 8 additions and 8 deletions.
4 changes: 0 additions & 4 deletions v5/proj.c
Original file line number Diff line number Diff line change
@@ -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,
Expand Down
11 changes: 8 additions & 3 deletions v5/proj.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ import "C"

import (
"errors"
"fmt"
"math"
"runtime"
"unsafe"
Expand Down Expand Up @@ -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)
Expand Down Expand Up @@ -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])
Expand Down
1 change: 0 additions & 1 deletion v5/proj_go.h
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@
#include <proj.h>
#include <stdlib.h>

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);

Expand Down

0 comments on commit 9be7742

Please sign in to comment.