我一直在使用Moveable-Type网站来帮助我进行一些Geocoordinate计算并且它非常有用,但是,我在计算两个坐标之间的中点时遇到了一个错误.我的结果接近预期,但不够接近:
posA = {47.64570362, -122.14073746}
posB = {47.64316917, -122.14032175}
Run Code Online (Sandbox Code Playgroud)
预期结果(取自可移动型计算器)= 47°38'40"N,122°08'26"W = {47.644444, -122.140556}我的结果:{49.6054801645915, -122.14052959995759}
这是我的代码:
private Geocoordinate MidPoint(Geocoordinate posA, Geocoordinate posB)
{
Geocoordinate midPoint = new Geocoordinate();
double dLon = DegreesToRadians(posB.Longitude - posA.Longitude);
double Bx = Math.Cos(DegreesToRadians(posB.Latitude)) * Math.Cos(dLon);
double By = Math.Cos(DegreesToRadians(posB.Latitude)) * Math.Sin(dLon);
midPoint.Latitude = RadiansToDegrees(Math.Atan2(Math.Sin(DegreesToRadians(posA.Latitude)) + Math.Sin(DegreesToRadians(posB.Latitude)),
Math.Sqrt((Math.Cos(DegreesToRadians(posA.Latitude)) + Bx) * (Math.Cos(DegreesToRadians(posA.Latitude))) + Bx) + By * By));
midPoint.Longitude = posA.Longitude + RadiansToDegrees(Math.Atan2(By, Math.Cos(DegreesToRadians(posA.Latitude)) + Bx));
return midPoint;
}
Run Code Online (Sandbox Code Playgroud)
我有几种私有方法可以在Degrees和Radians之间进行转换.例如
private double DegreeToRadian(double angle) …Run Code Online (Sandbox Code Playgroud) 我正在尝试hasMany使用mapping语句设置我的属性的默认排序.我正在关注grails doc,但它对我不起作用(grails 1.3.5).我的代码看起来像:
class Note {
Calendar sendDate
static belongsTo = Message
}
class Message {
static hasMany = [notes: Note]
static mapping = {
notes sort:'sendDate desc'
}
}
Run Code Online (Sandbox Code Playgroud)
错误消息如下所示:
...
Caused by: com.mysql.jdbc.exceptions.jdbc4.MySQLSyntaxErrorException: Unknown column 'notes0_.sendDate' in 'order clause'
at com.mysql.jdbc.Util.handleNewInstance(Util.java:409)
at com.mysql.jdbc.Util.getInstance(Util.java:384)
...
Run Code Online (Sandbox Code Playgroud)
你看到我的代码中有任何错误吗?
我有一个场景,其中一个类加载一种类型的对象,由于抽象我不能使用泛型类(泛型往往像癌症一样蔓延:)但我经常想要检索一次通用版本的对象,结果在像这样的代码(简化):
List<SomeClass> items = Storage.LoadItems(filename).OfType<SomeClass>().ToList();
Run Code Online (Sandbox Code Playgroud)
在LoadItems返回List <object>的地方,我意识到,为什么不这样做呢
public void LoadItems(string filename,IList list);
Run Code Online (Sandbox Code Playgroud)
现在我可以这样做
List<SomeClass> items = new List<SomeClass>();
LoadItems(filename,items);
Run Code Online (Sandbox Code Playgroud)
哪个应该更有效率.由于我可以使用现有的List并添加新项目,因此它似乎也更灵活一些.所以我的问题是,这是一种常见的模式还是你有不同/更好的方法来实现这一目标?
我也有点好奇你可以做到这一点,如果你尝试添加一个错误类型的对象你得到一个例外,但这是否意味着通用列表也进行类型检查?(这似乎有点不必要)
编辑 修改模式实际上可能更优雅一些
public IList LoadItems(string filename,IList list=null);
Run Code Online (Sandbox Code Playgroud)
这样你可以流利地使用语句,如果没有传递列表,你可以简单地实例化List <object>
这是我的绘图代码,用鼠标在图表上绘制自定义行.你能帮我做正确的方法吗?
namespace Grafi
{
public partial class Form1 : Form
{
bool isDrawing = false;
Point prevPoint;
public Form1()
{
InitializeComponent();
}
private void chartTemperature_MouseDown(object sender, MouseEventArgs e)
{
isDrawing = true;
prevPoint = e.Location;
}
private void chartTemperature_MouseMove(object sender, MouseEventArgs e)
{
Pen p = new Pen(Color.Red, 2);
if (isDrawing)
{
Graphics g = chartTemperature.CreateGraphics();
g.DrawLine(p, prevPoint, e.Location);
prevPoint = e.Location;
numOfMouseEvents = 0;
}
p.Dispose();
}
private void chartTemperature_MouseUp(object sender, MouseEventArgs e)
{
isDrawing = false;
}
} …Run Code Online (Sandbox Code Playgroud) 我有一个网站,用户将首先输入他们的搜索条件.搜索结合了来自两个来源的数据,其中一个来源不是数据库.搜索结果通常足够大,可以进行分页.
由于初始查询很昂贵,如果搜索条件没有随后的页面查看更改,我想缓存搜索结果.
我目前的方法如下:
def search(criteriaMap, offset, pagesize)
Run Code Online (Sandbox Code Playgroud)
在groovy/grails中缓存搜索结果的最佳方法是什么?我如何使搜索结果失效?
注意,我看到有一个springcache插件,但我不确定这是否适用于分页结果.我也知道grails是用ehcache打包的,但我还没有看到我可以直接访问的API,我只看到它用于GORM的二级缓存.
更新:我参与了@ mfloryan的解决方案来解决这个问题.
我在searchService中创建了两个方法:
@Cacheable("searchCache")
def searchResults(uid, trimmedParams)
def trimParams(params)
Run Code Online (Sandbox Code Playgroud)
(一个是缓存而另一个不是.)
我在searchController中的代码:
def trimmedParams = searchService.trimParams(params)
def results = searchService.searchResults(trimmedParams)
//Page results
results = HelperService.pageResults(results, params.offset, params.max)
[results: results, searchParams : trimmedParams]
Run Code Online (Sandbox Code Playgroud)
结果,我调用了搜索服务,其中包含一个不包含分页参数的修剪参数列表.可以返回缓存的搜索结果.
searchController负责分页.
注意:我没有缓存hibernate结果,因为我最终会在缓存中加倍数据.我只缓存了来自searchService.searchResults的组合结果(它访问了REST API和我的本地数据库)
我正在使用Git Bash,并且当我输入'git commit -a'时我想弄清楚发生了什么.
看起来VIM打开来编辑我的提交消息但是如何保存并实际完成此提交?我输入编辑器并按Enter键,但它只是创建另一行.
仅供参考:我在Mac上使用VM Fusion,因此我的一些按键可能会有所不同
我想检查上传文件的类型.如果名字喜欢example.txt,我想只得到这个.txt部分.我如何使用Jquery或javascript实现它.
任何建议或链接将是赞赏!
我有一个具有以下属性的Moose对象:
has 'people' => (
is => 'ro',
isa => 'ArrayRef[Person::Child]',
traits => ['Array'],
default => sub { [] },
handles => {
all_people => 'elements',
get_people => 'get',
push_people => 'push',
pop_people => 'pop',
count_people => 'count',
sort_people => 'sort',
grep_people => 'grep',
},
);
Run Code Online (Sandbox Code Playgroud)
注意,它isa被设置为'ArrayRef [Person :: Child]'.
我想能够之间进行选择Person::Child,Person::Adult在创建我的对象等.那是可能的,或者我必须创建不同的对象,这将是相同的,除了isa在的people属性?
(这让我想起了Java泛型).
我有类Person(名字,姓氏,地址,年龄)和重载运算符<<和>>来与文件流一起使用:
ostream& operator<< (ostream& outStream, Person& person)
{
...
}
istream& operator>> (istream& inStream, Person& person)
{
...
}
Run Code Online (Sandbox Code Playgroud)
它工作正常 - 我可以轻松地读取和写入文件,但我添加了两个继承自Person:Student和Worker的类.
我为他们编写了重载操作符,与上面的操作符非常相似:
ostream& operator<< (ostream& outStream, Worker& worker)
{
...
}
istream& operator>> (istream& inStream, Worker& worker)
{
...
}
ostream& operator<< (ostream& outStream, Student& student)
{
...
}
istream& operator>> (istream& inStream, Student& student)
{
...
}
Run Code Online (Sandbox Code Playgroud)
唯一不同的是每个班级还有两个字段.问题是,当我使用Student或Worker重载运算符时,我的编译器似乎使用运算符.可能它会从Student或Worker到Person进行隐藏转换,但结果是没有写入该文件的其他字段.offstream <<人们的工作与流出的<<学生或外来工人一样.也许首先为继承的类放置重载的运算符声明,然后在代码中为Person解决问题,但我不认为它是一个优雅的解决方案.
如果您有一些想法如何解决上述问题,我将不胜感激.
我的应用程序正在动态加载插件,当我添加一个新模块时,我需要重建管道段缓存,但该应用程序在程序文件夹中没有写入权限并导致UnauthorizedAccessException.我不想在临时目录或用户应用程序目录中复制插件.
有没有办法找到/激活新添加的插件而无需重建管道段缓存?
c# ×3
grails ×2
.net ×1
c++ ×1
drawing ×1
ehcache ×1
generics ×1
geolocation ×1
git ×1
grails-orm ×1
groovy ×1
ilist ×1
inheritance ×1
javascript ×1
jquery ×1
moose ×1
onpaint ×1
operators ×1
overloading ×1
perl ×1
system.addin ×1
vim ×1