// pt projects p from the source rectangle onto the target rectangle.
170692
func (s *projector) pt(p image.Point) image.Point {
	return image.Point{
		clamp(s.rx*float64(p.X)+s.dx, s.r.Min.X, s.r.Max.X),
		clamp(s.ry*float64(p.Y)+s.dy, s.r.Min.Y, s.r.Max.Y),
	}
}
1137154
func (p Point) DistanceTo(other Point) float64 {
	dx := math.Pow(float64(p.X-other.X), 2)
	dy := math.Pow(float64(p.Y-other.Y), 2)
	return math.Pow(dx+dy, 0.5)
}
946156
func (p *Path) InsertAt(index int, point *Point) *Path {
	(&p.PointSet).InsertAt(index, point)
	return p
}
761572
func PtrOf(itf interface{}) interface{} {
	t := reflect.TypeOf(itf)

	cp := reflect.New(t)
	cp.Elem().Set(reflect.ValueOf(itf))

	// Avoid double pointers if itf is a pointer
	if t.Kind() == reflect.Ptr {
		return cp.Elem().Interface()
	}

	return cp.Interface()
}
486322
func (oc *OpCommon) AddSelfUpdate(ptr data.BlockPointer) {
	oc.AddUpdate(ptr, ptr)
}
1128662
func (self *SizeSpec) TargetWH(rect image.Rectangle) (int, int) {
	if self.full {
		return rect.Dx(), rect.Dy()
	}
	if self.square {
		return self.width, self.height
	}
	if self.width == -1 {
		// scaling height only
		ratio := float64(rect.Dy()) / float64(self.height)
		x := int(float64(rect.Dx()) / ratio)
		return x, self.height
	}
	if self.height == -1 {
		// scaling height only
		ratio := float64(rect.Dx()) / float64(self.width)
		x := int(float64(rect.Dy()) / ratio)
		return self.width, x
	}

	return self.width, self.height
}
524791
func (g *MultiPoint) Push(p *Point) error {
	if p.layout != g.layout {
		return ErrLayoutMismatch{Got: p.layout, Want: g.layout}
	}
	g.flatCoords = append(g.flatCoords, p.flatCoords...)
	return nil
}
569121
func (cr *Context) Rectangle(x, y, width, height float64) {
	C.cairo_rectangle(cr.Ptr, C.double(x), C.double(y), C.double(width), C.double(height))
	if err := cr.status(); err != nil {
		panic(err)
	}
}
1142724
func (pTypeDef *Rect) Init() *Rect {
	if pTypeDef.P1 == nil {
		pTypeDef.P1 = NewPoint()
	}
	if pTypeDef.P2 == nil {
		pTypeDef.P2 = NewPoint()
	}
	return pTypeDef
}
751026
func (p *Polyline) RectBound() Rect {
	rb := NewRectBounder()
	for _, v := range *p {
		rb.AddPoint(v)
	}
	return rb.RectBound()
}
1344952
func (p *Point) ProjectOnto(p2 Point) Point {
	dot := p.X*p2.X + p.Y*p2.Y
	denom := p2.X*p2.X + p2.Y*p2.Y
	if FloatEqual(denom, 0) {
		return Point{}
	}
	return Point{
		dot / denom * p2.X,
		dot / denom * p2.Y,
	}
}
313036
func (p *MercatorProjection) Unproject(pt r2.Point) Point {
	return PointFromLatLng(p.ToLatLng(pt))
}
817974
func (p Point) VectorTo(op *Point) *Vector {
	return NewVector(op.X()-p.x, op.Y()-p.y)
}
58509
func (m *PlannerDefault) WalkProjectionSource(p *Source) error {
	// Add a Non-Final Projection to choose the columns for results
	//u.Debugf("exec.projection: %p job.proj: %p added  %s", p, m.Ctx.Projection, p.Stmt.String())
	proj := NewProjectionInProcess(p.Stmt.Source)
	//u.Debugf("source projection: %p added  %s", proj, p.Stmt.Source.String())
	p.Add(proj)
	m.Ctx.Projection = proj
	return nil
}
1352914
func (p *Point) InRect(r *Rect) bool {
	if (p.X >= r.X) && (p.X < (r.X + r.W)) &&
		(p.Y >= r.Y) && (p.Y < (r.Y + r.H)) {
		return true
	}
	return false
}
41325
func (l *Line) Project(point *Point) float64 {
	if point.Equals(&l.a) {
		return 0.0
	}

	if point.Equals(&l.b) {
		return 1.0
	}

	dx := l.b[0] - l.a[0]
	dy := l.b[1] - l.a[1]
	d := (dx*dx + dy*dy)
	if d == 0 {
		return 0
	}

	return ((point[0]-l.a[0])*dx + (point[1]-l.a[1])*dy) / d
}
1136920
func (p *Path) Push(point *Point) *Path {
	(&p.PointSet).Push(point)
	return p
}