Golang double示例

说明

golang double示例是从最受好评的开源项目中提取的实现代码,你可以参考下面示例的使用方式。

编程语言: Golang

命名空间/包名称: C

示例#1
文件: gdal.go 项目: kikht/gdal

// Compute raster histogram
func (rb RasterBand) Histogram(
	min, max float64,
	buckets int,
	includeOutOfRange, approxOK int,
	progress ProgressFunc,
	data interface{},
) ([]int, error) {
	arg := &goGDALProgressFuncProxyArgs{
		progress, data,
	}

	histogram := make([]int, buckets)

	err := C.GDALGetRasterHistogram(
		rb.cval,
		C.double(min),
		C.double(max),
		C.int(buckets),
		(*C.int)(unsafe.Pointer(&histogram[0])),
		C.int(includeOutOfRange),
		C.int(approxOK),
		C.goGDALProgressFuncProxyB(),
		unsafe.Pointer(arg),
	)
	if err != 0 {
		return nil, error(err)
	}

	return histogram, nil
}

示例#2
文件: liblinear.go 项目: shirayu/liblinear

func toFeatureNodes(X *mat64.Dense) []*C.struct_feature_node {
	featureNodes := []*C.struct_feature_node{}

	nRows, nCols := X.Dims()

	for i := 0; i < nRows; i++ {
		row := []C.struct_feature_node{}
		for j := 0; j < nCols; j++ {
			val := X.At(i, j)
			if val != 0 {
				row = append(row, C.struct_feature_node{
					index: C.int(j + 1),
					value: C.double(val),
				})
			}
		}

		row = append(row, C.struct_feature_node{
			index: C.int(-1),
			value: C.double(0),
		})
		featureNodes = append(featureNodes, &row[0])
	}

	return featureNodes
}

示例#3
文件: surface.go 项目: ungerik/go-cairo

func NewPDFSurface(filename string, widthInPoints, heightInPoints float64, version PDFVersion) *Surface {
	cs := C.CString(filename)
	defer C.free(unsafe.Pointer(cs))
	s := C.cairo_pdf_surface_create(cs, C.double(widthInPoints), C.double(heightInPoints))
	C.cairo_pdf_surface_restrict_to_version(s, C.cairo_pdf_version_t(version))
	return &Surface{surface: s, context: C.cairo_create(s)}
}

示例#4
文件: complex.go 项目: ericsnowcurrently/qur-gopy

func NewComplex(v complex128) (*Complex, error) {
	ret := C.PyComplex_FromDoubles(C.double(real(v)), C.double(imag(v)))
	if ret == nil {
		return nil, exception()
	}
	return newComplex(ret), nil
}

示例#5
文件: cairo.go 项目: raichu/gotk3

// CreateForRectangle is a wrapper around cairo_surface_create_for_rectangle().
func (v *Surface) CreateForRectangle(x, y, width, height float64) *Surface {
	c := C.cairo_surface_create_for_rectangle(v.native(), C.double(x),
		C.double(y), C.double(width), C.double(height))
	s := wrapSurface(c)
	runtime.SetFinalizer(s, (*Surface).destroy)
	return s
}

示例#6
文件: vips.go 项目: godeep/bimg

func vipsWatermark(image *C.VipsImage, w Watermark) (*C.VipsImage, error) {
	var out *C.VipsImage

	// Defaults
	noReplicate := 0
	if w.NoReplicate {
		noReplicate = 1
	}

	text := C.CString(w.Text)
	font := C.CString(w.Font)
	background := [3]C.double{C.double(w.Background.R), C.double(w.Background.G), C.double(w.Background.B)}

	textOpts := vipsWatermarkTextOptions{text, font}
	opts := vipsWatermarkOptions{C.int(w.Width), C.int(w.DPI), C.int(w.Margin), C.int(noReplicate), C.float(w.Opacity), background}

	defer C.free(unsafe.Pointer(text))
	defer C.free(unsafe.Pointer(font))

	err := C.vips_watermark(image, &out, (*C.WatermarkTextOptions)(unsafe.Pointer(&textOpts)), (*C.WatermarkOptions)(unsafe.Pointer(&opts)))
	if err != 0 {
		return nil, catchVipsError()
	}

	return out, nil
}

示例#7
文件: canvas.go 项目: mishudark/gosexy

// Adaptively blurs the image by blurring less intensely near the edges and more intensely far from edges.
func (cv Canvas) AdaptiveBlur(sigma float64) bool {
	status := C.MagickAdaptiveBlurImage(cv.wand, C.double(0), C.double(sigma))
	if status == C.MagickFalse {
		return false
	}
	return true
}

示例#8
文件: sct_nix.go 项目: faf0/go-sct

// setColorTemp changes the Xrandr colors to reflect the specified color temperature.
func setColorTemp(gammar, gammag, gammab float64) {
	dpy := C.XOpenDisplay(nil)
	screenCount := C.screenCount(dpy)
	for screen := C.int(0); screen < screenCount; screen++ {
		root := C.RootWindowMacro(dpy, screen)

		res := C.XRRGetScreenResourcesCurrent(dpy, root)

		for c := C.int(0); c < res.ncrtc; c++ {
			crtcxid := C.crtcxid(res.crtcs, c)

			size := C.XRRGetCrtcGammaSize(dpy, crtcxid)
			crtc_gamma := C.XRRAllocGamma(size)
			for i := C.int(0); i < size; i++ {
				g := 65535.0 * float64(i) / float64(size)
				C.ushortSet(C.ushortCast(unsafe.Pointer(crtc_gamma.red)), i, C.double(g*gammar))
				C.ushortSet(C.ushortCast(unsafe.Pointer(crtc_gamma.green)), i, C.double(g*gammag))
				C.ushortSet(C.ushortCast(unsafe.Pointer(crtc_gamma.blue)), i, C.double(g*gammab))
			}
			C.XRRSetCrtcGamma(dpy, crtcxid, crtc_gamma)
			C.XFree(unsafe.Pointer(crtc_gamma))
		}

		C.XFree(unsafe.Pointer(res))
	}
	C.XCloseDisplay(dpy)
}

示例#9
文件: encoding.go 项目: godeep/wellington

// make is needed to create types for use by test
func makevalue(v interface{}) (UnionSassValue, error) {
	f := reflect.ValueOf(v)
	err := error(nil)
	switch f.Kind() {
	default:
		return C.sass_make_null(), err
	case reflect.Bool:
		return C.sass_make_boolean(C.bool(v.(bool))), err
	case reflect.String:
		return C.sass_make_string(C.CString(v.(string))), err
	case reflect.Struct: //only SassNumber and color.RGBA are supported
		if reflect.TypeOf(v).String() == "context.SassNumber" {
			var sn = v.(SassNumber)
			return C.sass_make_number(C.double(sn.Value), C.CString(sn.Unit)), err
		} else if reflect.TypeOf(v).String() == "color.RGBA" {
			var sc = v.(color.RGBA)
			return C.sass_make_color(C.double(sc.R), C.double(sc.G), C.double(sc.B), C.double(sc.A)), err
		} else {
			err = errors.New(fmt.Sprintf("The struct type %s is unsupported for marshalling", reflect.TypeOf(v).String()))
			return C.sass_make_null(), err
		}
	case reflect.Slice:
		// Initialize the list
		l := C.sass_make_list(C.size_t(f.Len()), C.SASS_COMMA)
		for i := 0; i < f.Len(); i++ {
			t, er := makevalue(f.Index(i).Interface())
			if err == nil && er != nil {
				err = er
			}
			C.sass_list_set_value(l, C.size_t(i), t)
		}
		return l, err
	}
}

示例#10
文件: body.go 项目: pebbe/novas

// Compute the apparent place of an object.
func (p *Body) App(t Time) BodyData {

	t.update()

	data := BodyData{}

	var ra, dec, dis C.double
	switch p.class {
	case clPLANET:
		if err := C.app_planet(C.double(t.jd_tt), &p.object, C.short(Accuracy), &ra, &dec, &dis); err != 0 {
			log.Fatalf("Error %d from app_planet (%s)\n", int(err), p.name)
		}
		data.Dis = float64(dis)
	case clSTAR:
		if err := C.app_star(C.double(t.jd_tt), &p.cat_entry, C.short(Accuracy), &ra, &dec); err != 0 {
			log.Fatalf("Error %d from app_star (%s)\n", int(err), p.name)
		}
		data.Dis = math.NaN()
	}
	data.RA = float64(ra)
	data.Dec = float64(dec)

	var elon, elat C.double
	C.equ2ecl(C.double(t.jd_tt), 0, C.short(Accuracy), ra, dec, &elon, &elat)
	data.ELon = float64(elon)
	data.ELat = float64(elat)

	return data
}

示例#11
文件: query_parameter.go 项目: ssrl/gosqlite3

func (p QueryParameter) Bind(s *Statement, value interface{}) (e os.Error) {
	var rv Errno
	switch v := value.(type) {
	case nil:
		rv = Errno(C.sqlite3_bind_null(s.cptr, C.int(p)))
	case int:
		rv = Errno(C.sqlite3_bind_int(s.cptr, C.int(p), C.int(v)))
	case string:
		rv = Errno(C.gosqlite3_bind_text(s.cptr, C.int(p), C.CString(v), C.int(len(v))))
	case int64:
		rv = Errno(C.sqlite3_bind_int64(s.cptr, C.int(p), C.sqlite3_int64(v)))
	case float32:
		rv = Errno(C.sqlite3_bind_double(s.cptr, C.int(p), C.double(v)))
	case float64:
		rv = Errno(C.sqlite3_bind_double(s.cptr, C.int(p), C.double(v)))
	default:
		buffer := new(bytes.Buffer)
		encoder := gob.NewEncoder(buffer)
		if encoder.Encode(value) != nil {
			rv = ENCODER
		} else {
			rawbuffer := string(buffer.Bytes())
			rv = Errno(C.gosqlite3_bind_blob(s.cptr, C.int(p), unsafe.Pointer(C.CString(rawbuffer)), C.int(len(rawbuffer))))
		}
	}
	if rv != OK {
		e = rv
	}
	return
}

示例#12
文件: coulomb.go 项目: postfix/gsl-1

func WaveFGArray(lMin float64, kmax int32, eta float64, x float64, fcArray []float64, gcArray []float64, fExponent []float64, gExponent []float64) int32 {
	_slice_header_4 := (*reflect.SliceHeader)(unsafe.Pointer(&fcArray))
	_slice_header_5 := (*reflect.SliceHeader)(unsafe.Pointer(&gcArray))
	_slice_header_6 := (*reflect.SliceHeader)(unsafe.Pointer(&fExponent))
	_slice_header_7 := (*reflect.SliceHeader)(unsafe.Pointer(&gExponent))
	return int32(C.gsl_sf_coulomb_wave_FG_array(C.double(lMin), C.int(kmax), C.double(eta), C.double(x), (*C.double)(unsafe.Pointer(_slice_header_4.Data)), (*C.double)(unsafe.Pointer(_slice_header_5.Data)), (*C.double)(unsafe.Pointer(_slice_header_6.Data)), (*C.double)(unsafe.Pointer(_slice_header_7.Data))))
}

示例#13
文件: backend.go 项目: mrlauer/pdfmaker

func (t *PDFStreamTextObject) WriteAt(text string, props TypesettingProps, x float64, y float64) error {
	var layout *C.PangoLayout
	var font_description *C.PangoFontDescription

	font_description = C.pango_font_description_new()
	cfontname := C.CString(props.Fontname)
	defer C.free(unsafe.Pointer(cfontname))
	C.pango_font_description_set_family(font_description, cfontname)
	C.pango_font_description_set_weight(font_description, C.PANGO_WEIGHT_NORMAL)
	C.pango_font_description_set_absolute_size(font_description, C.double(props.Fontsize)*C.PANGO_SCALE)

	layout = C.pango_cairo_create_layout(t.context)
	C.pango_layout_set_font_description(layout, font_description)
	width := props.PageWidth - props.LeftMargin - props.RightMargin
	fmt.Printf("width is %f\n", width)
	C.pango_layout_set_width(layout, C.int(width*C.PANGO_SCALE))
	C.pango_layout_set_justify(layout, C.TRUE)
	ctext := C.CString(text)
	defer C.free(unsafe.Pointer(ctext))
	C.pango_layout_set_text(layout, ctext, -1)

	C.cairo_set_source_rgb(t.context, 0.0, 0.0, 0.0)
	C.cairo_move_to(t.context, C.double(x), C.double(y))
	skip := props.Baselineskip
	nlines := int(C.pango_layout_get_line_count(layout))
	for i := 0; i < nlines; i++ {
		C.cairo_move_to(t.context, C.double(x), C.double(y+float64(i)*skip))
		C.pango_cairo_show_layout_line(t.context, C.pango_layout_get_line(layout, C.int(i)))
	}

	C.g_object_unref(C.gpointer(layout))
	C.pango_font_description_free(font_description)
	return nil
}

示例#14
文件: gfx.go 项目: Zwobot/Go-SDL

func (s *Surface) Zoom(zoomX, zoomY float64, smooth bool) *Surface {
	cSmooth := C.int(0)
	if smooth {
		cSmooth = C.int(1)
	}
	return wrap(C.zoomSurface(s.cSurface, C.double(zoomX), C.double(zoomY), cSmooth))
}

示例#15
文件: param.go 项目: sridif/gosvm

func toCParameter(param Parameters) *C.svm_parameter_t {
	cParam := C.parameter_new()

	// SVM type parameters
	cParam.svm_type = param.SVMType.svmType
	cParam.C = param.SVMType.cost
	cParam.nu = param.SVMType.nu
	cParam.p = param.SVMType.epsilon

	// Kernel type parameters
	cParam.kernel_type = param.Kernel.kernelType
	cParam.gamma = param.Kernel.gamma
	cParam.coef0 = param.Kernel.coef0
	cParam.degree = param.Kernel.degree

	cParam.cache_size = C.double(param.CacheSize)
	cParam.eps = C.double(param.Epsilon)

	if param.Shrinking {
		cParam.shrinking = 1
	}

	if param.Probability {
		cParam.probability = 1
	}

	return cParam
}

示例#16
文件: drawing_wand.go 项目: qwo/abelana-gcp

// Draws a bezier curve through a set of points on the image.
func (dw *DrawingWand) Bezier(coordinates []PointInfo) {
	ccoordinates := [1 << 16]C.PointInfo{}
	for k, v := range coordinates {
		ccoordinates[k] = C.PointInfo{C.double(v.X), C.double(v.Y)}
	}
	C.DrawBezier(dw.dw, C.size_t(len(coordinates)), (*C.PointInfo)(&ccoordinates[0]))
}

示例#17
文件: ovr.go 项目: postfix/ovr

func (state HSWDisplayState) toC() C.ovrHSWDisplayState {
	return C.ovrHSWDisplayState{
		Displayed:       ovrBool(state.Displayed),
		StartTime:       C.double(state.StartTime),
		DismissibleTime: C.double(state.DismissibleTime),
	}
}

示例#18
文件: draw.go 项目: sjn1978/ui

// ArcTo adds a circular arc to the current figure of the Path.
// You pass it the center of the arc, its radius in radians, the starting
// angle (couterclockwise) in radians, and the number of radians the
// arc should sweep (counterclockwise). A line segment is drawn from
// the current point to the start of the arc. The current point is set to
// the end of the arc.
func (p *Path) ArcTo(xCenter float64, yCenter float64, radius float64, startAngle float64, sweep float64, isNegative bool) {
	C.uiDrawPathArcTo(p.p,
		C.double(xCenter), C.double(yCenter),
		C.double(radius),
		C.double(startAngle), C.double(sweep),
		frombool(isNegative))
}

示例#19
文件: mapnik.go 项目: fawick/go-mapnik-1

// Render returns the map as an encoded image.
func (m *Map) Render(opts RenderOpts) ([]byte, error) {
	scaleFactor := opts.ScaleFactor
	if scaleFactor == 0.0 {
		scaleFactor = 1.0
	}
	i := C.mapnik_map_render_to_image(m.m, C.double(opts.Scale), C.double(scaleFactor))
	if i == nil {
		return nil, m.lastError()
	}
	defer C.mapnik_image_free(i)
	if opts.Format == "raw" {
		size := 0
		raw := C.mapnik_image_to_raw(i, (*C.size_t)(unsafe.Pointer(&size)))
		return C.GoBytes(unsafe.Pointer(raw), C.int(size)), nil
	}
	var format *C.char
	if opts.Format != "" {
		format = C.CString(opts.Format)
	} else {
		format = C.CString("png256")
	}
	b := C.mapnik_image_to_blob(i, format)
	if b == nil {
		return nil, errors.New("mapnik: " + C.GoString(C.mapnik_image_last_error(i)))
	}
	C.free(unsafe.Pointer(format))
	defer C.mapnik_image_blob_free(b)
	return C.GoBytes(unsafe.Pointer(b.ptr), C.int(b.len)), nil
}

示例#20
文件: draw.go 项目: sjn1978/ui

// TODO
func (m *Matrix) Scale(xCenter float64, yCenter float64, x float64, y float64) {
	cm := m.toC()
	C.uiDrawMatrixScale(cm,
		C.double(xCenter), C.double(yCenter),
		C.double(x), C.double(y))
	m.fromC(cm)
}

示例#21
文件: axpy.go 项目: hrautila/gomas

func axpby(Y, X *cmat.FloatMatrix, alpha, beta float64, N int) {
	var x, y C.mvec_t

	xr, _ := X.Size()
	x.md = (*C.double)(unsafe.Pointer(&X.Data()[0]))
	x.inc = C.int(1)
	if xr == 1 {
		x.inc = C.int(X.Stride())
	}
	yr, _ := Y.Size()
	y.md = (*C.double)(unsafe.Pointer(&Y.Data()[0]))
	y.inc = C.int(1)
	if yr == 1 {
		y.inc = C.int(Y.Stride())
	}
	if beta == 1.0 {
		C.__d_vec_axpy(
			(*C.mvec_t)(unsafe.Pointer(&y)),
			(*C.mvec_t)(unsafe.Pointer(&x)),
			C.double(alpha), C.int(N))
	} else {
		C.__d_vec_axpby(
			(*C.mvec_t)(unsafe.Pointer(&y)),
			(*C.mvec_t)(unsafe.Pointer(&x)),
			C.double(alpha), C.double(beta), C.int(N))
	}
	return
}

示例#22
文件: draw.go 项目: sjn1978/ui

// TODO
func (m *Matrix) Skew(x float64, y float64, xamount float64, yamount float64) {
	cm := m.toC()
	C.uiDrawMatrixSkew(cm,
		C.double(x), C.double(y),
		C.double(xamount), C.double(yamount))
	m.fromC(cm)
}

示例#23
文件: osr.go 项目: sn-amber/gdal

// Set geographic coordinate system
func (sr SpatialReference) SetGeographicCS(
	geogName, datumName, spheroidName string,
	semiMajor, flattening float64,
	pmName string,
	offset float64,
	angularUnits string,
	toRadians float64,
) error {
	cGeogName := C.CString(geogName)
	defer C.free(unsafe.Pointer(cGeogName))
	cDatumName := C.CString(datumName)
	defer C.free(unsafe.Pointer(cDatumName))
	cSpheroidName := C.CString(spheroidName)
	defer C.free(unsafe.Pointer(cSpheroidName))
	cPMName := C.CString(pmName)
	defer C.free(unsafe.Pointer(cPMName))
	cAngularUnits := C.CString(angularUnits)
	defer C.free(unsafe.Pointer(cAngularUnits))
	return C.OSRSetGeogCS(
		sr.cval,
		cGeogName,
		cDatumName,
		cSpheroidName,
		C.double(semiMajor),
		C.double(flattening),
		cPMName,
		C.double(offset),
		cAngularUnits,
		C.double(toRadians),
	).Err()
}

示例#24
文件: sdl_gfx.go 项目: veandco/go-sdl2

func RotoZoomSurfaceXY(src *sdl.Surface, angle, zoomx, zoomy float64, smooth int) *sdl.Surface {
	_angle := C.double(angle)
	_zoomx := C.double(zoomx)
	_zoomy := C.double(zoomy)
	_smooth := C.int(smooth)
	return (*sdl.Surface)(unsafe.Pointer(C.rotozoomSurfaceXY(unsafe.Pointer(src), _angle, _zoomx, _zoomy, _smooth)))
}

示例#25
文件: convert.go 项目: jcf/go-osx-plist

// ===== CFDate =====
func convertTimeToCFDate(t time.Time) C.CFDateRef {
	// truncate to milliseconds, to get a more predictable conversion
	ms := int64(time.Duration(t.UnixNano()) / time.Millisecond * time.Millisecond)
	nano := C.double(ms) / C.double(time.Second)
	nano -= C.kCFAbsoluteTimeIntervalSince1970
	return C.CFDateCreate(nil, C.CFAbsoluteTime(nano))
}

示例#26
文件: vpsc_unix.go 项目: tajtiattila/vpsc

func RemoveOverlaps(rects Rectangles) {
	if rects.Len() == 0 {
		return
	}

	rcv := make([]C.struct_rect, rects.Len())
	for i := 0; i < rects.Len(); i++ {
		rc := &rcv[i]
		x0, y0, x1, y1 := rects.Position(i)
		rc.x0 = C.double(x0)
		rc.x1 = C.double(x1)
		rc.y0 = C.double(y0)
		rc.y1 = C.double(y1)
		rc.fixed = boolchar(rects.Fixed(i))
		rc.allow_overlap = boolchar(rects.AllowOverlap(i))
	}

	removeOverlapsMtx.Lock()
	C.remove_overlaps(&rcv[0], C.unsigned(len(rcv)))
	removeOverlapsMtx.Unlock()

	for i := 0; i < rects.Len(); i++ {
		rc := &rcv[i]
		x0 := float64(rc.x0)
		x1 := float64(rc.x1)
		y0 := float64(rc.y0)
		y1 := float64(rc.y1)
		rects.SetPosition(i, x0, y0, x1, y1)
	}
}

示例#27
文件: surface.go 项目: ungerik/go-cairo

func (self *Surface) CreateForRectangle(x, y, width, height float64) *Surface {
	return &Surface{
		context: self.context,
		surface: C.cairo_surface_create_for_rectangle(self.surface,
			C.double(x), C.double(y), C.double(width), C.double(height)),
	}
}

示例#28
文件: liblinear.go 项目: npbool/golearn

func convert_vector(x []float64, bias float64) *C.struct_feature_node {
	n_ele := 0
	for i := 0; i < len(x); i += 1 {
		if x[i] > 0 {
			n_ele += 1
		}
	}
	n_ele += 2

	c_x := make([]C.struct_feature_node, n_ele)
	j := 0
	for i := 0; i < len(x); i += 1 {
		if x[i] > 0 {
			c_x[j].index = C.int(i + 1)
			c_x[j].value = C.double(x[i])
			j += 1
		}
	}
	if bias > 0 {
		c_x[j].index = C.int(0)
		c_x[j].value = C.double(0)
		j += 1
	}
	c_x[j].index = C.int(-1)
	return &c_x[0]
}

示例#29
文件: surface.go 项目: ungerik/go-cairo

func NewPSSurface(filename string, widthInPoints, heightInPoints float64, level PSLevel) *Surface {
	cs := C.CString(filename)
	defer C.free(unsafe.Pointer(cs))
	s := C.cairo_ps_surface_create(cs, C.double(widthInPoints), C.double(heightInPoints))
	C.cairo_ps_surface_restrict_to_level(s, C.cairo_ps_level_t(level))
	return &Surface{surface: s, context: C.cairo_create(s)}
}

示例#30
文件: zset.go 项目: Skycrab/go-zset

func (z *zset) RangeByScore(s1, s2 float64) []string {
	var reverse int
	var node *C.skiplistNode
	cs1, cs2 := C.double(s1), C.double(s2)
	if s1 <= s2 {
		reverse = 0
		node = C.slFirstInRange(z.sl, cs1, cs2)
	} else {
		reverse = 1
		node = C.slLastInRange(z.sl, cs2, cs1)
	}

	result := make([]string, 0)
	rr := C.int(reverse)
	for node != nil {
		if reverse == 1 {
			if node.score < cs2 {
				break
			}
		} else {
			if node.score > cs2 {
				break
			}
		}
		result = append(result, C.GoStringN(node.obj.ptr, C.int(node.obj.length)))
		node = C.getNextNode(node, rr)
	}
	return result
}

展开阅读全文