repo_id
stringclasses
927 values
file_path
stringlengths
99
214
content
stringlengths
2
4.15M
TestXref
/home/linuxreitt/Michinereitt/Tuning/Workshop_Scripts/hf-codegen/data/golang_public_repos/vulndb/cmd/vulnreport/testdata/TestXref/no_xrefs.txtar
Copyright 2024 The Go Authors. All rights reserved. Use of this source code is governed by a BSD-style license that can be found in the LICENSE file. Expected output of test TestXref/no_xrefs command: "vulnreport xref 1" -- out -- GO-9999-0001: priority is unknown - module golang.org/x/vulndb not found -- logs -- info: xref: operating on 1 report(s) info: xref data/reports/GO-9999-0001.yaml info: data/reports/GO-9999-0001.yaml: no xrefs found info: xref: processed 1 report(s) (success=1; skip=0; error=0)
TestCVE
/home/linuxreitt/Michinereitt/Tuning/Workshop_Scripts/hf-codegen/data/golang_public_repos/vulndb/cmd/vulnreport/testdata/pkgsite/TestCVE/ok.json
{}
TestCVE
/home/linuxreitt/Michinereitt/Tuning/Workshop_Scripts/hf-codegen/data/golang_public_repos/vulndb/cmd/vulnreport/testdata/pkgsite/TestCVE/err.json
{}
TestXref
/home/linuxreitt/Michinereitt/Tuning/Workshop_Scripts/hf-codegen/data/golang_public_repos/vulndb/cmd/vulnreport/testdata/pkgsite/TestXref/no_xrefs.json
{}
TestXref
/home/linuxreitt/Michinereitt/Tuning/Workshop_Scripts/hf-codegen/data/golang_public_repos/vulndb/cmd/vulnreport/testdata/pkgsite/TestXref/found_xrefs.json
{}
TestFix
/home/linuxreitt/Michinereitt/Tuning/Workshop_Scripts/hf-codegen/data/golang_public_repos/vulndb/cmd/vulnreport/testdata/pkgsite/TestFix/no_change.json
{ "/mod/golang.org/x/vulndb/cmd/vulnreport": true }
TestLint
/home/linuxreitt/Michinereitt/Tuning/Workshop_Scripts/hf-codegen/data/golang_public_repos/vulndb/cmd/vulnreport/testdata/pkgsite/TestLint/no_lints.json
{}
TestLint
/home/linuxreitt/Michinereitt/Tuning/Workshop_Scripts/hf-codegen/data/golang_public_repos/vulndb/cmd/vulnreport/testdata/pkgsite/TestLint/found_lints.json
{}
TestTriage
/home/linuxreitt/Michinereitt/Tuning/Workshop_Scripts/hf-codegen/data/golang_public_repos/vulndb/cmd/vulnreport/testdata/pkgsite/TestTriage/all.json
{}
TestOSV
/home/linuxreitt/Michinereitt/Tuning/Workshop_Scripts/hf-codegen/data/golang_public_repos/vulndb/cmd/vulnreport/testdata/pkgsite/TestOSV/ok.json
{}
TestOSV
/home/linuxreitt/Michinereitt/Tuning/Workshop_Scripts/hf-codegen/data/golang_public_repos/vulndb/cmd/vulnreport/testdata/pkgsite/TestOSV/err.json
{}
TestFix
/home/linuxreitt/Michinereitt/Tuning/Workshop_Scripts/hf-codegen/data/golang_public_repos/vulndb/cmd/vulnreport/testdata/TestFix/no_change.txtar
Copyright 2024 The Go Authors. All rights reserved. Use of this source code is governed by a BSD-style license that can be found in the LICENSE file. Expected output of test TestFix/no_change command: "vulnreport fix 1" -- out -- data/reports/GO-9999-0001.yaml data/osv/GO-9999-0001.json -- logs -- info: fix: operating on 1 report(s) info: fix data/reports/GO-9999-0001.yaml info: GO-9999-0001: checking that all packages exist info: GO-9999-0001: checking symbols (use -skip-symbols to skip this) info: GO-9999-0001: skipping symbol checks for package golang.org/x/vulndb/cmd/vulnreport (no symbols) info: GO-9999-0001: checking for missing GHSAs and CVEs (use -skip-alias to skip this) info: GO-9999-0001: checking that all references are reachable info: fix: processed 1 report(s) (success=1; skip=0; error=0) -- data/reports/GO-9999-0001.yaml -- id: GO-9999-0001 modules: - module: golang.org/x/vulndb vulnerable_at: 0.0.0-20240716161253-dd7900b89e20 packages: - package: golang.org/x/vulndb/cmd/vulnreport summary: A problem with golang.org/x/vulndb description: A description of the issue review_status: REVIEWED -- data/osv/GO-9999-0001.json -- { "schema_version": "1.3.1", "id": "GO-9999-0001", "modified": "0001-01-01T00:00:00Z", "published": "0001-01-01T00:00:00Z", "summary": "A problem with golang.org/x/vulndb", "details": "A description of the issue", "affected": [ { "package": { "name": "golang.org/x/vulndb", "ecosystem": "Go" }, "ranges": [ { "type": "SEMVER", "events": [ { "introduced": "0" } ] } ], "ecosystem_specific": { "imports": [ { "path": "golang.org/x/vulndb/cmd/vulnreport" } ] } } ], "database_specific": { "url": "https://pkg.go.dev/vuln/GO-9999-0001", "review_status": "REVIEWED" } }
TestLint
/home/linuxreitt/Michinereitt/Tuning/Workshop_Scripts/hf-codegen/data/golang_public_repos/vulndb/cmd/vulnreport/testdata/TestLint/no_lints.txtar
Copyright 2024 The Go Authors. All rights reserved. Use of this source code is governed by a BSD-style license that can be found in the LICENSE file. Expected output of test TestLint/no_lints command: "vulnreport lint 1" -- out -- -- logs -- info: lint: operating on 1 report(s) info: lint data/reports/GO-9999-0001.yaml info: lint: processed 1 report(s) (success=1; skip=0; error=0)
TestLint
/home/linuxreitt/Michinereitt/Tuning/Workshop_Scripts/hf-codegen/data/golang_public_repos/vulndb/cmd/vulnreport/testdata/TestLint/found_lints.txtar
Copyright 2024 The Go Authors. All rights reserved. Use of this source code is governed by a BSD-style license that can be found in the LICENSE file. Expected output of test TestLint/found_lints command: "vulnreport lint 4" -- out -- -- logs -- info: lint: operating on 1 report(s) info: lint data/reports/GO-9999-0004.yaml ERROR: lint: GO-9999-0004 has 1 lint warnings: - references: missing advisory (required because report has no description or is UNREVIEWED) info: lint: processed 1 report(s) (success=0; skip=0; error=1)
TestCVE
/home/linuxreitt/Michinereitt/Tuning/Workshop_Scripts/hf-codegen/data/golang_public_repos/vulndb/cmd/vulnreport/testdata/proxy/TestCVE/ok.json
{ "golang.org/x/vulndb/@latest": { "body": "{\"Version\":\"v0.0.0-20240625224544-50d94f131669\",\"Time\":\"2024-06-25T22:45:44Z\",\"Origin\":{\"VCS\":\"git\",\"URL\":\"https://go.googlesource.com/vulndb\",\"Hash\":\"50d94f1316694e522dc8f1c8e9225bcec9ce0952\"}}", "status_code": 200 } }
TestCVE
/home/linuxreitt/Michinereitt/Tuning/Workshop_Scripts/hf-codegen/data/golang_public_repos/vulndb/cmd/vulnreport/testdata/proxy/TestCVE/err.json
{ "golang.org/x/tools/@latest": { "body": "{\"Version\":\"v0.22.0\",\"Time\":\"2024-06-04T17:56:46Z\",\"Origin\":{\"VCS\":\"git\",\"URL\":\"https://go.googlesource.com/tools\",\"Ref\":\"refs/tags/v0.22.0\",\"Hash\":\"bc6931db37c33e064504346d9259b3b6d20e13f6\"}}", "status_code": 200 } }
TestXref
/home/linuxreitt/Michinereitt/Tuning/Workshop_Scripts/hf-codegen/data/golang_public_repos/vulndb/cmd/vulnreport/testdata/proxy/TestXref/no_xrefs.json
{}
TestXref
/home/linuxreitt/Michinereitt/Tuning/Workshop_Scripts/hf-codegen/data/golang_public_repos/vulndb/cmd/vulnreport/testdata/proxy/TestXref/found_xrefs.json
{}
TestFix
/home/linuxreitt/Michinereitt/Tuning/Workshop_Scripts/hf-codegen/data/golang_public_repos/vulndb/cmd/vulnreport/testdata/proxy/TestFix/no_change.json
{ "golang.org/x/vulndb/@latest": { "body": "{\"Version\":\"v0.0.0-20240625224544-50d94f131669\",\"Time\":\"2024-06-25T22:45:44Z\",\"Origin\":{\"VCS\":\"git\",\"URL\":\"https://go.googlesource.com/vulndb\",\"Hash\":\"50d94f1316694e522dc8f1c8e9225bcec9ce0952\"}}", "status_code": 200 } }
TestLint
/home/linuxreitt/Michinereitt/Tuning/Workshop_Scripts/hf-codegen/data/golang_public_repos/vulndb/cmd/vulnreport/testdata/proxy/TestLint/no_lints.json
{ "golang.org/x/vulndb/@latest": { "body": "{\"Version\":\"v0.0.0-20240625224544-50d94f131669\",\"Time\":\"2024-06-25T22:45:44Z\",\"Origin\":{\"VCS\":\"git\",\"URL\":\"https://go.googlesource.com/vulndb\",\"Hash\":\"50d94f1316694e522dc8f1c8e9225bcec9ce0952\"}}", "status_code": 200 } }
TestLint
/home/linuxreitt/Michinereitt/Tuning/Workshop_Scripts/hf-codegen/data/golang_public_repos/vulndb/cmd/vulnreport/testdata/proxy/TestLint/found_lints.json
{ "golang.org/x/tools/@latest": { "body": "{\"Version\":\"v0.22.0\",\"Time\":\"2024-06-04T17:56:46Z\",\"Origin\":{\"VCS\":\"git\",\"URL\":\"https://go.googlesource.com/tools\",\"Ref\":\"refs/tags/v0.22.0\",\"Hash\":\"bc6931db37c33e064504346d9259b3b6d20e13f6\"}}", "status_code": 200 } }
TestTriage
/home/linuxreitt/Michinereitt/Tuning/Workshop_Scripts/hf-codegen/data/golang_public_repos/vulndb/cmd/vulnreport/testdata/proxy/TestTriage/all.json
{ "collectd.org/@latest": { "body": "{\"Version\":\"v0.6.0\",\"Time\":\"2024-01-04T14:25:32Z\",\"Origin\":{\"VCS\":\"git\",\"URL\":\"https://github.com/collectd/go-collectd\",\"Ref\":\"refs/tags/v0.6.0\",\"Hash\":\"500bf49ce4792086a56b4fb89ab7f750c23bffbb\"}}", "status_code": 200 }, "collectd.org/@v/v0.6.0.mod": { "body": "module collectd.org\n\ngo 1.19\n\nrequire (\n\tgithub.com/golang/protobuf v1.5.3\n\tgithub.com/google/go-cmp v0.6.0\n\tgo.uber.org/multierr v1.11.0\n\tgolang.org/x/net v0.19.0\n\tgoogle.golang.org/grpc v1.60.1\n)\n\nrequire (\n\tgolang.org/x/sys v0.15.0 // indirect\n\tgolang.org/x/text v0.14.0 // indirect\n\tgoogle.golang.org/genproto/googleapis/rpc v0.0.0-20231002182017-d307bd883b97 // indirect\n\tgoogle.golang.org/protobuf v1.31.0 // indirect\n)\n", "status_code": 200 }, "golang.org/x/tools/@latest": { "body": "{\"Version\":\"v0.22.0\",\"Time\":\"2024-06-04T17:56:46Z\",\"Origin\":{\"VCS\":\"git\",\"URL\":\"https://go.googlesource.com/tools\",\"Ref\":\"refs/tags/v0.22.0\",\"Hash\":\"bc6931db37c33e064504346d9259b3b6d20e13f6\"}}", "status_code": 200 }, "golang.org/x/tools/@v/v0.22.0.mod": { "body": "module golang.org/x/tools\n\ngo 1.19 // =\u003e default GODEBUG has gotypesalias=0\n\nrequire (\n\tgithub.com/google/go-cmp v0.6.0\n\tgithub.com/yuin/goldmark v1.4.13\n\tgolang.org/x/mod v0.18.0\n\tgolang.org/x/net v0.26.0\n\tgolang.org/x/sync v0.7.0\n\tgolang.org/x/telemetry v0.0.0-20240521205824-bda55230c457\n)\n\nrequire golang.org/x/sys v0.21.0 // indirect\n", "status_code": 200 }, "golang.org/x/vuln/@latest": { "body": "{\"Version\":\"v1.1.2\",\"Time\":\"2024-06-06T14:46:51Z\",\"Origin\":{\"VCS\":\"git\",\"URL\":\"https://go.googlesource.com/vuln\",\"Ref\":\"refs/tags/v1.1.2\",\"Hash\":\"3740f5cb12a3f93b18dbe200c4bcb6256f8586e2\"}}", "status_code": 200 }, "golang.org/x/vuln/@v/v1.1.2.mod": { "body": "module golang.org/x/vuln\n\ngo 1.18\n\nrequire (\n\tgithub.com/google/go-cmdtest v0.4.1-0.20220921163831-55ab3332a786\n\tgithub.com/google/go-cmp v0.6.0\n\tgolang.org/x/mod v0.18.0\n\tgolang.org/x/sync v0.7.0\n\tgolang.org/x/telemetry v0.0.0-20240522233618-39ace7a40ae7\n\tgolang.org/x/tools v0.22.0\n)\n\nrequire (\n\tgithub.com/google/renameio v0.1.0 // indirect\n\tgolang.org/x/sys v0.21.0 // indirect\n)\n", "status_code": 200 } }
TestOSV
/home/linuxreitt/Michinereitt/Tuning/Workshop_Scripts/hf-codegen/data/golang_public_repos/vulndb/cmd/vulnreport/testdata/proxy/TestOSV/ok.json
{ "golang.org/x/vulndb/@latest": { "body": "{\"Version\":\"v0.0.0-20240625224544-50d94f131669\",\"Time\":\"2024-06-25T22:45:44Z\",\"Origin\":{\"VCS\":\"git\",\"URL\":\"https://go.googlesource.com/vulndb\",\"Hash\":\"50d94f1316694e522dc8f1c8e9225bcec9ce0952\"}}", "status_code": 200 } }
TestOSV
/home/linuxreitt/Michinereitt/Tuning/Workshop_Scripts/hf-codegen/data/golang_public_repos/vulndb/cmd/vulnreport/testdata/proxy/TestOSV/err.json
{ "golang.org/x/tools/@latest": { "body": "{\"Version\":\"v0.22.0\",\"Time\":\"2024-06-04T17:56:46Z\",\"Origin\":{\"VCS\":\"git\",\"URL\":\"https://go.googlesource.com/tools\",\"Ref\":\"refs/tags/v0.22.0\",\"Hash\":\"bc6931db37c33e064504346d9259b3b6d20e13f6\"}}", "status_code": 200 } }
TestTriage
/home/linuxreitt/Michinereitt/Tuning/Workshop_Scripts/hf-codegen/data/golang_public_repos/vulndb/cmd/vulnreport/testdata/TestTriage/all.txtar
Copyright 2024 The Go Authors. All rights reserved. Use of this source code is governed by a BSD-style license that can be found in the LICENSE file. Expected output of test TestTriage/all command: "vulnreport triage " -- out -- issue test-issue-tracker/7 is likely duplicate - #7 shares alias(es) CVE-9999-0005 with data/reports/GO-9999-0005.yaml issue test-issue-tracker/10 is high priority - golang.org/x/vuln has 101 importers (>= 100) and as many reviewed (0) as likely-binary reports (0) issue test-issue-tracker/11 is possibly not Go - more than 20 percent of reports (1 of 1) with this module are NOT_GO_CODE triaged 3 issues: - 1 high priority - 2 low priority - 0 unknown priority - 1 likely duplicate - 1 possibly not Go helpful commands: $ vulnreport create 10 -- logs -- info: creating alias map for open issues info: triage: operating on 4 issue(s) info: triage: skipping issue #1 (already has report) info: triage 7 info: issue test-issue-tracker/7 is low priority - golang.org/x/tools has 50 importers (< 100) info: triage 10 info: triage 11 info: issue test-issue-tracker/11 is low priority - collectd.org has 0 importers (< 100) info: triage: processed 4 issue(s) (success=3; skip=1; error=0)
TestOSV
/home/linuxreitt/Michinereitt/Tuning/Workshop_Scripts/hf-codegen/data/golang_public_repos/vulndb/cmd/vulnreport/testdata/TestOSV/ok.txtar
Copyright 2024 The Go Authors. All rights reserved. Use of this source code is governed by a BSD-style license that can be found in the LICENSE file. Expected output of test TestOSV/ok command: "vulnreport osv 1" -- out -- data/osv/GO-9999-0001.json -- logs -- info: osv: operating on 1 report(s) info: osv data/reports/GO-9999-0001.yaml info: osv: processed 1 report(s) (success=1; skip=0; error=0) -- data/osv/GO-9999-0001.json -- { "schema_version": "1.3.1", "id": "GO-9999-0001", "modified": "0001-01-01T00:00:00Z", "published": "0001-01-01T00:00:00Z", "summary": "A problem with golang.org/x/vulndb", "details": "A description of the issue", "affected": [ { "package": { "name": "golang.org/x/vulndb", "ecosystem": "Go" }, "ranges": [ { "type": "SEMVER", "events": [ { "introduced": "0" } ] } ], "ecosystem_specific": { "imports": [ { "path": "golang.org/x/vulndb/cmd/vulnreport" } ] } } ], "database_specific": { "url": "https://pkg.go.dev/vuln/GO-9999-0001", "review_status": "REVIEWED" } }
TestOSV
/home/linuxreitt/Michinereitt/Tuning/Workshop_Scripts/hf-codegen/data/golang_public_repos/vulndb/cmd/vulnreport/testdata/TestOSV/err.txtar
Copyright 2024 The Go Authors. All rights reserved. Use of this source code is governed by a BSD-style license that can be found in the LICENSE file. Expected output of test TestOSV/err command: "vulnreport osv 4" -- out -- -- logs -- info: osv: operating on 1 report(s) info: osv data/reports/GO-9999-0004.yaml ERROR: osv: GO-9999-0004 has 1 lint warnings: - references: missing advisory (required because report has no description or is UNREVIEWED) info: osv: processed 1 report(s) (success=0; skip=0; error=1)
color
/home/linuxreitt/Michinereitt/Tuning/Workshop_Scripts/hf-codegen/data/golang_public_repos/vulndb/cmd/vulnreport/color/color.go
// Copyright 2024 The Go Authors. All rights reserved. // Use of this source code is governed by a BSD-style // license that can be found in the LICENSE file. package color const ( escape = "\033[" end = "m" // Reset all attributes and colors to their defaults. Reset = escape + "0" + end // Attribute codes Bold = escape + "1" + end Faint = escape + "2" + end Underline = escape + "4" + end Blink = escape + "5" + end // Foreground colors Black = escape + "30" + end Red = escape + "31" + end Green = escape + "32" + end Yellow = escape + "33" + end Blue = escape + "34" + end Magenta = escape + "35" + end Cyan = escape + "36" + end White = escape + "37" + end // Background colors BlackBG = escape + "40" + end RedBG = escape + "41" + end GreenBG = escape + "42" + end YellowBG = escape + "43" + end BlueBG = escape + "44" + end MagentaBG = escape + "45" + end CyanBG = escape + "46" + end WhiteBG = escape + "47" + end // High intensity foreground colors BlackHi = escape + "90" + end RedHi = escape + "91" + end GreenHi = escape + "92" + end YellowHi = escape + "93" + end BlueHi = escape + "94" + end MagentaHi = escape + "95" + end CyanHi = escape + "96" + end WhiteHi = escape + "97" + end // High intensity background colors BlackHiBG = escape + "100" + end RedHiBG = escape + "101" + end GreenHiBG = escape + "102" + end YellowHiBG = escape + "103" + end BlueHiBG = escape + "104" + end MagentaHiBG = escape + "105" + end CyanHiBG = escape + "106" + end WhiteHiBG = escape + "107" + end )
indexdb
/home/linuxreitt/Michinereitt/Tuning/Workshop_Scripts/hf-codegen/data/golang_public_repos/vulndb/cmd/indexdb/main.go
// Copyright 2023 The Go Authors. All rights reserved. // Use of this source code is governed by a BSD-style // license that can be found in the LICENSE file. // Command indexdb provides a tool for creating a v1 vulnerability // database from a folder containing OSV JSON files. package main import ( "flag" "log" "golang.org/x/vulndb/internal/database" ) var ( vulnsDir = flag.String("vulns", "", "Directory containing JSON OSV files") outDir = flag.String("out", "", "Directory to write database to") ) func main() { flag.Parse() if *vulnsDir == "" { log.Fatal("flag -vulns must be set") } if *outDir == "" { log.Fatal("flag -out must be set") } db, err := database.RawLoad(*vulnsDir) if err != nil { log.Fatal(err) } if err = db.Write(*outDir); err != nil { log.Fatal(err) } }
forks
/home/linuxreitt/Michinereitt/Tuning/Workshop_Scripts/hf-codegen/data/golang_public_repos/vulndb/cmd/forks/main.go
// Copyright 2021 The Go Authors. All rights reserved. // Use of this source code is governed by a BSD-style // license that can be found in the LICENSE file. //go:build go1.21 // Command forks determines if Go modules are similar. package main import ( "cmp" "context" "encoding/gob" "errors" "flag" "fmt" "log" "os" "os/signal" "slices" "strings" "time" ) func main() { out := flag.CommandLine.Output() flag.Usage = func() { fmt.Fprintf(out, "usage: forks [ PATH | PATH@VERSION ] ...\n") fmt.Fprintf(out, "Print potential forks for each module path or module path @ version.\n") fmt.Fprintf(out, "Each fork is preceded by its score. Scores range from 0 to 10, with 10 meaning most\n") fmt.Fprintf(out, "similar. Only matches with scores of at least 6 are printed.\n") fmt.Fprintf(out, "Scores are approximations that are based on partial data (not the full module content),\n") fmt.Fprintf(out, "so even a score of 10 does not mean that the modules are identical.\n") flag.PrintDefaults() } flag.Parse() ctx, _ := signal.NotifyContext(context.Background(), os.Interrupt) if err := run(ctx); err != nil { log.Fatal(err) } } type Forks struct { Comment string Timestamp time.Time MinScore int // smallest score that is stored Modules []string // mapping from int to module@version Matches map[int][]Score // from module ID to matches and their scores } type Score struct { Module int // index into Forks.Modules Score int // 0 - 10 } func run(_ context.Context) error { if flag.NArg() == 0 { flag.Usage() return nil } dbFilename := os.Getenv("FORKSDB") if dbFilename == "" { return errors.New("must set FORKSDB to file") } f, err := os.Open(dbFilename) if err != nil { return err } defer f.Close() dec := gob.NewDecoder(f) var db Forks if err := dec.Decode(&db); err != nil { return err } // Build a map from path@version and path to ID. modsToIDs := buildIndex(db.Modules) // Print the forks for each arg. for _, arg := range flag.Args() { if ids, ok := modsToIDs[arg]; ok { for _, id := range ids { fmt.Printf("%s\n", db.Modules[id]) matches := db.Matches[id] slices.SortFunc(matches, func(s1, s2 Score) int { if c := cmp.Compare(s1.Score, s2.Score); c != 0 { return c } return cmp.Compare(db.Modules[s1.Module], db.Modules[s2.Module]) }) for _, m := range matches { fmt.Printf(" %2d %s\n", m.Score, db.Modules[m.Module]) } } } else { fmt.Printf("%s: no forks\n", arg) } } return nil } // buildIndex builds a map from "path@version" and "path" to IDs. func buildIndex(mods []string) map[string][]int { modsToIDs := map[string][]int{} for i, mv := range mods { path, _, found := strings.Cut(mv, "@") if !found { panic(fmt.Errorf("no '@' in %s", mv)) } modsToIDs[mv] = append(modsToIDs[mv], i) modsToIDs[path] = append(modsToIDs[path], i) } return modsToIDs }
issue
/home/linuxreitt/Michinereitt/Tuning/Workshop_Scripts/hf-codegen/data/golang_public_repos/vulndb/cmd/issue/main.go
// Copyright 2022 The Go Authors. All rights reserved. // Use of this source code is governed by a BSD-style // license that can be found in the LICENSE file. // Command issue provides a tool for creating an issue on the x/vulndb issue // tracker. // // This is used to creating missing issues that were not created by the vulndb // worker for various reasons. package main import ( "context" "flag" "fmt" "log" "os" "sort" "strings" "golang.org/x/vulndb/internal" "golang.org/x/vulndb/internal/ghsa" "golang.org/x/vulndb/internal/gitrepo" "golang.org/x/vulndb/internal/idstr" "golang.org/x/vulndb/internal/issues" "golang.org/x/vulndb/internal/proxy" "golang.org/x/vulndb/internal/report" "golang.org/x/vulndb/internal/worker" ) var ( githubToken = flag.String("ghtoken", os.Getenv("VULN_GITHUB_ACCESS_TOKEN"), "GitHub access token") issueRepo = flag.String("issue-repo", "github.com/golang/vulndb", "repo to create issues in") ) func main() { ctx := context.Background() flag.Usage = func() { fmt.Fprintf(flag.CommandLine.Output(), "usage: issue [cmd] [filename | cves]\n") fmt.Fprintf(flag.CommandLine.Output(), " triage [filename]: create issues to triage on the tracker for the aliases listed in the file\n") fmt.Fprintf(flag.CommandLine.Output(), " excluded [filename]: create excluded issues on the tracker for the aliases listed in the file\n") fmt.Fprintf(flag.CommandLine.Output(), " placeholder [cve(s)]: create a placeholder issue on the tracker for the given CVE(s)\n") fmt.Fprintf(flag.CommandLine.Output(), "\n") fmt.Fprintf(flag.CommandLine.Output(), "Flags:\n") flag.PrintDefaults() } flag.Parse() if flag.NArg() != 2 { flag.Usage() os.Exit(1) } cmd := flag.Args()[0] filename := flag.Args()[1] owner, repoName, err := gitrepo.ParseGitHubRepo(*issueRepo) if err != nil { log.Fatal(err) } c := issues.NewClient(ctx, &issues.Config{Owner: owner, Repo: repoName, Token: *githubToken}) ghsaClient := ghsa.NewClient(ctx, *githubToken) pc := proxy.NewDefaultClient() switch cmd { case "triage": err = createIssueToTriage(ctx, c, ghsaClient, pc, filename) case "excluded": err = createExcluded(ctx, c, ghsaClient, pc, filename) case "placeholder": err = createPlaceholder(ctx, c, flag.Args()[1:]) default: err = fmt.Errorf("unsupported command: %q", cmd) } if err != nil { log.Fatal(err) } } func createIssueToTriage(ctx context.Context, c *issues.Client, ghsaClient *ghsa.Client, pc *proxy.Client, filename string) (err error) { aliases, err := parseAliases(filename) if err != nil { return err } for _, alias := range aliases { if err := constructIssue(ctx, c, ghsaClient, pc, alias, []string{"NeedsTriage"}); err != nil { return err } } return nil } func createExcluded(ctx context.Context, c *issues.Client, ghsaClient *ghsa.Client, pc *proxy.Client, filename string) (err error) { records, err := parseExcluded(filename) if err != nil { return err } for _, r := range records { if err := constructIssue(ctx, c, ghsaClient, pc, r.identifier, []string{r.category.ToLabel()}); err != nil { return err } } return nil } func createPlaceholder(ctx context.Context, c *issues.Client, args []string) error { for _, arg := range args { if !idstr.IsCVE(arg) { return fmt.Errorf("%q is not a CVE", arg) } aliases := []string{arg} packages := []string{"<placeholder>"} bodies := []string{fmt.Sprintf("This is a placeholder issue for %q.", arg)} if err := publishIssue(ctx, c, packages, aliases, bodies, []string{"first party"}); err != nil { return err } } return nil } func constructIssue(ctx context.Context, c *issues.Client, ghsaClient *ghsa.Client, pc *proxy.Client, alias string, labels []string) (err error) { var ghsas []*ghsa.SecurityAdvisory if strings.HasPrefix(alias, "GHSA") { sa, err := ghsaClient.FetchGHSA(ctx, alias) if err != nil { return err } ghsas = append(ghsas, sa) } else if strings.HasPrefix(alias, "CVE") { ghsas, err = ghsaClient.ListForCVE(ctx, alias) if err != nil { return err } if len(ghsas) == 0 { fmt.Printf("%q does not have a GHSA\n", alias) return nil } if len(ghsas) > 1 { fmt.Printf("%q has multiple GHSAs\n", alias) } } // Only include the first package path in the issue. pkgPath := "unknown" if len(ghsas[0].Vulns) != 0 { pkgPath = ghsas[0].Vulns[0].Package } // Put all the identifiers in the title. var ( ids []string bodies []string ) rc, err := report.NewDefaultClient(ctx) if err != nil { return err } for _, sa := range ghsas { for _, id := range sa.Identifiers { ids = append(ids, id.Value) } r := report.New(sa, pc) body, err := worker.NewIssueBody(r, sa.Description, rc) if err != nil { return err } bodies = append(bodies, body) } return publishIssue(ctx, c, []string{pkgPath}, ids, bodies, labels) } func publishIssue(ctx context.Context, c *issues.Client, packages, aliases, bodies, labels []string) error { sort.Strings(aliases) iss := &issues.Issue{ Title: fmt.Sprintf("x/vulndb: potential Go vuln in %s: %s", strings.Join(packages, ", "), strings.Join(aliases, ", ")), Body: strings.Join(bodies, "\n\n----------\n\n"), Labels: labels, } issNum, err := c.CreateIssue(ctx, iss) if err != nil { return err } fmt.Printf("published issue https://%s/issues/%d (%s)\n", *issueRepo, issNum, strings.Join(aliases, ", ")) return nil } type record struct { identifier string category report.ExcludedReason } func parseAliases(filename string) (aliases []string, err error) { lines, err := internal.ReadFileLines(filename) if err != nil { return nil, err } aliases = append(aliases, lines...) return aliases, nil } func parseExcluded(filename string) (records []*record, err error) { lines, err := internal.ReadFileLines(filename) if err != nil { return nil, err } for i, line := range lines { parts := strings.Split(line, ",") if len(parts) != 2 { return nil, fmt.Errorf("wrong number of fields on line %d: %q", i, line) } r := &record{ category: report.ExcludedReason(parts[0]), identifier: parts[1], } records = append(records, r) } return records, nil }
inspect
/home/linuxreitt/Michinereitt/Tuning/Workshop_Scripts/hf-codegen/data/golang_public_repos/vulndb/cmd/inspect/main.go
// Copyright 2023 The Go Authors. All rights reserved. // Use of this source code is governed by a BSD-style // license that can be found in the LICENSE file. // Command inspect provides insights into the current contents of vulndb. package main import ( "context" "flag" "fmt" "log" "os" "sort" "strconv" "strings" "text/tabwriter" "time" "golang.org/x/exp/maps" "golang.org/x/vulndb/internal/genericosv" "golang.org/x/vulndb/internal/ghsarepo" "golang.org/x/vulndb/internal/gitrepo" "golang.org/x/vulndb/internal/report" "golang.org/x/vulndb/internal/stdlib" ) var ( localGHSA = flag.String("local-ghsa", "", "path to local GHSA repo, instead of cloning remote") detail = flag.Bool("detail", false, "if true, print more details on GHSAs not yet in vulndb") ) func main() { start := time.Now() flag.Parse() localRepo, err := gitrepo.Open(context.Background(), ".") if err != nil { log.Fatal(err) } rc, err := report.NewClient(localRepo) if err != nil { log.Fatal(err) } var gc *ghsarepo.Client if *localGHSA != "" { repo, err := gitrepo.Open(context.Background(), *localGHSA) if err != nil { log.Fatal(err) } gc, err = ghsarepo.NewClientFromRepo(repo) if err != nil { log.Fatal(err) } } else { log.Println("cloning remote GHSA repo (use -local-ghsa to speed this up)...") gc, err = ghsarepo.NewClient() if err != nil { log.Fatal(err) } } overall, byYear := summarize(gc.List(), rc.List()) display(overall, byYear) if *detail { fmt.Println("\n=== GHSAs not yet in vulndb ===") displayGHSAs(overall.ghsasNotInVDB) } fmt.Printf("\n%s\n", time.Since(start).Truncate(time.Millisecond)) } func display(overall *summary, byYear map[int]*summary) { tw := tabwriter.NewWriter(os.Stdout, 2, 4, 2, ' ', 0) years := maps.Keys(byYear) sort.Sort(sort.Reverse(sort.IntSlice(years))) // sort descending headings := func() { fmt.Fprintf(tw, "\t%s", "Total") for _, year := range years { fmt.Fprintf(tw, "\t%4d", year) } fmt.Fprintf(tw, "\n") fmt.Fprintf(tw, "\t%s", "-----") for range years { fmt.Fprintf(tw, "\t%4s", "----") } fmt.Fprintf(tw, "\n") } data := func(desc string, indent int, getData func(s *summary) int) { var indentS string if indent > 0 { indentS = strings.Repeat("--", indent) + " " } fmt.Fprintf(tw, "%s%s\t%4d", indentS, desc, getData(overall)) for _, year := range years { fmt.Fprintf(tw, "\t%4d", getData(byYear[year])) } fmt.Fprintf(tw, "\n") } newline := func() { fmt.Fprintf(tw, "%s\n", strings.Repeat("\t", len(years))) // preserve tab formatting } // Summary of Go reports by year. headings() data("Go reports", 0, func(s *summary) int { return s.reports }) data("Regular reports", 1, func(s *summary) int { return s.regular }) for _, rs := range []report.ReviewStatus{report.Reviewed, report.Unreviewed} { data(rs.String(), 2, func(s *summary) int { return s.regularByReview[rs] }) } data("Withdrawn reports", 1, func(s *summary) int { return s.withdrawn }) data("Excluded reports", 1, func(s *summary) int { return s.excluded }) for _, er := range report.ExcludedReasons { data(string(er), 2, func(s *summary) int { return s.excludedByReason[er] }) } data("Reports with no GHSA (+)", 1, func(s *summary) int { return s.noGHSA }) data("Stdlib, toolchain and x/ reports", 1, func(s *summary) int { return s.firstParty }) // Summary of GHSAs by year. newline() headings() data("GHSAs affecting Go", 0, func(s *summary) int { return s.ghsas }) data("GHSAs not yet in vulndb (++)", 1, func(s *summary) int { return len(s.ghsasNotInVDB) }) // Additional context. newline() fmt.Fprintln(tw, "(+) \"Go reports with no GHSA\" are published third-party Go reports\nwith no corresponding GHSA. (This isn't a problem; it's informational only.)") fmt.Fprintln(tw, "(++) \"GHSAs not yet in vulndb\" are published GHSAs with no corresponding\nGo report. There may already be an open issue on the tracker for these.") tw.Flush() } func displayGHSAs(ghsas []string) { for i, g := range ghsas { fmt.Println() fmt.Printf("%d) %s\n", i+1, g) fmt.Printf("https://github.com/advisories/%s\n", g) fmt.Printf("search issue tracker: https://github.com/golang/vulndb/issues?q=is%%3Aissue+%s\n", g) } } type summary struct { reports, regular, withdrawn, excluded, noGHSA, firstParty int ghsas int ghsasNotInVDB []string excludedByReason map[report.ExcludedReason]int regularByReview map[report.ReviewStatus]int } func newSummary() *summary { return &summary{ excludedByReason: make(map[report.ExcludedReason]int), regularByReview: make(map[report.ReviewStatus]int), } } func summarize(ghsas []*genericosv.Entry, reports []*report.Report) (*summary, map[int]*summary) { overall := newSummary() byYear := make(map[int]*summary) ghsasWithReport := make(map[string]bool) for _, r := range reports { year, err := strconv.Atoi(strings.Split(r.ID, "-")[1]) if err != nil { panic(err) } if _, ok := byYear[year]; !ok { byYear[year] = newSummary() } yearSummary := byYear[year] overall.reports++ yearSummary.reports++ if isFirstParty(r) { overall.firstParty++ yearSummary.firstParty++ } if r.IsExcluded() { overall.excluded++ overall.excludedByReason[r.Excluded]++ yearSummary.excluded++ yearSummary.excludedByReason[r.Excluded]++ } else if r.Withdrawn != nil { overall.withdrawn++ yearSummary.withdrawn++ } else { overall.regular++ yearSummary.regular++ overall.regularByReview[r.ReviewStatus]++ yearSummary.regularByReview[r.ReviewStatus]++ } if len(r.GHSAs) == 0 && r.CVEMetadata == nil { overall.noGHSA++ yearSummary.noGHSA++ } for _, ghsa := range r.GHSAs { ghsasWithReport[ghsa] = true } } for _, ghsa := range ghsas { year := ghsa.Published.Year() if _, ok := byYear[year]; !ok { byYear[year] = newSummary() } yearSummary := byYear[year] overall.ghsas++ yearSummary.ghsas++ if _, ok := ghsasWithReport[ghsa.ID]; !ok { overall.ghsasNotInVDB = append(overall.ghsasNotInVDB, ghsa.ID) yearSummary.ghsasNotInVDB = append(yearSummary.ghsasNotInVDB, ghsa.ID) } } return overall, byYear } func isFirstParty(r *report.Report) bool { for _, m := range r.Modules { if stdlib.IsStdModule(m.Module) || stdlib.IsCmdModule(m.Module) || stdlib.IsXModule(m.Module) { return true } } return false }
modinfo
/home/linuxreitt/Michinereitt/Tuning/Workshop_Scripts/hf-codegen/data/golang_public_repos/vulndb/cmd/modinfo/main.go
// Copyright 2023 The Go Authors. All rights reserved. // Use of this source code is governed by a BSD-style // license that can be found in the LICENSE file. // Command modinfo displays module info from the pkgsite database. // // One-time setup: install the cloud sql proxy: // // > curl -o cloud-sql-proxy https://storage.googleapis.com/cloud-sql-connectors/cloud-sql-proxy/v2.6.0/cloud-sql-proxy.linux.amd64 // > chmod +x cloud-sql-proxy // > ./cloud-sql-proxy $MODINFO_DB?port=5429 & // // cloud-sql-proxy must be running in the background to run this command. // If it stops, restart it by running the last command above. // // You will also need to do // // > gcloud auth application-default login // // if you haven't already. package main import ( "context" "fmt" "log" "os" "sort" "strings" "text/tabwriter" "golang.org/x/exp/maps" "golang.org/x/vulndb/cmd/modinfo/internal/pkgsitedb" ) func main() { args := os.Args[1:] if len(args) == 0 { log.Fatal("missing module paths") } var cfg pkgsitedb.Config cfg.User = mustEnv("MODINFO_USER") cfg.Password = mustEnv("MODINFO_PASSWORD") cfg.Host = "127.0.0.1" cfg.Port = "5429" cfg.DBName = mustEnv("MODINFO_DBNAME") ctx := context.Background() db, err := pkgsitedb.Open(ctx, cfg) if err != nil { fmt.Fprintf(os.Stderr, `Could not open DB. You may need to run cloud-sql-proxy $MODINFO_DB?port=5429 & Details: %v`, err) fmt.Fprintln(os.Stderr) os.Exit(1) } defer db.Close() for _, modpath := range args { mod, err := pkgsitedb.QueryModule(ctx, db, modpath) if err != nil { log.Fatal(err) } display(mod) } } func mustEnv(ev string) string { if r := os.Getenv(ev); r != "" { return r } fmt.Fprintf(os.Stderr, "need value for environment variable %s\n", ev) os.Exit(1) return "" } func display(m *pkgsitedb.Module) { if len(m.Packages) == 0 { fmt.Printf("No packages for module %s; maybe it doesn't exist?\n", m.Path) return } versionMap := map[string]bool{} for _, p := range m.Packages { versionMap[p.Version] = true } versions := maps.Keys(versionMap) sort.Strings(versions) fmt.Printf("==== %s @ %s ====\n", m.Path, strings.Join(versions, ", ")) tw := tabwriter.NewWriter(os.Stdout, 2, 4, 1, ' ', 0) fmt.Fprintf(tw, "%s\t%s\n", "Import Path", "Importers") for _, p := range m.Packages { fmt.Fprintf(tw, "%s\t%5d\n", p.Path, p.NumImporters) } tw.Flush() }
pkgsitedb
/home/linuxreitt/Michinereitt/Tuning/Workshop_Scripts/hf-codegen/data/golang_public_repos/vulndb/cmd/modinfo/internal/pkgsitedb/db_plan9.go
// Copyright 2022 The Go Authors. All rights reserved. // Use of this source code is governed by a BSD-style // license that can be found in the LICENSE file. //go:build plan9 package pkgsitedb import ( "context" "database/sql" "errors" ) var errDoesNotCompile = errors.New("github.com/lib/pq does not compile on plan9") type Config struct { User string PasswordSecret string Password string Host string Port string DBName string } func Open(ctx context.Context, cfg Config) (_ *sql.DB, err error) { return nil, errDoesNotCompile } type Module struct { Path string Packages []*Package } type Package struct { Path string Version string NumImporters int } func QueryModule(ctx context.Context, db *sql.DB, modulePath string) (*Module, error) { return nil, errDoesNotCompile }
pkgsitedb
/home/linuxreitt/Michinereitt/Tuning/Workshop_Scripts/hf-codegen/data/golang_public_repos/vulndb/cmd/modinfo/internal/pkgsitedb/secrets.go
// Copyright 2023 The Go Authors. All rights reserved. // Use of this source code is governed by a BSD-style // license that can be found in the LICENSE file. package pkgsitedb
pkgsitedb
/home/linuxreitt/Michinereitt/Tuning/Workshop_Scripts/hf-codegen/data/golang_public_repos/vulndb/cmd/modinfo/internal/pkgsitedb/db.go
// Copyright 2022 The Go Authors. All rights reserved. // Use of this source code is governed by a BSD-style // license that can be found in the LICENSE file. //go:build !plan9 // Package pkgsitedb provides functionality for connecting to the pkgsite // database. package pkgsitedb import ( "context" "database/sql" "fmt" "regexp" secretmanager "cloud.google.com/go/secretmanager/apiv1" smpb "cloud.google.com/go/secretmanager/apiv1/secretmanagerpb" _ "github.com/lib/pq" ) type Config struct { User string PasswordSecret string Password string Host string Port string DBName string } // Open creates a connection to the pkgsite database. func Open(ctx context.Context, cfg Config) (_ *sql.DB, err error) { if cfg.Password == "" { var err error cfg.Password, err = getSecret(ctx, cfg.PasswordSecret) if err != nil { return nil, err } } connString := fmt.Sprintf( "user='%s' password='%s' host='%s' port=%s dbname='%s' sslmode='disable'", cfg.User, cfg.Password, cfg.Host, cfg.Port, cfg.DBName) db, err := sql.Open("postgres", connString) if err != nil { return nil, err } if err := db.PingContext(ctx); err != nil { return nil, err } return db, nil } type Module struct { Path string Packages []*Package } type Package struct { Path string Version string NumImporters int } func QueryModule(ctx context.Context, db *sql.DB, modulePath string) (*Module, error) { query := ` SELECT package_path, version, imported_by_count FROM search_documents WHERE module_path = $1 ORDER BY 3 DESC ` rows, err := db.QueryContext(ctx, query, modulePath) if err != nil { return nil, err } defer rows.Close() m := &Module{Path: modulePath} for rows.Next() { var p Package if err := rows.Scan(&p.Path, &p.Version, &p.NumImporters); err != nil { return nil, err } m.Packages = append(m.Packages, &p) } if err := rows.Err(); err != nil { return nil, err } return m, nil } var passwordRegexp = regexp.MustCompile(`password=\S+`) func redactPassword(dbinfo string) string { return passwordRegexp.ReplaceAllLiteralString(dbinfo, "password=REDACTED") } // getSecret retrieves a secret from the GCP Secret Manager. // secretFullName should be of the form "projects/PROJECT/secrets/NAME". func getSecret(ctx context.Context, secretFullName string) (_ string, err error) { client, err := secretmanager.NewClient(ctx) if err != nil { return "", err } defer client.Close() result, err := client.AccessSecretVersion(ctx, &smpb.AccessSecretVersionRequest{ Name: secretFullName + "/versions/latest", }) if err != nil { return "", err } return string(result.Payload.Data), nil }
pkgsitedb
/home/linuxreitt/Michinereitt/Tuning/Workshop_Scripts/hf-codegen/data/golang_public_repos/vulndb/cmd/modinfo/internal/pkgsitedb/db_test.go
// Copyright 2022 The Go Authors. All rights reserved. // Use of this source code is governed by a BSD-style // license that can be found in the LICENSE file. //go:build !plan9 package pkgsitedb import ( // imported to register the postgres database driver "context" "encoding/json" "flag" "fmt" "os" "testing" _ "github.com/lib/pq" ) var dbConfigFile = flag.String("dbconf", "", "filename with db config as JSON") func TestQueryModule(t *testing.T) { if *dbConfigFile == "" { t.Skip("missing -dbconf") } f, err := os.Open(*dbConfigFile) if err != nil { t.Fatal(err) } defer f.Close() var cfg Config if err := json.NewDecoder(f).Decode(&cfg); err != nil { t.Fatal(err) } ctx := context.Background() db, err := Open(ctx, cfg) if err != nil { t.Fatal(err) } defer db.Close() if err := db.PingContext(ctx); err != nil { t.Fatal(err) } m, err := QueryModule(ctx, db, "golang.org/x/tools") if err != nil { t.Fatal(err) } for _, p := range m.Packages { fmt.Printf("%+v\n", p) } }
checkdb
/home/linuxreitt/Michinereitt/Tuning/Workshop_Scripts/hf-codegen/data/golang_public_repos/vulndb/cmd/checkdb/main.go
// Copyright 2022 The Go Authors. All rights reserved. // Use of this source code is governed by a BSD-style // license that can be found in the LICENSE file. // Command checkdb validates Go vulnerability databases. package main import ( "flag" "fmt" "log" db "golang.org/x/vulndb/internal/database" ) func main() { flag.Parse() path := flag.Arg(0) if path == "" { log.Fatal("path must be set\nusage: checkdb [path]") } if _, err := db.Load(path); err != nil { log.Fatal(err) } fmt.Printf("%s contains valid v1 database\n", path) }
cve
/home/linuxreitt/Michinereitt/Tuning/Workshop_Scripts/hf-codegen/data/golang_public_repos/vulndb/cmd/cve/main.go
// Copyright 2022 The Go Authors. All rights reserved. // Use of this source code is governed by a BSD-style // license that can be found in the LICENSE file. // Command cve provides utilities for managing CVE IDs and CVE Records via the // MITRE CVE Services API. package main import ( "bufio" "encoding/json" "errors" "flag" "fmt" "log" "os" "path/filepath" "regexp" "strings" "time" "github.com/google/go-cmp/cmp" "golang.org/x/vulndb/internal/cve5" "golang.org/x/vulndb/internal/database" "golang.org/x/vulndb/internal/idstr" "golang.org/x/vulndb/internal/report" ) var ( apiKey = flag.String("key", os.Getenv("CVE_API_KEY"), "key for accessing the CVE API (can also be set via env var CVE_API_KEY)") apiUser = flag.String("user", os.Getenv("CVE_API_USER"), "username for accessing the CVE API (can also be set via env var CVE_API_USER)") testApiKey = flag.String("test-key", os.Getenv("TEST_CVE_API_KEY"), "key for accessing the CVE API in test env (can also be set via env var TEST_CVE_API_KEY)") testApiUser = flag.String("test-user", os.Getenv("TEST_CVE_API_USER"), "username for accessing the CVE API in test env (can also be set via env var TEST_CVE_API_USER)") apiOrg = flag.String("org", "Go", "organization name for accessing the CVE API") // Note: the cve tool does not currently support the dev endpoint as there // is no clear use case for us. test = flag.Bool("test", false, "whether to access the CVE API in the test environment") // flags for the reserve command reserveN = flag.Int("n", 1, "reserve: the number of new CVE IDs to reserve") reserveSequential = flag.Bool("seq", true, "reserve: if true, reserve new CVE ID batches in sequence") // flags for the list command listState = flag.String("state", "", "list: filter by CVE state (RESERVED, PUBLISHED, or REJECTED)") // flags that apply to multiple commands year = flag.Int("year", 0, "reserve: the CVE ID year for newly reserved CVE IDs (default is current year)\nlist: filter by the year in the CVE ID") ) func main() { out := flag.CommandLine.Output() flag.Usage = func() { fmt.Fprintln(out, "Command cve provides utilities for managing CVE IDs and CVE Records via the MITRE CVE Services API") formatCmd := " %s: %s\n" fmt.Fprintf(out, "usage: cve [-key] [-user] [-org] [-test] <cmd> ...\n commands:\n") fmt.Fprintf(out, formatCmd, "[-n] [-seq] [-year] reserve", "reserves new CVE IDs") fmt.Fprintf(out, formatCmd, "quota", "outputs the CVE ID quota of the authenticated organization") fmt.Fprintf(out, formatCmd, "id {cve-id}", "outputs details on an assigned CVE ID (CVE-YYYY-NNNN)") fmt.Fprintf(out, formatCmd, "record {cve-id}", "outputs the record associated with a CVE ID (CVE-YYYY-NNNN)") fmt.Fprintf(out, formatCmd, "reject {cve-id}", "rejects the CVE ID (CVE-YYYY-NNNN) - for CVEs that have been reserved but are no longer needed") fmt.Fprintf(out, formatCmd, "publish [{filename} | {issue ID}]", "publishes or updates a CVE Record from a YAML/JSON file or issue ID") fmt.Fprintf(out, formatCmd, "org", "outputs details on the authenticated organization") fmt.Fprintf(out, formatCmd, "[-year] [-state] list", "lists all CVE IDs for an organization") flag.PrintDefaults() } flag.Parse() if flag.NArg() < 1 { logFatalUsageErr("cve", fmt.Errorf("must provide subcommand")) } c := cve5.NewClient(*cfgFromFlags()) cmd := flag.Arg(0) switch cmd { case "help": flag.Usage() case "reserve": year := *year if year == 0 { year = currentYear() } mode := cve5.SequentialRequest if !*reserveSequential { mode = cve5.NonsequentialRequest } if err := reserve(c, cve5.ReserveOptions{ NumIDs: *reserveN, Year: year, Mode: mode, }); err != nil { log.Fatalf("cve reserve: could not reserve any new CVEs due to error:\n %v", err) } case "quota": if err := quota(c); err != nil { log.Fatalf("cve quota: could not retrieve quota info due to error:\n %v", err) } case "id": id, err := validateID(flag.Arg(1)) if err != nil { logFatalUsageErr("cve id", err) } if err := lookupID(c, id); err != nil { log.Fatalf("cve id: could not retrieve CVE IDs due to error:\n %v", err) } case "record": id, err := validateID(flag.Arg(1)) if err != nil { logFatalUsageErr("cve record", err) } if err := lookupRecord(c, id); err != nil { log.Fatalf("cve record: could not retrieve CVE record due to error:\n %v", err) } case "reject": args := flag.Args()[1:] if len(args) == 0 { logFatalUsageErr("cve reject", errors.New("must provide CVE ID")) } for _, arg := range args { if !idstr.IsCVE(arg) { log.Printf("%s is not a CVE id; skipping", arg) continue } if err := c.Reject(arg, "reserved but not needed"); err != nil { log.Printf("cve reject: could not reject CVE due to error:\n %v", err) } else { log.Printf("success: rejected CVE %s", arg) } } case "publish": args := flag.Args()[1:] if len(args) == 0 { logFatalUsageErr("cve publish", errors.New("must provide filename or issue ID")) } for _, arg := range args { filename, err := argToFilename(arg) if err != nil { logFatalUsageErr("cve publish", err) } if !strings.HasSuffix(filename, ".json") && !strings.HasSuffix(filename, ".yaml") { logFatalUsageErr("cve publish", errors.New("filename must end in '.json' or '.yaml'")) } if err := publish(c, filename); err != nil { log.Printf("cve publish: could not publish CVE record due to error:\n %v", err) } } case "org": if err := lookupOrg(c); err != nil { log.Fatalf("cve org: could not retrieve org info due to error:\n %v", err) } case "list": // TODO(http://go.dev/issues/53258): allow time-based filters via flags. var filters *cve5.ListOptions if *listState != "" || *year != 0 { filters = new(cve5.ListOptions) state, err := validateState(*listState) if err != nil { logFatalUsageErr("cve list", err) } filters.State = state filters.Year = *year } if err := list(c, filters); err != nil { log.Fatalf("cve list: could not retrieve CVE IDs due to error:\n %v", err) } default: logFatalUsageErr("cve", fmt.Errorf("unsupported command: %q", cmd)) } } func logFatalUsageErr(context string, err error) { flag.Usage() log.Fatalf("%s: %s\n", context, err) } func currentYear() int { year, _, _ := time.Now().Date() return year } func cfgFromFlags() *cve5.Config { if *test { if *testApiKey == "" { logFatalUsageErr("cve", errors.New("the test CVE API key (flag -test-key or env var TEST_CVE_API_KEY) must be set in test env")) } if *testApiUser == "" { logFatalUsageErr("cve", errors.New("the test CVE API user (flag -test-user or env var TEST_CVE_API_USER) must be set in test env")) } return &cve5.Config{ Endpoint: cve5.TestEndpoint, Key: *testApiKey, Org: *apiOrg, User: *testApiUser, } } if *apiKey == "" { logFatalUsageErr("cve", errors.New("the CVE API key (flag -key or env var CVE_API_KEY) must be set in prod env")) } if *apiUser == "" { logFatalUsageErr("cve", errors.New("the CVE API user (flag -user or env var CVE_API_USER) must be set in prod env")) } return &cve5.Config{ Endpoint: cve5.ProdEndpoint, Key: *apiKey, Org: *apiOrg, User: *apiUser, } } func validateID(id string) (string, error) { if id == "" { return "", errors.New("CVE ID must be provided") } if !idstr.IsCVE(id) { return "", fmt.Errorf("%q is not a valid CVE ID", id) } return id, nil } var stateRegex = regexp.MustCompile(`^(RESERVED|PUBLISHED|REJECTED)$`) func validateState(state string) (cve5.State, error) { if state != "" && !stateRegex.MatchString(state) { return "", fmt.Errorf("state must match regex %v", stateRegex) } return cve5.State(state), nil } func reserve(c *cve5.Client, opts cve5.ReserveOptions) error { cves, err := c.ReserveIDs(opts) if err != nil { return err } cvesReserved := len(cves) if cvesReserved < opts.NumIDs { fmt.Printf("warning: only %d of %d requested CVE IDs were reserved\n", len(cves), opts.NumIDs) } fmt.Println(cves.ShortString()) return nil } func quota(c *cve5.Client) error { quota, err := c.RetrieveQuota() if err != nil { return err } fmt.Printf("quota info for org %q:\n quota: %d\n total reserved: %d\n available: %d\n", c.Org, quota.Quota, quota.Reserved, quota.Available) return nil } func lookupOrg(c *cve5.Client) error { org, err := c.RetrieveOrg() if err != nil { return err } fmt.Printf("org name: %q\nshort name: %q\nuuid: %s\n", org.Name, org.ShortName, org.UUID) return nil } func lookupID(c *cve5.Client, id string) error { assigned, err := c.RetrieveID(id) if err != nil { return err } // Display the retrieved CVE ID metadata. fmt.Println(assigned) return nil } // toJSON converts a struct into a JSON string. // If JSON marshal fails, it falls back to fmt.Sprint. func toJSON(v any) string { s, err := json.Marshal(v) if err != nil { return fmt.Sprint(v) } return string(s) } func lookupRecord(c *cve5.Client, id string) error { record, err := c.RetrieveRecord(id) if err != nil { return err } // Display the retrieved CVE record. fmt.Println(toJSON(record)) return nil } func argToFilename(arg string) (string, error) { if arg == "" { return "", errors.New("filename or issue ID must be provided") } if _, err := os.Stat(arg); err != nil { // If arg isn't a file, see if it might be an issue ID // with an existing CVE record. for _, padding := range []string{"", "0", "00", "000"} { m, _ := filepath.Glob("data/cve/v5/GO-*-" + padding + arg + ".json") if len(m) == 1 { return m[0], nil } } return "", fmt.Errorf("could not parse argument %q: not a valid filename or issue ID with existing record", arg) } return arg, nil } func publish(c *cve5.Client, filename string) (err error) { if !strings.HasSuffix(filename, ".json") { return errors.New("filename must end in '.json'") } cveID, toPublish, err := cve5.ReadForPublish(filename) if err != nil { return err } // Determine if the record should be created or updated. assigned, err := c.RetrieveID(cveID) if err != nil { return err } var ( publishFunc func(string, *cve5.Containers) (*cve5.CVERecord, error) action string ) switch state := assigned.State; state { case cve5.StatePublished: existing, err := c.RetrieveRecord(cveID) if err != nil { return err } fmt.Printf("%s is published at %s\n", cveID, c.WebURL(cveID)) if diff := cmp.Diff(existing.Containers, *toPublish); diff != "" { fmt.Printf("publish would update record with diff (-existing, +new):\n%s\n", diff) // The CVE program sometimes adds references to CVEs, so we need // to make sure we don't accidentally delete them. if updated := handleDeleted(existing, toPublish, filename); updated { // If we updated the CVE, check if any changes remain. _, toPublish, err = cve5.ReadForPublish(filename) if err != nil { return err } if diff := cmp.Diff(existing.Containers, *toPublish); diff == "" { fmt.Println("after adding missing refs, updating record would now have no effect") return nil } fmt.Printf("after adding missing refs, publish would now update record with diff (-existing, +new):\n%s\n", diff) } } else { fmt.Println("updating record would have no effect, skipping") return nil } publishFunc = c.UpdateRecord action = "update" case cve5.StateReserved: fmt.Printf("publish would create new record for %s\n", cveID) publishFunc = c.CreateRecord action = "create" default: return fmt.Errorf("publishing a %s record is not supported", state) } reader := bufio.NewReader(os.Stdin) fmt.Printf("%s record for %s? (y/N)\n", action, cveID) text, _ := reader.ReadString('\n') if text != "y\n" { fmt.Printf("exiting without %sing record\n", strings.TrimSuffix(action, "e")) return nil } _, err = publishFunc(cveID, toPublish) if err != nil { return err } fmt.Printf("successfully %sd record for %s at %s\n", action, cveID, c.WebURL(cveID)) return nil } func handleDeleted(existing *cve5.CVERecord, toPublish *cve5.Containers, filename string) bool { deleted := findDeleted(existing.Containers.CNAContainer.References, toPublish.CNAContainer.References) if len(deleted) == 0 { return false } goID := strings.TrimSuffix(filepath.Base(filename), filepath.Ext(filename)) yamlReportFile := fmt.Sprintf("data/reports/%s.yaml", goID) // To preserve an externally-added reference, add it to // cve_metadata.references. An example is GO-2022-0476. // This warning may be spurious if a reference is deleted from // a YAML report - in this case it should be ignored. fmt.Printf( `!! WARNING !! updating record would delete %[1]d reference(s) that may have been added by the CVE program; to preserve these references, add references to %[2]s and run "vulnreport fix %[2]s": cve_metadata: ... references: ... - %[3]s only update now if this warning is spurious (i.e., the records were deleted on purpose) `, len(deleted), yamlReportFile, strings.Join(deleted, "\n - ")) reader := bufio.NewReader(os.Stdin) fmt.Printf("try to auto-add missing refs? (y/N)\n") text, _ := reader.ReadString('\n') if text != "y\n" { return false } if err := addMissing(yamlReportFile, deleted); err != nil { fmt.Println("ERROR: could not add missing refs: ", err) return false } fmt.Printf("successfully added %d missing refs\n", len(deleted)) return true } func addMissing(yamlFile string, missing []string) error { r, err := report.Read(yamlFile) if err != nil { return err } r.CVEMetadata.References = append(r.CVEMetadata.References, missing...) if err := r.Write(yamlFile); err != nil { return err } cve, err := cve5.FromReport(r) if err != nil { return err } return database.WriteJSON(r.CVEFilename(), cve, true) } // findDeleted returns a list of URLs in oldRefs that are not in newRefs. func findDeleted(oldRefs []cve5.Reference, newRefs []cve5.Reference) (deleted []string) { m := make(map[string]bool) for _, r := range newRefs { m[r.URL] = true } for _, r := range oldRefs { if !m[r.URL] { deleted = append(deleted, r.URL) } } return deleted } func list(c *cve5.Client, lf *cve5.ListOptions) error { cves, err := c.ListOrgCVEs(lf) if err != nil { return err } var filterString string if lf != nil { filterString = fmt.Sprintf(" with filters %s", lf) } if n := len(cves); n > 0 { fmt.Printf("found %d CVE IDs for org %q%s:\n%v\n", n, c.Org, filterString, cves) } else { fmt.Printf("found no CVE IDs for org %q%s\n", c.Org, filterString) } return nil }
deploy
/home/linuxreitt/Michinereitt/Tuning/Workshop_Scripts/hf-codegen/data/golang_public_repos/vulndb/deploy/build.yaml
steps: - id: Lock name: golang:1.21.5 entrypoint: bash args: - -ec - | if [[ "$COMMIT_SHA" = '' ]]; then echo "no COMMIT_SHA, not locking" exit 0 fi go run golang.org/x/website/cmd/locktrigger@latest \ -project $PROJECT_ID -build $BUILD_ID -repo https://go.googlesource.com/vulndb - id: Unshallow name: gcr.io/cloud-builders/git entrypoint: bash args: - -c - | if ! git fetch --unshallow; then echo "git fetch --unshallow failed, no worries mate" fi - id: Test name: golang:1.21.5 entrypoint: bash args: - -ec - go test ./... - id: CopyExisting name: gcr.io/cloud-builders/gsutil entrypoint: bash args: - -ec - gsutil -q -m cp -r gs://go-vulndb /workspace - id: Generate name: golang:1.21.5 entrypoint: bash args: ["-ec", "go run ./cmd/gendb -out /workspace/db -zip /workspace/db/vulndb.zip"] - id: PreValidate name: golang:1.21.5 entrypoint: bash args: - -ec - go run ./cmd/checkdeploy -new /workspace/db -existing /workspace/go-vulndb - id: Deploy name: gcr.io/cloud-builders/gsutil entrypoint: bash args: ["./deploy/gcp-deploy.sh"] - id: CopyDeployed name: gcr.io/cloud-builders/gsutil entrypoint: bash args: - -ec - mkdir /workspace/deployed && gsutil -q -m cp -r gs://go-vulndb /workspace/deployed - id: PostValidate name: golang:1.20.12 entrypoint: bash args: ["-ec", "go run ./cmd/checkdb /workspace/deployed/go-vulndb"] env: - 'GOPROXY=https://proxy.golang.org'
deploy
/home/linuxreitt/Michinereitt/Tuning/Workshop_Scripts/hf-codegen/data/golang_public_repos/vulndb/deploy/README.md
# Deploy The Go vulndb project is hosted on GCP and uses a continuous integration service called “Kokoro” for running tests. This directory contains files used for kokoro test job configurations and for building and deploying the vulnerability database and worker. (Additional job definitions live in an internal repository). `kokoro.sh` acts as the entry point for scripts to be run via kokoro. `build.yaml` and `gcp-deploy.sh` are used to deploy the vulnerability database GCS bucket. `worker.yaml` is used to build the vulnerability database worker.
deploy
/home/linuxreitt/Michinereitt/Tuning/Workshop_Scripts/hf-codegen/data/golang_public_repos/vulndb/deploy/gcp-deploy.sh
#!/bin/bash # Copyright 2023 The Go Authors. All rights reserved. # Use of this source code is governed by a BSD-style # license that can be found in the LICENSE file. set -e # Deploy v1 database files. gsutil -m cp -r /workspace/db/* gs://go-vulndb # Deploy web files. # index.html is deployed as-is to avoid a name conflict with # the "index/" folder, but other HTML files are deployed without the # ".html" suffix for a cleaner URL. gsutil cp webconfig/index.html gs://go-vulndb for file in 404 copyright privacy; do gsutil -h "Content-Type:text/html" cp webconfig/$file.html gs://go-vulndb/$file done gsutil cp webconfig/favicon.ico gs://go-vulndb
deploy
/home/linuxreitt/Michinereitt/Tuning/Workshop_Scripts/hf-codegen/data/golang_public_repos/vulndb/deploy/worker.yaml
# Copyright 2022 The Go Authors. All rights reserved. # Use of this source code is governed by a BSD-style # license that can be found in the LICENSE file. # This is a Cloud Build config file for the vuln worker. # Invoke locally from the command line using devtools/deploy_worker.sh. # It can also be configured to run from a trigger, by supplying the _ENV # substitution. substitutions: _ENV: '' steps: - id: Lock name: golang:1.21.5 entrypoint: bash args: - -ec - | if [[ "$COMMIT_SHA" = '' ]]; then echo "no COMMIT_SHA, not locking" exit 0 fi go run golang.org/x/website/cmd/locktrigger@latest \ -project $PROJECT_ID -build $BUILD_ID -repo https://go.googlesource.com/vulndb - id: Test name: golang:1.21.5 entrypoint: bash args: - -ec - go test ./... - id: Prepare name: bash args: - -ec - | if [[ "$SHORT_SHA" = '' ]]; then echo >&2 "missing SHORT_SHA; use --substitutions on command line" exit 1 fi if [[ "$_ENV" = '' ]]; then echo >&2 "missing _ENV; use --substitutions on command line" exit 1 fi tag=$(date +%Y%m%dt%H%M%S)-$SHORT_SHA image=gcr.io/$PROJECT_ID/vuln-worker:$tag echo "image is $image" # Save image tag for later steps. echo $image > /workspace/image.txt - id: Build name: gcr.io/cloud-builders/docker entrypoint: bash args: - -ec - | image=$(cat /workspace/image.txt) docker build -t $image --build-arg DOCKER_IMAGE=$image -f cmd/worker/Dockerfile . docker push $image - id: Deploy name: gcr.io/cloud-builders/gcloud entrypoint: bash args: - -ec - | image=$(cat /workspace/image.txt) service=${_ENV}-vuln-worker args="--project $PROJECT_ID --region us-central1" gcloud run deploy $args $service --image $image # If there was a rollback, `gcloud run deploy` will create a revision but # not point traffic to it. The following command ensures that the new revision # will get traffic. latestTraffic=$(gcloud run services $args describe $service \ --format='value(status.traffic.latestRevision)') if [[ $latestTraffic != True ]]; then gcloud run services $args update-traffic $service --to-latest fi
deploy
/home/linuxreitt/Michinereitt/Tuning/Workshop_Scripts/hf-codegen/data/golang_public_repos/vulndb/deploy/kokoro.sh
#!/usr/bin/env bash # Copyright 2022 The Go Authors. All rights reserved. # Use of this source code is governed by a BSD-style # license that can be found in the LICENSE file. set -ex # Make a full clone of the repo so that gendb can find missing PublishDates in # reports by reading the commit history. # # Kokoro creates a shallow clone. Attempts to # deepen the clone with `git fetch --unshallow` failed, # apparently because Kokoro uses the `rpc:` scheme to # clone the repo. git clone https://go.googlesource.com/vulndb cd vulndb # Copy the existing vuln DB into a local directory so we can diff it. mkdir old-db gsutil -q -m cp -r gs://go-vulndb/* old-db # Generate a copy of the DB using the current state of the repo # and diff it with the old one. Do all this in a docker container # so we can select the version of Go that we want. docker run --rm \ -v $PWD:/vulndb \ -w /vulndb \ golang:1.21.5 \ /bin/bash -c 'go run ./cmd/gendb -repo /vulndb -out new-db && go run ./cmd/dbdiff old-db new-db'
terraform
/home/linuxreitt/Michinereitt/Tuning/Workshop_Scripts/hf-codegen/data/golang_public_repos/vulndb/terraform/main.tf
# Copyright 2021 The Go Authors. All rights reserved. # Use of this source code is governed by a BSD-style # license that can be found in the LICENSE file. # Terraform configuration for GCP components from this repo. terraform { required_version = ">= 1.0.9, < 2.0.0" # Store terraform state in a GCS bucket, so all team members share it. backend "gcs" { bucket = "go-vuln" } required_providers { google = { version = "~> 3.90.1" source = "hashicorp/google" } } } locals { region = "us-central1" } provider "google" { region = local.region } # Inputs for values that should not appear in the repo. # Terraform will prompt for these when you run it, or # you can put them in a local file that is only readable # by you, and pass them to terraform. # See https://www.terraform.io/docs/language/values/variables.html#variable-definitions-tfvars-files. variable "prod_project" { description = "GCP project where resources live" type = string } variable "prod_issue_repo" { description = "repo where issues are filed" type = string } variable "prod_client_id" { description = "OAuth2 client ID" type = string } # Deployment environments module "prod" { source = "./environment" env = "prod" project = var.prod_project region = local.region use_profiler = true min_frontend_instances = 1 oauth_client_id = var.prod_client_id issue_repo = var.prod_issue_repo } resource "google_cloudbuild_trigger" "vulndb-redeploy" { project = var.prod_project description = "Rebuild vulndb database and push to GCS bucket" filename = "deploy/build.yaml" name = "vulndb-redeploy" trigger_template { branch_name = "^master$" project_id = "go-vuln" repo_name = "vulndb" } }
terraform
/home/linuxreitt/Michinereitt/Tuning/Workshop_Scripts/hf-codegen/data/golang_public_repos/vulndb/terraform/README.md
# Terraform configuration for vuln worker ## External variables Some inputs to this config are not checked into the repo. You can provide them on the `terraform` command line, or create a `terraform.tfvars` file in this directory with the information, like this one: ``` prod_project = "prod-project" prod_issue_repo = "org/repo" prod_client_id = "xyzzy@apps.googleusercontent.com" ``` `terraform.tfvars` is in the repo's `.gitignore` file, so it won't show up in `git status`. **Do not** check it into the repo. ## Cloud Run image We use terraform to set up the Cloud Run service, but we deploy in other ways. Our deploy process changes only the Docker image for the service. If we hardcoded a Docker image into the config, our config would often be out of date (since we apply it rarely compared to deploying), and we would risk overwriting a newer image with the old one in the config. For that reason, the Docker image in the config is obtained from the service itself, by using a `data` block: ``` resource "google_cloud_run_service" "worker" { ... template { spec { containers { image = data.google_cloud_run_service.worker.template[0].spec[0].containers[0].image ... } data "google_cloud_run_service" "worker" { name = "${var.env}-vuln-worker" project = var.project location = var.region } ``` This works fine once the service exists, but before it does we have a circularity: to create the service we need to get the image from the service! So to create the service: 1. Build and push a Docker image. 2. Replace the `data.google_cloud_run_service.worker` expressions (there are two) with the actual image label. 3. Run `terraform apply`. 4. Undo the replacement.
environment
/home/linuxreitt/Michinereitt/Tuning/Workshop_Scripts/hf-codegen/data/golang_public_repos/vulndb/terraform/environment/worker.tf
# Copyright 2021 The Go Authors. All rights reserved. # Use of this source code is governed by a BSD-style # license that can be found in the LICENSE file. # Config for vuln worker. ################################################################ # Inputs. variable "env" { description = "environment name" type = string } variable "project" { description = "GCP project" type = string } variable "region" { description = "GCP region" type = string } variable "use_profiler" { description = "use Stackdriver Profiler" type = bool } variable "min_frontend_instances" { description = "minimum number of frontend instances" type = number } variable "oauth_client_id" { description = "OAuth 2 client ID (visit APIs & Services > Credentials)" type = string } variable "issue_repo" { description = "name of GitHub repo to post issues on" type = string } ################################################################ # Cloud Run service. resource "google_cloud_run_service" "worker" { provider = google-beta lifecycle { ignore_changes = [ # When we deploy, we may use different clients at different versions. # Ignore those changes. template[0].metadata[0].annotations["run.googleapis.com/client-name"], template[0].metadata[0].annotations["run.googleapis.com/client-version"] ] } name = "${var.env}-vuln-worker" project = var.project location = var.region template { spec { containers { # Get the image from GCP (see the "data" block below). # Exception: when first creating the service, replace this with a hardcoded # image tag. image = data.google_cloud_run_service.worker.template[0].spec[0].containers[0].image env { name = "GOOGLE_CLOUD_PROJECT" value = var.project } env { name = "VULN_WORKER_NAMESPACE" value = var.env } env { name = "VULN_WORKER_REPORT_ERRORS" value = true } env { name = "VULN_WORKER_ISSUE_REPO" value = var.issue_repo } env { name = "VULN_GITHUB_ACCESS_TOKEN" value_from { secret_key_ref { name = google_secret_manager_secret.vuln_github_access_token.secret_id key = "latest" } } } env { name = "VULN_WORKER_USE_PROFILER" value = var.use_profiler } resources { limits = { "cpu" = "4000m" "memory" = "16Gi" } } } service_account_name = data.google_compute_default_service_account.default.email # 60 minutes is the maximum Cloud Run request time. timeout_seconds = 60 * 60 } metadata { annotations = { "autoscaling.knative.dev/minScale" = var.min_frontend_instances "autoscaling.knative.dev/maxScale" = "1" #"client.knative.dev/user-image" = data.google_cloud_run_service.worker.template[0].spec[0].containers[0].image } } } autogenerate_revision_name = true traffic { latest_revision = true percent = 100 } } # We deploy new images with gcloud, not terraform, so we need to # make sure that "terraform apply" doesn't change the deployed image # to whatever is in this file. (The image attribute is required in # a Cloud Run config; it can't be empty.) # # We use this data source is used to determine the deployed image. data "google_cloud_run_service" "worker" { name = "${var.env}-vuln-worker" project = var.project location = var.region } ################################################################ # Other components. locals { tz = "America/New_York" } resource "google_secret_manager_secret" "vuln_github_access_token" { secret_id = "vuln-${var.env}-github-access-token" project = var.project replication { automatic = true } } data "google_compute_default_service_account" "default" { project = var.project } resource "google_cloud_scheduler_job" "vuln_issue_triage" { name = "vuln-${var.env}-issue-triage" description = "Updates the DB and files issues." schedule = "0 * * * *" # every hour time_zone = local.tz project = var.project attempt_deadline = format("%ds", 30 * 60) http_target { http_method = "POST" uri = "${google_cloud_run_service.worker.status[0].url}/update-and-issues" oidc_token { service_account_email = data.google_compute_default_service_account.default.email audience = var.oauth_client_id } } retry_config { max_backoff_duration = "3600s" max_doublings = 5 max_retry_duration = "0s" min_backoff_duration = "5s" retry_count = 0 } }
mobile
/home/linuxreitt/Michinereitt/Tuning/Workshop_Scripts/hf-codegen/data/golang_public_repos/mobile/CONTRIBUTING.md
# Contributing to Go Go is an open source project. It is the work of hundreds of contributors. We appreciate your help! ## Filing issues When [filing an issue](https://golang.org/issue/new), make sure to answer these five questions: 1. What version of Go are you using (`go version`)? 2. What operating system and processor architecture are you using? 3. What did you do? 4. What did you expect to see? 5. What did you see instead? General questions should go to the [golang-nuts mailing list](https://groups.google.com/group/golang-nuts) instead of the issue tracker. The gophers there will answer or ask you to file an issue if you've tripped over a bug. ## Contributing code Please read the [Contribution Guidelines](https://golang.org/doc/contribute.html) before sending patches. Unless otherwise noted, the Go source files are distributed under the BSD-style license found in the LICENSE file.
mobile
/home/linuxreitt/Michinereitt/Tuning/Workshop_Scripts/hf-codegen/data/golang_public_repos/mobile/PATENTS
Additional IP Rights Grant (Patents) "This implementation" means the copyrightable works distributed by Google as part of the Go project. Google hereby grants to You a perpetual, worldwide, non-exclusive, no-charge, royalty-free, irrevocable (except as stated in this section) patent license to make, have made, use, offer to sell, sell, import, transfer and otherwise run, modify and propagate the contents of this implementation of Go, where such license applies only to those patent claims, both currently owned or controlled by Google and acquired in the future, licensable by Google that are necessarily infringed by this implementation of Go. This grant does not include claims that would be infringed only as a consequence of further modification of this implementation. If you or your agent or exclusive licensee institute or order or agree to the institution of patent litigation against any entity (including a cross-claim or counterclaim in a lawsuit) alleging that this implementation of Go or any code incorporated within this implementation of Go constitutes direct or contributory patent infringement, or inducement of patent infringement, then any patent rights granted to you under this License for this implementation of Go shall terminate as of the date such litigation is filed.
mobile
/home/linuxreitt/Michinereitt/Tuning/Workshop_Scripts/hf-codegen/data/golang_public_repos/mobile/go.mod
module golang.org/x/mobile go 1.18 require ( golang.org/x/exp/shiny v0.0.0-20230817173708-d852ddb80c63 golang.org/x/image v0.18.0 golang.org/x/mod v0.19.0 golang.org/x/sync v0.7.0 golang.org/x/tools v0.23.0 ) require golang.org/x/sys v0.22.0 // indirect
mobile
/home/linuxreitt/Michinereitt/Tuning/Workshop_Scripts/hf-codegen/data/golang_public_repos/mobile/README.md
# Go support for Mobile devices [![Go Reference](https://pkg.go.dev/badge/golang.org/x/mobile.svg)](https://pkg.go.dev/golang.org/x/mobile) The Go mobile repository holds packages and build tools for using Go on mobile platforms. Package documentation as a starting point: - [Building all-Go apps](https://golang.org/x/mobile/app) - [Building libraries for SDK apps](https://golang.org/x/mobile/cmd/gobind) ![Caution image](doc/caution.png) The Go Mobile project is experimental. Use this at your own risk. While we are working hard to improve it, neither Google nor the Go team can provide end-user support. This is early work and installing the build system requires Go 1.5. Follow the instructions on [golang.org/wiki/Mobile](https://golang.org/wiki/Mobile) to install the gomobile command, build the [basic](https://golang.org/x/mobile/example/basic) and the [bind](https://golang.org/x/mobile/example/bind) example apps. -- Contributions to Go are appreciated. See https://golang.org/doc/contribute.html. * Bugs can be filed at the [Go issue tracker](https://golang.org/issue/new?title=x/mobile:+). * Feature requests should preliminary be discussed on [golang-nuts](https://groups.google.com/forum/#!forum/golang-nuts) mailing list.
mobile
/home/linuxreitt/Michinereitt/Tuning/Workshop_Scripts/hf-codegen/data/golang_public_repos/mobile/go.sum
golang.org/x/exp/shiny v0.0.0-20230817173708-d852ddb80c63 h1:3AGKexOYqL+ztdWdkB1bDwXgPBuTS/S8A4WzuTvJ8Cg= golang.org/x/exp/shiny v0.0.0-20230817173708-d852ddb80c63/go.mod h1:UH99kUObWAZkDnWqppdQe5ZhPYESUw8I0zVV1uWBR+0= golang.org/x/image v0.18.0 h1:jGzIakQa/ZXI1I0Fxvaa9W7yP25TqT6cHIHn+6CqvSQ= golang.org/x/image v0.18.0/go.mod h1:4yyo5vMFQjVjUcVk4jEQcU9MGy/rulF5WvUILseCM2E= golang.org/x/mod v0.19.0 h1:fEdghXQSo20giMthA7cd28ZC+jts4amQ3YMXiP5oMQ8= golang.org/x/mod v0.19.0/go.mod h1:hTbmBsO62+eylJbnUtE2MGJUyE7QWk4xUqPFrRgJ+7c= golang.org/x/sync v0.7.0 h1:YsImfSBoP9QPYL0xyKJPq0gcaJdG3rInoqxTWbfQu9M= golang.org/x/sync v0.7.0/go.mod h1:Czt+wKu1gCyEFDUtn0jG5QVvpJ6rzVqr5aXyt9drQfk= golang.org/x/sys v0.22.0 h1:RI27ohtqKCnwULzJLqkv897zojh5/DwS/ENaMzUOaWI= golang.org/x/sys v0.22.0/go.mod h1:/VUhepiaJMQUp4+oa/7Zr1D23ma6VTLIYjOOTFZPUcA= golang.org/x/tools v0.23.0 h1:SGsXPZ+2l4JsgaCKkx+FQ9YZ5XEtA1GZYuoDjenLjvg= golang.org/x/tools v0.23.0/go.mod h1:pnu6ufv6vQkll6szChhK3C3L/ruaIv5eBeztNG8wtsI=
mobile
/home/linuxreitt/Michinereitt/Tuning/Workshop_Scripts/hf-codegen/data/golang_public_repos/mobile/LICENSE
Copyright 2009 The Go Authors. Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions are met: * Redistributions of source code must retain the above copyright notice, this list of conditions and the following disclaimer. * Redistributions in binary form must reproduce the above copyright notice, this list of conditions and the following disclaimer in the documentation and/or other materials provided with the distribution. * Neither the name of Google LLC nor the names of its contributors may be used to endorse or promote products derived from this software without specific prior written permission. THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
mobile
/home/linuxreitt/Michinereitt/Tuning/Workshop_Scripts/hf-codegen/data/golang_public_repos/mobile/codereview.cfg
issuerepo: golang/go
asset
/home/linuxreitt/Michinereitt/Tuning/Workshop_Scripts/hf-codegen/data/golang_public_repos/mobile/asset/asset_darwin_armx.go
// Copyright 2015 The Go Authors. All rights reserved. // Use of this source code is governed by a BSD-style // license that can be found in the LICENSE file. //go:build darwin && (arm || arm64) package asset import ( "os" "path/filepath" ) func openAsset(name string) (File, error) { if !filepath.IsAbs(name) { name = filepath.Join("assets", name) } f, err := os.Open(name) if err != nil { return nil, err } return f, nil }
asset
/home/linuxreitt/Michinereitt/Tuning/Workshop_Scripts/hf-codegen/data/golang_public_repos/mobile/asset/asset.go
// Copyright 2015 The Go Authors. All rights reserved. // Use of this source code is governed by a BSD-style // license that can be found in the LICENSE file. //go:build darwin || linux || windows package asset import "io" // Open opens a named asset. // // Errors are of type *os.PathError. // // This must not be called from init when used in android apps. func Open(name string) (File, error) { return openAsset(name) } // File is an open asset. type File interface { io.ReadSeeker io.Closer }
asset
/home/linuxreitt/Michinereitt/Tuning/Workshop_Scripts/hf-codegen/data/golang_public_repos/mobile/asset/doc.go
// Copyright 2015 The Go Authors. All rights reserved. // Use of this source code is governed by a BSD-style // license that can be found in the LICENSE file. // Package asset provides access to application-bundled assets. // // On Android, assets are accessed via android.content.res.AssetManager. // These files are stored in the assets/ directory of the app. Any raw asset // can be accessed by its direct relative name. For example assets/img.png // can be opened with Open("img.png"). // // On iOS an asset is a resource stored in the application bundle. // Resources can be loaded using the same relative paths. // // For consistency when debugging on a desktop, assets are read from a // directory named assets under the current working directory. package asset // import "golang.org/x/mobile/asset"
asset
/home/linuxreitt/Michinereitt/Tuning/Workshop_Scripts/hf-codegen/data/golang_public_repos/mobile/asset/asset_android.go
// Copyright 2015 The Go Authors. All rights reserved. // Use of this source code is governed by a BSD-style // license that can be found in the LICENSE file. package asset /* #cgo LDFLAGS: -landroid #include <android/asset_manager.h> #include <android/asset_manager_jni.h> #include <jni.h> #include <stdlib.h> static AAssetManager* asset_manager_init(uintptr_t java_vm, uintptr_t jni_env, jobject ctx) { JavaVM* vm = (JavaVM*)java_vm; JNIEnv* env = (JNIEnv*)jni_env; // Equivalent to: // assetManager = ctx.getResources().getAssets(); jclass ctx_clazz = (*env)->FindClass(env, "android/content/Context"); jmethodID getres_id = (*env)->GetMethodID(env, ctx_clazz, "getResources", "()Landroid/content/res/Resources;"); jobject res = (*env)->CallObjectMethod(env, ctx, getres_id); jclass res_clazz = (*env)->FindClass(env, "android/content/res/Resources"); jmethodID getam_id = (*env)->GetMethodID(env, res_clazz, "getAssets", "()Landroid/content/res/AssetManager;"); jobject am = (*env)->CallObjectMethod(env, res, getam_id); // Pin the AssetManager and load an AAssetManager from it. am = (*env)->NewGlobalRef(env, am); return AAssetManager_fromJava(env, am); } */ import "C" import ( "fmt" "io" "log" "os" "sync" "unsafe" "golang.org/x/mobile/internal/mobileinit" ) var assetOnce sync.Once // asset_manager is the asset manager of the app. var assetManager *C.AAssetManager func assetInit() { err := mobileinit.RunOnJVM(func(vm, env, ctx uintptr) error { assetManager = C.asset_manager_init(C.uintptr_t(vm), C.uintptr_t(env), C.jobject(ctx)) return nil }) if err != nil { log.Fatalf("asset: %v", err) } } func openAsset(name string) (File, error) { assetOnce.Do(assetInit) cname := C.CString(name) defer C.free(unsafe.Pointer(cname)) a := &asset{ ptr: C.AAssetManager_open(assetManager, cname, C.AASSET_MODE_UNKNOWN), name: name, } if a.ptr == nil { return nil, a.errorf("open", "bad asset") } return a, nil } type asset struct { ptr *C.AAsset name string } func (a *asset) errorf(op string, format string, v ...interface{}) error { return &os.PathError{ Op: op, Path: a.name, Err: fmt.Errorf(format, v...), } } func (a *asset) Read(p []byte) (n int, err error) { n = int(C.AAsset_read(a.ptr, unsafe.Pointer(&p[0]), C.size_t(len(p)))) if n == 0 && len(p) > 0 { return 0, io.EOF } if n < 0 { return 0, a.errorf("read", "negative bytes: %d", n) } return n, nil } func (a *asset) Seek(offset int64, whence int) (int64, error) { // TODO(crawshaw): use AAsset_seek64 if it is available. off := C.AAsset_seek(a.ptr, C.off_t(offset), C.int(whence)) if off == -1 { return 0, a.errorf("seek", "bad result for offset=%d, whence=%d", offset, whence) } return int64(off), nil } func (a *asset) Close() error { C.AAsset_close(a.ptr) return nil }
asset
/home/linuxreitt/Michinereitt/Tuning/Workshop_Scripts/hf-codegen/data/golang_public_repos/mobile/asset/asset_desktop.go
// Copyright 2014 The Go Authors. All rights reserved. // Use of this source code is governed by a BSD-style // license that can be found in the LICENSE file. //go:build (linux && !android) || (darwin && !arm && !arm64) || windows package asset import ( "os" "path/filepath" ) func openAsset(name string) (File, error) { if !filepath.IsAbs(name) { name = filepath.Join("assets", name) } f, err := os.Open(name) if err != nil { return nil, err } return f, nil }
exp
/home/linuxreitt/Michinereitt/Tuning/Workshop_Scripts/hf-codegen/data/golang_public_repos/mobile/exp/README
golang.org/x/mobile/exp contains experimental packages for mobile app development.
al
/home/linuxreitt/Michinereitt/Tuning/Workshop_Scripts/hf-codegen/data/golang_public_repos/mobile/exp/audio/al/al_notandroid.go
// Copyright 2015 The Go Authors. All rights reserved. // Use of this source code is governed by a BSD-style // license that can be found in the LICENSE file. //go:build darwin || (linux && !android) || windows package al /* #cgo darwin CFLAGS: -DGOOS_darwin #cgo linux CFLAGS: -DGOOS_linux #cgo windows CFLAGS: -DGOOS_windows #cgo darwin LDFLAGS: -framework OpenAL #cgo linux LDFLAGS: -lopenal #cgo windows LDFLAGS: -lOpenAL32 #ifdef GOOS_darwin #include <stdlib.h> #include <OpenAL/al.h> #endif #ifdef GOOS_linux #include <stdlib.h> #include <AL/al.h> // install on Ubuntu with: sudo apt-get install libopenal-dev #endif #ifdef GOOS_windows #include <windows.h> #include <stdlib.h> #include <AL/al.h> #endif */ import "C" import "unsafe" func alEnable(capability int32) { C.alEnable(C.ALenum(capability)) } func alDisable(capability int32) { C.alDisable(C.ALenum(capability)) } func alIsEnabled(capability int32) bool { return C.alIsEnabled(C.ALenum(capability)) == C.AL_TRUE } func alGetInteger(k int) int32 { return int32(C.alGetInteger(C.ALenum(k))) } func alGetIntegerv(k int, v []int32) { C.alGetIntegerv(C.ALenum(k), (*C.ALint)(unsafe.Pointer(&v[0]))) } func alGetFloat(k int) float32 { return float32(C.alGetFloat(C.ALenum(k))) } func alGetFloatv(k int, v []float32) { C.alGetFloatv(C.ALenum(k), (*C.ALfloat)(unsafe.Pointer(&v[0]))) } func alGetBoolean(k int) bool { return C.alGetBoolean(C.ALenum(k)) == C.AL_TRUE } func alGetBooleanv(k int, v []bool) { val := make([]C.ALboolean, len(v)) for i, bv := range v { if bv { val[i] = C.AL_TRUE } else { val[i] = C.AL_FALSE } } C.alGetBooleanv(C.ALenum(k), &val[0]) } func alGetString(v int) string { value := C.alGetString(C.ALenum(v)) return C.GoString((*C.char)(value)) } func alDistanceModel(v int32) { C.alDistanceModel(C.ALenum(v)) } func alDopplerFactor(v float32) { C.alDopplerFactor(C.ALfloat(v)) } func alDopplerVelocity(v float32) { C.alDopplerVelocity(C.ALfloat(v)) } func alSpeedOfSound(v float32) { C.alSpeedOfSound(C.ALfloat(v)) } func alGetError() int32 { return int32(C.alGetError()) } func alGenSources(n int) []Source { s := make([]Source, n) C.alGenSources(C.ALsizei(n), (*C.ALuint)(unsafe.Pointer(&s[0]))) return s } func alSourcePlayv(s []Source) { C.alSourcePlayv(C.ALsizei(len(s)), (*C.ALuint)(unsafe.Pointer(&s[0]))) } func alSourcePausev(s []Source) { C.alSourcePausev(C.ALsizei(len(s)), (*C.ALuint)(unsafe.Pointer(&s[0]))) } func alSourceStopv(s []Source) { C.alSourceStopv(C.ALsizei(len(s)), (*C.ALuint)(unsafe.Pointer(&s[0]))) } func alSourceRewindv(s []Source) { C.alSourceRewindv(C.ALsizei(len(s)), (*C.ALuint)(unsafe.Pointer(&s[0]))) } func alDeleteSources(s []Source) { C.alDeleteSources(C.ALsizei(len(s)), (*C.ALuint)(unsafe.Pointer(&s[0]))) } func alGetSourcei(s Source, k int) int32 { var v C.ALint C.alGetSourcei(C.ALuint(s), C.ALenum(k), &v) return int32(v) } func alGetSourcef(s Source, k int) float32 { var v C.ALfloat C.alGetSourcef(C.ALuint(s), C.ALenum(k), &v) return float32(v) } func alGetSourcefv(s Source, k int, v []float32) { C.alGetSourcefv(C.ALuint(s), C.ALenum(k), (*C.ALfloat)(unsafe.Pointer(&v[0]))) } func alSourcei(s Source, k int, v int32) { C.alSourcei(C.ALuint(s), C.ALenum(k), C.ALint(v)) } func alSourcef(s Source, k int, v float32) { C.alSourcef(C.ALuint(s), C.ALenum(k), C.ALfloat(v)) } func alSourcefv(s Source, k int, v []float32) { C.alSourcefv(C.ALuint(s), C.ALenum(k), (*C.ALfloat)(unsafe.Pointer(&v[0]))) } func alSourceQueueBuffers(s Source, b []Buffer) { C.alSourceQueueBuffers(C.ALuint(s), C.ALsizei(len(b)), (*C.ALuint)(unsafe.Pointer(&b[0]))) } func alSourceUnqueueBuffers(s Source, b []Buffer) { C.alSourceUnqueueBuffers(C.ALuint(s), C.ALsizei(len(b)), (*C.ALuint)(unsafe.Pointer(&b[0]))) } func alGetListenerf(k int) float32 { var v C.ALfloat C.alGetListenerf(C.ALenum(k), &v) return float32(v) } func alGetListenerfv(k int, v []float32) { C.alGetListenerfv(C.ALenum(k), (*C.ALfloat)(unsafe.Pointer(&v[0]))) } func alListenerf(k int, v float32) { C.alListenerf(C.ALenum(k), C.ALfloat(v)) } func alListenerfv(k int, v []float32) { C.alListenerfv(C.ALenum(k), (*C.ALfloat)(unsafe.Pointer(&v[0]))) } func alGenBuffers(n int) []Buffer { s := make([]Buffer, n) C.alGenBuffers(C.ALsizei(n), (*C.ALuint)(unsafe.Pointer(&s[0]))) return s } func alDeleteBuffers(b []Buffer) { C.alDeleteBuffers(C.ALsizei(len(b)), (*C.ALuint)(unsafe.Pointer(&b[0]))) } func alGetBufferi(b Buffer, k int) int32 { var v C.ALint C.alGetBufferi(C.ALuint(b), C.ALenum(k), &v) return int32(v) } func alBufferData(b Buffer, format uint32, data []byte, freq int32) { C.alBufferData(C.ALuint(b), C.ALenum(format), unsafe.Pointer(&data[0]), C.ALsizei(len(data)), C.ALsizei(freq)) } func alIsBuffer(b Buffer) bool { return C.alIsBuffer(C.ALuint(b)) == C.AL_TRUE }
al
/home/linuxreitt/Michinereitt/Tuning/Workshop_Scripts/hf-codegen/data/golang_public_repos/mobile/exp/audio/al/al.go
// Copyright 2015 The Go Authors. All rights reserved. // Use of this source code is governed by a BSD-style // license that can be found in the LICENSE file. //go:build darwin || linux || windows // Package al provides OpenAL Soft bindings for Go. // // Calls are not safe for concurrent use. // // More information about OpenAL Soft is available at // http://www.openal.org/documentation/openal-1.1-specification.pdf. // // In order to use this package on Linux desktop distros, // you will need OpenAL library as an external dependency. // On Ubuntu 14.04 'Trusty', you may have to install this library // by running the command below. // // sudo apt-get install libopenal-dev // // When compiled for Android, this package uses OpenAL Soft. Please add its // license file to the open source notices of your application. // OpenAL Soft's license file could be found at // http://repo.or.cz/w/openal-soft.git/blob/HEAD:/COPYING. package al // import "golang.org/x/mobile/exp/audio/al" // Capability represents OpenAL extension capabilities. type Capability int32 // Enable enables a capability. func Enable(c Capability) { alEnable(int32(c)) } // Disable disables a capability. func Disable(c Capability) { alDisable(int32(c)) } // Enabled reports whether the specified capability is enabled. func Enabled(c Capability) bool { return alIsEnabled(int32(c)) } // Vector represents an vector in a Cartesian coordinate system. type Vector [3]float32 // Orientation represents the angular position of an object in a // right-handed Cartesian coordinate system. // A cross product between the forward and up vector returns a vector // that points to the right. type Orientation struct { // Forward vector is the direction that the object is looking at. Forward Vector // Up vector represents the rotation of the object. Up Vector } func orientationFromSlice(v []float32) Orientation { return Orientation{ Forward: Vector{v[0], v[1], v[2]}, Up: Vector{v[3], v[4], v[5]}, } } func (v Orientation) slice() []float32 { return []float32{v.Forward[0], v.Forward[1], v.Forward[2], v.Up[0], v.Up[1], v.Up[2]} } // Geti returns the int32 value of the given parameter. func Geti(param int) int32 { return alGetInteger(param) } // Getiv returns the int32 vector value of the given parameter. func Getiv(param int, v []int32) { alGetIntegerv(param, v) } // Getf returns the float32 value of the given parameter. func Getf(param int) float32 { return alGetFloat(param) } // Getfv returns the float32 vector value of the given parameter. func Getfv(param int, v []float32) { alGetFloatv(param, v[:]) } // Getb returns the bool value of the given parameter. func Getb(param int) bool { return alGetBoolean(param) } // Getbv returns the bool vector value of the given parameter. func Getbv(param int, v []bool) { alGetBooleanv(param, v) } // GetString returns the string value of the given parameter. func GetString(param int) string { return alGetString(param) } // DistanceModel returns the distance model. func DistanceModel() int32 { return Geti(paramDistanceModel) } // SetDistanceModel sets the distance model. func SetDistanceModel(v int32) { alDistanceModel(v) } // DopplerFactor returns the doppler factor. func DopplerFactor() float32 { return Getf(paramDopplerFactor) } // SetDopplerFactor sets the doppler factor. func SetDopplerFactor(v float32) { alDopplerFactor(v) } // DopplerVelocity returns the doppler velocity. func DopplerVelocity() float32 { return Getf(paramDopplerVelocity) } // SetDopplerVelocity sets the doppler velocity. func SetDopplerVelocity(v float32) { alDopplerVelocity(v) } // SpeedOfSound is the speed of sound in meters per second (m/s). func SpeedOfSound() float32 { return Getf(paramSpeedOfSound) } // SetSpeedOfSound sets the speed of sound, its unit should be meters per second (m/s). func SetSpeedOfSound(v float32) { alSpeedOfSound(v) } // Vendor returns the vendor. func Vendor() string { return GetString(paramVendor) } // Version returns the version string. func Version() string { return GetString(paramVersion) } // Renderer returns the renderer information. func Renderer() string { return GetString(paramRenderer) } // Extensions returns the enabled extensions. func Extensions() string { return GetString(paramExtensions) } // Error returns the most recently generated error. func Error() int32 { return alGetError() } // Source represents an individual sound source in 3D-space. // They take PCM data, apply modifications and then submit them to // be mixed according to their spatial location. type Source uint32 // GenSources generates n new sources. These sources should be deleted // once they are not in use. func GenSources(n int) []Source { return alGenSources(n) } // PlaySources plays the sources. func PlaySources(source ...Source) { alSourcePlayv(source) } // PauseSources pauses the sources. func PauseSources(source ...Source) { alSourcePausev(source) } // StopSources stops the sources. func StopSources(source ...Source) { alSourceStopv(source) } // RewindSources rewinds the sources to their beginning positions. func RewindSources(source ...Source) { alSourceRewindv(source) } // DeleteSources deletes the sources. func DeleteSources(source ...Source) { alDeleteSources(source) } // Gain returns the source gain. func (s Source) Gain() float32 { return s.Getf(paramGain) } // SetGain sets the source gain. func (s Source) SetGain(v float32) { s.Setf(paramGain, v) } // MinGain returns the source's minimum gain setting. func (s Source) MinGain() float32 { return s.Getf(paramMinGain) } // SetMinGain sets the source's minimum gain setting. func (s Source) SetMinGain(v float32) { s.Setf(paramMinGain, v) } // MaxGain returns the source's maximum gain setting. func (s Source) MaxGain() float32 { return s.Getf(paramMaxGain) } // SetMaxGain sets the source's maximum gain setting. func (s Source) SetMaxGain(v float32) { s.Setf(paramMaxGain, v) } // Position returns the position of the source. func (s Source) Position() Vector { v := Vector{} s.Getfv(paramPosition, v[:]) return v } // SetPosition sets the position of the source. func (s Source) SetPosition(v Vector) { s.Setfv(paramPosition, v[:]) } // Velocity returns the source's velocity. func (s Source) Velocity() Vector { v := Vector{} s.Getfv(paramVelocity, v[:]) return v } // SetVelocity sets the source's velocity. func (s Source) SetVelocity(v Vector) { s.Setfv(paramVelocity, v[:]) } // Orientation returns the orientation of the source. func (s Source) Orientation() Orientation { v := make([]float32, 6) s.Getfv(paramOrientation, v) return orientationFromSlice(v) } // SetOrientation sets the orientation of the source. func (s Source) SetOrientation(o Orientation) { s.Setfv(paramOrientation, o.slice()) } // State returns the playing state of the source. func (s Source) State() int32 { return s.Geti(paramSourceState) } // BuffersQueued returns the number of the queued buffers. func (s Source) BuffersQueued() int32 { return s.Geti(paramBuffersQueued) } // BuffersProcessed returns the number of the processed buffers. func (s Source) BuffersProcessed() int32 { return s.Geti(paramBuffersProcessed) } // OffsetSeconds returns the current playback position of the source in seconds. func (s Source) OffsetSeconds() int32 { return s.Geti(paramSecOffset) } // OffsetSample returns the sample offset of the current playback position. func (s Source) OffsetSample() int32 { return s.Geti(paramSampleOffset) } // OffsetByte returns the byte offset of the current playback position. func (s Source) OffsetByte() int32 { return s.Geti(paramByteOffset) } // Geti returns the int32 value of the given parameter. func (s Source) Geti(param int) int32 { return alGetSourcei(s, param) } // Getf returns the float32 value of the given parameter. func (s Source) Getf(param int) float32 { return alGetSourcef(s, param) } // Getfv returns the float32 vector value of the given parameter. func (s Source) Getfv(param int, v []float32) { alGetSourcefv(s, param, v) } // Seti sets an int32 value for the given parameter. func (s Source) Seti(param int, v int32) { alSourcei(s, param, v) } // Setf sets a float32 value for the given parameter. func (s Source) Setf(param int, v float32) { alSourcef(s, param, v) } // Setfv sets a float32 vector value for the given parameter. func (s Source) Setfv(param int, v []float32) { alSourcefv(s, param, v) } // QueueBuffers adds the buffers to the buffer queue. func (s Source) QueueBuffers(buffer ...Buffer) { alSourceQueueBuffers(s, buffer) } // UnqueueBuffers removes the specified buffers from the buffer queue. func (s Source) UnqueueBuffers(buffer ...Buffer) { alSourceUnqueueBuffers(s, buffer) } // ListenerGain returns the total gain applied to the final mix. func ListenerGain() float32 { return GetListenerf(paramGain) } // ListenerPosition returns the position of the listener. func ListenerPosition() Vector { v := Vector{} GetListenerfv(paramPosition, v[:]) return v } // ListenerVelocity returns the velocity of the listener. func ListenerVelocity() Vector { v := Vector{} GetListenerfv(paramVelocity, v[:]) return v } // ListenerOrientation returns the orientation of the listener. func ListenerOrientation() Orientation { v := make([]float32, 6) GetListenerfv(paramOrientation, v) return orientationFromSlice(v) } // SetListenerGain sets the total gain that will be applied to the final mix. func SetListenerGain(v float32) { SetListenerf(paramGain, v) } // SetListenerPosition sets the position of the listener. func SetListenerPosition(v Vector) { SetListenerfv(paramPosition, v[:]) } // SetListenerVelocity sets the velocity of the listener. func SetListenerVelocity(v Vector) { SetListenerfv(paramVelocity, v[:]) } // SetListenerOrientation sets the orientation of the listener. func SetListenerOrientation(v Orientation) { SetListenerfv(paramOrientation, v.slice()) } // GetListenerf returns the float32 value of the listener parameter. func GetListenerf(param int) float32 { return alGetListenerf(param) } // GetListenerfv returns the float32 vector value of the listener parameter. func GetListenerfv(param int, v []float32) { alGetListenerfv(param, v) } // SetListenerf sets the float32 value for the listener parameter. func SetListenerf(param int, v float32) { alListenerf(param, v) } // SetListenerfv sets the float32 vector value of the listener parameter. func SetListenerfv(param int, v []float32) { alListenerfv(param, v) } // A buffer represents a chunk of PCM audio data that could be buffered to an audio // source. A single buffer could be shared between multiple sources. type Buffer uint32 // GenBuffers generates n new buffers. The generated buffers should be deleted // once they are no longer in use. func GenBuffers(n int) []Buffer { return alGenBuffers(n) } // DeleteBuffers deletes the buffers. func DeleteBuffers(buffer ...Buffer) { alDeleteBuffers(buffer) } // Geti returns the int32 value of the given parameter. func (b Buffer) Geti(param int) int32 { return b.Geti(param) } // Frequency returns the frequency of the buffer data in Hertz (Hz). func (b Buffer) Frequency() int32 { return b.Geti(paramFreq) } // Bits return the number of bits used to represent a sample. func (b Buffer) Bits() int32 { return b.Geti(paramBits) } // Channels return the number of the audio channels. func (b Buffer) Channels() int32 { return b.Geti(paramChannels) } // Size returns the size of the data. func (b Buffer) Size() int32 { return b.Geti(paramSize) } // BufferData buffers PCM data to the current buffer. func (b Buffer) BufferData(format uint32, data []byte, freq int32) { alBufferData(b, format, data, freq) } // Valid reports whether the buffer exists and is valid. func (b Buffer) Valid() bool { return alIsBuffer(b) }
al
/home/linuxreitt/Michinereitt/Tuning/Workshop_Scripts/hf-codegen/data/golang_public_repos/mobile/exp/audio/al/alc.go
// Copyright 2015 The Go Authors. All rights reserved. // Use of this source code is governed by a BSD-style // license that can be found in the LICENSE file. //go:build darwin || linux || windows package al import ( "errors" "sync" "unsafe" ) var ( mu sync.Mutex device unsafe.Pointer context unsafe.Pointer ) // DeviceError returns the last known error from the current device. func DeviceError() int32 { return alcGetError(device) } // TODO(jbd): Investigate the cases where multiple audio output // devices might be needed. // OpenDevice opens the default audio device. // Calls to OpenDevice are safe for concurrent use. func OpenDevice() error { mu.Lock() defer mu.Unlock() // already opened if device != nil { return nil } dev := alcOpenDevice("") if dev == nil { return errors.New("al: cannot open the default audio device") } ctx := alcCreateContext(dev, nil) if ctx == nil { alcCloseDevice(dev) return errors.New("al: cannot create a new context") } if !alcMakeContextCurrent(ctx) { alcCloseDevice(dev) return errors.New("al: cannot make context current") } device = dev context = ctx return nil } // CloseDevice closes the device and frees related resources. // Calls to CloseDevice are safe for concurrent use. func CloseDevice() { mu.Lock() defer mu.Unlock() if device == nil { return } alcCloseDevice(device) if context != nil { alcDestroyContext(context) } device = nil context = nil }
al
/home/linuxreitt/Michinereitt/Tuning/Workshop_Scripts/hf-codegen/data/golang_public_repos/mobile/exp/audio/al/alc_notandroid.go
// Copyright 2015 The Go Authors. All rights reserved. // Use of this source code is governed by a BSD-style // license that can be found in the LICENSE file. //go:build darwin || (linux && !android) || windows package al /* #cgo darwin CFLAGS: -DGOOS_darwin #cgo linux CFLAGS: -DGOOS_linux #cgo windows CFLAGS: -DGOOS_windows #cgo darwin LDFLAGS: -framework OpenAL #cgo linux LDFLAGS: -lopenal #cgo windows LDFLAGS: -lOpenAL32 #ifdef GOOS_darwin #include <stdlib.h> #include <OpenAL/alc.h> #endif #ifdef GOOS_linux #include <stdlib.h> #include <AL/alc.h> #endif #ifdef GOOS_windows #include <windows.h> #include <stdlib.h> #include <AL/alc.h> #endif */ import "C" import "unsafe" /* On Ubuntu 14.04 'Trusty', you may have to install these libraries: sudo apt-get install libopenal-dev */ func alcGetError(d unsafe.Pointer) int32 { dev := (*C.ALCdevice)(d) return int32(C.alcGetError(dev)) } func alcOpenDevice(name string) unsafe.Pointer { n := C.CString(name) defer C.free(unsafe.Pointer(n)) return (unsafe.Pointer)(C.alcOpenDevice((*C.ALCchar)(unsafe.Pointer(n)))) } func alcCloseDevice(d unsafe.Pointer) bool { dev := (*C.ALCdevice)(d) return C.alcCloseDevice(dev) == C.ALC_TRUE } func alcCreateContext(d unsafe.Pointer, attrs []int32) unsafe.Pointer { dev := (*C.ALCdevice)(d) return (unsafe.Pointer)(C.alcCreateContext(dev, nil)) } func alcMakeContextCurrent(c unsafe.Pointer) bool { ctx := (*C.ALCcontext)(c) return C.alcMakeContextCurrent(ctx) == C.ALC_TRUE } func alcDestroyContext(c unsafe.Pointer) { C.alcDestroyContext((*C.ALCcontext)(c)) }
al
/home/linuxreitt/Michinereitt/Tuning/Workshop_Scripts/hf-codegen/data/golang_public_repos/mobile/exp/audio/al/const.go
// Copyright 2015 The Go Authors. All rights reserved. // Use of this source code is governed by a BSD-style // license that can be found in the LICENSE file. //go:build darwin || linux || windows package al // Error returns one of these error codes. const ( InvalidName = 0xA001 InvalidEnum = 0xA002 InvalidValue = 0xA003 InvalidOperation = 0xA004 OutOfMemory = 0xA005 ) // Distance models. const ( InverseDistance = 0xD001 InverseDistanceClamped = 0xD002 LinearDistance = 0xD003 LinearDistanceClamped = 0xD004 ExponentDistance = 0xD005 ExponentDistanceClamped = 0xD006 ) // Global parameters. const ( paramDistanceModel = 0xD000 paramDopplerFactor = 0xC000 paramDopplerVelocity = 0xC001 paramSpeedOfSound = 0xC003 paramVendor = 0xB001 paramVersion = 0xB002 paramRenderer = 0xB003 paramExtensions = 0xB004 ) // Source and listener parameters. const ( paramGain = 0x100A paramPosition = 0x1004 paramVelocity = 0x1006 paramOrientation = 0x100F paramMinGain = 0x100D paramMaxGain = 0x100E paramSourceState = 0x1010 paramBuffersQueued = 0x1015 paramBuffersProcessed = 0x1016 paramSecOffset = 0x1024 paramSampleOffset = 0x1025 paramByteOffset = 0x1026 ) // A source could be in the state of initial, playing, paused or stopped. const ( Initial = 0x1011 Playing = 0x1012 Paused = 0x1013 Stopped = 0x1014 ) // Buffer parameters. const ( paramFreq = 0x2001 paramBits = 0x2002 paramChannels = 0x2003 paramSize = 0x2004 ) // Audio formats. Buffer.BufferData accepts one of these formats as the data format. const ( FormatMono8 = 0x1100 FormatMono16 = 0x1101 FormatStereo8 = 0x1102 FormatStereo16 = 0x1103 ) // CapabilityDistanceModel represents the capability of specifying a different distance // model for each source. const CapabilityDistanceModel = Capability(0x200)
al
/home/linuxreitt/Michinereitt/Tuning/Workshop_Scripts/hf-codegen/data/golang_public_repos/mobile/exp/audio/al/alc_android.go
// Copyright 2015 The Go Authors. All rights reserved. // Use of this source code is governed by a BSD-style // license that can be found in the LICENSE file. package al /* #include <stdlib.h> #include <dlfcn.h> #include <AL/al.h> #include <AL/alc.h> ALCint call_alcGetError(LPALCGETERROR fn, ALCdevice* d) { return fn(d); } ALCdevice* call_alcOpenDevice(LPALCOPENDEVICE fn, const ALCchar* name) { return fn(name); } ALCboolean call_alcCloseDevice(LPALCCLOSEDEVICE fn, ALCdevice* d) { return fn(d); } ALCcontext* call_alcCreateContext(LPALCCREATECONTEXT fn, ALCdevice* d, const ALCint* attrs) { return fn(d, attrs); } ALCboolean call_alcMakeContextCurrent(LPALCMAKECONTEXTCURRENT fn, ALCcontext* c) { return fn(c); } void call_alcDestroyContext(LPALCDESTROYCONTEXT fn, ALCcontext* c) { return fn(c); } */ import "C" import ( "sync" "unsafe" ) var once sync.Once func alcGetError(d unsafe.Pointer) int32 { dev := (*C.ALCdevice)(d) return int32(C.call_alcGetError(alcGetErrorFunc, dev)) } func alcOpenDevice(name string) unsafe.Pointer { once.Do(initAL) n := C.CString(name) defer C.free(unsafe.Pointer(n)) return (unsafe.Pointer)(C.call_alcOpenDevice(alcOpenDeviceFunc, (*C.ALCchar)(unsafe.Pointer(n)))) } func alcCloseDevice(d unsafe.Pointer) bool { dev := (*C.ALCdevice)(d) return C.call_alcCloseDevice(alcCloseDeviceFunc, dev) == C.AL_TRUE } func alcCreateContext(d unsafe.Pointer, attrs []int32) unsafe.Pointer { dev := (*C.ALCdevice)(d) // TODO(jbd): Handle attrs. return (unsafe.Pointer)(C.call_alcCreateContext(alcCreateContextFunc, dev, nil)) } func alcMakeContextCurrent(c unsafe.Pointer) bool { ctx := (*C.ALCcontext)(c) return C.call_alcMakeContextCurrent(alcMakeContextCurrentFunc, ctx) == C.AL_TRUE } func alcDestroyContext(c unsafe.Pointer) { C.call_alcDestroyContext(alcDestroyContextFunc, (*C.ALCcontext)(c)) }
al
/home/linuxreitt/Michinereitt/Tuning/Workshop_Scripts/hf-codegen/data/golang_public_repos/mobile/exp/audio/al/al_android.go
// Copyright 2015 The Go Authors. All rights reserved. // Use of this source code is governed by a BSD-style // license that can be found in the LICENSE file. package al /* #include <stdlib.h> #include <string.h> #include <dlfcn.h> #include <jni.h> #include <limits.h> #include <AL/al.h> #include <AL/alc.h> void al_init(uintptr_t java_vm, uintptr_t jni_env, jobject context, void** handle) { JavaVM* vm = (JavaVM*)java_vm; JNIEnv* env = (JNIEnv*)jni_env; jclass android_content_Context = (*env)->FindClass(env, "android/content/Context"); jmethodID get_application_info = (*env)->GetMethodID(env, android_content_Context, "getApplicationInfo", "()Landroid/content/pm/ApplicationInfo;"); jclass android_content_pm_ApplicationInfo = (*env)->FindClass(env, "android/content/pm/ApplicationInfo"); jfieldID native_library_dir = (*env)->GetFieldID(env, android_content_pm_ApplicationInfo, "nativeLibraryDir", "Ljava/lang/String;"); jobject app_info = (*env)->CallObjectMethod(env, context, get_application_info); jstring native_dir = (*env)->GetObjectField(env, app_info, native_library_dir); const char *cnative_dir = (*env)->GetStringUTFChars(env, native_dir, 0); char lib_path[PATH_MAX] = ""; strlcat(lib_path, cnative_dir, sizeof(lib_path)); strlcat(lib_path, "/libopenal.so", sizeof(lib_path)); *handle = dlopen(lib_path, RTLD_LAZY); (*env)->ReleaseStringUTFChars(env, native_dir, cnative_dir); } void call_alEnable(LPALENABLE fn, ALenum capability) { fn(capability); } void call_alDisable(LPALDISABLE fn, ALenum capability) { fn(capability); } ALboolean call_alIsEnabled(LPALISENABLED fn, ALenum capability) { return fn(capability); } ALint call_alGetInteger(LPALGETINTEGER fn, ALenum p) { return fn(p); } void call_alGetIntegerv(LPALGETINTEGERV fn, ALenum p, ALint* v) { fn(p, v); } ALfloat call_alGetFloat(LPALGETFLOAT fn, ALenum p) { return fn(p); } void call_alGetFloatv(LPALGETFLOATV fn, ALenum p, ALfloat* v) { fn(p, v); } ALboolean call_alGetBoolean(LPALGETBOOLEAN fn, ALenum p) { return fn(p); } void call_alGetBooleanv(LPALGETBOOLEANV fn, ALenum p, ALboolean* v) { fn(p, v); } const char* call_alGetString(LPALGETSTRING fn, ALenum p) { return fn(p); } void call_alDistanceModel(LPALDISTANCEMODEL fn, ALenum v) { fn(v); } void call_alDopplerFactor(LPALDOPPLERFACTOR fn, ALfloat v) { fn(v); } void call_alDopplerVelocity(LPALDOPPLERVELOCITY fn, ALfloat v) { fn(v); } void call_alSpeedOfSound(LPALSPEEDOFSOUND fn, ALfloat v) { fn(v); } ALint call_alGetError(LPALGETERROR fn) { return fn(); } void call_alGenSources(LPALGENSOURCES fn, ALsizei n, ALuint* s) { fn(n, s); } void call_alSourcePlayv(LPALSOURCEPLAYV fn, ALsizei n, const ALuint* s) { fn(n, s); } void call_alSourcePausev(LPALSOURCEPAUSEV fn, ALsizei n, const ALuint* s) { fn(n, s); } void call_alSourceStopv(LPALSOURCESTOPV fn, ALsizei n, const ALuint* s) { fn(n, s); } void call_alSourceRewindv(LPALSOURCEREWINDV fn, ALsizei n, const ALuint* s) { fn(n, s); } void call_alDeleteSources(LPALDELETESOURCES fn, ALsizei n, const ALuint* s) { fn(n, s); } void call_alGetSourcei(LPALGETSOURCEI fn, ALuint s, ALenum k, ALint* v) { fn(s, k, v); } void call_alGetSourcef(LPALGETSOURCEF fn, ALuint s, ALenum k, ALfloat* v) { fn(s, k, v); } void call_alGetSourcefv(LPALGETSOURCEFV fn, ALuint s, ALenum k, ALfloat* v) { fn(s, k, v); } void call_alSourcei(LPALSOURCEI fn, ALuint s, ALenum k, ALint v) { fn(s, k, v); } void call_alSourcef(LPALSOURCEF fn, ALuint s, ALenum k, ALfloat v) { fn(s, k, v); } void call_alSourcefv(LPALSOURCEFV fn, ALuint s, ALenum k, const ALfloat* v) { fn(s, k, v); } void call_alSourceQueueBuffers(LPALSOURCEQUEUEBUFFERS fn, ALuint s, ALsizei n, const ALuint* b) { fn(s, n, b); } void call_alSourceUnqueueBuffers(LPALSOURCEUNQUEUEBUFFERS fn, ALuint s, ALsizei n, ALuint* b) { fn(s, n, b); } void call_alGetListenerf(LPALGETLISTENERF fn, ALenum k, ALfloat* v) { fn(k, v); } void call_alGetListenerfv(LPALLISTENERFV fn, ALenum k, ALfloat* v) { fn(k, v); } void call_alListenerf(LPALLISTENERF fn, ALenum k, ALfloat v) { fn(k, v); } void call_alListenerfv(LPALLISTENERFV fn, ALenum k, const ALfloat* v) { fn(k, v); } void call_alGenBuffers(LPALGENBUFFERS fn, ALsizei n, ALuint* v) { fn(n, v); } void call_alDeleteBuffers(LPALDELETEBUFFERS fn, ALsizei n, ALuint* v) { fn(n, v); } void call_alGetBufferi(LPALGETBUFFERI fn, ALuint b, ALenum k, ALint* v) { fn(b, k, v); } void call_alBufferData(LPALBUFFERDATA fn, ALuint b, ALenum format, const ALvoid* data, ALsizei size, ALsizei freq) { fn(b, format, data, size, freq); } ALboolean call_alIsBuffer(LPALISBUFFER fn, ALuint b) { return fn(b); } */ import "C" import ( "errors" "log" "unsafe" "golang.org/x/mobile/internal/mobileinit" ) var ( alHandle unsafe.Pointer alEnableFunc C.LPALENABLE alDisableFunc C.LPALDISABLE alIsEnabledFunc C.LPALISENABLED alGetIntegerFunc C.LPALGETINTEGER alGetIntegervFunc C.LPALGETINTEGERV alGetFloatFunc C.LPALGETFLOAT alGetFloatvFunc C.LPALGETFLOATV alGetBooleanFunc C.LPALGETBOOLEAN alGetBooleanvFunc C.LPALGETBOOLEANV alGetStringFunc C.LPALGETSTRING alDistanceModelFunc C.LPALDISTANCEMODEL alDopplerFactorFunc C.LPALDOPPLERFACTOR alDopplerVelocityFunc C.LPALDOPPLERVELOCITY alSpeedOfSoundFunc C.LPALSPEEDOFSOUND alGetErrorFunc C.LPALGETERROR alGenSourcesFunc C.LPALGENSOURCES alSourcePlayvFunc C.LPALSOURCEPLAYV alSourcePausevFunc C.LPALSOURCEPAUSEV alSourceStopvFunc C.LPALSOURCESTOPV alSourceRewindvFunc C.LPALSOURCEREWINDV alDeleteSourcesFunc C.LPALDELETESOURCES alGetSourceiFunc C.LPALGETSOURCEI alGetSourcefFunc C.LPALGETSOURCEF alGetSourcefvFunc C.LPALGETSOURCEFV alSourceiFunc C.LPALSOURCEI alSourcefFunc C.LPALSOURCEF alSourcefvFunc C.LPALSOURCEFV alSourceQueueBuffersFunc C.LPALSOURCEQUEUEBUFFERS alSourceUnqueueBuffersFunc C.LPALSOURCEUNQUEUEBUFFERS alGetListenerfFunc C.LPALGETLISTENERF alGetListenerfvFunc C.LPALGETLISTENERFV alListenerfFunc C.LPALLISTENERF alListenerfvFunc C.LPALLISTENERFV alGenBuffersFunc C.LPALGENBUFFERS alDeleteBuffersFunc C.LPALDELETEBUFFERS alGetBufferiFunc C.LPALGETBUFFERI alBufferDataFunc C.LPALBUFFERDATA alIsBufferFunc C.LPALISBUFFER alcGetErrorFunc C.LPALCGETERROR alcOpenDeviceFunc C.LPALCOPENDEVICE alcCloseDeviceFunc C.LPALCCLOSEDEVICE alcCreateContextFunc C.LPALCCREATECONTEXT alcMakeContextCurrentFunc C.LPALCMAKECONTEXTCURRENT alcDestroyContextFunc C.LPALCDESTROYCONTEXT ) func initAL() { err := mobileinit.RunOnJVM(func(vm, env, ctx uintptr) error { C.al_init(C.uintptr_t(vm), C.uintptr_t(env), C.jobject(ctx), &alHandle) if alHandle == nil { return errors.New("al: cannot load libopenal.so") } return nil }) if err != nil { log.Fatalf("al: %v", err) } alEnableFunc = C.LPALENABLE(fn("alEnable")) alDisableFunc = C.LPALDISABLE(fn("alDisable")) alIsEnabledFunc = C.LPALISENABLED(fn("alIsEnabled")) alGetIntegerFunc = C.LPALGETINTEGER(fn("alGetInteger")) alGetIntegervFunc = C.LPALGETINTEGERV(fn("alGetIntegerv")) alGetFloatFunc = C.LPALGETFLOAT(fn("alGetFloat")) alGetFloatvFunc = C.LPALGETFLOATV(fn("alGetFloatv")) alGetBooleanFunc = C.LPALGETBOOLEAN(fn("alGetBoolean")) alGetBooleanvFunc = C.LPALGETBOOLEANV(fn("alGetBooleanv")) alGetStringFunc = C.LPALGETSTRING(fn("alGetString")) alDistanceModelFunc = C.LPALDISTANCEMODEL(fn("alDistanceModel")) alDopplerFactorFunc = C.LPALDOPPLERFACTOR(fn("alDopplerFactor")) alDopplerVelocityFunc = C.LPALDOPPLERVELOCITY(fn("alDopplerVelocity")) alSpeedOfSoundFunc = C.LPALSPEEDOFSOUND(fn("alSpeedOfSound")) alGetErrorFunc = C.LPALGETERROR(fn("alGetError")) alGenSourcesFunc = C.LPALGENSOURCES(fn("alGenSources")) alSourcePlayvFunc = C.LPALSOURCEPLAYV(fn("alSourcePlayv")) alSourcePausevFunc = C.LPALSOURCEPAUSEV(fn("alSourcePausev")) alSourceStopvFunc = C.LPALSOURCESTOPV(fn("alSourceStopv")) alSourceRewindvFunc = C.LPALSOURCEREWINDV(fn("alSourceRewindv")) alDeleteSourcesFunc = C.LPALDELETESOURCES(fn("alDeleteSources")) alGetSourceiFunc = C.LPALGETSOURCEI(fn("alGetSourcei")) alGetSourcefFunc = C.LPALGETSOURCEF(fn("alGetSourcef")) alGetSourcefvFunc = C.LPALGETSOURCEFV(fn("alGetSourcefv")) alSourceiFunc = C.LPALSOURCEI(fn("alSourcei")) alSourcefFunc = C.LPALSOURCEF(fn("alSourcef")) alSourcefvFunc = C.LPALSOURCEFV(fn("alSourcefv")) alSourceQueueBuffersFunc = C.LPALSOURCEQUEUEBUFFERS(fn("alSourceQueueBuffers")) alSourceUnqueueBuffersFunc = C.LPALSOURCEUNQUEUEBUFFERS(fn("alSourceUnqueueBuffers")) alGetListenerfFunc = C.LPALGETLISTENERF(fn("alGetListenerf")) alGetListenerfvFunc = C.LPALGETLISTENERFV(fn("alGetListenerfv")) alListenerfFunc = C.LPALLISTENERF(fn("alListenerf")) alListenerfvFunc = C.LPALLISTENERFV(fn("alListenerfv")) alGenBuffersFunc = C.LPALGENBUFFERS(fn("alGenBuffers")) alDeleteBuffersFunc = C.LPALDELETEBUFFERS(fn("alDeleteBuffers")) alGetBufferiFunc = C.LPALGETBUFFERI(fn("alGetBufferi")) alBufferDataFunc = C.LPALBUFFERDATA(fn("alBufferData")) alIsBufferFunc = C.LPALISBUFFER(fn("alIsBuffer")) alcGetErrorFunc = C.LPALCGETERROR(fn("alcGetError")) alcOpenDeviceFunc = C.LPALCOPENDEVICE(fn("alcOpenDevice")) alcCloseDeviceFunc = C.LPALCCLOSEDEVICE(fn("alcCloseDevice")) alcCreateContextFunc = C.LPALCCREATECONTEXT(fn("alcCreateContext")) alcMakeContextCurrentFunc = C.LPALCMAKECONTEXTCURRENT(fn("alcMakeContextCurrent")) alcDestroyContextFunc = C.LPALCDESTROYCONTEXT(fn("alcDestroyContext")) } func fn(fname string) unsafe.Pointer { name := C.CString(fname) defer C.free(unsafe.Pointer(name)) p := C.dlsym(alHandle, name) if uintptr(p) == 0 { log.Fatalf("al: couldn't dlsym %q", fname) } return p } func alEnable(capability int32) { C.call_alEnable(alEnableFunc, C.ALenum(capability)) } func alDisable(capability int32) { C.call_alDisable(alDisableFunc, C.ALenum(capability)) } func alIsEnabled(capability int32) bool { return C.call_alIsEnabled(alIsEnabledFunc, C.ALenum(capability)) == C.AL_TRUE } func alGetInteger(k int) int32 { return int32(C.call_alGetInteger(alGetIntegerFunc, C.ALenum(k))) } func alGetIntegerv(k int, v []int32) { C.call_alGetIntegerv(alGetIntegervFunc, C.ALenum(k), (*C.ALint)(unsafe.Pointer(&v[0]))) } func alGetFloat(k int) float32 { return float32(C.call_alGetFloat(alGetFloatFunc, C.ALenum(k))) } func alGetFloatv(k int, v []float32) { C.call_alGetFloatv(alGetFloatvFunc, C.ALenum(k), (*C.ALfloat)(unsafe.Pointer(&v[0]))) } func alGetBoolean(k int) bool { return C.call_alGetBoolean(alGetBooleanFunc, C.ALenum(k)) == C.AL_TRUE } func alGetBooleanv(k int, v []bool) { val := make([]C.ALboolean, len(v)) for i, bv := range v { if bv { val[i] = C.AL_TRUE } else { val[i] = C.AL_FALSE } } C.call_alGetBooleanv(alGetBooleanvFunc, C.ALenum(k), &val[0]) } func alGetString(v int) string { value := C.call_alGetString(alGetStringFunc, C.ALenum(v)) return C.GoString(value) } func alDistanceModel(v int32) { C.call_alDistanceModel(alDistanceModelFunc, C.ALenum(v)) } func alDopplerFactor(v float32) { C.call_alDopplerFactor(alDopplerFactorFunc, C.ALfloat(v)) } func alDopplerVelocity(v float32) { C.call_alDopplerVelocity(alDopplerVelocityFunc, C.ALfloat(v)) } func alSpeedOfSound(v float32) { C.call_alSpeedOfSound(alSpeedOfSoundFunc, C.ALfloat(v)) } func alGetError() int32 { return int32(C.call_alGetError(alGetErrorFunc)) } func alGenSources(n int) []Source { s := make([]Source, n) C.call_alGenSources(alGenSourcesFunc, C.ALsizei(n), (*C.ALuint)(unsafe.Pointer(&s[0]))) return s } func alSourcePlayv(s []Source) { C.call_alSourcePlayv(alSourcePlayvFunc, C.ALsizei(len(s)), (*C.ALuint)(unsafe.Pointer(&s[0]))) } func alSourcePausev(s []Source) { C.call_alSourcePausev(alSourcePausevFunc, C.ALsizei(len(s)), (*C.ALuint)(unsafe.Pointer(&s[0]))) } func alSourceStopv(s []Source) { C.call_alSourceStopv(alSourceStopvFunc, C.ALsizei(len(s)), (*C.ALuint)(unsafe.Pointer(&s[0]))) } func alSourceRewindv(s []Source) { C.call_alSourceRewindv(alSourceRewindvFunc, C.ALsizei(len(s)), (*C.ALuint)(unsafe.Pointer(&s[0]))) } func alDeleteSources(s []Source) { C.call_alDeleteSources(alDeleteSourcesFunc, C.ALsizei(len(s)), (*C.ALuint)(unsafe.Pointer(&s[0]))) } func alGetSourcei(s Source, k int) int32 { var v C.ALint C.call_alGetSourcei(alGetSourceiFunc, C.ALuint(s), C.ALenum(k), &v) return int32(v) } func alGetSourcef(s Source, k int) float32 { var v C.ALfloat C.call_alGetSourcef(alGetSourcefFunc, C.ALuint(s), C.ALenum(k), &v) return float32(v) } func alGetSourcefv(s Source, k int, v []float32) { C.call_alGetSourcefv(alGetSourcefvFunc, C.ALuint(s), C.ALenum(k), (*C.ALfloat)(unsafe.Pointer(&v[0]))) } func alSourcei(s Source, k int, v int32) { C.call_alSourcei(alSourcefFunc, C.ALuint(s), C.ALenum(k), C.ALint(v)) } func alSourcef(s Source, k int, v float32) { C.call_alSourcef(alSourcefFunc, C.ALuint(s), C.ALenum(k), C.ALfloat(v)) } func alSourcefv(s Source, k int, v []float32) { C.call_alSourcefv(alSourcefvFunc, C.ALuint(s), C.ALenum(k), (*C.ALfloat)(unsafe.Pointer(&v[0]))) } func alSourceQueueBuffers(s Source, b []Buffer) { C.call_alSourceQueueBuffers(alSourceQueueBuffersFunc, C.ALuint(s), C.ALsizei(len(b)), (*C.ALuint)(unsafe.Pointer(&b[0]))) } func alSourceUnqueueBuffers(s Source, b []Buffer) { C.call_alSourceUnqueueBuffers(alSourceUnqueueBuffersFunc, C.ALuint(s), C.ALsizei(len(b)), (*C.ALuint)(unsafe.Pointer(&b[0]))) } func alGetListenerf(k int) float32 { var v C.ALfloat C.call_alGetListenerf(alListenerfFunc, C.ALenum(k), &v) return float32(v) } func alGetListenerfv(k int, v []float32) { C.call_alGetListenerfv(alGetListenerfvFunc, C.ALenum(k), (*C.ALfloat)(unsafe.Pointer(&v[0]))) } func alListenerf(k int, v float32) { C.call_alListenerf(alListenerfFunc, C.ALenum(k), C.ALfloat(v)) } func alListenerfv(k int, v []float32) { C.call_alListenerfv(alListenerfvFunc, C.ALenum(k), (*C.ALfloat)(unsafe.Pointer(&v[0]))) } func alGenBuffers(n int) []Buffer { s := make([]Buffer, n) C.call_alGenBuffers(alGenBuffersFunc, C.ALsizei(n), (*C.ALuint)(unsafe.Pointer(&s[0]))) return s } func alDeleteBuffers(b []Buffer) { C.call_alDeleteBuffers(alDeleteBuffersFunc, C.ALsizei(len(b)), (*C.ALuint)(unsafe.Pointer(&b[0]))) } func alGetBufferi(b Buffer, k int) int32 { var v C.ALint C.call_alGetBufferi(alGetBufferiFunc, C.ALuint(b), C.ALenum(k), &v) return int32(v) } func alBufferData(b Buffer, format uint32, data []byte, freq int32) { C.call_alBufferData(alBufferDataFunc, C.ALuint(b), C.ALenum(format), unsafe.Pointer(&data[0]), C.ALsizei(len(data)), C.ALsizei(freq)) } func alIsBuffer(b Buffer) bool { return C.call_alIsBuffer(alIsBufferFunc, C.ALuint(b)) == C.AL_TRUE }
font
/home/linuxreitt/Michinereitt/Tuning/Workshop_Scripts/hf-codegen/data/golang_public_repos/mobile/exp/font/font_android.go
// Copyright 2014 The Go Authors. All rights reserved. // Use of this source code is governed by a BSD-style // license that can be found in the LICENSE file. package font import "io/ioutil" func buildDefault() ([]byte, error) { return ioutil.ReadFile("/system/fonts/DroidSans.ttf") } func buildMonospace() ([]byte, error) { return ioutil.ReadFile("/system/fonts/DroidSansMono.ttf") }
font
/home/linuxreitt/Michinereitt/Tuning/Workshop_Scripts/hf-codegen/data/golang_public_repos/mobile/exp/font/doc.go
// Copyright 2014 The Go Authors. All rights reserved. // Use of this source code is governed by a BSD-style // license that can be found in the LICENSE file. // Package font provides platform independent access to system fonts. package font // import "golang.org/x/mobile/exp/font"
font
/home/linuxreitt/Michinereitt/Tuning/Workshop_Scripts/hf-codegen/data/golang_public_repos/mobile/exp/font/font.go
// Copyright 2014 The Go Authors. All rights reserved. // Use of this source code is governed by a BSD-style // license that can be found in the LICENSE file. //go:build linux || darwin package font // Default returns the default system font. // The font is encoded as a TTF. func Default() []byte { b, err := buildDefault() if err != nil { panic(err) } return b } // Monospace returns the default system fixed-pitch font. // The font is encoded as a TTF. func Monospace() []byte { b, err := buildMonospace() if err != nil { panic(err) } return b }
font
/home/linuxreitt/Michinereitt/Tuning/Workshop_Scripts/hf-codegen/data/golang_public_repos/mobile/exp/font/font_darwin.go
// Copyright 2014 The Go Authors. All rights reserved. // Use of this source code is governed by a BSD-style // license that can be found in the LICENSE file. package font /* #cgo darwin LDFLAGS: -framework CoreFoundation -framework CoreText #include <CoreFoundation/CFArray.h> #include <CoreFoundation/CFBase.h> #include <CoreFoundation/CFData.h> #include <CoreText/CTFont.h> */ import "C" import "unsafe" func buildFont(f C.CTFontRef) []byte { ctags := C.CTFontCopyAvailableTables(f, C.kCTFontTableOptionExcludeSynthetic) tagsCount := C.CFArrayGetCount(ctags) var tags []uint32 var dataRefs []C.CFDataRef var dataLens []uint32 for i := C.CFIndex(0); i < tagsCount; i++ { tag := (C.CTFontTableTag)((uintptr)(C.CFArrayGetValueAtIndex(ctags, i))) dataRef := C.CTFontCopyTable(f, tag, 0) // retained tags = append(tags, uint32(tag)) dataRefs = append(dataRefs, dataRef) dataLens = append(dataLens, uint32(C.CFDataGetLength(dataRef))) } totalLen := 0 for _, l := range dataLens { totalLen += int(l) } // Big-endian output. buf := make([]byte, 0, 12+16*len(tags)+totalLen) write16 := func(x uint16) { buf = append(buf, byte(x>>8), byte(x)) } write32 := func(x uint32) { buf = append(buf, byte(x>>24), byte(x>>16), byte(x>>8), byte(x)) } // File format description: http://www.microsoft.com/typography/otspec/otff.htm write32(0x00010000) // version 1.0 write16(uint16(len(tags))) // numTables write16(0) // searchRange write16(0) // entrySelector write16(0) // rangeShift // Table tags, includes offsets into following data segments. offset := uint32(12 + 16*len(tags)) // offset starts after table tags for i, tag := range tags { write32(tag) write32(0) write32(offset) write32(dataLens[i]) offset += dataLens[i] } // Data segments. for i, dataRef := range dataRefs { data := (*[1<<31 - 2]byte)((unsafe.Pointer)(C.CFDataGetBytePtr(dataRef)))[:dataLens[i]] buf = append(buf, data...) C.CFRelease(C.CFTypeRef(dataRef)) } return buf } func buildDefault() ([]byte, error) { return buildFont(C.CTFontCreateUIFontForLanguage(C.kCTFontSystemFontType, 0, 0)), nil } func buildMonospace() ([]byte, error) { return buildFont(C.CTFontCreateUIFontForLanguage(C.kCTFontUserFixedPitchFontType, 0, 0)), nil }
font
/home/linuxreitt/Michinereitt/Tuning/Workshop_Scripts/hf-codegen/data/golang_public_repos/mobile/exp/font/font_linux.go
// Copyright 2014 The Go Authors. All rights reserved. // Use of this source code is governed by a BSD-style // license that can be found in the LICENSE file. //go:build !android package font import "io/ioutil" func buildDefault() ([]byte, error) { // Try Noto first, but fall back to Droid as the latter was deprecated noto, nerr := ioutil.ReadFile("/usr/share/fonts/truetype/noto/NotoSans-Regular.ttf") if nerr != nil { if droid, err := ioutil.ReadFile("/usr/share/fonts/truetype/droid/DroidSans.ttf"); err == nil { return droid, nil } } return noto, nerr } func buildMonospace() ([]byte, error) { // Try Noto first, but fall back to Droid as the latter was deprecated noto, nerr := ioutil.ReadFile("/usr/share/fonts/truetype/noto/NotoMono-Regular.ttf") if nerr != nil { if droid, err := ioutil.ReadFile("/usr/share/fonts/truetype/droid/DroidSansMono.ttf"); err == nil { return droid, nil } } return noto, nerr }
font
/home/linuxreitt/Michinereitt/Tuning/Workshop_Scripts/hf-codegen/data/golang_public_repos/mobile/exp/font/font_test.go
// Copyright 2014 The Go Authors. All rights reserved. // Use of this source code is governed by a BSD-style // license that can be found in the LICENSE file. //go:build linux || darwin package font import ( "bytes" "fmt" "testing" ) func looksLikeATTF(b []byte) error { if len(b) < 256 { return fmt.Errorf("not a TTF: not enough data") } b = b[:256] // Look for the 4-byte magic header. See // http://www.microsoft.com/typography/otspec/otff.htm switch string(b[:4]) { case "\x00\x01\x00\x00", "ttcf": // No-op. default: return fmt.Errorf("not a TTF: missing magic header") } // Look for a glyf table. if i := bytes.Index(b, []byte("glyf")); i < 0 { return fmt.Errorf(`not a TTF: missing "glyf" table`) } else if i%0x10 != 0x0c { return fmt.Errorf(`not a TTF: invalid "glyf" offset 0x%02x`, i) } return nil } func TestLoadDefault(t *testing.T) { def, err := buildDefault() if err != nil { t.Skip("default font not found") } if err := looksLikeATTF(def); err != nil { t.Errorf("default font: %v", err) } } func TestLoadMonospace(t *testing.T) { mono, err := buildMonospace() if err != nil { t.Skip("mono font not found") } if err := looksLikeATTF(mono); err != nil { t.Errorf("monospace font: %v", err) } }
debug
/home/linuxreitt/Michinereitt/Tuning/Workshop_Scripts/hf-codegen/data/golang_public_repos/mobile/exp/app/debug/fps.go
// Copyright 2014 The Go Authors. All rights reserved. // Use of this source code is governed by a BSD-style // license that can be found in the LICENSE file. //go:build darwin || linux || windows // Package debug provides GL-based debugging tools for apps. package debug // import "golang.org/x/mobile/exp/app/debug" import ( "image" "image/color" "image/draw" "time" "golang.org/x/mobile/event/size" "golang.org/x/mobile/exp/gl/glutil" "golang.org/x/mobile/geom" ) // FPS draws a count of the frames rendered per second. type FPS struct { sz size.Event images *glutil.Images m *glutil.Image lastDraw time.Time // TODO: store *gl.Context } // NewFPS creates an FPS tied to the current GL context. func NewFPS(images *glutil.Images) *FPS { return &FPS{ lastDraw: time.Now(), images: images, } } // Draw draws the per second framerate in the bottom-left of the screen. func (p *FPS) Draw(sz size.Event) { const imgW, imgH = 7*(fontWidth+1) + 1, fontHeight + 2 if sz.WidthPx == 0 && sz.HeightPx == 0 { return } if p.sz != sz { p.sz = sz if p.m != nil { p.m.Release() } p.m = p.images.NewImage(imgW, imgH) } display := [7]byte{ 4: 'F', 5: 'P', 6: 'S', } now := time.Now() f := 0 if dur := now.Sub(p.lastDraw); dur > 0 { f = int(time.Second / dur) } display[2] = '0' + byte((f/1e0)%10) display[1] = '0' + byte((f/1e1)%10) display[0] = '0' + byte((f/1e2)%10) draw.Draw(p.m.RGBA, p.m.RGBA.Bounds(), image.White, image.Point{}, draw.Src) for i, c := range display { glyph := glyphs[c] if len(glyph) != fontWidth*fontHeight { continue } for y := 0; y < fontHeight; y++ { for x := 0; x < fontWidth; x++ { if glyph[fontWidth*y+x] == ' ' { continue } p.m.RGBA.SetRGBA((fontWidth+1)*i+x+1, y+1, color.RGBA{A: 0xff}) } } } p.m.Upload() p.m.Draw( sz, geom.Point{0, sz.HeightPt - imgH}, geom.Point{imgW, sz.HeightPt - imgH}, geom.Point{0, sz.HeightPt}, p.m.RGBA.Bounds(), ) p.lastDraw = now } func (f *FPS) Release() { if f.m != nil { f.m.Release() f.m = nil f.images = nil } } const ( fontWidth = 5 fontHeight = 7 ) // glyphs comes from the 6x10 fixed font from the plan9port: // https://github.com/9fans/plan9port/tree/master/font/fixed // // 6x10 becomes 5x7 because each glyph has a 1-pixel margin plus space for // descenders. // // Its README file says that those fonts were converted from XFree86, and are // in the public domain. var glyphs = [256]string{ '0': "" + " X " + " X X " + "X X" + "X X" + "X X" + " X X " + " X ", '1': "" + " X " + " XX " + "X X " + " X " + " X " + " X " + "XXXXX", '2': "" + " XXX " + "X X" + " X" + " XX " + " X " + "X " + "XXXXX", '3': "" + "XXXXX" + " X" + " X " + " XX " + " X" + "X X" + " XXX ", '4': "" + " X " + " XX " + " X X " + "X X " + "XXXXX" + " X " + " X ", '5': "" + "XXXXX" + "X " + "X XX " + "XX X" + " X" + "X X" + " XXX ", '6': "" + " XX " + " X " + "X " + "X XX " + "XX X" + "X X" + " XXX ", '7': "" + "XXXXX" + " X" + " X " + " X " + " X " + " X " + " X ", '8': "" + " XXX " + "X X" + "X X" + " XXX " + "X X" + "X X" + " XXX ", '9': "" + " XXX " + "X X" + "X XX" + " XX X" + " X" + " X " + " XX ", 'F': "" + "XXXXX" + "X " + "X " + "XXXX " + "X " + "X " + "X ", 'P': "" + "XXXX " + "X X" + "X X" + "XXXX " + "X " + "X " + "X ", 'S': "" + " XXX " + "X X" + "X " + " XXX " + " X" + "X X" + " XXX ", }
f32
/home/linuxreitt/Michinereitt/Tuning/Workshop_Scripts/hf-codegen/data/golang_public_repos/mobile/exp/f32/vec3.go
// Copyright 2014 The Go Authors. All rights reserved. // Use of this source code is governed by a BSD-style // license that can be found in the LICENSE file. package f32 import "fmt" type Vec3 [3]float32 func (v Vec3) String() string { return fmt.Sprintf("Vec3[% 0.3f, % 0.3f, % 0.3f]", v[0], v[1], v[2]) } func (v *Vec3) Normalize() { sq := v.Dot(v) inv := 1 / Sqrt(sq) v[0] *= inv v[1] *= inv v[2] *= inv } func (v *Vec3) Sub(v0, v1 *Vec3) { v[0] = v0[0] - v1[0] v[1] = v0[1] - v1[1] v[2] = v0[2] - v1[2] } func (v *Vec3) Add(v0, v1 *Vec3) { v[0] = v0[0] + v1[0] v[1] = v0[1] + v1[1] v[2] = v0[2] + v1[2] } func (v *Vec3) Mul(v0, v1 *Vec3) { v[0] = v0[0] * v1[0] v[1] = v0[1] * v1[1] v[2] = v0[2] * v1[2] } func (v *Vec3) Cross(v0, v1 *Vec3) { v[0] = v0[1]*v1[2] - v0[2]*v1[1] v[1] = v0[2]*v1[0] - v0[0]*v1[2] v[2] = v0[0]*v1[1] - v0[1]*v1[0] } func (v *Vec3) Dot(v1 *Vec3) float32 { return v[0]*v1[0] + v[1]*v1[1] + v[2]*v1[2] }
f32
/home/linuxreitt/Michinereitt/Tuning/Workshop_Scripts/hf-codegen/data/golang_public_repos/mobile/exp/f32/mat3.go
// Copyright 2014 The Go Authors. All rights reserved. // Use of this source code is governed by a BSD-style // license that can be found in the LICENSE file. package f32 import "fmt" // A Mat3 is a 3x3 matrix of float32 values. // Elements are indexed first by row then column, i.e. m[row][column]. type Mat3 [3]Vec3 func (m Mat3) String() string { return fmt.Sprintf(`Mat3[% 0.3f, % 0.3f, % 0.3f, % 0.3f, % 0.3f, % 0.3f, % 0.3f, % 0.3f, % 0.3f]`, m[0][0], m[0][1], m[0][2], m[1][0], m[1][1], m[1][2], m[2][0], m[2][1], m[2][2]) } func (m *Mat3) Identity() { *m = Mat3{ {1, 0, 0}, {0, 1, 0}, {0, 0, 1}, } } func (m *Mat3) Eq(n *Mat3, epsilon float32) bool { for i := range m { for j := range m[i] { diff := m[i][j] - n[i][j] if diff < -epsilon || +epsilon < diff { return false } } } return true } // Mul stores a × b in m. func (m *Mat3) Mul(a, b *Mat3) { // Store the result in local variables, in case m == a || m == b. m00 := a[0][0]*b[0][0] + a[0][1]*b[1][0] + a[0][2]*b[2][0] m01 := a[0][0]*b[0][1] + a[0][1]*b[1][1] + a[0][2]*b[2][1] m02 := a[0][0]*b[0][2] + a[0][1]*b[1][2] + a[0][2]*b[2][2] m10 := a[1][0]*b[0][0] + a[1][1]*b[1][0] + a[1][2]*b[2][0] m11 := a[1][0]*b[0][1] + a[1][1]*b[1][1] + a[1][2]*b[2][1] m12 := a[1][0]*b[0][2] + a[1][1]*b[1][2] + a[1][2]*b[2][2] m20 := a[2][0]*b[0][0] + a[2][1]*b[1][0] + a[2][2]*b[2][0] m21 := a[2][0]*b[0][1] + a[2][1]*b[1][1] + a[2][2]*b[2][1] m22 := a[2][0]*b[0][2] + a[2][1]*b[1][2] + a[2][2]*b[2][2] m[0][0] = m00 m[0][1] = m01 m[0][2] = m02 m[1][0] = m10 m[1][1] = m11 m[1][2] = m12 m[2][0] = m20 m[2][1] = m21 m[2][2] = m22 }
f32
/home/linuxreitt/Michinereitt/Tuning/Workshop_Scripts/hf-codegen/data/golang_public_repos/mobile/exp/f32/vec4.go
// Copyright 2014 The Go Authors. All rights reserved. // Use of this source code is governed by a BSD-style // license that can be found in the LICENSE file. package f32 import "fmt" type Vec4 [4]float32 func (v Vec4) String() string { return fmt.Sprintf("Vec4[% 0.3f, % 0.3f, % 0.3f, % 0.3f]", v[0], v[1], v[2], v[3]) } func (v *Vec4) Normalize() { sq := v.Dot(v) inv := 1 / Sqrt(sq) v[0] *= inv v[1] *= inv v[2] *= inv v[3] *= inv } func (v *Vec4) Sub(v0, v1 *Vec4) { v[0] = v0[0] - v1[0] v[1] = v0[1] - v1[1] v[2] = v0[2] - v1[2] v[3] = v0[3] - v1[3] } func (v *Vec4) Add(v0, v1 *Vec4) { v[0] = v0[0] + v1[0] v[1] = v0[1] + v1[1] v[2] = v0[2] + v1[2] v[3] = v0[3] + v1[3] } func (v *Vec4) Mul(v0, v1 *Vec4) { v[0] = v0[0] * v1[0] v[1] = v0[1] * v1[1] v[2] = v0[2] * v1[2] v[3] = v0[3] * v1[3] } func (v *Vec4) Dot(v1 *Vec4) float32 { return v[0]*v1[0] + v[1]*v1[1] + v[2]*v1[2] + v[3]*v1[3] }
f32
/home/linuxreitt/Michinereitt/Tuning/Workshop_Scripts/hf-codegen/data/golang_public_repos/mobile/exp/f32/f32_test.go
// Copyright 2014 The Go Authors. All rights reserved. // Use of this source code is governed by a BSD-style // license that can be found in the LICENSE file. package f32 import ( "bytes" "encoding/binary" "math" "testing" ) func TestAffineTranslationsCommute(t *testing.T) { a := &Affine{ {1, 0, 3}, {0, 1, 4}, } b := &Affine{ {1, 0, 20}, {0, 1, 30}, } var m0, m1 Affine m0.Mul(a, b) m1.Mul(b, a) if !m0.Eq(&m1, 0) { t.Errorf("m0, m1 differ.\nm0: %v\nm1: %v", m0, m1) } } func TestAffineMat3Equivalence(t *testing.T) { a0 := Affine{ {13, 19, 37}, {101, 149, 311}, } m0 := Mat3{ a0[0], a0[1], {0, 0, 1}, } a1 := Affine{ {1009, 1051, 1087}, {563, 569, 571}, } m1 := Mat3{ a1[0], a1[1], {0, 0, 1}, } a2 := Affine{} a2.Mul(&a0, &a1) m2 := Mat3{ a2[0], a2[1], {0, 0, 1}, } mm := Mat3{} mm.Mul(&m0, &m1) if !m2.Eq(&mm, 0) { t.Errorf("m2, mm differ.\nm2: %v\nmm: %v", m2, mm) } } var x3 = Mat3{ {0, 1, 2}, {3, 4, 5}, {6, 7, 8}, } var x3sq = Mat3{ {15, 18, 21}, {42, 54, 66}, {69, 90, 111}, } var id3 = Mat3{ {1, 0, 0}, {0, 1, 0}, {0, 0, 1}, } func TestMat3Mul(t *testing.T) { tests := []struct{ m0, m1, want Mat3 }{ {x3, id3, x3}, {id3, x3, x3}, {x3, x3, x3sq}, { Mat3{ {+1.811, +0.000, +0.000}, {+0.000, +2.414, +0.000}, {+0.000, +0.000, -1.010}, }, Mat3{ {+0.992, -0.015, +0.123}, {+0.000, +0.992, +0.123}, {-0.124, -0.122, +0.985}, }, Mat3{ {+1.797, -0.027, +0.223}, {+0.000, +2.395, +0.297}, {+0.125, +0.123, -0.995}, }, }, } for i, test := range tests { got := Mat3{} got.Mul(&test.m0, &test.m1) if !got.Eq(&test.want, 0.01) { t.Errorf("test #%d:\n%s *\n%s =\n%s, want\n%s", i, test.m0, test.m1, got, test.want) } } } func TestMat3SelfMul(t *testing.T) { m := x3 m.Mul(&m, &m) if !m.Eq(&x3sq, 0) { t.Errorf("m, x3sq differ.\nm: %v\nx3sq: %v", m, x3sq) } } var x4 = Mat4{ {0, 1, 2, 3}, {4, 5, 6, 7}, {8, 9, 10, 11}, {12, 13, 14, 15}, } var x4sq = Mat4{ {56, 62, 68, 74}, {152, 174, 196, 218}, {248, 286, 324, 362}, {344, 398, 452, 506}, } var id4 = Mat4{ {1, 0, 0, 0}, {0, 1, 0, 0}, {0, 0, 1, 0}, {0, 0, 0, 1}, } func TestMat4Eq(t *testing.T) { tests := []struct { m0, m1 Mat4 eq bool }{ {x4, x4, true}, {id4, id4, true}, {x4, id4, false}, } for _, test := range tests { got := test.m0.Eq(&test.m1, 0.01) if got != test.eq { t.Errorf("Eq=%v, want %v for\n%s\n%s", got, test.eq, test.m0, test.m1) } } } func TestMat4Mul(t *testing.T) { tests := []struct{ m0, m1, want Mat4 }{ {x4, id4, x4}, {id4, x4, x4}, {x4, x4, x4sq}, { Mat4{ {+1.811, +0.000, +0.000, +0.000}, {+0.000, +2.414, +0.000, +0.000}, {+0.000, +0.000, -1.010, -1.000}, {+0.000, +0.000, -2.010, +0.000}, }, Mat4{ {+0.992, -0.015, +0.123, +0.000}, {+0.000, +0.992, +0.123, +0.000}, {-0.124, -0.122, +0.985, +0.000}, {-0.000, -0.000, -8.124, +1.000}, }, Mat4{ {+1.797, -0.027, +0.223, +0.000}, {+0.000, +2.395, +0.297, +0.000}, {+0.125, +0.123, +7.129, -1.000}, {+0.249, +0.245, -1.980, +0.000}, }, }, } for i, test := range tests { got := Mat4{} got.Mul(&test.m0, &test.m1) if !got.Eq(&test.want, 0.01) { t.Errorf("test #%d:\n%s *\n%s =\n%s, want\n%s", i, test.m0, test.m1, got, test.want) } } } func TestMat4LookAt(t *testing.T) { tests := []struct { eye, center, up Vec3 want Mat4 }{ { Vec3{1, 1, 8}, Vec3{0, 0, 0}, Vec3{0, 1, 0}, Mat4{ {0.992, -0.015, 0.123, 0.000}, {0.000, 0.992, 0.123, 0.000}, {-0.124, -0.122, 0.985, 0.000}, {-0.000, -0.000, -8.124, 1.000}, }, }, { Vec3{4, 5, 7}, Vec3{0.1, 0.2, 0.3}, Vec3{0, -1, 0}, Mat4{ {-0.864, 0.265, 0.428, 0.000}, {0.000, -0.850, 0.526, 0.000}, {0.503, 0.455, 0.735, 0.000}, {-0.064, 0.007, -9.487, 1.000}, }, }, } for _, test := range tests { got := Mat4{} got.LookAt(&test.eye, &test.center, &test.up) if !got.Eq(&test.want, 0.01) { t.Errorf("LookAt(%s,%s%s) =\n%s\nwant\n%s", test.eye, test.center, test.up, got, test.want) } } } func TestMat4Perspective(t *testing.T) { want := Mat4{ {1.811, 0.000, 0.000, 0.000}, {0.000, 2.414, 0.000, 0.000}, {0.000, 0.000, -1.010, -1.000}, {0.000, 0.000, -2.010, 0.000}, } got := Mat4{} got.Perspective(Radian(math.Pi/4), 4.0/3, 1, 200) if !got.Eq(&want, 0.01) { t.Errorf("got\n%s\nwant\n%s", got, want) } } func TestMat4Rotate(t *testing.T) { want := &Mat4{ {2.000, 1.000, -0.000, 3.000}, {6.000, 5.000, -4.000, 7.000}, {10.000, 9.000, -8.000, 11.000}, {14.000, 13.000, -12.000, 15.000}, } got := new(Mat4) got.Rotate(&x4, Radian(math.Pi/2), &Vec3{0, 1, 0}) if !got.Eq(want, 0.01) { t.Errorf("got\n%s\nwant\n%s", got, want) } } func TestMat4Scale(t *testing.T) { want := &Mat4{ {0 * 2, 1 * 3, 2 * 4, 3 * 1}, {4 * 2, 5 * 3, 6 * 4, 7 * 1}, {8 * 2, 9 * 3, 10 * 4, 11 * 1}, {12 * 2, 13 * 3, 14 * 4, 15 * 1}, } got := new(Mat4) got.Scale(&x4, 2, 3, 4) if !got.Eq(want, 0.01) { t.Errorf("got\n%s\nwant\n%s", got, want) } } func TestMat4Translate(t *testing.T) { want := &Mat4{ {0, 1, 2, 0*0.1 + 1*0.2 + 2*0.3 + 3*1}, {4, 5, 6, 4*0.1 + 5*0.2 + 6*0.3 + 7*1}, {8, 9, 10, 8*0.1 + 9*0.2 + 10*0.3 + 11*1}, {12, 13, 14, 12*0.1 + 13*0.2 + 14*0.3 + 15*1}, } got := new(Mat4) got.Translate(&x4, 0.1, 0.2, 0.3) if !got.Eq(want, 0.01) { t.Errorf("got\n%s\nwant\n%s", got, want) } } func testTrig(t *testing.T, gotFunc func(float32) float32, wantFunc func(float64) float64) { nBad := 0 for a := float32(-9); a < +9; a += .01 { got := gotFunc(a) want := float32(wantFunc(float64(a))) diff := got - want if diff < 0 { diff = -diff } if diff > 0.001 { if nBad++; nBad == 10 { t.Errorf("too many failures") break } t.Errorf("a=%+.2f: got %+.4f, want %+.4f, diff=%.4f", a, got, want, diff) } } } func TestCos(t *testing.T) { testTrig(t, Cos, math.Cos) } func TestSin(t *testing.T) { testTrig(t, Sin, math.Sin) } func TestTan(t *testing.T) { testTrig(t, Tan, math.Tan) } func BenchmarkSin(b *testing.B) { for i := 0; i < b.N; i++ { for a := 0; a < 3141; a++ { Sin(float32(a) / 1000) } } } func TestBytes(t *testing.T) { testCases := []struct { byteOrder binary.ByteOrder want []byte }{{ binary.BigEndian, []byte{ // The IEEE 754 binary32 format is 1 sign bit, 8 exponent bits and 23 fraction bits. 0x00, 0x00, 0x00, 0x00, // float32(+0.00) is 0 0000000_0 0000000_00000000_00000000 0x3f, 0xa0, 0x00, 0x00, // float32(+1.25) is 0 0111111_1 0100000_00000000_00000000 0xc0, 0x00, 0x00, 0x00, // float32(-2.00) is 1 1000000_0 0000000_00000000_00000000 }, }, { binary.LittleEndian, []byte{ 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xa0, 0x3f, 0x00, 0x00, 0x00, 0xc0, }, }} for _, tc := range testCases { got := Bytes(tc.byteOrder, +0.00, +1.25, -2.00) if !bytes.Equal(got, tc.want) { t.Errorf("%v:\ngot % x\nwant % x", tc.byteOrder, got, tc.want) } } }
f32
/home/linuxreitt/Michinereitt/Tuning/Workshop_Scripts/hf-codegen/data/golang_public_repos/mobile/exp/f32/affine_test.go
package f32 import ( "math" "testing" ) var xyTests = []struct { x, y float32 }{ {0, 0}, {1, 1}, {2, 3}, {6.5, 4.3}, } var a = Affine{ {3, 4, 5}, {6, 7, 8}, } func TestInverse(t *testing.T) { wantInv := Affine{ {-2.33333, 1.33333, 1}, {2, -1, -2}, } var gotInv Affine gotInv.Inverse(&a) if !gotInv.Eq(&wantInv, 0.01) { t.Errorf("Inverse: got %s want %s", gotInv, wantInv) } var wantId, gotId Affine wantId.Identity() gotId.Mul(&a, &wantInv) if !gotId.Eq(&wantId, 0.01) { t.Errorf("Identity #0: got %s want %s", gotId, wantId) } gotId.Mul(&wantInv, &a) if !gotId.Eq(&wantId, 0.01) { t.Errorf("Identity #1: got %s want %s", gotId, wantId) } } func TestAffineScale(t *testing.T) { for _, test := range xyTests { want := a want.Mul(&want, &Affine{{test.x, 0, 0}, {0, test.y, 0}}) got := a got.Scale(&got, test.x, test.y) if !got.Eq(&want, 0.01) { t.Errorf("(%.2f, %.2f): got %s want %s", test.x, test.y, got, want) } } } func TestAffineTranslate(t *testing.T) { for _, test := range xyTests { want := a want.Mul(&want, &Affine{{1, 0, test.x}, {0, 1, test.y}}) got := a got.Translate(&got, test.x, test.y) if !got.Eq(&want, 0.01) { t.Errorf("(%.2f, %.2f): got %s want %s", test.x, test.y, got, want) } } } func TestAffineRotate(t *testing.T) { want := Affine{ {-4.000, 3.000, 5.000}, {-7.000, 6.000, 8.000}, } got := a got.Rotate(&got, math.Pi/2) if !got.Eq(&want, 0.01) { t.Errorf("rotate π: got %s want %s", got, want) } want = a got = a got.Rotate(&got, 2*math.Pi) if !got.Eq(&want, 0.01) { t.Errorf("rotate 2π: got %s want %s", got, want) } got = a got.Rotate(&got, math.Pi) got.Rotate(&got, math.Pi) if !got.Eq(&want, 0.01) { t.Errorf("rotate π then π: got %s want %s", got, want) } got = a got.Rotate(&got, math.Pi/3) got.Rotate(&got, -math.Pi/3) if !got.Eq(&want, 0.01) { t.Errorf("rotate π/3 then -π/3: got %s want %s", got, want) } } func TestAffineScaleTranslate(t *testing.T) { mulVec := func(m *Affine, v [2]float32) (mv [2]float32) { mv[0] = m[0][0]*v[0] + m[0][1]*v[1] + m[0][2] mv[1] = m[1][0]*v[0] + m[1][1]*v[1] + m[1][2] return mv } v := [2]float32{1, 10} var sThenT Affine sThenT.Identity() sThenT.Scale(&sThenT, 13, 17) sThenT.Translate(&sThenT, 101, 151) wantSTT := [2]float32{ 13 * (101 + 1), 17 * (151 + 10), } if got := mulVec(&sThenT, v); got != wantSTT { t.Errorf("S then T: got %v, want %v", got, wantSTT) } var tThenS Affine tThenS.Identity() tThenS.Translate(&tThenS, 101, 151) tThenS.Scale(&tThenS, 13, 17) wantTTS := [2]float32{ 101 + (13 * 1), 151 + (17 * 10), } if got := mulVec(&tThenS, v); got != wantTTS { t.Errorf("T then S: got %v, want %v", got, wantTTS) } }
f32
/home/linuxreitt/Michinereitt/Tuning/Workshop_Scripts/hf-codegen/data/golang_public_repos/mobile/exp/f32/mat4.go
// Copyright 2014 The Go Authors. All rights reserved. // Use of this source code is governed by a BSD-style // license that can be found in the LICENSE file. package f32 import "fmt" // A Mat4 is a 4x4 matrix of float32 values. // Elements are indexed first by row then column, i.e. m[row][column]. type Mat4 [4]Vec4 func (m Mat4) String() string { return fmt.Sprintf(`Mat4[% 0.3f, % 0.3f, % 0.3f, % 0.3f, % 0.3f, % 0.3f, % 0.3f, % 0.3f, % 0.3f, % 0.3f, % 0.3f, % 0.3f, % 0.3f, % 0.3f, % 0.3f, % 0.3f]`, m[0][0], m[0][1], m[0][2], m[0][3], m[1][0], m[1][1], m[1][2], m[1][3], m[2][0], m[2][1], m[2][2], m[2][3], m[3][0], m[3][1], m[3][2], m[3][3]) } func (m *Mat4) Identity() { *m = Mat4{ {1, 0, 0, 0}, {0, 1, 0, 0}, {0, 0, 1, 0}, {0, 0, 0, 1}, } } func (m *Mat4) Eq(n *Mat4, epsilon float32) bool { for i := range m { for j := range m[i] { diff := m[i][j] - n[i][j] if diff < -epsilon || +epsilon < diff { return false } } } return true } // Mul stores a × b in m. func (m *Mat4) Mul(a, b *Mat4) { // Store the result in local variables, in case m == a || m == b. m00 := a[0][0]*b[0][0] + a[0][1]*b[1][0] + a[0][2]*b[2][0] + a[0][3]*b[3][0] m01 := a[0][0]*b[0][1] + a[0][1]*b[1][1] + a[0][2]*b[2][1] + a[0][3]*b[3][1] m02 := a[0][0]*b[0][2] + a[0][1]*b[1][2] + a[0][2]*b[2][2] + a[0][3]*b[3][2] m03 := a[0][0]*b[0][3] + a[0][1]*b[1][3] + a[0][2]*b[2][3] + a[0][3]*b[3][3] m10 := a[1][0]*b[0][0] + a[1][1]*b[1][0] + a[1][2]*b[2][0] + a[1][3]*b[3][0] m11 := a[1][0]*b[0][1] + a[1][1]*b[1][1] + a[1][2]*b[2][1] + a[1][3]*b[3][1] m12 := a[1][0]*b[0][2] + a[1][1]*b[1][2] + a[1][2]*b[2][2] + a[1][3]*b[3][2] m13 := a[1][0]*b[0][3] + a[1][1]*b[1][3] + a[1][2]*b[2][3] + a[1][3]*b[3][3] m20 := a[2][0]*b[0][0] + a[2][1]*b[1][0] + a[2][2]*b[2][0] + a[2][3]*b[3][0] m21 := a[2][0]*b[0][1] + a[2][1]*b[1][1] + a[2][2]*b[2][1] + a[2][3]*b[3][1] m22 := a[2][0]*b[0][2] + a[2][1]*b[1][2] + a[2][2]*b[2][2] + a[2][3]*b[3][2] m23 := a[2][0]*b[0][3] + a[2][1]*b[1][3] + a[2][2]*b[2][3] + a[2][3]*b[3][3] m30 := a[3][0]*b[0][0] + a[3][1]*b[1][0] + a[3][2]*b[2][0] + a[3][3]*b[3][0] m31 := a[3][0]*b[0][1] + a[3][1]*b[1][1] + a[3][2]*b[2][1] + a[3][3]*b[3][1] m32 := a[3][0]*b[0][2] + a[3][1]*b[1][2] + a[3][2]*b[2][2] + a[3][3]*b[3][2] m33 := a[3][0]*b[0][3] + a[3][1]*b[1][3] + a[3][2]*b[2][3] + a[3][3]*b[3][3] m[0][0] = m00 m[0][1] = m01 m[0][2] = m02 m[0][3] = m03 m[1][0] = m10 m[1][1] = m11 m[1][2] = m12 m[1][3] = m13 m[2][0] = m20 m[2][1] = m21 m[2][2] = m22 m[2][3] = m23 m[3][0] = m30 m[3][1] = m31 m[3][2] = m32 m[3][3] = m33 } // Perspective sets m to be the GL perspective matrix. func (m *Mat4) Perspective(fov Radian, aspect, near, far float32) { t := Tan(float32(fov) / 2) m[0][0] = 1 / (aspect * t) m[1][1] = 1 / t m[2][2] = -(far + near) / (far - near) m[2][3] = -1 m[3][2] = -2 * far * near / (far - near) } // Scale sets m to be a scale followed by p. // It is equivalent to // // m.Mul(p, &Mat4{ // {x, 0, 0, 0}, // {0, y, 0, 0}, // {0, 0, z, 0}, // {0, 0, 0, 1}, // }). func (m *Mat4) Scale(p *Mat4, x, y, z float32) { m[0][0] = p[0][0] * x m[0][1] = p[0][1] * y m[0][2] = p[0][2] * z m[0][3] = p[0][3] m[1][0] = p[1][0] * x m[1][1] = p[1][1] * y m[1][2] = p[1][2] * z m[1][3] = p[1][3] m[2][0] = p[2][0] * x m[2][1] = p[2][1] * y m[2][2] = p[2][2] * z m[2][3] = p[2][3] m[3][0] = p[3][0] * x m[3][1] = p[3][1] * y m[3][2] = p[3][2] * z m[3][3] = p[3][3] } // Translate sets m to be a translation followed by p. // It is equivalent to // // m.Mul(p, &Mat4{ // {1, 0, 0, x}, // {0, 1, 0, y}, // {0, 0, 1, z}, // {0, 0, 0, 1}, // }). func (m *Mat4) Translate(p *Mat4, x, y, z float32) { m[0][0] = p[0][0] m[0][1] = p[0][1] m[0][2] = p[0][2] m[0][3] = p[0][0]*x + p[0][1]*y + p[0][2]*z + p[0][3] m[1][0] = p[1][0] m[1][1] = p[1][1] m[1][2] = p[1][2] m[1][3] = p[1][0]*x + p[1][1]*y + p[1][2]*z + p[1][3] m[2][0] = p[2][0] m[2][1] = p[2][1] m[2][2] = p[2][2] m[2][3] = p[2][0]*x + p[2][1]*y + p[2][2]*z + p[2][3] m[3][0] = p[3][0] m[3][1] = p[3][1] m[3][2] = p[3][2] m[3][3] = p[3][0]*x + p[3][1]*y + p[3][2]*z + p[3][3] } // Rotate sets m to a rotation in radians around a specified axis, followed by p. // It is equivalent to m.Mul(p, affineRotation). func (m *Mat4) Rotate(p *Mat4, angle Radian, axis *Vec3) { a := *axis a.Normalize() c, s := Cos(float32(angle)), Sin(float32(angle)) d := 1 - c m.Mul(p, &Mat4{{ c + d*a[0]*a[1], 0 + d*a[0]*a[1] + s*a[2], 0 + d*a[0]*a[1] - s*a[1], 0, }, { 0 + d*a[1]*a[0] - s*a[2], c + d*a[1]*a[1], 0 + d*a[1]*a[2] + s*a[0], 0, }, { 0 + d*a[2]*a[0] + s*a[1], 0 + d*a[2]*a[1] - s*a[0], c + d*a[2]*a[2], 0, }, { 0, 0, 0, 1, }}) } func (m *Mat4) LookAt(eye, center, up *Vec3) { f, s, u := new(Vec3), new(Vec3), new(Vec3) *f = *center f.Sub(f, eye) f.Normalize() s.Cross(f, up) s.Normalize() u.Cross(s, f) *m = Mat4{ {s[0], u[0], -f[0], 0}, {s[1], u[1], -f[1], 0}, {s[2], u[2], -f[2], 0}, {-s.Dot(eye), -u.Dot(eye), +f.Dot(eye), 1}, } }
f32
/home/linuxreitt/Michinereitt/Tuning/Workshop_Scripts/hf-codegen/data/golang_public_repos/mobile/exp/f32/affine.go
// Copyright 2014 The Go Authors. All rights reserved. // Use of this source code is governed by a BSD-style // license that can be found in the LICENSE file. package f32 import "fmt" // An Affine is a 3x3 matrix of float32 values for which the bottom row is // implicitly always equal to [0 0 1]. // Elements are indexed first by row then column, i.e. m[row][column]. type Affine [2]Vec3 func (m Affine) String() string { return fmt.Sprintf(`Affine[% 0.3f, % 0.3f, % 0.3f, % 0.3f, % 0.3f, % 0.3f]`, m[0][0], m[0][1], m[0][2], m[1][0], m[1][1], m[1][2]) } // Identity sets m to be the identity transform. func (m *Affine) Identity() { *m = Affine{ {1, 0, 0}, {0, 1, 0}, } } // Eq reports whether each component of m is within epsilon of the same // component in n. func (m *Affine) Eq(n *Affine, epsilon float32) bool { for i := range m { for j := range m[i] { diff := m[i][j] - n[i][j] if diff < -epsilon || +epsilon < diff { return false } } } return true } // Mul sets m to be p × q. func (m *Affine) Mul(p, q *Affine) { // Store the result in local variables, in case m == a || m == b. m00 := p[0][0]*q[0][0] + p[0][1]*q[1][0] m01 := p[0][0]*q[0][1] + p[0][1]*q[1][1] m02 := p[0][0]*q[0][2] + p[0][1]*q[1][2] + p[0][2] m10 := p[1][0]*q[0][0] + p[1][1]*q[1][0] m11 := p[1][0]*q[0][1] + p[1][1]*q[1][1] m12 := p[1][0]*q[0][2] + p[1][1]*q[1][2] + p[1][2] m[0][0] = m00 m[0][1] = m01 m[0][2] = m02 m[1][0] = m10 m[1][1] = m11 m[1][2] = m12 } // Inverse sets m to be the inverse of p. func (m *Affine) Inverse(p *Affine) { m00 := p[1][1] m01 := -p[0][1] m02 := p[1][2]*p[0][1] - p[1][1]*p[0][2] m10 := -p[1][0] m11 := p[0][0] m12 := p[1][0]*p[0][2] - p[1][2]*p[0][0] det := m00*m11 - m10*m01 m[0][0] = m00 / det m[0][1] = m01 / det m[0][2] = m02 / det m[1][0] = m10 / det m[1][1] = m11 / det m[1][2] = m12 / det } // Scale sets m to be a scale followed by p. // It is equivalent to m.Mul(p, &Affine{{x,0,0}, {0,y,0}}). func (m *Affine) Scale(p *Affine, x, y float32) { m[0][0] = p[0][0] * x m[0][1] = p[0][1] * y m[0][2] = p[0][2] m[1][0] = p[1][0] * x m[1][1] = p[1][1] * y m[1][2] = p[1][2] } // Translate sets m to be a translation followed by p. // It is equivalent to m.Mul(p, &Affine{{1,0,x}, {0,1,y}}). func (m *Affine) Translate(p *Affine, x, y float32) { m[0][0] = p[0][0] m[0][1] = p[0][1] m[0][2] = p[0][0]*x + p[0][1]*y + p[0][2] m[1][0] = p[1][0] m[1][1] = p[1][1] m[1][2] = p[1][0]*x + p[1][1]*y + p[1][2] } // Rotate sets m to a rotation in radians followed by p. // It is equivalent to m.Mul(p, affineRotation). func (m *Affine) Rotate(p *Affine, radians float32) { s, c := Sin(radians), Cos(radians) m.Mul(p, &Affine{ {+c, +s, 0}, {-s, +c, 0}, }) }
f32
/home/linuxreitt/Michinereitt/Tuning/Workshop_Scripts/hf-codegen/data/golang_public_repos/mobile/exp/f32/f32.go
// Copyright 2014 The Go Authors. All rights reserved. // Use of this source code is governed by a BSD-style // license that can be found in the LICENSE file. //go:generate go run gen.go -output table.go // Package f32 implements some linear algebra and GL helpers for float32s. // // Types defined in this package have methods implementing common // mathematical operations. The common form for these functions is // // func (dst *T) Op(lhs, rhs *T) // // which reads in traditional mathematical notation as // // dst = lhs op rhs. // // It is safe to use the destination address as the left-hand side, // that is, dst *= rhs is dst.Mul(dst, rhs). // // # WARNING // // The interface to this package is not stable. It will change considerably. // Only use functions that provide package documentation. Semantics are // non-obvious. Be prepared for the package name to change. package f32 // import "golang.org/x/mobile/exp/f32" import ( "encoding/binary" "fmt" "math" ) type Radian float32 func Cos(x float32) float32 { const n = sinTableLen i := uint32(int32(x * (n / math.Pi))) i += n / 2 i &= 2*n - 1 if i >= n { return -sinTable[i&(n-1)] } return sinTable[i&(n-1)] } func Sin(x float32) float32 { const n = sinTableLen i := uint32(int32(x * (n / math.Pi))) i &= 2*n - 1 if i >= n { return -sinTable[i&(n-1)] } return sinTable[i&(n-1)] } func Sqrt(x float32) float32 { return float32(math.Sqrt(float64(x))) // TODO(crawshaw): implement } func Tan(x float32) float32 { return float32(math.Tan(float64(x))) // TODO(crawshaw): fast version } // Bytes returns the byte representation of float32 values in the given byte // order. byteOrder must be either binary.BigEndian or binary.LittleEndian. func Bytes(byteOrder binary.ByteOrder, values ...float32) []byte { le := false switch byteOrder { case binary.BigEndian: case binary.LittleEndian: le = true default: panic(fmt.Sprintf("invalid byte order %v", byteOrder)) } b := make([]byte, 4*len(values)) for i, v := range values { u := math.Float32bits(v) if le { b[4*i+0] = byte(u >> 0) b[4*i+1] = byte(u >> 8) b[4*i+2] = byte(u >> 16) b[4*i+3] = byte(u >> 24) } else { b[4*i+0] = byte(u >> 24) b[4*i+1] = byte(u >> 16) b[4*i+2] = byte(u >> 8) b[4*i+3] = byte(u >> 0) } } return b }
f32
/home/linuxreitt/Michinereitt/Tuning/Workshop_Scripts/hf-codegen/data/golang_public_repos/mobile/exp/f32/table.go
// Code generated by go run gen.go; DO NOT EDIT package f32 const sinTableLen = 4096 // sinTable[i] equals sin(i * π / sinTableLen). var sinTable = [sinTableLen]float32{ 0, 0.0007669903, 0.0015339801, 0.002300969, 0.0030679568, 0.0038349426, 0.004601926, 0.005368907, 0.0061358847, 0.0069028586, 0.007669829, 0.008436794, 0.009203754, 0.00997071, 0.010737659, 0.011504602, 0.012271538, 0.013038468, 0.0138053885, 0.014572302, 0.015339206, 0.016106103, 0.016872987, 0.017639864, 0.01840673, 0.019173585, 0.019940428, 0.02070726, 0.02147408, 0.022240888, 0.023007682, 0.023774462, 0.024541229, 0.025307981, 0.026074719, 0.02684144, 0.027608145, 0.028374836, 0.029141508, 0.029908165, 0.030674804, 0.031441424, 0.032208025, 0.03297461, 0.033741172, 0.034507714, 0.035274237, 0.036040742, 0.036807224, 0.037573684, 0.03834012, 0.039106537, 0.039872926, 0.040639296, 0.04140564, 0.042171963, 0.04293826, 0.04370453, 0.044470772, 0.04523699, 0.04600318, 0.046769347, 0.047535483, 0.048301592, 0.049067676, 0.049833726, 0.05059975, 0.05136574, 0.052131705, 0.052897636, 0.053663537, 0.05442941, 0.055195246, 0.05596105, 0.05672682, 0.057492558, 0.058258265, 0.059023935, 0.059789572, 0.06055517, 0.061320737, 0.062086266, 0.06285176, 0.063617215, 0.06438263, 0.06514801, 0.06591335, 0.06667866, 0.06744392, 0.06820914, 0.06897433, 0.06973947, 0.070504576, 0.07126963, 0.07203465, 0.07279963, 0.07356457, 0.07432945, 0.0750943, 0.07585911, 0.076623864, 0.07738858, 0.078153245, 0.07891786, 0.07968244, 0.080446966, 0.08121145, 0.08197588, 0.08274026, 0.0835046, 0.08426889, 0.085033126, 0.08579731, 0.08656145, 0.087325536, 0.08808957, 0.08885355, 0.08961748, 0.09038136, 0.09114519, 0.091908954, 0.092672676, 0.09343634, 0.09419994, 0.0949635, 0.09572699, 0.09649043, 0.097253814, 0.09801714, 0.09878041, 0.099543616, 0.10030677, 0.10106986, 0.1018329, 0.102595866, 0.10335878, 0.10412163, 0.10488442, 0.105647154, 0.10640982, 0.10717242, 0.10793497, 0.108697444, 0.109459855, 0.110222206, 0.11098449, 0.11174671, 0.11250886, 0.11327095, 0.11403298, 0.114794925, 0.115556814, 0.11631863, 0.11708038, 0.11784206, 0.11860368, 0.119365215, 0.12012669, 0.120888084, 0.121649414, 0.12241068, 0.12317186, 0.12393297, 0.12469402, 0.12545498, 0.12621588, 0.1269767, 0.12773745, 0.1284981, 0.1292587, 0.13001922, 0.13077967, 0.13154003, 0.13230032, 0.13306053, 0.13382065, 0.1345807, 0.13534068, 0.13610058, 0.13686039, 0.13762012, 0.13837977, 0.13913934, 0.13989884, 0.14065824, 0.14141756, 0.1421768, 0.14293596, 0.14369503, 0.14445402, 0.14521292, 0.14597175, 0.14673047, 0.14748912, 0.14824767, 0.14900614, 0.14976454, 0.15052283, 0.15128104, 0.15203916, 0.15279719, 0.15355512, 0.15431297, 0.15507074, 0.1558284, 0.15658598, 0.15734346, 0.15810084, 0.15885815, 0.15961535, 0.16037245, 0.16112947, 0.1618864, 0.16264322, 0.16339995, 0.16415659, 0.16491312, 0.16566956, 0.1664259, 0.16718215, 0.16793829, 0.16869435, 0.1694503, 0.17020614, 0.17096189, 0.17171754, 0.17247309, 0.17322853, 0.17398387, 0.17473911, 0.17549425, 0.1762493, 0.17700422, 0.17775905, 0.17851377, 0.17926839, 0.1800229, 0.18077731, 0.18153161, 0.1822858, 0.18303989, 0.18379387, 0.18454774, 0.1853015, 0.18605515, 0.18680869, 0.18756212, 0.18831545, 0.18906866, 0.18982176, 0.19057475, 0.19132763, 0.1920804, 0.19283305, 0.19358559, 0.19433801, 0.19509032, 0.19584252, 0.1965946, 0.19734657, 0.1980984, 0.19885014, 0.19960175, 0.20035325, 0.20110464, 0.2018559, 0.20260704, 0.20335807, 0.20410897, 0.20485975, 0.20561041, 0.20636095, 0.20711137, 0.20786168, 0.20861185, 0.20936191, 0.21011184, 0.21086164, 0.21161133, 0.21236089, 0.21311031, 0.21385963, 0.21460882, 0.21535787, 0.2161068, 0.2168556, 0.21760428, 0.21835282, 0.21910124, 0.21984953, 0.22059768, 0.22134572, 0.22209363, 0.2228414, 0.22358903, 0.22433653, 0.22508392, 0.22583115, 0.22657827, 0.22732525, 0.22807208, 0.22881879, 0.22956537, 0.23031181, 0.2310581, 0.23180428, 0.23255031, 0.2332962, 0.23404196, 0.23478758, 0.23553306, 0.2362784, 0.2370236, 0.23776866, 0.23851359, 0.23925838, 0.24000302, 0.24074753, 0.24149188, 0.24223611, 0.24298018, 0.24372411, 0.2444679, 0.24521154, 0.24595505, 0.24669841, 0.24744162, 0.24818468, 0.24892761, 0.24967039, 0.250413, 0.2511555, 0.2518978, 0.25264, 0.25338203, 0.25412393, 0.25486565, 0.25560725, 0.25634867, 0.25708997, 0.2578311, 0.25857207, 0.25931293, 0.2600536, 0.2607941, 0.26153448, 0.2622747, 0.26301476, 0.26375467, 0.26449442, 0.26523402, 0.26597348, 0.26671275, 0.26745188, 0.26819086, 0.26892966, 0.2696683, 0.2704068, 0.27114516, 0.27188334, 0.27262136, 0.2733592, 0.2740969, 0.27483445, 0.27557182, 0.27630904, 0.27704608, 0.27778298, 0.2785197, 0.27925625, 0.27999264, 0.28072888, 0.28146493, 0.28220084, 0.28293657, 0.28367212, 0.28440753, 0.28514278, 0.28587782, 0.28661272, 0.28734747, 0.28808203, 0.28881642, 0.28955063, 0.29028466, 0.29101855, 0.29175225, 0.2924858, 0.29321915, 0.29395235, 0.29468536, 0.2954182, 0.2961509, 0.29688337, 0.2976157, 0.29834786, 0.29907984, 0.29981163, 0.30054325, 0.3012747, 0.30200595, 0.30273703, 0.30346796, 0.30419868, 0.30492923, 0.3056596, 0.3063898, 0.30711982, 0.30784965, 0.3085793, 0.30930877, 0.31003806, 0.31076714, 0.31149608, 0.3122248, 0.31295338, 0.31368175, 0.31440994, 0.31513792, 0.31586576, 0.31659338, 0.31732082, 0.3180481, 0.31877515, 0.31950203, 0.32022873, 0.32095525, 0.32168156, 0.3224077, 0.32313362, 0.32385936, 0.32458493, 0.3253103, 0.32603547, 0.32676044, 0.32748523, 0.32820985, 0.32893425, 0.32965845, 0.3303825, 0.3311063, 0.33182994, 0.33255336, 0.3332766, 0.33399966, 0.3347225, 0.33544514, 0.3361676, 0.33688986, 0.3376119, 0.33833376, 0.33905542, 0.33977687, 0.34049815, 0.34121922, 0.34194008, 0.34266073, 0.34338117, 0.34410143, 0.34482148, 0.34554133, 0.34626096, 0.34698042, 0.34769964, 0.34841868, 0.3491375, 0.34985614, 0.35057455, 0.35129276, 0.35201076, 0.35272855, 0.35344616, 0.35416353, 0.3548807, 0.35559767, 0.35631442, 0.35703096, 0.3577473, 0.3584634, 0.35917935, 0.35989505, 0.3606105, 0.3613258, 0.36204088, 0.36275572, 0.36347038, 0.3641848, 0.364899, 0.36561298, 0.36632678, 0.36704034, 0.36775368, 0.36846682, 0.36917976, 0.36989245, 0.37060493, 0.3713172, 0.37202924, 0.37274107, 0.37345266, 0.37416407, 0.37487522, 0.37558618, 0.3762969, 0.37700742, 0.3777177, 0.37842774, 0.3791376, 0.3798472, 0.3805566, 0.38126576, 0.38197473, 0.38268343, 0.38339192, 0.3841002, 0.38480824, 0.38551605, 0.38622364, 0.386931, 0.38763815, 0.38834503, 0.38905174, 0.38975817, 0.3904644, 0.39117038, 0.39187613, 0.39258167, 0.39328697, 0.39399204, 0.39469686, 0.39540148, 0.39610586, 0.39681, 0.3975139, 0.39821756, 0.398921, 0.3996242, 0.40032718, 0.40102988, 0.4017324, 0.40243465, 0.40313667, 0.40383846, 0.40454, 0.4052413, 0.40594238, 0.4066432, 0.4073438, 0.40804416, 0.40874428, 0.40944415, 0.4101438, 0.41084316, 0.41154233, 0.41224122, 0.41293988, 0.41363832, 0.4143365, 0.4150344, 0.41573212, 0.41642955, 0.41712677, 0.4178237, 0.41852042, 0.4192169, 0.4199131, 0.4206091, 0.4213048, 0.42200026, 0.4226955, 0.42339048, 0.4240852, 0.42477968, 0.4254739, 0.42616788, 0.4268616, 0.42755508, 0.42824832, 0.42894128, 0.429634, 0.4303265, 0.4310187, 0.43171066, 0.43240237, 0.43309382, 0.43378502, 0.43447596, 0.43516666, 0.4358571, 0.43654725, 0.43723717, 0.43792683, 0.43861625, 0.4393054, 0.43999428, 0.4406829, 0.44137126, 0.44205937, 0.44274724, 0.4434348, 0.44412214, 0.4448092, 0.44549602, 0.44618255, 0.44686884, 0.44755486, 0.4482406, 0.4489261, 0.44961134, 0.45029628, 0.450981, 0.45166543, 0.45234957, 0.45303348, 0.4537171, 0.45440048, 0.45508358, 0.4557664, 0.45644897, 0.45713127, 0.4578133, 0.45849505, 0.45917654, 0.45985776, 0.46053872, 0.4612194, 0.4618998, 0.46257994, 0.4632598, 0.46393937, 0.46461868, 0.46529773, 0.4659765, 0.466655, 0.4673332, 0.46801114, 0.46868882, 0.46936622, 0.47004333, 0.47072017, 0.47139674, 0.47207302, 0.47274902, 0.47342476, 0.4741002, 0.47477537, 0.47545028, 0.47612488, 0.47679922, 0.4774733, 0.47814706, 0.47882056, 0.47949377, 0.48016667, 0.48083934, 0.48151168, 0.48218378, 0.48285556, 0.48352706, 0.4841983, 0.48486924, 0.4855399, 0.4862103, 0.48688036, 0.48755017, 0.48821968, 0.4888889, 0.48955783, 0.49022648, 0.49089485, 0.4915629, 0.4922307, 0.4928982, 0.4935654, 0.4942323, 0.49489895, 0.49556527, 0.4962313, 0.49689704, 0.4975625, 0.49822766, 0.49889255, 0.4995571, 0.5002214, 0.50088537, 0.50154907, 0.50221246, 0.50287557, 0.50353837, 0.5042009, 0.5048631, 0.50552505, 0.50618666, 0.506848, 0.507509, 0.5081697, 0.50883013, 0.50949025, 0.5101501, 0.5108096, 0.5114688, 0.51212776, 0.5127864, 0.5134447, 0.51410276, 0.51476043, 0.5154179, 0.516075, 0.5167318, 0.5173883, 0.51804453, 0.5187004, 0.519356, 0.52001125, 0.52066624, 0.52132094, 0.5219753, 0.5226294, 0.5232831, 0.52393657, 0.52458966, 0.5252425, 0.525895, 0.52654725, 0.52719915, 0.52785075, 0.528502, 0.529153, 0.52980363, 0.530454, 0.531104, 0.5317537, 0.5324031, 0.5330522, 0.533701, 0.53434944, 0.53499764, 0.5356455, 0.53629297, 0.53694016, 0.53758705, 0.53823364, 0.53887993, 0.53952587, 0.54017144, 0.5408168, 0.54146177, 0.54210645, 0.5427508, 0.5433948, 0.54403853, 0.5446819, 0.545325, 0.54596776, 0.5466102, 0.5472523, 0.54789406, 0.5485355, 0.54917663, 0.5498175, 0.55045795, 0.55109817, 0.55173796, 0.5523775, 0.5530167, 0.55365556, 0.5542941, 0.55493236, 0.55557024, 0.5562078, 0.556845, 0.55748194, 0.5581185, 0.5587548, 0.5593907, 0.5600263, 0.56066155, 0.5612965, 0.56193113, 0.5625654, 0.56319934, 0.56383294, 0.56446624, 0.5650992, 0.5657318, 0.5663641, 0.56699604, 0.56762767, 0.56825894, 0.5688899, 0.56952053, 0.5701508, 0.57078075, 0.57141036, 0.5720396, 0.57266855, 0.57329714, 0.57392544, 0.5745534, 0.57518095, 0.57580817, 0.5764351, 0.57706165, 0.5776879, 0.57831377, 0.5789393, 0.5795646, 0.5801894, 0.58081394, 0.5814381, 0.582062, 0.5826855, 0.58330864, 0.58393145, 0.58455396, 0.58517605, 0.58579785, 0.5864193, 0.58704036, 0.58766115, 0.5882816, 0.5889016, 0.5895213, 0.5901407, 0.5907597, 0.5913784, 0.59199667, 0.59261465, 0.5932323, 0.5938496, 0.5944665, 0.59508306, 0.5956993, 0.5963152, 0.5969307, 0.59754586, 0.5981607, 0.5987752, 0.5993893, 0.60000306, 0.60061646, 0.60122955, 0.6018422, 0.6024546, 0.6030666, 0.6036782, 0.60428953, 0.6049005, 0.60551107, 0.60612124, 0.6067311, 0.60734063, 0.6079498, 0.6085586, 0.60916704, 0.60977507, 0.6103828, 0.61099017, 0.6115972, 0.6122038, 0.6128101, 0.613416, 0.61402154, 0.61462677, 0.6152316, 0.6158361, 0.6164402, 0.6170439, 0.6176473, 0.6182503, 0.618853, 0.6194553, 0.6200572, 0.62065876, 0.62126, 0.6218608, 0.62246126, 0.62306136, 0.6236611, 0.6242605, 0.6248595, 0.6254581, 0.6260564, 0.62665427, 0.6272518, 0.627849, 0.62844574, 0.6290422, 0.62963825, 0.63023394, 0.6308292, 0.6314242, 0.63201874, 0.63261294, 0.6332068, 0.6338002, 0.6343933, 0.634986, 0.63557833, 0.63617027, 0.63676184, 0.63735306, 0.6379439, 0.63853437, 0.63912445, 0.6397142, 0.6403035, 0.64089245, 0.64148104, 0.6420692, 0.64265704, 0.6432445, 0.64383155, 0.64441824, 0.6450045, 0.6455905, 0.64617604, 0.6467612, 0.64734596, 0.6479304, 0.6485144, 0.64909804, 0.6496813, 0.6502642, 0.65084666, 0.6514288, 0.65201056, 0.6525919, 0.65317285, 0.6537534, 0.6543336, 0.6549134, 0.65549284, 0.6560719, 0.65665054, 0.6572288, 0.6578067, 0.6583842, 0.6589613, 0.65953803, 0.66011435, 0.6606903, 0.66126585, 0.661841, 0.6624158, 0.66299015, 0.66356415, 0.6641378, 0.664711, 0.6652838, 0.66585624, 0.66642827, 0.66699994, 0.6675712, 0.668142, 0.6687125, 0.6692826, 0.66985226, 0.67042154, 0.67099047, 0.671559, 0.67212707, 0.67269474, 0.67326206, 0.673829, 0.6743955, 0.6749616, 0.6755274, 0.6760927, 0.6766576, 0.6772222, 0.6777863, 0.67835003, 0.67891335, 0.6794763, 0.68003887, 0.680601, 0.6811627, 0.6817241, 0.682285, 0.68284553, 0.6834057, 0.6839654, 0.6845247, 0.6850837, 0.6856422, 0.6862003, 0.68675804, 0.68731534, 0.68787223, 0.68842876, 0.6889849, 0.68954057, 0.69009584, 0.6906507, 0.6912052, 0.6917592, 0.6923129, 0.69286615, 0.69341904, 0.69397146, 0.6945235, 0.6950751, 0.6956263, 0.6961771, 0.6967275, 0.6972775, 0.6978271, 0.69837624, 0.698925, 0.6994733, 0.70002127, 0.7005688, 0.7011159, 0.7016626, 0.7022089, 0.70275474, 0.7033002, 0.70384526, 0.70438987, 0.70493406, 0.7054779, 0.70602125, 0.70656425, 0.70710677, 0.70764893, 0.7081906, 0.70873195, 0.7092728, 0.7098133, 0.7103534, 0.710893, 0.7114322, 0.711971, 0.7125094, 0.7130473, 0.71358484, 0.714122, 0.7146587, 0.71519494, 0.71573085, 0.7162663, 0.7168013, 0.7173359, 0.71787006, 0.7184038, 0.7189371, 0.71947, 0.72000253, 0.72053456, 0.7210662, 0.72159743, 0.7221282, 0.7226586, 0.72318846, 0.723718, 0.7242471, 0.72477573, 0.72530395, 0.7258318, 0.7263591, 0.7268861, 0.72741264, 0.7279387, 0.72846437, 0.7289896, 0.7295144, 0.7300388, 0.73056275, 0.7310863, 0.7316094, 0.732132, 0.7326543, 0.73317605, 0.7336974, 0.73421836, 0.7347389, 0.73525894, 0.73577857, 0.7362978, 0.7368166, 0.7373349, 0.7378528, 0.7383703, 0.7388873, 0.7394039, 0.7399201, 0.74043584, 0.7409511, 0.741466, 0.74198043, 0.7424944, 0.74300796, 0.7435211, 0.74403375, 0.744546, 0.74505776, 0.74556917, 0.7460801, 0.74659055, 0.7471006, 0.7476102, 0.74811935, 0.7486281, 0.7491364, 0.7496442, 0.75015163, 0.75065863, 0.75116515, 0.7516712, 0.7521768, 0.75268203, 0.7531868, 0.75369114, 0.754195, 0.7546984, 0.7552014, 0.7557039, 0.756206, 0.75670767, 0.7572088, 0.7577096, 0.7582099, 0.7587098, 0.7592092, 0.75970817, 0.7602067, 0.76070476, 0.7612024, 0.76169956, 0.7621963, 0.7626926, 0.7631884, 0.7636838, 0.76417875, 0.76467323, 0.76516724, 0.7656609, 0.766154, 0.7666467, 0.7671389, 0.7676307, 0.768122, 0.7686129, 0.76910335, 0.7695933, 0.77008283, 0.7705719, 0.7710605, 0.7715487, 0.7720364, 0.77252364, 0.77301043, 0.7734968, 0.7739827, 0.7744681, 0.7749531, 0.77543765, 0.7759217, 0.77640533, 0.7768885, 0.77737117, 0.7778534, 0.7783352, 0.7788165, 0.77929735, 0.77977777, 0.78025776, 0.7807372, 0.78121626, 0.7816948, 0.7821729, 0.7826506, 0.7831278, 0.7836045, 0.7840808, 0.78455657, 0.7850319, 0.78550684, 0.78598124, 0.7864552, 0.7869287, 0.78740174, 0.78787434, 0.7883464, 0.78881806, 0.78928924, 0.78976, 0.7902302, 0.7907, 0.79116935, 0.7916382, 0.79210657, 0.7925745, 0.79304194, 0.79350895, 0.7939755, 0.7944415, 0.79490715, 0.79537225, 0.7958369, 0.79630107, 0.7967648, 0.79722804, 0.79769087, 0.79815316, 0.798615, 0.7990764, 0.79953724, 0.7999977, 0.80045766, 0.80091715, 0.80137616, 0.8018347, 0.8022928, 0.8027504, 0.8032075, 0.8036642, 0.80412036, 0.8045761, 0.80503136, 0.8054861, 0.8059404, 0.8063942, 0.8068476, 0.80730045, 0.80775285, 0.8082047, 0.80865616, 0.8091071, 0.8095576, 0.81000763, 0.81045717, 0.81090623, 0.8113549, 0.811803, 0.8122506, 0.81269777, 0.8131444, 0.8135906, 0.8140363, 0.81448156, 0.8149263, 0.8153706, 0.81581444, 0.8162577, 0.8167006, 0.8171429, 0.8175848, 0.8180262, 0.81846714, 0.81890756, 0.8193475, 0.81978697, 0.82022595, 0.82066447, 0.8211025, 0.82154006, 0.82197714, 0.8224137, 0.8228498, 0.8232854, 0.8237205, 0.82415515, 0.8245893, 0.825023, 0.82545614, 0.8258889, 0.82632107, 0.8267528, 0.827184, 0.8276148, 0.82804507, 0.8284748, 0.8289041, 0.82933295, 0.8297612, 0.83018905, 0.8306164, 0.83104324, 0.8314696, 0.8318955, 0.83232087, 0.8327458, 0.8331702, 0.8335941, 0.8340175, 0.8344404, 0.8348629, 0.8352848, 0.8357063, 0.8361273, 0.83654773, 0.8369677, 0.8373872, 0.8378062, 0.8382247, 0.8386427, 0.83906025, 0.83947724, 0.8398938, 0.84030986, 0.84072536, 0.84114045, 0.841555, 0.841969, 0.8423826, 0.84279567, 0.84320825, 0.8436203, 0.8440319, 0.84444296, 0.8448536, 0.84526366, 0.84567326, 0.8460823, 0.8464909, 0.84689903, 0.8473066, 0.84771377, 0.84812033, 0.8485265, 0.848932, 0.84933716, 0.84974176, 0.8501459, 0.85054946, 0.85095257, 0.8513552, 0.8517573, 0.8521589, 0.85256, 0.8529606, 0.8533607, 0.8537603, 0.8541594, 0.854558, 0.8549561, 0.85535365, 0.85575074, 0.85614735, 0.8565434, 0.85693896, 0.857334, 0.8577286, 0.85812265, 0.8585162, 0.85890925, 0.8593018, 0.8596939, 0.86008537, 0.86047643, 0.86086696, 0.86125696, 0.8616465, 0.86203545, 0.86242396, 0.8628119, 0.8631994, 0.86358637, 0.86397284, 0.8643588, 0.86474425, 0.8651292, 0.8655136, 0.86589754, 0.866281, 0.8666639, 0.86704624, 0.8674281, 0.8678095, 0.86819035, 0.8685707, 0.86895055, 0.86932987, 0.86970866, 0.87008697, 0.8704648, 0.87084204, 0.87121886, 0.8715951, 0.87197083, 0.87234604, 0.8727208, 0.873095, 0.8734687, 0.8738418, 0.87421453, 0.87458664, 0.8749583, 0.8753294, 0.8757, 0.8760701, 0.8764397, 0.8768087, 0.87717724, 0.8775453, 0.8779128, 0.8782798, 0.87864625, 0.8790122, 0.87937766, 0.8797426, 0.880107, 0.8804709, 0.8808343, 0.8811971, 0.88155943, 0.8819213, 0.88228256, 0.88264334, 0.8830036, 0.88336337, 0.88372254, 0.88408124, 0.88443947, 0.8847971, 0.88515425, 0.88551086, 0.88586694, 0.88622254, 0.8865776, 0.88693213, 0.8872861, 0.88763964, 0.88799256, 0.88834506, 0.88869697, 0.88904834, 0.88939923, 0.8897496, 0.8900994, 0.89044875, 0.8907975, 0.89114577, 0.8914935, 0.8918407, 0.8921874, 0.89253354, 0.8928792, 0.8932243, 0.8935689, 0.893913, 0.8942565, 0.8945995, 0.894942, 0.89528394, 0.89562535, 0.89596623, 0.89630663, 0.8966465, 0.89698577, 0.89732456, 0.8976628, 0.8980006, 0.8983378, 0.8986745, 0.8990106, 0.89934623, 0.8996813, 0.9000159, 0.9003499, 0.9006834, 0.9010164, 0.9013488, 0.90168077, 0.90201217, 0.902343, 0.9026733, 0.9030031, 0.90333235, 0.9036611, 0.9039893, 0.90431696, 0.9046441, 0.9049707, 0.90529674, 0.9056223, 0.90594727, 0.90627176, 0.9065957, 0.9069191, 0.907242, 0.90756434, 0.9078861, 0.90820736, 0.9085281, 0.90884835, 0.909168, 0.9094871, 0.9098057, 0.91012377, 0.9104413, 0.91075826, 0.91107476, 0.91139066, 0.91170603, 0.91202086, 0.91233516, 0.912649, 0.9129622, 0.9132749, 0.91358703, 0.91389865, 0.9142098, 0.9145203, 0.9148303, 0.9151398, 0.9154487, 0.9157571, 0.916065, 0.9163723, 0.9166791, 0.9169853, 0.917291, 0.91759616, 0.9179008, 0.91820484, 0.9185084, 0.9188114, 0.9191139, 0.9194158, 0.91971713, 0.92001796, 0.9203183, 0.92061806, 0.9209172, 0.9212159, 0.92151403, 0.92181164, 0.92210865, 0.9224052, 0.9227011, 0.9229965, 0.92329144, 0.9235858, 0.9238795, 0.92417276, 0.9244655, 0.9247576, 0.92504925, 0.9253403, 0.9256308, 0.9259208, 0.9262102, 0.9264991, 0.9267875, 0.92707527, 0.9273625, 0.92764926, 0.9279354, 0.928221, 0.9285061, 0.9287906, 0.9290746, 0.929358, 0.9296409, 0.92992324, 0.93020505, 0.93048626, 0.93076694, 0.9310471, 0.9313267, 0.93160576, 0.9318843, 0.9321622, 0.9324396, 0.9327165, 0.9329928, 0.93326855, 0.9335438, 0.93381846, 0.9340925, 0.9343661, 0.93463916, 0.9349116, 0.9351835, 0.93545485, 0.9357257, 0.93599594, 0.93626565, 0.9365348, 0.93680346, 0.9370715, 0.937339, 0.937606, 0.93787235, 0.93813825, 0.93840355, 0.9386683, 0.9389325, 0.9391961, 0.9394592, 0.93972176, 0.9399837, 0.9402452, 0.94050604, 0.9407664, 0.94102615, 0.9412854, 0.94154406, 0.9418022, 0.94205976, 0.9423168, 0.9425732, 0.9428291, 0.9430844, 0.9433392, 0.94359344, 0.9438471, 0.94410026, 0.9443528, 0.9446048, 0.9448563, 0.9451072, 0.94535756, 0.9456073, 0.9458566, 0.94610524, 0.9463534, 0.9466009, 0.9468479, 0.9470944, 0.94734025, 0.9475856, 0.9478304, 0.9480746, 0.94831824, 0.9485614, 0.9488039, 0.9490459, 0.9492873, 0.94952816, 0.9497685, 0.9500083, 0.95024747, 0.95048606, 0.9507241, 0.95096165, 0.95119864, 0.951435, 0.9516709, 0.95190614, 0.95214087, 0.952375, 0.9526086, 0.95284164, 0.9530741, 0.953306, 0.9535374, 0.9537682, 0.95399845, 0.9542281, 0.9544572, 0.95468575, 0.95491374, 0.9551412, 0.95536804, 0.95559436, 0.9558201, 0.95604527, 0.95626986, 0.9564939, 0.95671743, 0.95694035, 0.9571627, 0.9573845, 0.9576057, 0.95782644, 0.9580465, 0.9582661, 0.95848507, 0.95870346, 0.9589213, 0.95913863, 0.95935535, 0.95957154, 0.95978713, 0.9600021, 0.96021664, 0.9604305, 0.9606439, 0.9608566, 0.96106887, 0.96128047, 0.9614916, 0.96170205, 0.96191204, 0.9621214, 0.9623302, 0.9625385, 0.96274614, 0.96295327, 0.9631598, 0.9633658, 0.9635712, 0.96377605, 0.9639804, 0.96418405, 0.96438724, 0.9645898, 0.96479183, 0.96499324, 0.9651941, 0.96539444, 0.9655942, 0.9657934, 0.965992, 0.96619, 0.96638745, 0.9665844, 0.9667807, 0.96697646, 0.96717167, 0.9673663, 0.96756035, 0.9677538, 0.96794677, 0.9681391, 0.96833086, 0.9685221, 0.96871275, 0.9689028, 0.9690923, 0.96928126, 0.9694696, 0.96965736, 0.9698446, 0.97003126, 0.97021735, 0.97040284, 0.9705878, 0.97077215, 0.9709559, 0.97113913, 0.9713218, 0.9715039, 0.9716854, 0.9718663, 0.97204673, 0.9722265, 0.97240573, 0.97258437, 0.97276247, 0.97293997, 0.9731169, 0.97329324, 0.973469, 0.97364426, 0.9738189, 0.97399294, 0.97416645, 0.97433937, 0.97451174, 0.9746835, 0.9748547, 0.97502536, 0.9751954, 0.97536486, 0.9755338, 0.9757021, 0.9758699, 0.9760371, 0.9762037, 0.97636974, 0.9765352, 0.97670007, 0.9768644, 0.97702813, 0.9771913, 0.9773539, 0.97751594, 0.97767735, 0.9778382, 0.9779985, 0.97815824, 0.9783174, 0.9784759, 0.97863394, 0.97879136, 0.9789482, 0.97910446, 0.97926015, 0.97941524, 0.9795698, 0.97972375, 0.9798771, 0.9800299, 0.9801821, 0.9803338, 0.98048484, 0.98063534, 0.98078525, 0.9809346, 0.9810834, 0.9812316, 0.9813792, 0.98152626, 0.9816727, 0.98181856, 0.9819639, 0.9821086, 0.9822527, 0.9823963, 0.9825393, 0.9826817, 0.98282355, 0.9829648, 0.9831055, 0.9832456, 0.9833851, 0.983524, 0.9836624, 0.98380023, 0.98393744, 0.98407406, 0.9842101, 0.98434556, 0.98448044, 0.9846148, 0.9847485, 0.98488164, 0.98501426, 0.9851462, 0.98527765, 0.9854085, 0.9855387, 0.9856684, 0.9857975, 0.98592603, 0.98605394, 0.9861813, 0.9863081, 0.9864343, 0.9865599, 0.9866849, 0.9868094, 0.9869333, 0.98705655, 0.9871793, 0.9873014, 0.98742294, 0.98754394, 0.98766434, 0.98778415, 0.98790336, 0.988022, 0.9881401, 0.9882576, 0.9883745, 0.9884908, 0.9886065, 0.98872167, 0.9888363, 0.98895025, 0.9890637, 0.9891765, 0.98928875, 0.98940045, 0.9895115, 0.989622, 0.98973197, 0.9898413, 0.98995006, 0.9900582, 0.9901658, 0.9902728, 0.9903792, 0.9904851, 0.99059033, 0.990695, 0.9907991, 0.99090266, 0.99100554, 0.99110794, 0.9912097, 0.99131083, 0.99141145, 0.99151146, 0.9916109, 0.99170977, 0.991808, 0.9919057, 0.9920028, 0.9920993, 0.99219525, 0.9922906, 0.9923853, 0.99247956, 0.99257314, 0.9926661, 0.9927586, 0.9928504, 0.9929417, 0.99303234, 0.99312246, 0.9932119, 0.99330086, 0.9933892, 0.993477, 0.9935641, 0.99365073, 0.99373674, 0.99382216, 0.993907, 0.9939912, 0.9940749, 0.99415797, 0.99424046, 0.99432236, 0.99440366, 0.9944844, 0.9945646, 0.99464417, 0.99472314, 0.9948015, 0.9948793, 0.99495655, 0.9950332, 0.99510926, 0.9951847, 0.9952596, 0.9953339, 0.99540764, 0.9954808, 0.9955533, 0.99562526, 0.9956966, 0.9957674, 0.9958376, 0.99590725, 0.99597627, 0.9960447, 0.9961126, 0.9961798, 0.9962465, 0.9963126, 0.9963781, 0.99644303, 0.9965074, 0.9965711, 0.9966343, 0.9966969, 0.9967589, 0.9968203, 0.9968811, 0.9969413, 0.997001, 0.99706006, 0.99711853, 0.9971764, 0.99723375, 0.99729043, 0.9973466, 0.99740213, 0.9974571, 0.99751145, 0.9975652, 0.99761844, 0.99767107, 0.99772304, 0.9977745, 0.9978253, 0.99787563, 0.9979253, 0.9979744, 0.99802285, 0.9980708, 0.9981181, 0.99816483, 0.998211, 0.99825656, 0.99830157, 0.9983459, 0.9983897, 0.99843293, 0.99847555, 0.99851763, 0.99855906, 0.99859995, 0.99864024, 0.99867994, 0.99871904, 0.99875754, 0.99879545, 0.9988328, 0.99886954, 0.9989057, 0.9989413, 0.9989763, 0.9990107, 0.9990445, 0.99907774, 0.99911034, 0.9991424, 0.9991739, 0.99920475, 0.99923503, 0.9992648, 0.99929386, 0.99932235, 0.9993503, 0.99937767, 0.99940443, 0.9994306, 0.99945617, 0.9994812, 0.9995056, 0.9995294, 0.99955267, 0.9995753, 0.9995974, 0.9996188, 0.9996397, 0.99966, 0.9996797, 0.9996988, 0.99971735, 0.9997353, 0.99975264, 0.9997694, 0.9997856, 0.99980116, 0.9998162, 0.9998306, 0.99984443, 0.99985766, 0.9998703, 0.99988234, 0.99989384, 0.9999047, 0.999915, 0.9999247, 0.99993384, 0.99994236, 0.9999503, 0.9999576, 0.9999644, 0.9999706, 0.99997616, 0.99998116, 0.9999856, 0.9999894, 0.99999267, 0.9999953, 0.9999974, 0.9999988, 0.9999997, 1, 0.9999997, 0.9999988, 0.9999974, 0.9999953, 0.99999267, 0.9999894, 0.9999856, 0.99998116, 0.99997616, 0.9999706, 0.9999644, 0.9999576, 0.9999503, 0.99994236, 0.99993384, 0.9999247, 0.999915, 0.9999047, 0.99989384, 0.99988234, 0.9998703, 0.99985766, 0.99984443, 0.9998306, 0.9998162, 0.99980116, 0.9997856, 0.9997694, 0.99975264, 0.9997353, 0.99971735, 0.9996988, 0.9996797, 0.99966, 0.9996397, 0.9996188, 0.9995974, 0.9995753, 0.99955267, 0.9995294, 0.9995056, 0.9994812, 0.99945617, 0.9994306, 0.99940443, 0.99937767, 0.9993503, 0.99932235, 0.99929386, 0.9992648, 0.99923503, 0.99920475, 0.9991739, 0.9991424, 0.99911034, 0.99907774, 0.9990445, 0.9990107, 0.9989763, 0.9989413, 0.9989057, 0.99886954, 0.9988328, 0.99879545, 0.99875754, 0.99871904, 0.99867994, 0.99864024, 0.99859995, 0.99855906, 0.99851763, 0.99847555, 0.99843293, 0.9983897, 0.9983459, 0.99830157, 0.99825656, 0.998211, 0.99816483, 0.9981181, 0.9980708, 0.99802285, 0.9979744, 0.9979253, 0.99787563, 0.9978253, 0.9977745, 0.99772304, 0.99767107, 0.99761844, 0.9975652, 0.99751145, 0.9974571, 0.99740213, 0.9973466, 0.99729043, 0.99723375, 0.9971764, 0.99711853, 0.99706006, 0.997001, 0.9969413, 0.9968811, 0.9968203, 0.9967589, 0.9966969, 0.9966343, 0.9965711, 0.9965074, 0.99644303, 0.9963781, 0.9963126, 0.9962465, 0.9961798, 0.9961126, 0.9960447, 0.99597627, 0.99590725, 0.9958376, 0.9957674, 0.9956966, 0.99562526, 0.9955533, 0.9954808, 0.99540764, 0.9953339, 0.9952596, 0.9951847, 0.99510926, 0.9950332, 0.99495655, 0.9948793, 0.9948015, 0.99472314, 0.99464417, 0.9945646, 0.9944844, 0.99440366, 0.99432236, 0.99424046, 0.99415797, 0.9940749, 0.9939912, 0.993907, 0.99382216, 0.99373674, 0.99365073, 0.9935641, 0.993477, 0.9933892, 0.99330086, 0.9932119, 0.99312246, 0.99303234, 0.9929417, 0.9928504, 0.9927586, 0.9926661, 0.99257314, 0.99247956, 0.9923853, 0.9922906, 0.99219525, 0.9920993, 0.9920028, 0.9919057, 0.991808, 0.99170977, 0.9916109, 0.99151146, 0.99141145, 0.99131083, 0.9912097, 0.99110794, 0.99100554, 0.99090266, 0.9907991, 0.990695, 0.99059033, 0.9904851, 0.9903792, 0.9902728, 0.9901658, 0.9900582, 0.98995006, 0.9898413, 0.98973197, 0.989622, 0.9895115, 0.98940045, 0.98928875, 0.9891765, 0.9890637, 0.98895025, 0.9888363, 0.98872167, 0.9886065, 0.9884908, 0.9883745, 0.9882576, 0.9881401, 0.988022, 0.98790336, 0.98778415, 0.98766434, 0.98754394, 0.98742294, 0.9873014, 0.9871793, 0.98705655, 0.9869333, 0.9868094, 0.9866849, 0.9865599, 0.9864343, 0.9863081, 0.9861813, 0.98605394, 0.98592603, 0.9857975, 0.9856684, 0.9855387, 0.9854085, 0.98527765, 0.9851462, 0.98501426, 0.98488164, 0.9847485, 0.9846148, 0.98448044, 0.98434556, 0.9842101, 0.98407406, 0.98393744, 0.98380023, 0.9836624, 0.983524, 0.9833851, 0.9832456, 0.9831055, 0.9829648, 0.98282355, 0.9826817, 0.9825393, 0.9823963, 0.9822527, 0.9821086, 0.9819639, 0.98181856, 0.9816727, 0.98152626, 0.9813792, 0.9812316, 0.9810834, 0.9809346, 0.98078525, 0.98063534, 0.98048484, 0.9803338, 0.9801821, 0.9800299, 0.9798771, 0.97972375, 0.9795698, 0.97941524, 0.97926015, 0.97910446, 0.9789482, 0.97879136, 0.97863394, 0.9784759, 0.9783174, 0.97815824, 0.9779985, 0.9778382, 0.97767735, 0.97751594, 0.9773539, 0.9771913, 0.97702813, 0.9768644, 0.97670007, 0.9765352, 0.97636974, 0.9762037, 0.9760371, 0.9758699, 0.9757021, 0.9755338, 0.97536486, 0.9751954, 0.97502536, 0.9748547, 0.9746835, 0.97451174, 0.97433937, 0.97416645, 0.97399294, 0.9738189, 0.97364426, 0.973469, 0.97329324, 0.9731169, 0.97293997, 0.97276247, 0.97258437, 0.97240573, 0.9722265, 0.97204673, 0.9718663, 0.9716854, 0.9715039, 0.9713218, 0.97113913, 0.9709559, 0.97077215, 0.9705878, 0.97040284, 0.97021735, 0.97003126, 0.9698446, 0.96965736, 0.9694696, 0.96928126, 0.9690923, 0.9689028, 0.96871275, 0.9685221, 0.96833086, 0.9681391, 0.96794677, 0.9677538, 0.96756035, 0.9673663, 0.96717167, 0.96697646, 0.9667807, 0.9665844, 0.96638745, 0.96619, 0.965992, 0.9657934, 0.9655942, 0.96539444, 0.9651941, 0.96499324, 0.96479183, 0.9645898, 0.96438724, 0.96418405, 0.9639804, 0.96377605, 0.9635712, 0.9633658, 0.9631598, 0.96295327, 0.96274614, 0.9625385, 0.9623302, 0.9621214, 0.96191204, 0.96170205, 0.9614916, 0.96128047, 0.96106887, 0.9608566, 0.9606439, 0.9604305, 0.96021664, 0.9600021, 0.95978713, 0.95957154, 0.95935535, 0.95913863, 0.9589213, 0.95870346, 0.95848507, 0.9582661, 0.9580465, 0.95782644, 0.9576057, 0.9573845, 0.9571627, 0.95694035, 0.95671743, 0.9564939, 0.95626986, 0.95604527, 0.9558201, 0.95559436, 0.95536804, 0.9551412, 0.95491374, 0.95468575, 0.9544572, 0.9542281, 0.95399845, 0.9537682, 0.9535374, 0.953306, 0.9530741, 0.95284164, 0.9526086, 0.952375, 0.95214087, 0.95190614, 0.9516709, 0.951435, 0.95119864, 0.95096165, 0.9507241, 0.95048606, 0.95024747, 0.9500083, 0.9497685, 0.94952816, 0.9492873, 0.9490459, 0.9488039, 0.9485614, 0.94831824, 0.9480746, 0.9478304, 0.9475856, 0.94734025, 0.9470944, 0.9468479, 0.9466009, 0.9463534, 0.94610524, 0.9458566, 0.9456073, 0.94535756, 0.9451072, 0.9448563, 0.9446048, 0.9443528, 0.94410026, 0.9438471, 0.94359344, 0.9433392, 0.9430844, 0.9428291, 0.9425732, 0.9423168, 0.94205976, 0.9418022, 0.94154406, 0.9412854, 0.94102615, 0.9407664, 0.94050604, 0.9402452, 0.9399837, 0.93972176, 0.9394592, 0.9391961, 0.9389325, 0.9386683, 0.93840355, 0.93813825, 0.93787235, 0.937606, 0.937339, 0.9370715, 0.93680346, 0.9365348, 0.93626565, 0.93599594, 0.9357257, 0.93545485, 0.9351835, 0.9349116, 0.93463916, 0.9343661, 0.9340925, 0.93381846, 0.9335438, 0.93326855, 0.9329928, 0.9327165, 0.9324396, 0.9321622, 0.9318843, 0.93160576, 0.9313267, 0.9310471, 0.93076694, 0.93048626, 0.93020505, 0.92992324, 0.9296409, 0.929358, 0.9290746, 0.9287906, 0.9285061, 0.928221, 0.9279354, 0.92764926, 0.9273625, 0.92707527, 0.9267875, 0.9264991, 0.9262102, 0.9259208, 0.9256308, 0.9253403, 0.92504925, 0.9247576, 0.9244655, 0.92417276, 0.9238795, 0.9235858, 0.92329144, 0.9229965, 0.9227011, 0.9224052, 0.92210865, 0.92181164, 0.92151403, 0.9212159, 0.9209172, 0.92061806, 0.9203183, 0.92001796, 0.91971713, 0.9194158, 0.9191139, 0.9188114, 0.9185084, 0.91820484, 0.9179008, 0.91759616, 0.917291, 0.9169853, 0.9166791, 0.9163723, 0.916065, 0.9157571, 0.9154487, 0.9151398, 0.9148303, 0.9145203, 0.9142098, 0.91389865, 0.91358703, 0.9132749, 0.9129622, 0.912649, 0.91233516, 0.91202086, 0.91170603, 0.91139066, 0.91107476, 0.91075826, 0.9104413, 0.91012377, 0.9098057, 0.9094871, 0.909168, 0.90884835, 0.9085281, 0.90820736, 0.9078861, 0.90756434, 0.907242, 0.9069191, 0.9065957, 0.90627176, 0.90594727, 0.9056223, 0.90529674, 0.9049707, 0.9046441, 0.90431696, 0.9039893, 0.9036611, 0.90333235, 0.9030031, 0.9026733, 0.902343, 0.90201217, 0.90168077, 0.9013488, 0.9010164, 0.9006834, 0.9003499, 0.9000159, 0.8996813, 0.89934623, 0.8990106, 0.8986745, 0.8983378, 0.8980006, 0.8976628, 0.89732456, 0.89698577, 0.8966465, 0.89630663, 0.89596623, 0.89562535, 0.89528394, 0.894942, 0.8945995, 0.8942565, 0.893913, 0.8935689, 0.8932243, 0.8928792, 0.89253354, 0.8921874, 0.8918407, 0.8914935, 0.89114577, 0.8907975, 0.89044875, 0.8900994, 0.8897496, 0.88939923, 0.88904834, 0.88869697, 0.88834506, 0.88799256, 0.88763964, 0.8872861, 0.88693213, 0.8865776, 0.88622254, 0.88586694, 0.88551086, 0.88515425, 0.8847971, 0.88443947, 0.88408124, 0.88372254, 0.88336337, 0.8830036, 0.88264334, 0.88228256, 0.8819213, 0.88155943, 0.8811971, 0.8808343, 0.8804709, 0.880107, 0.8797426, 0.87937766, 0.8790122, 0.87864625, 0.8782798, 0.8779128, 0.8775453, 0.87717724, 0.8768087, 0.8764397, 0.8760701, 0.8757, 0.8753294, 0.8749583, 0.87458664, 0.87421453, 0.8738418, 0.8734687, 0.873095, 0.8727208, 0.87234604, 0.87197083, 0.8715951, 0.87121886, 0.87084204, 0.8704648, 0.87008697, 0.86970866, 0.86932987, 0.86895055, 0.8685707, 0.86819035, 0.8678095, 0.8674281, 0.86704624, 0.8666639, 0.866281, 0.86589754, 0.8655136, 0.8651292, 0.86474425, 0.8643588, 0.86397284, 0.86358637, 0.8631994, 0.8628119, 0.86242396, 0.86203545, 0.8616465, 0.86125696, 0.86086696, 0.86047643, 0.86008537, 0.8596939, 0.8593018, 0.85890925, 0.8585162, 0.85812265, 0.8577286, 0.857334, 0.85693896, 0.8565434, 0.85614735, 0.85575074, 0.85535365, 0.8549561, 0.854558, 0.8541594, 0.8537603, 0.8533607, 0.8529606, 0.85256, 0.8521589, 0.8517573, 0.8513552, 0.85095257, 0.85054946, 0.8501459, 0.84974176, 0.84933716, 0.848932, 0.8485265, 0.84812033, 0.84771377, 0.8473066, 0.84689903, 0.8464909, 0.8460823, 0.84567326, 0.84526366, 0.8448536, 0.84444296, 0.8440319, 0.8436203, 0.84320825, 0.84279567, 0.8423826, 0.841969, 0.841555, 0.84114045, 0.84072536, 0.84030986, 0.8398938, 0.83947724, 0.83906025, 0.8386427, 0.8382247, 0.8378062, 0.8373872, 0.8369677, 0.83654773, 0.8361273, 0.8357063, 0.8352848, 0.8348629, 0.8344404, 0.8340175, 0.8335941, 0.8331702, 0.8327458, 0.83232087, 0.8318955, 0.8314696, 0.83104324, 0.8306164, 0.83018905, 0.8297612, 0.82933295, 0.8289041, 0.8284748, 0.82804507, 0.8276148, 0.827184, 0.8267528, 0.82632107, 0.8258889, 0.82545614, 0.825023, 0.8245893, 0.82415515, 0.8237205, 0.8232854, 0.8228498, 0.8224137, 0.82197714, 0.82154006, 0.8211025, 0.82066447, 0.82022595, 0.81978697, 0.8193475, 0.81890756, 0.81846714, 0.8180262, 0.8175848, 0.8171429, 0.8167006, 0.8162577, 0.81581444, 0.8153706, 0.8149263, 0.81448156, 0.8140363, 0.8135906, 0.8131444, 0.81269777, 0.8122506, 0.811803, 0.8113549, 0.81090623, 0.81045717, 0.81000763, 0.8095576, 0.8091071, 0.80865616, 0.8082047, 0.80775285, 0.80730045, 0.8068476, 0.8063942, 0.8059404, 0.8054861, 0.80503136, 0.8045761, 0.80412036, 0.8036642, 0.8032075, 0.8027504, 0.8022928, 0.8018347, 0.80137616, 0.80091715, 0.80045766, 0.7999977, 0.79953724, 0.7990764, 0.798615, 0.79815316, 0.79769087, 0.79722804, 0.7967648, 0.79630107, 0.7958369, 0.79537225, 0.79490715, 0.7944415, 0.7939755, 0.79350895, 0.79304194, 0.7925745, 0.79210657, 0.7916382, 0.79116935, 0.7907, 0.7902302, 0.78976, 0.78928924, 0.78881806, 0.7883464, 0.78787434, 0.78740174, 0.7869287, 0.7864552, 0.78598124, 0.78550684, 0.7850319, 0.78455657, 0.7840808, 0.7836045, 0.7831278, 0.7826506, 0.7821729, 0.7816948, 0.78121626, 0.7807372, 0.78025776, 0.77977777, 0.77929735, 0.7788165, 0.7783352, 0.7778534, 0.77737117, 0.7768885, 0.77640533, 0.7759217, 0.77543765, 0.7749531, 0.7744681, 0.7739827, 0.7734968, 0.77301043, 0.77252364, 0.7720364, 0.7715487, 0.7710605, 0.7705719, 0.77008283, 0.7695933, 0.76910335, 0.7686129, 0.768122, 0.7676307, 0.7671389, 0.7666467, 0.766154, 0.7656609, 0.76516724, 0.76467323, 0.76417875, 0.7636838, 0.7631884, 0.7626926, 0.7621963, 0.76169956, 0.7612024, 0.76070476, 0.7602067, 0.75970817, 0.7592092, 0.7587098, 0.7582099, 0.7577096, 0.7572088, 0.75670767, 0.756206, 0.7557039, 0.7552014, 0.7546984, 0.754195, 0.75369114, 0.7531868, 0.75268203, 0.7521768, 0.7516712, 0.75116515, 0.75065863, 0.75015163, 0.7496442, 0.7491364, 0.7486281, 0.74811935, 0.7476102, 0.7471006, 0.74659055, 0.7460801, 0.74556917, 0.74505776, 0.744546, 0.74403375, 0.7435211, 0.74300796, 0.7424944, 0.74198043, 0.741466, 0.7409511, 0.74043584, 0.7399201, 0.7394039, 0.7388873, 0.7383703, 0.7378528, 0.7373349, 0.7368166, 0.7362978, 0.73577857, 0.73525894, 0.7347389, 0.73421836, 0.7336974, 0.73317605, 0.7326543, 0.732132, 0.7316094, 0.7310863, 0.73056275, 0.7300388, 0.7295144, 0.7289896, 0.72846437, 0.7279387, 0.72741264, 0.7268861, 0.7263591, 0.7258318, 0.72530395, 0.72477573, 0.7242471, 0.723718, 0.72318846, 0.7226586, 0.7221282, 0.72159743, 0.7210662, 0.72053456, 0.72000253, 0.71947, 0.7189371, 0.7184038, 0.71787006, 0.7173359, 0.7168013, 0.7162663, 0.71573085, 0.71519494, 0.7146587, 0.714122, 0.71358484, 0.7130473, 0.7125094, 0.711971, 0.7114322, 0.710893, 0.7103534, 0.7098133, 0.7092728, 0.70873195, 0.7081906, 0.70764893, 0.70710677, 0.70656425, 0.70602125, 0.7054779, 0.70493406, 0.70438987, 0.70384526, 0.7033002, 0.70275474, 0.7022089, 0.7016626, 0.7011159, 0.7005688, 0.70002127, 0.6994733, 0.698925, 0.69837624, 0.6978271, 0.6972775, 0.6967275, 0.6961771, 0.6956263, 0.6950751, 0.6945235, 0.69397146, 0.69341904, 0.69286615, 0.6923129, 0.6917592, 0.6912052, 0.6906507, 0.69009584, 0.68954057, 0.6889849, 0.68842876, 0.68787223, 0.68731534, 0.68675804, 0.6862003, 0.6856422, 0.6850837, 0.6845247, 0.6839654, 0.6834057, 0.68284553, 0.682285, 0.6817241, 0.6811627, 0.680601, 0.68003887, 0.6794763, 0.67891335, 0.67835003, 0.6777863, 0.6772222, 0.6766576, 0.6760927, 0.6755274, 0.6749616, 0.6743955, 0.673829, 0.67326206, 0.67269474, 0.67212707, 0.671559, 0.67099047, 0.67042154, 0.66985226, 0.6692826, 0.6687125, 0.668142, 0.6675712, 0.66699994, 0.66642827, 0.66585624, 0.6652838, 0.664711, 0.6641378, 0.66356415, 0.66299015, 0.6624158, 0.661841, 0.66126585, 0.6606903, 0.66011435, 0.65953803, 0.6589613, 0.6583842, 0.6578067, 0.6572288, 0.65665054, 0.6560719, 0.65549284, 0.6549134, 0.6543336, 0.6537534, 0.65317285, 0.6525919, 0.65201056, 0.6514288, 0.65084666, 0.6502642, 0.6496813, 0.64909804, 0.6485144, 0.6479304, 0.64734596, 0.6467612, 0.64617604, 0.6455905, 0.6450045, 0.64441824, 0.64383155, 0.6432445, 0.64265704, 0.6420692, 0.64148104, 0.64089245, 0.6403035, 0.6397142, 0.63912445, 0.63853437, 0.6379439, 0.63735306, 0.63676184, 0.63617027, 0.63557833, 0.634986, 0.6343933, 0.6338002, 0.6332068, 0.63261294, 0.63201874, 0.6314242, 0.6308292, 0.63023394, 0.62963825, 0.6290422, 0.62844574, 0.627849, 0.6272518, 0.62665427, 0.6260564, 0.6254581, 0.6248595, 0.6242605, 0.6236611, 0.62306136, 0.62246126, 0.6218608, 0.62126, 0.62065876, 0.6200572, 0.6194553, 0.618853, 0.6182503, 0.6176473, 0.6170439, 0.6164402, 0.6158361, 0.6152316, 0.61462677, 0.61402154, 0.613416, 0.6128101, 0.6122038, 0.6115972, 0.61099017, 0.6103828, 0.60977507, 0.60916704, 0.6085586, 0.6079498, 0.60734063, 0.6067311, 0.60612124, 0.60551107, 0.6049005, 0.60428953, 0.6036782, 0.6030666, 0.6024546, 0.6018422, 0.60122955, 0.60061646, 0.60000306, 0.5993893, 0.5987752, 0.5981607, 0.59754586, 0.5969307, 0.5963152, 0.5956993, 0.59508306, 0.5944665, 0.5938496, 0.5932323, 0.59261465, 0.59199667, 0.5913784, 0.5907597, 0.5901407, 0.5895213, 0.5889016, 0.5882816, 0.58766115, 0.58704036, 0.5864193, 0.58579785, 0.58517605, 0.58455396, 0.58393145, 0.58330864, 0.5826855, 0.582062, 0.5814381, 0.58081394, 0.5801894, 0.5795646, 0.5789393, 0.57831377, 0.5776879, 0.57706165, 0.5764351, 0.57580817, 0.57518095, 0.5745534, 0.57392544, 0.57329714, 0.57266855, 0.5720396, 0.57141036, 0.57078075, 0.5701508, 0.56952053, 0.5688899, 0.56825894, 0.56762767, 0.56699604, 0.5663641, 0.5657318, 0.5650992, 0.56446624, 0.56383294, 0.56319934, 0.5625654, 0.56193113, 0.5612965, 0.56066155, 0.5600263, 0.5593907, 0.5587548, 0.5581185, 0.55748194, 0.556845, 0.5562078, 0.55557024, 0.55493236, 0.5542941, 0.55365556, 0.5530167, 0.5523775, 0.55173796, 0.55109817, 0.55045795, 0.5498175, 0.54917663, 0.5485355, 0.54789406, 0.5472523, 0.5466102, 0.54596776, 0.545325, 0.5446819, 0.54403853, 0.5433948, 0.5427508, 0.54210645, 0.54146177, 0.5408168, 0.54017144, 0.53952587, 0.53887993, 0.53823364, 0.53758705, 0.53694016, 0.53629297, 0.5356455, 0.53499764, 0.53434944, 0.533701, 0.5330522, 0.5324031, 0.5317537, 0.531104, 0.530454, 0.52980363, 0.529153, 0.528502, 0.52785075, 0.52719915, 0.52654725, 0.525895, 0.5252425, 0.52458966, 0.52393657, 0.5232831, 0.5226294, 0.5219753, 0.52132094, 0.52066624, 0.52001125, 0.519356, 0.5187004, 0.51804453, 0.5173883, 0.5167318, 0.516075, 0.5154179, 0.51476043, 0.51410276, 0.5134447, 0.5127864, 0.51212776, 0.5114688, 0.5108096, 0.5101501, 0.50949025, 0.50883013, 0.5081697, 0.507509, 0.506848, 0.50618666, 0.50552505, 0.5048631, 0.5042009, 0.50353837, 0.50287557, 0.50221246, 0.50154907, 0.50088537, 0.5002214, 0.4995571, 0.49889255, 0.49822766, 0.4975625, 0.49689704, 0.4962313, 0.49556527, 0.49489895, 0.4942323, 0.4935654, 0.4928982, 0.4922307, 0.4915629, 0.49089485, 0.49022648, 0.48955783, 0.4888889, 0.48821968, 0.48755017, 0.48688036, 0.4862103, 0.4855399, 0.48486924, 0.4841983, 0.48352706, 0.48285556, 0.48218378, 0.48151168, 0.48083934, 0.48016667, 0.47949377, 0.47882056, 0.47814706, 0.4774733, 0.47679922, 0.47612488, 0.47545028, 0.47477537, 0.4741002, 0.47342476, 0.47274902, 0.47207302, 0.47139674, 0.47072017, 0.47004333, 0.46936622, 0.46868882, 0.46801114, 0.4673332, 0.466655, 0.4659765, 0.46529773, 0.46461868, 0.46393937, 0.4632598, 0.46257994, 0.4618998, 0.4612194, 0.46053872, 0.45985776, 0.45917654, 0.45849505, 0.4578133, 0.45713127, 0.45644897, 0.4557664, 0.45508358, 0.45440048, 0.4537171, 0.45303348, 0.45234957, 0.45166543, 0.450981, 0.45029628, 0.44961134, 0.4489261, 0.4482406, 0.44755486, 0.44686884, 0.44618255, 0.44549602, 0.4448092, 0.44412214, 0.4434348, 0.44274724, 0.44205937, 0.44137126, 0.4406829, 0.43999428, 0.4393054, 0.43861625, 0.43792683, 0.43723717, 0.43654725, 0.4358571, 0.43516666, 0.43447596, 0.43378502, 0.43309382, 0.43240237, 0.43171066, 0.4310187, 0.4303265, 0.429634, 0.42894128, 0.42824832, 0.42755508, 0.4268616, 0.42616788, 0.4254739, 0.42477968, 0.4240852, 0.42339048, 0.4226955, 0.42200026, 0.4213048, 0.4206091, 0.4199131, 0.4192169, 0.41852042, 0.4178237, 0.41712677, 0.41642955, 0.41573212, 0.4150344, 0.4143365, 0.41363832, 0.41293988, 0.41224122, 0.41154233, 0.41084316, 0.4101438, 0.40944415, 0.40874428, 0.40804416, 0.4073438, 0.4066432, 0.40594238, 0.4052413, 0.40454, 0.40383846, 0.40313667, 0.40243465, 0.4017324, 0.40102988, 0.40032718, 0.3996242, 0.398921, 0.39821756, 0.3975139, 0.39681, 0.39610586, 0.39540148, 0.39469686, 0.39399204, 0.39328697, 0.39258167, 0.39187613, 0.39117038, 0.3904644, 0.38975817, 0.38905174, 0.38834503, 0.38763815, 0.386931, 0.38622364, 0.38551605, 0.38480824, 0.3841002, 0.38339192, 0.38268343, 0.38197473, 0.38126576, 0.3805566, 0.3798472, 0.3791376, 0.37842774, 0.3777177, 0.37700742, 0.3762969, 0.37558618, 0.37487522, 0.37416407, 0.37345266, 0.37274107, 0.37202924, 0.3713172, 0.37060493, 0.36989245, 0.36917976, 0.36846682, 0.36775368, 0.36704034, 0.36632678, 0.36561298, 0.364899, 0.3641848, 0.36347038, 0.36275572, 0.36204088, 0.3613258, 0.3606105, 0.35989505, 0.35917935, 0.3584634, 0.3577473, 0.35703096, 0.35631442, 0.35559767, 0.3548807, 0.35416353, 0.35344616, 0.35272855, 0.35201076, 0.35129276, 0.35057455, 0.34985614, 0.3491375, 0.34841868, 0.34769964, 0.34698042, 0.34626096, 0.34554133, 0.34482148, 0.34410143, 0.34338117, 0.34266073, 0.34194008, 0.34121922, 0.34049815, 0.33977687, 0.33905542, 0.33833376, 0.3376119, 0.33688986, 0.3361676, 0.33544514, 0.3347225, 0.33399966, 0.3332766, 0.33255336, 0.33182994, 0.3311063, 0.3303825, 0.32965845, 0.32893425, 0.32820985, 0.32748523, 0.32676044, 0.32603547, 0.3253103, 0.32458493, 0.32385936, 0.32313362, 0.3224077, 0.32168156, 0.32095525, 0.32022873, 0.31950203, 0.31877515, 0.3180481, 0.31732082, 0.31659338, 0.31586576, 0.31513792, 0.31440994, 0.31368175, 0.31295338, 0.3122248, 0.31149608, 0.31076714, 0.31003806, 0.30930877, 0.3085793, 0.30784965, 0.30711982, 0.3063898, 0.3056596, 0.30492923, 0.30419868, 0.30346796, 0.30273703, 0.30200595, 0.3012747, 0.30054325, 0.29981163, 0.29907984, 0.29834786, 0.2976157, 0.29688337, 0.2961509, 0.2954182, 0.29468536, 0.29395235, 0.29321915, 0.2924858, 0.29175225, 0.29101855, 0.29028466, 0.28955063, 0.28881642, 0.28808203, 0.28734747, 0.28661272, 0.28587782, 0.28514278, 0.28440753, 0.28367212, 0.28293657, 0.28220084, 0.28146493, 0.28072888, 0.27999264, 0.27925625, 0.2785197, 0.27778298, 0.27704608, 0.27630904, 0.27557182, 0.27483445, 0.2740969, 0.2733592, 0.27262136, 0.27188334, 0.27114516, 0.2704068, 0.2696683, 0.26892966, 0.26819086, 0.26745188, 0.26671275, 0.26597348, 0.26523402, 0.26449442, 0.26375467, 0.26301476, 0.2622747, 0.26153448, 0.2607941, 0.2600536, 0.25931293, 0.25857207, 0.2578311, 0.25708997, 0.25634867, 0.25560725, 0.25486565, 0.25412393, 0.25338203, 0.25264, 0.2518978, 0.2511555, 0.250413, 0.24967039, 0.24892761, 0.24818468, 0.24744162, 0.24669841, 0.24595505, 0.24521154, 0.2444679, 0.24372411, 0.24298018, 0.24223611, 0.24149188, 0.24074753, 0.24000302, 0.23925838, 0.23851359, 0.23776866, 0.2370236, 0.2362784, 0.23553306, 0.23478758, 0.23404196, 0.2332962, 0.23255031, 0.23180428, 0.2310581, 0.23031181, 0.22956537, 0.22881879, 0.22807208, 0.22732525, 0.22657827, 0.22583115, 0.22508392, 0.22433653, 0.22358903, 0.2228414, 0.22209363, 0.22134572, 0.22059768, 0.21984953, 0.21910124, 0.21835282, 0.21760428, 0.2168556, 0.2161068, 0.21535787, 0.21460882, 0.21385963, 0.21311031, 0.21236089, 0.21161133, 0.21086164, 0.21011184, 0.20936191, 0.20861185, 0.20786168, 0.20711137, 0.20636095, 0.20561041, 0.20485975, 0.20410897, 0.20335807, 0.20260704, 0.2018559, 0.20110464, 0.20035325, 0.19960175, 0.19885014, 0.1980984, 0.19734657, 0.1965946, 0.19584252, 0.19509032, 0.19433801, 0.19358559, 0.19283305, 0.1920804, 0.19132763, 0.19057475, 0.18982176, 0.18906866, 0.18831545, 0.18756212, 0.18680869, 0.18605515, 0.1853015, 0.18454774, 0.18379387, 0.18303989, 0.1822858, 0.18153161, 0.18077731, 0.1800229, 0.17926839, 0.17851377, 0.17775905, 0.17700422, 0.1762493, 0.17549425, 0.17473911, 0.17398387, 0.17322853, 0.17247309, 0.17171754, 0.17096189, 0.17020614, 0.1694503, 0.16869435, 0.16793829, 0.16718215, 0.1664259, 0.16566956, 0.16491312, 0.16415659, 0.16339995, 0.16264322, 0.1618864, 0.16112947, 0.16037245, 0.15961535, 0.15885815, 0.15810084, 0.15734346, 0.15658598, 0.1558284, 0.15507074, 0.15431297, 0.15355512, 0.15279719, 0.15203916, 0.15128104, 0.15052283, 0.14976454, 0.14900614, 0.14824767, 0.14748912, 0.14673047, 0.14597175, 0.14521292, 0.14445402, 0.14369503, 0.14293596, 0.1421768, 0.14141756, 0.14065824, 0.13989884, 0.13913934, 0.13837977, 0.13762012, 0.13686039, 0.13610058, 0.13534068, 0.1345807, 0.13382065, 0.13306053, 0.13230032, 0.13154003, 0.13077967, 0.13001922, 0.1292587, 0.1284981, 0.12773745, 0.1269767, 0.12621588, 0.12545498, 0.12469402, 0.12393297, 0.12317186, 0.12241068, 0.121649414, 0.120888084, 0.12012669, 0.119365215, 0.11860368, 0.11784206, 0.11708038, 0.11631863, 0.115556814, 0.114794925, 0.11403298, 0.11327095, 0.11250886, 0.11174671, 0.11098449, 0.110222206, 0.109459855, 0.108697444, 0.10793497, 0.10717242, 0.10640982, 0.105647154, 0.10488442, 0.10412163, 0.10335878, 0.102595866, 0.1018329, 0.10106986, 0.10030677, 0.099543616, 0.09878041, 0.09801714, 0.097253814, 0.09649043, 0.09572699, 0.0949635, 0.09419994, 0.09343634, 0.092672676, 0.091908954, 0.09114519, 0.09038136, 0.08961748, 0.08885355, 0.08808957, 0.087325536, 0.08656145, 0.08579731, 0.085033126, 0.08426889, 0.0835046, 0.08274026, 0.08197588, 0.08121145, 0.080446966, 0.07968244, 0.07891786, 0.078153245, 0.07738858, 0.076623864, 0.07585911, 0.0750943, 0.07432945, 0.07356457, 0.07279963, 0.07203465, 0.07126963, 0.070504576, 0.06973947, 0.06897433, 0.06820914, 0.06744392, 0.06667866, 0.06591335, 0.06514801, 0.06438263, 0.063617215, 0.06285176, 0.062086266, 0.061320737, 0.06055517, 0.059789572, 0.059023935, 0.058258265, 0.057492558, 0.05672682, 0.05596105, 0.055195246, 0.05442941, 0.053663537, 0.052897636, 0.052131705, 0.05136574, 0.05059975, 0.049833726, 0.049067676, 0.048301592, 0.047535483, 0.046769347, 0.04600318, 0.04523699, 0.044470772, 0.04370453, 0.04293826, 0.042171963, 0.04140564, 0.040639296, 0.039872926, 0.039106537, 0.03834012, 0.037573684, 0.036807224, 0.036040742, 0.035274237, 0.034507714, 0.033741172, 0.03297461, 0.032208025, 0.031441424, 0.030674804, 0.029908165, 0.029141508, 0.028374836, 0.027608145, 0.02684144, 0.026074719, 0.025307981, 0.024541229, 0.023774462, 0.023007682, 0.022240888, 0.02147408, 0.02070726, 0.019940428, 0.019173585, 0.01840673, 0.017639864, 0.016872987, 0.016106103, 0.015339206, 0.014572302, 0.0138053885, 0.013038468, 0.012271538, 0.011504602, 0.010737659, 0.00997071, 0.009203754, 0.008436794, 0.007669829, 0.0069028586, 0.0061358847, 0.005368907, 0.004601926, 0.0038349426, 0.0030679568, 0.002300969, 0.0015339801, 0.0007669903, }
f32
/home/linuxreitt/Michinereitt/Tuning/Workshop_Scripts/hf-codegen/data/golang_public_repos/mobile/exp/f32/gen.go
// Copyright 2014 The Go Authors. All rights reserved. // Use of this source code is governed by a BSD-style // license that can be found in the LICENSE file. //go:build ignore package main /* This program generates table.go. Invoke it as: go run gen.go -output table.go */ import ( "bytes" "flag" "fmt" "go/format" "io/ioutil" "log" "math" ) // N is the number of entries in the sin look-up table. It must be a power of 2. const N = 4096 var filename = flag.String("output", "table.go", "output file name") func main() { b := new(bytes.Buffer) fmt.Fprintf(b, "// Code generated by go run gen.go; DO NOT EDIT\n\npackage f32\n\n") fmt.Fprintf(b, "const sinTableLen = %d\n\n", N) fmt.Fprintf(b, "// sinTable[i] equals sin(i * π / sinTableLen).\n") fmt.Fprintf(b, "var sinTable = [sinTableLen]float32{\n") for i := 0; i < N; i++ { radians := float64(i) * (math.Pi / N) fmt.Fprintf(b, "%v,\n", float32(math.Sin(radians))) } fmt.Fprintf(b, "}\n") data, err := format.Source(b.Bytes()) if err != nil { log.Fatal(err) } if err := ioutil.WriteFile(*filename, data, 0644); err != nil { log.Fatal(err) } }
glutil
/home/linuxreitt/Michinereitt/Tuning/Workshop_Scripts/hf-codegen/data/golang_public_repos/mobile/exp/gl/glutil/doc.go
// Copyright 2014 The Go Authors. All rights reserved. // Use of this source code is governed by a BSD-style // license that can be found in the LICENSE file. // Package glutil implements OpenGL utility functions. package glutil // import "golang.org/x/mobile/exp/gl/glutil"
glutil
/home/linuxreitt/Michinereitt/Tuning/Workshop_Scripts/hf-codegen/data/golang_public_repos/mobile/exp/gl/glutil/glimage.go
// Copyright 2014 The Go Authors. All rights reserved. // Use of this source code is governed by a BSD-style // license that can be found in the LICENSE file. //go:build linux || darwin || windows package glutil import ( "encoding/binary" "image" "runtime" "sync" "golang.org/x/mobile/event/size" "golang.org/x/mobile/exp/f32" "golang.org/x/mobile/geom" "golang.org/x/mobile/gl" ) // Images maintains the shared state used by a set of *Image objects. type Images struct { glctx gl.Context quadXY gl.Buffer quadUV gl.Buffer program gl.Program pos gl.Attrib mvp gl.Uniform uvp gl.Uniform inUV gl.Attrib textureSample gl.Uniform mu sync.Mutex activeImages int } // NewImages creates an *Images. func NewImages(glctx gl.Context) *Images { program, err := CreateProgram(glctx, vertexShader, fragmentShader) if err != nil { panic(err) } p := &Images{ glctx: glctx, quadXY: glctx.CreateBuffer(), quadUV: glctx.CreateBuffer(), program: program, pos: glctx.GetAttribLocation(program, "pos"), mvp: glctx.GetUniformLocation(program, "mvp"), uvp: glctx.GetUniformLocation(program, "uvp"), inUV: glctx.GetAttribLocation(program, "inUV"), textureSample: glctx.GetUniformLocation(program, "textureSample"), } glctx.BindBuffer(gl.ARRAY_BUFFER, p.quadXY) glctx.BufferData(gl.ARRAY_BUFFER, quadXYCoords, gl.STATIC_DRAW) glctx.BindBuffer(gl.ARRAY_BUFFER, p.quadUV) glctx.BufferData(gl.ARRAY_BUFFER, quadUVCoords, gl.STATIC_DRAW) return p } // Release releases any held OpenGL resources. // All *Image objects must be released first, or this function panics. func (p *Images) Release() { if p.program == (gl.Program{}) { return } p.mu.Lock() rem := p.activeImages p.mu.Unlock() if rem > 0 { panic("glutil.Images.Release called, but active *Image objects remain") } p.glctx.DeleteProgram(p.program) p.glctx.DeleteBuffer(p.quadXY) p.glctx.DeleteBuffer(p.quadUV) p.program = gl.Program{} } // Image bridges between an *image.RGBA and an OpenGL texture. // // The contents of the *image.RGBA can be uploaded as a texture and drawn as a // 2D quad. // // The number of active Images must fit in the system's OpenGL texture limit. // The typical use of an Image is as a texture atlas. type Image struct { RGBA *image.RGBA gltex gl.Texture width int height int images *Images } // NewImage creates an Image of the given size. // // Both a host-memory *image.RGBA and a GL texture are created. func (p *Images) NewImage(w, h int) *Image { dx := roundToPower2(w) dy := roundToPower2(h) // TODO(crawshaw): Using VertexAttribPointer we can pass texture // data with a stride, which would let us use the exact number of // pixels on the host instead of the rounded up power 2 size. m := image.NewRGBA(image.Rect(0, 0, dx, dy)) img := &Image{ RGBA: m.SubImage(image.Rect(0, 0, w, h)).(*image.RGBA), images: p, width: dx, height: dy, } p.mu.Lock() p.activeImages++ p.mu.Unlock() img.gltex = p.glctx.CreateTexture() p.glctx.BindTexture(gl.TEXTURE_2D, img.gltex) p.glctx.TexImage2D(gl.TEXTURE_2D, 0, gl.RGBA, img.width, img.height, gl.RGBA, gl.UNSIGNED_BYTE, nil) p.glctx.TexParameteri(gl.TEXTURE_2D, gl.TEXTURE_MAG_FILTER, gl.LINEAR) p.glctx.TexParameteri(gl.TEXTURE_2D, gl.TEXTURE_MIN_FILTER, gl.LINEAR) p.glctx.TexParameteri(gl.TEXTURE_2D, gl.TEXTURE_WRAP_S, gl.CLAMP_TO_EDGE) p.glctx.TexParameteri(gl.TEXTURE_2D, gl.TEXTURE_WRAP_T, gl.CLAMP_TO_EDGE) runtime.SetFinalizer(img, (*Image).Release) return img } func roundToPower2(x int) int { x2 := 1 for x2 < x { x2 *= 2 } return x2 } // Upload copies the host image data to the GL device. func (img *Image) Upload() { img.images.glctx.BindTexture(gl.TEXTURE_2D, img.gltex) img.images.glctx.TexSubImage2D(gl.TEXTURE_2D, 0, 0, 0, img.width, img.height, gl.RGBA, gl.UNSIGNED_BYTE, img.RGBA.Pix) } // Release invalidates the Image and removes any underlying data structures. // The Image cannot be used after being deleted. func (img *Image) Release() { if img.gltex == (gl.Texture{}) { return } img.images.glctx.DeleteTexture(img.gltex) img.gltex = gl.Texture{} img.images.mu.Lock() img.images.activeImages-- img.images.mu.Unlock() } // Draw draws the srcBounds part of the image onto a parallelogram, defined by // three of its corners, in the current GL framebuffer. func (img *Image) Draw(sz size.Event, topLeft, topRight, bottomLeft geom.Point, srcBounds image.Rectangle) { glimage := img.images glctx := img.images.glctx glctx.BlendFunc(gl.ONE, gl.ONE_MINUS_SRC_ALPHA) glctx.Enable(gl.BLEND) // TODO(crawshaw): Adjust viewport for the top bar on android? glctx.UseProgram(glimage.program) { // We are drawing a parallelogram PQRS, defined by three of its // corners, onto the entire GL framebuffer ABCD. The two quads may // actually be equal, but in the general case, PQRS can be smaller, // and PQRS is not necessarily axis-aligned. // // A +---------------+ B // | P +-----+ Q | // | | | | // | S +-----+ R | // D +---------------+ C // // There are two co-ordinate spaces: geom space and framebuffer space. // In geom space, the ABCD rectangle is: // // (0, 0) (geom.Width, 0) // (0, geom.Height) (geom.Width, geom.Height) // // and the PQRS quad is: // // (topLeft.X, topLeft.Y) (topRight.X, topRight.Y) // (bottomLeft.X, bottomLeft.Y) (implicit, implicit) // // In framebuffer space, the ABCD rectangle is: // // (-1, +1) (+1, +1) // (-1, -1) (+1, -1) // // First of all, convert from geom space to framebuffer space. For // later convenience, we divide everything by 2 here: px2 is half of // the P.X co-ordinate (in framebuffer space). px2 := -0.5 + float32(topLeft.X/sz.WidthPt) py2 := +0.5 - float32(topLeft.Y/sz.HeightPt) qx2 := -0.5 + float32(topRight.X/sz.WidthPt) qy2 := +0.5 - float32(topRight.Y/sz.HeightPt) sx2 := -0.5 + float32(bottomLeft.X/sz.WidthPt) sy2 := +0.5 - float32(bottomLeft.Y/sz.HeightPt) // Next, solve for the affine transformation matrix // [ a00 a01 a02 ] // a = [ a10 a11 a12 ] // [ 0 0 1 ] // that maps A to P: // a × [ -1 +1 1 ]' = [ 2*px2 2*py2 1 ]' // and likewise maps B to Q and D to S. Solving those three constraints // implies that C maps to R, since affine transformations keep parallel // lines parallel. This gives 6 equations in 6 unknowns: // -a00 + a01 + a02 = 2*px2 // -a10 + a11 + a12 = 2*py2 // +a00 + a01 + a02 = 2*qx2 // +a10 + a11 + a12 = 2*qy2 // -a00 - a01 + a02 = 2*sx2 // -a10 - a11 + a12 = 2*sy2 // which gives: // a00 = (2*qx2 - 2*px2) / 2 = qx2 - px2 // and similarly for the other elements of a. writeAffine(glctx, glimage.mvp, &f32.Affine{{ qx2 - px2, px2 - sx2, qx2 + sx2, }, { qy2 - py2, py2 - sy2, qy2 + sy2, }}) } { // Mapping texture co-ordinates is similar, except that in texture // space, the ABCD rectangle is: // // (0,0) (1,0) // (0,1) (1,1) // // and the PQRS quad is always axis-aligned. First of all, convert // from pixel space to texture space. w := float32(img.width) h := float32(img.height) px := float32(srcBounds.Min.X-img.RGBA.Rect.Min.X) / w py := float32(srcBounds.Min.Y-img.RGBA.Rect.Min.Y) / h qx := float32(srcBounds.Max.X-img.RGBA.Rect.Min.X) / w sy := float32(srcBounds.Max.Y-img.RGBA.Rect.Min.Y) / h // Due to axis alignment, qy = py and sx = px. // // The simultaneous equations are: // 0 + 0 + a02 = px // 0 + 0 + a12 = py // a00 + 0 + a02 = qx // a10 + 0 + a12 = qy = py // 0 + a01 + a02 = sx = px // 0 + a11 + a12 = sy writeAffine(glctx, glimage.uvp, &f32.Affine{{ qx - px, 0, px, }, { 0, sy - py, py, }}) } glctx.ActiveTexture(gl.TEXTURE0) glctx.BindTexture(gl.TEXTURE_2D, img.gltex) glctx.Uniform1i(glimage.textureSample, 0) glctx.BindBuffer(gl.ARRAY_BUFFER, glimage.quadXY) glctx.EnableVertexAttribArray(glimage.pos) glctx.VertexAttribPointer(glimage.pos, 2, gl.FLOAT, false, 0, 0) glctx.BindBuffer(gl.ARRAY_BUFFER, glimage.quadUV) glctx.EnableVertexAttribArray(glimage.inUV) glctx.VertexAttribPointer(glimage.inUV, 2, gl.FLOAT, false, 0, 0) glctx.DrawArrays(gl.TRIANGLE_STRIP, 0, 4) glctx.DisableVertexAttribArray(glimage.pos) glctx.DisableVertexAttribArray(glimage.inUV) glctx.Disable(gl.BLEND) } var quadXYCoords = f32.Bytes(binary.LittleEndian, -1, +1, // top left +1, +1, // top right -1, -1, // bottom left +1, -1, // bottom right ) var quadUVCoords = f32.Bytes(binary.LittleEndian, 0, 0, // top left 1, 0, // top right 0, 1, // bottom left 1, 1, // bottom right ) const vertexShader = `#version 100 uniform mat3 mvp; uniform mat3 uvp; attribute vec3 pos; attribute vec2 inUV; varying vec2 UV; void main() { vec3 p = pos; p.z = 1.0; gl_Position = vec4(mvp * p, 1); UV = (uvp * vec3(inUV, 1)).xy; } ` const fragmentShader = `#version 100 precision mediump float; varying vec2 UV; uniform sampler2D textureSample; void main(){ gl_FragColor = texture2D(textureSample, UV); } `
glutil
/home/linuxreitt/Michinereitt/Tuning/Workshop_Scripts/hf-codegen/data/golang_public_repos/mobile/exp/gl/glutil/context_darwin_desktop.go
// Copyright 2014 The Go Authors. All rights reserved. // Use of this source code is governed by a BSD-style // license that can be found in the LICENSE file. //go:build darwin && !ios package glutil // TODO(crawshaw): Only used in glutil tests for now (cgo is not support in _test.go files). // TODO(crawshaw): Export some kind of Context. Work out what we can offer, where. Maybe just for tests. // TODO(crawshaw): Support android and windows. /* #cgo CFLAGS: -DGL_SILENCE_DEPRECATION #cgo LDFLAGS: -framework OpenGL #import <OpenGL/OpenGL.h> #import <OpenGL/gl3.h> CGLError CGCreate(CGLContextObj* ctx) { CGLError err; CGLPixelFormatAttribute attributes[] = { kCGLPFAOpenGLProfile, (CGLPixelFormatAttribute)kCGLOGLPVersion_3_2_Core, kCGLPFAColorSize, (CGLPixelFormatAttribute)24, kCGLPFAAlphaSize, (CGLPixelFormatAttribute)8, kCGLPFADepthSize, (CGLPixelFormatAttribute)16, kCGLPFAAccelerated, kCGLPFADoubleBuffer, (CGLPixelFormatAttribute) 0 }; CGLPixelFormatObj pix; GLint num; if ((err = CGLChoosePixelFormat(attributes, &pix, &num)) != kCGLNoError) { return err; } if ((err = CGLCreateContext(pix, 0, ctx)) != kCGLNoError) { return err; } if ((err = CGLDestroyPixelFormat(pix)) != kCGLNoError) { return err; } if ((err = CGLSetCurrentContext(*ctx)) != kCGLNoError) { return err; } if ((err = CGLLockContext(*ctx)) != kCGLNoError) { return err; } return kCGLNoError; } */ import "C" import ( "fmt" "runtime" ) // contextGL holds a copy of the OpenGL Context from thread-local storage. // // Do not move a contextGL between goroutines or OS threads. type contextGL struct { ctx C.CGLContextObj } // createContext creates an OpenGL context, binds it as the current context // stored in thread-local storage, and locks the current goroutine to an os // thread. func createContext() (*contextGL, error) { // The OpenGL active context is stored in TLS. runtime.LockOSThread() c := new(contextGL) if cglErr := C.CGCreate(&c.ctx); cglErr != C.kCGLNoError { return nil, fmt.Errorf("CGL: %v", C.GoString(C.CGLErrorString(cglErr))) } // Using attribute arrays in OpenGL 3.3 requires the use of a VBA. // But VBAs don't exist in ES 2. So we bind a default one. var id C.GLuint C.glGenVertexArrays(1, &id) C.glBindVertexArray(id) return c, nil } // destroy destroys an OpenGL context and unlocks the current goroutine from // its os thread. func (c *contextGL) destroy() { C.CGLUnlockContext(c.ctx) C.CGLSetCurrentContext(nil) C.CGLDestroyContext(c.ctx) c.ctx = nil runtime.UnlockOSThread() }
glutil
/home/linuxreitt/Michinereitt/Tuning/Workshop_Scripts/hf-codegen/data/golang_public_repos/mobile/exp/gl/glutil/context_x11.go
// Copyright 2014 The Go Authors. All rights reserved. // Use of this source code is governed by a BSD-style // license that can be found in the LICENSE file. //go:build linux && !android package glutil /* #cgo LDFLAGS: -lEGL #include <EGL/egl.h> #include <stdio.h> #include <stdlib.h> void createContext(EGLDisplay *out_dpy, EGLContext *out_ctx, EGLSurface *out_surf) { EGLDisplay e_dpy = eglGetDisplay(EGL_DEFAULT_DISPLAY); if (!e_dpy) { fprintf(stderr, "eglGetDisplay failed\n"); exit(1); } EGLint e_major, e_minor; if (!eglInitialize(e_dpy, &e_major, &e_minor)) { fprintf(stderr, "eglInitialize failed\n"); exit(1); } eglBindAPI(EGL_OPENGL_ES_API); static const EGLint config_attribs[] = { EGL_RENDERABLE_TYPE, EGL_OPENGL_ES2_BIT, EGL_SURFACE_TYPE, EGL_PBUFFER_BIT, EGL_BLUE_SIZE, 8, EGL_GREEN_SIZE, 8, EGL_RED_SIZE, 8, EGL_CONFIG_CAVEAT, EGL_NONE, EGL_NONE }; EGLConfig config; EGLint num_configs; if (!eglChooseConfig(e_dpy, config_attribs, &config, 1, &num_configs)) { fprintf(stderr, "eglChooseConfig failed\n"); exit(1); } static const EGLint ctx_attribs[] = { EGL_CONTEXT_CLIENT_VERSION, 2, EGL_NONE }; EGLContext e_ctx = eglCreateContext(e_dpy, config, EGL_NO_CONTEXT, ctx_attribs); if (e_ctx == EGL_NO_CONTEXT) { fprintf(stderr, "eglCreateContext failed\n"); exit(1); } static const EGLint pbuf_attribs[] = { EGL_NONE }; EGLSurface e_surf = eglCreatePbufferSurface(e_dpy, config, pbuf_attribs); if (e_surf == EGL_NO_SURFACE) { fprintf(stderr, "eglCreatePbufferSurface failed\n"); exit(1); } if (!eglMakeCurrent(e_dpy, e_surf, e_surf, e_ctx)) { fprintf(stderr, "eglMakeCurrent failed\n"); exit(1); } *out_surf = e_surf; *out_ctx = e_ctx; *out_dpy = e_dpy; } void destroyContext(EGLDisplay e_dpy, EGLContext e_ctx, EGLSurface e_surf) { if (!eglMakeCurrent(e_dpy, EGL_NO_SURFACE, EGL_NO_SURFACE, EGL_NO_CONTEXT)) { fprintf(stderr, "eglMakeCurrent failed\n"); exit(1); } if (!eglDestroySurface(e_dpy, e_surf)) { fprintf(stderr, "eglDestroySurface failed\n"); exit(1); } if (!eglDestroyContext(e_dpy, e_ctx)) { fprintf(stderr, "eglDestroyContext failed\n"); exit(1); } } */ import "C" import ( "runtime" ) type contextGL struct { dpy C.EGLDisplay ctx C.EGLContext surf C.EGLSurface } func createContext() (*contextGL, error) { runtime.LockOSThread() c := &contextGL{} C.createContext(&c.dpy, &c.ctx, &c.surf) return c, nil } func (c *contextGL) destroy() { C.destroyContext(c.dpy, c.ctx, c.surf) runtime.UnlockOSThread() }
glutil
/home/linuxreitt/Michinereitt/Tuning/Workshop_Scripts/hf-codegen/data/golang_public_repos/mobile/exp/gl/glutil/glimage_test.go
// Copyright 2014 The Go Authors. All rights reserved. // Use of this source code is governed by a BSD-style // license that can be found in the LICENSE file. //go:build darwin || (linux && !android) // TODO(crawshaw): Run tests on other OSs when more contexts are supported. package glutil import ( "image" "image/color" ) // TODO: Re-enable test. /*func TestImage(t *testing.T) { done := make(chan error) defer close(done) go func() { runtime.LockOSThread() ctx, err := createContext() done <- err for { select { case <-gl.WorkAvailable: gl.DoWork() case <-done: ctx.destroy() return } } }() if err := <-done; err != nil { t.Fatalf("cannot create GL context: %v", err) } start() defer stop() // GL testing strategy: // 1. Create an offscreen framebuffer object. // 2. Configure framebuffer to render to a GL texture. // 3. Run test code: use glimage to draw testdata. // 4. Copy GL texture back into system memory. // 5. Compare to a pre-computed image. f, err := os.Open("../../../testdata/testpattern.png") if err != nil { t.Fatal(err) } defer f.Close() src, _, err := image.Decode(f) if err != nil { t.Fatal(err) } const ( pixW = 100 pixH = 100 ptW = geom.Pt(50) ptH = geom.Pt(50) ) sz := size.Event{ WidthPx: pixW, HeightPx: pixH, WidthPt: ptW, HeightPt: ptH, PixelsPerPt: float32(pixW) / float32(ptW), } fBuf := gl.CreateFramebuffer() gl.BindFramebuffer(gl.FRAMEBUFFER, fBuf) colorBuf := gl.CreateRenderbuffer() gl.BindRenderbuffer(gl.RENDERBUFFER, colorBuf) // https://www.khronos.org/opengles/sdk/docs/man/xhtml/glRenderbufferStorage.xml // says that the internalFormat "must be one of the following symbolic constants: // GL_RGBA4, GL_RGB565, GL_RGB5_A1, GL_DEPTH_COMPONENT16, or GL_STENCIL_INDEX8". gl.RenderbufferStorage(gl.RENDERBUFFER, gl.RGB565, pixW, pixH) gl.FramebufferRenderbuffer(gl.FRAMEBUFFER, gl.COLOR_ATTACHMENT0, gl.RENDERBUFFER, colorBuf) if status := gl.CheckFramebufferStatus(gl.FRAMEBUFFER); status != gl.FRAMEBUFFER_COMPLETE { t.Fatalf("framebuffer create failed: %v", status) } allocs := testing.AllocsPerRun(100, func() { gl.ClearColor(0, 0, 1, 1) // blue }) if allocs != 0 { t.Errorf("unexpected allocations from calling gl.ClearColor: %f", allocs) } gl.Clear(gl.COLOR_BUFFER_BIT) gl.Viewport(0, 0, pixW, pixH) m := NewImage(src.Bounds().Dx(), src.Bounds().Dy()) b := m.RGBA.Bounds() draw.Draw(m.RGBA, b, src, src.Bounds().Min, draw.Src) m.Upload() b.Min.X += 10 b.Max.Y /= 2 // All-integer right-angled triangles offsetting the // box: 24-32-40, 12-16-20. ptTopLeft := geom.Point{0, 24} ptTopRight := geom.Point{32, 0} ptBottomLeft := geom.Point{12, 24 + 16} ptBottomRight := geom.Point{12 + 32, 16} m.Draw(sz, ptTopLeft, ptTopRight, ptBottomLeft, b) // For unknown reasons, a windowless OpenGL context renders upside- // down. That is, a quad covering the initial viewport spans: // // (-1, -1) ( 1, -1) // (-1, 1) ( 1, 1) // // To avoid modifying live code for tests, we flip the rows // recovered from the renderbuffer. We are not the first: // // http://lists.apple.com/archives/mac-opengl/2010/Jun/msg00080.html got := image.NewRGBA(image.Rect(0, 0, pixW, pixH)) upsideDownPix := make([]byte, len(got.Pix)) gl.ReadPixels(upsideDownPix, 0, 0, pixW, pixH, gl.RGBA, gl.UNSIGNED_BYTE) for y := 0; y < pixH; y++ { i0 := (pixH - 1 - y) * got.Stride i1 := i0 + pixW*4 copy(got.Pix[y*got.Stride:], upsideDownPix[i0:i1]) } drawCross(got, 0, 0) drawCross(got, int(ptTopLeft.X.Px(sz.PixelsPerPt)), int(ptTopLeft.Y.Px(sz.PixelsPerPt))) drawCross(got, int(ptBottomRight.X.Px(sz.PixelsPerPt)), int(ptBottomRight.Y.Px(sz.PixelsPerPt))) drawCross(got, pixW-1, pixH-1) const wantPath = "../../../testdata/testpattern-window.png" f, err = os.Open(wantPath) if err != nil { t.Fatal(err) } defer f.Close() wantSrc, _, err := image.Decode(f) if err != nil { t.Fatal(err) } want, ok := wantSrc.(*image.RGBA) if !ok { b := wantSrc.Bounds() want = image.NewRGBA(b) draw.Draw(want, b, wantSrc, b.Min, draw.Src) } if !imageEq(got, want) { // Write out the image we got. f, err = ioutil.TempFile("", "testpattern-window-got") if err != nil { t.Fatal(err) } f.Close() gotPath := f.Name() + ".png" f, err = os.Create(gotPath) if err != nil { t.Fatal(err) } if err := png.Encode(f, got); err != nil { t.Fatal(err) } if err := f.Close(); err != nil { t.Fatal(err) } t.Errorf("got\n%s\nwant\n%s", gotPath, wantPath) } }*/ func drawCross(m *image.RGBA, x, y int) { c := color.RGBA{0xff, 0, 0, 0xff} // red m.SetRGBA(x+0, y-2, c) m.SetRGBA(x+0, y-1, c) m.SetRGBA(x-2, y+0, c) m.SetRGBA(x-1, y+0, c) m.SetRGBA(x+0, y+0, c) m.SetRGBA(x+1, y+0, c) m.SetRGBA(x+2, y+0, c) m.SetRGBA(x+0, y+1, c) m.SetRGBA(x+0, y+2, c) } func eqEpsilon(x, y uint8) bool { const epsilon = 9 return x-y < epsilon || y-x < epsilon } func colorEq(c0, c1 color.RGBA) bool { return eqEpsilon(c0.R, c1.R) && eqEpsilon(c0.G, c1.G) && eqEpsilon(c0.B, c1.B) && eqEpsilon(c0.A, c1.A) } func imageEq(m0, m1 *image.RGBA) bool { b0 := m0.Bounds() b1 := m1.Bounds() if b0 != b1 { return false } badPx := 0 for y := b0.Min.Y; y < b0.Max.Y; y++ { for x := b0.Min.X; x < b0.Max.X; x++ { c0, c1 := m0.At(x, y).(color.RGBA), m1.At(x, y).(color.RGBA) if !colorEq(c0, c1) { badPx++ } } } badFrac := float64(badPx) / float64(b0.Dx()*b0.Dy()) return badFrac < 0.01 }
glutil
/home/linuxreitt/Michinereitt/Tuning/Workshop_Scripts/hf-codegen/data/golang_public_repos/mobile/exp/gl/glutil/glutil.go
// Copyright 2014 The Go Authors. All rights reserved. // Use of this source code is governed by a BSD-style // license that can be found in the LICENSE file. //go:build darwin || linux || windows package glutil // import "golang.org/x/mobile/exp/gl/glutil" import ( "fmt" "golang.org/x/mobile/exp/f32" "golang.org/x/mobile/gl" ) // CreateProgram creates, compiles, and links a gl.Program. func CreateProgram(glctx gl.Context, vertexSrc, fragmentSrc string) (gl.Program, error) { program := glctx.CreateProgram() if program.Value == 0 { return gl.Program{}, fmt.Errorf("glutil: no programs available") } vertexShader, err := loadShader(glctx, gl.VERTEX_SHADER, vertexSrc) if err != nil { return gl.Program{}, err } fragmentShader, err := loadShader(glctx, gl.FRAGMENT_SHADER, fragmentSrc) if err != nil { glctx.DeleteShader(vertexShader) return gl.Program{}, err } glctx.AttachShader(program, vertexShader) glctx.AttachShader(program, fragmentShader) glctx.LinkProgram(program) // Flag shaders for deletion when program is unlinked. glctx.DeleteShader(vertexShader) glctx.DeleteShader(fragmentShader) if glctx.GetProgrami(program, gl.LINK_STATUS) == 0 { defer glctx.DeleteProgram(program) return gl.Program{}, fmt.Errorf("glutil: %s", glctx.GetProgramInfoLog(program)) } return program, nil } func loadShader(glctx gl.Context, shaderType gl.Enum, src string) (gl.Shader, error) { shader := glctx.CreateShader(shaderType) if shader.Value == 0 { return gl.Shader{}, fmt.Errorf("glutil: could not create shader (type %v)", shaderType) } glctx.ShaderSource(shader, src) glctx.CompileShader(shader) if glctx.GetShaderi(shader, gl.COMPILE_STATUS) == 0 { defer glctx.DeleteShader(shader) return gl.Shader{}, fmt.Errorf("shader compile: %s", glctx.GetShaderInfoLog(shader)) } return shader, nil } // writeAffine writes the contents of an Affine to a 3x3 matrix GL uniform. func writeAffine(glctx gl.Context, u gl.Uniform, a *f32.Affine) { var m [9]float32 m[0*3+0] = a[0][0] m[0*3+1] = a[1][0] m[0*3+2] = 0 m[1*3+0] = a[0][1] m[1*3+1] = a[1][1] m[1*3+2] = 0 m[2*3+0] = a[0][2] m[2*3+1] = a[1][2] m[2*3+2] = 1 glctx.UniformMatrix3fv(u, m[:]) }
sensor
/home/linuxreitt/Michinereitt/Tuning/Workshop_Scripts/hf-codegen/data/golang_public_repos/mobile/exp/sensor/android.go
// Copyright 2015 The Go Authors. All rights reserved. // Use of this source code is governed by a BSD-style // license that can be found in the LICENSE file. //go:build android package sensor /* #cgo LDFLAGS: -landroid #include <stdlib.h> #include <android/sensor.h> void GoAndroid_createManager(); void GoAndroid_destroyManager(); int GoAndroid_enableSensor(int, int32_t); void GoAndroid_disableSensor(int); int GoAndroid_readQueue(int n, int32_t* types, int64_t* timestamps, float* vectors); */ import "C" import ( "fmt" "runtime" "sync" "time" "unsafe" ) var ( collectingMu sync.Mutex // guards collecting // collecting is true if sensor event collecting background // job has already started. collecting bool ) // closeSignal destroys the underlying looper and event queue. type closeSignal struct{} // readSignal reads up to len(dst) events and mutates n with // the number of returned events. type readSignal struct { dst []Event n *int } // enableSignal enables the sensors events on the underlying // event queue for the specified sensor type with the specified // latency criterion. type enableSignal struct { t Type delay time.Duration err *error } // disableSignal disables the events on the underlying event queue // from the sensor specified. type disableSignal struct { t Type } type inOut struct { in interface{} out chan struct{} } var inout = make(chan inOut) // init inits the manager and creates a goroutine to proxy the CGO calls. // All actions related to an ALooper needs to be performed from the same // OS thread. The goroutine proxy locks itself to an OS thread and handles the // CGO traffic on the same thread. func init() { go func() { runtime.LockOSThread() C.GoAndroid_createManager() for { v := <-inout switch s := v.in.(type) { case enableSignal: usecsDelay := s.delay.Nanoseconds() / 1000 code := int(C.GoAndroid_enableSensor(typeToInt(s.t), C.int32_t(usecsDelay))) if code != 0 { *s.err = fmt.Errorf("sensor: no default %v sensor on the device", s.t) } case disableSignal: C.GoAndroid_disableSensor(typeToInt(s.t)) case readSignal: n := readEvents(s.dst) *s.n = n case closeSignal: C.GoAndroid_destroyManager() close(v.out) return // we don't need this goroutine anymore } close(v.out) } }() } // enable enables the sensor t on sender. A non-nil sender is // required before calling enable. func enable(t Type, delay time.Duration) error { startCollecting() var err error done := make(chan struct{}) inout <- inOut{ in: enableSignal{t: t, delay: delay, err: &err}, out: done, } <-done return err } func startCollecting() { collectingMu.Lock() defer collectingMu.Unlock() if collecting { // already collecting. return } collecting = true go func() { ev := make([]Event, 8) var n int for { done := make(chan struct{}) inout <- inOut{ in: readSignal{dst: ev, n: &n}, out: done, } <-done for i := 0; i < n; i++ { sender.Send(ev[i]) } } }() } func disable(t Type) error { done := make(chan struct{}) inout <- inOut{ in: disableSignal{t: t}, out: done, } <-done return nil } func readEvents(e []Event) int { num := len(e) types := make([]C.int32_t, num) timestamps := make([]C.int64_t, num) vectors := make([]C.float, 3*num) n := int(C.GoAndroid_readQueue( C.int(num), (*C.int32_t)(unsafe.Pointer(&types[0])), (*C.int64_t)(unsafe.Pointer(&timestamps[0])), (*C.float)(unsafe.Pointer(&vectors[0]))), ) for i := 0; i < n; i++ { e[i] = Event{ Sensor: intToType[int(types[i])], Timestamp: int64(timestamps[i]), Data: []float64{ float64(vectors[i*3]), float64(vectors[i*3+1]), float64(vectors[i*3+2]), }, } } return n } // TODO(jbd): Remove destroy? func destroy() error { done := make(chan struct{}) inout <- inOut{ in: closeSignal{}, out: done, } <-done return nil } var intToType = map[int]Type{ C.ASENSOR_TYPE_ACCELEROMETER: Accelerometer, C.ASENSOR_TYPE_GYROSCOPE: Gyroscope, C.ASENSOR_TYPE_MAGNETIC_FIELD: Magnetometer, } func typeToInt(t Type) C.int { for k, v := range intToType { if v == t { return C.int(k) } } return C.int(-1) }
sensor
/home/linuxreitt/Michinereitt/Tuning/Workshop_Scripts/hf-codegen/data/golang_public_repos/mobile/exp/sensor/android.c
// Copyright 2015 The Go Authors. All rights reserved. // Use of this source code is governed by a BSD-style // license that can be found in the LICENSE file. //go:build android // +build android #include <stdlib.h> #include <jni.h> #include <android/sensor.h> #define GO_ANDROID_SENSOR_LOOPER_ID 100 #define GO_ANDROID_READ_TIMEOUT_MS 1000 ASensorEventQueue* queue = NULL; ALooper* looper = NULL; static ASensorManager* getSensorManager() { #pragma clang diagnostic push // Builders convert C warnings to errors, so suppress the // error from ASensorManager_getInstance being deprecated // in Android 26. #pragma clang diagnostic ignored "-Wdeprecated-declarations" return ASensorManager_getInstance(); #pragma clang diagnostic pop } void GoAndroid_createManager() { ASensorManager* manager = getSensorManager(); looper = ALooper_forThread(); if (looper == NULL) { looper = ALooper_prepare(ALOOPER_PREPARE_ALLOW_NON_CALLBACKS); } queue = ASensorManager_createEventQueue(manager, looper, GO_ANDROID_SENSOR_LOOPER_ID, NULL, NULL); } int GoAndroid_enableSensor(int s, int32_t usec) { ASensorManager* manager = getSensorManager(); const ASensor* sensor = ASensorManager_getDefaultSensor(manager, s); if (sensor == NULL) { return 1; } ASensorEventQueue_enableSensor(queue, sensor); ASensorEventQueue_setEventRate(queue, sensor, usec); return 0; } void GoAndroid_disableSensor(int s) { ASensorManager* manager = getSensorManager(); const ASensor* sensor = ASensorManager_getDefaultSensor(manager, s); ASensorEventQueue_disableSensor(queue, sensor); } int GoAndroid_readQueue(int n, int32_t* types, int64_t* timestamps, float* vectors) { int id; int events; ASensorEvent event; int i = 0; // Try n times read from the event queue. // If anytime timeout occurs, don't retry to read and immediately return. // Consume the event queue entirely between polls. while (i < n && (id = ALooper_pollOnce(GO_ANDROID_READ_TIMEOUT_MS, NULL, &events, NULL)) >= 0) { if (id != GO_ANDROID_SENSOR_LOOPER_ID) { continue; } while (i < n && ASensorEventQueue_getEvents(queue, &event, 1)) { types[i] = event.type; timestamps[i] = event.timestamp; vectors[i*3] = event.vector.x; vectors[i*3+1] = event.vector.y; vectors[i*3+2] = event.vector.z; i++; } } return i; } void GoAndroid_destroyManager() { ASensorManager* manager = getSensorManager(); ASensorManager_destroyEventQueue(manager, queue); queue = NULL; looper = NULL; }
sensor
/home/linuxreitt/Michinereitt/Tuning/Workshop_Scripts/hf-codegen/data/golang_public_repos/mobile/exp/sensor/notmobile.go
// Copyright 2015 The Go Authors. All rights reserved. // Use of this source code is governed by a BSD-style // license that can be found in the LICENSE file. //go:build (linux && !android) || (darwin && !arm && !arm64) || windows package sensor import ( "errors" "time" ) func enable(t Type, delay time.Duration) error { return errors.New("sensor: no sensors available") } func disable(t Type) error { return errors.New("sensor: no sensors available") } func destroy() error { return nil }
sensor
/home/linuxreitt/Michinereitt/Tuning/Workshop_Scripts/hf-codegen/data/golang_public_repos/mobile/exp/sensor/sensor.go
// Copyright 2015 The Go Authors. All rights reserved. // Use of this source code is governed by a BSD-style // license that can be found in the LICENSE file. // Package sensor provides sensor events from various movement sensors. package sensor // import "golang.org/x/mobile/exp/sensor" import ( "errors" "sync" "time" ) // Type represents a sensor type. type Type int var sensorNames = map[Type]string{ Accelerometer: "Accelerometer", Gyroscope: "Gyroscope", Magnetometer: "Magnetometer", } // String returns the string representation of the sensor type. func (t Type) String() string { if n, ok := sensorNames[t]; ok { return n } return "Unknown sensor" } const ( Accelerometer = Type(0) Gyroscope = Type(1) Magnetometer = Type(2) nTypes = Type(3) ) // Event represents a sensor event. type Event struct { // Sensor is the type of the sensor the event is coming from. Sensor Type // Timestamp is a device specific event time in nanoseconds. // Timestamps are not Unix times, they represent a time that is // only valid for the device's default sensor. Timestamp int64 // Data is the event data. // // If the event source is Accelerometer, // - Data[0]: acceleration force in x axis in m/s^2 // - Data[1]: acceleration force in y axis in m/s^2 // - Data[2]: acceleration force in z axis in m/s^2 // // If the event source is Gyroscope, // - Data[0]: rate of rotation around the x axis in rad/s // - Data[1]: rate of rotation around the y axis in rad/s // - Data[2]: rate of rotation around the z axis in rad/s // // If the event source is Magnetometer, // - Data[0]: force of gravity along the x axis in m/s^2 // - Data[1]: force of gravity along the y axis in m/s^2 // - Data[2]: force of gravity along the z axis in m/s^2 // Data []float64 } // TODO(jbd): Move Sender interface definition to a top-level package. var ( // senderMu protects sender. senderMu sync.Mutex // sender is notified with the sensor data each time a new event is available. sender Sender ) // Sender sends an event. type Sender interface { Send(event interface{}) } // Notify registers a Sender and sensor events will be sent to s. // A typical example of Sender implementations is app.App. // Once you call Notify, you are not allowed to call it again. // You cannot call Notify with a nil Sender. func Notify(s Sender) { senderMu.Lock() defer senderMu.Unlock() if s == nil { panic("sensor: cannot set a nil sender") } if sender != nil { panic("sensor: another sender is being notified, cannot set s as the sender") } sender = s } // Enable enables the specified sensor type with the given delay rate. // Users must set a non-nil Sender via Notify before enabling a sensor, // otherwise an error will be returned. func Enable(t Type, delay time.Duration) error { if t < 0 || int(t) >= len(sensorNames) { return errors.New("sensor: unknown sensor type") } if err := validSender(); err != nil { return err } return enable(t, delay) } // Disable disables to feed the manager with the specified sensor. // Disable is not safe for concurrent use. func Disable(t Type) error { if t < 0 || int(t) >= len(sensorNames) { return errors.New("sensor: unknown sensor type") } return disable(t) } func validSender() error { senderMu.Lock() defer senderMu.Unlock() if sender == nil { return errors.New("sensor: no senders to be notified; cannot enable the sensor") } return nil }
sensor
/home/linuxreitt/Michinereitt/Tuning/Workshop_Scripts/hf-codegen/data/golang_public_repos/mobile/exp/sensor/darwin_armx.m
// Copyright 2015 The Go Authors. All rights reserved. // Use of this source code is governed by a BSD-style // license that can be found in the LICENSE file. //go:build darwin && (arm || arm64) // +build darwin // +build arm arm64 #import <CoreMotion/CoreMotion.h> CMMotionManager* manager = nil; void GoIOS_createManager() { manager = [[CMMotionManager alloc] init]; } void GoIOS_startAccelerometer(float interval) { manager.accelerometerUpdateInterval = interval; [manager startAccelerometerUpdates]; } void GoIOS_stopAccelerometer() { [manager stopAccelerometerUpdates]; } void GoIOS_readAccelerometer(int64_t* timestamp, float* v) { CMAccelerometerData* data = manager.accelerometerData; *timestamp = (int64_t)(data.timestamp * 1000 * 1000); v[0] = data.acceleration.x; v[1] = data.acceleration.y; v[2] = data.acceleration.z; } void GoIOS_startGyro(float interval) { manager.gyroUpdateInterval = interval; [manager startGyroUpdates]; } void GoIOS_stopGyro() { [manager stopGyroUpdates]; } void GoIOS_readGyro(int64_t* timestamp, float* v) { CMGyroData* data = manager.gyroData; *timestamp = (int64_t)(data.timestamp * 1000 * 1000); v[0] = data.rotationRate.x; v[1] = data.rotationRate.y; v[2] = data.rotationRate.z; } void GoIOS_startMagneto(float interval) { manager.magnetometerUpdateInterval = interval; [manager startMagnetometerUpdates]; } void GoIOS_stopMagneto() { [manager stopMagnetometerUpdates]; } void GoIOS_readMagneto(int64_t* timestamp, float* v) { CMMagnetometerData* data = manager.magnetometerData; *timestamp = (int64_t)(data.timestamp * 1000 * 1000); v[0] = data.magneticField.x; v[1] = data.magneticField.y; v[2] = data.magneticField.z; } void GoIOS_destroyManager() { [manager release]; manager = nil; }
sensor
/home/linuxreitt/Michinereitt/Tuning/Workshop_Scripts/hf-codegen/data/golang_public_repos/mobile/exp/sensor/darwin_armx.go
// Copyright 2015 The Go Authors. All rights reserved. // Use of this source code is governed by a BSD-style // license that can be found in the LICENSE file. //go:build darwin && (arm || arm64) package sensor /* #cgo CFLAGS: -x objective-c #cgo LDFLAGS: -framework CoreMotion #import <stdlib.h> void GoIOS_createManager(); void GoIOS_startAccelerometer(float interval); void GoIOS_stopAccelerometer(); void GoIOS_readAccelerometer(int64_t* timestamp, float* vector); void GoIOS_startGyro(float interval); void GoIOS_stopGyro(); void GoIOS_readGyro(int64_t* timestamp, float* vector); void GoIOS_startMagneto(float interval); void GoIOS_stopMagneto(); void GoIOS_readMagneto(int64_t* timestamp, float* vector); void GoIOS_destroyManager(); */ import "C" import ( "fmt" "sync" "time" "unsafe" ) var channels struct { sync.Mutex done [nTypes]chan struct{} } func init() { C.GoIOS_createManager() } // minDelay is the minimum delay allowed. // // From Event Handling Guide for iOS: // // "You can set the reporting interval to be as small as 10 // milliseconds (ms), which corresponds to a 100 Hz update rate, // but most app operate sufficiently with a larger interval." // // There is no need to poll more frequently than once every 10ms. // // https://developer.apple.com/library/ios/documentation/EventHandling/Conceptual/EventHandlingiPhoneOS/motion_event_basics/motion_event_basics.html const minDelay = 10 * time.Millisecond // enable enables the sensor t on sender. A non-nil sender is // required before calling enable. func enable(t Type, delay time.Duration) error { channels.Lock() defer channels.Unlock() if channels.done[t] != nil { return fmt.Errorf("sensor: cannot enable; %v sensor is already enabled", t) } channels.done[t] = make(chan struct{}) if delay < minDelay { delay = minDelay } interval := C.float(float64(delay) / float64(time.Second)) switch t { case Accelerometer: C.GoIOS_startAccelerometer(interval) case Gyroscope: C.GoIOS_startGyro(interval) case Magnetometer: C.GoIOS_startMagneto(interval) } go pollSensor(t, delay, channels.done[t]) return nil } func disable(t Type) error { channels.Lock() defer channels.Unlock() if channels.done[t] == nil { return fmt.Errorf("sensor: cannot disable; %v sensor is not enabled", t) } close(channels.done[t]) channels.done[t] = nil switch t { case Accelerometer: C.GoIOS_stopAccelerometer() case Gyroscope: C.GoIOS_stopGyro() case Magnetometer: C.GoIOS_stopMagneto() } return nil } func pollSensor(t Type, d time.Duration, done chan struct{}) { var lastTimestamp int64 var timestamp C.int64_t var ev [3]C.float for { select { case <-done: return default: tp := (*C.int64_t)(unsafe.Pointer(&timestamp)) vp := (*C.float)(unsafe.Pointer(&ev[0])) switch t { case Accelerometer: C.GoIOS_readAccelerometer(tp, vp) case Gyroscope: C.GoIOS_readGyro(tp, vp) case Magnetometer: C.GoIOS_readMagneto(tp, vp) } ts := int64(timestamp) if ts > lastTimestamp { // TODO(jbd): Do we need to convert the values to another unit? // How does iOS units compare to the Android units. sender.Send(Event{ Sensor: t, Timestamp: ts, Data: []float64{float64(ev[0]), float64(ev[1]), float64(ev[2])}, }) lastTimestamp = ts time.Sleep(d / 2) } } } } // TODO(jbd): Remove destroy? func destroy() error { C.GoIOS_destroyManager() return nil }
sprite
/home/linuxreitt/Michinereitt/Tuning/Workshop_Scripts/hf-codegen/data/golang_public_repos/mobile/exp/sprite/sprite.go
// Copyright 2014 The Go Authors. All rights reserved. // Use of this source code is governed by a BSD-style // license that can be found in the LICENSE file. // Package sprite provides a 2D scene graph for rendering and animation. // // A tree of nodes is drawn by a rendering Engine, provided by another // package. The OS-independent Go version based on the image package is: // // golang.org/x/mobile/exp/sprite/portable // // An Engine draws a screen starting at a root Node. The tree is walked // depth-first, with affine transformations applied at each level. // // Nodes are rendered relative to their parent. // // Typical main loop: // // for each frame { // quantize time.Now() to a clock.Time // process UI events // modify the scene's nodes and animations (Arranger values) // e.Render(scene, t, sz) // } package sprite // import "golang.org/x/mobile/exp/sprite" import ( "image" "image/draw" "golang.org/x/mobile/event/size" "golang.org/x/mobile/exp/f32" "golang.org/x/mobile/exp/sprite/clock" ) type Arranger interface { Arrange(e Engine, n *Node, t clock.Time) } type Texture interface { Bounds() (w, h int) Download(r image.Rectangle, dst draw.Image) Upload(r image.Rectangle, src image.Image) Release() } type SubTex struct { T Texture R image.Rectangle } type Engine interface { Register(n *Node) Unregister(n *Node) LoadTexture(a image.Image) (Texture, error) SetSubTex(n *Node, x SubTex) SetTransform(n *Node, m f32.Affine) // sets transform relative to parent. // Render renders the scene arranged at the given time, for the given // window configuration (dimensions and resolution). Render(scene *Node, t clock.Time, sz size.Event) Release() } // A Node is a renderable element and forms a tree of Nodes. type Node struct { Parent, FirstChild, LastChild, PrevSibling, NextSibling *Node Arranger Arranger // EngineFields contains fields that should only be accessed by Engine // implementations. It is exported because such implementations can be // in other packages. EngineFields struct { // TODO: separate TexDirty and TransformDirty bits? Dirty bool Index int32 SubTex SubTex } } // AppendChild adds a node c as a child of n. // // It will panic if c already has a parent or siblings. func (n *Node) AppendChild(c *Node) { if c.Parent != nil || c.PrevSibling != nil || c.NextSibling != nil { panic("sprite: AppendChild called for an attached child Node") } last := n.LastChild if last != nil { last.NextSibling = c } else { n.FirstChild = c } n.LastChild = c c.Parent = n c.PrevSibling = last } // RemoveChild removes a node c that is a child of n. Afterwards, c will have // no parent and no siblings. // // It will panic if c's parent is not n. func (n *Node) RemoveChild(c *Node) { if c.Parent != n { panic("sprite: RemoveChild called for a non-child Node") } if n.FirstChild == c { n.FirstChild = c.NextSibling } if c.NextSibling != nil { c.NextSibling.PrevSibling = c.PrevSibling } if n.LastChild == c { n.LastChild = c.PrevSibling } if c.PrevSibling != nil { c.PrevSibling.NextSibling = c.NextSibling } c.Parent = nil c.PrevSibling = nil c.NextSibling = nil }
clock
/home/linuxreitt/Michinereitt/Tuning/Workshop_Scripts/hf-codegen/data/golang_public_repos/mobile/exp/sprite/clock/clock.go
// Copyright 2014 The Go Authors. All rights reserved. // Use of this source code is governed by a BSD-style // license that can be found in the LICENSE file. // Package clock provides a clock and time functions for a sprite engine. package clock // import "golang.org/x/mobile/exp/sprite/clock" // A Time represents an instant in sprite time. // // The application using the sprite engine is responsible for // determining sprite time. // // Typically time 0 is when the app is initialized and time is // quantized at the intended frame rate. For example, an app may // record wall time when it is initialized // // var start = time.Now() // // and then compute the current instant in time for 60 FPS: // // now := clock.Time(time.Since(start) * 60 / time.Second) // // An application can pause or reset sprite time, but it must be aware // of any stateful sprite.Arranger instances that expect time to // continue. type Time int32
clock
/home/linuxreitt/Michinereitt/Tuning/Workshop_Scripts/hf-codegen/data/golang_public_repos/mobile/exp/sprite/clock/tween_test.go
// Copyright 2014 The Go Authors. All rights reserved. // Use of this source code is governed by a BSD-style // license that can be found in the LICENSE file. package clock import "testing" func TestLinear(t *testing.T) { t0 := Time(0) t1 := Time(6 * 60) now := Time(3 * 60) if c := Linear(t0, t1, now); c != 0.5 { t.Errorf("c=%.2f, want 0.5", c) } } func TestCubicBezier(t *testing.T) { t0 := Time(0) t1 := Time(1e6) tests := []struct { x0, y0, x1, y1 float32 x, y float32 }{ {0.00, 0.1, 0.4, 1.00, 0.0, 0.00}, {0.00, 0.1, 0.4, 1.00, 0.1, 0.26}, {0.00, 0.1, 0.4, 1.00, 0.5, 0.79}, {0.00, 0.1, 0.4, 1.00, 0.9, 0.99}, {0.00, 0.1, 0.4, 1.00, 1.0, 1.00}, {0.36, 0.2, 0.3, 0.85, 0.0, 0.0}, {0.36, 0.2, 0.3, 0.85, 0.3059, 0.3952}, {0.36, 0.2, 0.3, 0.85, 0.4493, 0.6408}, {0.36, 0.2, 0.3, 0.85, 0.8116, 0.9410}, {0.00, 0.0, 1.0, 1.00, 0.1, 0.1}, {0.00, 0.0, 1.0, 1.00, 0.5, 0.5}, {0.00, 0.0, 1.0, 1.00, 0.9, 0.9}, {0.42, 0.0, 1.0, 1.00, 0.0, 0.0}, } for _, test := range tests { cb := CubicBezier(test.x0, test.y0, test.x1, test.y1) now := t0 + Time(float32(t1-t0)*test.x) y := cb(t0, t1, now) const epsilon = 0.01 diff := y - test.y if diff < -epsilon || +epsilon < diff { t.Errorf("CubicBezier(%.2f,%.2f,%.2f,%.2f): for x=%.2f got y=%.2f, want %.2f", test.x0, test.y0, test.x1, test.y1, test.x, y, test.y) } } }
clock
/home/linuxreitt/Michinereitt/Tuning/Workshop_Scripts/hf-codegen/data/golang_public_repos/mobile/exp/sprite/clock/tween.go
// Copyright 2014 The Go Authors. All rights reserved. // Use of this source code is governed by a BSD-style // license that can be found in the LICENSE file. package clock // Standard tween functions. // // Easing means a slowing near the timing boundary, as defined by // a cubic bezier curve. Exact parameters match the CSS properties. var ( EaseIn = CubicBezier(0.42, 0, 1, 1) EaseOut = CubicBezier(0, 0, 0.58, 1) EaseInOut = CubicBezier(0.42, 0, 0.58, 1) ) // Linear computes the fraction [0,1] that t lies between [t0,t1]. func Linear(t0, t1, t Time) float32 { if t >= t1 { return 1 } if t <= t0 { return 0 } return float32(t-t0) / float32(t1-t0) } // CubicBezier generates a tween function determined by a Cubic Bézier curve. // // The parameters are cubic control parameters. The curve starts at (0,0) // going toward (x0,y0), and arrives at (1,1) coming from (x1,y1). func CubicBezier(x0, y0, x1, y1 float32) func(t0, t1, t Time) float32 { return func(start, end, now Time) float32 { // A Cubic-Bezier curve restricted to starting at (0,0) and // ending at (1,1) is defined as // // B(t) = 3*(1-t)^2*t*P0 + 3*(1-t)*t^2*P1 + t^3 // // with derivative // // B'(t) = 3*(1-t)^2*P0 + 6*(1-t)*t*(P1-P0) + 3*t^2*(1-P1) // // Given a value x ∈ [0,1], we solve for t using Newton's // method and solve for y using t. x := Linear(start, end, now) // Solve for t using x. t := x for i := 0; i < 5; i++ { t2 := t * t t3 := t2 * t d := 1 - t d2 := d * d nx := 3*d2*t*x0 + 3*d*t2*x1 + t3 dxdt := 3*d2*x0 + 6*d*t*(x1-x0) + 3*t2*(1-x1) if dxdt == 0 { break } t -= (nx - x) / dxdt if t <= 0 || t >= 1 { break } } if t < 0 { t = 0 } if t > 1 { t = 1 } // Solve for y using t. t2 := t * t t3 := t2 * t d := 1 - t d2 := d * d y := 3*d2*t*y0 + 3*d*t2*y1 + t3 return y } }