我想在曲面内画一个半圆。所以我想使用,
pygame.draw.arc() 但我不知道如何在表面内绘制圆弧,我已经看到了官方文档,并且正在使用math.radians()将度数转换为弧度,但我看不到圆弧。正在画一个圆...
import pygame
import math
pygame.init()
width, height = 800, 600
screen = pygame.display.set_mode((width, height))
surf = pygame.Surface((100, 100))
surf.fill("green")
rect = surf.get_rect(center=(100, 100))
run = 1
while run:
for event in pygame.event.get():
if event.type == pygame.QUIT:
run = 0
screen.fill((255, 202, 135))
pygame.draw.circle(surf, (255, 255, 255), (30,30),25)
pygame.draw.arc(surf, (255, 255, 255), rect, math.radians(270), math.radians(90))
screen.blit(surf, rect)
pygame.display.flip()
pygame.quit()
Run Code Online (Sandbox Code Playgroud)
提前致谢
我读过有关notnullC# 中的约束的内容,其中写道“这允许值类型或不可为空的引用类型,但不允许可为空的引用类型。” (引用自《Programming C# - 10.0 By Ian Griffiths》)
我尝试在下面的代码中检查这个约束:
MyTestClass<int?> instance1 = new MyTestClass<int?>();
MyTestClass<string?> instance2 = new MyTestClass<string?>();
public class MyTestClass<T> where T : notnull
{
T Value { get; set; }
public MyTestClass()
{
Value = default(T);
if (Value == null)
Console.WriteLine($"Type of T is {typeof(T)} and its default value is 'Null'");
else
Console.WriteLine($"Type of T is {typeof(T)} and its default value is {Value}");
}
}
Run Code Online (Sandbox Code Playgroud)
如您所见,我使用可为空类型int?(可为空值类型)和string?(可为空引用类型)实例化了我的泛型类,它仍然适用于我。
它还为我打印这样的输出:
Type of T …Run Code Online (Sandbox Code Playgroud) 我有索引向量,我想根据它进行过滤。在每一列中,将选择不同的行。输出将是一个过滤值向量,其长度为列数。芽不使用慢循环。例如
set.seed(123)
(M <- matrix(rnorm(25), 5))
[,1] [,2] [,3] [,4] [,5]
[1,] -0.56047565 1.7150650 1.2240818 1.7869131 -1.0678237
[2,] -0.23017749 0.4609162 0.3598138 0.4978505 -0.2179749
[3,] 1.55870831 -1.2650612 0.4007715 -1.9666172 -1.0260044
[4,] 0.07050839 -0.6868529 0.1106827 0.7013559 -0.7288912
[5,] 0.12928774 -0.4456620 -0.5558411 -0.4727914 -0.6250393
indices <- c(2, 3, 1, 4, 4)
vect <- c()
for(i in 1:5) {
vect <- c(vect, M[indices[i], i])
}
vect
[1] -0.2301775 -1.2650612 1.2240818 0.7013559 -0.7288912
Run Code Online (Sandbox Code Playgroud)
我有更大的数据集,因此 for 循环并不理想。但我想不出更好的办法,也找不到更好的办法。
我想在 RStudio 中执行有 2 个条件的连接。我的目标是复制如下所示的SQL 查询,但使用 R 语言:
SELECT
ticket_id,
sum(time_to_close)
FROM helpdesk_ticket ht
LEFT JOIN dim_date dd ON ht.create_date <= dd.formatted_date AND dd.formatted_date <= ht.closed_date
GROUP BY 1
Run Code Online (Sandbox Code Playgroud)
假设 helpdesk_ticket 和 dim_date 是两个 R 数据帧,这是我尝试过的,但它在 left_join 中返回错误:
result <- helpdesk_ticket %>%
left_join(dim_date, by = c("create_date" <= "formatted_date", "formatted_date" <= "closed_date")) %>%
group_by(ticket_id) %>%
summarise(time_to_close = sum(time_to_close))
Run Code Online (Sandbox Code Playgroud) 下面的代码:
#include <stdio.h>
int main(void) {
char buf[80] = "salam";
const char *fmt = "\"%79[^\"]\"";
int n;
n = sscanf("\"\"", fmt, buf);
printf("%d fields were read. buf = '%s'\n", n, buf);
n = sscanf("\"hamidi\"", fmt, buf);
printf("%d fields were read. buf = '%s'\n", n, buf);
}
Run Code Online (Sandbox Code Playgroud)
输出:
已读取 0 个字段。buf = 'salam'
已读取 1 个字段。buf = '哈米迪'
这表明 sscanf 函数无法读取具有指定格式字符串的空字符串。是否有一个很好的替代正则表达式格式字符串来通过 sscanf 函数读取长度为零到最多 79 个字符的字符串?换句话说,我希望第一个 sscanf 将 '\0' 插入 buf[0] 并返回 1 而不是 0。有办法吗?
我有一个计算字符串文字的哈希值的函数:
inline consteval uint64_t HashLiteral(const char* key)
{
// body not important here...
return 0;
}
Run Code Online (Sandbox Code Playgroud)
在另一个函数中,我需要文字字符串及其哈希值,我想在编译时计算它:
void function(const char* s)
{
worker(s, HashLiteral(s));
}
Run Code Online (Sandbox Code Playgroud)
然而,似乎不可能进行这样的调用function("string"),并在编译时在其主体中计算哈希值。我现在想到的最好方法是使用宏,并重新定义函数:
#define MakeHashParms(s) s,HashLiteral(s)
void function(const char* s, const uint64_t hash)
{
worker(s, hash);
}
function(MakeHashParms("string"));
Run Code Online (Sandbox Code Playgroud)
是否可以有更直接的解决方案?
在 Visual Studio 中发布 ASP.Net Core 网站项目时,在“站点扩展选项”下,我会看到以下选项:
选择该选项有什么作用?我的项目已包含Microsoft.ApplicationInsights.AspNetCoreNuGet 包,并且通过Microsoft.Extensions.Logging.Ilogger扩展方法进行日志记录可以按预期将日志记录信息发送到 Application Insights。
来自铁锈书:
在任何给定时间,您可以拥有一个可变引用或任意数量的不可变引用。
考虑以下代码:
fn main() {
let mut a = 41;
let b = &mut a;
let c: &i32 = &a; // [1]
let d: &i32 = &b;
println!("{} {}", b, c); // [2]
println!("{} {}", b, d);
}
Run Code Online (Sandbox Code Playgroud)
如果我们尝试编译我们会得到:
error[E0502]: cannot borrow `a` as immutable because it is also borrowed as mutable
--> src\main.rs:43:19
|
42 | let b = &mut a;
| ------ mutable borrow occurs here
43 | let c: &i32 = &a; // [1] …Run Code Online (Sandbox Code Playgroud) 如果存在std::map<std::pair<std::string, std::string>, some_type>找到其值的最佳方法是什么?
我想最明显的一个是做这样的事情:
但这将导致在对构造期间对和字符串map.find(std::make_pair(str1, str2));
进行复制构造。str1str2
我希望也许map.find(std::make_pair(std::ref(str1), std::ref(str2)));能有所帮助,但不幸的是没有,这仍然会产生字符串副本。
map.find(std::make_pair(std::move(str1), std::move(str2))应该可以工作,但我们假设这些字符串 ( str1, str2) 是 const 或者不应该移动。
所以我问是否有其他方法可以进行地图搜索而不进行多余的字符串副本?
(请注意,使用std::string_viewforstd::map key不是一个选项,因为地图应该拥有其字符串。)
我的 Flutter 应用程序的 Xcode Cloud 构建突然开始失败,而我没有对其进行任何预期的更改。
以下是我的ci_post_clone.sh脚本。
echo "Starting CI script..."
echo $CI_WORKSPACE
# The default execution directory of this script is the ci_scripts directory.
cd $CI_WORKSPACE # change working directory to the root of your cloned repo.
ls
# Install Flutter using git.
git clone https://github.com/flutter/flutter.git --depth 1 -b stable $HOME/flutter
export PATH="$PATH:$HOME/flutter/bin"
# Install Flutter artifacts for iOS (--ios), or macOS (--macos) platforms.
flutter precache --ios
# Install Flutter dependencies.
flutter pub get
# Install CocoaPods …Run Code Online (Sandbox Code Playgroud)