Philipp Schrader | e625ba2 | 2020-11-16 20:11:37 -0800 | [diff] [blame] | 1 | import * as configuration from 'org_frc971/aos/configuration_generated'; |
Philipp Schrader | e625ba2 | 2020-11-16 20:11:37 -0800 | [diff] [blame] | 2 | import {Connection} from 'org_frc971/aos/network/www/proxy'; |
| 3 | import * as flatbuffers_builder from 'org_frc971/external/com_github_google_flatbuffers/ts/builder'; |
| 4 | import {ByteBuffer} from 'org_frc971/external/com_github_google_flatbuffers/ts/byte-buffer'; |
| 5 | import {Long} from 'org_frc971/external/com_github_google_flatbuffers/ts/long'; |
| 6 | import * as sift from 'org_frc971/y2020/vision/sift/sift_generated' |
| 7 | import * as vision from 'org_frc971/y2020/vision/vision_generated'; |
James Kuszmaul | 71a8193 | 2020-12-15 21:08:01 -0800 | [diff] [blame^] | 8 | import * as web_proxy from 'org_frc971/aos/network/web_proxy_generated'; |
Philipp Schrader | e625ba2 | 2020-11-16 20:11:37 -0800 | [diff] [blame] | 9 | |
| 10 | import Channel = configuration.aos.Channel; |
| 11 | import Configuration = configuration.aos.Configuration; |
Philipp Schrader | e625ba2 | 2020-11-16 20:11:37 -0800 | [diff] [blame] | 12 | import CameraImage = vision.frc971.vision.CameraImage; |
| 13 | import ImageMatchResult = sift.frc971.vision.sift.ImageMatchResult; |
| 14 | import Feature = sift.frc971.vision.sift.Feature; |
James Kuszmaul | 71a8193 | 2020-12-15 21:08:01 -0800 | [diff] [blame^] | 15 | import SubscriberRequest = web_proxy.aos.web_proxy.SubscriberRequest; |
| 16 | import ChannelRequest = web_proxy.aos.web_proxy.ChannelRequest; |
| 17 | import TransferMethod = web_proxy.aos.web_proxy.TransferMethod; |
Alex Perry | d196988 | 2020-03-06 21:19:00 -0800 | [diff] [blame] | 18 | |
| 19 | /* |
| 20 | * All the messages that are required to show an image with metadata. |
| 21 | * Messages not readable on the server node are ignored. |
| 22 | */ |
| 23 | const REQUIRED_CHANNELS = [ |
| 24 | { |
| 25 | name: '/pi1/camera', |
Philipp Schrader | e625ba2 | 2020-11-16 20:11:37 -0800 | [diff] [blame] | 26 | type: CameraImage.getFullyQualifiedName(), |
Alex Perry | d196988 | 2020-03-06 21:19:00 -0800 | [diff] [blame] | 27 | }, |
| 28 | { |
| 29 | name: '/pi2/camera', |
Philipp Schrader | e625ba2 | 2020-11-16 20:11:37 -0800 | [diff] [blame] | 30 | type: CameraImage.getFullyQualifiedName(), |
Alex Perry | d196988 | 2020-03-06 21:19:00 -0800 | [diff] [blame] | 31 | }, |
| 32 | { |
| 33 | name: '/pi3/camera', |
Philipp Schrader | e625ba2 | 2020-11-16 20:11:37 -0800 | [diff] [blame] | 34 | type: CameraImage.getFullyQualifiedName(), |
Alex Perry | d196988 | 2020-03-06 21:19:00 -0800 | [diff] [blame] | 35 | }, |
| 36 | { |
| 37 | name: '/pi4/camera', |
Philipp Schrader | e625ba2 | 2020-11-16 20:11:37 -0800 | [diff] [blame] | 38 | type: CameraImage.getFullyQualifiedName(), |
Alex Perry | d196988 | 2020-03-06 21:19:00 -0800 | [diff] [blame] | 39 | }, |
| 40 | { |
| 41 | name: '/pi5/camera', |
Philipp Schrader | e625ba2 | 2020-11-16 20:11:37 -0800 | [diff] [blame] | 42 | type: CameraImage.getFullyQualifiedName(), |
Alex Perry | d196988 | 2020-03-06 21:19:00 -0800 | [diff] [blame] | 43 | }, |
| 44 | { |
| 45 | name: '/pi1/camera/detailed', |
Philipp Schrader | e625ba2 | 2020-11-16 20:11:37 -0800 | [diff] [blame] | 46 | type: ImageMatchResult.getFullyQualifiedName(), |
Alex Perry | d196988 | 2020-03-06 21:19:00 -0800 | [diff] [blame] | 47 | }, |
| 48 | { |
| 49 | name: '/pi2/camera/detailed', |
Philipp Schrader | e625ba2 | 2020-11-16 20:11:37 -0800 | [diff] [blame] | 50 | type: ImageMatchResult.getFullyQualifiedName(), |
Alex Perry | d196988 | 2020-03-06 21:19:00 -0800 | [diff] [blame] | 51 | }, |
| 52 | { |
| 53 | name: '/pi3/camera/detailed', |
Philipp Schrader | e625ba2 | 2020-11-16 20:11:37 -0800 | [diff] [blame] | 54 | type: ImageMatchResult.getFullyQualifiedName(), |
Alex Perry | d196988 | 2020-03-06 21:19:00 -0800 | [diff] [blame] | 55 | }, |
| 56 | { |
| 57 | name: '/pi4/camera/detailed', |
Philipp Schrader | e625ba2 | 2020-11-16 20:11:37 -0800 | [diff] [blame] | 58 | type: ImageMatchResult.getFullyQualifiedName(), |
Alex Perry | d196988 | 2020-03-06 21:19:00 -0800 | [diff] [blame] | 59 | }, |
| 60 | { |
| 61 | name: '/pi5/camera/detailed', |
Philipp Schrader | e625ba2 | 2020-11-16 20:11:37 -0800 | [diff] [blame] | 62 | type: ImageMatchResult.getFullyQualifiedName(), |
Alex Perry | d196988 | 2020-03-06 21:19:00 -0800 | [diff] [blame] | 63 | }, |
| 64 | ]; |
Alex Perry | 5f474f2 | 2020-02-01 12:14:24 -0800 | [diff] [blame] | 65 | |
| 66 | export class ImageHandler { |
| 67 | private canvas = document.createElement('canvas'); |
Alex Perry | fffe2e3 | 2020-02-29 19:48:17 -0800 | [diff] [blame] | 68 | private select = document.createElement('select'); |
| 69 | |
Alex Perry | b41d578 | 2020-02-09 17:06:40 -0800 | [diff] [blame] | 70 | private imageBuffer: Uint8ClampedArray|null = null; |
Philipp Schrader | e625ba2 | 2020-11-16 20:11:37 -0800 | [diff] [blame] | 71 | private image: CameraImage|null = null; |
| 72 | private imageTimestamp: Long|null = null; |
| 73 | private result: ImageMatchResult|null = null; |
| 74 | private resultTimestamp: Long|null = null; |
Alex Perry | 22824d7 | 2020-02-29 17:11:43 -0800 | [diff] [blame] | 75 | private width = 0; |
| 76 | private height = 0; |
Alex Perry | fffe2e3 | 2020-02-29 19:48:17 -0800 | [diff] [blame] | 77 | private selectedIndex = 0; |
Alex Perry | 22824d7 | 2020-02-29 17:11:43 -0800 | [diff] [blame] | 78 | private imageSkipCount = 3; |
Alex Perry | 5f474f2 | 2020-02-01 12:14:24 -0800 | [diff] [blame] | 79 | |
Alex Perry | d196988 | 2020-03-06 21:19:00 -0800 | [diff] [blame] | 80 | constructor(private readonly connection: Connection) { |
Alex Perry | fffe2e3 | 2020-02-29 19:48:17 -0800 | [diff] [blame] | 81 | document.body.appendChild(this.select); |
| 82 | const defaultOption = document.createElement('option'); |
| 83 | defaultOption.innerText = 'Show all features'; |
| 84 | this.select.appendChild(defaultOption); |
| 85 | this.select.addEventListener('change', (ev) => this.handleSelect(ev)); |
Alex Perry | 5f474f2 | 2020-02-01 12:14:24 -0800 | [diff] [blame] | 86 | document.body.appendChild(this.canvas); |
Alex Perry | d196988 | 2020-03-06 21:19:00 -0800 | [diff] [blame] | 87 | |
| 88 | this.connection.addConfigHandler(() => { |
| 89 | this.sendConnect(); |
| 90 | }); |
Austin Schuh | 7c75e58 | 2020-11-14 16:41:18 -0800 | [diff] [blame] | 91 | this.connection.addHandler( |
Philipp Schrader | e625ba2 | 2020-11-16 20:11:37 -0800 | [diff] [blame] | 92 | ImageMatchResult.getFullyQualifiedName(), (data) => { |
Austin Schuh | 7c75e58 | 2020-11-14 16:41:18 -0800 | [diff] [blame] | 93 | this.handleImageMetadata(data); |
| 94 | }); |
Philipp Schrader | e625ba2 | 2020-11-16 20:11:37 -0800 | [diff] [blame] | 95 | this.connection.addHandler(CameraImage.getFullyQualifiedName(), (data) => { |
| 96 | this.handleImage(data); |
| 97 | }); |
Alex Perry | d196988 | 2020-03-06 21:19:00 -0800 | [diff] [blame] | 98 | } |
| 99 | |
| 100 | private sendConnect(): void { |
Philipp Schrader | e625ba2 | 2020-11-16 20:11:37 -0800 | [diff] [blame] | 101 | const builder = |
| 102 | new flatbuffers_builder.Builder(512) as unknown as flatbuffers.Builder; |
Alex Perry | d196988 | 2020-03-06 21:19:00 -0800 | [diff] [blame] | 103 | const channels: flatbuffers.Offset[] = []; |
| 104 | for (const channel of REQUIRED_CHANNELS) { |
| 105 | const nameFb = builder.createString(channel.name); |
| 106 | const typeFb = builder.createString(channel.type); |
Philipp Schrader | e625ba2 | 2020-11-16 20:11:37 -0800 | [diff] [blame] | 107 | Channel.startChannel(builder); |
| 108 | Channel.addName(builder, nameFb); |
| 109 | Channel.addType(builder, typeFb); |
| 110 | const channelFb = Channel.endChannel(builder); |
James Kuszmaul | 71a8193 | 2020-12-15 21:08:01 -0800 | [diff] [blame^] | 111 | ChannelRequest.startChannelRequest(builder); |
| 112 | ChannelRequest.addChannel(builder, channelFb); |
| 113 | ChannelRequest.addMethod(builder, TransferMethod.SUBSAMPLE); |
| 114 | channels.push(ChannelRequest.endChannelRequest(builder)); |
Alex Perry | d196988 | 2020-03-06 21:19:00 -0800 | [diff] [blame] | 115 | } |
| 116 | |
Philipp Schrader | e625ba2 | 2020-11-16 20:11:37 -0800 | [diff] [blame] | 117 | const channelsFb = |
James Kuszmaul | 71a8193 | 2020-12-15 21:08:01 -0800 | [diff] [blame^] | 118 | SubscriberRequest.createChannelsToTransferVector(builder, channels); |
| 119 | SubscriberRequest.startSubscriberRequest(builder); |
| 120 | SubscriberRequest.addChannelsToTransfer(builder, channelsFb); |
| 121 | const connect = SubscriberRequest.endSubscriberRequest(builder); |
Alex Perry | d196988 | 2020-03-06 21:19:00 -0800 | [diff] [blame] | 122 | builder.finish(connect); |
| 123 | this.connection.sendConnectMessage(builder); |
Alex Perry | 5f474f2 | 2020-02-01 12:14:24 -0800 | [diff] [blame] | 124 | } |
| 125 | |
Alex Perry | fffe2e3 | 2020-02-29 19:48:17 -0800 | [diff] [blame] | 126 | handleSelect(ev: Event) { |
Philipp Schrader | a227d04 | 2020-11-14 17:33:52 -0800 | [diff] [blame] | 127 | this.selectedIndex = (ev.target as HTMLSelectElement).selectedIndex; |
Alex Perry | fffe2e3 | 2020-02-29 19:48:17 -0800 | [diff] [blame] | 128 | } |
| 129 | |
Alex Perry | b41d578 | 2020-02-09 17:06:40 -0800 | [diff] [blame] | 130 | handleImage(data: Uint8Array): void { |
Alex Perry | 3dfcb81 | 2020-03-04 19:32:17 -0800 | [diff] [blame] | 131 | console.log('got an image to process'); |
Alex Perry | 22824d7 | 2020-02-29 17:11:43 -0800 | [diff] [blame] | 132 | if (this.imageSkipCount != 0) { |
| 133 | this.imageSkipCount--; |
| 134 | return; |
| 135 | } else { |
| 136 | this.imageSkipCount = 3; |
| 137 | } |
| 138 | |
Philipp Schrader | e625ba2 | 2020-11-16 20:11:37 -0800 | [diff] [blame] | 139 | const fbBuffer = new ByteBuffer(data); |
| 140 | this.image = CameraImage.getRootAsCameraImage( |
| 141 | fbBuffer as unknown as flatbuffers.ByteBuffer); |
Alex Perry | 3dfcb81 | 2020-03-04 19:32:17 -0800 | [diff] [blame] | 142 | this.imageTimestamp = this.image.monotonicTimestampNs(); |
Alex Perry | 5f474f2 | 2020-02-01 12:14:24 -0800 | [diff] [blame] | 143 | |
Alex Perry | 3dfcb81 | 2020-03-04 19:32:17 -0800 | [diff] [blame] | 144 | this.width = this.image.cols(); |
| 145 | this.height = this.image.rows(); |
Alex Perry | 22824d7 | 2020-02-29 17:11:43 -0800 | [diff] [blame] | 146 | if (this.width === 0 || this.height === 0) { |
Alex Perry | 5f474f2 | 2020-02-01 12:14:24 -0800 | [diff] [blame] | 147 | return; |
| 148 | } |
Alex Perry | 5f474f2 | 2020-02-01 12:14:24 -0800 | [diff] [blame] | 149 | |
Alex Perry | 3dfcb81 | 2020-03-04 19:32:17 -0800 | [diff] [blame] | 150 | this.draw(); |
| 151 | } |
| 152 | |
| 153 | convertImage(): void { |
Philipp Schrader | e625ba2 | 2020-11-16 20:11:37 -0800 | [diff] [blame] | 154 | this.imageBuffer = |
| 155 | new Uint8ClampedArray(this.width * this.height * 4); // RGBA |
Alex Perry | 5f474f2 | 2020-02-01 12:14:24 -0800 | [diff] [blame] | 156 | // Read four bytes (YUYV) from the data and transform into two pixels of |
| 157 | // RGBA for canvas |
Philipp Schrader | a227d04 | 2020-11-14 17:33:52 -0800 | [diff] [blame] | 158 | for (let j = 0; j < this.height; j++) { |
| 159 | for (let i = 0; i < this.width; i += 2) { |
Alex Perry | 3dfcb81 | 2020-03-04 19:32:17 -0800 | [diff] [blame] | 160 | const y1 = this.image.data((j * this.width + i) * 2); |
| 161 | const u = this.image.data((j * this.width + i) * 2 + 1); |
| 162 | const y2 = this.image.data((j * this.width + i + 1) * 2); |
| 163 | const v = this.image.data((j * this.width + i + 1) * 2 + 1); |
Alex Perry | 5f474f2 | 2020-02-01 12:14:24 -0800 | [diff] [blame] | 164 | |
| 165 | // Based on https://en.wikipedia.org/wiki/YUV#Converting_between_Y%E2%80%B2UV_and_RGB |
| 166 | const c1 = y1 - 16; |
| 167 | const c2 = y2 - 16; |
| 168 | const d = u - 128; |
| 169 | const e = v - 128; |
| 170 | |
Alex Perry | fffe2e3 | 2020-02-29 19:48:17 -0800 | [diff] [blame] | 171 | this.imageBuffer[(j * this.width + i) * 4 + 0] = |
| 172 | (298 * c1 + 409 * e + 128) >> 8; |
| 173 | this.imageBuffer[(j * this.width + i) * 4 + 1] = |
| 174 | (298 * c1 - 100 * d - 208 * e + 128) >> 8; |
| 175 | this.imageBuffer[(j * this.width + i) * 4 + 2] = |
| 176 | (298 * c1 + 516 * d + 128) >> 8; |
Alex Perry | 22824d7 | 2020-02-29 17:11:43 -0800 | [diff] [blame] | 177 | this.imageBuffer[(j * this.width + i) * 4 + 3] = 255; |
Alex Perry | fffe2e3 | 2020-02-29 19:48:17 -0800 | [diff] [blame] | 178 | this.imageBuffer[(j * this.width + i) * 4 + 4] = |
| 179 | (298 * c2 + 409 * e + 128) >> 8; |
| 180 | this.imageBuffer[(j * this.width + i) * 4 + 5] = |
| 181 | (298 * c2 - 100 * d - 208 * e + 128) >> 8; |
| 182 | this.imageBuffer[(j * this.width + i) * 4 + 6] = |
| 183 | (298 * c2 + 516 * d + 128) >> 8; |
Alex Perry | 22824d7 | 2020-02-29 17:11:43 -0800 | [diff] [blame] | 184 | this.imageBuffer[(j * this.width + i) * 4 + 7] = 255; |
Alex Perry | 5f474f2 | 2020-02-01 12:14:24 -0800 | [diff] [blame] | 185 | } |
| 186 | } |
Alex Perry | b41d578 | 2020-02-09 17:06:40 -0800 | [diff] [blame] | 187 | } |
| 188 | |
| 189 | handleImageMetadata(data: Uint8Array): void { |
Alex Perry | 3dfcb81 | 2020-03-04 19:32:17 -0800 | [diff] [blame] | 190 | console.log('got an image match result to process'); |
Philipp Schrader | e625ba2 | 2020-11-16 20:11:37 -0800 | [diff] [blame] | 191 | const fbBuffer = new ByteBuffer(data); |
| 192 | this.result = ImageMatchResult.getRootAsImageMatchResult( |
| 193 | fbBuffer as unknown as flatbuffers.ByteBuffer); |
Alex Perry | 22824d7 | 2020-02-29 17:11:43 -0800 | [diff] [blame] | 194 | this.resultTimestamp = this.result.imageMonotonicTimestampNs(); |
| 195 | this.draw(); |
Alex Perry | b41d578 | 2020-02-09 17:06:40 -0800 | [diff] [blame] | 196 | } |
| 197 | |
| 198 | draw(): void { |
Alex Perry | fffe2e3 | 2020-02-29 19:48:17 -0800 | [diff] [blame] | 199 | if (!this.imageTimestamp || !this.resultTimestamp || |
Alex Perry | 22824d7 | 2020-02-29 17:11:43 -0800 | [diff] [blame] | 200 | this.imageTimestamp.low !== this.resultTimestamp.low || |
| 201 | this.imageTimestamp.high !== this.resultTimestamp.high) { |
Alex Perry | f23c05d | 2020-03-07 13:52:02 -0800 | [diff] [blame] | 202 | // console.log('image and result do not match'); |
| 203 | // console.log(this.imageTimestamp.low, this.resultTimestamp.low); |
| 204 | // console.log(this.imageTimestamp.high, this.resultTimestamp.high); |
Alex Perry | b41d578 | 2020-02-09 17:06:40 -0800 | [diff] [blame] | 205 | return; |
| 206 | } |
Alex Perry | 3dfcb81 | 2020-03-04 19:32:17 -0800 | [diff] [blame] | 207 | this.convertImage(); |
Alex Perry | 5f474f2 | 2020-02-01 12:14:24 -0800 | [diff] [blame] | 208 | const ctx = this.canvas.getContext('2d'); |
| 209 | |
Alex Perry | 22824d7 | 2020-02-29 17:11:43 -0800 | [diff] [blame] | 210 | this.canvas.width = this.width; |
| 211 | this.canvas.height = this.height; |
| 212 | const idata = ctx.createImageData(this.width, this.height); |
Alex Perry | b41d578 | 2020-02-09 17:06:40 -0800 | [diff] [blame] | 213 | idata.data.set(this.imageBuffer); |
Alex Perry | 5f474f2 | 2020-02-01 12:14:24 -0800 | [diff] [blame] | 214 | ctx.putImageData(idata, 0, 0); |
Philipp Schrader | a227d04 | 2020-11-14 17:33:52 -0800 | [diff] [blame] | 215 | console.log('features: ', this.result.featuresLength()); |
Alex Perry | fffe2e3 | 2020-02-29 19:48:17 -0800 | [diff] [blame] | 216 | if (this.selectedIndex === 0) { |
Philipp Schrader | a227d04 | 2020-11-14 17:33:52 -0800 | [diff] [blame] | 217 | for (let i = 0; i < this.result.featuresLength(); i++) { |
Alex Perry | fffe2e3 | 2020-02-29 19:48:17 -0800 | [diff] [blame] | 218 | const feature = this.result.features(i); |
| 219 | this.drawFeature(feature); |
| 220 | } |
| 221 | } else { |
Alex Perry | f23c05d | 2020-03-07 13:52:02 -0800 | [diff] [blame] | 222 | console.log(this.result.imageMatchesLength(), this.result.cameraPosesLength()); |
Alex Perry | fffe2e3 | 2020-02-29 19:48:17 -0800 | [diff] [blame] | 223 | const imageMatch = this.result.imageMatches(this.selectedIndex - 1); |
Philipp Schrader | a227d04 | 2020-11-14 17:33:52 -0800 | [diff] [blame] | 224 | for (let i = 0; i < imageMatch.matchesLength(); i++) { |
Alex Perry | fffe2e3 | 2020-02-29 19:48:17 -0800 | [diff] [blame] | 225 | const featureIndex = imageMatch.matches(i).queryFeature(); |
| 226 | this.drawFeature(this.result.features(featureIndex)); |
| 227 | } |
Alex Perry | f23c05d | 2020-03-07 13:52:02 -0800 | [diff] [blame] | 228 | // Draw center of target. |
Philipp Schrader | a227d04 | 2020-11-14 17:33:52 -0800 | [diff] [blame] | 229 | const cameraPose = this.result.cameraPoses(this.selectedIndex - 1); |
Alex Perry | f23c05d | 2020-03-07 13:52:02 -0800 | [diff] [blame] | 230 | ctx.strokeStyle = 'red'; |
| 231 | ctx.beginPath(); |
| 232 | ctx.arc( |
| 233 | cameraPose.queryTargetPointX(), cameraPose.queryTargetPointY(), |
| 234 | cameraPose.queryTargetPointRadius(), 0, 2 * Math.PI); |
| 235 | console.log(cameraPose.queryTargetPointX(), cameraPose.queryTargetPointY(), cameraPose.queryTargetPointRadius()); |
| 236 | ctx.stroke(); |
Alex Perry | b41d578 | 2020-02-09 17:06:40 -0800 | [diff] [blame] | 237 | } |
Alex Perry | fffe2e3 | 2020-02-29 19:48:17 -0800 | [diff] [blame] | 238 | |
Alex Perry | fffe2e3 | 2020-02-29 19:48:17 -0800 | [diff] [blame] | 239 | while (this.select.lastChild) { |
| 240 | this.select.removeChild(this.select.lastChild); |
| 241 | } |
| 242 | const defaultOption = document.createElement('option'); |
| 243 | defaultOption.innerText = 'Show all features'; |
Philipp Schrader | a227d04 | 2020-11-14 17:33:52 -0800 | [diff] [blame] | 244 | defaultOption.setAttribute('value', '0'); |
Alex Perry | fffe2e3 | 2020-02-29 19:48:17 -0800 | [diff] [blame] | 245 | this.select.appendChild(defaultOption); |
Philipp Schrader | a227d04 | 2020-11-14 17:33:52 -0800 | [diff] [blame] | 246 | for (let i = 0; i < this.result.imageMatchesLength(); i++) { |
Alex Perry | fffe2e3 | 2020-02-29 19:48:17 -0800 | [diff] [blame] | 247 | const imageMatch = this.result.imageMatches(i); |
| 248 | const option = document.createElement('option'); |
Philipp Schrader | a227d04 | 2020-11-14 17:33:52 -0800 | [diff] [blame] | 249 | option.setAttribute('value', (i + 1).toString()); |
Alex Perry | fffe2e3 | 2020-02-29 19:48:17 -0800 | [diff] [blame] | 250 | option.innerText = |
| 251 | `Show image ${i} features (${imageMatch.matchesLength()})`; |
| 252 | this.select.appendChild(option); |
| 253 | } |
| 254 | this.select.selectedIndex = this.selectedIndex; |
| 255 | } |
| 256 | |
| 257 | // Based on OpenCV drawKeypoint. |
| 258 | private drawFeature(feature: Feature) { |
| 259 | const ctx = this.canvas.getContext('2d'); |
| 260 | ctx.beginPath(); |
| 261 | ctx.arc(feature.x(), feature.y(), feature.size(), 0, 2 * Math.PI); |
| 262 | ctx.stroke(); |
| 263 | |
| 264 | ctx.beginPath(); |
| 265 | ctx.moveTo(feature.x(), feature.y()); |
| 266 | const angle = feature.angle() * Math.PI / 180; |
| 267 | ctx.lineTo( |
| 268 | feature.x() + feature.size() * Math.cos(angle), |
| 269 | feature.y() + feature.size() * Math.sin(angle)); |
| 270 | ctx.stroke(); |
Alex Perry | 5f474f2 | 2020-02-01 12:14:24 -0800 | [diff] [blame] | 271 | } |
Alex Perry | 5f474f2 | 2020-02-01 12:14:24 -0800 | [diff] [blame] | 272 | } |