示例#1
0
void SectionRenderer::Draw(Gdiplus::Graphics* g, MapViewport* viewport, const Component* component)
{
	const Section* section = static_cast<const Section*>(component);
	Vector2d last;
	bool haslast = false;
	
	const Properties& props = component->GetProperties();
	Gdiplus::Pen pen(Gdiplus::Color(props.Get<prop::Color>(Gdiplus::Color::Black)),
									props.Get<prop::LineWidth>(2));
	pen.SetDashStyle((Gdiplus::DashStyle)props.Get<prop::DashStyle>(Gdiplus::DashStyle::DashStyleSolid));
	pen.SetLineJoin(Gdiplus::LineJoin::LineJoinRound);
	bool dispEnd = props.Get<prop::DisplaySectionEnd>(false);

	Gdiplus::GraphicsPath path;

	const Section::LocationList& locations = section->GetLocations();
	for(const Location& location : locations)
	{
		Vector2d point = viewport->LocationToPixel(location);
		if(haslast)
			path.AddLine((float)last.GetX(), (float)last.GetY(), (float)point.GetX(), (float)point.GetY());
		last = point;
		haslast = true;
	}
	g->DrawPath(&pen, &path);

	if(dispEnd)
	{
		Vector2d point = viewport->LocationToPixel(locations.front());
		g->FillEllipse(pen.GetBrush(), point.GetX() - 3.f, point.GetY() - 3.f, 6.f, 6.f);
		point.Set(viewport->LocationToPixel(locations.back()));
		g->FillEllipse(pen.GetBrush(), point.GetX() - 3.f, point.GetY() - 3.f, 6.f, 6.f);
	}
}
示例#2
0
void LocationRenderer::Draw(Gdiplus::Graphics* g, MapViewport* viewport, const Component* component)
{
	const Properties& prop = component->GetProperties();
	Gdiplus::SolidBrush brush(prop.Get<prop::Color>(Gdiplus::Color::Red));
	Vector2d p = viewport->LocationToPixel(*static_cast<const Location*>(component));
	switch(prop.Get<prop::Shape>(Shape::FilledCircle))
	{
	case Shape::FilledCircle:
		g->FillEllipse(&brush, (float)p.GetX() - 5, (float)p.GetY() - 5, 10.f, 10.f);
		break;

	case Shape::Circle:
		Gdiplus::Pen pen(&brush, prop.Get<prop::LineWidth>(2));
		g->DrawEllipse(&pen, (float)p.GetX() - 5, (float)p.GetY() - 5, 10.f, 10.f);
		break;
	}
	
}
示例#3
0
double DistanceToSegment(const Vector2d& p, const Vector2d& a, const Vector2d& b, Vector2d* nearest)
{
	if(p == a) { if(nearest != nullptr) nearest->Set(a); return 0; }
	if(p == b) { if(nearest != nullptr) nearest->Set(b); return 0; }
	Vector2d ab(b.GetX() - a.GetX(), b.GetY() - a.GetY());
	Vector2d ap(p.GetX() - a.GetX(), p.GetY() - a.GetY());
	double abap = ab.GetX()*ap.GetX() + ab.GetY()*ap.GetY();
	if(abap < 0) { if(nearest != nullptr) nearest->Set(a); return p.GetDistance(a); }
	double absq = SQ(ab.GetX()) + SQ(ab.GetY());
	double ahsq = SQ(abap)/(SQ(ab.GetX()) + SQ(ab.GetY()));
	if(ahsq > absq) { if(nearest != nullptr) nearest->Set(b); return p.GetDistance(b); }
	if(nearest != nullptr)
	{
		double normab = a.GetDistance(b);
		double ah = std::sqrt(ahsq);
		nearest->Set({a.GetX() + ah*ab.GetX()/normab, a.GetY() + ah*ab.GetY()/normab});
	}
	return std::sqrt(SQ(ap.GetX()) + SQ(ap.GetY()) - ahsq);
}
示例#4
0
void PRFilledPolygon::setPoints(Vector2dVector &points) {
    
    CC_SAFE_FREE(areaTrianglePoints);
    CC_SAFE_FREE(textureCoordinates);
    
    Vector2dVector triangulatedPoints = PRRatcliffTriangulator::triangulateVertices(points);
    
    areaTrianglePointCount = triangulatedPoints.size();
    areaTrianglePoints = (CCPoint*) malloc(sizeof(CCPoint) * areaTrianglePointCount);
    textureCoordinates = (CCPoint*) malloc(sizeof(CCPoint) * areaTrianglePointCount);
    
    for (int i = 0; i < areaTrianglePointCount; i++) {
        Vector2d v = (Vector2d)triangulatedPoints.at(i);
        areaTrianglePoints[i] = CCPointMake(v.GetX(), v.GetY());
    }
    
    calculateTextureCoordinates();
}
示例#5
0
void EasyPolygon::setPoints(Vector2dVector &points) {
    
    if (points.size() <= 0) {
        areaTrianglePointCount = 0;
        return;
    }
    
    CC_SAFE_FREE(areaTrianglePoints);
    CC_SAFE_FREE(textureCoordinates);
    
    /*Vector2dVector triangulatedPoints = PRRatcliffTriangulator::triangulateVertices(points);
    
    areaTrianglePointCount = (int)triangulatedPoints.size();
    areaTrianglePoints = (Point*) malloc(sizeof(Point) * areaTrianglePointCount);
    textureCoordinates = (Point*) malloc(sizeof(Point) * areaTrianglePointCount);
    
    for (int i = 0; i < areaTrianglePointCount; i++) {
        Vector2d v = (Vector2d)triangulatedPoints.at(i);
        areaTrianglePoints[i] = Point(v.GetX(), v.GetY());
       // printf("x = %f, y = %f\n", v.GetX, v.GetY);
    }*/
    areaTrianglePointCount = 6;
    areaTrianglePoints = (Point*) malloc(sizeof(Point) * areaTrianglePointCount);
    textureCoordinates = (Point*) malloc(sizeof(Point) * areaTrianglePointCount);
    
    Vector2d v = points.at(0);
    areaTrianglePoints[0] = Point(v.GetX(), v.GetY());
    v = points.at(3);
    areaTrianglePoints[1] = Point(v.GetX(), v.GetY());
    v = points.at(2);
    areaTrianglePoints[2] = Point(v.GetX(), v.GetY());
    v = points.at(2);
    areaTrianglePoints[3] = Point(v.GetX(), v.GetY());
    v = points.at(1);
    areaTrianglePoints[4] = Point(v.GetX(), v.GetY());
    v = points.at(0);
    areaTrianglePoints[5] = Point(v.GetX(), v.GetY());

    
    calculateTextureCoordinates();
}