id
int32
0
167k
repo
stringlengths
5
54
path
stringlengths
4
155
func_name
stringlengths
1
118
original_string
stringlengths
52
85.5k
language
stringclasses
1 value
code
stringlengths
52
85.5k
code_tokens
sequencelengths
21
1.41k
docstring
stringlengths
6
2.61k
docstring_tokens
sequencelengths
3
215
sha
stringlengths
40
40
url
stringlengths
85
252
149,900
hyperhq/hyperd
integration/client.go
ContainerExecSignal
func (c *HyperClient) ContainerExecSignal(container, execID string, sig int64) error { req := types.ExecSignalRequest{ ContainerID: container, ExecID: execID, Signal: sig, } _, err := c.client.ExecSignal(c.ctx, &req) if err != nil { return err } return nil }
go
func (c *HyperClient) ContainerExecSignal(container, execID string, sig int64) error { req := types.ExecSignalRequest{ ContainerID: container, ExecID: execID, Signal: sig, } _, err := c.client.ExecSignal(c.ctx, &req) if err != nil { return err } return nil }
[ "func", "(", "c", "*", "HyperClient", ")", "ContainerExecSignal", "(", "container", ",", "execID", "string", ",", "sig", "int64", ")", "error", "{", "req", ":=", "types", ".", "ExecSignalRequest", "{", "ContainerID", ":", "container", ",", "ExecID", ":", "execID", ",", "Signal", ":", "sig", ",", "}", "\n", "_", ",", "err", ":=", "c", ".", "client", ".", "ExecSignal", "(", "c", ".", "ctx", ",", "&", "req", ")", "\n", "if", "err", "!=", "nil", "{", "return", "err", "\n", "}", "\n\n", "return", "nil", "\n", "}" ]
// ContainerExecSignal sends signal to specified exec of specified container
[ "ContainerExecSignal", "sends", "signal", "to", "specified", "exec", "of", "specified", "container" ]
8a7e67dc33bbccdfc92b5e2a908bbdb1c5d9b956
https://github.com/hyperhq/hyperd/blob/8a7e67dc33bbccdfc92b5e2a908bbdb1c5d9b956/integration/client.go#L355-L367
149,901
hyperhq/hyperd
integration/client.go
ContainerExecCreate
func (c *HyperClient) ContainerExecCreate(container string, command []string, tty bool) (string, error) { req := types.ExecCreateRequest{ ContainerID: container, Command: command, Tty: tty, } resp, err := c.client.ExecCreate(c.ctx, &req) if err != nil { return "", err } return resp.ExecID, nil }
go
func (c *HyperClient) ContainerExecCreate(container string, command []string, tty bool) (string, error) { req := types.ExecCreateRequest{ ContainerID: container, Command: command, Tty: tty, } resp, err := c.client.ExecCreate(c.ctx, &req) if err != nil { return "", err } return resp.ExecID, nil }
[ "func", "(", "c", "*", "HyperClient", ")", "ContainerExecCreate", "(", "container", "string", ",", "command", "[", "]", "string", ",", "tty", "bool", ")", "(", "string", ",", "error", ")", "{", "req", ":=", "types", ".", "ExecCreateRequest", "{", "ContainerID", ":", "container", ",", "Command", ":", "command", ",", "Tty", ":", "tty", ",", "}", "\n", "resp", ",", "err", ":=", "c", ".", "client", ".", "ExecCreate", "(", "c", ".", "ctx", ",", "&", "req", ")", "\n", "if", "err", "!=", "nil", "{", "return", "\"", "\"", ",", "err", "\n", "}", "\n\n", "return", "resp", ".", "ExecID", ",", "nil", "\n", "}" ]
// ContainerExecCreate creates exec in a container
[ "ContainerExecCreate", "creates", "exec", "in", "a", "container" ]
8a7e67dc33bbccdfc92b5e2a908bbdb1c5d9b956
https://github.com/hyperhq/hyperd/blob/8a7e67dc33bbccdfc92b5e2a908bbdb1c5d9b956/integration/client.go#L370-L382
149,902
hyperhq/hyperd
integration/client.go
ContainerExecStart
func (c *HyperClient) ContainerExecStart(containerId, execId string, stdin io.ReadCloser, stdout, stderr io.Writer, tty bool) error { request := types.ExecStartRequest{ ContainerID: containerId, ExecID: execId, } stream, err := c.client.ExecStart(context.Background()) if err != nil { return err } if err := stream.Send(&request); err != nil { return err } extractor := NewExtractor(tty) var recvStdoutError chan error if stdout != nil || stderr != nil { recvStdoutError = promise.Go(func() (err error) { for { in, err := stream.Recv() if err != nil && err != io.EOF { return err } if in != nil && in.Stdout != nil { so, se, ee := extractor.Extract(in.Stdout) if ee != nil { return ee } if len(so) > 0 { nw, ew := stdout.Write(so) if ew != nil { return ew } if nw != len(so) { return io.ErrShortWrite } } if len(se) > 0 { nw, ew := stdout.Write(se) if ew != nil { return ew } if nw != len(se) { return io.ErrShortWrite } } } if err == io.EOF { break } } return nil }) } if stdin != nil { go func() error { defer stream.CloseSend() buf := make([]byte, 32) for { nr, err := stdin.Read(buf) if nr > 0 { if err := stream.Send(&types.ExecStartRequest{Stdin: buf[:nr]}); err != nil { return err } } if err == io.EOF { break } if err != nil { return err } } return nil }() } if stdout != nil || stderr != nil { if err := <-recvStdoutError; err != nil { return err } } return nil }
go
func (c *HyperClient) ContainerExecStart(containerId, execId string, stdin io.ReadCloser, stdout, stderr io.Writer, tty bool) error { request := types.ExecStartRequest{ ContainerID: containerId, ExecID: execId, } stream, err := c.client.ExecStart(context.Background()) if err != nil { return err } if err := stream.Send(&request); err != nil { return err } extractor := NewExtractor(tty) var recvStdoutError chan error if stdout != nil || stderr != nil { recvStdoutError = promise.Go(func() (err error) { for { in, err := stream.Recv() if err != nil && err != io.EOF { return err } if in != nil && in.Stdout != nil { so, se, ee := extractor.Extract(in.Stdout) if ee != nil { return ee } if len(so) > 0 { nw, ew := stdout.Write(so) if ew != nil { return ew } if nw != len(so) { return io.ErrShortWrite } } if len(se) > 0 { nw, ew := stdout.Write(se) if ew != nil { return ew } if nw != len(se) { return io.ErrShortWrite } } } if err == io.EOF { break } } return nil }) } if stdin != nil { go func() error { defer stream.CloseSend() buf := make([]byte, 32) for { nr, err := stdin.Read(buf) if nr > 0 { if err := stream.Send(&types.ExecStartRequest{Stdin: buf[:nr]}); err != nil { return err } } if err == io.EOF { break } if err != nil { return err } } return nil }() } if stdout != nil || stderr != nil { if err := <-recvStdoutError; err != nil { return err } } return nil }
[ "func", "(", "c", "*", "HyperClient", ")", "ContainerExecStart", "(", "containerId", ",", "execId", "string", ",", "stdin", "io", ".", "ReadCloser", ",", "stdout", ",", "stderr", "io", ".", "Writer", ",", "tty", "bool", ")", "error", "{", "request", ":=", "types", ".", "ExecStartRequest", "{", "ContainerID", ":", "containerId", ",", "ExecID", ":", "execId", ",", "}", "\n", "stream", ",", "err", ":=", "c", ".", "client", ".", "ExecStart", "(", "context", ".", "Background", "(", ")", ")", "\n", "if", "err", "!=", "nil", "{", "return", "err", "\n", "}", "\n", "if", "err", ":=", "stream", ".", "Send", "(", "&", "request", ")", ";", "err", "!=", "nil", "{", "return", "err", "\n", "}", "\n", "extractor", ":=", "NewExtractor", "(", "tty", ")", "\n", "var", "recvStdoutError", "chan", "error", "\n", "if", "stdout", "!=", "nil", "||", "stderr", "!=", "nil", "{", "recvStdoutError", "=", "promise", ".", "Go", "(", "func", "(", ")", "(", "err", "error", ")", "{", "for", "{", "in", ",", "err", ":=", "stream", ".", "Recv", "(", ")", "\n", "if", "err", "!=", "nil", "&&", "err", "!=", "io", ".", "EOF", "{", "return", "err", "\n", "}", "\n", "if", "in", "!=", "nil", "&&", "in", ".", "Stdout", "!=", "nil", "{", "so", ",", "se", ",", "ee", ":=", "extractor", ".", "Extract", "(", "in", ".", "Stdout", ")", "\n", "if", "ee", "!=", "nil", "{", "return", "ee", "\n", "}", "\n", "if", "len", "(", "so", ")", ">", "0", "{", "nw", ",", "ew", ":=", "stdout", ".", "Write", "(", "so", ")", "\n", "if", "ew", "!=", "nil", "{", "return", "ew", "\n", "}", "\n", "if", "nw", "!=", "len", "(", "so", ")", "{", "return", "io", ".", "ErrShortWrite", "\n", "}", "\n", "}", "\n", "if", "len", "(", "se", ")", ">", "0", "{", "nw", ",", "ew", ":=", "stdout", ".", "Write", "(", "se", ")", "\n", "if", "ew", "!=", "nil", "{", "return", "ew", "\n", "}", "\n", "if", "nw", "!=", "len", "(", "se", ")", "{", "return", "io", ".", "ErrShortWrite", "\n", "}", "\n\n", "}", "\n", "}", "\n", "if", "err", "==", "io", ".", "EOF", "{", "break", "\n", "}", "\n", "}", "\n", "return", "nil", "\n", "}", ")", "\n", "}", "\n", "if", "stdin", "!=", "nil", "{", "go", "func", "(", ")", "error", "{", "defer", "stream", ".", "CloseSend", "(", ")", "\n", "buf", ":=", "make", "(", "[", "]", "byte", ",", "32", ")", "\n", "for", "{", "nr", ",", "err", ":=", "stdin", ".", "Read", "(", "buf", ")", "\n", "if", "nr", ">", "0", "{", "if", "err", ":=", "stream", ".", "Send", "(", "&", "types", ".", "ExecStartRequest", "{", "Stdin", ":", "buf", "[", ":", "nr", "]", "}", ")", ";", "err", "!=", "nil", "{", "return", "err", "\n", "}", "\n", "}", "\n", "if", "err", "==", "io", ".", "EOF", "{", "break", "\n", "}", "\n", "if", "err", "!=", "nil", "{", "return", "err", "\n", "}", "\n", "}", "\n", "return", "nil", "\n", "}", "(", ")", "\n", "}", "\n", "if", "stdout", "!=", "nil", "||", "stderr", "!=", "nil", "{", "if", "err", ":=", "<-", "recvStdoutError", ";", "err", "!=", "nil", "{", "return", "err", "\n", "}", "\n", "}", "\n\n", "return", "nil", "\n", "}" ]
// ContainerExecStart starts exec in a container with input stream in and output stream out
[ "ContainerExecStart", "starts", "exec", "in", "a", "container", "with", "input", "stream", "in", "and", "output", "stream", "out" ]
8a7e67dc33bbccdfc92b5e2a908bbdb1c5d9b956
https://github.com/hyperhq/hyperd/blob/8a7e67dc33bbccdfc92b5e2a908bbdb1c5d9b956/integration/client.go#L385-L466
149,903
hyperhq/hyperd
integration/client.go
StartPod
func (c *HyperClient) StartPod(podID string) error { req := &types.PodStartRequest{ PodID: podID, } _, err := c.client.PodStart(c.ctx, req) if err != nil { return err } return nil }
go
func (c *HyperClient) StartPod(podID string) error { req := &types.PodStartRequest{ PodID: podID, } _, err := c.client.PodStart(c.ctx, req) if err != nil { return err } return nil }
[ "func", "(", "c", "*", "HyperClient", ")", "StartPod", "(", "podID", "string", ")", "error", "{", "req", ":=", "&", "types", ".", "PodStartRequest", "{", "PodID", ":", "podID", ",", "}", "\n\n", "_", ",", "err", ":=", "c", ".", "client", ".", "PodStart", "(", "c", ".", "ctx", ",", "req", ")", "\n", "if", "err", "!=", "nil", "{", "return", "err", "\n", "}", "\n\n", "return", "nil", "\n", "}" ]
// StartPod starts a pod by podID
[ "StartPod", "starts", "a", "pod", "by", "podID" ]
8a7e67dc33bbccdfc92b5e2a908bbdb1c5d9b956
https://github.com/hyperhq/hyperd/blob/8a7e67dc33bbccdfc92b5e2a908bbdb1c5d9b956/integration/client.go#L469-L480
149,904
hyperhq/hyperd
integration/client.go
StopPod
func (c *HyperClient) StopPod(podID string) (int, string, error) { resp, err := c.client.PodStop(c.ctx, &types.PodStopRequest{ PodID: podID, }) if err != nil { return -1, "", err } return int(resp.Code), resp.Cause, nil }
go
func (c *HyperClient) StopPod(podID string) (int, string, error) { resp, err := c.client.PodStop(c.ctx, &types.PodStopRequest{ PodID: podID, }) if err != nil { return -1, "", err } return int(resp.Code), resp.Cause, nil }
[ "func", "(", "c", "*", "HyperClient", ")", "StopPod", "(", "podID", "string", ")", "(", "int", ",", "string", ",", "error", ")", "{", "resp", ",", "err", ":=", "c", ".", "client", ".", "PodStop", "(", "c", ".", "ctx", ",", "&", "types", ".", "PodStopRequest", "{", "PodID", ":", "podID", ",", "}", ")", "\n", "if", "err", "!=", "nil", "{", "return", "-", "1", ",", "\"", "\"", ",", "err", "\n", "}", "\n\n", "return", "int", "(", "resp", ".", "Code", ")", ",", "resp", ".", "Cause", ",", "nil", "\n", "}" ]
// StopPod stops a pod
[ "StopPod", "stops", "a", "pod" ]
8a7e67dc33bbccdfc92b5e2a908bbdb1c5d9b956
https://github.com/hyperhq/hyperd/blob/8a7e67dc33bbccdfc92b5e2a908bbdb1c5d9b956/integration/client.go#L483-L492
149,905
hyperhq/hyperd
integration/client.go
PausePod
func (c *HyperClient) PausePod(podID string) error { _, err := c.client.PodPause(c.ctx, &types.PodPauseRequest{ PodID: podID, }) if err != nil { return err } return nil }
go
func (c *HyperClient) PausePod(podID string) error { _, err := c.client.PodPause(c.ctx, &types.PodPauseRequest{ PodID: podID, }) if err != nil { return err } return nil }
[ "func", "(", "c", "*", "HyperClient", ")", "PausePod", "(", "podID", "string", ")", "error", "{", "_", ",", "err", ":=", "c", ".", "client", ".", "PodPause", "(", "c", ".", "ctx", ",", "&", "types", ".", "PodPauseRequest", "{", "PodID", ":", "podID", ",", "}", ")", "\n", "if", "err", "!=", "nil", "{", "return", "err", "\n", "}", "\n\n", "return", "nil", "\n", "}" ]
// PausePod pauses a pod
[ "PausePod", "pauses", "a", "pod" ]
8a7e67dc33bbccdfc92b5e2a908bbdb1c5d9b956
https://github.com/hyperhq/hyperd/blob/8a7e67dc33bbccdfc92b5e2a908bbdb1c5d9b956/integration/client.go#L495-L504
149,906
hyperhq/hyperd
integration/client.go
UnpausePod
func (c *HyperClient) UnpausePod(podID string) error { _, err := c.client.PodUnpause(c.ctx, &types.PodUnpauseRequest{ PodID: podID, }) if err != nil { return err } return nil }
go
func (c *HyperClient) UnpausePod(podID string) error { _, err := c.client.PodUnpause(c.ctx, &types.PodUnpauseRequest{ PodID: podID, }) if err != nil { return err } return nil }
[ "func", "(", "c", "*", "HyperClient", ")", "UnpausePod", "(", "podID", "string", ")", "error", "{", "_", ",", "err", ":=", "c", ".", "client", ".", "PodUnpause", "(", "c", ".", "ctx", ",", "&", "types", ".", "PodUnpauseRequest", "{", "PodID", ":", "podID", ",", "}", ")", "\n", "if", "err", "!=", "nil", "{", "return", "err", "\n", "}", "\n\n", "return", "nil", "\n", "}" ]
// UnpausePod unpauses a pod
[ "UnpausePod", "unpauses", "a", "pod" ]
8a7e67dc33bbccdfc92b5e2a908bbdb1c5d9b956
https://github.com/hyperhq/hyperd/blob/8a7e67dc33bbccdfc92b5e2a908bbdb1c5d9b956/integration/client.go#L507-L516
149,907
hyperhq/hyperd
integration/client.go
PodSignal
func (c *HyperClient) PodSignal(podID string, signal int64) error { _, err := c.client.PodSignal(c.ctx, &types.PodSignalRequest{ PodID: podID, Signal: signal, }) if err != nil { return err } return nil }
go
func (c *HyperClient) PodSignal(podID string, signal int64) error { _, err := c.client.PodSignal(c.ctx, &types.PodSignalRequest{ PodID: podID, Signal: signal, }) if err != nil { return err } return nil }
[ "func", "(", "c", "*", "HyperClient", ")", "PodSignal", "(", "podID", "string", ",", "signal", "int64", ")", "error", "{", "_", ",", "err", ":=", "c", ".", "client", ".", "PodSignal", "(", "c", ".", "ctx", ",", "&", "types", ".", "PodSignalRequest", "{", "PodID", ":", "podID", ",", "Signal", ":", "signal", ",", "}", ")", "\n", "if", "err", "!=", "nil", "{", "return", "err", "\n", "}", "\n\n", "return", "nil", "\n", "}" ]
// PodSignal sends a signal to all containers of specified pod
[ "PodSignal", "sends", "a", "signal", "to", "all", "containers", "of", "specified", "pod" ]
8a7e67dc33bbccdfc92b5e2a908bbdb1c5d9b956
https://github.com/hyperhq/hyperd/blob/8a7e67dc33bbccdfc92b5e2a908bbdb1c5d9b956/integration/client.go#L519-L529
149,908
hyperhq/hyperd
integration/client.go
DeleteService
func (c *HyperClient) DeleteService(podID string, services []*types.UserService) error { _, err := c.client.ServiceDelete( c.ctx, &types.ServiceDelRequest{PodID: podID, Services: services}, ) if err != nil { return err } return nil }
go
func (c *HyperClient) DeleteService(podID string, services []*types.UserService) error { _, err := c.client.ServiceDelete( c.ctx, &types.ServiceDelRequest{PodID: podID, Services: services}, ) if err != nil { return err } return nil }
[ "func", "(", "c", "*", "HyperClient", ")", "DeleteService", "(", "podID", "string", ",", "services", "[", "]", "*", "types", ".", "UserService", ")", "error", "{", "_", ",", "err", ":=", "c", ".", "client", ".", "ServiceDelete", "(", "c", ".", "ctx", ",", "&", "types", ".", "ServiceDelRequest", "{", "PodID", ":", "podID", ",", "Services", ":", "services", "}", ",", ")", "\n\n", "if", "err", "!=", "nil", "{", "return", "err", "\n", "}", "\n", "return", "nil", "\n", "}" ]
// DeleteService deletes user service by podID and service content
[ "DeleteService", "deletes", "user", "service", "by", "podID", "and", "service", "content" ]
8a7e67dc33bbccdfc92b5e2a908bbdb1c5d9b956
https://github.com/hyperhq/hyperd/blob/8a7e67dc33bbccdfc92b5e2a908bbdb1c5d9b956/integration/client.go#L620-L630
149,909
hyperhq/hyperd
integration/client.go
ListService
func (c *HyperClient) ListService(podID string) ([]*types.UserService, error) { resp, err := c.client.ServiceList( c.ctx, &types.ServiceListRequest{PodID: podID}, ) if err != nil { return nil, err } return resp.Services, nil }
go
func (c *HyperClient) ListService(podID string) ([]*types.UserService, error) { resp, err := c.client.ServiceList( c.ctx, &types.ServiceListRequest{PodID: podID}, ) if err != nil { return nil, err } return resp.Services, nil }
[ "func", "(", "c", "*", "HyperClient", ")", "ListService", "(", "podID", "string", ")", "(", "[", "]", "*", "types", ".", "UserService", ",", "error", ")", "{", "resp", ",", "err", ":=", "c", ".", "client", ".", "ServiceList", "(", "c", ".", "ctx", ",", "&", "types", ".", "ServiceListRequest", "{", "PodID", ":", "podID", "}", ",", ")", "\n\n", "if", "err", "!=", "nil", "{", "return", "nil", ",", "err", "\n", "}", "\n\n", "return", "resp", ".", "Services", ",", "nil", "\n", "}" ]
// ListService lists user services by podID
[ "ListService", "lists", "user", "services", "by", "podID" ]
8a7e67dc33bbccdfc92b5e2a908bbdb1c5d9b956
https://github.com/hyperhq/hyperd/blob/8a7e67dc33bbccdfc92b5e2a908bbdb1c5d9b956/integration/client.go#L633-L644
149,910
hyperhq/hyperd
integration/client.go
GetPodStats
func (c *HyperClient) GetPodStats(podID string) (*types.PodStats, error) { statsResponse, err := c.client.PodStats( c.ctx, &types.PodStatsRequest{PodID: podID}, ) if err != nil { return nil, err } return statsResponse.PodStats, nil }
go
func (c *HyperClient) GetPodStats(podID string) (*types.PodStats, error) { statsResponse, err := c.client.PodStats( c.ctx, &types.PodStatsRequest{PodID: podID}, ) if err != nil { return nil, err } return statsResponse.PodStats, nil }
[ "func", "(", "c", "*", "HyperClient", ")", "GetPodStats", "(", "podID", "string", ")", "(", "*", "types", ".", "PodStats", ",", "error", ")", "{", "statsResponse", ",", "err", ":=", "c", ".", "client", ".", "PodStats", "(", "c", ".", "ctx", ",", "&", "types", ".", "PodStatsRequest", "{", "PodID", ":", "podID", "}", ",", ")", "\n\n", "if", "err", "!=", "nil", "{", "return", "nil", ",", "err", "\n", "}", "\n\n", "return", "statsResponse", ".", "PodStats", ",", "nil", "\n", "}" ]
// GetPodStats get stats of Pod by podID
[ "GetPodStats", "get", "stats", "of", "Pod", "by", "podID" ]
8a7e67dc33bbccdfc92b5e2a908bbdb1c5d9b956
https://github.com/hyperhq/hyperd/blob/8a7e67dc33bbccdfc92b5e2a908bbdb1c5d9b956/integration/client.go#L647-L658
149,911
hyperhq/hyperd
integration/client.go
AddService
func (c *HyperClient) AddService(podID string, services []*types.UserService) error { _, err := c.client.ServiceAdd( c.ctx, &types.ServiceAddRequest{PodID: podID, Services: services}, ) if err != nil { return err } return nil }
go
func (c *HyperClient) AddService(podID string, services []*types.UserService) error { _, err := c.client.ServiceAdd( c.ctx, &types.ServiceAddRequest{PodID: podID, Services: services}, ) if err != nil { return err } return nil }
[ "func", "(", "c", "*", "HyperClient", ")", "AddService", "(", "podID", "string", ",", "services", "[", "]", "*", "types", ".", "UserService", ")", "error", "{", "_", ",", "err", ":=", "c", ".", "client", ".", "ServiceAdd", "(", "c", ".", "ctx", ",", "&", "types", ".", "ServiceAddRequest", "{", "PodID", ":", "podID", ",", "Services", ":", "services", "}", ",", ")", "\n\n", "if", "err", "!=", "nil", "{", "return", "err", "\n", "}", "\n\n", "return", "nil", "\n", "}" ]
// AddService adds user service by podID and service content
[ "AddService", "adds", "user", "service", "by", "podID", "and", "service", "content" ]
8a7e67dc33bbccdfc92b5e2a908bbdb1c5d9b956
https://github.com/hyperhq/hyperd/blob/8a7e67dc33bbccdfc92b5e2a908bbdb1c5d9b956/integration/client.go#L661-L672
149,912
hyperhq/hyperd
integration/client.go
UpdateService
func (c *HyperClient) UpdateService(podID string, services []*types.UserService) error { _, err := c.client.ServiceUpdate( c.ctx, &types.ServiceUpdateRequest{PodID: podID, Services: services}, ) if err != nil { return err } return nil }
go
func (c *HyperClient) UpdateService(podID string, services []*types.UserService) error { _, err := c.client.ServiceUpdate( c.ctx, &types.ServiceUpdateRequest{PodID: podID, Services: services}, ) if err != nil { return err } return nil }
[ "func", "(", "c", "*", "HyperClient", ")", "UpdateService", "(", "podID", "string", ",", "services", "[", "]", "*", "types", ".", "UserService", ")", "error", "{", "_", ",", "err", ":=", "c", ".", "client", ".", "ServiceUpdate", "(", "c", ".", "ctx", ",", "&", "types", ".", "ServiceUpdateRequest", "{", "PodID", ":", "podID", ",", "Services", ":", "services", "}", ",", ")", "\n", "if", "err", "!=", "nil", "{", "return", "err", "\n", "}", "\n\n", "return", "nil", "\n", "}" ]
// UpdateService updates user service by podID and service content
[ "UpdateService", "updates", "user", "service", "by", "podID", "and", "service", "content" ]
8a7e67dc33bbccdfc92b5e2a908bbdb1c5d9b956
https://github.com/hyperhq/hyperd/blob/8a7e67dc33bbccdfc92b5e2a908bbdb1c5d9b956/integration/client.go#L675-L685
149,913
hyperhq/hyperd
integration/client.go
SetPodLabels
func (c *HyperClient) SetPodLabels(podID string, override bool, labels map[string]string) error { _, err := c.client.SetPodLabels( c.ctx, &types.PodLabelsRequest{PodID: podID, Override: override, Labels: labels}, ) if err != nil { return err } return nil }
go
func (c *HyperClient) SetPodLabels(podID string, override bool, labels map[string]string) error { _, err := c.client.SetPodLabels( c.ctx, &types.PodLabelsRequest{PodID: podID, Override: override, Labels: labels}, ) if err != nil { return err } return nil }
[ "func", "(", "c", "*", "HyperClient", ")", "SetPodLabels", "(", "podID", "string", ",", "override", "bool", ",", "labels", "map", "[", "string", "]", "string", ")", "error", "{", "_", ",", "err", ":=", "c", ".", "client", ".", "SetPodLabels", "(", "c", ".", "ctx", ",", "&", "types", ".", "PodLabelsRequest", "{", "PodID", ":", "podID", ",", "Override", ":", "override", ",", "Labels", ":", "labels", "}", ",", ")", "\n\n", "if", "err", "!=", "nil", "{", "return", "err", "\n", "}", "\n\n", "return", "nil", "\n", "}" ]
// SetPodLabels sets labels to Pod by podID
[ "SetPodLabels", "sets", "labels", "to", "Pod", "by", "podID" ]
8a7e67dc33bbccdfc92b5e2a908bbdb1c5d9b956
https://github.com/hyperhq/hyperd/blob/8a7e67dc33bbccdfc92b5e2a908bbdb1c5d9b956/integration/client.go#L688-L699
149,914
hyperhq/hyperd
integration/client.go
Info
func (c *HyperClient) Info() (*types.InfoResponse, error) { info, err := c.client.Info( c.ctx, &types.InfoRequest{}, ) if err != nil { return nil, err } return info, nil }
go
func (c *HyperClient) Info() (*types.InfoResponse, error) { info, err := c.client.Info( c.ctx, &types.InfoRequest{}, ) if err != nil { return nil, err } return info, nil }
[ "func", "(", "c", "*", "HyperClient", ")", "Info", "(", ")", "(", "*", "types", ".", "InfoResponse", ",", "error", ")", "{", "info", ",", "err", ":=", "c", ".", "client", ".", "Info", "(", "c", ".", "ctx", ",", "&", "types", ".", "InfoRequest", "{", "}", ",", ")", "\n\n", "if", "err", "!=", "nil", "{", "return", "nil", ",", "err", "\n", "}", "\n\n", "return", "info", ",", "nil", "\n", "}" ]
// Info gets system info of hyperd
[ "Info", "gets", "system", "info", "of", "hyperd" ]
8a7e67dc33bbccdfc92b5e2a908bbdb1c5d9b956
https://github.com/hyperhq/hyperd/blob/8a7e67dc33bbccdfc92b5e2a908bbdb1c5d9b956/integration/client.go#L702-L713
149,915
hyperhq/hyperd
integration/client.go
ContainerSignal
func (c *HyperClient) ContainerSignal(podID, containerID string, signal int64) error { _, err := c.client.ContainerSignal(c.ctx, &types.ContainerSignalRequest{ PodID: podID, ContainerID: containerID, Signal: signal, }) return err }
go
func (c *HyperClient) ContainerSignal(podID, containerID string, signal int64) error { _, err := c.client.ContainerSignal(c.ctx, &types.ContainerSignalRequest{ PodID: podID, ContainerID: containerID, Signal: signal, }) return err }
[ "func", "(", "c", "*", "HyperClient", ")", "ContainerSignal", "(", "podID", ",", "containerID", "string", ",", "signal", "int64", ")", "error", "{", "_", ",", "err", ":=", "c", ".", "client", ".", "ContainerSignal", "(", "c", ".", "ctx", ",", "&", "types", ".", "ContainerSignalRequest", "{", "PodID", ":", "podID", ",", "ContainerID", ":", "containerID", ",", "Signal", ":", "signal", ",", "}", ")", "\n\n", "return", "err", "\n", "}" ]
// ContainerSignal sends a signal to specified container of specified pod
[ "ContainerSignal", "sends", "a", "signal", "to", "specified", "container", "of", "specified", "pod" ]
8a7e67dc33bbccdfc92b5e2a908bbdb1c5d9b956
https://github.com/hyperhq/hyperd/blob/8a7e67dc33bbccdfc92b5e2a908bbdb1c5d9b956/integration/client.go#L730-L738
149,916
hyperhq/hyperd
daemon/pod/decommission.go
cleanup
func (p *XPod) cleanup() { //if removing, the remove will get the resourceLock in advance, and it will set // the pod status to NONE when it complete. // Therefore, if get into cleanup() after remove, cleanup should exit when it // got a p.resourceLock.Lock() defer p.resourceLock.Unlock() p.statusLock.Lock() if p.status == S_POD_STOPPED { p.statusLock.Unlock() return } else if p.status != S_POD_NONE { p.status = S_POD_STOPPING } p.statusLock.Unlock() err := p.decommissionResources() if err != nil { // even if error, we set the vm to be stopped p.Log(ERROR, "pod stopping failed, failed to decommit the resources: %v", err) err = nil } err = p.removeSandboxFromDB() if err != nil { p.Log(ERROR, "pod stopping failed, failed to remove sandbox persist data: %v", err) err = nil } p.Log(DEBUG, "tag pod as stopped") p.statusLock.Lock() if p.status != S_POD_NONE { p.status = S_POD_STOPPED } p.statusLock.Unlock() p.Log(INFO, "pod stopped") select { case p.stoppedChan <- true: default: } }
go
func (p *XPod) cleanup() { //if removing, the remove will get the resourceLock in advance, and it will set // the pod status to NONE when it complete. // Therefore, if get into cleanup() after remove, cleanup should exit when it // got a p.resourceLock.Lock() defer p.resourceLock.Unlock() p.statusLock.Lock() if p.status == S_POD_STOPPED { p.statusLock.Unlock() return } else if p.status != S_POD_NONE { p.status = S_POD_STOPPING } p.statusLock.Unlock() err := p.decommissionResources() if err != nil { // even if error, we set the vm to be stopped p.Log(ERROR, "pod stopping failed, failed to decommit the resources: %v", err) err = nil } err = p.removeSandboxFromDB() if err != nil { p.Log(ERROR, "pod stopping failed, failed to remove sandbox persist data: %v", err) err = nil } p.Log(DEBUG, "tag pod as stopped") p.statusLock.Lock() if p.status != S_POD_NONE { p.status = S_POD_STOPPED } p.statusLock.Unlock() p.Log(INFO, "pod stopped") select { case p.stoppedChan <- true: default: } }
[ "func", "(", "p", "*", "XPod", ")", "cleanup", "(", ")", "{", "//if removing, the remove will get the resourceLock in advance, and it will set", "// the pod status to NONE when it complete.", "// Therefore, if get into cleanup() after remove, cleanup should exit when it", "// got a", "p", ".", "resourceLock", ".", "Lock", "(", ")", "\n", "defer", "p", ".", "resourceLock", ".", "Unlock", "(", ")", "\n\n", "p", ".", "statusLock", ".", "Lock", "(", ")", "\n", "if", "p", ".", "status", "==", "S_POD_STOPPED", "{", "p", ".", "statusLock", ".", "Unlock", "(", ")", "\n", "return", "\n", "}", "else", "if", "p", ".", "status", "!=", "S_POD_NONE", "{", "p", ".", "status", "=", "S_POD_STOPPING", "\n", "}", "\n", "p", ".", "statusLock", ".", "Unlock", "(", ")", "\n\n", "err", ":=", "p", ".", "decommissionResources", "(", ")", "\n", "if", "err", "!=", "nil", "{", "// even if error, we set the vm to be stopped", "p", ".", "Log", "(", "ERROR", ",", "\"", "\"", ",", "err", ")", "\n", "err", "=", "nil", "\n", "}", "\n\n", "err", "=", "p", ".", "removeSandboxFromDB", "(", ")", "\n", "if", "err", "!=", "nil", "{", "p", ".", "Log", "(", "ERROR", ",", "\"", "\"", ",", "err", ")", "\n", "err", "=", "nil", "\n", "}", "\n\n", "p", ".", "Log", "(", "DEBUG", ",", "\"", "\"", ")", "\n", "p", ".", "statusLock", ".", "Lock", "(", ")", "\n", "if", "p", ".", "status", "!=", "S_POD_NONE", "{", "p", ".", "status", "=", "S_POD_STOPPED", "\n", "}", "\n", "p", ".", "statusLock", ".", "Unlock", "(", ")", "\n\n", "p", ".", "Log", "(", "INFO", ",", "\"", "\"", ")", "\n", "select", "{", "case", "p", ".", "stoppedChan", "<-", "true", ":", "default", ":", "}", "\n", "}" ]
//cleanup is used to cleanup the resource after VM shutdown. This method should only called by waitVMStop
[ "cleanup", "is", "used", "to", "cleanup", "the", "resource", "after", "VM", "shutdown", ".", "This", "method", "should", "only", "called", "by", "waitVMStop" ]
8a7e67dc33bbccdfc92b5e2a908bbdb1c5d9b956
https://github.com/hyperhq/hyperd/blob/8a7e67dc33bbccdfc92b5e2a908bbdb1c5d9b956/daemon/pod/decommission.go#L542-L584
149,917
hyperhq/hyperd
client/client.go
Cmd
func (cli *HyperClient) Cmd(args ...string) error { if len(args) > 1 { method, exists := cli.getMethod(args[:2]...) if exists { return method(args[2:]...) } } if len(args) > 0 { method, exists := cli.getMethod(args[0]) if !exists { fmt.Printf("%s: '%s' is not a %s command. See '%s --help'.\n", os.Args[0], args[0], os.Args[0], os.Args[0]) os.Exit(1) } return method(args[1:]...) } return cli.HyperCmdHelp() }
go
func (cli *HyperClient) Cmd(args ...string) error { if len(args) > 1 { method, exists := cli.getMethod(args[:2]...) if exists { return method(args[2:]...) } } if len(args) > 0 { method, exists := cli.getMethod(args[0]) if !exists { fmt.Printf("%s: '%s' is not a %s command. See '%s --help'.\n", os.Args[0], args[0], os.Args[0], os.Args[0]) os.Exit(1) } return method(args[1:]...) } return cli.HyperCmdHelp() }
[ "func", "(", "cli", "*", "HyperClient", ")", "Cmd", "(", "args", "...", "string", ")", "error", "{", "if", "len", "(", "args", ")", ">", "1", "{", "method", ",", "exists", ":=", "cli", ".", "getMethod", "(", "args", "[", ":", "2", "]", "...", ")", "\n", "if", "exists", "{", "return", "method", "(", "args", "[", "2", ":", "]", "...", ")", "\n", "}", "\n", "}", "\n", "if", "len", "(", "args", ")", ">", "0", "{", "method", ",", "exists", ":=", "cli", ".", "getMethod", "(", "args", "[", "0", "]", ")", "\n", "if", "!", "exists", "{", "fmt", ".", "Printf", "(", "\"", "\\n", "\"", ",", "os", ".", "Args", "[", "0", "]", ",", "args", "[", "0", "]", ",", "os", ".", "Args", "[", "0", "]", ",", "os", ".", "Args", "[", "0", "]", ")", "\n", "os", ".", "Exit", "(", "1", ")", "\n", "}", "\n", "return", "method", "(", "args", "[", "1", ":", "]", "...", ")", "\n", "}", "\n", "return", "cli", ".", "HyperCmdHelp", "(", ")", "\n", "}" ]
// Cmd executes the specified command.
[ "Cmd", "executes", "the", "specified", "command", "." ]
8a7e67dc33bbccdfc92b5e2a908bbdb1c5d9b956
https://github.com/hyperhq/hyperd/blob/8a7e67dc33bbccdfc92b5e2a908bbdb1c5d9b956/client/client.go#L86-L102
149,918
hyperhq/hyperd
utils/utils.go
FormatMountLabel
func FormatMountLabel(src, mountLabel string) string { if mountLabel != "" { switch src { case "": src = fmt.Sprintf("context=%q", mountLabel) default: src = fmt.Sprintf("%s,context=%q", src, mountLabel) } } return src }
go
func FormatMountLabel(src, mountLabel string) string { if mountLabel != "" { switch src { case "": src = fmt.Sprintf("context=%q", mountLabel) default: src = fmt.Sprintf("%s,context=%q", src, mountLabel) } } return src }
[ "func", "FormatMountLabel", "(", "src", ",", "mountLabel", "string", ")", "string", "{", "if", "mountLabel", "!=", "\"", "\"", "{", "switch", "src", "{", "case", "\"", "\"", ":", "src", "=", "fmt", ".", "Sprintf", "(", "\"", "\"", ",", "mountLabel", ")", "\n", "default", ":", "src", "=", "fmt", ".", "Sprintf", "(", "\"", "\"", ",", "src", ",", "mountLabel", ")", "\n", "}", "\n", "}", "\n", "return", "src", "\n", "}" ]
// FormatMountLabel returns a string to be used by the mount command. // The format of this string will be used to alter the labeling of the mountpoint. // The string returned is suitable to be used as the options field of the mount command. // If you need to have additional mount point options, you can pass them in as // the first parameter. Second parameter is the label that you wish to apply // to all content in the mount point.
[ "FormatMountLabel", "returns", "a", "string", "to", "be", "used", "by", "the", "mount", "command", ".", "The", "format", "of", "this", "string", "will", "be", "used", "to", "alter", "the", "labeling", "of", "the", "mountpoint", ".", "The", "string", "returned", "is", "suitable", "to", "be", "used", "as", "the", "options", "field", "of", "the", "mount", "command", ".", "If", "you", "need", "to", "have", "additional", "mount", "point", "options", "you", "can", "pass", "them", "in", "as", "the", "first", "parameter", ".", "Second", "parameter", "is", "the", "label", "that", "you", "wish", "to", "apply", "to", "all", "content", "in", "the", "mount", "point", "." ]
8a7e67dc33bbccdfc92b5e2a908bbdb1c5d9b956
https://github.com/hyperhq/hyperd/blob/8a7e67dc33bbccdfc92b5e2a908bbdb1c5d9b956/utils/utils.go#L72-L82
149,919
hyperhq/hyperd
serverrpc/info.go
PodInfo
func (s *ServerRPC) PodInfo(c context.Context, req *types.PodInfoRequest) (*types.PodInfoResponse, error) { info, err := s.daemon.GetPodInfo(req.PodID) if err != nil { return nil, err } return &types.PodInfoResponse{ PodInfo: info, }, nil }
go
func (s *ServerRPC) PodInfo(c context.Context, req *types.PodInfoRequest) (*types.PodInfoResponse, error) { info, err := s.daemon.GetPodInfo(req.PodID) if err != nil { return nil, err } return &types.PodInfoResponse{ PodInfo: info, }, nil }
[ "func", "(", "s", "*", "ServerRPC", ")", "PodInfo", "(", "c", "context", ".", "Context", ",", "req", "*", "types", ".", "PodInfoRequest", ")", "(", "*", "types", ".", "PodInfoResponse", ",", "error", ")", "{", "info", ",", "err", ":=", "s", ".", "daemon", ".", "GetPodInfo", "(", "req", ".", "PodID", ")", "\n", "if", "err", "!=", "nil", "{", "return", "nil", ",", "err", "\n", "}", "\n\n", "return", "&", "types", ".", "PodInfoResponse", "{", "PodInfo", ":", "info", ",", "}", ",", "nil", "\n", "}" ]
// PodInfo gets PodInfo by podID
[ "PodInfo", "gets", "PodInfo", "by", "podID" ]
8a7e67dc33bbccdfc92b5e2a908bbdb1c5d9b956
https://github.com/hyperhq/hyperd/blob/8a7e67dc33bbccdfc92b5e2a908bbdb1c5d9b956/serverrpc/info.go#L14-L23
149,920
hyperhq/hyperd
serverrpc/info.go
ContainerInfo
func (s *ServerRPC) ContainerInfo(c context.Context, req *types.ContainerInfoRequest) (*types.ContainerInfoResponse, error) { info, err := s.daemon.GetContainerInfo(req.Container) if err != nil { return nil, err } return &types.ContainerInfoResponse{ ContainerInfo: info, }, nil }
go
func (s *ServerRPC) ContainerInfo(c context.Context, req *types.ContainerInfoRequest) (*types.ContainerInfoResponse, error) { info, err := s.daemon.GetContainerInfo(req.Container) if err != nil { return nil, err } return &types.ContainerInfoResponse{ ContainerInfo: info, }, nil }
[ "func", "(", "s", "*", "ServerRPC", ")", "ContainerInfo", "(", "c", "context", ".", "Context", ",", "req", "*", "types", ".", "ContainerInfoRequest", ")", "(", "*", "types", ".", "ContainerInfoResponse", ",", "error", ")", "{", "info", ",", "err", ":=", "s", ".", "daemon", ".", "GetContainerInfo", "(", "req", ".", "Container", ")", "\n", "if", "err", "!=", "nil", "{", "return", "nil", ",", "err", "\n", "}", "\n\n", "return", "&", "types", ".", "ContainerInfoResponse", "{", "ContainerInfo", ":", "info", ",", "}", ",", "nil", "\n", "}" ]
// ContainerInfo gets ContainerInfo by ID or name of container
[ "ContainerInfo", "gets", "ContainerInfo", "by", "ID", "or", "name", "of", "container" ]
8a7e67dc33bbccdfc92b5e2a908bbdb1c5d9b956
https://github.com/hyperhq/hyperd/blob/8a7e67dc33bbccdfc92b5e2a908bbdb1c5d9b956/serverrpc/info.go#L26-L35
149,921
hyperhq/hyperd
serverrpc/info.go
Info
func (s *ServerRPC) Info(c context.Context, req *types.InfoRequest) (*types.InfoResponse, error) { info, err := s.daemon.CmdSystemInfo() if err != nil { return nil, err } return info, nil }
go
func (s *ServerRPC) Info(c context.Context, req *types.InfoRequest) (*types.InfoResponse, error) { info, err := s.daemon.CmdSystemInfo() if err != nil { return nil, err } return info, nil }
[ "func", "(", "s", "*", "ServerRPC", ")", "Info", "(", "c", "context", ".", "Context", ",", "req", "*", "types", ".", "InfoRequest", ")", "(", "*", "types", ".", "InfoResponse", ",", "error", ")", "{", "info", ",", "err", ":=", "s", ".", "daemon", ".", "CmdSystemInfo", "(", ")", "\n", "if", "err", "!=", "nil", "{", "return", "nil", ",", "err", "\n", "}", "\n\n", "return", "info", ",", "nil", "\n", "}" ]
// Info gets CmdSystemInfo
[ "Info", "gets", "CmdSystemInfo" ]
8a7e67dc33bbccdfc92b5e2a908bbdb1c5d9b956
https://github.com/hyperhq/hyperd/blob/8a7e67dc33bbccdfc92b5e2a908bbdb1c5d9b956/serverrpc/info.go#L38-L45
149,922
hyperhq/hyperd
serverrpc/info.go
Version
func (s *ServerRPC) Version(c context.Context, req *types.VersionRequest) (*types.VersionResponse, error) { return &types.VersionResponse{ Version: utils.VERSION, ApiVersion: GRPC_API_VERSION, }, nil }
go
func (s *ServerRPC) Version(c context.Context, req *types.VersionRequest) (*types.VersionResponse, error) { return &types.VersionResponse{ Version: utils.VERSION, ApiVersion: GRPC_API_VERSION, }, nil }
[ "func", "(", "s", "*", "ServerRPC", ")", "Version", "(", "c", "context", ".", "Context", ",", "req", "*", "types", ".", "VersionRequest", ")", "(", "*", "types", ".", "VersionResponse", ",", "error", ")", "{", "return", "&", "types", ".", "VersionResponse", "{", "Version", ":", "utils", ".", "VERSION", ",", "ApiVersion", ":", "GRPC_API_VERSION", ",", "}", ",", "nil", "\n", "}" ]
// Version gets the version and apiVersion of hyperd
[ "Version", "gets", "the", "version", "and", "apiVersion", "of", "hyperd" ]
8a7e67dc33bbccdfc92b5e2a908bbdb1c5d9b956
https://github.com/hyperhq/hyperd/blob/8a7e67dc33bbccdfc92b5e2a908bbdb1c5d9b956/serverrpc/info.go#L48-L53
149,923
hyperhq/hyperd
serverrpc/container.go
ContainerCreate
func (s *ServerRPC) ContainerCreate(ctx context.Context, req *types.ContainerCreateRequest) (*types.ContainerCreateResponse, error) { containerID, err := s.daemon.CreateContainerInPod(req.PodID, req.ContainerSpec) if err != nil { return nil, err } return &types.ContainerCreateResponse{ ContainerID: containerID, }, nil }
go
func (s *ServerRPC) ContainerCreate(ctx context.Context, req *types.ContainerCreateRequest) (*types.ContainerCreateResponse, error) { containerID, err := s.daemon.CreateContainerInPod(req.PodID, req.ContainerSpec) if err != nil { return nil, err } return &types.ContainerCreateResponse{ ContainerID: containerID, }, nil }
[ "func", "(", "s", "*", "ServerRPC", ")", "ContainerCreate", "(", "ctx", "context", ".", "Context", ",", "req", "*", "types", ".", "ContainerCreateRequest", ")", "(", "*", "types", ".", "ContainerCreateResponse", ",", "error", ")", "{", "containerID", ",", "err", ":=", "s", ".", "daemon", ".", "CreateContainerInPod", "(", "req", ".", "PodID", ",", "req", ".", "ContainerSpec", ")", "\n", "if", "err", "!=", "nil", "{", "return", "nil", ",", "err", "\n", "}", "\n\n", "return", "&", "types", ".", "ContainerCreateResponse", "{", "ContainerID", ":", "containerID", ",", "}", ",", "nil", "\n", "}" ]
// ContainerCreate creates a container by UserContainer spec
[ "ContainerCreate", "creates", "a", "container", "by", "UserContainer", "spec" ]
8a7e67dc33bbccdfc92b5e2a908bbdb1c5d9b956
https://github.com/hyperhq/hyperd/blob/8a7e67dc33bbccdfc92b5e2a908bbdb1c5d9b956/serverrpc/container.go#L9-L18
149,924
hyperhq/hyperd
serverrpc/container.go
ContainerRename
func (s *ServerRPC) ContainerRename(c context.Context, req *types.ContainerRenameRequest) (*types.ContainerRenameResponse, error) { err := s.daemon.ContainerRename(req.OldContainerName, req.NewContainerName) if err != nil { return nil, err } return &types.ContainerRenameResponse{}, nil }
go
func (s *ServerRPC) ContainerRename(c context.Context, req *types.ContainerRenameRequest) (*types.ContainerRenameResponse, error) { err := s.daemon.ContainerRename(req.OldContainerName, req.NewContainerName) if err != nil { return nil, err } return &types.ContainerRenameResponse{}, nil }
[ "func", "(", "s", "*", "ServerRPC", ")", "ContainerRename", "(", "c", "context", ".", "Context", ",", "req", "*", "types", ".", "ContainerRenameRequest", ")", "(", "*", "types", ".", "ContainerRenameResponse", ",", "error", ")", "{", "err", ":=", "s", ".", "daemon", ".", "ContainerRename", "(", "req", ".", "OldContainerName", ",", "req", ".", "NewContainerName", ")", "\n", "if", "err", "!=", "nil", "{", "return", "nil", ",", "err", "\n", "}", "\n\n", "return", "&", "types", ".", "ContainerRenameResponse", "{", "}", ",", "nil", "\n", "}" ]
// ContainerRename rename a container
[ "ContainerRename", "rename", "a", "container" ]
8a7e67dc33bbccdfc92b5e2a908bbdb1c5d9b956
https://github.com/hyperhq/hyperd/blob/8a7e67dc33bbccdfc92b5e2a908bbdb1c5d9b956/serverrpc/container.go#L40-L47
149,925
hyperhq/hyperd
serverrpc/container.go
ContainerSignal
func (s *ServerRPC) ContainerSignal(ctx context.Context, req *types.ContainerSignalRequest) (*types.ContainerSignalResponse, error) { err := s.daemon.KillPodContainers(req.PodID, req.ContainerID, req.Signal) if err != nil { return nil, err } return &types.ContainerSignalResponse{}, nil }
go
func (s *ServerRPC) ContainerSignal(ctx context.Context, req *types.ContainerSignalRequest) (*types.ContainerSignalResponse, error) { err := s.daemon.KillPodContainers(req.PodID, req.ContainerID, req.Signal) if err != nil { return nil, err } return &types.ContainerSignalResponse{}, nil }
[ "func", "(", "s", "*", "ServerRPC", ")", "ContainerSignal", "(", "ctx", "context", ".", "Context", ",", "req", "*", "types", ".", "ContainerSignalRequest", ")", "(", "*", "types", ".", "ContainerSignalResponse", ",", "error", ")", "{", "err", ":=", "s", ".", "daemon", ".", "KillPodContainers", "(", "req", ".", "PodID", ",", "req", ".", "ContainerID", ",", "req", ".", "Signal", ")", "\n", "if", "err", "!=", "nil", "{", "return", "nil", ",", "err", "\n", "}", "\n\n", "return", "&", "types", ".", "ContainerSignalResponse", "{", "}", ",", "nil", "\n", "}" ]
// ContainerSignal sends a singal to specified container of specified pod
[ "ContainerSignal", "sends", "a", "singal", "to", "specified", "container", "of", "specified", "pod" ]
8a7e67dc33bbccdfc92b5e2a908bbdb1c5d9b956
https://github.com/hyperhq/hyperd/blob/8a7e67dc33bbccdfc92b5e2a908bbdb1c5d9b956/serverrpc/container.go#L59-L66
149,926
hyperhq/hyperd
daemon/daemonbuilder/builder.go
Pull
func (d Docker) Pull(name string) (builder.Image, error) { ref, err := reference.ParseNamed(name) if err != nil { return nil, err } ref = reference.WithDefaultTag(ref) pullRegistryAuth := &types.AuthConfig{} if len(d.AuthConfigs) > 0 { // The request came with a full auth config file, we prefer to use that repoInfo, err := d.Daemon.RegistryService.ResolveRepository(ref) if err != nil { return nil, err } resolvedConfig := registry.ResolveAuthConfig( d.AuthConfigs, repoInfo.Index, ) pullRegistryAuth = &resolvedConfig } if err := d.Daemon.PullImage(ref, nil, pullRegistryAuth, ioutils.NopWriteCloser(d.OutOld)); err != nil { return nil, err } return d.GetImage(name) }
go
func (d Docker) Pull(name string) (builder.Image, error) { ref, err := reference.ParseNamed(name) if err != nil { return nil, err } ref = reference.WithDefaultTag(ref) pullRegistryAuth := &types.AuthConfig{} if len(d.AuthConfigs) > 0 { // The request came with a full auth config file, we prefer to use that repoInfo, err := d.Daemon.RegistryService.ResolveRepository(ref) if err != nil { return nil, err } resolvedConfig := registry.ResolveAuthConfig( d.AuthConfigs, repoInfo.Index, ) pullRegistryAuth = &resolvedConfig } if err := d.Daemon.PullImage(ref, nil, pullRegistryAuth, ioutils.NopWriteCloser(d.OutOld)); err != nil { return nil, err } return d.GetImage(name) }
[ "func", "(", "d", "Docker", ")", "Pull", "(", "name", "string", ")", "(", "builder", ".", "Image", ",", "error", ")", "{", "ref", ",", "err", ":=", "reference", ".", "ParseNamed", "(", "name", ")", "\n", "if", "err", "!=", "nil", "{", "return", "nil", ",", "err", "\n", "}", "\n", "ref", "=", "reference", ".", "WithDefaultTag", "(", "ref", ")", "\n\n", "pullRegistryAuth", ":=", "&", "types", ".", "AuthConfig", "{", "}", "\n", "if", "len", "(", "d", ".", "AuthConfigs", ")", ">", "0", "{", "// The request came with a full auth config file, we prefer to use that", "repoInfo", ",", "err", ":=", "d", ".", "Daemon", ".", "RegistryService", ".", "ResolveRepository", "(", "ref", ")", "\n", "if", "err", "!=", "nil", "{", "return", "nil", ",", "err", "\n", "}", "\n\n", "resolvedConfig", ":=", "registry", ".", "ResolveAuthConfig", "(", "d", ".", "AuthConfigs", ",", "repoInfo", ".", "Index", ",", ")", "\n", "pullRegistryAuth", "=", "&", "resolvedConfig", "\n", "}", "\n\n", "if", "err", ":=", "d", ".", "Daemon", ".", "PullImage", "(", "ref", ",", "nil", ",", "pullRegistryAuth", ",", "ioutils", ".", "NopWriteCloser", "(", "d", ".", "OutOld", ")", ")", ";", "err", "!=", "nil", "{", "return", "nil", ",", "err", "\n", "}", "\n", "return", "d", ".", "GetImage", "(", "name", ")", "\n", "}" ]
// Pull tells Docker to pull image referenced by `name`.
[ "Pull", "tells", "Docker", "to", "pull", "image", "referenced", "by", "name", "." ]
8a7e67dc33bbccdfc92b5e2a908bbdb1c5d9b956
https://github.com/hyperhq/hyperd/blob/8a7e67dc33bbccdfc92b5e2a908bbdb1c5d9b956/daemon/daemonbuilder/builder.go#L49-L75
149,927
hyperhq/hyperd
daemon/daemonbuilder/builder.go
GetImage
func (d Docker) GetImage(name string) (builder.Image, error) { img, err := d.Daemon.GetImage(name) if err != nil { return nil, err } return imgWrap{img}, nil }
go
func (d Docker) GetImage(name string) (builder.Image, error) { img, err := d.Daemon.GetImage(name) if err != nil { return nil, err } return imgWrap{img}, nil }
[ "func", "(", "d", "Docker", ")", "GetImage", "(", "name", "string", ")", "(", "builder", ".", "Image", ",", "error", ")", "{", "img", ",", "err", ":=", "d", ".", "Daemon", ".", "GetImage", "(", "name", ")", "\n", "if", "err", "!=", "nil", "{", "return", "nil", ",", "err", "\n", "}", "\n", "return", "imgWrap", "{", "img", "}", ",", "nil", "\n", "}" ]
// GetImage looks up a Docker image referenced by `name`.
[ "GetImage", "looks", "up", "a", "Docker", "image", "referenced", "by", "name", "." ]
8a7e67dc33bbccdfc92b5e2a908bbdb1c5d9b956
https://github.com/hyperhq/hyperd/blob/8a7e67dc33bbccdfc92b5e2a908bbdb1c5d9b956/daemon/daemonbuilder/builder.go#L78-L84
149,928
hyperhq/hyperd
daemon/daemonbuilder/builder.go
ContainerUpdateCmd
func (d Docker) ContainerUpdateCmd(cID string, cmd []string) error { c, err := d.Daemon.GetContainer(cID) if err != nil { return err } c.Path = cmd[0] c.Args = cmd[1:] return nil }
go
func (d Docker) ContainerUpdateCmd(cID string, cmd []string) error { c, err := d.Daemon.GetContainer(cID) if err != nil { return err } c.Path = cmd[0] c.Args = cmd[1:] return nil }
[ "func", "(", "d", "Docker", ")", "ContainerUpdateCmd", "(", "cID", "string", ",", "cmd", "[", "]", "string", ")", "error", "{", "c", ",", "err", ":=", "d", ".", "Daemon", ".", "GetContainer", "(", "cID", ")", "\n", "if", "err", "!=", "nil", "{", "return", "err", "\n", "}", "\n", "c", ".", "Path", "=", "cmd", "[", "0", "]", "\n", "c", ".", "Args", "=", "cmd", "[", "1", ":", "]", "\n", "return", "nil", "\n", "}" ]
// ContainerUpdateCmd updates Path and Args for the container with ID cID.
[ "ContainerUpdateCmd", "updates", "Path", "and", "Args", "for", "the", "container", "with", "ID", "cID", "." ]
8a7e67dc33bbccdfc92b5e2a908bbdb1c5d9b956
https://github.com/hyperhq/hyperd/blob/8a7e67dc33bbccdfc92b5e2a908bbdb1c5d9b956/daemon/daemonbuilder/builder.go#L87-L95
149,929
hyperhq/hyperd
daemon/daemonbuilder/builder.go
GetCachedImage
func (d Docker) GetCachedImage(imgID string, cfg *container.Config) (string, error) { cache, err := d.Daemon.ImageGetCached(image.ID(imgID), cfg) if cache == nil || err != nil { return "", err } return cache.ID().String(), nil }
go
func (d Docker) GetCachedImage(imgID string, cfg *container.Config) (string, error) { cache, err := d.Daemon.ImageGetCached(image.ID(imgID), cfg) if cache == nil || err != nil { return "", err } return cache.ID().String(), nil }
[ "func", "(", "d", "Docker", ")", "GetCachedImage", "(", "imgID", "string", ",", "cfg", "*", "container", ".", "Config", ")", "(", "string", ",", "error", ")", "{", "cache", ",", "err", ":=", "d", ".", "Daemon", ".", "ImageGetCached", "(", "image", ".", "ID", "(", "imgID", ")", ",", "cfg", ")", "\n", "if", "cache", "==", "nil", "||", "err", "!=", "nil", "{", "return", "\"", "\"", ",", "err", "\n", "}", "\n", "return", "cache", ".", "ID", "(", ")", ".", "String", "(", ")", ",", "nil", "\n", "}" ]
// GetCachedImage returns a reference to a cached image whose parent equals `parent` // and runconfig equals `cfg`. A cache miss is expected to return an empty ID and a nil error.
[ "GetCachedImage", "returns", "a", "reference", "to", "a", "cached", "image", "whose", "parent", "equals", "parent", "and", "runconfig", "equals", "cfg", ".", "A", "cache", "miss", "is", "expected", "to", "return", "an", "empty", "ID", "and", "a", "nil", "error", "." ]
8a7e67dc33bbccdfc92b5e2a908bbdb1c5d9b956
https://github.com/hyperhq/hyperd/blob/8a7e67dc33bbccdfc92b5e2a908bbdb1c5d9b956/daemon/daemonbuilder/builder.go#L99-L105
149,930
hyperhq/hyperd
daemon/pod/migration.go
MigrateLagecyPersistentData
func MigrateLagecyPersistentData(db *daemondb.DaemonDB, podFactory func() *PodFactory) (err error) { num := 0 count := 0 defer func() { logInfo := fmt.Sprintf("Migrate lagecy persistent pod data, found: %d, migrated: %d", num, count) if err == nil { hlog.Log(INFO, logInfo) } else { hlog.Log(ERROR, "%s, but failed with %v", logInfo, err) } }() list, err := db.LagecyListPod() if err != nil { return err } num = len(list) if num == 0 { return nil } ch := db.LagecyGetAllPods() if ch == nil { err = fmt.Errorf("cannot list pods in daemondb") return err } for { item, ok := <-ch if !ok { break } if item == nil { err = fmt.Errorf("error during get pods from daemondb") return err } podID := string(item.K[4:]) hlog.Log(TRACE, "try to migrate lagecy pod %s from daemondb", podID) var podSpec apitypes.UserPod if err = json.Unmarshal(item.V, &podSpec); err != nil { return err } factory := podFactory() // fill in corresponding container id in pod spec if err = setupContanerID(factory, podID, &podSpec); err != nil { return err } // convert some lagecy volume field to current format if err = setupVolumes(factory.db, podID, item.V, &podSpec); err != nil { return err } if err = persistLagecyPod(factory, &podSpec); err != nil { return err } var vmID string if vmID, err = db.LagecyGetP2V(podID); err != nil { hlog.Log(DEBUG, "no existing VM for pod %s: %v", podID, err) } else { var vmData []byte if vmData, err = db.LagecyGetVM(vmID); err != nil { return err } // save sandbox data in current layout sandboxInfo := types.SandboxPersistInfo{ Id: vmID, PersistInfo: vmData, } err = saveMessage(db, fmt.Sprintf(SB_KEY_FMT, podSpec.Id), &sandboxInfo, nil, "sandbox info") if err != nil { return err } } errs := purgeLagecyPersistPod(db, podID) if len(errs) != 0 { hlog.Log(DEBUG, "%v", errs) } count++ } return nil }
go
func MigrateLagecyPersistentData(db *daemondb.DaemonDB, podFactory func() *PodFactory) (err error) { num := 0 count := 0 defer func() { logInfo := fmt.Sprintf("Migrate lagecy persistent pod data, found: %d, migrated: %d", num, count) if err == nil { hlog.Log(INFO, logInfo) } else { hlog.Log(ERROR, "%s, but failed with %v", logInfo, err) } }() list, err := db.LagecyListPod() if err != nil { return err } num = len(list) if num == 0 { return nil } ch := db.LagecyGetAllPods() if ch == nil { err = fmt.Errorf("cannot list pods in daemondb") return err } for { item, ok := <-ch if !ok { break } if item == nil { err = fmt.Errorf("error during get pods from daemondb") return err } podID := string(item.K[4:]) hlog.Log(TRACE, "try to migrate lagecy pod %s from daemondb", podID) var podSpec apitypes.UserPod if err = json.Unmarshal(item.V, &podSpec); err != nil { return err } factory := podFactory() // fill in corresponding container id in pod spec if err = setupContanerID(factory, podID, &podSpec); err != nil { return err } // convert some lagecy volume field to current format if err = setupVolumes(factory.db, podID, item.V, &podSpec); err != nil { return err } if err = persistLagecyPod(factory, &podSpec); err != nil { return err } var vmID string if vmID, err = db.LagecyGetP2V(podID); err != nil { hlog.Log(DEBUG, "no existing VM for pod %s: %v", podID, err) } else { var vmData []byte if vmData, err = db.LagecyGetVM(vmID); err != nil { return err } // save sandbox data in current layout sandboxInfo := types.SandboxPersistInfo{ Id: vmID, PersistInfo: vmData, } err = saveMessage(db, fmt.Sprintf(SB_KEY_FMT, podSpec.Id), &sandboxInfo, nil, "sandbox info") if err != nil { return err } } errs := purgeLagecyPersistPod(db, podID) if len(errs) != 0 { hlog.Log(DEBUG, "%v", errs) } count++ } return nil }
[ "func", "MigrateLagecyPersistentData", "(", "db", "*", "daemondb", ".", "DaemonDB", ",", "podFactory", "func", "(", ")", "*", "PodFactory", ")", "(", "err", "error", ")", "{", "num", ":=", "0", "\n", "count", ":=", "0", "\n", "defer", "func", "(", ")", "{", "logInfo", ":=", "fmt", ".", "Sprintf", "(", "\"", "\"", ",", "num", ",", "count", ")", "\n", "if", "err", "==", "nil", "{", "hlog", ".", "Log", "(", "INFO", ",", "logInfo", ")", "\n", "}", "else", "{", "hlog", ".", "Log", "(", "ERROR", ",", "\"", "\"", ",", "logInfo", ",", "err", ")", "\n", "}", "\n", "}", "(", ")", "\n", "list", ",", "err", ":=", "db", ".", "LagecyListPod", "(", ")", "\n", "if", "err", "!=", "nil", "{", "return", "err", "\n", "}", "\n", "num", "=", "len", "(", "list", ")", "\n", "if", "num", "==", "0", "{", "return", "nil", "\n", "}", "\n", "ch", ":=", "db", ".", "LagecyGetAllPods", "(", ")", "\n", "if", "ch", "==", "nil", "{", "err", "=", "fmt", ".", "Errorf", "(", "\"", "\"", ")", "\n", "return", "err", "\n", "}", "\n", "for", "{", "item", ",", "ok", ":=", "<-", "ch", "\n", "if", "!", "ok", "{", "break", "\n", "}", "\n", "if", "item", "==", "nil", "{", "err", "=", "fmt", ".", "Errorf", "(", "\"", "\"", ")", "\n", "return", "err", "\n", "}", "\n\n", "podID", ":=", "string", "(", "item", ".", "K", "[", "4", ":", "]", ")", "\n\n", "hlog", ".", "Log", "(", "TRACE", ",", "\"", "\"", ",", "podID", ")", "\n\n", "var", "podSpec", "apitypes", ".", "UserPod", "\n", "if", "err", "=", "json", ".", "Unmarshal", "(", "item", ".", "V", ",", "&", "podSpec", ")", ";", "err", "!=", "nil", "{", "return", "err", "\n", "}", "\n\n", "factory", ":=", "podFactory", "(", ")", "\n\n", "// fill in corresponding container id in pod spec", "if", "err", "=", "setupContanerID", "(", "factory", ",", "podID", ",", "&", "podSpec", ")", ";", "err", "!=", "nil", "{", "return", "err", "\n", "}", "\n", "// convert some lagecy volume field to current format", "if", "err", "=", "setupVolumes", "(", "factory", ".", "db", ",", "podID", ",", "item", ".", "V", ",", "&", "podSpec", ")", ";", "err", "!=", "nil", "{", "return", "err", "\n", "}", "\n\n", "if", "err", "=", "persistLagecyPod", "(", "factory", ",", "&", "podSpec", ")", ";", "err", "!=", "nil", "{", "return", "err", "\n", "}", "\n\n", "var", "vmID", "string", "\n", "if", "vmID", ",", "err", "=", "db", ".", "LagecyGetP2V", "(", "podID", ")", ";", "err", "!=", "nil", "{", "hlog", ".", "Log", "(", "DEBUG", ",", "\"", "\"", ",", "podID", ",", "err", ")", "\n", "}", "else", "{", "var", "vmData", "[", "]", "byte", "\n", "if", "vmData", ",", "err", "=", "db", ".", "LagecyGetVM", "(", "vmID", ")", ";", "err", "!=", "nil", "{", "return", "err", "\n", "}", "\n", "// save sandbox data in current layout", "sandboxInfo", ":=", "types", ".", "SandboxPersistInfo", "{", "Id", ":", "vmID", ",", "PersistInfo", ":", "vmData", ",", "}", "\n", "err", "=", "saveMessage", "(", "db", ",", "fmt", ".", "Sprintf", "(", "SB_KEY_FMT", ",", "podSpec", ".", "Id", ")", ",", "&", "sandboxInfo", ",", "nil", ",", "\"", "\"", ")", "\n", "if", "err", "!=", "nil", "{", "return", "err", "\n", "}", "\n", "}", "\n\n", "errs", ":=", "purgeLagecyPersistPod", "(", "db", ",", "podID", ")", "\n", "if", "len", "(", "errs", ")", "!=", "0", "{", "hlog", ".", "Log", "(", "DEBUG", ",", "\"", "\"", ",", "errs", ")", "\n", "}", "\n", "count", "++", "\n", "}", "\n", "return", "nil", "\n", "}" ]
// MigrateLagecyData migrate lagecy persistence data to current layout.
[ "MigrateLagecyData", "migrate", "lagecy", "persistence", "data", "to", "current", "layout", "." ]
8a7e67dc33bbccdfc92b5e2a908bbdb1c5d9b956
https://github.com/hyperhq/hyperd/blob/8a7e67dc33bbccdfc92b5e2a908bbdb1c5d9b956/daemon/pod/migration.go#L17-L101
149,931
hyperhq/hyperd
serverrpc/portmapping.go
PortMappingList
func (s *ServerRPC) PortMappingList(ctx context.Context, req *types.PortMappingListRequest) (*types.PortMappingListResponse, error) { p, ok := s.daemon.PodList.Get(req.PodID) if !ok { return nil, fmt.Errorf("Pod not found") } return &types.PortMappingListResponse{ PortMappings: p.ListPortMappings(), }, nil }
go
func (s *ServerRPC) PortMappingList(ctx context.Context, req *types.PortMappingListRequest) (*types.PortMappingListResponse, error) { p, ok := s.daemon.PodList.Get(req.PodID) if !ok { return nil, fmt.Errorf("Pod not found") } return &types.PortMappingListResponse{ PortMappings: p.ListPortMappings(), }, nil }
[ "func", "(", "s", "*", "ServerRPC", ")", "PortMappingList", "(", "ctx", "context", ".", "Context", ",", "req", "*", "types", ".", "PortMappingListRequest", ")", "(", "*", "types", ".", "PortMappingListResponse", ",", "error", ")", "{", "p", ",", "ok", ":=", "s", ".", "daemon", ".", "PodList", ".", "Get", "(", "req", ".", "PodID", ")", "\n", "if", "!", "ok", "{", "return", "nil", ",", "fmt", ".", "Errorf", "(", "\"", "\"", ")", "\n", "}", "\n\n", "return", "&", "types", ".", "PortMappingListResponse", "{", "PortMappings", ":", "p", ".", "ListPortMappings", "(", ")", ",", "}", ",", "nil", "\n", "}" ]
// PortMappingList get a list of PortMappings
[ "PortMappingList", "get", "a", "list", "of", "PortMappings" ]
8a7e67dc33bbccdfc92b5e2a908bbdb1c5d9b956
https://github.com/hyperhq/hyperd/blob/8a7e67dc33bbccdfc92b5e2a908bbdb1c5d9b956/serverrpc/portmapping.go#L10-L19
149,932
hyperhq/hyperd
serverrpc/portmapping.go
PortMappingDel
func (s *ServerRPC) PortMappingDel(ctx context.Context, req *types.PortMappingModifyRequest) (*types.PortMappingModifyResponse, error) { p, ok := s.daemon.PodList.Get(req.PodID) if !ok { return nil, fmt.Errorf("Pod not found") } err := p.RemovePortMappingByDest(req.PortMappings) if err != nil { return nil, fmt.Errorf("p.RemovePortMappingByDest error: %v", err) } return &types.PortMappingModifyResponse{}, nil }
go
func (s *ServerRPC) PortMappingDel(ctx context.Context, req *types.PortMappingModifyRequest) (*types.PortMappingModifyResponse, error) { p, ok := s.daemon.PodList.Get(req.PodID) if !ok { return nil, fmt.Errorf("Pod not found") } err := p.RemovePortMappingByDest(req.PortMappings) if err != nil { return nil, fmt.Errorf("p.RemovePortMappingByDest error: %v", err) } return &types.PortMappingModifyResponse{}, nil }
[ "func", "(", "s", "*", "ServerRPC", ")", "PortMappingDel", "(", "ctx", "context", ".", "Context", ",", "req", "*", "types", ".", "PortMappingModifyRequest", ")", "(", "*", "types", ".", "PortMappingModifyResponse", ",", "error", ")", "{", "p", ",", "ok", ":=", "s", ".", "daemon", ".", "PodList", ".", "Get", "(", "req", ".", "PodID", ")", "\n", "if", "!", "ok", "{", "return", "nil", ",", "fmt", ".", "Errorf", "(", "\"", "\"", ")", "\n", "}", "\n\n", "err", ":=", "p", ".", "RemovePortMappingByDest", "(", "req", ".", "PortMappings", ")", "\n", "if", "err", "!=", "nil", "{", "return", "nil", ",", "fmt", ".", "Errorf", "(", "\"", "\"", ",", "err", ")", "\n", "}", "\n\n", "return", "&", "types", ".", "PortMappingModifyResponse", "{", "}", ",", "nil", "\n", "}" ]
// PortMappingDel remove a list of PortMapping rules from a Pod
[ "PortMappingDel", "remove", "a", "list", "of", "PortMapping", "rules", "from", "a", "Pod" ]
8a7e67dc33bbccdfc92b5e2a908bbdb1c5d9b956
https://github.com/hyperhq/hyperd/blob/8a7e67dc33bbccdfc92b5e2a908bbdb1c5d9b956/serverrpc/portmapping.go#L37-L49
149,933
hyperhq/hyperd
server/middleware.go
debugRequestMiddleware
func debugRequestMiddleware(handler httputils.APIFunc) httputils.APIFunc { return func(ctx context.Context, w http.ResponseWriter, r *http.Request, vars map[string]string) error { glog.V(3).Infof("%s %s", r.Method, r.RequestURI) if r.Method != "POST" { return handler(ctx, w, r, vars) } if err := httputils.CheckForJSON(r); err != nil { return handler(ctx, w, r, vars) } maxBodySize := 4096 // 4KB if r.ContentLength > int64(maxBodySize) { return handler(ctx, w, r, vars) } body := r.Body bufReader := bufio.NewReaderSize(body, maxBodySize) r.Body = ioutils.NewReadCloserWrapper(bufReader, func() error { return body.Close() }) b, err := bufReader.Peek(maxBodySize) if err != io.EOF { // either there was an error reading, or the buffer is full (in which case the request is too large) return handler(ctx, w, r, vars) } var postForm map[string]interface{} if err := json.Unmarshal(b, &postForm); err == nil { if _, exists := postForm["password"]; exists { postForm["password"] = "*****" } formStr, errMarshal := json.Marshal(postForm) if errMarshal == nil { glog.V(3).Infof("form data: %s", string(formStr)) } else { glog.V(3).Infof("form data: %q", postForm) } } return handler(ctx, w, r, vars) } }
go
func debugRequestMiddleware(handler httputils.APIFunc) httputils.APIFunc { return func(ctx context.Context, w http.ResponseWriter, r *http.Request, vars map[string]string) error { glog.V(3).Infof("%s %s", r.Method, r.RequestURI) if r.Method != "POST" { return handler(ctx, w, r, vars) } if err := httputils.CheckForJSON(r); err != nil { return handler(ctx, w, r, vars) } maxBodySize := 4096 // 4KB if r.ContentLength > int64(maxBodySize) { return handler(ctx, w, r, vars) } body := r.Body bufReader := bufio.NewReaderSize(body, maxBodySize) r.Body = ioutils.NewReadCloserWrapper(bufReader, func() error { return body.Close() }) b, err := bufReader.Peek(maxBodySize) if err != io.EOF { // either there was an error reading, or the buffer is full (in which case the request is too large) return handler(ctx, w, r, vars) } var postForm map[string]interface{} if err := json.Unmarshal(b, &postForm); err == nil { if _, exists := postForm["password"]; exists { postForm["password"] = "*****" } formStr, errMarshal := json.Marshal(postForm) if errMarshal == nil { glog.V(3).Infof("form data: %s", string(formStr)) } else { glog.V(3).Infof("form data: %q", postForm) } } return handler(ctx, w, r, vars) } }
[ "func", "debugRequestMiddleware", "(", "handler", "httputils", ".", "APIFunc", ")", "httputils", ".", "APIFunc", "{", "return", "func", "(", "ctx", "context", ".", "Context", ",", "w", "http", ".", "ResponseWriter", ",", "r", "*", "http", ".", "Request", ",", "vars", "map", "[", "string", "]", "string", ")", "error", "{", "glog", ".", "V", "(", "3", ")", ".", "Infof", "(", "\"", "\"", ",", "r", ".", "Method", ",", "r", ".", "RequestURI", ")", "\n\n", "if", "r", ".", "Method", "!=", "\"", "\"", "{", "return", "handler", "(", "ctx", ",", "w", ",", "r", ",", "vars", ")", "\n", "}", "\n", "if", "err", ":=", "httputils", ".", "CheckForJSON", "(", "r", ")", ";", "err", "!=", "nil", "{", "return", "handler", "(", "ctx", ",", "w", ",", "r", ",", "vars", ")", "\n", "}", "\n", "maxBodySize", ":=", "4096", "// 4KB", "\n", "if", "r", ".", "ContentLength", ">", "int64", "(", "maxBodySize", ")", "{", "return", "handler", "(", "ctx", ",", "w", ",", "r", ",", "vars", ")", "\n", "}", "\n\n", "body", ":=", "r", ".", "Body", "\n", "bufReader", ":=", "bufio", ".", "NewReaderSize", "(", "body", ",", "maxBodySize", ")", "\n", "r", ".", "Body", "=", "ioutils", ".", "NewReadCloserWrapper", "(", "bufReader", ",", "func", "(", ")", "error", "{", "return", "body", ".", "Close", "(", ")", "}", ")", "\n\n", "b", ",", "err", ":=", "bufReader", ".", "Peek", "(", "maxBodySize", ")", "\n", "if", "err", "!=", "io", ".", "EOF", "{", "// either there was an error reading, or the buffer is full (in which case the request is too large)", "return", "handler", "(", "ctx", ",", "w", ",", "r", ",", "vars", ")", "\n", "}", "\n\n", "var", "postForm", "map", "[", "string", "]", "interface", "{", "}", "\n", "if", "err", ":=", "json", ".", "Unmarshal", "(", "b", ",", "&", "postForm", ")", ";", "err", "==", "nil", "{", "if", "_", ",", "exists", ":=", "postForm", "[", "\"", "\"", "]", ";", "exists", "{", "postForm", "[", "\"", "\"", "]", "=", "\"", "\"", "\n", "}", "\n", "formStr", ",", "errMarshal", ":=", "json", ".", "Marshal", "(", "postForm", ")", "\n", "if", "errMarshal", "==", "nil", "{", "glog", ".", "V", "(", "3", ")", ".", "Infof", "(", "\"", "\"", ",", "string", "(", "formStr", ")", ")", "\n", "}", "else", "{", "glog", ".", "V", "(", "3", ")", ".", "Infof", "(", "\"", "\"", ",", "postForm", ")", "\n", "}", "\n", "}", "\n\n", "return", "handler", "(", "ctx", ",", "w", ",", "r", ",", "vars", ")", "\n", "}", "\n", "}" ]
// debugRequestMiddleware dumps the request to logger
[ "debugRequestMiddleware", "dumps", "the", "request", "to", "logger" ]
8a7e67dc33bbccdfc92b5e2a908bbdb1c5d9b956
https://github.com/hyperhq/hyperd/blob/8a7e67dc33bbccdfc92b5e2a908bbdb1c5d9b956/server/middleware.go#L27-L67
149,934
hyperhq/hyperd
server/middleware.go
authorizationMiddleware
func (s *Server) authorizationMiddleware(handler httputils.APIFunc) httputils.APIFunc { return func(ctx context.Context, w http.ResponseWriter, r *http.Request, vars map[string]string) error { // FIXME: fill when authN gets in // User and UserAuthNMethod are taken from AuthN plugins // Currently tracked in https://github.com/docker/docker/pull/13994 user := "" userAuthNMethod := "" authCtx := authorization.NewCtx(s.authZPlugins, user, userAuthNMethod, r.Method, r.RequestURI) if err := authCtx.AuthZRequest(w, r); err != nil { glog.Errorf("AuthZRequest for %s %s returned error: %s", r.Method, r.RequestURI, err) return err } rw := authorization.NewResponseModifier(w) if err := handler(ctx, rw, r, vars); err != nil { glog.Errorf("Handler for %s %s returned error: %s", r.Method, r.RequestURI, err) return err } if err := authCtx.AuthZResponse(rw, r); err != nil { glog.Errorf("AuthZResponse for %s %s returned error: %s", r.Method, r.RequestURI, err) return err } return nil } }
go
func (s *Server) authorizationMiddleware(handler httputils.APIFunc) httputils.APIFunc { return func(ctx context.Context, w http.ResponseWriter, r *http.Request, vars map[string]string) error { // FIXME: fill when authN gets in // User and UserAuthNMethod are taken from AuthN plugins // Currently tracked in https://github.com/docker/docker/pull/13994 user := "" userAuthNMethod := "" authCtx := authorization.NewCtx(s.authZPlugins, user, userAuthNMethod, r.Method, r.RequestURI) if err := authCtx.AuthZRequest(w, r); err != nil { glog.Errorf("AuthZRequest for %s %s returned error: %s", r.Method, r.RequestURI, err) return err } rw := authorization.NewResponseModifier(w) if err := handler(ctx, rw, r, vars); err != nil { glog.Errorf("Handler for %s %s returned error: %s", r.Method, r.RequestURI, err) return err } if err := authCtx.AuthZResponse(rw, r); err != nil { glog.Errorf("AuthZResponse for %s %s returned error: %s", r.Method, r.RequestURI, err) return err } return nil } }
[ "func", "(", "s", "*", "Server", ")", "authorizationMiddleware", "(", "handler", "httputils", ".", "APIFunc", ")", "httputils", ".", "APIFunc", "{", "return", "func", "(", "ctx", "context", ".", "Context", ",", "w", "http", ".", "ResponseWriter", ",", "r", "*", "http", ".", "Request", ",", "vars", "map", "[", "string", "]", "string", ")", "error", "{", "// FIXME: fill when authN gets in", "// User and UserAuthNMethod are taken from AuthN plugins", "// Currently tracked in https://github.com/docker/docker/pull/13994", "user", ":=", "\"", "\"", "\n", "userAuthNMethod", ":=", "\"", "\"", "\n", "authCtx", ":=", "authorization", ".", "NewCtx", "(", "s", ".", "authZPlugins", ",", "user", ",", "userAuthNMethod", ",", "r", ".", "Method", ",", "r", ".", "RequestURI", ")", "\n\n", "if", "err", ":=", "authCtx", ".", "AuthZRequest", "(", "w", ",", "r", ")", ";", "err", "!=", "nil", "{", "glog", ".", "Errorf", "(", "\"", "\"", ",", "r", ".", "Method", ",", "r", ".", "RequestURI", ",", "err", ")", "\n", "return", "err", "\n", "}", "\n\n", "rw", ":=", "authorization", ".", "NewResponseModifier", "(", "w", ")", "\n\n", "if", "err", ":=", "handler", "(", "ctx", ",", "rw", ",", "r", ",", "vars", ")", ";", "err", "!=", "nil", "{", "glog", ".", "Errorf", "(", "\"", "\"", ",", "r", ".", "Method", ",", "r", ".", "RequestURI", ",", "err", ")", "\n", "return", "err", "\n", "}", "\n\n", "if", "err", ":=", "authCtx", ".", "AuthZResponse", "(", "rw", ",", "r", ")", ";", "err", "!=", "nil", "{", "glog", ".", "Errorf", "(", "\"", "\"", ",", "r", ".", "Method", ",", "r", ".", "RequestURI", ",", "err", ")", "\n", "return", "err", "\n", "}", "\n", "return", "nil", "\n", "}", "\n", "}" ]
// authorizationMiddleware perform authorization on the request.
[ "authorizationMiddleware", "perform", "authorization", "on", "the", "request", "." ]
8a7e67dc33bbccdfc92b5e2a908bbdb1c5d9b956
https://github.com/hyperhq/hyperd/blob/8a7e67dc33bbccdfc92b5e2a908bbdb1c5d9b956/server/middleware.go#L70-L97
149,935
hyperhq/hyperd
server/middleware.go
userAgentMiddleware
func (s *Server) userAgentMiddleware(handler httputils.APIFunc) httputils.APIFunc { return func(ctx context.Context, w http.ResponseWriter, r *http.Request, vars map[string]string) error { if strings.Contains(r.Header.Get("User-Agent"), "Docker-Client/") { dockerVersion := version.Version(s.cfg.Version) userAgent := strings.Split(r.Header.Get("User-Agent"), "/") // v1.20 onwards includes the GOOS of the client after the version // such as Docker/1.7.0 (linux) if len(userAgent) == 2 && strings.Contains(userAgent[1], " ") { userAgent[1] = strings.Split(userAgent[1], " ")[0] } if len(userAgent) == 2 && !dockerVersion.Equal(version.Version(userAgent[1])) { glog.V(3).Infof("Warning: client and server don't have the same version (client: %s, server: %s)", userAgent[1], dockerVersion) } } return handler(ctx, w, r, vars) } }
go
func (s *Server) userAgentMiddleware(handler httputils.APIFunc) httputils.APIFunc { return func(ctx context.Context, w http.ResponseWriter, r *http.Request, vars map[string]string) error { if strings.Contains(r.Header.Get("User-Agent"), "Docker-Client/") { dockerVersion := version.Version(s.cfg.Version) userAgent := strings.Split(r.Header.Get("User-Agent"), "/") // v1.20 onwards includes the GOOS of the client after the version // such as Docker/1.7.0 (linux) if len(userAgent) == 2 && strings.Contains(userAgent[1], " ") { userAgent[1] = strings.Split(userAgent[1], " ")[0] } if len(userAgent) == 2 && !dockerVersion.Equal(version.Version(userAgent[1])) { glog.V(3).Infof("Warning: client and server don't have the same version (client: %s, server: %s)", userAgent[1], dockerVersion) } } return handler(ctx, w, r, vars) } }
[ "func", "(", "s", "*", "Server", ")", "userAgentMiddleware", "(", "handler", "httputils", ".", "APIFunc", ")", "httputils", ".", "APIFunc", "{", "return", "func", "(", "ctx", "context", ".", "Context", ",", "w", "http", ".", "ResponseWriter", ",", "r", "*", "http", ".", "Request", ",", "vars", "map", "[", "string", "]", "string", ")", "error", "{", "if", "strings", ".", "Contains", "(", "r", ".", "Header", ".", "Get", "(", "\"", "\"", ")", ",", "\"", "\"", ")", "{", "dockerVersion", ":=", "version", ".", "Version", "(", "s", ".", "cfg", ".", "Version", ")", "\n\n", "userAgent", ":=", "strings", ".", "Split", "(", "r", ".", "Header", ".", "Get", "(", "\"", "\"", ")", ",", "\"", "\"", ")", "\n\n", "// v1.20 onwards includes the GOOS of the client after the version", "// such as Docker/1.7.0 (linux)", "if", "len", "(", "userAgent", ")", "==", "2", "&&", "strings", ".", "Contains", "(", "userAgent", "[", "1", "]", ",", "\"", "\"", ")", "{", "userAgent", "[", "1", "]", "=", "strings", ".", "Split", "(", "userAgent", "[", "1", "]", ",", "\"", "\"", ")", "[", "0", "]", "\n", "}", "\n\n", "if", "len", "(", "userAgent", ")", "==", "2", "&&", "!", "dockerVersion", ".", "Equal", "(", "version", ".", "Version", "(", "userAgent", "[", "1", "]", ")", ")", "{", "glog", ".", "V", "(", "3", ")", ".", "Infof", "(", "\"", "\"", ",", "userAgent", "[", "1", "]", ",", "dockerVersion", ")", "\n", "}", "\n", "}", "\n", "return", "handler", "(", "ctx", ",", "w", ",", "r", ",", "vars", ")", "\n", "}", "\n", "}" ]
// userAgentMiddleware checks the User-Agent header looking for a valid docker client spec.
[ "userAgentMiddleware", "checks", "the", "User", "-", "Agent", "header", "looking", "for", "a", "valid", "docker", "client", "spec", "." ]
8a7e67dc33bbccdfc92b5e2a908bbdb1c5d9b956
https://github.com/hyperhq/hyperd/blob/8a7e67dc33bbccdfc92b5e2a908bbdb1c5d9b956/server/middleware.go#L100-L119
149,936
hyperhq/hyperd
server/middleware.go
corsMiddleware
func (s *Server) corsMiddleware(handler httputils.APIFunc) httputils.APIFunc { return func(ctx context.Context, w http.ResponseWriter, r *http.Request, vars map[string]string) error { // If "api-cors-header" is not given, but "api-enable-cors" is true, we set cors to "*" // otherwise, all head values will be passed to HTTP handler corsHeaders := s.cfg.CorsHeaders if corsHeaders == "" && s.cfg.EnableCors { corsHeaders = "*" } if corsHeaders != "" { writeCorsHeaders(w, r, corsHeaders) } return handler(ctx, w, r, vars) } }
go
func (s *Server) corsMiddleware(handler httputils.APIFunc) httputils.APIFunc { return func(ctx context.Context, w http.ResponseWriter, r *http.Request, vars map[string]string) error { // If "api-cors-header" is not given, but "api-enable-cors" is true, we set cors to "*" // otherwise, all head values will be passed to HTTP handler corsHeaders := s.cfg.CorsHeaders if corsHeaders == "" && s.cfg.EnableCors { corsHeaders = "*" } if corsHeaders != "" { writeCorsHeaders(w, r, corsHeaders) } return handler(ctx, w, r, vars) } }
[ "func", "(", "s", "*", "Server", ")", "corsMiddleware", "(", "handler", "httputils", ".", "APIFunc", ")", "httputils", ".", "APIFunc", "{", "return", "func", "(", "ctx", "context", ".", "Context", ",", "w", "http", ".", "ResponseWriter", ",", "r", "*", "http", ".", "Request", ",", "vars", "map", "[", "string", "]", "string", ")", "error", "{", "// If \"api-cors-header\" is not given, but \"api-enable-cors\" is true, we set cors to \"*\"", "// otherwise, all head values will be passed to HTTP handler", "corsHeaders", ":=", "s", ".", "cfg", ".", "CorsHeaders", "\n", "if", "corsHeaders", "==", "\"", "\"", "&&", "s", ".", "cfg", ".", "EnableCors", "{", "corsHeaders", "=", "\"", "\"", "\n", "}", "\n\n", "if", "corsHeaders", "!=", "\"", "\"", "{", "writeCorsHeaders", "(", "w", ",", "r", ",", "corsHeaders", ")", "\n", "}", "\n", "return", "handler", "(", "ctx", ",", "w", ",", "r", ",", "vars", ")", "\n", "}", "\n", "}" ]
// corsMiddleware sets the CORS header expectations in the server.
[ "corsMiddleware", "sets", "the", "CORS", "header", "expectations", "in", "the", "server", "." ]
8a7e67dc33bbccdfc92b5e2a908bbdb1c5d9b956
https://github.com/hyperhq/hyperd/blob/8a7e67dc33bbccdfc92b5e2a908bbdb1c5d9b956/server/middleware.go#L122-L136
149,937
hyperhq/hyperd
server/middleware.go
versionMiddleware
func versionMiddleware(handler httputils.APIFunc) httputils.APIFunc { return func(ctx context.Context, w http.ResponseWriter, r *http.Request, vars map[string]string) error { apiVersion := version.Version(vars["version"]) if apiVersion == "" { apiVersion = api.DefaultVersion } // FIXME: do not check version now /* if apiVersion.GreaterThan(api.DefaultVersion) { return errors.ErrorCodeNewerClientVersion.WithArgs(apiVersion, api.DefaultVersion) } if apiVersion.LessThan(api.MinVersion) { return errors.ErrorCodeOldClientVersion.WithArgs(apiVersion, api.DefaultVersion) } */ w.Header().Set("Server", "Docker/"+dockerversion.Version+" ("+runtime.GOOS+")") ctx = context.WithValue(ctx, httputils.APIVersionKey, apiVersion) return handler(ctx, w, r, vars) } }
go
func versionMiddleware(handler httputils.APIFunc) httputils.APIFunc { return func(ctx context.Context, w http.ResponseWriter, r *http.Request, vars map[string]string) error { apiVersion := version.Version(vars["version"]) if apiVersion == "" { apiVersion = api.DefaultVersion } // FIXME: do not check version now /* if apiVersion.GreaterThan(api.DefaultVersion) { return errors.ErrorCodeNewerClientVersion.WithArgs(apiVersion, api.DefaultVersion) } if apiVersion.LessThan(api.MinVersion) { return errors.ErrorCodeOldClientVersion.WithArgs(apiVersion, api.DefaultVersion) } */ w.Header().Set("Server", "Docker/"+dockerversion.Version+" ("+runtime.GOOS+")") ctx = context.WithValue(ctx, httputils.APIVersionKey, apiVersion) return handler(ctx, w, r, vars) } }
[ "func", "versionMiddleware", "(", "handler", "httputils", ".", "APIFunc", ")", "httputils", ".", "APIFunc", "{", "return", "func", "(", "ctx", "context", ".", "Context", ",", "w", "http", ".", "ResponseWriter", ",", "r", "*", "http", ".", "Request", ",", "vars", "map", "[", "string", "]", "string", ")", "error", "{", "apiVersion", ":=", "version", ".", "Version", "(", "vars", "[", "\"", "\"", "]", ")", "\n", "if", "apiVersion", "==", "\"", "\"", "{", "apiVersion", "=", "api", ".", "DefaultVersion", "\n", "}", "\n", "// FIXME: do not check version now", "/*\n\t\t\tif apiVersion.GreaterThan(api.DefaultVersion) {\n\t\t\t\treturn errors.ErrorCodeNewerClientVersion.WithArgs(apiVersion, api.DefaultVersion)\n\t\t\t}\n\t\t\tif apiVersion.LessThan(api.MinVersion) {\n\t\t\t\treturn errors.ErrorCodeOldClientVersion.WithArgs(apiVersion, api.DefaultVersion)\n\t\t\t}\n\t\t*/", "w", ".", "Header", "(", ")", ".", "Set", "(", "\"", "\"", ",", "\"", "\"", "+", "dockerversion", ".", "Version", "+", "\"", "\"", "+", "runtime", ".", "GOOS", "+", "\"", "\"", ")", "\n", "ctx", "=", "context", ".", "WithValue", "(", "ctx", ",", "httputils", ".", "APIVersionKey", ",", "apiVersion", ")", "\n", "return", "handler", "(", "ctx", ",", "w", ",", "r", ",", "vars", ")", "\n", "}", "\n", "}" ]
// versionMiddleware checks the api version requirements before passing the request to the server handler.
[ "versionMiddleware", "checks", "the", "api", "version", "requirements", "before", "passing", "the", "request", "to", "the", "server", "handler", "." ]
8a7e67dc33bbccdfc92b5e2a908bbdb1c5d9b956
https://github.com/hyperhq/hyperd/blob/8a7e67dc33bbccdfc92b5e2a908bbdb1c5d9b956/server/middleware.go#L139-L158
149,938
hyperhq/hyperd
storage/vbox/vbox.go
MountContainerToSharedDir
func MountContainerToSharedDir(containerId, sharedDir, devPrefix string) (string, error) { devFullName := fmt.Sprintf("%s/vbox/images/%s.vdi", utils.HYPER_ROOT, containerId) return devFullName, nil }
go
func MountContainerToSharedDir(containerId, sharedDir, devPrefix string) (string, error) { devFullName := fmt.Sprintf("%s/vbox/images/%s.vdi", utils.HYPER_ROOT, containerId) return devFullName, nil }
[ "func", "MountContainerToSharedDir", "(", "containerId", ",", "sharedDir", ",", "devPrefix", "string", ")", "(", "string", ",", "error", ")", "{", "devFullName", ":=", "fmt", ".", "Sprintf", "(", "\"", "\"", ",", "utils", ".", "HYPER_ROOT", ",", "containerId", ")", "\n", "return", "devFullName", ",", "nil", "\n", "}" ]
// For device mapper, we do not need to mount the container to sharedDir. // All of we need to provide the block device name of container.
[ "For", "device", "mapper", "we", "do", "not", "need", "to", "mount", "the", "container", "to", "sharedDir", ".", "All", "of", "we", "need", "to", "provide", "the", "block", "device", "name", "of", "container", "." ]
8a7e67dc33bbccdfc92b5e2a908bbdb1c5d9b956
https://github.com/hyperhq/hyperd/blob/8a7e67dc33bbccdfc92b5e2a908bbdb1c5d9b956/storage/vbox/vbox.go#L11-L14
149,939
hyperhq/hyperd
serverrpc/images.go
ImagePull
func (s *ServerRPC) ImagePull(req *types.ImagePullRequest, stream types.PublicAPI_ImagePullServer) error { authConfig := &enginetypes.AuthConfig{} if req.Auth != nil { authConfig = &enginetypes.AuthConfig{ Username: req.Auth.Username, Password: req.Auth.Password, Auth: req.Auth.Auth, Email: req.Auth.Email, ServerAddress: req.Auth.Serveraddress, RegistryToken: req.Auth.Registrytoken, } } glog.V(3).Infof("ImagePull with ServerStream %s request %s", stream, req.String()) r, w := io.Pipe() var pullResult error var complete = false go func() { defer r.Close() for { data := make([]byte, 512) n, err := r.Read(data) if err == io.EOF { if complete { break } else { continue } } if err != nil { glog.Errorf("Read image pull stream error: %v", err) return } if err := stream.Send(&types.ImagePullResponse{Data: data[:n]}); err != nil { glog.Errorf("Send image pull progress to stream error: %v", err) return } } }() pullResult = s.daemon.CmdImagePull(req.Image, req.Tag, authConfig, nil, w) complete = true if pullResult != nil { pullResult = fmt.Errorf("s.daemon.CmdImagePull with request %s error: %v", req.String(), pullResult) } return pullResult }
go
func (s *ServerRPC) ImagePull(req *types.ImagePullRequest, stream types.PublicAPI_ImagePullServer) error { authConfig := &enginetypes.AuthConfig{} if req.Auth != nil { authConfig = &enginetypes.AuthConfig{ Username: req.Auth.Username, Password: req.Auth.Password, Auth: req.Auth.Auth, Email: req.Auth.Email, ServerAddress: req.Auth.Serveraddress, RegistryToken: req.Auth.Registrytoken, } } glog.V(3).Infof("ImagePull with ServerStream %s request %s", stream, req.String()) r, w := io.Pipe() var pullResult error var complete = false go func() { defer r.Close() for { data := make([]byte, 512) n, err := r.Read(data) if err == io.EOF { if complete { break } else { continue } } if err != nil { glog.Errorf("Read image pull stream error: %v", err) return } if err := stream.Send(&types.ImagePullResponse{Data: data[:n]}); err != nil { glog.Errorf("Send image pull progress to stream error: %v", err) return } } }() pullResult = s.daemon.CmdImagePull(req.Image, req.Tag, authConfig, nil, w) complete = true if pullResult != nil { pullResult = fmt.Errorf("s.daemon.CmdImagePull with request %s error: %v", req.String(), pullResult) } return pullResult }
[ "func", "(", "s", "*", "ServerRPC", ")", "ImagePull", "(", "req", "*", "types", ".", "ImagePullRequest", ",", "stream", "types", ".", "PublicAPI_ImagePullServer", ")", "error", "{", "authConfig", ":=", "&", "enginetypes", ".", "AuthConfig", "{", "}", "\n", "if", "req", ".", "Auth", "!=", "nil", "{", "authConfig", "=", "&", "enginetypes", ".", "AuthConfig", "{", "Username", ":", "req", ".", "Auth", ".", "Username", ",", "Password", ":", "req", ".", "Auth", ".", "Password", ",", "Auth", ":", "req", ".", "Auth", ".", "Auth", ",", "Email", ":", "req", ".", "Auth", ".", "Email", ",", "ServerAddress", ":", "req", ".", "Auth", ".", "Serveraddress", ",", "RegistryToken", ":", "req", ".", "Auth", ".", "Registrytoken", ",", "}", "\n", "}", "\n", "glog", ".", "V", "(", "3", ")", ".", "Infof", "(", "\"", "\"", ",", "stream", ",", "req", ".", "String", "(", ")", ")", "\n\n", "r", ",", "w", ":=", "io", ".", "Pipe", "(", ")", "\n\n", "var", "pullResult", "error", "\n", "var", "complete", "=", "false", "\n\n", "go", "func", "(", ")", "{", "defer", "r", ".", "Close", "(", ")", "\n", "for", "{", "data", ":=", "make", "(", "[", "]", "byte", ",", "512", ")", "\n", "n", ",", "err", ":=", "r", ".", "Read", "(", "data", ")", "\n", "if", "err", "==", "io", ".", "EOF", "{", "if", "complete", "{", "break", "\n", "}", "else", "{", "continue", "\n", "}", "\n", "}", "\n\n", "if", "err", "!=", "nil", "{", "glog", ".", "Errorf", "(", "\"", "\"", ",", "err", ")", "\n", "return", "\n", "}", "\n\n", "if", "err", ":=", "stream", ".", "Send", "(", "&", "types", ".", "ImagePullResponse", "{", "Data", ":", "data", "[", ":", "n", "]", "}", ")", ";", "err", "!=", "nil", "{", "glog", ".", "Errorf", "(", "\"", "\"", ",", "err", ")", "\n", "return", "\n", "}", "\n", "}", "\n", "}", "(", ")", "\n\n", "pullResult", "=", "s", ".", "daemon", ".", "CmdImagePull", "(", "req", ".", "Image", ",", "req", ".", "Tag", ",", "authConfig", ",", "nil", ",", "w", ")", "\n", "complete", "=", "true", "\n\n", "if", "pullResult", "!=", "nil", "{", "pullResult", "=", "fmt", ".", "Errorf", "(", "\"", "\"", ",", "req", ".", "String", "(", ")", ",", "pullResult", ")", "\n", "}", "\n", "return", "pullResult", "\n", "}" ]
// ImagePull pulls a image from registry
[ "ImagePull", "pulls", "a", "image", "from", "registry" ]
8a7e67dc33bbccdfc92b5e2a908bbdb1c5d9b956
https://github.com/hyperhq/hyperd/blob/8a7e67dc33bbccdfc92b5e2a908bbdb1c5d9b956/serverrpc/images.go#L41-L92
149,940
hyperhq/hyperd
serverrpc/images.go
ImagePush
func (s *ServerRPC) ImagePush(req *types.ImagePushRequest, stream types.PublicAPI_ImagePushServer) error { authConfig := &enginetypes.AuthConfig{} if req.Auth != nil { authConfig = &enginetypes.AuthConfig{ Username: req.Auth.Username, Password: req.Auth.Password, Auth: req.Auth.Auth, Email: req.Auth.Email, ServerAddress: req.Auth.Serveraddress, RegistryToken: req.Auth.Registrytoken, } } glog.V(3).Infof("ImagePush with ServerStream %s request %s", stream, req.String()) buffer := bytes.NewBuffer([]byte{}) var pushResult error var complete = false go func() { pushResult = s.daemon.CmdImagePush(req.Repo, req.Tag, authConfig, nil, buffer) complete = true }() for { data, err := ioutil.ReadAll(buffer) if err == io.EOF { if complete { break } else { continue } } if err != nil { return fmt.Errorf("ImagePush read image push stream with request %s error: %v", req.String(), err) } if err := stream.Send(&types.ImagePushResponse{Data: data}); err != nil { return fmt.Errorf("stream.Send with request %s error: %v", req.String(), err) } } if pushResult != nil { pushResult = fmt.Errorf("s.daemon.CmdImagePush with request %s error: %v", req.String(), pushResult) } return pushResult }
go
func (s *ServerRPC) ImagePush(req *types.ImagePushRequest, stream types.PublicAPI_ImagePushServer) error { authConfig := &enginetypes.AuthConfig{} if req.Auth != nil { authConfig = &enginetypes.AuthConfig{ Username: req.Auth.Username, Password: req.Auth.Password, Auth: req.Auth.Auth, Email: req.Auth.Email, ServerAddress: req.Auth.Serveraddress, RegistryToken: req.Auth.Registrytoken, } } glog.V(3).Infof("ImagePush with ServerStream %s request %s", stream, req.String()) buffer := bytes.NewBuffer([]byte{}) var pushResult error var complete = false go func() { pushResult = s.daemon.CmdImagePush(req.Repo, req.Tag, authConfig, nil, buffer) complete = true }() for { data, err := ioutil.ReadAll(buffer) if err == io.EOF { if complete { break } else { continue } } if err != nil { return fmt.Errorf("ImagePush read image push stream with request %s error: %v", req.String(), err) } if err := stream.Send(&types.ImagePushResponse{Data: data}); err != nil { return fmt.Errorf("stream.Send with request %s error: %v", req.String(), err) } } if pushResult != nil { pushResult = fmt.Errorf("s.daemon.CmdImagePush with request %s error: %v", req.String(), pushResult) } return pushResult }
[ "func", "(", "s", "*", "ServerRPC", ")", "ImagePush", "(", "req", "*", "types", ".", "ImagePushRequest", ",", "stream", "types", ".", "PublicAPI_ImagePushServer", ")", "error", "{", "authConfig", ":=", "&", "enginetypes", ".", "AuthConfig", "{", "}", "\n", "if", "req", ".", "Auth", "!=", "nil", "{", "authConfig", "=", "&", "enginetypes", ".", "AuthConfig", "{", "Username", ":", "req", ".", "Auth", ".", "Username", ",", "Password", ":", "req", ".", "Auth", ".", "Password", ",", "Auth", ":", "req", ".", "Auth", ".", "Auth", ",", "Email", ":", "req", ".", "Auth", ".", "Email", ",", "ServerAddress", ":", "req", ".", "Auth", ".", "Serveraddress", ",", "RegistryToken", ":", "req", ".", "Auth", ".", "Registrytoken", ",", "}", "\n", "}", "\n", "glog", ".", "V", "(", "3", ")", ".", "Infof", "(", "\"", "\"", ",", "stream", ",", "req", ".", "String", "(", ")", ")", "\n\n", "buffer", ":=", "bytes", ".", "NewBuffer", "(", "[", "]", "byte", "{", "}", ")", "\n", "var", "pushResult", "error", "\n", "var", "complete", "=", "false", "\n", "go", "func", "(", ")", "{", "pushResult", "=", "s", ".", "daemon", ".", "CmdImagePush", "(", "req", ".", "Repo", ",", "req", ".", "Tag", ",", "authConfig", ",", "nil", ",", "buffer", ")", "\n", "complete", "=", "true", "\n", "}", "(", ")", "\n\n", "for", "{", "data", ",", "err", ":=", "ioutil", ".", "ReadAll", "(", "buffer", ")", "\n", "if", "err", "==", "io", ".", "EOF", "{", "if", "complete", "{", "break", "\n", "}", "else", "{", "continue", "\n", "}", "\n", "}", "\n\n", "if", "err", "!=", "nil", "{", "return", "fmt", ".", "Errorf", "(", "\"", "\"", ",", "req", ".", "String", "(", ")", ",", "err", ")", "\n", "}", "\n\n", "if", "err", ":=", "stream", ".", "Send", "(", "&", "types", ".", "ImagePushResponse", "{", "Data", ":", "data", "}", ")", ";", "err", "!=", "nil", "{", "return", "fmt", ".", "Errorf", "(", "\"", "\"", ",", "req", ".", "String", "(", ")", ",", "err", ")", "\n", "}", "\n", "}", "\n\n", "if", "pushResult", "!=", "nil", "{", "pushResult", "=", "fmt", ".", "Errorf", "(", "\"", "\"", ",", "req", ".", "String", "(", ")", ",", "pushResult", ")", "\n", "}", "\n", "return", "pushResult", "\n", "}" ]
// ImagePush pushes a local image to registry
[ "ImagePush", "pushes", "a", "local", "image", "to", "registry" ]
8a7e67dc33bbccdfc92b5e2a908bbdb1c5d9b956
https://github.com/hyperhq/hyperd/blob/8a7e67dc33bbccdfc92b5e2a908bbdb1c5d9b956/serverrpc/images.go#L95-L140
149,941
hyperhq/hyperd
serverrpc/images.go
ImageRemove
func (s *ServerRPC) ImageRemove(ctx context.Context, req *types.ImageRemoveRequest) (*types.ImageRemoveResponse, error) { resp, err := s.daemon.CmdImageDelete(req.Image, req.Force, req.Prune) if err != nil { return nil, err } return &types.ImageRemoveResponse{ Images: resp, }, nil }
go
func (s *ServerRPC) ImageRemove(ctx context.Context, req *types.ImageRemoveRequest) (*types.ImageRemoveResponse, error) { resp, err := s.daemon.CmdImageDelete(req.Image, req.Force, req.Prune) if err != nil { return nil, err } return &types.ImageRemoveResponse{ Images: resp, }, nil }
[ "func", "(", "s", "*", "ServerRPC", ")", "ImageRemove", "(", "ctx", "context", ".", "Context", ",", "req", "*", "types", ".", "ImageRemoveRequest", ")", "(", "*", "types", ".", "ImageRemoveResponse", ",", "error", ")", "{", "resp", ",", "err", ":=", "s", ".", "daemon", ".", "CmdImageDelete", "(", "req", ".", "Image", ",", "req", ".", "Force", ",", "req", ".", "Prune", ")", "\n", "if", "err", "!=", "nil", "{", "return", "nil", ",", "err", "\n", "}", "\n\n", "return", "&", "types", ".", "ImageRemoveResponse", "{", "Images", ":", "resp", ",", "}", ",", "nil", "\n", "}" ]
// ImageRemove deletes a image from hyperd
[ "ImageRemove", "deletes", "a", "image", "from", "hyperd" ]
8a7e67dc33bbccdfc92b5e2a908bbdb1c5d9b956
https://github.com/hyperhq/hyperd/blob/8a7e67dc33bbccdfc92b5e2a908bbdb1c5d9b956/serverrpc/images.go#L143-L152
149,942
hyperhq/hyperd
serverrpc/pod.go
PodCreate
func (s *ServerRPC) PodCreate(ctx context.Context, req *types.PodCreateRequest) (*types.PodCreateResponse, error) { p, err := s.daemon.CreatePod(req.PodID, req.PodSpec) if err != nil { return nil, err } return &types.PodCreateResponse{ PodID: p.Id(), }, nil }
go
func (s *ServerRPC) PodCreate(ctx context.Context, req *types.PodCreateRequest) (*types.PodCreateResponse, error) { p, err := s.daemon.CreatePod(req.PodID, req.PodSpec) if err != nil { return nil, err } return &types.PodCreateResponse{ PodID: p.Id(), }, nil }
[ "func", "(", "s", "*", "ServerRPC", ")", "PodCreate", "(", "ctx", "context", ".", "Context", ",", "req", "*", "types", ".", "PodCreateRequest", ")", "(", "*", "types", ".", "PodCreateResponse", ",", "error", ")", "{", "p", ",", "err", ":=", "s", ".", "daemon", ".", "CreatePod", "(", "req", ".", "PodID", ",", "req", ".", "PodSpec", ")", "\n", "if", "err", "!=", "nil", "{", "return", "nil", ",", "err", "\n", "}", "\n\n", "return", "&", "types", ".", "PodCreateResponse", "{", "PodID", ":", "p", ".", "Id", "(", ")", ",", "}", ",", "nil", "\n", "}" ]
// PodCreate creates a pod by PodSpec
[ "PodCreate", "creates", "a", "pod", "by", "PodSpec" ]
8a7e67dc33bbccdfc92b5e2a908bbdb1c5d9b956
https://github.com/hyperhq/hyperd/blob/8a7e67dc33bbccdfc92b5e2a908bbdb1c5d9b956/serverrpc/pod.go#L12-L21
149,943
hyperhq/hyperd
serverrpc/pod.go
PodStart
func (s *ServerRPC) PodStart(ctx context.Context, req *types.PodStartRequest) (*types.PodStartResponse, error) { err := s.daemon.StartPod(req.PodID) if err != nil { return nil, err } return &types.PodStartResponse{}, nil }
go
func (s *ServerRPC) PodStart(ctx context.Context, req *types.PodStartRequest) (*types.PodStartResponse, error) { err := s.daemon.StartPod(req.PodID) if err != nil { return nil, err } return &types.PodStartResponse{}, nil }
[ "func", "(", "s", "*", "ServerRPC", ")", "PodStart", "(", "ctx", "context", ".", "Context", ",", "req", "*", "types", ".", "PodStartRequest", ")", "(", "*", "types", ".", "PodStartResponse", ",", "error", ")", "{", "err", ":=", "s", ".", "daemon", ".", "StartPod", "(", "req", ".", "PodID", ")", "\n", "if", "err", "!=", "nil", "{", "return", "nil", ",", "err", "\n", "}", "\n\n", "return", "&", "types", ".", "PodStartResponse", "{", "}", ",", "nil", "\n", "}" ]
// PodStart starts a pod by podID
[ "PodStart", "starts", "a", "pod", "by", "podID" ]
8a7e67dc33bbccdfc92b5e2a908bbdb1c5d9b956
https://github.com/hyperhq/hyperd/blob/8a7e67dc33bbccdfc92b5e2a908bbdb1c5d9b956/serverrpc/pod.go#L24-L31
149,944
hyperhq/hyperd
serverrpc/pod.go
PodRemove
func (s *ServerRPC) PodRemove(ctx context.Context, req *types.PodRemoveRequest) (*types.PodRemoveResponse, error) { if req.PodID == "" { return nil, fmt.Errorf("PodRemove failed PodID is required for PodRemove") } code, cause, err := s.daemon.RemovePod(req.PodID) if err != nil { return nil, fmt.Errorf("s.daemon.RemovePod error: %v", err) } return &types.PodRemoveResponse{ Cause: cause, Code: int32(code), }, nil }
go
func (s *ServerRPC) PodRemove(ctx context.Context, req *types.PodRemoveRequest) (*types.PodRemoveResponse, error) { if req.PodID == "" { return nil, fmt.Errorf("PodRemove failed PodID is required for PodRemove") } code, cause, err := s.daemon.RemovePod(req.PodID) if err != nil { return nil, fmt.Errorf("s.daemon.RemovePod error: %v", err) } return &types.PodRemoveResponse{ Cause: cause, Code: int32(code), }, nil }
[ "func", "(", "s", "*", "ServerRPC", ")", "PodRemove", "(", "ctx", "context", ".", "Context", ",", "req", "*", "types", ".", "PodRemoveRequest", ")", "(", "*", "types", ".", "PodRemoveResponse", ",", "error", ")", "{", "if", "req", ".", "PodID", "==", "\"", "\"", "{", "return", "nil", ",", "fmt", ".", "Errorf", "(", "\"", "\"", ")", "\n", "}", "\n\n", "code", ",", "cause", ",", "err", ":=", "s", ".", "daemon", ".", "RemovePod", "(", "req", ".", "PodID", ")", "\n", "if", "err", "!=", "nil", "{", "return", "nil", ",", "fmt", ".", "Errorf", "(", "\"", "\"", ",", "err", ")", "\n", "}", "\n\n", "return", "&", "types", ".", "PodRemoveResponse", "{", "Cause", ":", "cause", ",", "Code", ":", "int32", "(", "code", ")", ",", "}", ",", "nil", "\n", "}" ]
// PodRemove removes a pod by podID
[ "PodRemove", "removes", "a", "pod", "by", "podID" ]
8a7e67dc33bbccdfc92b5e2a908bbdb1c5d9b956
https://github.com/hyperhq/hyperd/blob/8a7e67dc33bbccdfc92b5e2a908bbdb1c5d9b956/serverrpc/pod.go#L34-L48
149,945
hyperhq/hyperd
serverrpc/pod.go
PodStop
func (s *ServerRPC) PodStop(ctx context.Context, req *types.PodStopRequest) (*types.PodStopResponse, error) { code, cause, err := s.daemon.StopPod(req.PodID) if err != nil { return nil, err } return &types.PodStopResponse{ Cause: cause, Code: int32(code), }, nil }
go
func (s *ServerRPC) PodStop(ctx context.Context, req *types.PodStopRequest) (*types.PodStopResponse, error) { code, cause, err := s.daemon.StopPod(req.PodID) if err != nil { return nil, err } return &types.PodStopResponse{ Cause: cause, Code: int32(code), }, nil }
[ "func", "(", "s", "*", "ServerRPC", ")", "PodStop", "(", "ctx", "context", ".", "Context", ",", "req", "*", "types", ".", "PodStopRequest", ")", "(", "*", "types", ".", "PodStopResponse", ",", "error", ")", "{", "code", ",", "cause", ",", "err", ":=", "s", ".", "daemon", ".", "StopPod", "(", "req", ".", "PodID", ")", "\n", "if", "err", "!=", "nil", "{", "return", "nil", ",", "err", "\n", "}", "\n\n", "return", "&", "types", ".", "PodStopResponse", "{", "Cause", ":", "cause", ",", "Code", ":", "int32", "(", "code", ")", ",", "}", ",", "nil", "\n", "}" ]
// PodStop stops a pod
[ "PodStop", "stops", "a", "pod" ]
8a7e67dc33bbccdfc92b5e2a908bbdb1c5d9b956
https://github.com/hyperhq/hyperd/blob/8a7e67dc33bbccdfc92b5e2a908bbdb1c5d9b956/serverrpc/pod.go#L51-L61
149,946
hyperhq/hyperd
serverrpc/pod.go
PodSignal
func (s *ServerRPC) PodSignal(ctx context.Context, req *types.PodSignalRequest) (*types.PodSignalResponse, error) { err := s.daemon.KillPodContainers(req.PodID, "", req.Signal) if err != nil { return nil, err } return &types.PodSignalResponse{}, nil }
go
func (s *ServerRPC) PodSignal(ctx context.Context, req *types.PodSignalRequest) (*types.PodSignalResponse, error) { err := s.daemon.KillPodContainers(req.PodID, "", req.Signal) if err != nil { return nil, err } return &types.PodSignalResponse{}, nil }
[ "func", "(", "s", "*", "ServerRPC", ")", "PodSignal", "(", "ctx", "context", ".", "Context", ",", "req", "*", "types", ".", "PodSignalRequest", ")", "(", "*", "types", ".", "PodSignalResponse", ",", "error", ")", "{", "err", ":=", "s", ".", "daemon", ".", "KillPodContainers", "(", "req", ".", "PodID", ",", "\"", "\"", ",", "req", ".", "Signal", ")", "\n", "if", "err", "!=", "nil", "{", "return", "nil", ",", "err", "\n", "}", "\n\n", "return", "&", "types", ".", "PodSignalResponse", "{", "}", ",", "nil", "\n", "}" ]
// PodSignal sends a singal to all containers of specified pod
[ "PodSignal", "sends", "a", "singal", "to", "all", "containers", "of", "specified", "pod" ]
8a7e67dc33bbccdfc92b5e2a908bbdb1c5d9b956
https://github.com/hyperhq/hyperd/blob/8a7e67dc33bbccdfc92b5e2a908bbdb1c5d9b956/serverrpc/pod.go#L64-L71
149,947
hyperhq/hyperd
serverrpc/pod.go
PodPause
func (s *ServerRPC) PodPause(ctx context.Context, req *types.PodPauseRequest) (*types.PodPauseResponse, error) { err := s.daemon.PausePod(req.PodID) if err != nil { return nil, err } return &types.PodPauseResponse{}, nil }
go
func (s *ServerRPC) PodPause(ctx context.Context, req *types.PodPauseRequest) (*types.PodPauseResponse, error) { err := s.daemon.PausePod(req.PodID) if err != nil { return nil, err } return &types.PodPauseResponse{}, nil }
[ "func", "(", "s", "*", "ServerRPC", ")", "PodPause", "(", "ctx", "context", ".", "Context", ",", "req", "*", "types", ".", "PodPauseRequest", ")", "(", "*", "types", ".", "PodPauseResponse", ",", "error", ")", "{", "err", ":=", "s", ".", "daemon", ".", "PausePod", "(", "req", ".", "PodID", ")", "\n", "if", "err", "!=", "nil", "{", "return", "nil", ",", "err", "\n", "}", "\n\n", "return", "&", "types", ".", "PodPauseResponse", "{", "}", ",", "nil", "\n", "}" ]
// PodPause pauses a pod
[ "PodPause", "pauses", "a", "pod" ]
8a7e67dc33bbccdfc92b5e2a908bbdb1c5d9b956
https://github.com/hyperhq/hyperd/blob/8a7e67dc33bbccdfc92b5e2a908bbdb1c5d9b956/serverrpc/pod.go#L74-L81
149,948
hyperhq/hyperd
serverrpc/pod.go
PodUnpause
func (s *ServerRPC) PodUnpause(ctx context.Context, req *types.PodUnpauseRequest) (*types.PodUnpauseResponse, error) { err := s.daemon.UnpausePod(req.PodID) if err != nil { return nil, err } return &types.PodUnpauseResponse{}, nil }
go
func (s *ServerRPC) PodUnpause(ctx context.Context, req *types.PodUnpauseRequest) (*types.PodUnpauseResponse, error) { err := s.daemon.UnpausePod(req.PodID) if err != nil { return nil, err } return &types.PodUnpauseResponse{}, nil }
[ "func", "(", "s", "*", "ServerRPC", ")", "PodUnpause", "(", "ctx", "context", ".", "Context", ",", "req", "*", "types", ".", "PodUnpauseRequest", ")", "(", "*", "types", ".", "PodUnpauseResponse", ",", "error", ")", "{", "err", ":=", "s", ".", "daemon", ".", "UnpausePod", "(", "req", ".", "PodID", ")", "\n", "if", "err", "!=", "nil", "{", "return", "nil", ",", "err", "\n", "}", "\n\n", "return", "&", "types", ".", "PodUnpauseResponse", "{", "}", ",", "nil", "\n", "}" ]
// PodUnpause unpauses a pod
[ "PodUnpause", "unpauses", "a", "pod" ]
8a7e67dc33bbccdfc92b5e2a908bbdb1c5d9b956
https://github.com/hyperhq/hyperd/blob/8a7e67dc33bbccdfc92b5e2a908bbdb1c5d9b956/serverrpc/pod.go#L84-L91
149,949
hyperhq/hyperd
serverrpc/pod.go
SetPodLabels
func (s *ServerRPC) SetPodLabels(c context.Context, req *types.PodLabelsRequest) (*types.PodLabelsResponse, error) { err := s.daemon.SetPodLabels(req.PodID, req.Override, req.Labels) if err != nil { return nil, err } return &types.PodLabelsResponse{}, nil }
go
func (s *ServerRPC) SetPodLabels(c context.Context, req *types.PodLabelsRequest) (*types.PodLabelsResponse, error) { err := s.daemon.SetPodLabels(req.PodID, req.Override, req.Labels) if err != nil { return nil, err } return &types.PodLabelsResponse{}, nil }
[ "func", "(", "s", "*", "ServerRPC", ")", "SetPodLabels", "(", "c", "context", ".", "Context", ",", "req", "*", "types", ".", "PodLabelsRequest", ")", "(", "*", "types", ".", "PodLabelsResponse", ",", "error", ")", "{", "err", ":=", "s", ".", "daemon", ".", "SetPodLabels", "(", "req", ".", "PodID", ",", "req", ".", "Override", ",", "req", ".", "Labels", ")", "\n", "if", "err", "!=", "nil", "{", "return", "nil", ",", "err", "\n", "}", "\n\n", "return", "&", "types", ".", "PodLabelsResponse", "{", "}", ",", "nil", "\n", "}" ]
// PodLabels sets the labels of Pod
[ "PodLabels", "sets", "the", "labels", "of", "Pod" ]
8a7e67dc33bbccdfc92b5e2a908bbdb1c5d9b956
https://github.com/hyperhq/hyperd/blob/8a7e67dc33bbccdfc92b5e2a908bbdb1c5d9b956/serverrpc/pod.go#L94-L101
149,950
golang/geo
s2/point.go
Distance
func (p Point) Distance(b Point) s1.Angle { return p.Vector.Angle(b.Vector) }
go
func (p Point) Distance(b Point) s1.Angle { return p.Vector.Angle(b.Vector) }
[ "func", "(", "p", "Point", ")", "Distance", "(", "b", "Point", ")", "s1", ".", "Angle", "{", "return", "p", ".", "Vector", ".", "Angle", "(", "b", ".", "Vector", ")", "\n", "}" ]
// Distance returns the angle between two points.
[ "Distance", "returns", "the", "angle", "between", "two", "points", "." ]
476085157cff9aaeef4d4f124649436542d4114a
https://github.com/golang/geo/blob/476085157cff9aaeef4d4f124649436542d4114a/s2/point.go#L125-L127
149,951
golang/geo
s2/point.go
ApproxEqual
func (p Point) ApproxEqual(other Point) bool { return p.Vector.Angle(other.Vector) <= s1.Angle(epsilon) }
go
func (p Point) ApproxEqual(other Point) bool { return p.Vector.Angle(other.Vector) <= s1.Angle(epsilon) }
[ "func", "(", "p", "Point", ")", "ApproxEqual", "(", "other", "Point", ")", "bool", "{", "return", "p", ".", "Vector", ".", "Angle", "(", "other", ".", "Vector", ")", "<=", "s1", ".", "Angle", "(", "epsilon", ")", "\n", "}" ]
// ApproxEqual reports whether the two points are similar enough to be equal.
[ "ApproxEqual", "reports", "whether", "the", "two", "points", "are", "similar", "enough", "to", "be", "equal", "." ]
476085157cff9aaeef4d4f124649436542d4114a
https://github.com/golang/geo/blob/476085157cff9aaeef4d4f124649436542d4114a/s2/point.go#L130-L132
149,952
golang/geo
s2/point.go
ChordAngleBetweenPoints
func ChordAngleBetweenPoints(x, y Point) s1.ChordAngle { return s1.ChordAngle(math.Min(4.0, x.Sub(y.Vector).Norm2())) }
go
func ChordAngleBetweenPoints(x, y Point) s1.ChordAngle { return s1.ChordAngle(math.Min(4.0, x.Sub(y.Vector).Norm2())) }
[ "func", "ChordAngleBetweenPoints", "(", "x", ",", "y", "Point", ")", "s1", ".", "ChordAngle", "{", "return", "s1", ".", "ChordAngle", "(", "math", ".", "Min", "(", "4.0", ",", "x", ".", "Sub", "(", "y", ".", "Vector", ")", ".", "Norm2", "(", ")", ")", ")", "\n", "}" ]
// ChordAngleBetweenPoints constructs a ChordAngle corresponding to the distance // between the two given points. The points must be unit length.
[ "ChordAngleBetweenPoints", "constructs", "a", "ChordAngle", "corresponding", "to", "the", "distance", "between", "the", "two", "given", "points", ".", "The", "points", "must", "be", "unit", "length", "." ]
476085157cff9aaeef4d4f124649436542d4114a
https://github.com/golang/geo/blob/476085157cff9aaeef4d4f124649436542d4114a/s2/point.go#L136-L138
149,953
golang/geo
s2/point.go
regularPoints
func regularPoints(center Point, radius s1.Angle, numVertices int) []Point { return regularPointsForFrame(getFrame(center), radius, numVertices) }
go
func regularPoints(center Point, radius s1.Angle, numVertices int) []Point { return regularPointsForFrame(getFrame(center), radius, numVertices) }
[ "func", "regularPoints", "(", "center", "Point", ",", "radius", "s1", ".", "Angle", ",", "numVertices", "int", ")", "[", "]", "Point", "{", "return", "regularPointsForFrame", "(", "getFrame", "(", "center", ")", ",", "radius", ",", "numVertices", ")", "\n", "}" ]
// regularPoints generates a slice of points shaped as a regular polygon with // the numVertices vertices, all located on a circle of the specified angular radius // around the center. The radius is the actual distance from center to each vertex.
[ "regularPoints", "generates", "a", "slice", "of", "points", "shaped", "as", "a", "regular", "polygon", "with", "the", "numVertices", "vertices", "all", "located", "on", "a", "circle", "of", "the", "specified", "angular", "radius", "around", "the", "center", ".", "The", "radius", "is", "the", "actual", "distance", "from", "center", "to", "each", "vertex", "." ]
476085157cff9aaeef4d4f124649436542d4114a
https://github.com/golang/geo/blob/476085157cff9aaeef4d4f124649436542d4114a/s2/point.go#L143-L145
149,954
golang/geo
s2/point.go
regularPointsForFrame
func regularPointsForFrame(frame matrix3x3, radius s1.Angle, numVertices int) []Point { // We construct the loop in the given frame coordinates, with the center at // (0, 0, 1). For a loop of radius r, the loop vertices have the form // (x, y, z) where x^2 + y^2 = sin(r) and z = cos(r). The distance on the // sphere (arc length) from each vertex to the center is acos(cos(r)) = r. z := math.Cos(radius.Radians()) r := math.Sin(radius.Radians()) radianStep := 2 * math.Pi / float64(numVertices) var vertices []Point for i := 0; i < numVertices; i++ { angle := float64(i) * radianStep p := Point{r3.Vector{r * math.Cos(angle), r * math.Sin(angle), z}} vertices = append(vertices, Point{fromFrame(frame, p).Normalize()}) } return vertices }
go
func regularPointsForFrame(frame matrix3x3, radius s1.Angle, numVertices int) []Point { // We construct the loop in the given frame coordinates, with the center at // (0, 0, 1). For a loop of radius r, the loop vertices have the form // (x, y, z) where x^2 + y^2 = sin(r) and z = cos(r). The distance on the // sphere (arc length) from each vertex to the center is acos(cos(r)) = r. z := math.Cos(radius.Radians()) r := math.Sin(radius.Radians()) radianStep := 2 * math.Pi / float64(numVertices) var vertices []Point for i := 0; i < numVertices; i++ { angle := float64(i) * radianStep p := Point{r3.Vector{r * math.Cos(angle), r * math.Sin(angle), z}} vertices = append(vertices, Point{fromFrame(frame, p).Normalize()}) } return vertices }
[ "func", "regularPointsForFrame", "(", "frame", "matrix3x3", ",", "radius", "s1", ".", "Angle", ",", "numVertices", "int", ")", "[", "]", "Point", "{", "// We construct the loop in the given frame coordinates, with the center at", "// (0, 0, 1). For a loop of radius r, the loop vertices have the form", "// (x, y, z) where x^2 + y^2 = sin(r) and z = cos(r). The distance on the", "// sphere (arc length) from each vertex to the center is acos(cos(r)) = r.", "z", ":=", "math", ".", "Cos", "(", "radius", ".", "Radians", "(", ")", ")", "\n", "r", ":=", "math", ".", "Sin", "(", "radius", ".", "Radians", "(", ")", ")", "\n", "radianStep", ":=", "2", "*", "math", ".", "Pi", "/", "float64", "(", "numVertices", ")", "\n", "var", "vertices", "[", "]", "Point", "\n\n", "for", "i", ":=", "0", ";", "i", "<", "numVertices", ";", "i", "++", "{", "angle", ":=", "float64", "(", "i", ")", "*", "radianStep", "\n", "p", ":=", "Point", "{", "r3", ".", "Vector", "{", "r", "*", "math", ".", "Cos", "(", "angle", ")", ",", "r", "*", "math", ".", "Sin", "(", "angle", ")", ",", "z", "}", "}", "\n", "vertices", "=", "append", "(", "vertices", ",", "Point", "{", "fromFrame", "(", "frame", ",", "p", ")", ".", "Normalize", "(", ")", "}", ")", "\n", "}", "\n\n", "return", "vertices", "\n", "}" ]
// regularPointsForFrame generates a slice of points shaped as a regular polygon // with numVertices vertices, all on a circle of the specified angular radius around // the center. The radius is the actual distance from the center to each vertex.
[ "regularPointsForFrame", "generates", "a", "slice", "of", "points", "shaped", "as", "a", "regular", "polygon", "with", "numVertices", "vertices", "all", "on", "a", "circle", "of", "the", "specified", "angular", "radius", "around", "the", "center", ".", "The", "radius", "is", "the", "actual", "distance", "from", "the", "center", "to", "each", "vertex", "." ]
476085157cff9aaeef4d4f124649436542d4114a
https://github.com/golang/geo/blob/476085157cff9aaeef4d4f124649436542d4114a/s2/point.go#L150-L167
149,955
golang/geo
s2/crossing_edge_query.go
NewCrossingEdgeQuery
func NewCrossingEdgeQuery(index *ShapeIndex) *CrossingEdgeQuery { c := &CrossingEdgeQuery{ index: index, iter: index.Iterator(), } return c }
go
func NewCrossingEdgeQuery(index *ShapeIndex) *CrossingEdgeQuery { c := &CrossingEdgeQuery{ index: index, iter: index.Iterator(), } return c }
[ "func", "NewCrossingEdgeQuery", "(", "index", "*", "ShapeIndex", ")", "*", "CrossingEdgeQuery", "{", "c", ":=", "&", "CrossingEdgeQuery", "{", "index", ":", "index", ",", "iter", ":", "index", ".", "Iterator", "(", ")", ",", "}", "\n", "return", "c", "\n", "}" ]
// NewCrossingEdgeQuery creates a CrossingEdgeQuery for the given index.
[ "NewCrossingEdgeQuery", "creates", "a", "CrossingEdgeQuery", "for", "the", "given", "index", "." ]
476085157cff9aaeef4d4f124649436542d4114a
https://github.com/golang/geo/blob/476085157cff9aaeef4d4f124649436542d4114a/s2/crossing_edge_query.go#L43-L49
149,956
golang/geo
s2/crossing_edge_query.go
Crossings
func (c *CrossingEdgeQuery) Crossings(a, b Point, shape Shape, crossType CrossingType) []int { edges := c.candidates(a, b, shape) if len(edges) == 0 { return nil } crosser := NewEdgeCrosser(a, b) out := 0 n := len(edges) for in := 0; in < n; in++ { b := shape.Edge(edges[in]) sign := crosser.CrossingSign(b.V0, b.V1) if crossType == CrossingTypeAll && (sign == MaybeCross || sign == Cross) || crossType != CrossingTypeAll && sign == Cross { edges[out] = edges[in] out++ } } if out < n { edges = edges[0:out] } return edges }
go
func (c *CrossingEdgeQuery) Crossings(a, b Point, shape Shape, crossType CrossingType) []int { edges := c.candidates(a, b, shape) if len(edges) == 0 { return nil } crosser := NewEdgeCrosser(a, b) out := 0 n := len(edges) for in := 0; in < n; in++ { b := shape.Edge(edges[in]) sign := crosser.CrossingSign(b.V0, b.V1) if crossType == CrossingTypeAll && (sign == MaybeCross || sign == Cross) || crossType != CrossingTypeAll && sign == Cross { edges[out] = edges[in] out++ } } if out < n { edges = edges[0:out] } return edges }
[ "func", "(", "c", "*", "CrossingEdgeQuery", ")", "Crossings", "(", "a", ",", "b", "Point", ",", "shape", "Shape", ",", "crossType", "CrossingType", ")", "[", "]", "int", "{", "edges", ":=", "c", ".", "candidates", "(", "a", ",", "b", ",", "shape", ")", "\n", "if", "len", "(", "edges", ")", "==", "0", "{", "return", "nil", "\n", "}", "\n\n", "crosser", ":=", "NewEdgeCrosser", "(", "a", ",", "b", ")", "\n", "out", ":=", "0", "\n", "n", ":=", "len", "(", "edges", ")", "\n\n", "for", "in", ":=", "0", ";", "in", "<", "n", ";", "in", "++", "{", "b", ":=", "shape", ".", "Edge", "(", "edges", "[", "in", "]", ")", "\n", "sign", ":=", "crosser", ".", "CrossingSign", "(", "b", ".", "V0", ",", "b", ".", "V1", ")", "\n", "if", "crossType", "==", "CrossingTypeAll", "&&", "(", "sign", "==", "MaybeCross", "||", "sign", "==", "Cross", ")", "||", "crossType", "!=", "CrossingTypeAll", "&&", "sign", "==", "Cross", "{", "edges", "[", "out", "]", "=", "edges", "[", "in", "]", "\n", "out", "++", "\n", "}", "\n", "}", "\n\n", "if", "out", "<", "n", "{", "edges", "=", "edges", "[", "0", ":", "out", "]", "\n", "}", "\n", "return", "edges", "\n", "}" ]
// Crossings returns the set of edge of the shape S that intersect the given edge AB. // If the CrossingType is Interior, then only intersections at a point interior to both // edges are reported, while if it is CrossingTypeAll then edges that share a vertex // are also reported.
[ "Crossings", "returns", "the", "set", "of", "edge", "of", "the", "shape", "S", "that", "intersect", "the", "given", "edge", "AB", ".", "If", "the", "CrossingType", "is", "Interior", "then", "only", "intersections", "at", "a", "point", "interior", "to", "both", "edges", "are", "reported", "while", "if", "it", "is", "CrossingTypeAll", "then", "edges", "that", "share", "a", "vertex", "are", "also", "reported", "." ]
476085157cff9aaeef4d4f124649436542d4114a
https://github.com/golang/geo/blob/476085157cff9aaeef4d4f124649436542d4114a/s2/crossing_edge_query.go#L55-L78
149,957
golang/geo
s2/crossing_edge_query.go
CrossingsEdgeMap
func (c *CrossingEdgeQuery) CrossingsEdgeMap(a, b Point, crossType CrossingType) EdgeMap { edgeMap := c.candidatesEdgeMap(a, b) if len(edgeMap) == 0 { return nil } crosser := NewEdgeCrosser(a, b) for shape, edges := range edgeMap { out := 0 n := len(edges) for in := 0; in < n; in++ { edge := shape.Edge(edges[in]) sign := crosser.CrossingSign(edge.V0, edge.V1) if (crossType == CrossingTypeAll && (sign == MaybeCross || sign == Cross)) || (crossType != CrossingTypeAll && sign == Cross) { edgeMap[shape][out] = edges[in] out++ } } if out == 0 { delete(edgeMap, shape) } else { if out < n { edgeMap[shape] = edgeMap[shape][0:out] } } } return edgeMap }
go
func (c *CrossingEdgeQuery) CrossingsEdgeMap(a, b Point, crossType CrossingType) EdgeMap { edgeMap := c.candidatesEdgeMap(a, b) if len(edgeMap) == 0 { return nil } crosser := NewEdgeCrosser(a, b) for shape, edges := range edgeMap { out := 0 n := len(edges) for in := 0; in < n; in++ { edge := shape.Edge(edges[in]) sign := crosser.CrossingSign(edge.V0, edge.V1) if (crossType == CrossingTypeAll && (sign == MaybeCross || sign == Cross)) || (crossType != CrossingTypeAll && sign == Cross) { edgeMap[shape][out] = edges[in] out++ } } if out == 0 { delete(edgeMap, shape) } else { if out < n { edgeMap[shape] = edgeMap[shape][0:out] } } } return edgeMap }
[ "func", "(", "c", "*", "CrossingEdgeQuery", ")", "CrossingsEdgeMap", "(", "a", ",", "b", "Point", ",", "crossType", "CrossingType", ")", "EdgeMap", "{", "edgeMap", ":=", "c", ".", "candidatesEdgeMap", "(", "a", ",", "b", ")", "\n", "if", "len", "(", "edgeMap", ")", "==", "0", "{", "return", "nil", "\n", "}", "\n\n", "crosser", ":=", "NewEdgeCrosser", "(", "a", ",", "b", ")", "\n", "for", "shape", ",", "edges", ":=", "range", "edgeMap", "{", "out", ":=", "0", "\n", "n", ":=", "len", "(", "edges", ")", "\n", "for", "in", ":=", "0", ";", "in", "<", "n", ";", "in", "++", "{", "edge", ":=", "shape", ".", "Edge", "(", "edges", "[", "in", "]", ")", "\n", "sign", ":=", "crosser", ".", "CrossingSign", "(", "edge", ".", "V0", ",", "edge", ".", "V1", ")", "\n", "if", "(", "crossType", "==", "CrossingTypeAll", "&&", "(", "sign", "==", "MaybeCross", "||", "sign", "==", "Cross", ")", ")", "||", "(", "crossType", "!=", "CrossingTypeAll", "&&", "sign", "==", "Cross", ")", "{", "edgeMap", "[", "shape", "]", "[", "out", "]", "=", "edges", "[", "in", "]", "\n", "out", "++", "\n", "}", "\n", "}", "\n\n", "if", "out", "==", "0", "{", "delete", "(", "edgeMap", ",", "shape", ")", "\n", "}", "else", "{", "if", "out", "<", "n", "{", "edgeMap", "[", "shape", "]", "=", "edgeMap", "[", "shape", "]", "[", "0", ":", "out", "]", "\n", "}", "\n", "}", "\n", "}", "\n", "return", "edgeMap", "\n", "}" ]
// CrossingsEdgeMap returns the set of all edges in the index that intersect the given // edge AB. If crossType is CrossingTypeInterior, then only intersections at a // point interior to both edges are reported, while if it is CrossingTypeAll // then edges that share a vertex are also reported. // // The edges are returned as a mapping from shape to the edges of that shape // that intersect AB. Every returned shape has at least one crossing edge.
[ "CrossingsEdgeMap", "returns", "the", "set", "of", "all", "edges", "in", "the", "index", "that", "intersect", "the", "given", "edge", "AB", ".", "If", "crossType", "is", "CrossingTypeInterior", "then", "only", "intersections", "at", "a", "point", "interior", "to", "both", "edges", "are", "reported", "while", "if", "it", "is", "CrossingTypeAll", "then", "edges", "that", "share", "a", "vertex", "are", "also", "reported", ".", "The", "edges", "are", "returned", "as", "a", "mapping", "from", "shape", "to", "the", "edges", "of", "that", "shape", "that", "intersect", "AB", ".", "Every", "returned", "shape", "has", "at", "least", "one", "crossing", "edge", "." ]
476085157cff9aaeef4d4f124649436542d4114a
https://github.com/golang/geo/blob/476085157cff9aaeef4d4f124649436542d4114a/s2/crossing_edge_query.go#L90-L118
149,958
golang/geo
s2/crossing_edge_query.go
candidates
func (c *CrossingEdgeQuery) candidates(a, b Point, shape Shape) []int { var edges []int // For small loops it is faster to use brute force. The threshold below was // determined using benchmarks. const maxBruteForceEdges = 27 maxEdges := shape.NumEdges() if maxEdges <= maxBruteForceEdges { edges = make([]int, maxEdges) for i := 0; i < maxEdges; i++ { edges[i] = i } return edges } // Compute the set of index cells intersected by the query edge. c.getCellsForEdge(a, b) if len(c.cells) == 0 { return nil } // Gather all the edges that intersect those cells and sort them. // TODO(roberts): Shapes don't track their ID, so we need to range over // the index to find the ID manually. var shapeID int32 for k, v := range c.index.shapes { if v == shape { shapeID = k } } for _, cell := range c.cells { if cell == nil { } clipped := cell.findByShapeID(shapeID) if clipped == nil { continue } for _, j := range clipped.edges { edges = append(edges, j) } } if len(c.cells) > 1 { edges = uniqueInts(edges) } return edges }
go
func (c *CrossingEdgeQuery) candidates(a, b Point, shape Shape) []int { var edges []int // For small loops it is faster to use brute force. The threshold below was // determined using benchmarks. const maxBruteForceEdges = 27 maxEdges := shape.NumEdges() if maxEdges <= maxBruteForceEdges { edges = make([]int, maxEdges) for i := 0; i < maxEdges; i++ { edges[i] = i } return edges } // Compute the set of index cells intersected by the query edge. c.getCellsForEdge(a, b) if len(c.cells) == 0 { return nil } // Gather all the edges that intersect those cells and sort them. // TODO(roberts): Shapes don't track their ID, so we need to range over // the index to find the ID manually. var shapeID int32 for k, v := range c.index.shapes { if v == shape { shapeID = k } } for _, cell := range c.cells { if cell == nil { } clipped := cell.findByShapeID(shapeID) if clipped == nil { continue } for _, j := range clipped.edges { edges = append(edges, j) } } if len(c.cells) > 1 { edges = uniqueInts(edges) } return edges }
[ "func", "(", "c", "*", "CrossingEdgeQuery", ")", "candidates", "(", "a", ",", "b", "Point", ",", "shape", "Shape", ")", "[", "]", "int", "{", "var", "edges", "[", "]", "int", "\n\n", "// For small loops it is faster to use brute force. The threshold below was", "// determined using benchmarks.", "const", "maxBruteForceEdges", "=", "27", "\n", "maxEdges", ":=", "shape", ".", "NumEdges", "(", ")", "\n", "if", "maxEdges", "<=", "maxBruteForceEdges", "{", "edges", "=", "make", "(", "[", "]", "int", ",", "maxEdges", ")", "\n", "for", "i", ":=", "0", ";", "i", "<", "maxEdges", ";", "i", "++", "{", "edges", "[", "i", "]", "=", "i", "\n", "}", "\n", "return", "edges", "\n", "}", "\n\n", "// Compute the set of index cells intersected by the query edge.", "c", ".", "getCellsForEdge", "(", "a", ",", "b", ")", "\n", "if", "len", "(", "c", ".", "cells", ")", "==", "0", "{", "return", "nil", "\n", "}", "\n\n", "// Gather all the edges that intersect those cells and sort them.", "// TODO(roberts): Shapes don't track their ID, so we need to range over", "// the index to find the ID manually.", "var", "shapeID", "int32", "\n", "for", "k", ",", "v", ":=", "range", "c", ".", "index", ".", "shapes", "{", "if", "v", "==", "shape", "{", "shapeID", "=", "k", "\n", "}", "\n", "}", "\n\n", "for", "_", ",", "cell", ":=", "range", "c", ".", "cells", "{", "if", "cell", "==", "nil", "{", "}", "\n", "clipped", ":=", "cell", ".", "findByShapeID", "(", "shapeID", ")", "\n", "if", "clipped", "==", "nil", "{", "continue", "\n", "}", "\n", "for", "_", ",", "j", ":=", "range", "clipped", ".", "edges", "{", "edges", "=", "append", "(", "edges", ",", "j", ")", "\n", "}", "\n", "}", "\n\n", "if", "len", "(", "c", ".", "cells", ")", ">", "1", "{", "edges", "=", "uniqueInts", "(", "edges", ")", "\n", "}", "\n\n", "return", "edges", "\n", "}" ]
// candidates returns a superset of the edges of the given shape that intersect // the edge AB.
[ "candidates", "returns", "a", "superset", "of", "the", "edges", "of", "the", "given", "shape", "that", "intersect", "the", "edge", "AB", "." ]
476085157cff9aaeef4d4f124649436542d4114a
https://github.com/golang/geo/blob/476085157cff9aaeef4d4f124649436542d4114a/s2/crossing_edge_query.go#L122-L170
149,959
golang/geo
s2/crossing_edge_query.go
uniqueInts
func uniqueInts(in []int) []int { var edges []int m := make(map[int]bool) for _, i := range in { if m[i] { continue } m[i] = true edges = append(edges, i) } sort.Ints(edges) return edges }
go
func uniqueInts(in []int) []int { var edges []int m := make(map[int]bool) for _, i := range in { if m[i] { continue } m[i] = true edges = append(edges, i) } sort.Ints(edges) return edges }
[ "func", "uniqueInts", "(", "in", "[", "]", "int", ")", "[", "]", "int", "{", "var", "edges", "[", "]", "int", "\n", "m", ":=", "make", "(", "map", "[", "int", "]", "bool", ")", "\n", "for", "_", ",", "i", ":=", "range", "in", "{", "if", "m", "[", "i", "]", "{", "continue", "\n", "}", "\n", "m", "[", "i", "]", "=", "true", "\n", "edges", "=", "append", "(", "edges", ",", "i", ")", "\n", "}", "\n", "sort", ".", "Ints", "(", "edges", ")", "\n", "return", "edges", "\n", "}" ]
// uniqueInts returns the sorted uniqued values from the given input.
[ "uniqueInts", "returns", "the", "sorted", "uniqued", "values", "from", "the", "given", "input", "." ]
476085157cff9aaeef4d4f124649436542d4114a
https://github.com/golang/geo/blob/476085157cff9aaeef4d4f124649436542d4114a/s2/crossing_edge_query.go#L173-L185
149,960
golang/geo
s2/crossing_edge_query.go
getCells
func (c *CrossingEdgeQuery) getCells(a, b Point, root *PaddedCell) []*ShapeIndexCell { aUV, bUV, ok := ClipToFace(a, b, root.id.Face()) if ok { c.a = aUV c.b = bUV edgeBound := r2.RectFromPoints(c.a, c.b) if root.Bound().Intersects(edgeBound) { c.computeCellsIntersected(root, edgeBound) } } if len(c.cells) == 0 { return nil } return c.cells }
go
func (c *CrossingEdgeQuery) getCells(a, b Point, root *PaddedCell) []*ShapeIndexCell { aUV, bUV, ok := ClipToFace(a, b, root.id.Face()) if ok { c.a = aUV c.b = bUV edgeBound := r2.RectFromPoints(c.a, c.b) if root.Bound().Intersects(edgeBound) { c.computeCellsIntersected(root, edgeBound) } } if len(c.cells) == 0 { return nil } return c.cells }
[ "func", "(", "c", "*", "CrossingEdgeQuery", ")", "getCells", "(", "a", ",", "b", "Point", ",", "root", "*", "PaddedCell", ")", "[", "]", "*", "ShapeIndexCell", "{", "aUV", ",", "bUV", ",", "ok", ":=", "ClipToFace", "(", "a", ",", "b", ",", "root", ".", "id", ".", "Face", "(", ")", ")", "\n", "if", "ok", "{", "c", ".", "a", "=", "aUV", "\n", "c", ".", "b", "=", "bUV", "\n", "edgeBound", ":=", "r2", ".", "RectFromPoints", "(", "c", ".", "a", ",", "c", ".", "b", ")", "\n", "if", "root", ".", "Bound", "(", ")", ".", "Intersects", "(", "edgeBound", ")", "{", "c", ".", "computeCellsIntersected", "(", "root", ",", "edgeBound", ")", "\n", "}", "\n", "}", "\n\n", "if", "len", "(", "c", ".", "cells", ")", "==", "0", "{", "return", "nil", "\n", "}", "\n\n", "return", "c", ".", "cells", "\n", "}" ]
// getCells returns the set of ShapeIndexCells that might contain edges intersecting // the edge AB in the given cell root. This method is used primarly by loop and shapeutil.
[ "getCells", "returns", "the", "set", "of", "ShapeIndexCells", "that", "might", "contain", "edges", "intersecting", "the", "edge", "AB", "in", "the", "given", "cell", "root", ".", "This", "method", "is", "used", "primarly", "by", "loop", "and", "shapeutil", "." ]
476085157cff9aaeef4d4f124649436542d4114a
https://github.com/golang/geo/blob/476085157cff9aaeef4d4f124649436542d4114a/s2/crossing_edge_query.go#L236-L252
149,961
golang/geo
s2/crossing_edge_query.go
getCellsForEdge
func (c *CrossingEdgeQuery) getCellsForEdge(a, b Point) { c.cells = nil segments := FaceSegments(a, b) for _, segment := range segments { c.a = segment.a c.b = segment.b // Optimization: rather than always starting the recursive subdivision at // the top level face cell, instead we start at the smallest S2CellId that // contains the edge (the edge root cell). This typically lets us skip // quite a few levels of recursion since most edges are short. edgeBound := r2.RectFromPoints(c.a, c.b) pcell := PaddedCellFromCellID(CellIDFromFace(segment.face), 0) edgeRoot := pcell.ShrinkToFit(edgeBound) // Now we need to determine how the edge root cell is related to the cells // in the spatial index (cellMap). There are three cases: // // 1. edgeRoot is an index cell or is contained within an index cell. // In this case we only need to look at the contents of that cell. // 2. edgeRoot is subdivided into one or more index cells. In this case // we recursively subdivide to find the cells intersected by AB. // 3. edgeRoot does not intersect any index cells. In this case there // is nothing to do. relation := c.iter.LocateCellID(edgeRoot) if relation == Indexed { // edgeRoot is an index cell or is contained by an index cell (case 1). c.cells = append(c.cells, c.iter.IndexCell()) } else if relation == Subdivided { // edgeRoot is subdivided into one or more index cells (case 2). We // find the cells intersected by AB using recursive subdivision. if !edgeRoot.isFace() { pcell = PaddedCellFromCellID(edgeRoot, 0) } c.computeCellsIntersected(pcell, edgeBound) } } }
go
func (c *CrossingEdgeQuery) getCellsForEdge(a, b Point) { c.cells = nil segments := FaceSegments(a, b) for _, segment := range segments { c.a = segment.a c.b = segment.b // Optimization: rather than always starting the recursive subdivision at // the top level face cell, instead we start at the smallest S2CellId that // contains the edge (the edge root cell). This typically lets us skip // quite a few levels of recursion since most edges are short. edgeBound := r2.RectFromPoints(c.a, c.b) pcell := PaddedCellFromCellID(CellIDFromFace(segment.face), 0) edgeRoot := pcell.ShrinkToFit(edgeBound) // Now we need to determine how the edge root cell is related to the cells // in the spatial index (cellMap). There are three cases: // // 1. edgeRoot is an index cell or is contained within an index cell. // In this case we only need to look at the contents of that cell. // 2. edgeRoot is subdivided into one or more index cells. In this case // we recursively subdivide to find the cells intersected by AB. // 3. edgeRoot does not intersect any index cells. In this case there // is nothing to do. relation := c.iter.LocateCellID(edgeRoot) if relation == Indexed { // edgeRoot is an index cell or is contained by an index cell (case 1). c.cells = append(c.cells, c.iter.IndexCell()) } else if relation == Subdivided { // edgeRoot is subdivided into one or more index cells (case 2). We // find the cells intersected by AB using recursive subdivision. if !edgeRoot.isFace() { pcell = PaddedCellFromCellID(edgeRoot, 0) } c.computeCellsIntersected(pcell, edgeBound) } } }
[ "func", "(", "c", "*", "CrossingEdgeQuery", ")", "getCellsForEdge", "(", "a", ",", "b", "Point", ")", "{", "c", ".", "cells", "=", "nil", "\n\n", "segments", ":=", "FaceSegments", "(", "a", ",", "b", ")", "\n", "for", "_", ",", "segment", ":=", "range", "segments", "{", "c", ".", "a", "=", "segment", ".", "a", "\n", "c", ".", "b", "=", "segment", ".", "b", "\n\n", "// Optimization: rather than always starting the recursive subdivision at", "// the top level face cell, instead we start at the smallest S2CellId that", "// contains the edge (the edge root cell). This typically lets us skip", "// quite a few levels of recursion since most edges are short.", "edgeBound", ":=", "r2", ".", "RectFromPoints", "(", "c", ".", "a", ",", "c", ".", "b", ")", "\n", "pcell", ":=", "PaddedCellFromCellID", "(", "CellIDFromFace", "(", "segment", ".", "face", ")", ",", "0", ")", "\n", "edgeRoot", ":=", "pcell", ".", "ShrinkToFit", "(", "edgeBound", ")", "\n\n", "// Now we need to determine how the edge root cell is related to the cells", "// in the spatial index (cellMap). There are three cases:", "//", "// 1. edgeRoot is an index cell or is contained within an index cell.", "// In this case we only need to look at the contents of that cell.", "// 2. edgeRoot is subdivided into one or more index cells. In this case", "// we recursively subdivide to find the cells intersected by AB.", "// 3. edgeRoot does not intersect any index cells. In this case there", "// is nothing to do.", "relation", ":=", "c", ".", "iter", ".", "LocateCellID", "(", "edgeRoot", ")", "\n", "if", "relation", "==", "Indexed", "{", "// edgeRoot is an index cell or is contained by an index cell (case 1).", "c", ".", "cells", "=", "append", "(", "c", ".", "cells", ",", "c", ".", "iter", ".", "IndexCell", "(", ")", ")", "\n", "}", "else", "if", "relation", "==", "Subdivided", "{", "// edgeRoot is subdivided into one or more index cells (case 2). We", "// find the cells intersected by AB using recursive subdivision.", "if", "!", "edgeRoot", ".", "isFace", "(", ")", "{", "pcell", "=", "PaddedCellFromCellID", "(", "edgeRoot", ",", "0", ")", "\n", "}", "\n", "c", ".", "computeCellsIntersected", "(", "pcell", ",", "edgeBound", ")", "\n", "}", "\n", "}", "\n", "}" ]
// getCellsForEdge populates the cells field to the set of index cells intersected by an edge AB.
[ "getCellsForEdge", "populates", "the", "cells", "field", "to", "the", "set", "of", "index", "cells", "intersected", "by", "an", "edge", "AB", "." ]
476085157cff9aaeef4d4f124649436542d4114a
https://github.com/golang/geo/blob/476085157cff9aaeef4d4f124649436542d4114a/s2/crossing_edge_query.go#L255-L293
149,962
golang/geo
s2/crossing_edge_query.go
computeCellsIntersected
func (c *CrossingEdgeQuery) computeCellsIntersected(pcell *PaddedCell, edgeBound r2.Rect) { c.iter.seek(pcell.id.RangeMin()) if c.iter.Done() || c.iter.CellID() > pcell.id.RangeMax() { // The index does not contain pcell or any of its descendants. return } if c.iter.CellID() == pcell.id { // The index contains this cell exactly. c.cells = append(c.cells, c.iter.IndexCell()) return } // Otherwise, split the edge among the four children of pcell. center := pcell.Middle().Lo() if edgeBound.X.Hi < center.X { // Edge is entirely contained in the two left children. c.clipVAxis(edgeBound, center.Y, 0, pcell) return } else if edgeBound.X.Lo >= center.X { // Edge is entirely contained in the two right children. c.clipVAxis(edgeBound, center.Y, 1, pcell) return } childBounds := c.splitUBound(edgeBound, center.X) if edgeBound.Y.Hi < center.Y { // Edge is entirely contained in the two lower children. c.computeCellsIntersected(PaddedCellFromParentIJ(pcell, 0, 0), childBounds[0]) c.computeCellsIntersected(PaddedCellFromParentIJ(pcell, 1, 0), childBounds[1]) } else if edgeBound.Y.Lo >= center.Y { // Edge is entirely contained in the two upper children. c.computeCellsIntersected(PaddedCellFromParentIJ(pcell, 0, 1), childBounds[0]) c.computeCellsIntersected(PaddedCellFromParentIJ(pcell, 1, 1), childBounds[1]) } else { // The edge bound spans all four children. The edge itself intersects // at most three children (since no padding is being used). c.clipVAxis(childBounds[0], center.Y, 0, pcell) c.clipVAxis(childBounds[1], center.Y, 1, pcell) } }
go
func (c *CrossingEdgeQuery) computeCellsIntersected(pcell *PaddedCell, edgeBound r2.Rect) { c.iter.seek(pcell.id.RangeMin()) if c.iter.Done() || c.iter.CellID() > pcell.id.RangeMax() { // The index does not contain pcell or any of its descendants. return } if c.iter.CellID() == pcell.id { // The index contains this cell exactly. c.cells = append(c.cells, c.iter.IndexCell()) return } // Otherwise, split the edge among the four children of pcell. center := pcell.Middle().Lo() if edgeBound.X.Hi < center.X { // Edge is entirely contained in the two left children. c.clipVAxis(edgeBound, center.Y, 0, pcell) return } else if edgeBound.X.Lo >= center.X { // Edge is entirely contained in the two right children. c.clipVAxis(edgeBound, center.Y, 1, pcell) return } childBounds := c.splitUBound(edgeBound, center.X) if edgeBound.Y.Hi < center.Y { // Edge is entirely contained in the two lower children. c.computeCellsIntersected(PaddedCellFromParentIJ(pcell, 0, 0), childBounds[0]) c.computeCellsIntersected(PaddedCellFromParentIJ(pcell, 1, 0), childBounds[1]) } else if edgeBound.Y.Lo >= center.Y { // Edge is entirely contained in the two upper children. c.computeCellsIntersected(PaddedCellFromParentIJ(pcell, 0, 1), childBounds[0]) c.computeCellsIntersected(PaddedCellFromParentIJ(pcell, 1, 1), childBounds[1]) } else { // The edge bound spans all four children. The edge itself intersects // at most three children (since no padding is being used). c.clipVAxis(childBounds[0], center.Y, 0, pcell) c.clipVAxis(childBounds[1], center.Y, 1, pcell) } }
[ "func", "(", "c", "*", "CrossingEdgeQuery", ")", "computeCellsIntersected", "(", "pcell", "*", "PaddedCell", ",", "edgeBound", "r2", ".", "Rect", ")", "{", "c", ".", "iter", ".", "seek", "(", "pcell", ".", "id", ".", "RangeMin", "(", ")", ")", "\n", "if", "c", ".", "iter", ".", "Done", "(", ")", "||", "c", ".", "iter", ".", "CellID", "(", ")", ">", "pcell", ".", "id", ".", "RangeMax", "(", ")", "{", "// The index does not contain pcell or any of its descendants.", "return", "\n", "}", "\n", "if", "c", ".", "iter", ".", "CellID", "(", ")", "==", "pcell", ".", "id", "{", "// The index contains this cell exactly.", "c", ".", "cells", "=", "append", "(", "c", ".", "cells", ",", "c", ".", "iter", ".", "IndexCell", "(", ")", ")", "\n", "return", "\n", "}", "\n\n", "// Otherwise, split the edge among the four children of pcell.", "center", ":=", "pcell", ".", "Middle", "(", ")", ".", "Lo", "(", ")", "\n\n", "if", "edgeBound", ".", "X", ".", "Hi", "<", "center", ".", "X", "{", "// Edge is entirely contained in the two left children.", "c", ".", "clipVAxis", "(", "edgeBound", ",", "center", ".", "Y", ",", "0", ",", "pcell", ")", "\n", "return", "\n", "}", "else", "if", "edgeBound", ".", "X", ".", "Lo", ">=", "center", ".", "X", "{", "// Edge is entirely contained in the two right children.", "c", ".", "clipVAxis", "(", "edgeBound", ",", "center", ".", "Y", ",", "1", ",", "pcell", ")", "\n", "return", "\n", "}", "\n\n", "childBounds", ":=", "c", ".", "splitUBound", "(", "edgeBound", ",", "center", ".", "X", ")", "\n", "if", "edgeBound", ".", "Y", ".", "Hi", "<", "center", ".", "Y", "{", "// Edge is entirely contained in the two lower children.", "c", ".", "computeCellsIntersected", "(", "PaddedCellFromParentIJ", "(", "pcell", ",", "0", ",", "0", ")", ",", "childBounds", "[", "0", "]", ")", "\n", "c", ".", "computeCellsIntersected", "(", "PaddedCellFromParentIJ", "(", "pcell", ",", "1", ",", "0", ")", ",", "childBounds", "[", "1", "]", ")", "\n", "}", "else", "if", "edgeBound", ".", "Y", ".", "Lo", ">=", "center", ".", "Y", "{", "// Edge is entirely contained in the two upper children.", "c", ".", "computeCellsIntersected", "(", "PaddedCellFromParentIJ", "(", "pcell", ",", "0", ",", "1", ")", ",", "childBounds", "[", "0", "]", ")", "\n", "c", ".", "computeCellsIntersected", "(", "PaddedCellFromParentIJ", "(", "pcell", ",", "1", ",", "1", ")", ",", "childBounds", "[", "1", "]", ")", "\n", "}", "else", "{", "// The edge bound spans all four children. The edge itself intersects", "// at most three children (since no padding is being used).", "c", ".", "clipVAxis", "(", "childBounds", "[", "0", "]", ",", "center", ".", "Y", ",", "0", ",", "pcell", ")", "\n", "c", ".", "clipVAxis", "(", "childBounds", "[", "1", "]", ",", "center", ".", "Y", ",", "1", ",", "pcell", ")", "\n", "}", "\n", "}" ]
// computeCellsIntersected computes the index cells intersected by the current // edge that are descendants of pcell and adds them to this queries set of cells.
[ "computeCellsIntersected", "computes", "the", "index", "cells", "intersected", "by", "the", "current", "edge", "that", "are", "descendants", "of", "pcell", "and", "adds", "them", "to", "this", "queries", "set", "of", "cells", "." ]
476085157cff9aaeef4d4f124649436542d4114a
https://github.com/golang/geo/blob/476085157cff9aaeef4d4f124649436542d4114a/s2/crossing_edge_query.go#L297-L338
149,963
golang/geo
s2/crossing_edge_query.go
splitUBound
func (c *CrossingEdgeQuery) splitUBound(edgeBound r2.Rect, u float64) [2]r2.Rect { v := edgeBound.Y.ClampPoint(interpolateFloat64(u, c.a.X, c.b.X, c.a.Y, c.b.Y)) // diag indicates which diagonal of the bounding box is spanned by AB: // it is 0 if AB has positive slope, and 1 if AB has negative slope. var diag int if (c.a.X > c.b.X) != (c.a.Y > c.b.Y) { diag = 1 } return splitBound(edgeBound, 0, diag, u, v) }
go
func (c *CrossingEdgeQuery) splitUBound(edgeBound r2.Rect, u float64) [2]r2.Rect { v := edgeBound.Y.ClampPoint(interpolateFloat64(u, c.a.X, c.b.X, c.a.Y, c.b.Y)) // diag indicates which diagonal of the bounding box is spanned by AB: // it is 0 if AB has positive slope, and 1 if AB has negative slope. var diag int if (c.a.X > c.b.X) != (c.a.Y > c.b.Y) { diag = 1 } return splitBound(edgeBound, 0, diag, u, v) }
[ "func", "(", "c", "*", "CrossingEdgeQuery", ")", "splitUBound", "(", "edgeBound", "r2", ".", "Rect", ",", "u", "float64", ")", "[", "2", "]", "r2", ".", "Rect", "{", "v", ":=", "edgeBound", ".", "Y", ".", "ClampPoint", "(", "interpolateFloat64", "(", "u", ",", "c", ".", "a", ".", "X", ",", "c", ".", "b", ".", "X", ",", "c", ".", "a", ".", "Y", ",", "c", ".", "b", ".", "Y", ")", ")", "\n", "// diag indicates which diagonal of the bounding box is spanned by AB:", "// it is 0 if AB has positive slope, and 1 if AB has negative slope.", "var", "diag", "int", "\n", "if", "(", "c", ".", "a", ".", "X", ">", "c", ".", "b", ".", "X", ")", "!=", "(", "c", ".", "a", ".", "Y", ">", "c", ".", "b", ".", "Y", ")", "{", "diag", "=", "1", "\n", "}", "\n", "return", "splitBound", "(", "edgeBound", ",", "0", ",", "diag", ",", "u", ",", "v", ")", "\n", "}" ]
// splitUBound returns the bound for two children as a result of spliting the // current edge at the given value U.
[ "splitUBound", "returns", "the", "bound", "for", "two", "children", "as", "a", "result", "of", "spliting", "the", "current", "edge", "at", "the", "given", "value", "U", "." ]
476085157cff9aaeef4d4f124649436542d4114a
https://github.com/golang/geo/blob/476085157cff9aaeef4d4f124649436542d4114a/s2/crossing_edge_query.go#L362-L371
149,964
golang/geo
s2/polyline_measures.go
polylineLength
func polylineLength(p []Point) s1.Angle { var length s1.Angle for i := 1; i < len(p); i++ { length += p[i-1].Distance(p[i]) } return length }
go
func polylineLength(p []Point) s1.Angle { var length s1.Angle for i := 1; i < len(p); i++ { length += p[i-1].Distance(p[i]) } return length }
[ "func", "polylineLength", "(", "p", "[", "]", "Point", ")", "s1", ".", "Angle", "{", "var", "length", "s1", ".", "Angle", "\n\n", "for", "i", ":=", "1", ";", "i", "<", "len", "(", "p", ")", ";", "i", "++", "{", "length", "+=", "p", "[", "i", "-", "1", "]", ".", "Distance", "(", "p", "[", "i", "]", ")", "\n", "}", "\n", "return", "length", "\n", "}" ]
// polylineLength returns the length of the given Polyline. // It returns 0 for polylines with fewer than two vertices.
[ "polylineLength", "returns", "the", "length", "of", "the", "given", "Polyline", ".", "It", "returns", "0", "for", "polylines", "with", "fewer", "than", "two", "vertices", "." ]
476085157cff9aaeef4d4f124649436542d4114a
https://github.com/golang/geo/blob/476085157cff9aaeef4d4f124649436542d4114a/s2/polyline_measures.go#L28-L35
149,965
golang/geo
s2/latlng.go
LatLngFromDegrees
func LatLngFromDegrees(lat, lng float64) LatLng { return LatLng{s1.Angle(lat) * s1.Degree, s1.Angle(lng) * s1.Degree} }
go
func LatLngFromDegrees(lat, lng float64) LatLng { return LatLng{s1.Angle(lat) * s1.Degree, s1.Angle(lng) * s1.Degree} }
[ "func", "LatLngFromDegrees", "(", "lat", ",", "lng", "float64", ")", "LatLng", "{", "return", "LatLng", "{", "s1", ".", "Angle", "(", "lat", ")", "*", "s1", ".", "Degree", ",", "s1", ".", "Angle", "(", "lng", ")", "*", "s1", ".", "Degree", "}", "\n", "}" ]
// LatLngFromDegrees returns a LatLng for the coordinates given in degrees.
[ "LatLngFromDegrees", "returns", "a", "LatLng", "for", "the", "coordinates", "given", "in", "degrees", "." ]
476085157cff9aaeef4d4f124649436542d4114a
https://github.com/golang/geo/blob/476085157cff9aaeef4d4f124649436542d4114a/s2/latlng.go#L36-L38
149,966
golang/geo
s2/latlng.go
Distance
func (ll LatLng) Distance(ll2 LatLng) s1.Angle { // Haversine formula, as used in C++ S2LatLng::GetDistance. lat1, lat2 := ll.Lat.Radians(), ll2.Lat.Radians() lng1, lng2 := ll.Lng.Radians(), ll2.Lng.Radians() dlat := math.Sin(0.5 * (lat2 - lat1)) dlng := math.Sin(0.5 * (lng2 - lng1)) x := dlat*dlat + dlng*dlng*math.Cos(lat1)*math.Cos(lat2) return s1.Angle(2*math.Atan2(math.Sqrt(x), math.Sqrt(math.Max(0, 1-x)))) * s1.Radian }
go
func (ll LatLng) Distance(ll2 LatLng) s1.Angle { // Haversine formula, as used in C++ S2LatLng::GetDistance. lat1, lat2 := ll.Lat.Radians(), ll2.Lat.Radians() lng1, lng2 := ll.Lng.Radians(), ll2.Lng.Radians() dlat := math.Sin(0.5 * (lat2 - lat1)) dlng := math.Sin(0.5 * (lng2 - lng1)) x := dlat*dlat + dlng*dlng*math.Cos(lat1)*math.Cos(lat2) return s1.Angle(2*math.Atan2(math.Sqrt(x), math.Sqrt(math.Max(0, 1-x)))) * s1.Radian }
[ "func", "(", "ll", "LatLng", ")", "Distance", "(", "ll2", "LatLng", ")", "s1", ".", "Angle", "{", "// Haversine formula, as used in C++ S2LatLng::GetDistance.", "lat1", ",", "lat2", ":=", "ll", ".", "Lat", ".", "Radians", "(", ")", ",", "ll2", ".", "Lat", ".", "Radians", "(", ")", "\n", "lng1", ",", "lng2", ":=", "ll", ".", "Lng", ".", "Radians", "(", ")", ",", "ll2", ".", "Lng", ".", "Radians", "(", ")", "\n", "dlat", ":=", "math", ".", "Sin", "(", "0.5", "*", "(", "lat2", "-", "lat1", ")", ")", "\n", "dlng", ":=", "math", ".", "Sin", "(", "0.5", "*", "(", "lng2", "-", "lng1", ")", ")", "\n", "x", ":=", "dlat", "*", "dlat", "+", "dlng", "*", "dlng", "*", "math", ".", "Cos", "(", "lat1", ")", "*", "math", ".", "Cos", "(", "lat2", ")", "\n", "return", "s1", ".", "Angle", "(", "2", "*", "math", ".", "Atan2", "(", "math", ".", "Sqrt", "(", "x", ")", ",", "math", ".", "Sqrt", "(", "math", ".", "Max", "(", "0", ",", "1", "-", "x", ")", ")", ")", ")", "*", "s1", ".", "Radian", "\n", "}" ]
// Distance returns the angle between two LatLngs.
[ "Distance", "returns", "the", "angle", "between", "two", "LatLngs", "." ]
476085157cff9aaeef4d4f124649436542d4114a
https://github.com/golang/geo/blob/476085157cff9aaeef4d4f124649436542d4114a/s2/latlng.go#L61-L69
149,967
golang/geo
r3/vector.go
IsUnit
func (v Vector) IsUnit() bool { const epsilon = 5e-14 return math.Abs(v.Norm2()-1) <= epsilon }
go
func (v Vector) IsUnit() bool { const epsilon = 5e-14 return math.Abs(v.Norm2()-1) <= epsilon }
[ "func", "(", "v", "Vector", ")", "IsUnit", "(", ")", "bool", "{", "const", "epsilon", "=", "5e-14", "\n", "return", "math", ".", "Abs", "(", "v", ".", "Norm2", "(", ")", "-", "1", ")", "<=", "epsilon", "\n", "}" ]
// IsUnit returns whether this vector is of approximately unit length.
[ "IsUnit", "returns", "whether", "this", "vector", "is", "of", "approximately", "unit", "length", "." ]
476085157cff9aaeef4d4f124649436542d4114a
https://github.com/golang/geo/blob/476085157cff9aaeef4d4f124649436542d4114a/r3/vector.go#L53-L56
149,968
golang/geo
r3/vector.go
Angle
func (v Vector) Angle(ov Vector) s1.Angle { return s1.Angle(math.Atan2(v.Cross(ov).Norm(), v.Dot(ov))) * s1.Radian }
go
func (v Vector) Angle(ov Vector) s1.Angle { return s1.Angle(math.Atan2(v.Cross(ov).Norm(), v.Dot(ov))) * s1.Radian }
[ "func", "(", "v", "Vector", ")", "Angle", "(", "ov", "Vector", ")", "s1", ".", "Angle", "{", "return", "s1", ".", "Angle", "(", "math", ".", "Atan2", "(", "v", ".", "Cross", "(", "ov", ")", ".", "Norm", "(", ")", ",", "v", ".", "Dot", "(", "ov", ")", ")", ")", "*", "s1", ".", "Radian", "\n", "}" ]
// Angle returns the angle between v and ov.
[ "Angle", "returns", "the", "angle", "between", "v", "and", "ov", "." ]
476085157cff9aaeef4d4f124649436542d4114a
https://github.com/golang/geo/blob/476085157cff9aaeef4d4f124649436542d4114a/r3/vector.go#L86-L88
149,969
golang/geo
s2/polygon.go
compareLoops
func compareLoops(a, b *Loop) int { if na, nb := a.NumVertices(), b.NumVertices(); na != nb { return na - nb } ai, aDir := a.CanonicalFirstVertex() bi, bDir := b.CanonicalFirstVertex() if aDir != bDir { return aDir - bDir } for n := a.NumVertices() - 1; n >= 0; n, ai, bi = n-1, ai+aDir, bi+bDir { if cmp := a.Vertex(ai).Cmp(b.Vertex(bi).Vector); cmp != 0 { return cmp } } return 0 }
go
func compareLoops(a, b *Loop) int { if na, nb := a.NumVertices(), b.NumVertices(); na != nb { return na - nb } ai, aDir := a.CanonicalFirstVertex() bi, bDir := b.CanonicalFirstVertex() if aDir != bDir { return aDir - bDir } for n := a.NumVertices() - 1; n >= 0; n, ai, bi = n-1, ai+aDir, bi+bDir { if cmp := a.Vertex(ai).Cmp(b.Vertex(bi).Vector); cmp != 0 { return cmp } } return 0 }
[ "func", "compareLoops", "(", "a", ",", "b", "*", "Loop", ")", "int", "{", "if", "na", ",", "nb", ":=", "a", ".", "NumVertices", "(", ")", ",", "b", ".", "NumVertices", "(", ")", ";", "na", "!=", "nb", "{", "return", "na", "-", "nb", "\n", "}", "\n", "ai", ",", "aDir", ":=", "a", ".", "CanonicalFirstVertex", "(", ")", "\n", "bi", ",", "bDir", ":=", "b", ".", "CanonicalFirstVertex", "(", ")", "\n", "if", "aDir", "!=", "bDir", "{", "return", "aDir", "-", "bDir", "\n", "}", "\n", "for", "n", ":=", "a", ".", "NumVertices", "(", ")", "-", "1", ";", "n", ">=", "0", ";", "n", ",", "ai", ",", "bi", "=", "n", "-", "1", ",", "ai", "+", "aDir", ",", "bi", "+", "bDir", "{", "if", "cmp", ":=", "a", ".", "Vertex", "(", "ai", ")", ".", "Cmp", "(", "b", ".", "Vertex", "(", "bi", ")", ".", "Vector", ")", ";", "cmp", "!=", "0", "{", "return", "cmp", "\n", "}", "\n", "}", "\n", "return", "0", "\n", "}" ]
// Defines a total ordering on Loops that does not depend on the cyclic // order of loop vertices. This function is used to choose which loop to // invert in the case where several loops have exactly the same area.
[ "Defines", "a", "total", "ordering", "on", "Loops", "that", "does", "not", "depend", "on", "the", "cyclic", "order", "of", "loop", "vertices", ".", "This", "function", "is", "used", "to", "choose", "which", "loop", "to", "invert", "in", "the", "case", "where", "several", "loops", "have", "exactly", "the", "same", "area", "." ]
476085157cff9aaeef4d4f124649436542d4114a
https://github.com/golang/geo/blob/476085157cff9aaeef4d4f124649436542d4114a/s2/polygon.go#L254-L269
149,970
golang/geo
s2/polygon.go
insertLoop
func (lm loopMap) insertLoop(newLoop, parent *Loop) { var children []*Loop for done := false; !done; { children = lm[parent] done = true for _, child := range children { if child.ContainsNested(newLoop) { parent = child done = false break } } } // Now, we have found a parent for this loop, it may be that some of the // children of the parent of this loop may now be children of the new loop. newChildren := lm[newLoop] for i := 0; i < len(children); { child := children[i] if newLoop.ContainsNested(child) { newChildren = append(newChildren, child) children = append(children[0:i], children[i+1:]...) } else { i++ } } lm[newLoop] = newChildren lm[parent] = append(children, newLoop) }
go
func (lm loopMap) insertLoop(newLoop, parent *Loop) { var children []*Loop for done := false; !done; { children = lm[parent] done = true for _, child := range children { if child.ContainsNested(newLoop) { parent = child done = false break } } } // Now, we have found a parent for this loop, it may be that some of the // children of the parent of this loop may now be children of the new loop. newChildren := lm[newLoop] for i := 0; i < len(children); { child := children[i] if newLoop.ContainsNested(child) { newChildren = append(newChildren, child) children = append(children[0:i], children[i+1:]...) } else { i++ } } lm[newLoop] = newChildren lm[parent] = append(children, newLoop) }
[ "func", "(", "lm", "loopMap", ")", "insertLoop", "(", "newLoop", ",", "parent", "*", "Loop", ")", "{", "var", "children", "[", "]", "*", "Loop", "\n", "for", "done", ":=", "false", ";", "!", "done", ";", "{", "children", "=", "lm", "[", "parent", "]", "\n", "done", "=", "true", "\n", "for", "_", ",", "child", ":=", "range", "children", "{", "if", "child", ".", "ContainsNested", "(", "newLoop", ")", "{", "parent", "=", "child", "\n", "done", "=", "false", "\n", "break", "\n", "}", "\n", "}", "\n", "}", "\n\n", "// Now, we have found a parent for this loop, it may be that some of the", "// children of the parent of this loop may now be children of the new loop.", "newChildren", ":=", "lm", "[", "newLoop", "]", "\n", "for", "i", ":=", "0", ";", "i", "<", "len", "(", "children", ")", ";", "{", "child", ":=", "children", "[", "i", "]", "\n", "if", "newLoop", ".", "ContainsNested", "(", "child", ")", "{", "newChildren", "=", "append", "(", "newChildren", ",", "child", ")", "\n", "children", "=", "append", "(", "children", "[", "0", ":", "i", "]", ",", "children", "[", "i", "+", "1", ":", "]", "...", ")", "\n", "}", "else", "{", "i", "++", "\n", "}", "\n", "}", "\n\n", "lm", "[", "newLoop", "]", "=", "newChildren", "\n", "lm", "[", "parent", "]", "=", "append", "(", "children", ",", "newLoop", ")", "\n", "}" ]
// insertLoop adds the given loop to the loop map under the specified parent. // All children of the new entry are checked to see if the need to move up to // a different level.
[ "insertLoop", "adds", "the", "given", "loop", "to", "the", "loop", "map", "under", "the", "specified", "parent", ".", "All", "children", "of", "the", "new", "entry", "are", "checked", "to", "see", "if", "the", "need", "to", "move", "up", "to", "a", "different", "level", "." ]
476085157cff9aaeef4d4f124649436542d4114a
https://github.com/golang/geo/blob/476085157cff9aaeef4d4f124649436542d4114a/s2/polygon.go#L305-L334
149,971
golang/geo
s2/polygon.go
initLoops
func (p *Polygon) initLoops(lm loopMap) { var stack loopStack stack.push(nil) depth := -1 for len(stack) > 0 { loop := stack.pop() if loop != nil { depth = loop.depth p.loops = append(p.loops, loop) } children := lm[loop] for i := len(children) - 1; i >= 0; i-- { child := children[i] child.depth = depth + 1 stack.push(child) } } }
go
func (p *Polygon) initLoops(lm loopMap) { var stack loopStack stack.push(nil) depth := -1 for len(stack) > 0 { loop := stack.pop() if loop != nil { depth = loop.depth p.loops = append(p.loops, loop) } children := lm[loop] for i := len(children) - 1; i >= 0; i-- { child := children[i] child.depth = depth + 1 stack.push(child) } } }
[ "func", "(", "p", "*", "Polygon", ")", "initLoops", "(", "lm", "loopMap", ")", "{", "var", "stack", "loopStack", "\n", "stack", ".", "push", "(", "nil", ")", "\n", "depth", ":=", "-", "1", "\n\n", "for", "len", "(", "stack", ")", ">", "0", "{", "loop", ":=", "stack", ".", "pop", "(", ")", "\n", "if", "loop", "!=", "nil", "{", "depth", "=", "loop", ".", "depth", "\n", "p", ".", "loops", "=", "append", "(", "p", ".", "loops", ",", "loop", ")", "\n", "}", "\n", "children", ":=", "lm", "[", "loop", "]", "\n", "for", "i", ":=", "len", "(", "children", ")", "-", "1", ";", "i", ">=", "0", ";", "i", "--", "{", "child", ":=", "children", "[", "i", "]", "\n", "child", ".", "depth", "=", "depth", "+", "1", "\n", "stack", ".", "push", "(", "child", ")", "\n", "}", "\n", "}", "\n", "}" ]
// initLoops walks the mapping of loops to all of their children, and adds them in // order into to the polygons set of loops.
[ "initLoops", "walks", "the", "mapping", "of", "loops", "to", "all", "of", "their", "children", "and", "adds", "them", "in", "order", "into", "to", "the", "polygons", "set", "of", "loops", "." ]
476085157cff9aaeef4d4f124649436542d4114a
https://github.com/golang/geo/blob/476085157cff9aaeef4d4f124649436542d4114a/s2/polygon.go#L351-L369
149,972
golang/geo
s2/polygon.go
initLoopProperties
func (p *Polygon) initLoopProperties() { // the loops depths are set by initNested/initOriented prior to this. p.hasHoles = false for _, l := range p.loops { if l.IsHole() { p.hasHoles = true } else { p.bound = p.bound.Union(l.RectBound()) } p.numVertices += l.NumVertices() } p.subregionBound = ExpandForSubregions(p.bound) p.initEdgesAndIndex() }
go
func (p *Polygon) initLoopProperties() { // the loops depths are set by initNested/initOriented prior to this. p.hasHoles = false for _, l := range p.loops { if l.IsHole() { p.hasHoles = true } else { p.bound = p.bound.Union(l.RectBound()) } p.numVertices += l.NumVertices() } p.subregionBound = ExpandForSubregions(p.bound) p.initEdgesAndIndex() }
[ "func", "(", "p", "*", "Polygon", ")", "initLoopProperties", "(", ")", "{", "// the loops depths are set by initNested/initOriented prior to this.", "p", ".", "hasHoles", "=", "false", "\n", "for", "_", ",", "l", ":=", "range", "p", ".", "loops", "{", "if", "l", ".", "IsHole", "(", ")", "{", "p", ".", "hasHoles", "=", "true", "\n", "}", "else", "{", "p", ".", "bound", "=", "p", ".", "bound", ".", "Union", "(", "l", ".", "RectBound", "(", ")", ")", "\n", "}", "\n", "p", ".", "numVertices", "+=", "l", ".", "NumVertices", "(", ")", "\n", "}", "\n", "p", ".", "subregionBound", "=", "ExpandForSubregions", "(", "p", ".", "bound", ")", "\n\n", "p", ".", "initEdgesAndIndex", "(", ")", "\n", "}" ]
// initLoopProperties sets the properties for polygons with multiple loops.
[ "initLoopProperties", "sets", "the", "properties", "for", "polygons", "with", "multiple", "loops", "." ]
476085157cff9aaeef4d4f124649436542d4114a
https://github.com/golang/geo/blob/476085157cff9aaeef4d4f124649436542d4114a/s2/polygon.go#L385-L400
149,973
golang/geo
s2/polygon.go
initEdgesAndIndex
func (p *Polygon) initEdgesAndIndex() { if p.IsFull() { return } const maxLinearSearchLoops = 12 // Based on benchmarks. if len(p.loops) > maxLinearSearchLoops { p.cumulativeEdges = make([]int, 0, len(p.loops)) } for _, l := range p.loops { if p.cumulativeEdges != nil { p.cumulativeEdges = append(p.cumulativeEdges, p.numEdges) } p.numEdges += len(l.vertices) } p.index = NewShapeIndex() p.index.Add(p) }
go
func (p *Polygon) initEdgesAndIndex() { if p.IsFull() { return } const maxLinearSearchLoops = 12 // Based on benchmarks. if len(p.loops) > maxLinearSearchLoops { p.cumulativeEdges = make([]int, 0, len(p.loops)) } for _, l := range p.loops { if p.cumulativeEdges != nil { p.cumulativeEdges = append(p.cumulativeEdges, p.numEdges) } p.numEdges += len(l.vertices) } p.index = NewShapeIndex() p.index.Add(p) }
[ "func", "(", "p", "*", "Polygon", ")", "initEdgesAndIndex", "(", ")", "{", "if", "p", ".", "IsFull", "(", ")", "{", "return", "\n", "}", "\n", "const", "maxLinearSearchLoops", "=", "12", "// Based on benchmarks.", "\n", "if", "len", "(", "p", ".", "loops", ")", ">", "maxLinearSearchLoops", "{", "p", ".", "cumulativeEdges", "=", "make", "(", "[", "]", "int", ",", "0", ",", "len", "(", "p", ".", "loops", ")", ")", "\n", "}", "\n\n", "for", "_", ",", "l", ":=", "range", "p", ".", "loops", "{", "if", "p", ".", "cumulativeEdges", "!=", "nil", "{", "p", ".", "cumulativeEdges", "=", "append", "(", "p", ".", "cumulativeEdges", ",", "p", ".", "numEdges", ")", "\n", "}", "\n", "p", ".", "numEdges", "+=", "len", "(", "l", ".", "vertices", ")", "\n", "}", "\n\n", "p", ".", "index", "=", "NewShapeIndex", "(", ")", "\n", "p", ".", "index", ".", "Add", "(", "p", ")", "\n", "}" ]
// initEdgesAndIndex performs the shape related initializations and adds the final // polygon to the index.
[ "initEdgesAndIndex", "performs", "the", "shape", "related", "initializations", "and", "adds", "the", "final", "polygon", "to", "the", "index", "." ]
476085157cff9aaeef4d4f124649436542d4114a
https://github.com/golang/geo/blob/476085157cff9aaeef4d4f124649436542d4114a/s2/polygon.go#L404-L422
149,974
golang/geo
s2/polygon.go
FullPolygon
func FullPolygon() *Polygon { ret := &Polygon{ loops: []*Loop{ FullLoop(), }, numVertices: len(FullLoop().Vertices()), bound: FullRect(), subregionBound: FullRect(), } ret.initEdgesAndIndex() return ret }
go
func FullPolygon() *Polygon { ret := &Polygon{ loops: []*Loop{ FullLoop(), }, numVertices: len(FullLoop().Vertices()), bound: FullRect(), subregionBound: FullRect(), } ret.initEdgesAndIndex() return ret }
[ "func", "FullPolygon", "(", ")", "*", "Polygon", "{", "ret", ":=", "&", "Polygon", "{", "loops", ":", "[", "]", "*", "Loop", "{", "FullLoop", "(", ")", ",", "}", ",", "numVertices", ":", "len", "(", "FullLoop", "(", ")", ".", "Vertices", "(", ")", ")", ",", "bound", ":", "FullRect", "(", ")", ",", "subregionBound", ":", "FullRect", "(", ")", ",", "}", "\n", "ret", ".", "initEdgesAndIndex", "(", ")", "\n", "return", "ret", "\n", "}" ]
// FullPolygon returns a special "full" polygon.
[ "FullPolygon", "returns", "a", "special", "full", "polygon", "." ]
476085157cff9aaeef4d4f124649436542d4114a
https://github.com/golang/geo/blob/476085157cff9aaeef4d4f124649436542d4114a/s2/polygon.go#L425-L436
149,975
golang/geo
s2/polygon.go
Validate
func (p *Polygon) Validate() error { for i, l := range p.loops { // Check for loop errors that don't require building a ShapeIndex. if err := l.findValidationErrorNoIndex(); err != nil { return fmt.Errorf("loop %d: %v", i, err) } // Check that no loop is empty, and that the full loop only appears in the // full polygon. if l.IsEmpty() { return fmt.Errorf("loop %d: empty loops are not allowed", i) } if l.IsFull() && len(p.loops) > 1 { return fmt.Errorf("loop %d: full loop appears in non-full polygon", i) } } // TODO(roberts): Uncomment the remaining checks when they are completed. // Check for loop self-intersections and loop pairs that cross // (including duplicate edges and vertices). // if findSelfIntersection(p.index) { // return fmt.Errorf("polygon has loop pairs that cross") // } // Check whether initOriented detected inconsistent loop orientations. // if p.hasInconsistentLoopOrientations { // return fmt.Errorf("inconsistent loop orientations detected") // } // Finally, verify the loop nesting hierarchy. return p.findLoopNestingError() }
go
func (p *Polygon) Validate() error { for i, l := range p.loops { // Check for loop errors that don't require building a ShapeIndex. if err := l.findValidationErrorNoIndex(); err != nil { return fmt.Errorf("loop %d: %v", i, err) } // Check that no loop is empty, and that the full loop only appears in the // full polygon. if l.IsEmpty() { return fmt.Errorf("loop %d: empty loops are not allowed", i) } if l.IsFull() && len(p.loops) > 1 { return fmt.Errorf("loop %d: full loop appears in non-full polygon", i) } } // TODO(roberts): Uncomment the remaining checks when they are completed. // Check for loop self-intersections and loop pairs that cross // (including duplicate edges and vertices). // if findSelfIntersection(p.index) { // return fmt.Errorf("polygon has loop pairs that cross") // } // Check whether initOriented detected inconsistent loop orientations. // if p.hasInconsistentLoopOrientations { // return fmt.Errorf("inconsistent loop orientations detected") // } // Finally, verify the loop nesting hierarchy. return p.findLoopNestingError() }
[ "func", "(", "p", "*", "Polygon", ")", "Validate", "(", ")", "error", "{", "for", "i", ",", "l", ":=", "range", "p", ".", "loops", "{", "// Check for loop errors that don't require building a ShapeIndex.", "if", "err", ":=", "l", ".", "findValidationErrorNoIndex", "(", ")", ";", "err", "!=", "nil", "{", "return", "fmt", ".", "Errorf", "(", "\"", "\"", ",", "i", ",", "err", ")", "\n", "}", "\n", "// Check that no loop is empty, and that the full loop only appears in the", "// full polygon.", "if", "l", ".", "IsEmpty", "(", ")", "{", "return", "fmt", ".", "Errorf", "(", "\"", "\"", ",", "i", ")", "\n", "}", "\n", "if", "l", ".", "IsFull", "(", ")", "&&", "len", "(", "p", ".", "loops", ")", ">", "1", "{", "return", "fmt", ".", "Errorf", "(", "\"", "\"", ",", "i", ")", "\n", "}", "\n", "}", "\n\n", "// TODO(roberts): Uncomment the remaining checks when they are completed.", "// Check for loop self-intersections and loop pairs that cross", "// (including duplicate edges and vertices).", "// if findSelfIntersection(p.index) {", "//\treturn fmt.Errorf(\"polygon has loop pairs that cross\")", "// }", "// Check whether initOriented detected inconsistent loop orientations.", "// if p.hasInconsistentLoopOrientations {", "// \treturn fmt.Errorf(\"inconsistent loop orientations detected\")", "// }", "// Finally, verify the loop nesting hierarchy.", "return", "p", ".", "findLoopNestingError", "(", ")", "\n", "}" ]
// Validate checks whether this is a valid polygon, // including checking whether all the loops are themselves valid.
[ "Validate", "checks", "whether", "this", "is", "a", "valid", "polygon", "including", "checking", "whether", "all", "the", "loops", "are", "themselves", "valid", "." ]
476085157cff9aaeef4d4f124649436542d4114a
https://github.com/golang/geo/blob/476085157cff9aaeef4d4f124649436542d4114a/s2/polygon.go#L440-L471
149,976
golang/geo
s2/polygon.go
findLoopNestingError
func (p *Polygon) findLoopNestingError() error { // First check that the loop depths make sense. lastDepth := -1 for i, l := range p.loops { depth := l.depth if depth < 0 || depth > lastDepth+1 { return fmt.Errorf("loop %d: invalid loop depth (%d)", i, depth) } lastDepth = depth } // Then check that they correspond to the actual loop nesting. This test // is quadratic in the number of loops but the cost per iteration is small. for i, l := range p.loops { last := p.LastDescendant(i) for j, l2 := range p.loops { if i == j { continue } nested := (j >= i+1) && (j <= last) const reverseB = false if l.containsNonCrossingBoundary(l2, reverseB) != nested { nestedStr := "" if !nested { nestedStr = "not " } return fmt.Errorf("invalid nesting: loop %d should %scontain loop %d", i, nestedStr, j) } } } return nil }
go
func (p *Polygon) findLoopNestingError() error { // First check that the loop depths make sense. lastDepth := -1 for i, l := range p.loops { depth := l.depth if depth < 0 || depth > lastDepth+1 { return fmt.Errorf("loop %d: invalid loop depth (%d)", i, depth) } lastDepth = depth } // Then check that they correspond to the actual loop nesting. This test // is quadratic in the number of loops but the cost per iteration is small. for i, l := range p.loops { last := p.LastDescendant(i) for j, l2 := range p.loops { if i == j { continue } nested := (j >= i+1) && (j <= last) const reverseB = false if l.containsNonCrossingBoundary(l2, reverseB) != nested { nestedStr := "" if !nested { nestedStr = "not " } return fmt.Errorf("invalid nesting: loop %d should %scontain loop %d", i, nestedStr, j) } } } return nil }
[ "func", "(", "p", "*", "Polygon", ")", "findLoopNestingError", "(", ")", "error", "{", "// First check that the loop depths make sense.", "lastDepth", ":=", "-", "1", "\n", "for", "i", ",", "l", ":=", "range", "p", ".", "loops", "{", "depth", ":=", "l", ".", "depth", "\n", "if", "depth", "<", "0", "||", "depth", ">", "lastDepth", "+", "1", "{", "return", "fmt", ".", "Errorf", "(", "\"", "\"", ",", "i", ",", "depth", ")", "\n", "}", "\n", "lastDepth", "=", "depth", "\n", "}", "\n", "// Then check that they correspond to the actual loop nesting. This test", "// is quadratic in the number of loops but the cost per iteration is small.", "for", "i", ",", "l", ":=", "range", "p", ".", "loops", "{", "last", ":=", "p", ".", "LastDescendant", "(", "i", ")", "\n", "for", "j", ",", "l2", ":=", "range", "p", ".", "loops", "{", "if", "i", "==", "j", "{", "continue", "\n", "}", "\n", "nested", ":=", "(", "j", ">=", "i", "+", "1", ")", "&&", "(", "j", "<=", "last", ")", "\n", "const", "reverseB", "=", "false", "\n\n", "if", "l", ".", "containsNonCrossingBoundary", "(", "l2", ",", "reverseB", ")", "!=", "nested", "{", "nestedStr", ":=", "\"", "\"", "\n", "if", "!", "nested", "{", "nestedStr", "=", "\"", "\"", "\n", "}", "\n", "return", "fmt", ".", "Errorf", "(", "\"", "\"", ",", "i", ",", "nestedStr", ",", "j", ")", "\n", "}", "\n", "}", "\n", "}", "\n", "return", "nil", "\n", "}" ]
// findLoopNestingError reports if there is an error in the loop nesting hierarchy.
[ "findLoopNestingError", "reports", "if", "there", "is", "an", "error", "in", "the", "loop", "nesting", "hierarchy", "." ]
476085157cff9aaeef4d4f124649436542d4114a
https://github.com/golang/geo/blob/476085157cff9aaeef4d4f124649436542d4114a/s2/polygon.go#L474-L505
149,977
golang/geo
s2/polygon.go
Parent
func (p *Polygon) Parent(k int) (index int, ok bool) { // See where we are on the depth hierarchy. depth := p.loops[k].depth if depth == 0 { return -1, false } // There may be several loops at the same nesting level as us that share a // parent loop with us. (Imagine a slice of swiss cheese, of which we are one loop. // we don't know how many may be next to us before we get back to our parent loop.) // Move up one position from us, and then begin traversing back through the set of loops // until we find the one that is our parent or we get to the top of the polygon. for k--; k >= 0 && p.loops[k].depth <= depth; k-- { } return k, true }
go
func (p *Polygon) Parent(k int) (index int, ok bool) { // See where we are on the depth hierarchy. depth := p.loops[k].depth if depth == 0 { return -1, false } // There may be several loops at the same nesting level as us that share a // parent loop with us. (Imagine a slice of swiss cheese, of which we are one loop. // we don't know how many may be next to us before we get back to our parent loop.) // Move up one position from us, and then begin traversing back through the set of loops // until we find the one that is our parent or we get to the top of the polygon. for k--; k >= 0 && p.loops[k].depth <= depth; k-- { } return k, true }
[ "func", "(", "p", "*", "Polygon", ")", "Parent", "(", "k", "int", ")", "(", "index", "int", ",", "ok", "bool", ")", "{", "// See where we are on the depth hierarchy.", "depth", ":=", "p", ".", "loops", "[", "k", "]", ".", "depth", "\n", "if", "depth", "==", "0", "{", "return", "-", "1", ",", "false", "\n", "}", "\n\n", "// There may be several loops at the same nesting level as us that share a", "// parent loop with us. (Imagine a slice of swiss cheese, of which we are one loop.", "// we don't know how many may be next to us before we get back to our parent loop.)", "// Move up one position from us, and then begin traversing back through the set of loops", "// until we find the one that is our parent or we get to the top of the polygon.", "for", "k", "--", ";", "k", ">=", "0", "&&", "p", ".", "loops", "[", "k", "]", ".", "depth", "<=", "depth", ";", "k", "--", "{", "}", "\n", "return", "k", ",", "true", "\n", "}" ]
// Parent returns the index of the parent of loop k. // If the loop does not have a parent, ok=false is returned.
[ "Parent", "returns", "the", "index", "of", "the", "parent", "of", "loop", "k", ".", "If", "the", "loop", "does", "not", "have", "a", "parent", "ok", "=", "false", "is", "returned", "." ]
476085157cff9aaeef4d4f124649436542d4114a
https://github.com/golang/geo/blob/476085157cff9aaeef4d4f124649436542d4114a/s2/polygon.go#L539-L554
149,978
golang/geo
s2/polygon.go
ContainsPoint
func (p *Polygon) ContainsPoint(point Point) bool { // NOTE: A bounds check slows down this function by about 50%. It is // worthwhile only when it might allow us to delay building the index. if !p.index.IsFresh() && !p.bound.ContainsPoint(point) { return false } // For small polygons, and during initial construction, it is faster to just // check all the crossing. const maxBruteForceVertices = 32 if p.numVertices < maxBruteForceVertices || p.index == nil { inside := false for _, l := range p.loops { // use loops bruteforce to avoid building the index on each loop. inside = inside != l.bruteForceContainsPoint(point) } return inside } // Otherwise, look up the ShapeIndex cell containing this point. it := p.index.Iterator() if !it.LocatePoint(point) { return false } return p.iteratorContainsPoint(it, point) }
go
func (p *Polygon) ContainsPoint(point Point) bool { // NOTE: A bounds check slows down this function by about 50%. It is // worthwhile only when it might allow us to delay building the index. if !p.index.IsFresh() && !p.bound.ContainsPoint(point) { return false } // For small polygons, and during initial construction, it is faster to just // check all the crossing. const maxBruteForceVertices = 32 if p.numVertices < maxBruteForceVertices || p.index == nil { inside := false for _, l := range p.loops { // use loops bruteforce to avoid building the index on each loop. inside = inside != l.bruteForceContainsPoint(point) } return inside } // Otherwise, look up the ShapeIndex cell containing this point. it := p.index.Iterator() if !it.LocatePoint(point) { return false } return p.iteratorContainsPoint(it, point) }
[ "func", "(", "p", "*", "Polygon", ")", "ContainsPoint", "(", "point", "Point", ")", "bool", "{", "// NOTE: A bounds check slows down this function by about 50%. It is", "// worthwhile only when it might allow us to delay building the index.", "if", "!", "p", ".", "index", ".", "IsFresh", "(", ")", "&&", "!", "p", ".", "bound", ".", "ContainsPoint", "(", "point", ")", "{", "return", "false", "\n", "}", "\n\n", "// For small polygons, and during initial construction, it is faster to just", "// check all the crossing.", "const", "maxBruteForceVertices", "=", "32", "\n", "if", "p", ".", "numVertices", "<", "maxBruteForceVertices", "||", "p", ".", "index", "==", "nil", "{", "inside", ":=", "false", "\n", "for", "_", ",", "l", ":=", "range", "p", ".", "loops", "{", "// use loops bruteforce to avoid building the index on each loop.", "inside", "=", "inside", "!=", "l", ".", "bruteForceContainsPoint", "(", "point", ")", "\n", "}", "\n", "return", "inside", "\n", "}", "\n\n", "// Otherwise, look up the ShapeIndex cell containing this point.", "it", ":=", "p", ".", "index", ".", "Iterator", "(", ")", "\n", "if", "!", "it", ".", "LocatePoint", "(", "point", ")", "{", "return", "false", "\n", "}", "\n\n", "return", "p", ".", "iteratorContainsPoint", "(", "it", ",", "point", ")", "\n", "}" ]
// ContainsPoint reports whether the polygon contains the point.
[ "ContainsPoint", "reports", "whether", "the", "polygon", "contains", "the", "point", "." ]
476085157cff9aaeef4d4f124649436542d4114a
https://github.com/golang/geo/blob/476085157cff9aaeef4d4f124649436542d4114a/s2/polygon.go#L584-L610
149,979
golang/geo
s2/polygon.go
ContainsCell
func (p *Polygon) ContainsCell(cell Cell) bool { it := p.index.Iterator() relation := it.LocateCellID(cell.ID()) // If "cell" is disjoint from all index cells, it is not contained. // Similarly, if "cell" is subdivided into one or more index cells then it // is not contained, since index cells are subdivided only if they (nearly) // intersect a sufficient number of edges. (But note that if "cell" itself // is an index cell then it may be contained, since it could be a cell with // no edges in the loop interior.) if relation != Indexed { return false } // Otherwise check if any edges intersect "cell". if p.boundaryApproxIntersects(it, cell) { return false } // Otherwise check if the loop contains the center of "cell". return p.iteratorContainsPoint(it, cell.Center()) }
go
func (p *Polygon) ContainsCell(cell Cell) bool { it := p.index.Iterator() relation := it.LocateCellID(cell.ID()) // If "cell" is disjoint from all index cells, it is not contained. // Similarly, if "cell" is subdivided into one or more index cells then it // is not contained, since index cells are subdivided only if they (nearly) // intersect a sufficient number of edges. (But note that if "cell" itself // is an index cell then it may be contained, since it could be a cell with // no edges in the loop interior.) if relation != Indexed { return false } // Otherwise check if any edges intersect "cell". if p.boundaryApproxIntersects(it, cell) { return false } // Otherwise check if the loop contains the center of "cell". return p.iteratorContainsPoint(it, cell.Center()) }
[ "func", "(", "p", "*", "Polygon", ")", "ContainsCell", "(", "cell", "Cell", ")", "bool", "{", "it", ":=", "p", ".", "index", ".", "Iterator", "(", ")", "\n", "relation", ":=", "it", ".", "LocateCellID", "(", "cell", ".", "ID", "(", ")", ")", "\n\n", "// If \"cell\" is disjoint from all index cells, it is not contained.", "// Similarly, if \"cell\" is subdivided into one or more index cells then it", "// is not contained, since index cells are subdivided only if they (nearly)", "// intersect a sufficient number of edges. (But note that if \"cell\" itself", "// is an index cell then it may be contained, since it could be a cell with", "// no edges in the loop interior.)", "if", "relation", "!=", "Indexed", "{", "return", "false", "\n", "}", "\n\n", "// Otherwise check if any edges intersect \"cell\".", "if", "p", ".", "boundaryApproxIntersects", "(", "it", ",", "cell", ")", "{", "return", "false", "\n", "}", "\n\n", "// Otherwise check if the loop contains the center of \"cell\".", "return", "p", ".", "iteratorContainsPoint", "(", "it", ",", "cell", ".", "Center", "(", ")", ")", "\n", "}" ]
// ContainsCell reports whether the polygon contains the given cell.
[ "ContainsCell", "reports", "whether", "the", "polygon", "contains", "the", "given", "cell", "." ]
476085157cff9aaeef4d4f124649436542d4114a
https://github.com/golang/geo/blob/476085157cff9aaeef4d4f124649436542d4114a/s2/polygon.go#L613-L634
149,980
golang/geo
s2/polygon.go
IntersectsCell
func (p *Polygon) IntersectsCell(cell Cell) bool { it := p.index.Iterator() relation := it.LocateCellID(cell.ID()) // If cell does not overlap any index cell, there is no intersection. if relation == Disjoint { return false } // If cell is subdivided into one or more index cells, there is an // intersection to within the S2ShapeIndex error bound (see Contains). if relation == Subdivided { return true } // If cell is an index cell, there is an intersection because index cells // are created only if they have at least one edge or they are entirely // contained by the loop. if it.CellID() == cell.id { return true } // Otherwise check if any edges intersect cell. if p.boundaryApproxIntersects(it, cell) { return true } // Otherwise check if the loop contains the center of cell. return p.iteratorContainsPoint(it, cell.Center()) }
go
func (p *Polygon) IntersectsCell(cell Cell) bool { it := p.index.Iterator() relation := it.LocateCellID(cell.ID()) // If cell does not overlap any index cell, there is no intersection. if relation == Disjoint { return false } // If cell is subdivided into one or more index cells, there is an // intersection to within the S2ShapeIndex error bound (see Contains). if relation == Subdivided { return true } // If cell is an index cell, there is an intersection because index cells // are created only if they have at least one edge or they are entirely // contained by the loop. if it.CellID() == cell.id { return true } // Otherwise check if any edges intersect cell. if p.boundaryApproxIntersects(it, cell) { return true } // Otherwise check if the loop contains the center of cell. return p.iteratorContainsPoint(it, cell.Center()) }
[ "func", "(", "p", "*", "Polygon", ")", "IntersectsCell", "(", "cell", "Cell", ")", "bool", "{", "it", ":=", "p", ".", "index", ".", "Iterator", "(", ")", "\n", "relation", ":=", "it", ".", "LocateCellID", "(", "cell", ".", "ID", "(", ")", ")", "\n\n", "// If cell does not overlap any index cell, there is no intersection.", "if", "relation", "==", "Disjoint", "{", "return", "false", "\n", "}", "\n", "// If cell is subdivided into one or more index cells, there is an", "// intersection to within the S2ShapeIndex error bound (see Contains).", "if", "relation", "==", "Subdivided", "{", "return", "true", "\n", "}", "\n", "// If cell is an index cell, there is an intersection because index cells", "// are created only if they have at least one edge or they are entirely", "// contained by the loop.", "if", "it", ".", "CellID", "(", ")", "==", "cell", ".", "id", "{", "return", "true", "\n", "}", "\n", "// Otherwise check if any edges intersect cell.", "if", "p", ".", "boundaryApproxIntersects", "(", "it", ",", "cell", ")", "{", "return", "true", "\n", "}", "\n", "// Otherwise check if the loop contains the center of cell.", "return", "p", ".", "iteratorContainsPoint", "(", "it", ",", "cell", ".", "Center", "(", ")", ")", "\n", "}" ]
// IntersectsCell reports whether the polygon intersects the given cell.
[ "IntersectsCell", "reports", "whether", "the", "polygon", "intersects", "the", "given", "cell", "." ]
476085157cff9aaeef4d4f124649436542d4114a
https://github.com/golang/geo/blob/476085157cff9aaeef4d4f124649436542d4114a/s2/polygon.go#L637-L662
149,981
golang/geo
s2/polygon.go
iteratorContainsPoint
func (p *Polygon) iteratorContainsPoint(it *ShapeIndexIterator, point Point) bool { // Test containment by drawing a line segment from the cell center to the // given point and counting edge crossings. aClipped := it.IndexCell().findByShapeID(0) inside := aClipped.containsCenter if len(aClipped.edges) == 0 { return inside } // This block requires ShapeIndex. crosser := NewEdgeCrosser(it.Center(), point) shape := p.index.Shape(0) for _, e := range aClipped.edges { edge := shape.Edge(e) inside = inside != crosser.EdgeOrVertexCrossing(edge.V0, edge.V1) } return inside }
go
func (p *Polygon) iteratorContainsPoint(it *ShapeIndexIterator, point Point) bool { // Test containment by drawing a line segment from the cell center to the // given point and counting edge crossings. aClipped := it.IndexCell().findByShapeID(0) inside := aClipped.containsCenter if len(aClipped.edges) == 0 { return inside } // This block requires ShapeIndex. crosser := NewEdgeCrosser(it.Center(), point) shape := p.index.Shape(0) for _, e := range aClipped.edges { edge := shape.Edge(e) inside = inside != crosser.EdgeOrVertexCrossing(edge.V0, edge.V1) } return inside }
[ "func", "(", "p", "*", "Polygon", ")", "iteratorContainsPoint", "(", "it", "*", "ShapeIndexIterator", ",", "point", "Point", ")", "bool", "{", "// Test containment by drawing a line segment from the cell center to the", "// given point and counting edge crossings.", "aClipped", ":=", "it", ".", "IndexCell", "(", ")", ".", "findByShapeID", "(", "0", ")", "\n", "inside", ":=", "aClipped", ".", "containsCenter", "\n\n", "if", "len", "(", "aClipped", ".", "edges", ")", "==", "0", "{", "return", "inside", "\n", "}", "\n\n", "// This block requires ShapeIndex.", "crosser", ":=", "NewEdgeCrosser", "(", "it", ".", "Center", "(", ")", ",", "point", ")", "\n", "shape", ":=", "p", ".", "index", ".", "Shape", "(", "0", ")", "\n", "for", "_", ",", "e", ":=", "range", "aClipped", ".", "edges", "{", "edge", ":=", "shape", ".", "Edge", "(", "e", ")", "\n", "inside", "=", "inside", "!=", "crosser", ".", "EdgeOrVertexCrossing", "(", "edge", ".", "V0", ",", "edge", ".", "V1", ")", "\n", "}", "\n\n", "return", "inside", "\n", "}" ]
// iteratorContainsPoint reports whether the iterator that is positioned at the // ShapeIndexCell that may contain p, contains the point p.
[ "iteratorContainsPoint", "reports", "whether", "the", "iterator", "that", "is", "positioned", "at", "the", "ShapeIndexCell", "that", "may", "contain", "p", "contains", "the", "point", "p", "." ]
476085157cff9aaeef4d4f124649436542d4114a
https://github.com/golang/geo/blob/476085157cff9aaeef4d4f124649436542d4114a/s2/polygon.go#L704-L723
149,982
golang/geo
s2/polygon.go
ReferencePoint
func (p *Polygon) ReferencePoint() ReferencePoint { containsOrigin := false for _, l := range p.loops { containsOrigin = containsOrigin != l.ContainsOrigin() } return OriginReferencePoint(containsOrigin) }
go
func (p *Polygon) ReferencePoint() ReferencePoint { containsOrigin := false for _, l := range p.loops { containsOrigin = containsOrigin != l.ContainsOrigin() } return OriginReferencePoint(containsOrigin) }
[ "func", "(", "p", "*", "Polygon", ")", "ReferencePoint", "(", ")", "ReferencePoint", "{", "containsOrigin", ":=", "false", "\n", "for", "_", ",", "l", ":=", "range", "p", ".", "loops", "{", "containsOrigin", "=", "containsOrigin", "!=", "l", ".", "ContainsOrigin", "(", ")", "\n", "}", "\n", "return", "OriginReferencePoint", "(", "containsOrigin", ")", "\n", "}" ]
// ReferencePoint returns the reference point for this polygon.
[ "ReferencePoint", "returns", "the", "reference", "point", "for", "this", "polygon", "." ]
476085157cff9aaeef4d4f124649436542d4114a
https://github.com/golang/geo/blob/476085157cff9aaeef4d4f124649436542d4114a/s2/polygon.go#L755-L761
149,983
golang/geo
s2/polygon.go
Contains
func (p *Polygon) Contains(o *Polygon) bool { // If both polygons have one loop, use the more efficient Loop method. // Note that Loop's Contains does its own bounding rectangle check. if len(p.loops) == 1 && len(o.loops) == 1 { return p.loops[0].Contains(o.loops[0]) } // Otherwise if neither polygon has holes, we can still use the more // efficient Loop's Contains method (rather than compareBoundary), // but it's worthwhile to do our own bounds check first. if !p.subregionBound.Contains(o.bound) { // Even though Bound(A) does not contain Bound(B), it is still possible // that A contains B. This can only happen when union of the two bounds // spans all longitudes. For example, suppose that B consists of two // shells with a longitude gap between them, while A consists of one shell // that surrounds both shells of B but goes the other way around the // sphere (so that it does not intersect the longitude gap). if !p.bound.Lng.Union(o.bound.Lng).IsFull() { return false } } if !p.hasHoles && !o.hasHoles { for _, l := range o.loops { if !p.anyLoopContains(l) { return false } } return true } // Polygon A contains B iff B does not intersect the complement of A. From // the intersection algorithm below, this means that the complement of A // must exclude the entire boundary of B, and B must exclude all shell // boundaries of the complement of A. (It can be shown that B must then // exclude the entire boundary of the complement of A.) The first call // below returns false if the boundaries cross, therefore the second call // does not need to check for any crossing edges (which makes it cheaper). return p.containsBoundary(o) && o.excludesNonCrossingComplementShells(p) }
go
func (p *Polygon) Contains(o *Polygon) bool { // If both polygons have one loop, use the more efficient Loop method. // Note that Loop's Contains does its own bounding rectangle check. if len(p.loops) == 1 && len(o.loops) == 1 { return p.loops[0].Contains(o.loops[0]) } // Otherwise if neither polygon has holes, we can still use the more // efficient Loop's Contains method (rather than compareBoundary), // but it's worthwhile to do our own bounds check first. if !p.subregionBound.Contains(o.bound) { // Even though Bound(A) does not contain Bound(B), it is still possible // that A contains B. This can only happen when union of the two bounds // spans all longitudes. For example, suppose that B consists of two // shells with a longitude gap between them, while A consists of one shell // that surrounds both shells of B but goes the other way around the // sphere (so that it does not intersect the longitude gap). if !p.bound.Lng.Union(o.bound.Lng).IsFull() { return false } } if !p.hasHoles && !o.hasHoles { for _, l := range o.loops { if !p.anyLoopContains(l) { return false } } return true } // Polygon A contains B iff B does not intersect the complement of A. From // the intersection algorithm below, this means that the complement of A // must exclude the entire boundary of B, and B must exclude all shell // boundaries of the complement of A. (It can be shown that B must then // exclude the entire boundary of the complement of A.) The first call // below returns false if the boundaries cross, therefore the second call // does not need to check for any crossing edges (which makes it cheaper). return p.containsBoundary(o) && o.excludesNonCrossingComplementShells(p) }
[ "func", "(", "p", "*", "Polygon", ")", "Contains", "(", "o", "*", "Polygon", ")", "bool", "{", "// If both polygons have one loop, use the more efficient Loop method.", "// Note that Loop's Contains does its own bounding rectangle check.", "if", "len", "(", "p", ".", "loops", ")", "==", "1", "&&", "len", "(", "o", ".", "loops", ")", "==", "1", "{", "return", "p", ".", "loops", "[", "0", "]", ".", "Contains", "(", "o", ".", "loops", "[", "0", "]", ")", "\n", "}", "\n\n", "// Otherwise if neither polygon has holes, we can still use the more", "// efficient Loop's Contains method (rather than compareBoundary),", "// but it's worthwhile to do our own bounds check first.", "if", "!", "p", ".", "subregionBound", ".", "Contains", "(", "o", ".", "bound", ")", "{", "// Even though Bound(A) does not contain Bound(B), it is still possible", "// that A contains B. This can only happen when union of the two bounds", "// spans all longitudes. For example, suppose that B consists of two", "// shells with a longitude gap between them, while A consists of one shell", "// that surrounds both shells of B but goes the other way around the", "// sphere (so that it does not intersect the longitude gap).", "if", "!", "p", ".", "bound", ".", "Lng", ".", "Union", "(", "o", ".", "bound", ".", "Lng", ")", ".", "IsFull", "(", ")", "{", "return", "false", "\n", "}", "\n", "}", "\n\n", "if", "!", "p", ".", "hasHoles", "&&", "!", "o", ".", "hasHoles", "{", "for", "_", ",", "l", ":=", "range", "o", ".", "loops", "{", "if", "!", "p", ".", "anyLoopContains", "(", "l", ")", "{", "return", "false", "\n", "}", "\n", "}", "\n", "return", "true", "\n", "}", "\n\n", "// Polygon A contains B iff B does not intersect the complement of A. From", "// the intersection algorithm below, this means that the complement of A", "// must exclude the entire boundary of B, and B must exclude all shell", "// boundaries of the complement of A. (It can be shown that B must then", "// exclude the entire boundary of the complement of A.) The first call", "// below returns false if the boundaries cross, therefore the second call", "// does not need to check for any crossing edges (which makes it cheaper).", "return", "p", ".", "containsBoundary", "(", "o", ")", "&&", "o", ".", "excludesNonCrossingComplementShells", "(", "p", ")", "\n", "}" ]
// Contains reports whether this polygon contains the other polygon. // Specifically, it reports whether all the points in the other polygon // are also in this polygon.
[ "Contains", "reports", "whether", "this", "polygon", "contains", "the", "other", "polygon", ".", "Specifically", "it", "reports", "whether", "all", "the", "points", "in", "the", "other", "polygon", "are", "also", "in", "this", "polygon", "." ]
476085157cff9aaeef4d4f124649436542d4114a
https://github.com/golang/geo/blob/476085157cff9aaeef4d4f124649436542d4114a/s2/polygon.go#L822-L861
149,984
golang/geo
s2/polygon.go
Intersects
func (p *Polygon) Intersects(o *Polygon) bool { // If both polygons have one loop, use the more efficient Loop method. // Note that Loop Intersects does its own bounding rectangle check. if len(p.loops) == 1 && len(o.loops) == 1 { return p.loops[0].Intersects(o.loops[0]) } // Otherwise if neither polygon has holes, we can still use the more // efficient Loop.Intersects method. The polygons intersect if and // only if some pair of loop regions intersect. if !p.bound.Intersects(o.bound) { return false } if !p.hasHoles && !o.hasHoles { for _, l := range o.loops { if p.anyLoopIntersects(l) { return true } } return false } // Polygon A is disjoint from B if A excludes the entire boundary of B and B // excludes all shell boundaries of A. (It can be shown that B must then // exclude the entire boundary of A.) The first call below returns false if // the boundaries cross, therefore the second call does not need to check // for crossing edges. return !p.excludesBoundary(o) || !o.excludesNonCrossingShells(p) }
go
func (p *Polygon) Intersects(o *Polygon) bool { // If both polygons have one loop, use the more efficient Loop method. // Note that Loop Intersects does its own bounding rectangle check. if len(p.loops) == 1 && len(o.loops) == 1 { return p.loops[0].Intersects(o.loops[0]) } // Otherwise if neither polygon has holes, we can still use the more // efficient Loop.Intersects method. The polygons intersect if and // only if some pair of loop regions intersect. if !p.bound.Intersects(o.bound) { return false } if !p.hasHoles && !o.hasHoles { for _, l := range o.loops { if p.anyLoopIntersects(l) { return true } } return false } // Polygon A is disjoint from B if A excludes the entire boundary of B and B // excludes all shell boundaries of A. (It can be shown that B must then // exclude the entire boundary of A.) The first call below returns false if // the boundaries cross, therefore the second call does not need to check // for crossing edges. return !p.excludesBoundary(o) || !o.excludesNonCrossingShells(p) }
[ "func", "(", "p", "*", "Polygon", ")", "Intersects", "(", "o", "*", "Polygon", ")", "bool", "{", "// If both polygons have one loop, use the more efficient Loop method.", "// Note that Loop Intersects does its own bounding rectangle check.", "if", "len", "(", "p", ".", "loops", ")", "==", "1", "&&", "len", "(", "o", ".", "loops", ")", "==", "1", "{", "return", "p", ".", "loops", "[", "0", "]", ".", "Intersects", "(", "o", ".", "loops", "[", "0", "]", ")", "\n", "}", "\n\n", "// Otherwise if neither polygon has holes, we can still use the more", "// efficient Loop.Intersects method. The polygons intersect if and", "// only if some pair of loop regions intersect.", "if", "!", "p", ".", "bound", ".", "Intersects", "(", "o", ".", "bound", ")", "{", "return", "false", "\n", "}", "\n\n", "if", "!", "p", ".", "hasHoles", "&&", "!", "o", ".", "hasHoles", "{", "for", "_", ",", "l", ":=", "range", "o", ".", "loops", "{", "if", "p", ".", "anyLoopIntersects", "(", "l", ")", "{", "return", "true", "\n", "}", "\n", "}", "\n", "return", "false", "\n", "}", "\n\n", "// Polygon A is disjoint from B if A excludes the entire boundary of B and B", "// excludes all shell boundaries of A. (It can be shown that B must then", "// exclude the entire boundary of A.) The first call below returns false if", "// the boundaries cross, therefore the second call does not need to check", "// for crossing edges.", "return", "!", "p", ".", "excludesBoundary", "(", "o", ")", "||", "!", "o", ".", "excludesNonCrossingShells", "(", "p", ")", "\n", "}" ]
// Intersects reports whether this polygon intersects the other polygon, i.e. // if there is a point that is contained by both polygons.
[ "Intersects", "reports", "whether", "this", "polygon", "intersects", "the", "other", "polygon", "i", ".", "e", ".", "if", "there", "is", "a", "point", "that", "is", "contained", "by", "both", "polygons", "." ]
476085157cff9aaeef4d4f124649436542d4114a
https://github.com/golang/geo/blob/476085157cff9aaeef4d4f124649436542d4114a/s2/polygon.go#L865-L894
149,985
golang/geo
s2/polygon.go
compareBoundary
func (p *Polygon) compareBoundary(o *Loop) int { result := -1 for i := 0; i < len(p.loops) && result != 0; i++ { // If B crosses any loop of A, the result is 0. Otherwise the result // changes sign each time B is contained by a loop of A. result *= -p.loops[i].compareBoundary(o) } return result }
go
func (p *Polygon) compareBoundary(o *Loop) int { result := -1 for i := 0; i < len(p.loops) && result != 0; i++ { // If B crosses any loop of A, the result is 0. Otherwise the result // changes sign each time B is contained by a loop of A. result *= -p.loops[i].compareBoundary(o) } return result }
[ "func", "(", "p", "*", "Polygon", ")", "compareBoundary", "(", "o", "*", "Loop", ")", "int", "{", "result", ":=", "-", "1", "\n", "for", "i", ":=", "0", ";", "i", "<", "len", "(", "p", ".", "loops", ")", "&&", "result", "!=", "0", ";", "i", "++", "{", "// If B crosses any loop of A, the result is 0. Otherwise the result", "// changes sign each time B is contained by a loop of A.", "result", "*=", "-", "p", ".", "loops", "[", "i", "]", ".", "compareBoundary", "(", "o", ")", "\n", "}", "\n", "return", "result", "\n", "}" ]
// compareBoundary returns +1 if this polygon contains the boundary of B, -1 if A // excludes the boundary of B, and 0 if the boundaries of A and B cross.
[ "compareBoundary", "returns", "+", "1", "if", "this", "polygon", "contains", "the", "boundary", "of", "B", "-", "1", "if", "A", "excludes", "the", "boundary", "of", "B", "and", "0", "if", "the", "boundaries", "of", "A", "and", "B", "cross", "." ]
476085157cff9aaeef4d4f124649436542d4114a
https://github.com/golang/geo/blob/476085157cff9aaeef4d4f124649436542d4114a/s2/polygon.go#L898-L906
149,986
golang/geo
s2/polygon.go
containsBoundary
func (p *Polygon) containsBoundary(o *Polygon) bool { for _, l := range o.loops { if p.compareBoundary(l) <= 0 { return false } } return true }
go
func (p *Polygon) containsBoundary(o *Polygon) bool { for _, l := range o.loops { if p.compareBoundary(l) <= 0 { return false } } return true }
[ "func", "(", "p", "*", "Polygon", ")", "containsBoundary", "(", "o", "*", "Polygon", ")", "bool", "{", "for", "_", ",", "l", ":=", "range", "o", ".", "loops", "{", "if", "p", ".", "compareBoundary", "(", "l", ")", "<=", "0", "{", "return", "false", "\n", "}", "\n", "}", "\n", "return", "true", "\n", "}" ]
// containsBoundary reports whether this polygon contains the entire boundary of B.
[ "containsBoundary", "reports", "whether", "this", "polygon", "contains", "the", "entire", "boundary", "of", "B", "." ]
476085157cff9aaeef4d4f124649436542d4114a
https://github.com/golang/geo/blob/476085157cff9aaeef4d4f124649436542d4114a/s2/polygon.go#L909-L916
149,987
golang/geo
s2/polygon.go
containsNonCrossingBoundary
func (p *Polygon) containsNonCrossingBoundary(o *Loop, reverse bool) bool { var inside bool for _, l := range p.loops { x := l.containsNonCrossingBoundary(o, reverse) inside = (inside != x) } return inside }
go
func (p *Polygon) containsNonCrossingBoundary(o *Loop, reverse bool) bool { var inside bool for _, l := range p.loops { x := l.containsNonCrossingBoundary(o, reverse) inside = (inside != x) } return inside }
[ "func", "(", "p", "*", "Polygon", ")", "containsNonCrossingBoundary", "(", "o", "*", "Loop", ",", "reverse", "bool", ")", "bool", "{", "var", "inside", "bool", "\n", "for", "_", ",", "l", ":=", "range", "p", ".", "loops", "{", "x", ":=", "l", ".", "containsNonCrossingBoundary", "(", "o", ",", "reverse", ")", "\n", "inside", "=", "(", "inside", "!=", "x", ")", "\n", "}", "\n", "return", "inside", "\n", "}" ]
// containsNonCrossingBoundary reports whether polygon A contains the boundary of // loop B. Shared edges are handled according to the rule described in loops // containsNonCrossingBoundary.
[ "containsNonCrossingBoundary", "reports", "whether", "polygon", "A", "contains", "the", "boundary", "of", "loop", "B", ".", "Shared", "edges", "are", "handled", "according", "to", "the", "rule", "described", "in", "loops", "containsNonCrossingBoundary", "." ]
476085157cff9aaeef4d4f124649436542d4114a
https://github.com/golang/geo/blob/476085157cff9aaeef4d4f124649436542d4114a/s2/polygon.go#L931-L938
149,988
golang/geo
s2/polygon.go
excludesNonCrossingShells
func (p *Polygon) excludesNonCrossingShells(o *Polygon) bool { for _, l := range o.loops { if l.IsHole() { continue } if p.containsNonCrossingBoundary(l, false) { return false } } return true }
go
func (p *Polygon) excludesNonCrossingShells(o *Polygon) bool { for _, l := range o.loops { if l.IsHole() { continue } if p.containsNonCrossingBoundary(l, false) { return false } } return true }
[ "func", "(", "p", "*", "Polygon", ")", "excludesNonCrossingShells", "(", "o", "*", "Polygon", ")", "bool", "{", "for", "_", ",", "l", ":=", "range", "o", ".", "loops", "{", "if", "l", ".", "IsHole", "(", ")", "{", "continue", "\n", "}", "\n", "if", "p", ".", "containsNonCrossingBoundary", "(", "l", ",", "false", ")", "{", "return", "false", "\n", "}", "\n", "}", "\n", "return", "true", "\n", "}" ]
// excludesNonCrossingShells reports wheterh given two polygons A and B such that the // boundary of A does not cross any loop of B, if A excludes all shell boundaries of B.
[ "excludesNonCrossingShells", "reports", "wheterh", "given", "two", "polygons", "A", "and", "B", "such", "that", "the", "boundary", "of", "A", "does", "not", "cross", "any", "loop", "of", "B", "if", "A", "excludes", "all", "shell", "boundaries", "of", "B", "." ]
476085157cff9aaeef4d4f124649436542d4114a
https://github.com/golang/geo/blob/476085157cff9aaeef4d4f124649436542d4114a/s2/polygon.go#L942-L952
149,989
golang/geo
s2/polygon.go
excludesNonCrossingComplementShells
func (p *Polygon) excludesNonCrossingComplementShells(o *Polygon) bool { // Special case to handle the complement of the empty or full polygons. if o.IsEmpty() { return !p.IsFull() } if o.IsFull() { return true } // Otherwise the complement of B may be obtained by inverting loop(0) and // then swapping the shell/hole status of all other loops. This implies // that the shells of the complement consist of loop 0 plus all the holes of // the original polygon. for j, l := range o.loops { if j > 0 && !l.IsHole() { continue } // The interior of the complement is to the right of loop 0, and to the // left of the loops that were originally holes. if p.containsNonCrossingBoundary(l, j == 0) { return false } } return true }
go
func (p *Polygon) excludesNonCrossingComplementShells(o *Polygon) bool { // Special case to handle the complement of the empty or full polygons. if o.IsEmpty() { return !p.IsFull() } if o.IsFull() { return true } // Otherwise the complement of B may be obtained by inverting loop(0) and // then swapping the shell/hole status of all other loops. This implies // that the shells of the complement consist of loop 0 plus all the holes of // the original polygon. for j, l := range o.loops { if j > 0 && !l.IsHole() { continue } // The interior of the complement is to the right of loop 0, and to the // left of the loops that were originally holes. if p.containsNonCrossingBoundary(l, j == 0) { return false } } return true }
[ "func", "(", "p", "*", "Polygon", ")", "excludesNonCrossingComplementShells", "(", "o", "*", "Polygon", ")", "bool", "{", "// Special case to handle the complement of the empty or full polygons.", "if", "o", ".", "IsEmpty", "(", ")", "{", "return", "!", "p", ".", "IsFull", "(", ")", "\n", "}", "\n", "if", "o", ".", "IsFull", "(", ")", "{", "return", "true", "\n", "}", "\n\n", "// Otherwise the complement of B may be obtained by inverting loop(0) and", "// then swapping the shell/hole status of all other loops. This implies", "// that the shells of the complement consist of loop 0 plus all the holes of", "// the original polygon.", "for", "j", ",", "l", ":=", "range", "o", ".", "loops", "{", "if", "j", ">", "0", "&&", "!", "l", ".", "IsHole", "(", ")", "{", "continue", "\n", "}", "\n\n", "// The interior of the complement is to the right of loop 0, and to the", "// left of the loops that were originally holes.", "if", "p", ".", "containsNonCrossingBoundary", "(", "l", ",", "j", "==", "0", ")", "{", "return", "false", "\n", "}", "\n", "}", "\n", "return", "true", "\n", "}" ]
// excludesNonCrossingComplementShells reports whether given two polygons A and B // such that the boundary of A does not cross any loop of B, if A excludes all // shell boundaries of the complement of B.
[ "excludesNonCrossingComplementShells", "reports", "whether", "given", "two", "polygons", "A", "and", "B", "such", "that", "the", "boundary", "of", "A", "does", "not", "cross", "any", "loop", "of", "B", "if", "A", "excludes", "all", "shell", "boundaries", "of", "the", "complement", "of", "B", "." ]
476085157cff9aaeef4d4f124649436542d4114a
https://github.com/golang/geo/blob/476085157cff9aaeef4d4f124649436542d4114a/s2/polygon.go#L957-L982
149,990
golang/geo
s2/polygon.go
anyLoopContains
func (p *Polygon) anyLoopContains(o *Loop) bool { for _, l := range p.loops { if l.Contains(o) { return true } } return false }
go
func (p *Polygon) anyLoopContains(o *Loop) bool { for _, l := range p.loops { if l.Contains(o) { return true } } return false }
[ "func", "(", "p", "*", "Polygon", ")", "anyLoopContains", "(", "o", "*", "Loop", ")", "bool", "{", "for", "_", ",", "l", ":=", "range", "p", ".", "loops", "{", "if", "l", ".", "Contains", "(", "o", ")", "{", "return", "true", "\n", "}", "\n", "}", "\n", "return", "false", "\n", "}" ]
// anyLoopContains reports whether any loop in this polygon contains the given loop.
[ "anyLoopContains", "reports", "whether", "any", "loop", "in", "this", "polygon", "contains", "the", "given", "loop", "." ]
476085157cff9aaeef4d4f124649436542d4114a
https://github.com/golang/geo/blob/476085157cff9aaeef4d4f124649436542d4114a/s2/polygon.go#L985-L992
149,991
golang/geo
s2/polygon.go
anyLoopIntersects
func (p *Polygon) anyLoopIntersects(o *Loop) bool { for _, l := range p.loops { if l.Intersects(o) { return true } } return false }
go
func (p *Polygon) anyLoopIntersects(o *Loop) bool { for _, l := range p.loops { if l.Intersects(o) { return true } } return false }
[ "func", "(", "p", "*", "Polygon", ")", "anyLoopIntersects", "(", "o", "*", "Loop", ")", "bool", "{", "for", "_", ",", "l", ":=", "range", "p", ".", "loops", "{", "if", "l", ".", "Intersects", "(", "o", ")", "{", "return", "true", "\n", "}", "\n", "}", "\n", "return", "false", "\n", "}" ]
// anyLoopIntersects reports whether any loop in this polygon intersects the given loop.
[ "anyLoopIntersects", "reports", "whether", "any", "loop", "in", "this", "polygon", "intersects", "the", "given", "loop", "." ]
476085157cff9aaeef4d4f124649436542d4114a
https://github.com/golang/geo/blob/476085157cff9aaeef4d4f124649436542d4114a/s2/polygon.go#L995-L1002
149,992
golang/geo
s2/polygon.go
encode
func (p *Polygon) encode(e *encoder) { if p.numVertices == 0 { p.encodeCompressed(e, maxLevel, nil) return } // Convert all the polygon vertices to XYZFaceSiTi format. vs := make([]xyzFaceSiTi, 0, p.numVertices) for _, l := range p.loops { vs = append(vs, l.xyzFaceSiTiVertices()...) } // Computes a histogram of the cell levels at which the vertices are snapped. // (histogram[0] is the number of unsnapped vertices, histogram[i] the number // of vertices snapped at level i-1). histogram := make([]int, maxLevel+2) for _, v := range vs { histogram[v.level+1]++ } // Compute the level at which most of the vertices are snapped. // If multiple levels have the same maximum number of vertices // snapped to it, the first one (lowest level number / largest // area / smallest encoding length) will be chosen, so this // is desired. var snapLevel, numSnapped int for level, h := range histogram[1:] { if h > numSnapped { snapLevel, numSnapped = level, h } } // Choose an encoding format based on the number of unsnapped vertices and a // rough estimate of the encoded sizes. numUnsnapped := p.numVertices - numSnapped // Number of vertices that won't be snapped at snapLevel. const pointSize = 3 * 8 // s2.Point is an r3.Vector, which is 3 float64s. That's 3*8 = 24 bytes. compressedSize := 4*p.numVertices + (pointSize+2)*numUnsnapped losslessSize := pointSize * p.numVertices if compressedSize < losslessSize { p.encodeCompressed(e, snapLevel, vs) } else { p.encodeLossless(e) } }
go
func (p *Polygon) encode(e *encoder) { if p.numVertices == 0 { p.encodeCompressed(e, maxLevel, nil) return } // Convert all the polygon vertices to XYZFaceSiTi format. vs := make([]xyzFaceSiTi, 0, p.numVertices) for _, l := range p.loops { vs = append(vs, l.xyzFaceSiTiVertices()...) } // Computes a histogram of the cell levels at which the vertices are snapped. // (histogram[0] is the number of unsnapped vertices, histogram[i] the number // of vertices snapped at level i-1). histogram := make([]int, maxLevel+2) for _, v := range vs { histogram[v.level+1]++ } // Compute the level at which most of the vertices are snapped. // If multiple levels have the same maximum number of vertices // snapped to it, the first one (lowest level number / largest // area / smallest encoding length) will be chosen, so this // is desired. var snapLevel, numSnapped int for level, h := range histogram[1:] { if h > numSnapped { snapLevel, numSnapped = level, h } } // Choose an encoding format based on the number of unsnapped vertices and a // rough estimate of the encoded sizes. numUnsnapped := p.numVertices - numSnapped // Number of vertices that won't be snapped at snapLevel. const pointSize = 3 * 8 // s2.Point is an r3.Vector, which is 3 float64s. That's 3*8 = 24 bytes. compressedSize := 4*p.numVertices + (pointSize+2)*numUnsnapped losslessSize := pointSize * p.numVertices if compressedSize < losslessSize { p.encodeCompressed(e, snapLevel, vs) } else { p.encodeLossless(e) } }
[ "func", "(", "p", "*", "Polygon", ")", "encode", "(", "e", "*", "encoder", ")", "{", "if", "p", ".", "numVertices", "==", "0", "{", "p", ".", "encodeCompressed", "(", "e", ",", "maxLevel", ",", "nil", ")", "\n", "return", "\n", "}", "\n\n", "// Convert all the polygon vertices to XYZFaceSiTi format.", "vs", ":=", "make", "(", "[", "]", "xyzFaceSiTi", ",", "0", ",", "p", ".", "numVertices", ")", "\n", "for", "_", ",", "l", ":=", "range", "p", ".", "loops", "{", "vs", "=", "append", "(", "vs", ",", "l", ".", "xyzFaceSiTiVertices", "(", ")", "...", ")", "\n", "}", "\n\n", "// Computes a histogram of the cell levels at which the vertices are snapped.", "// (histogram[0] is the number of unsnapped vertices, histogram[i] the number", "// of vertices snapped at level i-1).", "histogram", ":=", "make", "(", "[", "]", "int", ",", "maxLevel", "+", "2", ")", "\n", "for", "_", ",", "v", ":=", "range", "vs", "{", "histogram", "[", "v", ".", "level", "+", "1", "]", "++", "\n", "}", "\n\n", "// Compute the level at which most of the vertices are snapped.", "// If multiple levels have the same maximum number of vertices", "// snapped to it, the first one (lowest level number / largest", "// area / smallest encoding length) will be chosen, so this", "// is desired.", "var", "snapLevel", ",", "numSnapped", "int", "\n", "for", "level", ",", "h", ":=", "range", "histogram", "[", "1", ":", "]", "{", "if", "h", ">", "numSnapped", "{", "snapLevel", ",", "numSnapped", "=", "level", ",", "h", "\n", "}", "\n", "}", "\n\n", "// Choose an encoding format based on the number of unsnapped vertices and a", "// rough estimate of the encoded sizes.", "numUnsnapped", ":=", "p", ".", "numVertices", "-", "numSnapped", "// Number of vertices that won't be snapped at snapLevel.", "\n", "const", "pointSize", "=", "3", "*", "8", "// s2.Point is an r3.Vector, which is 3 float64s. That's 3*8 = 24 bytes.", "\n", "compressedSize", ":=", "4", "*", "p", ".", "numVertices", "+", "(", "pointSize", "+", "2", ")", "*", "numUnsnapped", "\n", "losslessSize", ":=", "pointSize", "*", "p", ".", "numVertices", "\n", "if", "compressedSize", "<", "losslessSize", "{", "p", ".", "encodeCompressed", "(", "e", ",", "snapLevel", ",", "vs", ")", "\n", "}", "else", "{", "p", ".", "encodeLossless", "(", "e", ")", "\n", "}", "\n", "}" ]
// encode only supports lossless encoding and not compressed format.
[ "encode", "only", "supports", "lossless", "encoding", "and", "not", "compressed", "format", "." ]
476085157cff9aaeef4d4f124649436542d4114a
https://github.com/golang/geo/blob/476085157cff9aaeef4d4f124649436542d4114a/s2/polygon.go#L1022-L1065
149,993
golang/geo
s2/polygon.go
encodeLossless
func (p *Polygon) encodeLossless(e *encoder) { e.writeInt8(encodingVersion) e.writeBool(true) // a legacy c++ value. must be true. e.writeBool(p.hasHoles) e.writeUint32(uint32(len(p.loops))) if e.err != nil { return } if len(p.loops) > maxEncodedLoops { e.err = fmt.Errorf("too many loops (%d; max is %d)", len(p.loops), maxEncodedLoops) return } for _, l := range p.loops { l.encode(e) } // Encode the bound. p.bound.encode(e) }
go
func (p *Polygon) encodeLossless(e *encoder) { e.writeInt8(encodingVersion) e.writeBool(true) // a legacy c++ value. must be true. e.writeBool(p.hasHoles) e.writeUint32(uint32(len(p.loops))) if e.err != nil { return } if len(p.loops) > maxEncodedLoops { e.err = fmt.Errorf("too many loops (%d; max is %d)", len(p.loops), maxEncodedLoops) return } for _, l := range p.loops { l.encode(e) } // Encode the bound. p.bound.encode(e) }
[ "func", "(", "p", "*", "Polygon", ")", "encodeLossless", "(", "e", "*", "encoder", ")", "{", "e", ".", "writeInt8", "(", "encodingVersion", ")", "\n", "e", ".", "writeBool", "(", "true", ")", "// a legacy c++ value. must be true.", "\n", "e", ".", "writeBool", "(", "p", ".", "hasHoles", ")", "\n", "e", ".", "writeUint32", "(", "uint32", "(", "len", "(", "p", ".", "loops", ")", ")", ")", "\n\n", "if", "e", ".", "err", "!=", "nil", "{", "return", "\n", "}", "\n", "if", "len", "(", "p", ".", "loops", ")", ">", "maxEncodedLoops", "{", "e", ".", "err", "=", "fmt", ".", "Errorf", "(", "\"", "\"", ",", "len", "(", "p", ".", "loops", ")", ",", "maxEncodedLoops", ")", "\n", "return", "\n", "}", "\n", "for", "_", ",", "l", ":=", "range", "p", ".", "loops", "{", "l", ".", "encode", "(", "e", ")", "\n", "}", "\n\n", "// Encode the bound.", "p", ".", "bound", ".", "encode", "(", "e", ")", "\n", "}" ]
// encodeLossless encodes the polygon's Points as float64s.
[ "encodeLossless", "encodes", "the", "polygon", "s", "Points", "as", "float64s", "." ]
476085157cff9aaeef4d4f124649436542d4114a
https://github.com/golang/geo/blob/476085157cff9aaeef4d4f124649436542d4114a/s2/polygon.go#L1068-L1087
149,994
golang/geo
s2/polygon.go
Decode
func (p *Polygon) Decode(r io.Reader) error { d := &decoder{r: asByteReader(r)} version := int8(d.readUint8()) var dec func(*decoder) switch version { case encodingVersion: dec = p.decode case encodingCompressedVersion: dec = p.decodeCompressed default: return fmt.Errorf("unsupported version %d", version) } dec(d) return d.err }
go
func (p *Polygon) Decode(r io.Reader) error { d := &decoder{r: asByteReader(r)} version := int8(d.readUint8()) var dec func(*decoder) switch version { case encodingVersion: dec = p.decode case encodingCompressedVersion: dec = p.decodeCompressed default: return fmt.Errorf("unsupported version %d", version) } dec(d) return d.err }
[ "func", "(", "p", "*", "Polygon", ")", "Decode", "(", "r", "io", ".", "Reader", ")", "error", "{", "d", ":=", "&", "decoder", "{", "r", ":", "asByteReader", "(", "r", ")", "}", "\n", "version", ":=", "int8", "(", "d", ".", "readUint8", "(", ")", ")", "\n", "var", "dec", "func", "(", "*", "decoder", ")", "\n", "switch", "version", "{", "case", "encodingVersion", ":", "dec", "=", "p", ".", "decode", "\n", "case", "encodingCompressedVersion", ":", "dec", "=", "p", ".", "decodeCompressed", "\n", "default", ":", "return", "fmt", ".", "Errorf", "(", "\"", "\"", ",", "version", ")", "\n", "}", "\n", "dec", "(", "d", ")", "\n", "return", "d", ".", "err", "\n", "}" ]
// Decode decodes the Polygon.
[ "Decode", "decodes", "the", "Polygon", "." ]
476085157cff9aaeef4d4f124649436542d4114a
https://github.com/golang/geo/blob/476085157cff9aaeef4d4f124649436542d4114a/s2/polygon.go#L1112-L1126
149,995
golang/geo
s2/rect.go
RectFromLatLng
func RectFromLatLng(p LatLng) Rect { return Rect{ Lat: r1.Interval{p.Lat.Radians(), p.Lat.Radians()}, Lng: s1.Interval{p.Lng.Radians(), p.Lng.Radians()}, } }
go
func RectFromLatLng(p LatLng) Rect { return Rect{ Lat: r1.Interval{p.Lat.Radians(), p.Lat.Radians()}, Lng: s1.Interval{p.Lng.Radians(), p.Lng.Radians()}, } }
[ "func", "RectFromLatLng", "(", "p", "LatLng", ")", "Rect", "{", "return", "Rect", "{", "Lat", ":", "r1", ".", "Interval", "{", "p", ".", "Lat", ".", "Radians", "(", ")", ",", "p", ".", "Lat", ".", "Radians", "(", ")", "}", ",", "Lng", ":", "s1", ".", "Interval", "{", "p", ".", "Lng", ".", "Radians", "(", ")", ",", "p", ".", "Lng", ".", "Radians", "(", ")", "}", ",", "}", "\n", "}" ]
// RectFromLatLng constructs a rectangle containing a single point p.
[ "RectFromLatLng", "constructs", "a", "rectangle", "containing", "a", "single", "point", "p", "." ]
476085157cff9aaeef4d4f124649436542d4114a
https://github.com/golang/geo/blob/476085157cff9aaeef4d4f124649436542d4114a/s2/rect.go#L45-L50
149,996
golang/geo
s2/rect.go
Lo
func (r Rect) Lo() LatLng { return LatLng{s1.Angle(r.Lat.Lo) * s1.Radian, s1.Angle(r.Lng.Lo) * s1.Radian} }
go
func (r Rect) Lo() LatLng { return LatLng{s1.Angle(r.Lat.Lo) * s1.Radian, s1.Angle(r.Lng.Lo) * s1.Radian} }
[ "func", "(", "r", "Rect", ")", "Lo", "(", ")", "LatLng", "{", "return", "LatLng", "{", "s1", ".", "Angle", "(", "r", ".", "Lat", ".", "Lo", ")", "*", "s1", ".", "Radian", ",", "s1", ".", "Angle", "(", "r", ".", "Lng", ".", "Lo", ")", "*", "s1", ".", "Radian", "}", "\n", "}" ]
// Lo returns one corner of the rectangle.
[ "Lo", "returns", "one", "corner", "of", "the", "rectangle", "." ]
476085157cff9aaeef4d4f124649436542d4114a
https://github.com/golang/geo/blob/476085157cff9aaeef4d4f124649436542d4114a/s2/rect.go#L108-L110
149,997
golang/geo
s2/rect.go
Size
func (r Rect) Size() LatLng { return LatLng{s1.Angle(r.Lat.Length()) * s1.Radian, s1.Angle(r.Lng.Length()) * s1.Radian} }
go
func (r Rect) Size() LatLng { return LatLng{s1.Angle(r.Lat.Length()) * s1.Radian, s1.Angle(r.Lng.Length()) * s1.Radian} }
[ "func", "(", "r", "Rect", ")", "Size", "(", ")", "LatLng", "{", "return", "LatLng", "{", "s1", ".", "Angle", "(", "r", ".", "Lat", ".", "Length", "(", ")", ")", "*", "s1", ".", "Radian", ",", "s1", ".", "Angle", "(", "r", ".", "Lng", ".", "Length", "(", ")", ")", "*", "s1", ".", "Radian", "}", "\n", "}" ]
// Size returns the size of the Rect.
[ "Size", "returns", "the", "size", "of", "the", "Rect", "." ]
476085157cff9aaeef4d4f124649436542d4114a
https://github.com/golang/geo/blob/476085157cff9aaeef4d4f124649436542d4114a/s2/rect.go#L123-L125
149,998
golang/geo
s2/rect.go
Area
func (r Rect) Area() float64 { if r.IsEmpty() { return 0 } capDiff := math.Abs(math.Sin(r.Lat.Hi) - math.Sin(r.Lat.Lo)) return r.Lng.Length() * capDiff }
go
func (r Rect) Area() float64 { if r.IsEmpty() { return 0 } capDiff := math.Abs(math.Sin(r.Lat.Hi) - math.Sin(r.Lat.Lo)) return r.Lng.Length() * capDiff }
[ "func", "(", "r", "Rect", ")", "Area", "(", ")", "float64", "{", "if", "r", ".", "IsEmpty", "(", ")", "{", "return", "0", "\n", "}", "\n", "capDiff", ":=", "math", ".", "Abs", "(", "math", ".", "Sin", "(", "r", ".", "Lat", ".", "Hi", ")", "-", "math", ".", "Sin", "(", "r", ".", "Lat", ".", "Lo", ")", ")", "\n", "return", "r", ".", "Lng", ".", "Length", "(", ")", "*", "capDiff", "\n", "}" ]
// Area returns the surface area of the Rect.
[ "Area", "returns", "the", "surface", "area", "of", "the", "Rect", "." ]
476085157cff9aaeef4d4f124649436542d4114a
https://github.com/golang/geo/blob/476085157cff9aaeef4d4f124649436542d4114a/s2/rect.go#L128-L134
149,999
golang/geo
s2/rect.go
AddPoint
func (r Rect) AddPoint(ll LatLng) Rect { if !ll.IsValid() { return r } return Rect{ Lat: r.Lat.AddPoint(ll.Lat.Radians()), Lng: r.Lng.AddPoint(ll.Lng.Radians()), } }
go
func (r Rect) AddPoint(ll LatLng) Rect { if !ll.IsValid() { return r } return Rect{ Lat: r.Lat.AddPoint(ll.Lat.Radians()), Lng: r.Lng.AddPoint(ll.Lng.Radians()), } }
[ "func", "(", "r", "Rect", ")", "AddPoint", "(", "ll", "LatLng", ")", "Rect", "{", "if", "!", "ll", ".", "IsValid", "(", ")", "{", "return", "r", "\n", "}", "\n", "return", "Rect", "{", "Lat", ":", "r", ".", "Lat", ".", "AddPoint", "(", "ll", ".", "Lat", ".", "Radians", "(", ")", ")", ",", "Lng", ":", "r", ".", "Lng", ".", "AddPoint", "(", "ll", ".", "Lng", ".", "Radians", "(", ")", ")", ",", "}", "\n", "}" ]
// AddPoint increases the size of the rectangle to include the given point.
[ "AddPoint", "increases", "the", "size", "of", "the", "rectangle", "to", "include", "the", "given", "point", "." ]
476085157cff9aaeef4d4f124649436542d4114a
https://github.com/golang/geo/blob/476085157cff9aaeef4d4f124649436542d4114a/s2/rect.go#L137-L145