package main

import (
	"cicv-data-closedloop/pjisuv_msgs"
	"cicv-data-closedloop/pjisuv_param"
	"math"
)

/*
def callback_tpperception(data):
    global obj_dic
    obj_list=data.objs
    for obj in obj_list:

        if  obj.x>=5  and abs(obj.y)<=10: # 根据这个条件过滤一遍目标物 ,  用于前车切入切出判别
            if obj.id not in obj_dic:
                obj_dic[obj.id]=[]
            obj_dic[obj.id].append(obj.y)

        if abs(obj.y)<=2 and obj.x>=6: # 根据这个条件过滤一遍目标物 ,  用于计算ＴＴＣ

            TTC=-(obj.x-4)/(obj.vxrel+0.0001)
            if 0<=TTC<=3:
                event_label='TTC'
                print(event_label)
                break
*/

func Topic() string {
	return "/tpperception"
}

// Label todo 禁止存在下划线_
func Label() string {
	return "TTC"
}

func Rule(data *pjisuv_msgs.PerceptionObjects, param pjisuv_param.PjisuvParam) string {
	for _, obj := range data.Objs {
		if math.Abs(float64(obj.Y)) <= 2 && obj.X >= 6 && param.VelocityYOfCicvLocation > 1 {
			ttc := -((float64(obj.X) - 4) / (float64(obj.Vxrel) + 0.001))
			if ttc >= 0 && ttc <= 3 {
				return "TTC"
			}
		}
	}
	return ""
}

// DegreesToRadians 计算角度转弧度
func DegreesToRadians(degrees float64) float64 {
	return degrees * math.Pi / 180.0
}
