所以我正在玩OpenGL并试图弄清楚如何绘制一些有趣的形状.
现在,我正在做一个管子.我可以画直管很好用:
void tube(GLfloat radius, GLfloat segment_length) {
glPolygonMode(GL_BACK, GL_NONE);
glPolygonMode(GL_FRONT, GL_FILL);
glPushMatrix(); {
GLfloat z1 = 0.0;
GLfloat z2 = segment_length;
GLfloat y_offset = 0.0;
GLfloat y_change = 0.00;
int i = 0;
int j = 0;
for (j = 0; j < 20; j++) {
glPushMatrix(); {
glBegin(GL_TRIANGLE_STRIP); {
for (i = 360; i >= 0; i--) {
GLfloat theta = i * pi/180;
GLfloat x = radius * cos(theta);
GLfloat y = radius * sin(theta) + y_offset; …Run Code Online (Sandbox Code Playgroud) 给定具有此签名的函数:
def parser[A](otherParser: BodyParser[A]): BodyParser[A]
Run Code Online (Sandbox Code Playgroud)
如何在传递请求体之前检查和验证请求体的方式来编写函数otherParser?
为简单起见,我想说我想验证标题("Some-Header",或许)有一个与主体完全匹配的值.所以如果我有这个动作:
def post(): Action(parser(parse.tolerantText)) { request =>
Ok(request.body)
}
Run Code Online (Sandbox Code Playgroud)
当我提出类似请求时curl -H "Some-Header: hello" -d "hello" http://localhost:9000/post,应该在状态为200的响应正文中返回"hello".如果我的请求是curl -H "Some-Header: hello" -d "hi" http://localhost:9000/post它应该返回400没有正文.
这是我尝试过的.
这个不编译因为otherParser(request).through(flow)期望flow输出a ByteString.这里的想法是流程可以通知累加器是否继续通过Either输出进行处理.我不知道如何让累加器知道上一步的状态.
def parser[A](otherParser: BodyParser[A]): BodyParser[A] = BodyParser { request =>
val flow: Flow[ByteString, Either[Result, ByteString], NotUsed] = Flow[ByteString].map { bytes =>
if (request.headers.get("Some-Header").contains(bytes.utf8String)) {
Right(bytes)
} else {
Left(BadRequest)
}
}
val acc: Accumulator[ByteString, Either[Result, A]] = …Run Code Online (Sandbox Code Playgroud) 摘要:
我希望能够针对外部数据库运行查询,以便在用户登录时获取所需的数据.我不希望此站点对外部数据库执行任何其他操作.从长远来看,它可能需要能够推回数据,但具体来说,我不希望symfony尝试为外部数据库构建架构,它应该不管它并且不时允许连接.
细节:
我正在尝试创建一个临时连接到另一个symfony应用程序的数据库,我似乎无法弄清楚如何做到这一点.
我有一个已建立并运行的现有symfony站点.我正在尝试为这个主站点的用户创建一种管理系统.管理系统将为每个选择加入它的用户进行单独部署,因此它也将拥有与之关联的自己的数据库.但是,此管理系统需要从主站点系统访问2或3个表.
我已经尝试在管理系统中的databases.yml中添加单独的条目来创建与两个数据库的连接,但是每当我构建所有数据库时,它都希望将我的模式放在两个数据库中.
我想出的最好的想法是在管理系统的所有表中放置连接:管理,并在主站点的所有表中放置连接:main_site.但是,这需要我在管理系统和主站点上维护yml文件,以确保它们彼此保持最新.
我希望这一点有点清楚.
谢谢你的帮助:D
我正在尝试在Symfony中为我的应用程序创建一个单元测试.
我的/config/app.yml看起来像这样:
all:
tmp_dir: "tmp"
# usps
usps_username: xxxxx
usps_password: xxxxx
usps_dir: usps
Run Code Online (Sandbox Code Playgroud)
在单元测试中,当我运行类似于:
$t->comment(sfConfig::get('app_usps_username'));
Run Code Online (Sandbox Code Playgroud)
它只会输出和空行.这是怎么回事?如何从单元测试中从app.yml访问这些值?如果我尝试从其他地方访问值,它会按预期工作.
我试图确定特定点是否位于多面体内.在我目前的实现中,我正在研究的方法是我们正在寻找多面体的面数组(在这种情况下为三角形,但稍后可能是其他多边形).我一直在努力从这里找到的信息开始工作:http://softsurfer.com/Archive/algorithm_0111/algorithm_0111.htm
下面,你会看到我的"内部"方法.我知道nrml /正常的东西有点奇怪..它是旧代码的结果.当我运行它时,无论我给出什么输入,它似乎总是返回真实.(这个问题已经解决了,请参阅下面的答案 - 此代码现在正在运行).
bool Container::inside(Point* point, float* polyhedron[3], int faces) {
Vector* dS = Vector::fromPoints(point->X, point->Y, point->Z,
100, 100, 100);
int T_e = 0;
int T_l = 1;
for (int i = 0; i < faces; i++) {
float* polygon = polyhedron[i];
float* nrml = normal(&polygon[0], &polygon[1], &polygon[2]);
Vector* normal = new Vector(nrml[0], nrml[1], nrml[2]);
delete nrml;
float N = -((point->X-polygon[0][0])*normal->X +
(point->Y-polygon[0][1])*normal->Y +
(point->Z-polygon[0][2])*normal->Z);
float D = dS->dot(*normal);
if (D == 0) {
if …Run Code Online (Sandbox Code Playgroud) 我有这些定义:
memberx(X, [X|_]).
memberx(X, [_|T]) :- memberx(X, T).
intersectionx([], _, []).
intersectionx([H|T], Y, [_|Z]) :- memberx(H, Y), !, intersectionx(T, Y, Z).
intersectionx([_|T], Y, Z) :- intersectionx(T, Y, Z).
Run Code Online (Sandbox Code Playgroud)
我得到以下结果:
?- intersectionx([1], [1], Z).
Z = [_G305].
Run Code Online (Sandbox Code Playgroud)
为什么不导致Z = [1]?
我很难掌握如何做到这一点.我有一个由三个点定义的多边形.我在太空的某个地方也有一个观点.我想将空间中的某点移动到与多边形相同的平面上.据我所知,众所周知如何做到这一点.但是,我并不为人所熟知.
我找不到任何直接的算法或如何做到这一点的可靠解释.
我一直在看这个:http://www.odeion.org/pythagoras/pythag3d.html
但这会给我距离而不是顶点的距离.我可以看到,如果多边形限制为2d,那将是多么有用,但在我的情况下,它可能有任何方向.
不幸的是,我的数学相当薄弱,但我更愿意学习.
我正在考虑如何在C++中快速扩大阵列,我想出了这个:
// set up arr1
int *arr1 = new int[5];
// add data to arr1
arr1[0] = 1;
arr1[1] = 2;
arr1[2] = 3;
arr1[3] = 4;
arr1[4] = 5;
// set up arr2
int *arr2 = new int[10];
arr2 = arr1; // assign arr1 to arr2
// add more values
arr2[5] = 6;
arr2[6] = 7;
arr2[7] = 8;
arr2[8] = 9;
arr2[9] = 10;
Run Code Online (Sandbox Code Playgroud)
这甚至安全吗?我担心这会导致一些奇怪的行为,并且arr2只是一个int [5]数组,你现在正在覆盖不属于它的数据.
我已经通过drupal模块将youtube视频嵌入到网站中(我不确定这是否与此相关).一切正常,我可以通过javascript与视频互动,并做我需要的一切,但是,全屏不再有效.
这是我用来嵌入视频的字符串:
orientation.start_id = $('#orientation-player').attr('data-youtube_id');
var params = {allowScriptAccess: 'always'};
var atts = {id: 'orientation-player', wmode: 'opaque'};
swfobject.embedSWF('http://www.youtube.com/v/'+orientation.start_id+'?version=3&enablejsapi=1&playerapiid=orientation-player',
'orientation-player', '854', '480', '8', null, null, params, atts);
Run Code Online (Sandbox Code Playgroud) 我有这个 mootools 请求:
new Request({
url: 'http://localhost:8080/list',
method: 'get',
}).send();
Run Code Online (Sandbox Code Playgroud)
和一个小型 python 服务器,用以下方式处理它:
from BaseHTTPServer import BaseHTTPRequestHandler, HTTPServer
import subprocess
class HttpHandler(BaseHTTPRequestHandler):
def do_GET(self):
if self.path == '/list':
self.list()
else:
self._404()
def list(self):
self.response200()
res = "some string"
self.wfile.write(res)
def _404(self):
self.response404()
self.wfile.write("404\n")
def response200(self):
self.send_response(200)
self.send_header('Access-Control-Allow-Origin', '*')
self.send_header('Access-Control-Allow-Headers', 'X-Request, X-Requested-With')
self.send_header('Content-type', 'application/json')
self.end_headers()
def response404(self):
self.send_response(404)
self.send_header('Content-type', 'application/json')
self.end_headers()
def main():
try:
server = HTTPServer(('', 8080), HttpHandler)
server.serve_forever()
except KeyboardInterrupt:
server.socket.close()
if __name__ == '__main__':
main()
Run Code Online (Sandbox Code Playgroud)
当我尝试提出此请求时,我收到以下错误:
OPTIONS http://localhost:8080/ …Run Code Online (Sandbox Code Playgroud) 可能重复:
为什么模板只能在头文件中实现?
我在gcc和clang中遇到一些我不熟悉的错误.首先,这是有问题的代码.
WaypointTree.h:
class WaypointTree {
private:
Waypoint *head = nullptr;
Waypoint *current = nullptr;
template<class Function>
void each_recur(Waypoint *current, Function f);
public:
template<class Function>
void foreach(Function f);
void add(Waypoint *wp, Waypoint *parent = nullptr);
bool isLast(Waypoint *wp);
Waypoint *next();
Waypoint *getHead() { return head; }
void reverse() {}
};
Run Code Online (Sandbox Code Playgroud)
WaypointTree.cpp:
. . .
template<class Function>
void WaypointTree::foreach(Function f) {
each_recur(head, f);
}
. . .
Run Code Online (Sandbox Code Playgroud)
Flock.cpp:
...
_waypoints->foreach([] (Waypoint *wp) {
glPushMatrix(); {
glTranslatef(wp->getX(), wp->getY(), wp->getZ());
glutSolidSphere(0.02, 5, …Run Code Online (Sandbox Code Playgroud) 我正在尝试创建一些单选按钮并动态添加一个RadioGroup.当我使用LayoutInflater方法拉入xml并将其添加到当前视图时,一切正常.出现正确的单选按钮.
但是,当我尝试将LayoutInflater.inflate的View转换为RadioButton(因此我可以使用setText)时,我得到一个强制关闭java.lang.ClassCastException.
for (int i = 0; i < options.length(); i++) {
JSONObject option = options.getJSONObject(i);
View option_view = vi.inflate(R.layout.poll_option, radio_group, true);
option_view.setId(i);
RadioButton rb = (RadioButton) option_view.findViewById(i);
rb.setText(option.getString("response"));
}
Run Code Online (Sandbox Code Playgroud)
poll_option.xml:
<RadioButton xmlns:android="http://schemas.android.com/apk/res/android"
android:text="RadioButton"
android:layout_width="wrap_content"
android:layout_height="wrap_content" />
Run Code Online (Sandbox Code Playgroud) 我遇到了一个脚本,其代码如下:
arr=($p)
np=${#arr[*]}
Run Code Online (Sandbox Code Playgroud)
p是一对整数对:"0,1 2,4 3,5"等.首先,我不是100%确定()在第一行中做了什么,但我认为它只是改变了事情成为一个关联的数组?这可能也不正确......但更重要的是,我完全不知道第二行的作用.