// 将 points 中的所有点，以 x,y 为原点旋转 angle 个角度。
// angle 取值只能是 [0,1,2,3]，分别表示 [0，90，180，270]
972905
func rotate(points []float64, x, y float64, angle int) {
	if angle < 0 || angle > 3 {
		panic("rotate:参数angle必须0,1,2,3三值之一")
	}

	for i := 0; i < len(points); i += 2 {
		px := points[i] - x
		py := points[i+1] - y
		points[i] = px*cos[angle] - py*sin[angle] + x
		points[i+1] = px*sin[angle] + py*cos[angle] + y
	}
}
474108
func Point(lon, lat interface{}) Term {
	return constructRootTerm("Point", p.Term_POINT, []interface{}{lon, lat}, map[string]interface{}{})
}
793213
func (f *Fpdf) point(x, y float64) {
	f.outf("%.2f %.2f m", x*f.k, (f.h-y)*f.k)
}
238422
func (s GeoDistanceSort) Point(lat, lon float64) GeoDistanceSort {
	s.points = append(s.points, GeoPointFromLatLon(lat, lon))
	return s
}
689966
func (ps PointSet) Centroid() *Point {
	x := 0.0
	y := 0.0
	numPoints := float64(len(ps))
	for _, point := range ps {
		x += point[0]
		y += point[1]
	}
	return &Point{x / numPoints, y / numPoints}
}
1148457
func (e *G2) CurvePoints() (*gfP2, *gfP2, *gfP2, *gfP2) {
	return e.p.x, e.p.y, e.p.z, e.p.t
}
677950
func (e *G1) CurvePoints() (*big.Int, *big.Int, *big.Int, *big.Int) {
	return e.p.x, e.p.y, e.p.z, e.p.t
}
1155906
func NormalizePoint(x []float64) {

	var sum float64
	for i := range x {
		sum += x[i] * x[i]
	}

	mag := math.Sqrt(sum)

	for i := range x {
		if math.IsInf(x[i]/mag, 0) || math.IsNaN(x[i]/mag) {
			// fallback to zero when dividing by 0
			x[i] = 0
			continue
		}

		x[i] /= mag
	}
}
1338489
func (calc *PointCentroidCalculator) AddPoint(point *geom.Point) {
	calc.AddCoord(geom.Coord(point.FlatCoords()))
}
725844
func (p *Point) Dot(v *Point) float64 {
	return p[0]*v[0] + p[1]*v[1]
}
861619
func (g *MultiPoint) Point(i int) *Point {
	return NewPointFlat(g.layout, g.Coord(i))
}
1092762
func (p *Point) Normalize() (Point, float32) {
	if p.X == 0 && p.Y == 0 {
		return *p, 0
	}

	mag := math.Sqrt(p.X*p.X + p.Y*p.Y)
	unit := Point{p.X / mag, p.Y / mag}

	return unit, mag
}
282270
func ValuesToPoints(values map[string][]Value) []models.Point {
	points := make([]models.Point, 0, len(values))
	for composite, vals := range values {
		series, field := SeriesAndFieldFromCompositeKey([]byte(composite))
		strField := string(field)
		for _, val := range vals {
			t := time.Unix(0, val.UnixNano())
			fields := models.Fields{strField: val.Value()}
			points = append(points, models.NewPointFromSeries(series, fields, t))
		}
	}
	return points
}
641852
func (l *Line) Side(p *Point) int {
	val := (l.b[0]-l.a[0])*(p[1]-l.b[1]) - (l.b[1]-l.a[1])*(p[0]-l.b[0])

	if val < 0 {
		return 1 // right
	} else if val > 0 {
		return -1 // left
	}

	return 0 // collinear
}
1144605
func (m mathUtil) CirclePoint(cx, cy int, radius, thetaRadians float64) (x, y int) {
	x = cx + int(radius*math.Sin(thetaRadians))
	y = cy - int(radius*math.Cos(thetaRadians))
	return
}
737950
func (vec *T) RotateAroundPoint(point *T, angle float32) *T {
	return vec.Sub(point).Rotate(angle).Add(point)
}
1124211
func (p *Point) Round(factor ...int) *Point {
	f := 1.0e5
	if len(factor) != 0 {
		f = float64(factor[0])
	}

	for idx, val := range p {
		x := val * f
		p[idx] = math.Floor(x+0.5) / f
	}

	return p
}